Waldek,

On Wed, Sep 17, 2008 at 10:06 AM, Bill Page wrote:
>
> Thanks. I applied this change and the result is much better, but
> the result of 'unparse' followed by 'parse' does not yield the same
> result. Parenthesis are missing around the numerator and
> denominator of the following expression:
>
>   (8)
>  "4*tan(1/2)^2*cos(x+1)*sin(x+1)+-2*tan(1/2)^3+2*tan(1/2)*cos(x+1
> )^2+x*tan(1/2
>  )^4+2*x*tan(1/2)^2+x/tan(1/2)^4+2*tan(1/2)^2+1"
>

Here is a new version of the sumOrParen, productOrParen, powerOrParen
and appOrParen that seems to produce a correct result. Note in
particular that I moved

       op = "/" or op = '"/" =>
           concat(productOrParen(arg1), '"/", powerOrParen(arg2))

from sumOrParen to productOrParen. Also I added

       concat('"(", appOrParen(x), '")")

to powerOrParen and removed the special coding for unary minus in appOrParen.

----

sumOrParen(x) ==
   x is [op, arg1, arg2] =>
       op = "+" or op = '"+" =>
           concat(sumOrParen(arg1), '"+", productOrParen(arg2))
       op = "-" or op = '"-" =>
           concat(sumOrParen(arg1), '"-", productOrParen(arg2))
       productOrParen(x)
   productOrParen(x)

productOrParen(x) ==
   x is [op, arg1, arg2] =>
       op = "*" or op ='"*" =>
           concat(productOrParen(arg1), '"*", powerOrParen(arg2))
       op = "/" or op = '"/" =>
           concat(productOrParen(arg1), '"/", powerOrParen(arg2))
       powerOrParen(x)
   powerOrParen(x)

powerOrParen(x) ==
   x is [op, arg1, arg2] =>
       op = "**" or op = '"**" or op = "^" or op = '"^"  =>
           concat(appOrParen(arg1), '"^", appOrParen(arg2))
       concat('"(", appOrParen(x), '")")
   appOrParen(x)

appOrParen(x) ==
   SYMBOLP(x) and not(constructor? x) => toString formWrapId x
   INTEGERP(x) => WRITE_-TO_-STRING x
   ATOM(x) => form2String0(x)
   [op, :argl] := x
   -- Put parenthesis around anything special
   not(SYMBOLP op) or GET(op, 'LED) or GET(op, 'NUD)_
     or op= 'mkCategory or constructor? op or op = "SEGMENT" _
     or op = 'construct or op = 'COLLECT or op = "SIGNATURE"_
     or op = 'BRACKET or op = 'AGGLST or op = "ATTRIBUTE"_
     or op = 'Join or op = "#" =>
        concat('"(", form2String0(x), '")")
   op = "Zero" => '"0"
   op = "One" => '"1"
   toString0(form2String1 x)

-----

Now I get:

  (8)
  "(4*tan(1/2)^2*cos(x+1)*sin(x+1)+((-2*tan(1/2)^3+2*tan(1/2))*cos
(x+1)^2+(x*tan(1/2)^4+2*x*tan(1/2)^2+x)))/(tan(1/2)^4+2*tan(1/2)^2+1)"

which parses correctly. It seems that this produces the required
minimum number of parenthesis.

Regards,
Bill Page.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to