Waldek,

Here is a follow up patch that further improves format.boot and
unparse. It solves the problem demonstrated by your CliffordAlgebra
example as illustrated below:

(1) -> d:=CliffordAlgebra(2,Fraction Integer,quadraticForm
matrix([[1,2],[2,-1]]))

   (1)  CliffordAlgebra(2,Fraction(Integer),[[1,2],[2,-1]])
                                                             Type: Domain
(2) -> d::InputForm

   (2)
   (CliffordAlgebra  2  (Fraction (Integer))
     (quadraticForm
      (squareMatrix (matrix (construct (construct 1 2) (construct 2 - 1)))))
     )
                                                             Type: InputForm
(3) -> unparse %

   (3)
  "CliffordAlgebra(2,Fraction(Integer),quadraticForm(squareMatrix(matrix([[1,2]
  ,[2,-1]]))))"
                                                             Type: String
(4) -> parse(%)@InputForm

   (4)
   (CliffordAlgebra  2  (Fraction Integer)
     (quadraticForm
      (squareMatrix (matrix (construct (construct 1 2) (construct 2 (- 1))))))
     )
                                                             Type: InputForm

(5) -> 1$d

   (5)  1
                    Type: CliffordAlgebra(2,Fraction(Integer),[[1,2],[2,-1]])

--------

The changes to 'src/algebra/constant.spad.pamphlet' and
'src/algebra/clifford.spad.pamphlet' provide some missing conversions
to InputForm. See for example (2) above. There are many more domains
with missing or problematic conversions to InputForm.

The routine 'matrix2String' in 'src/interp/format.boot' provides a
string representation for matrix objects. This is used when
'prefix2String' is called from 'src/interp/i-output.boot' and
'src/interp/msgdb.boot'. E.g. (1) and (5) above.

Finally $InteractiveMode is set to false when 'unparse' calls
'form2String'. This results in the output shown in (3) above.

[EMAIL PROTECTED]:~/fricas-src$ svn diff
Index: src/algebra/constant.spad.pamphlet
===================================================================
--- src/algebra/constant.spad.pamphlet  (revision 391)
+++ src/algebra/constant.spad.pamphlet  (working copy)
@@ -34,6 +34,8 @@
                    ConvertibleTo Complex Float, DifferentialRing) with
     coerce : P -> %
       ++ coerce(p) returns p viewed as an algebraic number.
+    convert: % -> InputForm
+      ++ convert(f) returns f as an InputForm
     numer  : % -> P
       ++ numer(f) returns the numerator of f viewed as a
       ++ polynomial in the kernels over Z.
@@ -134,6 +136,7 @@
        z
     belong? op           == belong?(op)$ExpressionSpace_&(%) or has?(op, ALGOP)

+    convert(x:%):InputForm == convert(x pretend FE)$FE
     convert(x:%):Float ==
       retract map(#1::Float, x pretend FE)$ExpressionFunctions2(Z,Float)

@@ -168,6 +171,8 @@
                    ConvertibleTo Complex Float, DifferentialRing) with
     coerce : P -> %
       ++ coerce(p) returns p viewed as an algebraic number.
+    convert: % -> InputForm
+      ++ convert(f) returns f as an InputForm
     numer  : % -> P
       ++ numer(f) returns the numerator of f viewed as a
       ++ polynomial in the kernels over Z.
Index: src/algebra/clifford.spad.pamphlet
===================================================================
--- src/algebra/clifford.spad.pamphlet  (revision 391)
+++ src/algebra/clifford.spad.pamphlet  (working copy)
@@ -40,12 +40,19 @@
         matrix: % -> SM(n, K)
             ++ matrix(qf) creates a square matrix from the quadratic form qf.
         elt: (%, V(n, K)) -> K
-            ++ elt(qf,v) evaluates the quadratic form qf on the vector v,
+            ++ elt(qf,v) evaluates the quadratic form qf on the vector v,
             ++ producing a scalar.
-
+        convert: % -> InputForm
+            ++ coerce(qf) returns an InputForm that evaluates to qf.
     Impl ==> SM(n,K) add
         Rep := SM(n,K)

