latex() in SetCategory and its use vs TeXFormat

6 views
Skip to first unread message

Grégory Vanuxem

unread,
May 30, 2024, 6:54:04 AMMay 30
to fricas...@googlegroups.com
Hello,

I am wondering what is the use of the 'latex' function in FriCAS. And,
more importantly, why it is not used by TeXFormat.

Apparently the TeX format which is used when one issue ')set output
tex on' in the interpreter uses only the "official" OutForm to
translate it in LaTeX.

Is it possible to bypass this mechanism or am I wrong here?

In fact I would like to have better control of the output.

- Greg

Ralf Hemmecke

unread,
May 30, 2024, 7:15:23 AMMay 30
to fricas...@googlegroups.com
Hi Greg,

You now get a more personal view from my side.

> I am wondering what is the use of the 'latex' function in FriCAS.

Nothing, currently. I have no idea about the history, but I do not see
much use of it now.

You could actually think of this: each element "know" how it should be
represented in LaTeX.

> And, more importantly, why it is not used by TeXFormat.

I guess, historical reasons and maybe a different view. There is
basically the following question to solve.

You have n object types (basically elements from different domains) and
m output formats (like 1d, 2d, latex, html, etc.). How do you implement
that each domain can be output in each output format?

In FriCAS the view is that each element type can be converted to
OutputForm and each OutputForm can be converted to each of the possible
Formats.

You could also say each element type (i.e. each domain) knows how to
format for each output format. Introducing a new output format then
would require to add new functions to every domain in the library to
support such output. (Looks like that this does not scale very well.)

The other extreme approach is that for each output format there is a
function that knows how to represent each and every element type in this
respective format. (Looks like that this is also not the best, because
every time a new domain is added to the library, all the formatting
functions must be told about it.

OutputForm is the FriCAS way to have a common API. I do not claim that
this is perfect, but it's a reasonable approach.

> Apparently the TeX format which is used when one issue ')set output
> tex on' in the interpreter uses only the "official" OutForm to
> translate it in LaTeX.

You should start to write the actual problem in your mails.

> In fact I would like to have better control of the output.

I can only guess that I can help you with your problem. The formatting
framework that I have programmed, is very flexible. Without looking at
my old code, I would claim that you can even extend the formatters at
runtime in order to handle new (i.e. unofficial) OutputForm operators.
Just specify precisely what you want to achieve.

Warning, I will be away till Monday.

Ralf

Grégory Vanuxem

unread,
May 30, 2024, 8:57:59 AMMay 30
to fricas...@googlegroups.com
Hello Ralf,

I know and I was waiting somewhere for your reply, there is Spad code from you in FriCAS about that . Just quick notes, I'll respond more clearly when time allows, my thoughts are vague and scattered. But think about sqrt(x) or asin(x) in LaTeX, they may be formatted differently if you use \sqrt, \asin or sin^1 (x), x^(1/2), negative power for rational numbers, etc. The way OutputForm works doesn't allow a domain's coder to choose which representation to display. And if you want to have different representations as an option, that doesn't seem to be possible. From my point of view, if you want another format, you have to write a whole new format. It's just not practical.

For tables and other “containers”, I am pretty sure that's not easy to manage, but for relatively simple operations or numbers implemented in LaTeX that should be doable I think.

Other vague ideas, there are generalizations of input/output type like MIME, OS file extensions and much more. Since from tracing the TeX formatter, the 'display' function is used at end, why not, a dream, display-ing with a "draw" format the .xpm in the FriCAS graphic window, there is also png or other, "image/png" etc. I do not think to all possible data types of course I will not edit videos in FiCAS ;) And to add to this, yes, OutputForm is a very handy general "representation".

Just thoughts. The first part of my mail respond to "state your problem":

How to handle for example \asin or \sin ^{-1}(a) in LatTeX.

- Greg 




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 fricas-devel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/b4b868a7-5a86-4962-8636-52b83680bd2b%40hemmecke.org.

Ralf Hemmecke

unread,
May 30, 2024, 9:02:59 AMMay 30
to fricas...@googlegroups.com
> How to handle for example \asin or \sin ^{-1}(a) in LatTeX.

