axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] 20071216.03.acr.patch mathml derivative patch (7019)


From: daly
Subject: [Axiom-developer] 20071216.03.acr.patch mathml derivative patch (7019)
Date: Sun, 16 Dec 2007 21:48:09 -0600

This patch fixes the problem with derivatives. That is,

F:=operator 'F
x:=operator 'x
y:=operator 'y
a:=F(x z,y z,z^2)*x y(z+1)
D(a,z)

The MathML output for F,3 is now correct.

Tim

=======================================================================

diff --git a/changelog b/changelog
index 49e15d1..6759734 100644
--- a/changelog
+++ b/changelog
@@ -1,3 +1,4 @@
+20071216 acr src/algebra/mathml.spad fix F,3 mathml rendering (7019)
 20071216 tpd Makefile fix mistake of using wrong Makefile for Xpm fix (7045)
 20071216 cys Makefile add -lXpm to loader flags (7045)
 20071215 gxv src/graph/viewman/makegraph.c discardGraph free corrected (7023)
diff --git a/src/algebra/mathml.spad.pamphlet b/src/algebra/mathml.spad.pamphlet
index e5eaaf7..be7cf47 100644
--- a/src/algebra/mathml.spad.pamphlet
+++ b/src/algebra/mathml.spad.pamphlet
@@ -25,14 +25,14 @@ MathML exists in two forms: presentation and content.
 At this time (2007-02-11) the package only has a presentation
 package.  A content package is in the
 works however it is more difficult.  Unfortunately Axiom does
-not make its semantics easliy available.  The \spadtype{OutputForm}
+not make its semantics easily available.  The \spadtype{OutputForm}
 domain mediates between the individual Axiom domains and the
 user visible output but \spadtype{OutputForm} does not provide full
 semantic information.  From my currently incomplete understanding
 of Axiom it appears that remedying this would entail going back
 to the individual domains and rewriting a lot of code.
 However some semantics are conveyed directly by \spadtype{OutputForm} and other
-things can be deduced from \spadtype{OutputForm} or form the original
+things can be deduced from \spadtype{OutputForm} or from the original
 user command.
 
 \section{Displaying MathML}
@@ -107,7 +107,7 @@ subscripts, superscripts, presubscripts and presuperscripts 
however
 I don't know of any Axiom command that produces such an object. In
 fact at present I see the case of "SUPERSUB" being used for putting
 primes in the superscript position to denote ordinary differentiation.
-I also only see the "SUB" case being only used to denote partial
+I also only see the "SUB" case being used to denote partial
 derivatives.
 
 \section{)set output mathml on}
@@ -116,7 +116,7 @@ derivatives.
 Making mathml appear as output during a normal Axiom session
 by invoking ")set output mathml on" proved to be a bit tedious
 and seems to be undocumented.  I document my experience here
-in case in proves useful to somebody else trying to get a new
+in case it proves useful to somebody else trying to get a new
 output format from Axiom.
 
 In \spadtype{MathMLFormat} the functions 
@@ -231,7 +231,7 @@ Add the line "($\vert{}$MathMLFormat$\vert$ . MMLFORM)"
 
 I don't see that this file is used anywhere but I made
 the appropriate changes anyway by searching for "TEX" and
-mimicing everthing for MMLFORM.
+mimicing everything for MMLFORM.
 
 \subsection{File src/doc/axiom.bib.pamphlet}
 
@@ -285,14 +285,14 @@ provide abbreviations for domains used heavily in the 
code.
 The publicly exposed functions are:
 
     \spadfun{coerce: E -$>$ S}  This function is the main one for converting
-and expression in domain OutputForm into a MathML string.
+an expression in domain OutputForm into a MathML string.
 
-    \spadfun{coerceS: E -$>$ S}  This function is for use from the command 
line.
+    \spadfun{coerceS: E -$>$ S} This function is for use from the command line.
 It converts an OutputForm expression into a MathML string and does
 some formatting so that the output is not one long line.  If you take
 the output from this function, stick it in an emacs buffer in
 nxml-mode and then indent according to mode, you'll get something that's
