Martin R wrote:
> 
> Dear all,
> 
> as you may know, I am trying to improve the accessibility of FriCAS from 
> sage, since some people (including myself) value FriCAS strengths.
> 
> I wanted to add functionality to translate FriCAS' sums and products into 
> sage's, but ran into a stupid problem.
> 
> Basically, I use the unparsed InputForm to obtain an expression tree from 
> FriCAS EXPR.  Consider now:
> 
> (52) -> f := guess([reduce(*, [reduce(+, [1/k for k in 1..m], 0) for m in 
> 1..n], 1) for n in 0..10]).1
> 
>                  p   - 1
>          n - 1    11
>          ++-++     --+       1
>    (52)   | |      >      ------- + 1
>           | |      --+    s   + 2
>          p  = 0  s  = 0    10
>           11      10
>                                                     Type: 
> Expression(Integer)
> (53) -> f::INFORM
> 
>    (53)
>    (%defprod  (+ (%defsum (/ 1 (+ %LW 2)) %LW (*01000s 10) 0 (+ %LX - 1)) 1)
>     %LX  (*01000p 11)  0  (+ n - 1))
>                                                               Type: 
> InputForm
> 
> As you can see, the summation variables have subscripts.  However, the 
> string representation of the InputForm of scripted symbols does not allow 
> to reproduce the symbol.  In fact, the code in symbol.spad is simply:
> 
>     convert(s : %) : InputForm == convert(s pretend Symbol)$InputForm
> 
> Would it be possible to change that to something like the following 
> (WARNING: only lightly tested!).  Two comments:
> 
> 1) The scripts are of type OutputForm, but there is no way to get an 
> InputForm from an OutputForm.  So the below will not work always, but only 
> when the input is reasonable.  In fact
> interpret convert subscript('s, [z^2]) works...
> 
> 2) There seems to be a problem when the subscript has a value.  For 
> example, x := subscript('s, ['x^2]) produces an error about cons'ing 
> InputForm with InputForm.  Not sure what's happening there.
> 
> Best wishes,
> 
> Martin
> 
> Code:
> 
> convert(s: Symbol): InputForm ==
>     not scripted? s => convert(name s)$InputForm
> 
>     ls := scripts s
>     A: List InputForm := [e pretend InputForm for e in ls.sub]
>     B: List InputForm := [e pretend InputForm for e in ls.sup]
>     C: List InputForm := [e pretend InputForm for e in ls.presup]
>     D: List InputForm := [e pretend InputForm for e in ls.presub]
>     E: List InputForm := [e pretend InputForm for e in ls.args]
>     a: InputForm := convert('script)
>     b: InputForm := convert name s
>     c: InputForm := cons(convert('construct), [cons(convert('construct), e) 
> for e in [A, B, C, D, E]])
>     convert([a, b, c])

Well, you need coercion from OutputForm to InputForm.  Above
you try 'pretend' but it is very poor coercion.  The problem is
that InputForm is evaluated, at least you would need something
like Lisp quote.  Since we do not have quote, the correct way
is to walk aroud InputForm and recursively convert them.  So
correct InputForm for OutputForm of 'x^2' is something like
parsed version of the following

prefix(outputForm('^), [outputForm('x), outputForm(2)])$OutputForm

-- 
                              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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to