+        import List InputForm
+
+        convert(q:%):InputForm ==
+            convert(['quadraticForm,algCoerceInteractive(q,SM(n,K),
+                InputForm)$Lisp pretend InputForm])
+
         quadraticForm m ==
             not symmetric? m =>
                 error "quadraticForm requires a symmetric matrix"
Index: src/interp/format.boot
===================================================================
--- src/interp/format.boot      (revision 393)
+++ src/interp/format.boot      (working copy)
@@ -319,7 +319,8 @@
   form2StringAsTeX form

 prefix2String form ==
-  form2String form
+  $formatSigAsTeX: local := 1
+  form2StringLocal form

 -- local version
 prefix2String0 form ==
@@ -353,6 +354,7 @@

 form2String u ==
   $formatSigAsTeX: local := 1
+  $InteractiveMode: local := false
   form2StringLocal u

 form2StringAsTeX u ==
@@ -428,11 +430,13 @@
     argl := rest argl
     (null argl) or null (first argl) => [lo, '".."]
     [lo, '"..", form2String1 first argl]
-  -- op = "MATRIX" => op
-  -- does no work
-  -- fortranCleanUp exp2Fort1 [op,:argl]
-  -- somewhat works, but causes regression
-  -- fortranCleanUp exp2Fort1 exp2FortOptimize [op,:argl]
+  op = "MATRIX" => matrix2String argl
+  u1 is ["OVER", arg1, arg2] =>
+     concat(appOrParen(arg1), '"/", appOrParen(arg2))
+  u1 is ["ROOT", arg1] =>
+     concat("sqrt(", appOrParen(arg1),")")
+  u1 is ["ROOT", arg1, arg2] =>
+     concat(appOrParen(arg1), '"^", appOrParen(["OVER",1,arg2]))
   u1 is ["$elt", t, f] =>
      concat(form2String1 f, '"$", form2String1 t)
   #argl = 2 and (isBinaryInfix op or op = "::" or op = '"::"_
@@ -440,6 +444,13 @@
           binop2String [op,:argl]
   application2String(op,[form2String1 x for x in argl], u1)

+matrix2String x ==
+  concat(lbrkSch(),
+    tuple2String [outtranRow x.i for i in 0..MAXINDEX x],rbrkSch()) where
+      outtranRow x ==
+        concat(lbrkSch(),
+          tuple2String [form2String1 x.i for i in 0..MAXINDEX x], rbrkSch())
+
 binop2String x ==
     $curExpr : local := x
     x is ["=", arg1, arg2] or x is ['"=", arg1, arg2] =>


On Fri, Sep 19, 2008 at 7:51 AM,  <[EMAIL PROTECTED]> wrote:
>
> Revision: 373
>          http://fricas.svn.sourceforge.net/fricas/?rev=373&view=rev
> Author:   whebisch
> Date:     2008-09-19 11:51:25 +0000 (Fri, 19 Sep 2008)
>
> Log Message:
> -----------
> Better unparsing.
>
> Modified Paths:
> --------------
>    trunk/ChangeLog
>    trunk/src/interp/format.boot
>
> Modified: trunk/ChangeLog
> ===================================================================
> --- trunk/ChangeLog     2008-09-19 11:05:17 UTC (rev 372)
> +++ trunk/ChangeLog     2008-09-19 11:51:25 UTC (rev 373)
> @@ -1,5 +1,15 @@
>  2008-09-19  Waldek Hebisch  <[EMAIL PROTECTED]>
>
> +       Better unparsing.
> +       * src/interp/format.boot: sumOrParen(), productOrParen(),
> +       powerOrParen(), coerceOrParen(), appOrParen(): New functions.
> +       binop2String(): call sumOrParen insted of Fortran machinery.
> +       form2String1(): Handle package calls.
> +       application2String(): Likewise, add parentheses also in
> +       one argument case.
> +
> +2008-09-19  Waldek Hebisch  <[EMAIL PROTECTED]>
> +
>        * src/algebra/boo-cat.input: Remove nonexistent categories
>        from the list.
>
>
> Modified: trunk/src/interp/format.boot
> ===================================================================
> ...

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to