Bill Page wrote:
>
> 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.
I had
op = "/" or op = '"/" =>
concat(appOrParen(arg1), '"/", appOrParen(arg2))
in sumOrParen to force parentheses around arguments of "/" in
a product. While most parser (incuding the interpreter parser)
treat "*" and "/" as having equal priority, some parses give
them different priority. Exact rules seem to be confusing
for humans, so I think that extra parentheses here are
whorthwile.
> Also I added
>
> concat('"(", appOrParen(x), '")")
>
> to powerOrParen and removed the special coding for unary minus in appOrParen.
>
Hmm, have you tried:
unparse(parse("sin(x)^2"))
AFAICS your change will produce extra parentheses here.
> 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)_
^^^ ^^^
This is source of the problem, this line should read:
not(SYMBOLP op) or GET(op, "Led") or GET(op, "Nud")_
> 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.
>
Whithout the change above you are still going to get wrong
results for complicated expressions.
--
Waldek Hebisch
[EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---