That sounds like a LaTeX question you probably want a connection to
FriCAS. No?

Ralf

Grégory Vanuxem

unread,
May 30, 2024, 9:09:47 AMMay 30
to fricas...@googlegroups.com
No. Think of jFriCAS and )set output tex on.
latex() is not used but choosing the representation at the domain
level is possible with this function (for simple elements).

In LaTeX you can prefer 1D or 2D for fraction also. That's possible in
the interpreter, ')set output fraction' for pure OutputForm. For the
texfomat I have not tested. In fact I am thinking about a more general
way of outputting objects/elments.


> 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 fricas-devel...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/2971ed5c-1ff2-4df6-83c2-06d38579ab22%40hemmecke.org.

Ralf Hemmecke

unread,
May 30, 2024, 9:19:10 AMMay 30
to fricas...@googlegroups.com
>>> How to handle for example \asin or \sin ^{-1}(a) in LatTeX.
>>
>> That sounds like a LaTeX question you probably want a connection to
>> FriCAS. No?
>
> No. Think of jFriCAS and )set output tex on.

I would claim, that ")set output tex on" in jFriCAS is not a very good idea.

Why not outputting LaTeX output via FormatLaTeX, if you want the LaTeX
representation. OK FormatLaTeX is maybe too over-flexible, you would
need fricasmath.sty
https://github.com/fricas/fricas/blob/master/src/doc/fricasmath.sty#L41
for the respective .tex file to compile.
But it allows to redefine anything you like. For example, you could
(inside the fricasmath environment) define \sqrt like this.

\def\sqrt##1{\left(##1\right)^1/2}

(Note the double ##, since that definition appears inside a definition.)

> In LaTeX you can prefer 1D or 2D for fraction also. That's possible in
> the interpreter, ')set output fraction' for pure OutputForm. For the
> texfomat I have not tested. In fact I am thinking about a more general
> way of outputting objects/elments.

I would also like to see an expression handling as it was started in the
Algebra library of Aldor (look for ExpressionTree and friends).

Ralf

Grégory Vanuxem

unread,
May 30, 2024, 9:20:14 AMMay 30
to fricas...@googlegroups.com
To add to this, I am on a smartphone so it’s from memory, there is a GnuPlot domain or package that was used by Bill Page to display graphics on MathAction. It’s another way to output a graphic, to display it, here in a Web browser. I am not against OutoutForm, not at all.

Grégory Vanuxem

unread,
May 30, 2024, 9:44:14 AMMay 30
to fricas...@googlegroups.com
I will look at this, thanks!

--
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 fricas-devel...@googlegroups.com.

Waldek Hebisch

unread,
May 30, 2024, 10:11:52 AMMay 30
to fricas...@googlegroups.com
On Thu, May 30, 2024 at 03:20:01PM +0200, Grégory Vanuxem wrote:
> To add to this, I am on a smartphone so it’s from memory, there is a
> GnuPlot domain or package that was used by Bill Page to display graphics on
> MathAction. It’s another way to output a graphic, to display it, here in a
> Web browser. I am not against OutoutForm, not at all.

It is GnuDraw and it is included in FriCAS for several years.

--
Waldek Hebisch

Waldek Hebisch

unread,
May 30, 2024, 10:37:07 AMMay 30
to fricas...@googlegroups.com
On Thu, May 30, 2024 at 12:53:26PM +0200, Grégory Vanuxem wrote:
> Hello,
>
> I am wondering what is the use of the 'latex' function in FriCAS. And,
> more importantly, why it is not used by TeXFormat.

Well, I suspect that there were multiple parallel attempts to
create output framework for Axiom. OutputFrom got implemented
and works reasonably well, 'latex' was just a try, mostly
unimplemented. But few people here wanted 'latex' to stay,
so now it just uses TeXFormat. And of course since 'latex'
uses TeXFormat using 'latex' to implement TeXFormat would
lead to infinte loop. In other words, you can delegate work
only finitely many times, at the end somebody has to do real work.

> Apparently the TeX format which is used when one issue ')set output
> tex on' in the interpreter uses only the "official" OutForm to
> translate it in LaTeX.
>
> Is it possible to bypass this mechanism or am I wrong here?

OutputForm is supposed to contain enough information to allow
needed formatting. If not, we can extend OutputForm.

The point here is that algebra structures are defined in recursive
way, no single domain knows everthing. And we want multiple formats.
OutputForm allows to decompose formating work between various
domains. For example, SparseMultivariatePolynomial knows that
there are variables, that powers of variables are multiplied together
and preceeded by coefficients. But SparseMultivariatePolynomial does
not know how to format coefficients, this is delegated to coefficient
domain. Similarly SparseMultivariatePolynomial does not know how
to format variables, this is delegated to variable domain.

> In fact I would like to have better control of the output.

Well, currently there is bunch of choices:
- you can use different formatter or different options to
given formatter
- if domain supports this you can set options in the domain
(like for Float)
- you can create a new domain which re-uses old domain, but
has new coercion to OutputForm

Admitedly, creating new domain only to have different output
is clumsy. In principle we could have more options at
OutputForm level. OTOH bypassing OutputForm is likely to
lead to _less_ control because is such case places needing
changed bahaviour would be spread out and hard to find and
influence.


--
Waldek Hebisch

Waldek Hebisch

unread,
May 30, 2024, 11:14:55 AMMay 30
to fricas...@googlegroups.com
On Thu, May 30, 2024 at 02:57:20PM +0200, Grégory Vanuxem wrote:
>
> time allows, my thoughts are vague and scattered. But think about sqrt(x)
> or asin(x) in LaTeX, they may be formatted differently if you use \sqrt,
> \asin or sin^1 (x), x^(1/2), negative power for rational numbers, etc. The
> way OutputForm works doesn't allow a domain's coder to choose which
> representation to display.

OutputForm can represent each variant and domain's coder can use what
is more appropriate, like:

(2) -> y*(x::OutputForm)^(-1)

- 1
(2) y x
Type: OutputForm

>
> How to handle for example \asin or \sin ^{-1}(a) in LatTeX.

Just produce right OutputForm:

(4) -> )set output tex on
(4) -> prefix((sin::OutputForm)^(-1), [a])