-nicer to look at than comes from coerce. Note that coerceS returns
+nicer to look at than what comes from coerce. Note that coerceS returns
 the same value as coerce but invokes a display function as well so that
 the result will be printed twice in different formats.  The need for this
 is that the output from coerce is automatically formatted with line breaks
@@ -377,7 +377,7 @@ MathMLFormat(): public == private where
     import List OutputForm
     import List String
 
-    -- local variables declarations and definitions
+    -- local variable declarations and definitions
 
     expr: E
     prec,opPrec: I
@@ -884,6 +884,8 @@ have to be switched by swapping names.
 
     formatSub(expr : E, args : L E, opPrec : I) : S ==
       -- This one produces differential notation partial derivatives.
+      -- It doesn't work in all cases and may not be workable, use
+      -- formatSub1 below for now.
       -- At this time this is only to handle partial derivatives.
       -- If the SUB case handles anything else I'm not aware of it.
       -- This an example of the 4th partial of y(x,z) w.r.t. x,x,z,x
@@ -1002,26 +1004,33 @@ have to be switched by swapping names.
       s := s"</mrow></msub><mo>(</mo>"
       i := 1
       while i < #posLS+1 repeat
-        tmpS := stringify args.i
+--        tmpS := stringify args.i
+       tmpS := formatMml(first args,minPrec)
+       args := rest args
        s := s"<mi>"tmpS"</mi>"
        if i < #posLS then s := s"<mo>,</mo>"
        i := i+1
       s := s"<mo>)</mo>"
 
-    formatSuperSub1(expr : E, args : L E, opPrec : I) : S ==
-      -- this produces differential notation ordinary derivatives.
+    formatSuperSub(expr : E, args : L E, opPrec : I) : S ==
+      -- this produces prime notation ordinary derivatives.
       -- first have to divine the semantics, add cases as needed
+      WriteLine$Lisp "SuperSub1 begin"
       atomE : L E := atomize(expr)      
       op : S := stringify first atomE
-      op ^= "SUPERSUB" => "<mtext>Mistake in formatSuperSub: no 
SUPERSUB</mtext>"
-      #args ^= 1 => "<mtext>Mistake in SuperSub: #args <> 1</mtext>"
+      WriteLine$Lisp "op: "op
+      op ^= "SUPERSUB" => _
+          "<mtext>Mistake in formatSuperSub: no SUPERSUB1</mtext>"
+      #args ^= 1 => "<mtext>Mistake in SuperSub1: #args <> 1</mtext>"
       var : E := first args
       -- should be looking at something like {{SUPERSUB}{var}{ }{,,...,}} for
       -- example here's the second derivative of y w.r.t. x
       -- {{{SUPERSUB}{y}{ }{,,}}{x}}, expr is the first {} and args is the
       -- {x}
       funcS : S := stringify first rest atomE
+      WriteLine$Lisp "funcS: "funcS
       bvarS : S := stringify first args
+      WriteLine$Lisp "bvarS: "bvarS
       -- count the number of commas
       commaS : S := stringify first rest rest rest atomE
       commaTest : S := ","
@@ -1030,18 +1039,22 @@ have to be switched by swapping names.
         i := i+1
        commaTest := commaTest","
       s : S := "<msup><mi>"funcS"</mi><mrow>"
+      WriteLine$Lisp "s: "s
       j : I := 0
       while j < i repeat
         s := s"<mo>&#x02032;</mo>"
        j := j + 1
-      s := 
s"</mrow></msup><mo>&#x02061;</mo><mo>(</mo><mi>"bvarS"</mi><mo>)</mo>"
+      s := s"</mrow></msup><mo>&#x02061;</mo><mo>(</mo>"formatMml(first 
args,minPrec)"<mo>)</mo>"
 
-    formatSuperSub(expr : E, args : L E, opPrec : I) : S ==
-      -- This one produces ordinary derivatives with prime notation.
+    formatSuperSub1(expr : E, args : L E, opPrec : I) : S ==
+      -- This one produces ordinary derivatives with differential notation,
+      -- it needs a little more work yet.
       -- first have to divine the semantics, add cases as needed
