On 05.03.21 14:25, Waldek Hebisch wrote:
> On Thu, Mar 04, 2021 at 05:02:41PM +0100, Ralf Hemmecke wrote:
>>>> Third, is it a bug that compile TMFORM requires so much RAM?
>>>> We should look into it to see if RAM usage can be reduced.
>>>
>>> AFAICS RAM usage during compilation of TMFORM is really sbcl
>>> bug.  It seem that the problem is the same as AWAIC.
>>> Namely, we need to initialise a table and at Lisp level
>>> it is longish segment of code with calls but no jump.
>>
>> Are we talking about TexmacsFormat?
>>
>> The only long list is for CorkFunc. But that is a list of records. What
>> can be difficult for that to be compiled in Lisp?
> 
> Just one explanation: Spad data is mutable.  Lisp constant
> data is immutable, so Spad _have to_ translate list for CorkFunc
> as a sequence of calls to 'construct'.  This is 794 calls,
> not very large number and _should_ not be problem for Lisp
> compiler.  But apparently it is.

First of all, I actually do not understand why this Cork stuff is in
texmacs.spad at all. FriCAS does not generate any Unicode data.
The only way unicode can appear is inside a String. This is what
texmacs.spad takes care of. Obviously, the Texmacs people seem to use
mathematical symbols in strings when working with FriCAS. What I do not
quite understand is why TexmacsFormat has to do that this translation
from unicode encoding to Texmacs encoding. I would have guessed that
Texmacs itself is able to do this conversion.

Anyway, attached you find a modified texmacs.spad, where I simply
translated the List(Record(key:SI, entry:String)) into a simple
List(String) and constructed the respective HashTable from that list.
On my laptop, the compilation if that texmacs.spad is more or less
instant, at least it takes a few seconds less than the texmacs.spad that
is currently in the repository. Presumably, it takes also less RAM, but
I don't know how to check that.

> AWAIC produces more than

Sorry, what is AWAIC?

>> Maybe it helps to list
>> the data as a list of lists and do the construction a bit differently.
> 
> AFAICS there is no reasonable workaround at Spad level...

I wonder whether my attempt might work.

Ralf

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ba6ca17a-5f5a-5449-003e-bce0255eb29b%40hemmecke.org.
)if false
TexmacsFormat is a package to produce output as the
special scheme code for TeXmacs.

About this module
The most of this code were copy-n-pasted from MathML format package. Although I
am going to make stand alone fully-functional TeXmacs package I've left many
comments about the code untouched in order to understand the code quicker. They
will be removed as soon as they won't be needed.

The testing is made using {\tt of.input} test file.

)endif

)abbrev domain TMFORM TexmacsFormat
++ Author: Alexander D. Solovets
++ Date: October 2010
++ This package is based on the MathMLFormat domain by Arthur C. Ralfs
++ without which I wouldn't have known where to start.
++ Basic Operations: coerce, coerceL, display
++ Description:
++    \spadtype{TexmacsFormat} provides a coercion from \spadtype{OutputForm}
++    to TeXmacs format.