- 1
(4) sin (a)
$$
{{\sin} \sp {-1}}
\left(
{a}
\right)
\leqno(4)
$$

Type: OutputForm

Both your wishes could be done by relatively simple transformation
of OutputForm. Currently before formattiong OutputForm is transformed
by 'precondition' in OutputFormTools. In principle 'precondition'
could be replaced by a user function.

--
Waldek Hebisch

Grégory Vanuxem

unread,
May 30, 2024, 6:56:06 PMMay 30
to fricas...@googlegroups.com
Thanks Waldek,

My principal problem would be to have a hook in the TeX formatter I think, I already have the LaTeX string, it comes from the WolframEngine and I can't know in advance which function it will return. I have no problem to coerce to OutputForm rationals, integers etc. For numbers it is not a problem, but I am also writing a parallel Expression domain, an interface in fact, where for example LambertW is PolyLog.

An example:

(1) -> x:=jWSExpr("x")

   (1)  x
                                                      Type: JuliaWSExpression
                           Time: 0.04 (IN) + 0.40 (EV) + 0.26 (OT) = 0.70 sec
(2) -> y:=jWSExpr("y")

   (2)  y
                                                      Type: JuliaWSExpression
                                                   Time: 0.05 (OT) = 0.06 sec
(3) -> trigToExp(sin(x) * sinh(y)+sqrt(y))

   (3)  (I/4)*(E^((-I)*x) - E^(I*x))*(-E^(-y) + E^y) + sqrt(y)
                                                      Type: JuliaWSExpression
                                       Time: 0.04 (EV) + 0.06 (OT) = 0.10 sec
(4) -> sin(x) * sinh(y)+sqrt(y)

   (4)  sqrt(y) + sin(x)*sinh(y)
                                                      Type: JuliaWSExpression
                                                   Time: 0.05 (OT) = 0.06 sec
(5) -> jlPlot(x+->sinc(x), -5..5)
-- lot of time the first time 
                                                                    Type: Void
                           Time: 0.04 (IN) + 1.08 (EV) + 0.09 (OT) = 1.20 sec