+      WriteLine$Lisp "SuperSub begin"
       atomE : L E := atomize(expr)      
       op : S := stringify first atomE
-      op ^= "SUPERSUB" => "<mtext>Mistake in formatSuperSub: no 
SUPERSUB</mtext>"
+      op ^= "SUPERSUB" => _
+         "<mtext>Mistake in formatSuperSub: no SUPERSUB</mtext>"
       #args ^= 1 => "<mtext>Mistake in SuperSub: #args <> 1</mtext>"
       var : E := first args
       -- should be looking at something like {{SUPERSUB}{var}{ }{,,...,}} for
@@ -1057,7 +1070,7 @@ have to be switched by swapping names.
       while position(commaTest,commaS,1) > 0 repeat
         ndiffs := ndiffs+1
        commaTest := commaTest","
-      s : S := 
"<mfrac><mrow><msup><mo>&#x02146;</mo><mn>"string(ndiffs)"</mn></msup><mi>"funcS"</mi></mrow><mrow><mo>&#x02146;</mo><msup><mi>"bvarS"</mi><mn>"string(ndiffs)"</mn></msup></mrow></mfrac><mo>&#x02061;</mo><mo>(</mo><mi>"bvarS"</mi><mo>)</mo>"
+      s : S := 
"<mfrac><mrow><msup><mo>&#x02146;</mo><mn>"string(ndiffs)"</mn></msup><mi>"funcS"</mi></mrow><mrow><mo>&#x02146;</mo><msup><mi>"formatMml(first
 
args,minPrec)"</mi><mn>"string(ndiffs)"</mn></msup></mrow></mfrac><mo>&#x02061;</mo><mo>(</mo><mi>"formatMml(first
 args,minPrec)"</mi><mo>)</mo>"
 
     formatPlex(op : S, args : L E, prec : I) : S ==
       hold : S
@@ -1191,15 +1204,31 @@ have to be switched by swapping names.
       null args => ""
       p : I := position(op,naryOps)
       p < 1 => error "unknown nary op"
-      -- need to test for "ZAG" case and divert it here, here's an
-      -- example including "op", the args list would be the rest of this
+      -- need to test for "ZAG" case and divert it here
+      -- ex 1. continuedFraction(314159/100000)
       -- {{+}{3}{{ZAG}{1}{7}}{{ZAG}{1}{15}}{{ZAG}{1}{1}}{{ZAG}{1}{25}}
       -- {{ZAG}{1}{1}}{{ZAG}{1}{7}}{{ZAG}{1}{4}}}
-      -- The first arg, the "3" in this case, could be a "ZAG" or something
+      -- this is the preconditioned output form
+      -- including "op", the args list would be the rest of this
+      -- i.e op = '+' and args = {{3}{{ZAG}{1}{7}}{{ZAG}{1}{15}}
+      -- {{ZAG}{1}{1}}{{ZAG}{1}{25}}{{ZAG}{1}{1}}{{ZAG}{1}{7}}{{ZAG}{1}{4}}}
+      -- ex 2. continuedFraction(14159/100000)
+      -- this one doesn't have the leading integer
+      -- {{+}{{ZAG}{1}{7}}{{ZAG}{1}{15}}{{ZAG}{1}{1}}{{ZAG}{1}{25}}
+      -- {{ZAG}{1}{1}}{{ZAG}{1}{7}}{{ZAG}{1}{4}}}
+      --
+      -- ex 3. continuedFraction(3,repeating [1], repeating [3,6])
+      -- {{+}{3}{{ZAG}{1}{3}}{{ZAG}{1}{6}}{{ZAG}{1}{3}}{{ZAG}{1}{6}}
+      -- {{ZAG}{1}{3}}{{ZAG}{1}{6}}{{ZAG}{1}{3}}{{ZAG}{1}{6}}
+      -- {{ZAG}{1}{3}}{{ZAG}{1}{6}}{...}}
+      -- In each of these examples the args list consists of the terms
+      -- following the '+' op
+      -- so the first arg could be a "ZAG" or something
       -- else, but the second arg looks like it has to be "ZAG", so maybe
