On Tue, Sep 30, 2008 at 3:21 PM, Waldek Hebisch wrote:
>
> Bill Page wrote:
>>
>> 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:
>>
Here is version 2 of the patch addressing most of your comments below:
[EMAIL PROTECTED]:~/fricas-src/src$ svn diff
Index: algebra/constant.spad.pamphlet
===================================================================
--- algebra/constant.spad.pamphlet (revision 391)
+++ algebra/constant.spad.pamphlet (working copy)
@@ -31,7 +31,9 @@
LinearlyExplicitRingOver Z, RealConstant,
LinearlyExplicitRingOver Fraction Z,
CharacteristicZero,
- ConvertibleTo Complex Float, DifferentialRing) with
+ ConvertibleTo Complex Float,
+ ConvertibleTo InputForm,
+ DifferentialRing) with
coerce : P -> %
++ coerce(p) returns p viewed as an algebraic number.
numer : % -> P
@@ -134,6 +136,9 @@
z
belong? op == belong?(op)$ExpressionSpace_&(%) or has?(op, ALGOP)
+ convert(x:%):InputForm ==
+ convert(x pretend Rep)$Rep
+
convert(x:%):Float ==
retract map(#1::Float, x pretend FE)$ExpressionFunctions2(Z,Float)
@@ -165,7 +170,8 @@
LinearlyExplicitRingOver Z, RealConstant,
LinearlyExplicitRingOver Fraction Z,
CharacteristicZero,
- ConvertibleTo Complex Float, DifferentialRing) with
+ ConvertibleTo Complex Float,
+ ConvertibleTo InputForm, DifferentialRing) with
coerce : P -> %
++ coerce(p) returns p viewed as an algebraic number.
numer : % -> P
@@ -195,6 +201,9 @@
zero? a == trueEqual(a::Rep,0::Rep)
one? a == trueEqual(a::Rep,1::Rep)
a=b == trueEqual((a-b)::Rep,0::Rep)
+ -- make sure the interpreter gets an AlgebraicNumber!
+ convert(x:%):InputForm ==
+ coerceToType(convert(x pretend Rep)$Rep)$InputFormFunctions1(%)
@
\section{License}
Index: algebra/clifford.spad.pamphlet
===================================================================
--- algebra/clifford.spad.pamphlet (revision 391)
+++ algebra/clifford.spad.pamphlet (working copy)
@@ -33,19 +33,27 @@
SM ==> SquareMatrix
V ==> DirectProduct
- T ==> AbelianGroup with
+ T ==> Join(AbelianGroup,
+ if SM(n, K) has ConvertibleTo InputForm then
+ ConvertibleTo InputForm)
+ with
quadraticForm: SM(n, K) -> %
++ quadraticForm(m) creates a quadratic form from a symmetric,
++ square matrix m.
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.
-
Impl ==> SM(n,K) add
Rep := SM(n,K)
+ import List InputForm
+
+ if SM(n, K) has ConvertibleTo InputForm then
+ convert(q:%):InputForm ==
+ convert(['quadraticForm,convert(matrix q)])
+
quadraticForm m ==
not symmetric? m =>
error "quadraticForm requires a symmetric matrix"
Index: interp/format.boot
===================================================================
--- interp/format.boot (revision 393)
+++ 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,14 @@
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("nthRoot(", appOrParen(arg1),",",appOrParen(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 +445,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] =>
---
>
> For quadratic forms we should use code like this:
>
> if SM(n, K) has ConvertibleTo InputForm then ConvertibleTo InputForm
> convert : % -> InputForm
> ++ convert(qf) returns an InputForm that evaluates to qf.
>
> ....
> if SM(n, K) has ConvertibleTo InputForm then
> convert(q:%):InputForm ==
> convert(['quadraticForm, convert(q::SM(n,K))@InputForm])
>
> In constant.spad we should add ConvertibleTo InputForm instead of
> giving signature.
>
Ok, done.
>
> matrix2String looks OK, but I think that OVER, should be done
> exactly like division in binop2String. Also, power is somewhat
> differet than root, so I would just use "nthRoot" for root.
>
Done.
>> Finally $InteractiveMode is set to false when 'unparse' calls
>> 'form2String'. This results in the output shown in (3) above.
>>
>
> This does not look right: it seems that form2String is also called
> from the browser and to format messages from runtime support.
>
I realize that this change affects more than just the 'unparse' output
but in most the of the cases that I have checked in makes sense to
provide a more complete representation of the type, e.g. in debugging
and error message output.
Can you give me a specific example where this is undesirable?
Of course we could avoid these behavioural changes by introducing yet
another entry into the format routines, e.g. form2FullString but the
interface here is already rather complex.
Regards,
Bill Page.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---