(6) -> jlPlotTitle! jlLatex latex %%(3)
                                                                   Type: Void
                                       Time: 0.02 (IN) + 0.33 (EV) = 0.36 sec

 (7) -> latex %%(3)

   (7)
  "\sqrt{y}+\frac{1}{4} i \left(e^{-i x}-e^{i x}\right) \left(e^y-e^{-y}\right)
  "
                                                                 Type: String
                                                                 Time: 0 sec

This is not the good title, it is just for illustration. For graph that's easily possible to use the LaTeX string in my settings, but having it used internally ')with set output tex on", I am stuck. Unless I dig into FriCAS internals? Probably. Nevertheless I can use it with graph, it's just saveFig("test.png") for this mail after it was displayed on a Window:

test.png

I looked at precondition but in this context my OutputForm is already a formatted String, it can represent too many things in comparison with FriCAS Expression domain. That's illusory and Wolfram™ has already done the job to translate to LaTeX .It's common apparently with mathematical software.

I am still continuing to better understand the OutputForm and its link to other formatters. For example, part of MathML output seems coded sometimes in domains themselves.

- Greg

PS: the FriCAS output in this mail is regex substituted before (downcase and brackets to parens substitutions), normally my output in FriCAS has the Wolfram language form: Sin[Cos[x]] 



--
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 fricas-devel...@googlegroups.com.

Grégory Vanuxem

unread,
May 30, 2024, 7:16:52 PMMay 30
to fricas...@googlegroups.com
Or having a double representation when calling a symbolic function, one for FriCAS and another for Wolfram. I have no idea right now but since it's just an interface the code is very simple:

    asech(x) == junfunc("W_"ArcSech_"",x)
    acsch(x) == junfunc("W_"ArcCsch_"",x)
    acoth(x) == junfunc("W_"ArcCoth_"",x)

    erf(x)      == junfunc("W_"Erf_"",x)
    erfc(x)     == junfunc("W_"Erfc_"",x)
    erf(x, y)   == jbinfunc("W_"Erf_"",x, y)
    erfi(x)     == junfunc("W_"Erfi_"",x)
    Si(x)       == junfunc("W_"SinIntegral_"",x)
    Shi(x)       == junfunc("W_"SinhIntegral_"",x)
    Ci(x)       == junfunc("W_"CosIntegral_"",x)
    Chi(x)      == junfunc("W_"CoshIntegral_"",x)
    Ei(x)       == junfunc("W_"ExpIntegralEi_"",x)
    fresnelC(x) == junfunc("W_"FresnelC_"",x)
    fresnelS(x) == junfunc("W_"FresnelS_"",x)

    riemannZeta(x) == junfunc("W_"Zeta_"",x)
    lambertW(x) == junfunc("W_"ProductLog_"",x)
    lambertW(x,y) == jbinfunc("W_"ProductLog_"",x, y)
    polygamma(x,y) == jbinfunc("W_"PolyGamma_"",x, y)

    toString(x) == jbinfunc("W_"ToString_"", x, jWSExpr("InputForm"))
    toString(x, form) == jbinfunc("W_"ToString_"", x, form)
    simplify(expr) == junfunc("W_"Simplify_"", expr)
    simplify(expr, assume) == jbinfunc("W_"Simplify_"", expr, assume)
    extendedSimplify(expr) == junfunc("W_"FullSimplify_"", expr)
    extendedSimplify(expr, assume) == jbinfunc("W_"FullSimplify_"", expr, assume)
    piecewiseExpand(expr) == junfunc("W_"PiecewiseExpand_"", expr)
    piecewiseExpand(expr, assume) == jbinfunc("W_"PiecewiseExpand_"", expr, assume)

After, this is just practical things to handle.

Waldek Hebisch

unread,
May 30, 2024, 8:13:53 PMMay 30
to fricas...@googlegroups.com
On Fri, May 31, 2024 at 12:55:26AM +0200, Grégory Vanuxem wrote:
> Thanks Waldek,
>
> My principal problem would be to have a hook in the TeX formatter I think,
> I already have the LaTeX string, it comes from the WolframEngine and I
> can't know in advance which function it will return. I have no problem to
> coerce to OutputForm rationals, integers etc. For numbers it is not a
> problem, but I am also writing a parallel Expression domain, an interface
> in fact, where for example LambertW is PolyLog.