-      -- test for #args > 1 and args.2 is "ZAG".
-      -- This test should work so long as axiom doesn't try to evaluate
-      -- the second half of the "and" when the first half is false.
+      -- test for #args > 1 and args.2 contains "ZAG".
+      -- Note that since the resulting MathML <mfrac>s are nested we need
+      -- to handle the whole continued fraction at once, i.e. we can't
+      -- just look for, e.g., {{ZAG}{1}{6}}
       (#args > 1) and (position("ZAG",stringify first rest args,1) > 0) =>
           tmpS : S := stringify first args
           position("ZAG",tmpS,1) > 0 => formatZag(args)
@@ -1224,12 +1253,18 @@ have to be switched by swapping names.
       s
 
     formatZag(args : L E) : S ==
-    -- {{ZAG}{1}{7}}
+    -- args will be a list of things like this {{ZAG}{1}{7}}, the ZAG
+    -- must be there, the '1' and '7' could conceivably be more complex
+    -- expressions
       tmpZag : L E := first args pretend L E
+      -- may want to test that tmpZag contains 'ZAG'
       #args > 1 => "<mfrac>"formatMml(first rest 
tmpZag,minPrec)"<mrow><mn>"formatMml(first rest rest 
tmpZag,minPrec)"</mn><mo>+</mo>"formatZag(rest args)"</mrow></mfrac>"
       -- EQUAL(tmpZag, "...")$Lisp => "<mo>&#x2026;</mo>"
-      (first args = "...":: E)@Boolean => "<mo>&#x2026;</mo>"
-      error "formatZag: Unexpected kind of ZAG"
+      (first args = "..."::E)@Boolean => "<mo>&#x2026;</mo>"
+      position("ZAG",stringify first args,1) > 0 =>
+          "<mfrac>"formatMml(first rest tmpZag,minPrec)formatMml(first rest 
rest tmpZag,minPrec)"</mfrac>"      
+      "<mtext>formatZag: Unexpected kind of ZAG</mtext>"
+
       
     formatZag1(args : L E) : S ==
     -- make alternative ZAG format without diminishing fonts, maybe
@@ -1285,12 +1320,23 @@ have to be switched by swapping names.
          -- where it arises.  Removed 2007-02-14
           concat(concat("<mtext>",str),"</mtext>")
        -- if we get to here does that mean it's a variable?
+       -- test for something like #\A and strip off #\
+       str.1 = char "#" and str.2 = char "\" =>
+           u : US := segment(3,len)$US
+           concat ["<mi>",str.u,"</mi>"]
         concat ["<mi>",str,"</mi>"]
       l : L E := (expr pretend L E)
       null l => blank
       op : S := stringify first l
       args : L E := rest l
       nargs : I := #args
+      -- need to test here in case first l is SUPERSUB case and then
+      -- pass first l and args to formatSuperSub.
+      position("SUPERSUB",op,1) > 0 =>
+        formatSuperSub(first l,args,minPrec)
+      -- now test for SUB
+      position("SUB",op,1) > 0 =>
+        formatSub1(first l,args,minPrec)
 
       -- special cases
       member?(op, specialOps) => formatSpecial(op,args,prec)
@@ -1310,13 +1356,6 @@ have to be switched by swapping names.
       -- nary case
       member?(op,naryNGOps) => formatNaryNoGroup(op,args, prec)
       member?(op,naryOps) => formatNary(op,args, prec)
-      -- need to test here in case first l is SUPERSUB case and then
-      -- pass first l and args to formatSuperSub.
-      position("SUPERSUB",op,1) > 0 =>
-        formatSuperSub(first l,args,minPrec)
-      -- now test for SUB
-      position("SUB",op,1) > 0 =>
-        formatSub(first l,args,minPrec)
 
       op := formatMml(first l,minPrec)
       formatFunction(op,args,prec)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]