TexmacsFormat() : public == private where
  E      ==> OutputForm
  I      ==> Integer
  SI     ==> SingleInteger
  L      ==> List
  S      ==> String
  Sy     ==> Symbol
  US     ==> UniversalSegment(Integer)

  public == SetCategory with
    coerce :    E -> S
      ++ coerce(o) changes o in the standard output format to Texmacs
      ++ format.
    coerceL :   E -> S
      ++ coerceL(o) changes o in the standard output format to Texmacs
      ++ format and displays result as one long string.
    display :   S -> Void
      ++ prints the string returned by coerce, adding <math ...> tags.

  private == add
    import from OutputForm
    import from Character
    import from Integer
    import from List OutputForm
    import from List String
    import from OutputFormTools

    -- local variable declarations and definitions

    corkHash(): HashTable(SI, String, "EQ") ==
      -- the key is unicode, and the entry is corkcode
      corkList: List String := [_
        "60","<less>", _
        "62","<gtr>", _
        "160","<varspace>", _
        "162","<cent>", _
        "163","<sterling>", _
        "164","<currency>", _
        "165","<yen>", _
        "166","<brokenvert>", _
        "169","<copyright>", _
        "170","<ordfeminine>", _
        "171","<guillemotleft>", _
        "172","<neg>", _
        "173","<hyphen>", _
        "174","<circledR>", _
        "176","<degree>", _
        "177","<pm>", _
        "178","<twosuperior>", _
        "179","<threesuperior>", _
        "181","<mu>", _
        "182","<paragraph>", _
        "183","<centerdot>", _
        "185","<onesuperior>", _
        "186","<masculine>", _
        "188","<onequarter>", _
        "189","<onehalf>", _
        "190","<threequarters>", _
        "215","<times>", _
        "247","<div>", _
        "8209","<nbhyph>", _
        "8214","<||>", _
        "8224","<dagger>", _
        "8225","<ddagger>", _
        "8226","<bullet>", _
        "8230","...", _
        "8242","<prime>", _
        "8245","<backprime>", _
        "8450","<bbb-C>", _
        "8458","<cal-g>", _
        "8459","<cal-H>", _
        "8460","<frak-H>", _
        "8461","<bbb-H>", _
        "8463","<hslash>", _
        "8464","<cal-I>", _
        "8465","<frak-I>", _
        "8466","<cal-L>", _
        "8467","<ell>", _
        "8469","<bbb-N>", _
        "8472","<wp>", _
        "8473","<bbb-P>", _
        "8474","<bbb-Q>", _
        "8475","<cal-R>", _
        "8476","<frak-R>", _
        "8477","<bbb-R>", _
        "8482","<trademark>", _
        "8484","<bbb-Z>", _
        "8487","<Mho>", _
        "8488","<frak-Z>", _
        "8492","<cal-B>", _
        "8493","<frak-C>", _
        "8495","<cal-e>", _
        "8496","<cal-E>", _
        "8497","<cal-F>", _
        "8499","<cal-M>", _
        "8500","<cal-o>", _
        "8501","<aleph>", _
        "8502","<beth>", _
        "8503","<gimel>", _
        "8504","<daleth>", _
        "8592","<leftarrow>", _
        "8593","<uparrow>", _
        "8594","<rightarrow>", _
        "8595","<downarrow>", _
        "8596","<leftrightarrow>", _
        "8597","<updownarrow>", _
        "8598","<nwarrow>", _
        "8599","<nearrow>", _
        "8600","<searrow>", _
        "8601","<swarrow>", _
        "8602","<nleftarrow>", _
        "8603","<nrightarrow>", _
        "8604","<leftsquigarrow>", _
        "8605","<rightsquigarrow>", _
        "8606","<twoheadleftarrow>", _
        "8608","<twoheadrightarrow>", _
        "8610","<leftarrowtail>", _
        "8611","<rightarrowtail>", _
        "8612","<mapsfrom>", _
        "8614","<mapsto>", _
        "8617","<hookleftarrow>", _
        "8618","<hookrightarrow>", _
        "8619","<looparrowleft>", _
        "8620","<looparrowright>", _
        "8621","<leftrightsquigarrow>", _
        "8622","<nleftrightarrow>", _
        "8623","<lightning>", _
        "8624","<Lsh>", _
        "8625","<Rsh>", _
        "8630","<curvearrowleft>", _
        "8631","<curvearrowright>", _
        "8634","<circlearrowleft>", _
        "8635","<circlearrowright>", _
        "8636","<leftharpoonup>", _
        "8637","<leftharpoondown>", _
        "8638","<upharpoonright>", _
        "8639","<upharpoonleft>", _
        "8640","<rightharpoonup>", _
        "8641","<rightharpoondown>", _
        "8642","<downharpoonright>", _
        "8643","<downharpoonleft>", _
        "8644","<rightleftarrows>", _
        "8646","<leftrightarrows>", _
        "8647","<leftleftarrows>", _
        "8648","<upuparrows>", _
        "8649","<rightrightarrows>", _
        "8650","<downdownarrows>", _
        "8651","<leftrightharpoons>", _
        "8652","<rightleftharpoons>", _
        "8653","<nLeftarrow>", _
        "8654","<nLeftrightarrow>", _
        "8655","<nRightarrow>", _
        "8656","<Leftarrow>", _
        "8657","<Uparrow>", _
        "8658","<Rightarrow>", _
        "8659","<Downarrow>", _
        "8660","<Leftrightarrow>", _
        "8661","<Updownarrow>", _
        "8666","<Lleftarrow>", _
        "8667","<Rrightarrow>", _
        "8704","<forall>", _
        "8705","<complement>", _
        "8706","<partial>", _
        "8707","<exists>", _
        "8708","<nexists>", _
        "8709","<emptyset>", _
        "8711","<nabla>", _
        "8712","<in>", _
        "8713","<nin>", _
        "8715","<ni>", _
        "8716","<nni>", _
        "8719","<big-prod>", _
        "8720","<big-amalg>", _
        "8721","<big-sum>", _
        "8722","<minus>", _
        "8723","<mp>", _
        "8724","<dotplus>", _
        "8726","<setminus>", _
        "8727","<ast>", _
        "8728","<circ>", _
        "8730","<sqrt>", _
        "8733","<propto>", _
        "8734","<infty>", _
        "8736","<angle>", _
        "8737","<measuredangle>", _
        "8738","<sphericalangle>", _
        "8739","<mid>", _
        "8740","<nmid>", _
        "8741","<parallel>", _
        "8742","<nparallel>", _
        "8743","<wedge>", _
        "8744","<vee>", _
        "8745","<cap>", _
        "8746","<cup>", _
        "8747","<big-int>", _
        "8750","<big-oint>", _
        "8756","<therefore>", _
        "8757","<because>", _
        "8764","<sim>", _
        "8765","<backsim>", _
        "8768","<wr>", _
        "8769","<nsim>", _
        "8770","<eqsim>", _
        "8771","<simeq>", _
        "8772","<nsimeq>", _
        "8773","<cong>", _
        "8775","<ncong>", _
        "8776","<approx>", _
        "8777","<napprox>", _
        "8778","<approxeq>", _
        "8781","<asymp>", _
        "8782","<Bumpeq>", _
        "8783","<bumpeq>", _
        "8784","<doteq>", _
        "8785","<doteqdot>", _
        "8786","<fallingdoteq>", _
        "8787","<risingdoteq>", _
        "8788","<assign>", _
        "8790","<eqcirc>", _
        "8791","<circeq>", _
        "8796","<triangleq>", _
        "8800","<neq>", _
        "8801","<equiv>", _
        "8802","<nequiv>", _
        "8804","<leq>", _
        "8805","<geq>", _
        "8806","<leqq>", _
        "8807","<geqq>", _
        "8808","<lneqq>", _
        "8809","<gneqq>", _
        "8810","<ll>", _
        "8811","<gg>", _
        "8812","<between>", _
        "8813","<nasymp>", _
        "8814","<nless>", _
        "8815","<ngtr>", _
        "8816","<nleq>", _
        "8817","<ngeq>", _
        "8818","<lesssim>", _
        "8819","<gtrsim>", _
        "8822","<lessgtr>", _
        "8823","<gtrless>", _
        "8826","<prec>", _
        "8827","<succ>", _
        "8828","<preccurlyeq>", _
        "8829","<succcurlyeq>", _
        "8830","<precsim>", _
        "8831","<succsim>", _
        "8832","<nprec>", _
        "8833","<nsucc>", _
        "8834","<subset>", _
        "8835","<supset>", _
        "8836","<nsubset>", _
        "8837","<nsupset>", _
        "8838","<subseteq>", _
        "8839","<supseteq>", _
        "8840","<nsubseteq>", _
        "8841","<nsupseteq>", _
        "8842","<subsetneq>", _
        "8843","<supsetneq>", _
        "8846","<uplus>", _
        "8847","<sqsubset>", _
        "8848","<sqsupset>", _
        "8849","<sqsubseteq>", _
        "8850","<sqsupseteq>", _
        "8851","<sqcap>", _
        "8852","<sqcup>", _
        "8853","<varoplus>", _
        "8854","<varominus>", _
        "8855","<varotimes>", _
        "8856","<varoslash>", _
        "8857","<varodot>", _
        "8858","<varocircle>", _
        "8859","<varoast>", _
        "8861","<circleddash>", _
        "8862","<boxplus>", _
        "8863","<boxminus>", _
        "8864","<boxtimes>", _
        "8865","<boxdot>", _
        "8866","<vdash>", _
        "8867","<dashv>", _
        "8868","<top>", _
        "8869","<bot>", _
        "8871","<models>", _
        "8872","<vDash>", _
        "8873","<Vdash>", _
        "8874","<Vvdash>", _
        "8876","<nvdash>", _
        "8877","<nvDash>", _
        "8878","<nVdash>", _
        "8879","<nVDash>", _
        "8882","<vartriangleleft>", _
        "8883","<vartriangleright>", _
        "8884","<trianglelefteq>", _
        "8885","<trianglerighteq>", _
        "8888","<multimap>", _
        "8890","<intercal>", _
        "8891","<veebar>", _
        "8896","<big-wedge>", _
        "8897","<big-vee>", _
        "8898","<big-cap>", _
        "8899","<big-cup>", _
        "8900","<diamond>", _
        "8901","<cdot>", _
        "8902","<star>", _
        "8903","<divideontimes>", _
        "8904","<join>", _
        "8905","<ltimes>", _
        "8906","<rtimes>", _
        "8907","<leftthreetimes>", _
        "8908","<rightthreetimes>", _
        "8909","<backsimeq>", _
        "8910","<curlyvee>", _
        "8911","<curlywedge>", _
        "8912","<Subset>", _
        "8913","<Supset>", _
        "8914","<Cap>", _
        "8915","<Cup>", _
        "8916","<pitchfork>", _
        "8918","<lessdot>", _
        "8919","<gtrdot>", _
        "8920","<lll>", _
        "8921","<ggg>", _
        "8922","<lesseqgtr>", _
        "8923","<gtreqless>", _
        "8926","<curlyeqprec>", _
        "8927","<curlyeqsucc>", _
        "8928","<npreccurlyeq>", _
        "8929","<nsucccurlyeq>", _
        "8930","<nsqsubseteq>", _
        "8931","<nsqsupseteq>", _
        "8934","<lnsim>", _
        "8935","<gnsim>", _
        "8936","<precnsim>", _
        "8937","<succnsim>", _
        "8938","<ntriangleleft>", _
        "8939","<ntriangleright>", _
        "8940","<ntrianglelefteq>", _
        "8941","<ntrianglerighteq>", _
        "8942","<vdots>", _
        "8943","<cdots>", _
        "8944","<udots>", _
        "8945","<ddots>", _
        "8960","<diameter>", _
        "8965","<barwedge>", _
        "8966","<doublebarwedge>", _
        "8968","<lceil>", _
        "8969","<rceil>", _
        "8970","<lfloor>", _
        "8971","<rfloor>", _
        "8976","<invneg>", _
        "8981","<recorder>", _
        "8988","<ulcorner>", _
        "8989","<urcorner>", _
        "8990","<llcorner>", _
        "8991","<lrcorner>", _
        "8994","<frown>", _
        "8995","<smile>", _
        "9016","<talloblong>", _
        "9031","<APLleftarrowbox>", _
        "9032","<APLrightarrowbox>", _
        "9040","<APLuparrowbox>", _
        "9047","<APLdownarrowbox>", _
        "9054","<APLinput>", _
        "9109","<APLbox>", _
        "9416","<circledS>", _
        "9632","<blacksquare>", _
        "9633","<Square>", _
        "9647","<oblong>", _
        "9651","<bigtriangleup>", _
        "9652","<blacktriangle>", _
        "9653","<vartriangle>", _
        "9656","<blacktriangleright>", _
        "9657","<triangleright>", _
        "9661","<bigtriangledown>", _
        "9662","<blacktriangledown>", _
        "9663","<triangledown>", _
        "9666","<blacktriangleleft>", _
        "9667","<triangleleft>", _
        "9671","<wasyDiamond>", _
        "9674","<lozenge>", _
        "9675","<Circle>", _
        "9679","<CIRCLE>", _
        "9680","<LEFTcircle>", _
        "9681","<RIGHTcircle>", _
        "9686","<LEFTCIRCLE>", _
        "9687","<RIGHTCIRCLE>", _
        "9711","<varbigcirc>", _
        "9725","<square>", _
        "9733","<bigstar>", _
        "9737","<astrosun>", _
        "9738","<ascnode>", _
        "9739","<descnode>", _
        "9740","<conjunction>", _
        "9741","<opposition>", _
        "9742","<phone>", _
        "9745","<XBox>", _
        "9746","<CheckedBox>", _
        "9785","<frownie>", _
        "9786","<smiley>", _
        "9787","<blacksmiley>", _
        "9788","<sun>", _
        "9789","<rightmoon>", _
        "9790","<leftmoon>", _
        "9791","<mercury>", _
        "9792","<female>", _
        "9793","<earth>", _
        "9794","<male>", _
        "9795","<jupiter>", _
        "9796","<saturn>", _
        "9797","<uranus>", _
        "9798","<neptune>", _
        "9799","<pluto>", _
        "9800","<aries>", _
        "9801","<taurus>", _
        "9802","<gemini>", _
        "9803","<cancer>", _
        "9804","<leo>", _
        "9805","<virgo>", _
        "9806","<libra>", _
        "9807","<scorpio>", _
        "9808","<sagittarius>", _
        "9809","<capricornus>", _
        "9810","<aquarius>", _
        "9811","<pisces>", _
        "9824","<spadesuit>", _
        "9827","<clubsuit>", _
        "9829","<heartsuit>", _
        "9830","<diamondsuit>", _
        "9833","<quarternote>", _
        "9834","<eighthnote>", _
        "9835","<twonotes>", _
        "9837","<flat>", _
        "9838","<natural>", _
        "9839","<sharp>", _
        "10003","<checkmark>", _
        "913","<Alpha>", _
        "914","<Beta>", _
        "915","<Gamma>", _
        "916","<Delta>", _
        "917","<Epsilon>", _
        "918","<Zeta>", _
        "919","<Eta>", _
        "920","<Theta>", _
        "921","<Iota>", _
        "922","<Kappa>", _
        "923","<Lambda>", _
        "924","<Mu>", _
        "925","<Nu>", _
        "926","<Xi>", _
        "927","<Omicron>", _
        "928","<Pi>", _
        "929","<Rho>", _
        "931","<Sigma>", _
        "932","<Tau>", _
        "933","<Upsilon>", _
        "934","<Phi>", _
        "935","<Chi>", _
        "936","<Psi>", _
        "937","<Omega>", _
        "945","<alpha>", _
        "946","<beta>", _
        "947","<gamma>", _
        "948","<delta>", _
        "949","<varepsilon>", _
        "950","<zeta>", _
        "951","<eta>", _
        "952","<theta>", _
        "953","<iota>", _
        "954","<kappa>", _
        "955","<lambda>", _
        "956","<mu>", _
        "957","<nu>", _
        "958","<xi>", _
        "959","<omicron>", _
        "960","<pi>", _
        "961","<rho>", _
        "962","<varsigma>", _
        "963","<sigma>", _
        "964","<tau>", _
        "965","<upsilon>", _
        "966","<varphi>", _
        "967","<chi>", _
        "968","<psi>", _
        "969","<omega>", _
        "977","<vartheta>", _
        "981","<phi>", _
        "982","<varpi>", _
        "989","<digamma>", _
        "1008","<varkappa>", _
        "1009","<varrho>", _
        "1013","<epsilon>", _
        "65309","<longequal>", _
        "119808","<b-up-A>", _
        "119809","<b-up-B>", _
        "119810","<b-up-C>", _
        "119811","<b-up-D>", _
        "119812","<b-up-E>", _
        "119813","<b-up-F>", _
        "119814","<b-up-G>", _
        "119815","<b-up-H>", _
        "119816","<b-up-I>", _
        "119817","<b-up-J>", _
        "119818","<b-up-K>", _
        "119819","<b-up-L>", _
        "119820","<b-up-M>", _
        "119821","<b-up-N>", _
        "119822","<b-up-O>", _
        "119823","<b-up-P>", _
        "119824","<b-up-Q>", _
        "119825","<b-up-R>", _
        "119826","<b-up-S>", _
        "119827","<b-up-T>", _
        "119828","<b-up-U>", _
        "119829","<b-up-V>", _
        "119830","<b-up-W>", _
        "119831","<b-up-X>", _
        "119832","<b-up-Y>", _
        "119833","<b-up-Z>", _
        "119834","<b-up-a>", _
        "119835","<b-up-b>", _
        "119836","<b-up-c>", _
        "119837","<b-up-d>", _
        "119838","<b-up-e>", _
        "119839","<b-up-f>", _
        "119840","<b-up-g>", _
        "119841","<b-up-h>", _
        "119842","<b-up-i>", _
        "119843","<b-up-j>", _
        "119844","<b-up-k>", _
        "119845","<b-up-l>", _
        "119846","<b-up-m>", _
        "119847","<b-up-n>", _
        "119848","<b-up-o>", _
        "119849","<b-up-p>", _
        "119850","<b-up-q>", _
        "119851","<b-up-r>", _
        "119852","<b-up-s>", _
        "119853","<b-up-t>", _
        "119854","<b-up-u>", _
        "119855","<b-up-v>", _
        "119856","<b-up-w>", _
        "119857","<b-up-x>", _
        "119858","<b-up-y>", _
        "119859","<b-up-z>", _
        "119912","<b-A>", _
        "119913","<b-B>", _
        "119914","<b-C>", _
        "119915","<b-D>", _
        "119916","<b-E>", _
        "119917","<b-F>", _
        "119918","<b-G>", _
        "119919","<b-H>", _
        "119920","<b-I>", _
        "119921","<b-J>", _
        "119922","<b-K>", _
        "119923","<b-L>", _
        "119924","<b-M>", _
        "119925","<b-N>", _
        "119926","<b-O>", _
        "119927","<b-P>", _
        "119928","<b-Q>", _
        "119929","<b-R>", _
        "119930","<b-S>", _
        "119931","<b-T>", _
        "119932","<b-U>", _
        "119933","<b-V>", _
        "119934","<b-W>", _
        "119935","<b-X>", _
        "119936","<b-Y>", _
        "119937","<b-Z>", _
        "119938","<b-a>", _
        "119939","<b-b>", _
        "119940","<b-c>", _
        "119941","<b-d>", _
        "119942","<b-e>", _
        "119943","<b-f>", _
        "119944","<b-g>", _
        "119945","<b-h>", _
        "119946","<b-i>", _
        "119947","<b-j>", _
        "119948","<b-k>", _
        "119949","<b-l>", _
        "119950","<b-m>", _
        "119951","<b-n>", _
        "119952","<b-o>", _
        "119953","<b-p>", _
        "119954","<b-q>", _
        "119955","<b-r>", _
        "119956","<b-s>", _
        "119957","<b-t>", _
        "119958","<b-u>", _
        "119959","<b-v>", _
        "119960","<b-w>", _
        "119961","<b-x>", _
        "119962","<b-y>", _
        "119963","<b-z>", _
        "119964","<cal-A>", _
        "119966","<cal-C>", _
        "119967","<cal-D>", _
        "119970","<cal-G>", _
        "119973","<cal-J>", _
        "119974","<cal-K>", _
        "119977","<cal-N>", _
        "119978","<cal-O>", _
        "119979","<cal-P>", _
        "119980","<cal-Q>", _
        "119982","<cal-S>", _
        "119983","<cal-T>", _
        "119984","<cal-U>", _
        "119985","<cal-V>", _
        "119986","<cal-W>", _
        "119987","<cal-X>", _
        "119988","<cal-Y>", _
        "119989","<cal-Z>", _
        "119990","<cal-a>", _
        "119991","<cal-b>", _
        "119992","<cal-c>", _
        "119993","<cal-d>", _
        "119995","<cal-f>", _
        "119997","<cal-h>", _
        "119998","<cal-i>", _
        "119999","<cal-j>", _
        "120000","<cal-k>", _
        "120001","<cal-l>", _
        "120002","<cal-m>", _
        "120003","<cal-n>", _
        "120005","<cal-p>", _
        "120006","<cal-q>", _
        "120007","<cal-r>", _
        "120008","<cal-s>", _
        "120009","<cal-t>", _
        "120010","<cal-u>", _
        "120011","<cal-v>", _
        "120012","<cal-w>", _
        "120013","<cal-x>", _
        "120014","<cal-y>", _
        "120015","<cal-z>", _
        "120068","<frak-A>", _
        "120069","<frak-B>", _
        "120071","<frak-D>", _
        "120072","<frak-E>", _
        "120073","<frak-F>", _
        "120074","<frak-G>", _
        "120077","<frak-J>", _
        "120078","<frak-K>", _
        "120079","<frak-L>", _
        "120080","<frak-M>", _
        "120081","<frak-N>", _
        "120082","<frak-O>", _
        "120083","<frak-P>", _
        "120084","<frak-Q>", _
        "120086","<frak-S>", _
        "120087","<frak-T>", _
        "120088","<frak-U>", _
        "120089","<frak-V>", _
        "120090","<frak-W>", _
        "120091","<frak-X>", _
        "120092","<frak-Y>", _
        "120094","<frak-a>", _
        "120095","<frak-b>", _
        "120096","<frak-c>", _
        "120097","<frak-d>", _
        "120098","<frak-e>", _
        "120099","<frak-f>", _
        "120100","<frak-g>", _
        "120101","<frak-h>", _
        "120102","<frak-i>", _
        "120103","<frak-j>", _
        "120104","<frak-k>", _
        "120105","<frak-l>", _
        "120106","<frak-m>", _
        "120107","<frak-n>", _
        "120108","<frak-o>", _
        "120109","<frak-p>", _
        "120110","<frak-q>", _
        "120111","<frak-r>", _
        "120112","<frak-s>", _
        "120113","<frak-t>", _
        "120114","<frak-u>", _
        "120115","<frak-v>", _
        "120116","<frak-w>", _
        "120117","<frak-x>", _
        "120118","<frak-y>", _
        "120119","<frak-z>", _
        "120120","<bbb-A>", _
        "120121","<bbb-B>", _
        "120123","<bbb-D>", _
        "120124","<bbb-E>", _
        "120125","<bbb-F>", _
        "120126","<bbb-G>", _
        "120128","<bbb-I>", _
        "120129","<bbb-J>", _
        "120130","<bbb-K>", _
        "120131","<bbb-L>", _
        "120132","<bbb-M>", _
        "120134","<bbb-O>", _
        "120138","<bbb-S>", _
        "120139","<bbb-T>", _
        "120140","<bbb-U>", _
        "120141","<bbb-V>", _
        "120142","<bbb-W>", _
        "120143","<bbb-X>", _
        "120144","<bbb-Y>", _
        "120146","<bbb-a>", _
        "120147","<bbb-b>", _
        "120148","<bbb-c>", _
        "120149","<bbb-d>", _
        "120150","<bbb-e>", _
        "120151","<bbb-f>", _
        "120152","<bbb-g>", _
        "120153","<bbb-h>", _
        "120154","<bbb-i>", _
        "120155","<bbb-j>", _
        "120156","<bbb-k>", _
        "120157","<bbb-l>", _
        "120158","<bbb-m>", _
        "120159","<bbb-n>", _
        "120160","<bbb-o>", _
        "120161","<bbb-p>", _
        "120162","<bbb-q>", _
        "120163","<bbb-r>", _
        "120164","<bbb-s>", _
        "120165","<bbb-t>", _
        "120166","<bbb-u>", _
        "120167","<bbb-v>", _
        "120168","<bbb-w>", _
        "120169","<bbb-x>", _
        "120170","<bbb-y>", _
        "120171","<bbb-z>", _
        "120488","<b-Alpha>", _
        "120489","<b-Beta>", _
        "120490","<b-Gamma>", _
        "120491","<b-Delta>", _
        "120492","<b-Epsilon>", _
        "120493","<b-Zeta>", _
        "120494","<b-Eta>", _
        "120495","<b-Theta>", _
        "120496","<b-Iota>", _
        "120497","<b-Kappa>", _
        "120498","<b-Lambda>", _
        "120499","<b-Mu>", _
        "120500","<b-Nu>", _
        "120501","<b-Xi>", _
        "120502","<b-Omicron>", _
        "120503","<b-Pi>", _
        "120504","<b-Rho>", _
        "120506","<b-Sigma>", _
        "120507","<b-Tau>", _
        "120508","<b-Upsilon>", _
        "120509","<b-Phi>", _
        "120510","<b-Chi>", _
        "120511","<b-Psi>", _
        "120512","<b-Omega>", _
        "120514","<b-up-alpha>", _
        "120515","<b-up-beta>", _
        "120516","<b-up-gamma>", _
        "120517","<b-up-delta>", _
        "120518","<b-up-varepsilon>", _
        "120519","<b-up-zeta>", _
        "120520","<b-up-eta>", _
        "120521","<b-up-theta>", _
        "120522","<b-up-iota>", _
        "120523","<b-up-kappa>", _
        "120524","<b-up-lambda>", _
        "120525","<b-up-mu>", _
        "120526","<b-up-nu>", _
        "120527","<b-up-xi>", _
        "120528","<b-up-omicron>", _
        "120529","<b-up-pi>", _
        "120530","<b-up-rho>", _
        "120531","<b-up-varsigma>", _
        "120532","<b-up-sigma>", _
        "120533","<b-up-tau>", _
        "120534","<b-up-upsilon>", _
        "120535","<b-up-varphi>", _
        "120536","<b-up-chi>", _
        "120537","<b-up-psi>", _
        "120538","<b-up-omega>", _
        "120540","<b-up-epsilon>", _
        "120541","<b-up-vartheta>", _
        "120542","<b-up-varkappa>", _
        "120543","<b-up-phi>", _
        "120544","<b-up-varrho>", _
        "120545","<b-up-varpi>", _
        "120630","<b-alpha>", _
        "120631","<b-beta>", _
        "120632","<b-gamma>", _
        "120633","<b-delta>", _
        "120634","<b-varepsilon>", _
        "120635","<b-zeta>", _
        "120636","<b-eta>", _
        "120637","<b-theta>", _
        "120638","<b-iota>", _
        "120639","<b-kappa>", _
        "120640","<b-lambda>", _
        "120641","<b-mu>", _
        "120642","<b-nu>", _
        "120643","<b-xi>", _
        "120644","<b-omicron>", _
        "120645","<b-pi>", _
        "120646","<b-rho>", _
        "120647","<b-varsigma>", _
        "120648","<b-sigma>", _
        "120649","<b-tau>", _
        "120650","<b-upsilon>", _
        "120651","<b-varphi>", _
        "120652","<b-chi>", _
        "120653","<b-psi>", _
        "120654","<b-omega>", _
        "120656","<b-epsilon>", _
        "120657","<b-vartheta>", _
        "120658","<b-varkappa>", _
        "120659","<b-phi>", _
        "120660","<b-varrho>", _
        "120661","<b-varpi>", _
        "120782","<b-0>", _
        "120783","<b-1>", _
        "120784","<b-2>", _
        "120785","<b-3>", _
        "120786","<b-4>", _
        "120787","<b-5>", _
        "120788","<b-6>", _
        "120789","<b-7>", _
        "120790","<b-8>", _
        "120791","<b-9>"]
      h: HashTable(SI, String, "EQ") := empty()
      while not empty? corkList repeat
        i: Integer := parse_integer(first corkList)$ScanningUtilities
        corkList := rest corkList
        qsetelt!(h, i::SingleInteger, first corkList)
        corkList := rest corkList
      return h

    Cork : HashTable(SI, String, "EQ") := corkHash()

    expr : E
    prec, opPrec : I
    str :  S
    blank         : S := " \  "

    maxPrec       : I   := 1000000
    minPrec       : I   := 0

    unaryOps      : L Sy := ["-"::Sy]$(L Sy)
    unaryPrecs    : L I := [710]$(L I)

    -- the precedence of / in the following is relatively low because
    -- the bar obviates the need for parentheses.
    binaryOps     : L Sy := ["+->"::Sy, "|"::Sy, "^"::Sy, "/"::Sy, "="::Sy,
                             "~="::Sy, "<"::Sy, "<="::Sy, ">"::Sy, ">="::Sy,
                               'OVER, 'LET]
    binaryPrecs   : L I := [0, 0, 900, 700, 400,
                            400, 400, 400, 400, 400,
                              700, 125]$(L I)

    naryOps       : L Sy := ["-"::Sy, "+"::Sy, "*"::Sy, ","::Sy, ";"::Sy,
                             'ROW, 'STRSEP, 'TENSOR]
    naryPrecs     : L I := [700, 700, 800, 110, 110,
                            0, 0, 850]$(L I)
    naryNGOps     : L Sy := ['ROW]

    plexOps       : L Sy := ['SIGMA, 'SIGMA2, 'PI, 'PI2, 'INTSIGN]
    plexPrecs     : L I := [ 750, 750, 750, 750, 700]$(L I)

    specialOps    : L Sy := ['MATRIX, 'BRACKET, 'BRACE, 'CONCATB, 'VCONCAT,  _
                             'AGGLST, 'CONCAT, 'OVERBAR, 'ROOT, 'SUB, 'TAG, _
                             'SUPERSUB, 'ZAG, 'AGGSET, 'SC, 'PAREN, _
                             'SEGMENT, 'QUOTE, 'theMap, 'SLASH, 'PRIME, _
                             'BOX, 'EQUATNUM, 'BINOMIAL, 'NOTHING]

    -- the next two lists provide translations for some strings for
    -- which MML provides special macros.

    specialStrings : L Sy :=
      ['cos, 'cot, 'csc, 'log, 'sec, 'sin, 'tan,
        'cosh, 'coth, 'csch, 'sech, 'sinh, 'tanh,
          'acos, 'asin, 'atan, 'erf, "..."::Sy, "$"::Sy, 'infinity,
            'Gamma]
    specialStringsInMML : L S :=
      ["_"cos_"","_"cot_"","_"csc_"","_"log_"","_"sec_"","_"sin_"","_"tan_"",
        "_"cosh_"","_"coth_"","_"csch_"","_"sech_"","_"sinh_"","_"tanh_"",
          "_"arccos_"","_"arcsin_"","_"arctan_"","_"erf_"","_"<cdots>_"","_"$_"","_"<infty>_"","_"<Gamma>_""]

    -- local function signatures

    addBraces :      S -> S
    addBrackets :    S -> S
    group :          S -> S
    cork :           SI -> S
    utf2cork :       S -> S
    formatBinary :   (Sy, L E, I) -> S
    formatFunction : (E, L E, I) -> S
    formatIntBody :  (E, I) -> S
    formatMatrix :   L E -> S
    formatNary :     (Sy, S, I, L E, I) -> S
    formatNaryNoGroup : (Sy, S, I, L E, I) -> S
    formatNullary :  Sy -> S
    formatPlex :     (Sy, L E, I) -> S
    formatSpecial :  (Sy, L E, I) -> S
    formatUnary :    (Sy, E, I) -> S
    formatExpr :      (E, I) -> S

    formatZag :      L E -> S
    formatZag1 :     L E -> S
    newWithNum :     I -> %
    parenthesize :   S -> S
    postcondition :  S -> S
    ungroup :        S -> S

    -- public function definitions

    coerce(expr : E) : S ==
      s : S := postcondition formatExpr(precondition expr, minPrec)
      s

    sayExpr(s : S) : Void ==
        sayTexmacs$Lisp s

    coerceL(expr : E) : S ==
        s : S := postcondition formatExpr(precondition expr, minPrec)
        sayExpr "scheme: (with _"mode_" _"math_""
        sayExpr s
        sayExpr ")"
        s

    display(texmacs : S) : Void ==
        sayExpr "scheme: (with _"mode_" _"math_""
        sayExpr texmacs
        sayExpr ")"
        void()$Void

    ungroup(str : S) : S ==
        -- not really correct, but should not matter
        str

    postcondition(str : S) : S ==
--      str := ungroup str
      len : I := #str
      plusminus : S := "_"+_" (concat _"-_""
      pos : I := position(plusminus, str, 1)
      if pos > 0 then
        ustart : US := segment(1, pos-1)$US
        uend : US := segment(pos+15, len)$US
        str := concat [str.ustart,"(concat _"-_"",str.uend]
        if pos < len-13 then
          str := postcondition(str)
      str



    optionalWrap(s : S, expr : E, prec : I) : S ==
        tmp : S := formatExpr(expr, prec)
        tmp = "" or tmp = " " => ""
        concat ["(", s, " ", tmp, ")"]

    group str ==
      concat ["(concat ",str,")"]

    import from NumberFormats
    cork(x) ==
      res := search(x, Cork)
      res case "failed" =>
         if (x > 1000) then  -- the range of Unicode that TeXmacs can't handle
             s := FormatRadix(x, 16)
             concat ["\<#", s, "\>"]
         else
             ucodeToString(x::Integer)
      res::String

    utf2cork str ==
      concat [cork i for i in uentries str]

    addBraces str ==
      concat [" _"{_" ",str," _"}_" "]

    addBrackets str ==
      concat [" _"[_" ",str," _"]_" "]

    parenthesize str ==
      concat [" _"(_" ",str," _")_" "]

    formatSpecial(op : Sy, args : L E, prec : I) : S ==
        arg : E
        prescript : Boolean := false
        op = 'theMap => "(concat _"theMap(...)_")"
        op = 'AGGLST =>
            formatNary(","::Sy, "", 0, args, prec)
        op = 'AGGSET =>
            formatNary(";"::Sy, "", 0, args, prec)
        op = 'TAG =>
            group concat [formatExpr(first args, prec),
                          " _"<rightarrow>_" ",
                            formatExpr(second args, prec)]
                         --RightArrow
        op = 'SLASH =>
            group concat [formatExpr(first args, prec),
                          " _"/_" ", formatExpr(second args, prec)]
)if false
        op = 'VCONCAT =>
            group concat("<mtable><mtr>",
                     concat(concat([concat("<mtd>",concat(formatExpr(u, minPrec),"</mtd>"))
                                    for u in args]::L S),
                            "</mtr></mtable>"))
)endif
        op = 'CONCATB =>
            formatNary('STRSEP, "(space _"1spc_")", 0, args, prec)
            --formatNary('STRSEP, " ", 0, args, prec)
        op = 'CONCAT =>
            formatNary('STRSEP, "", 0, args, minPrec)
        op = 'QUOTE =>
            group concat("'", formatExpr(first args, minPrec))
        op = 'BRACKET =>
            group addBrackets ungroup formatExpr(first args, minPrec)
        op = 'BRACE =>
            group addBraces ungroup formatExpr(first args, minPrec)
        op = 'PAREN =>
            group parenthesize ungroup formatExpr(first args, minPrec)
        op = 'PRIME =>
            formatSpecial('SUPERSUB, [first args, empty()$E,
                                      second(args)], prec)
        op = 'OVERBAR =>
            empty?(args) => ""
            concat ["(wide ", formatExpr(first args, minPrec), " _"<bar>_")"]
            --OverBar
        op = 'ROOT =>
            empty?(args) => ""
            tmp : S := group formatExpr(first args, minPrec)
            empty?(rest(args)) => concat ["(sqrt ", tmp, ")"]
            concat ["(sqrt ", tmp, " ", formatExpr(first rest args, minPrec),
                    ")"]
        op = 'SEGMENT =>
            tmp : S := concat [formatExpr(first args, minPrec), " _".._" "]
            group
                empty?(rest(args)) =>  tmp
                concat [tmp, formatExpr(first rest args, minPrec)]
        op = 'SUB =>
            group concat ["(concat ", formatExpr(first args, minPrec),
                 "(rsub ", formatSpecial('AGGLST, rest args, minPrec), "))"]
        op = 'SUPERSUB =>
            base : S := formatExpr(first args, minPrec)
            args := rest args
            #args > 4 => error "multiscript object has more than 4 scripts"
            if not(empty?(args)) then
                base := concat [base, " ",
                                optionalWrap("rsub", args(1), minPrec)]
                args := rest args
            if not(empty?(args)) then
                base := concat [base, " ",
                                optionalWrap("rsup", args(1), minPrec)]
                args := rest args
            if not(empty?(args)) then
                base := concat [optionalWrap("lsup", args(1), minPrec),
                                " ", base]
                args := rest args
            if not(empty?(args)) then
                base := concat [optionalWrap("lsub", args(1), minPrec),
                                " ", base]
            concat ["(concat ", base, ")"]
        op = 'SC =>
            empty?(args) => ""
            tmp := formatNaryNoGroup('STRSEP, ")) (row (cell ",
                                     0, args, minPrec)
            concat ["(tabular (tformat (twith _"table-valign_" _"t_") (table (row (cell ", tmp, ")))))"]
        op = 'MATRIX => formatMatrix rest args
)if false
        op = 'BOX =>
            empty?(args) => ""
            tmp := formatNaryNoGroup("",args,minPrec)
            group concat ["<mtable frame=_"solid_"><mtr><mtd>",tmp,"</mtd></mtr></mtable>"]
        op = 'EQUATNUM =>
            concat ["<mtable><mtr><mtd>",formatExpr(args.1,minPrec),"</mtd><mtd style=_"padding-left: 50px;_">",formatExpr(args.2,minPrec),"</mtd></mtr></mtable>"]
)endif
        op = 'BINOMIAL =>
            -- binomial('f: OutputForm, 'z: OutputForm) produces
            -- {{BINOMIAL}{f}{z}}
            concat ["(binom ", formatExpr(args.1,minPrec), " ", formatExpr(args.2,minPrec), ")"]
        op = 'NOTHING => "_"_""
)if false
        -- this is the output from 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}}}
        -- to format continued fraction traditionally need to intercept it at the
        -- formatNary of the "+"
        --  concat [" \zag{",formatExpr(first args, minPrec),"}{",
        --    formatExpr(first rest args,minPrec),"}"]
        op = 'ZAG =>
            concat ["<mtable><mtr><mtd style=_"border-right: solid 1px black;
              border-bottom: solid 1px black; padding-right: 2px; padding-left: 2px;_">",formatExpr(first args, minPrec),
                "</mtd></mtr><mtr><mtd style=_"border-left: solid 1px black; padding-left: 2px; padding-right: 2px;_">",
                   formatExpr(first rest args,minPrec),"</mtd></mtr></mtable>"]
)endif
        concat ["(concat _"not done yet for: ", string(op),"_")"]

)if false
    formatSuperSub(expr : E, args : L E, opPrec : I) : S ==
      s : S := "(concat _""funcS"_" (rprime _""
      while j < i repeat
        s := s"'"
        j := j + 1
      s := s"_") _"(_" "formatExpr(first args,minPrec)" _")_")"
)endif

    formatPlex(op : Sy, args : L E, prec : I) : S ==
        p : I := position(op, plexOps)
        p < 1 => error "unknown plex op"
        opPrec := plexPrecs.p
        n : I := #args
        (n ~= 2) and (n ~= 3) => error "wrong number of arguments for plex"
        ops : S :=
            op = 'SIGMA =>
                -- sum(a::OutputForm, b::OutputForm) produces
                -- (SIGMA b a)
                n = 2 => "<sum>"
                error "wrong number of arguments for plex"
            op = 'SIGMA2 =>
                -- sum(a::OutputForm, b::OutputForm, c::OutputForm) produces
                -- (SIGMA2 b c a)
                n = 3 => "<sum>"
                error "wrong number of arguments for plex"
            op = 'PI =>
                -- prod(a::OutputForm, b::OutputForm) produces
                -- (PI b a)
                n = 2 =>  "<prod>"
                error "wrong number of arguments for plex"
            op = 'PI2 =>
                -- prod(a::OutputForm, b::OutputForm, c::OutputForm) produces
                -- (PI2 b c a)
                n = 3 => "<prod>"
                error "wrong number of arguments for plex"
            op = 'INTSIGN =>
                -- int(a::OutputForm) produces
                -- (INTSIGN NOTHING NOTHING a)
                -- int(a::OutputForm, b::OutputForm) produces
                -- (INTSIGN b NOTHING a)
                -- int(a::OutputForm, b::OutputForm, c::OutputForm) produces
                -- (INTSIGN b c a)
                n = 3 => "<int>"
                error "wrong number of arguments for plex"
            error "Unexpected plex op:" string(op)
        body :=
            op = 'INTSIGN =>
                concat(formatIntBody(args(3), minPrec), " (big _"._")")
            formatExpr(args(n), opPrec)
        t2 : S :=
            n = 3 => concat [" (rsup ", formatExpr(args.2,minPrec),")"]
            ""
        t1 := formatExpr(args(1), minPrec)
        s := concat ["(big-around _"", ops, "_" (concat (rsub ", t1,
                     ")", t2, " ", body, "))"]
        if opPrec < prec then s := parenthesize s
        s


    formatIntBody(body : E, opPrec : I) : S ==
        -- the original OutputForm expression looks something like this:
        -- {{INTSIGN}{NOTHING or lower limit?}
        -- {bvar or upper limit?}{{*}{integrand}{{CONCAT}{d}{fricas var}}}}
        -- the args list passed here consists of the rest of this list, i.e.
        -- starting at the NOTHING or ...
        if has_op?(body, "*"::Sy) then
            bodyL := arguments(body)
            if #bodyL = 2 and has_op?(bvar := bodyL(2), 'CONCAT) then
                bvarL := arguments(bvar)
                if #bvarL = 2 and is_symbol?(bvarL(1), 'd)
                        and symbol?(bvarL(2)) then
                    bvarS : S := string(symbol(bvarL(2)))
                    return concat ["(concat ", formatExpr(bodyL(1), opPrec),
                                   " _"*<mathd>", bvarS, "_")"]
        formatExpr(body, opPrec)

    formatMatrix(args : L E) : S ==
        -- format for args is [[ROW ...], [ROW ...], [ROW ...]]
        -- generate string for formatting columns (centered)
        group concat
            ["(matrix (tformat (table (row (cell ",
              formatNaryNoGroup('STRSEP, ")) (row (cell ", 0, args, minPrec),
                ")))))"]

    formatFunction(op : E, args : L E, prec : I) : S ==
        ops := formatExpr(op, minPrec)
        group concat [ops, " ", parenthesize
                      formatNary(","::Sy, "", 0, args, minPrec)]

    formatNullary(op : Sy) ==
        op = 'NOTHING => "_"_""
        group concat ["_"", string(op), "()_""]

    formatUnary(op : Sy, arg : E, prec : I) ==
        p : I := position(op, unaryOps)
        p < 1 => error "unknown unary op"
        opPrec := unaryPrecs.p
        s : S := concat ["(concat _"", string(op), "_" ",
                         formatExpr(arg, opPrec), ")"]
        opPrec < prec => group parenthesize s
        op = "-"::Sy => s
        group s

    formatBinary(op : Sy, args : L E, prec : I) : S ==
        p : I := position(op, binaryOps)
        p < 1 => error "unknown binary op"
        opPrec := binaryPrecs.p
        s1 := formatExpr(first args, opPrec)
        s2 := formatExpr(first rest args, opPrec)
        s : S :=
            op = "^"::Sy    => concat ["(concat " s1 "(rsup " s2 "))"]
            op = "/"::Sy     => concat ["(frac ",s1," ",s2,")"]
            op = 'OVER  => concat ["(frac ",s1," ",s2,")"]
            ops : S :=
                op = "~="::Sy => "<ne>"
                op = "<"::Sy => "<less>"
                op = "<="::Sy => "<leq>"
                op = ">"::Sy => "<gtr>"
                op = ">="::Sy => "<geq>"
                op = "+->"::Sy => "<mapsto>"
                -- FIXME how to do this properly ???
                op = 'LET   => ":="
                string(op)
            concat ["(concat ", s1, " _"", ops, "_" ", s2, ")"]
        group
            op = "/"::Sy or op = 'OVER => s
            opPrec < prec => parenthesize s
            s

    formatNary(op : Sy, sep : S, opprec : I, args : L E, prec : I) : S ==
        group formatNaryNoGroup(op, sep, opprec, args, prec)

    formatNaryNoGroup(op : Sy, sep : S, opprec : I, args : L E, prec : I) : S ==
        empty?(args) => ""
        p : I := position(op, naryOps)
        p < 1 => error "unknown nary op"
        -- 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}}}
        -- 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 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 has_op?(args(2), 'ZAG) =>
            op ~= "+"::Sy => error "ZAG in unexpected place"
            has_op?(args(1), 'ZAG) => formatZag(args)
            concat [formatExpr(first args, minPrec), " _"+_" ",
                    formatZag(rest args)]
        ops : S :=
            op = 'STRSEP => sep
            op = 'ROW   => ") (cell "
            op = 'TENSOR => " _"<otimes>_" "
            concat [" _"", string(op), "_" "]
        l : L S := []
        opPrec :=
            op = 'STRSEP => opprec
            naryPrecs.p
        for a in args repeat
            l := concat(ops, concat(formatExpr(a, opPrec), l)$L(S))$L(S)
        s : S := concat reverse rest l
        opPrec < prec => parenthesize s
        s

    formatZag(args : L E) : S ==
      -- 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
      is_symbol?(first args, "..."::Symbol) => "<ldots>"
      not(has_op?(first args, 'ZAG)) =>
          error "formatZag: Last argument in ZAG construct "
                 "has unknown operator"
      tmpZag : L E := arguments(first args)
      #args > 1 => "(frac " formatExpr(first tmpZag, minPrec) "(concat "
                    formatExpr(first rest tmpZag, minPrec) " _"+_" "
                        formatZag(rest args) "))"
      "(frac " formatExpr(first tmpZag, minPrec)
          formatExpr(first rest tmpZag, minPrec) ")"

    formatExpr(expr : E, prec : I) : S ==
      i, len : Integer
      intSplitLen : Integer := 20
      atom?(expr) =>
        -- this bit deals with integers
        integer?(expr) =>
          i := integer(expr)
          str := string(i)
          if (i < 0) or (i > 9)
            then
              group
                 nstr : String := ""
                 -- insert some blanks into the string, if too long
                 while ((len := #str) > intSplitLen) repeat
                   nstr := concat [nstr, " ",
                     elt(str, segment(1, intSplitLen)$US)]
                   str := elt(str, segment(intSplitLen + 1)$US)
                 empty? nstr => concat [" _"", str, "_" "]
                 nstr :=
                   empty? str => nstr
                   concat [nstr, " ", str]
                 concat [elt(nstr, segment(2)$US)]
            else concat [" _"", str, "_" "]

        if symbol?(expr) then
            es := symbol(expr)
            es = "%pi"::Sy => return "<mathpi>"
            es = "%e"::Sy => return "<mathe>"
            es = "%i"::Sy  => return "<mathi>"
            es = 'infinity => return "<infty>"
            str := string(es)
        else if string?(expr) then
            str := string(expr)
        else
            error "Unrecognized atom in OutputForm"
        len := #str

        len > 0 and str.1 = char "%" => concat [" _"", str, "_" "]
        -- presumably this is a literal string
        -- WSP: preserve "..." and encode <less> symbols
        len > 0 and str.1 = char "_"" =>
          --concat ["(concat ", str, ")"]
          concat ["(text (concat ", "_"_\_"_" ",concat ["(math ",utf2cork str, ")"], " _"_\_"_") )"]
        len = 1 and str.1 = char " " => " "
        if symbol?(expr) then
            op := symbol(expr)
            (i := position(op, specialStrings)) > 0 =>
                specialStringsInMML.i
        (i := position(char " ", str)) > 0 =>
          -- We want to preserve spacing, so use a roman font.
          concat [" _"", str, "_" "]
        -- if we get to here does that mean it's a variable?
        group utf2cork concat [" _"", str, "_" "]
      opf : E := operator(expr)
      args : L E := arguments(expr)
      nargs : I := #args

      symbol?(opf) =>
          op := symbol(opf)
          -- special cases
          member?(op, specialOps) => formatSpecial(op, args, prec)
          member?(op, plexOps)    => formatPlex(op, args, prec)

          -- nullary case
          0 = nargs => formatNullary op

          -- unary case
          (1 = nargs) and member?(op, unaryOps) =>
            formatUnary(op, first args, prec)

          -- binary case
          (2 = nargs) and member?(op, binaryOps) =>
            formatBinary(op, args, prec)

          -- nary case
          member?(op, naryNGOps) => formatNaryNoGroup(op, "", 0, args, prec)
          member?(op, naryOps) => formatNary(op, "", 0, args, prec)
          formatFunction(opf, args, prec)
      formatFunction(opf, args, prec)

--Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
--All rights reserved.
--
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are
--met:
--
--    - Redistributions of source code must retain the above copyright
--      notice, this list of conditions and the following disclaimer.
--
--    - Redistributions in binary form must reproduce the above copyright
--      notice, this list of conditions and the following disclaimer in
--      the documentation and/or other materials provided with the
--      distribution.
--
--    - Neither the name of The Numerical ALgorithms Group Ltd. nor the
--      names of its contributors may be used to endorse or promote products
--      derived from this software without specific prior written permission.
--
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
--IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
--TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
--PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
--OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
--EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
--PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Reply via email to