Well, I do not know what is your final goal. From my point of view,
interface is useful if FriCAS can programtically construct and
analyse "foreign" objects. I mean, "foreign" objects may live in
their own world, that is OK. But we need some set of operations
on them. If all what interface can do is passing strings and getting
string output, then it is rather uninteresting to me. To put it
differently, for me interesting part is sending some FriCAS data
to "foreign" code and eventually getting back FriCAS data. AFAICS
this implies that writing convertion of "foreign" data to OutputForm
is more or less trivial. I mean, to build OutputForm you need to
be able to dissect data into parts, recursively convert each part to
OutputForm and combinie then back. If this process of dissection
is too complicated, then what useful can you do with such data?

--
Waldek Hebisch

Grégory Vanuxem

unread,
May 31, 2024, 6:45:06 AMMay 31
to fricas...@googlegroups.com
Hello,

Le ven. 31 mai 2024 à 02:13, Waldek Hebisch <de...@fricas.org> a écrit :
>
> On Fri, May 31, 2024 at 12:55:26AM +0200, Grégory Vanuxem wrote:
> > Thanks Waldek,
> >
> > My principal problem would be to have a hook in the TeX formatter I think,
> > I already have the LaTeX string, it comes from the WolframEngine and I
> > can't know in advance which function it will return. I have no problem to
> > coerce to OutputForm rationals, integers etc. For numbers it is not a
> > problem, but I am also writing a parallel Expression domain, an interface
> > in fact, where for example LambertW is PolyLog.
>
> Well, I do not know what is your final goal.

I don't even know myself, death ? Bad joking aside, as I said earlier
with WSLP the categories/domains I am writing are somewhat toy domains
but they raise interesting coding questions for example with the
JuliaWSExpression domain. But, first, having access to one of probably
the best CASs in the world, heavily used, and well tested I guess, can
help for testing and development purposes, comparisons in numerical
analysis but also with symbolic manipulation.
Furthermore it's usually very fast in large areas of computational mathematics.

> From my point of view,
> interface is useful if FriCAS can programtically construct and
> analyse "foreign" objects. I mean, "foreign" objects may live in
> their own world, that is OK. But we need some set of operations
> on them. If all what interface can do is passing strings and getting
> string output, then it is rather uninteresting to me.

Of course, this is one aim I am pursuing. Right now I am doing the
rotten job, adding usual routines, after that I can easily modify the
internal rules used behind if necessary. I could even code a C
wrapper, that should not be very difficult, but that does not enter
into my intentions.

> To put it
> differently, for me interesting part is sending some FriCAS data
> to "foreign" code and eventually getting back FriCAS data.

This is the purpose of WSTP, but you know that I think:
https://www.wolfram.com/wstp/

What you are mentioning is mentioned here:
https://reference.wolfram.com/language/ref/LinkProtocol.html
https://reference.wolfram.com/language/guide/WSTPAPI.html

> AFAICS
> this implies that writing convertion of "foreign" data to OutputForm
> is more or less trivial.

Not trivial for me. OutputForm is the root of the outputting system in
FriCAS. For latex():

SetCategory() : Category == Join(BasicType, CoercibleTo OutputForm) with
--operations
latex : % -> String
++ latex(s) returns a LaTeX-printable output
++ representation of s.
add
latex(s : %) : String ==
of := s::OutputForm
tf := of::TexFormat
sl := tex(tf)
reduce(concat, sl)

and from my point of view it has a lot of hardcoded things in it. It's
a "must to pass by it". Even the interpreter has operator knowledge
from what I have read. So using OutputForm is using its "language" as
you said. (ROOT 2) for a square root of 2 for example, not (^ 2 (/ 1
2)) . So if you want to use your personal representation in LaTeX
here, that seems somewhat complicated. My first question is about
that, for simple elements I do not understand why the domain coder
could not give its representation to OutputForm and otherwise let
OutputForm handle it.


Expression(INT) -> Complex(INT -> %i

I mean, to build OutputForm you need to
> be able to dissect data into parts, recursively convert each part to
> OutputForm and combinie then back. If this process of dissection
> is too complicated, then what useful can you do with such data?

I can do whatever I want, in fact at different levels, FriCAS, Lisp,
Julia or the engine behind. I will do that later. I am at the
"thinking about" stage. But basically and that raises interesting
questions to me, I am not at all a big fan of rotten coding, I use a
strictly formal way of representing my expressions, and they are
_only_ evaluated at output time. That will change for some routines.

I use simplify with an assumption below, I do not have in mind right
now a better example without simplify, it's a pity. As far as the
expression is not evaluated, FriCAS has it its full form in a String:

(1) -> x:=jWSExpr("x")

(1) x
Type: JuliaWSExpression
(2) -> x^(jWSRat 1/7)+sqrt(x^2)

(2) x^(1/7) + Sqrt[x^2]
Type: JuliaWSExpression
(3) -> simplifiedEx:=simplify(%, "x<0")

(3) x^(1/7) - x
Type: JuliaWSExpression
(4) -> string %

(4)
"W`Simplify[Plus[Power[x, Rational[1, 7]], Sqrt[Power[x, 2]]], Less[x, 0]]`"
Type: String
(5) -> jlSymbolic simplifiedEx

(5) "Plus[Power[x, Rational[1, 7]], Times[-1, x]]"
Type: String
(6) -> toString simplifiedEx

(6) "x^(1/7) - x"
Type: JuliaWSExpression
(7) -> toString(simplifiedEx,"InputForm")

(7) "x^(1/7) - x"
Type: JuliaWSExpression
(8) -> jlSymbolic %%(2)

(8) "Plus[Power[x, Rational[1, 7]], Power[Power[x, 2], Rational[1, 2]]]"
Type: String
(9) -> %%(2)

(9) x^(1/7) + Sqrt[x^2]
Type: JuliaWSExpression

These output to string routines are useful to better know the
different internal structures.

Behind the scenes, in Julia, W"Sqrt" produces the Julia WS language
symbol 'Sqrt' that can be applied to the symbol x when they are sent
to the engine.

- Greg





>
> --
> Waldek Hebisch
>
> --
> 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 fricas-devel...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/ZlkWPiVbayDKhsiJ%40fricas.org.

Waldek Hebisch

unread,
May 31, 2024, 5:07:46 PMMay 31
to fricas...@googlegroups.com
Ralf explained well overall design, but let me restate it. Since our
domains can be composed in recursive way the only resonable way to
produce output is via cooperation of domains, each domain is responsible
for its part calling recursively output function for domains that
it uses. OutputForm has tree structure and one can easily compose
parts. Of course, it is possible to do composition on level of
strings, but it is more clumsy. Important point is that we have
multiple output formats. Independent implementation of 'latex'
would create significant code duplication: each domain would need
higher level logic very similar to current logic for producing
OutputForm. But beside higher level logic there would be specific
handling for latex. This would require more code than current
design. Also, note that currently formatter has full control
of produced strings, so it can assume that they have specific
structure. Just image possible complications if domain author
decides that he/she wants to redefine some basic LaTeX operator.

Coming back to multiple formats: we have several output formats
and can be resonably sure that they work. More precisely, once
formatter correctly handles operators from OutputForm it can
handle output from any domain. In alternative world with
specialised formatters there is danger that domain authors would
decide to leave some formats unimplemented. You have examples
how it works in practice: in NAG sources 'latex' worked for
few 'major' domains but was mostly unimplmented. Simply domain
authors decided not to bother implementing 'latex'. And we
have InputForm which has substantial gaps. Since uses of
InputForm are limited there is limited motivation to fill the
gaps. Coming back to output, imagine that one author only
implements text output for domain D1. Another author
only implements LaTeX output for parametrised domain D2.
Now, even if D2(D1) works in sense of doing computations
you are unable to get any output from it: since D2 only
supports LaTeX you can get output from D2(T) only if T
supports LaTeX, which fails for D1 having only text output.
While missing LaTeX output have low probability, we have
MathML output and it is much more likely that domain author
would skip this. Or Texmacs interface: it depends on
specialized formatter and I bet that most domain authors
would not bother implementing Texmacs output.

I understand that you would prefer to avoid implementing proper
conversion to OutputForm. After all, while not hard it is
clearly more work than faking it using strings. But looking
at big picture, somebody has to ensure that various parts of
FriCAS work together. For formatting in FriCAS this work is
minimised by having OutputForm and coercion to OutputForm
in each domain.

> I mean, to build OutputForm you need to
> > be able to dissect data into parts, recursively convert each part to
> > OutputForm and combinie then back. If this process of dissection
> > is too complicated, then what useful can you do with such data?
>
> I can do whatever I want, in fact at different levels, FriCAS, Lisp,
> Julia or the engine behind. I will do that later. I am at the
> "thinking about" stage. But basically and that raises interesting
> questions to me, I am not at all a big fan of rotten coding, I use a

I do not know what "rotten coding" is supposed to mean.

> strictly formal way of representing my expressions, and they are
> _only_ evaluated at output time. That will change for some routines.

Hmm, that looks horribly inefficient.
Consider

z := big_expr - big_expr_written_in_different_way
(z = 0)@Boolean

Do you mean that each time code/user test if 'z = 0' you repeat
computations? There is concept of lazy evaluation, but normally
lazy evaluation keeps things unevaluated as long as it can, but
when "forced" it evaluets them and further computations use
evaluated result.

> I use simplify with an assumption below, I do not have in mind right
> now a better example without simplify, it's a pity. As far as the
> expression is not evaluated, FriCAS has it its full form in a String:
>
> (1) -> x:=jWSExpr("x")
>
> (1) x
> Type: JuliaWSExpression
> (2) -> x^(jWSRat 1/7)+sqrt(x^2)
>
> (2) x^(1/7) + Sqrt[x^2]
> Type: JuliaWSExpression
> (3) -> simplifiedEx:=simplify(%, "x<0")
>
> (3) x^(1/7) - x
> Type: JuliaWSExpression
> (4) -> string %
>
> (4)
> "W`Simplify[Plus[Power[x, Rational[1, 7]], Sqrt[Power[x, 2]]], Less[x, 0]]`"
> Type: String
> (5) -> jlSymbolic simplifiedEx
>
> (5) "Plus[Power[x, Rational[1, 7]], Times[-1, x]]"
> Type: String
> (6) -> toString simplifiedEx
>
> (6) "x^(1/7) - x"
> Type: JuliaWSExpression

That is not entirely clear. I mean, due to assignment in (3) in (4)
% and simplifiedEx should be the same. So do you mean that

string simplifiedEx

and

toString simplifiedEx

produce different results? And do you mean that 'toString' (and
presumably 'jlSymbolic' is re-doing computations? Or do you
remember "everything" and just recall previously computed result
(but apparently keep all history of comutations)?

> (7) -> toString(simplifiedEx,"InputForm")
>
> (7) "x^(1/7) - x"
> Type: JuliaWSExpression
> (8) -> jlSymbolic %%(2)
>
> (8) "Plus[Power[x, Rational[1, 7]], Power[Power[x, 2], Rational[1, 2]]]"
> Type: String
> (9) -> %%(2)
>
> (9) x^(1/7) + Sqrt[x^2]
> Type: JuliaWSExpression
>
> These output to string routines are useful to better know the
> different internal structures.
>
> Behind the scenes, in Julia, W"Sqrt" produces the Julia WS language
> symbol 'Sqrt' that can be applied to the symbol x when they are sent
> to the engine.

--
Waldek Hebisch

Grégory Vanuxem

unread,
May 31, 2024, 11:14:12 PMMay 31
to fricas...@googlegroups.com
Le ven. 31 mai 2024 à 23:07, Waldek Hebisch <de...@fricas.org> a écrit :
>
> On Fri, May 31, 2024 at 12:44:27PM +0200, Grégory Vanuxem wrote:

> I do not know what "rotten coding" is supposed to mean.

Borrowed from the expression "rotten job".

Will look later at your response, thanks for it.
Reply all
Reply to author
Forward
0 new messages