Bill Allombert on Mon, 02 Jan 2023 23:10:58 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Question on using eval...


On Mon, Jan 02, 2023 at 03:31:00PM -0600, wraithx@morpheus.net wrote:
> Hello,
> 
> I've run into an issue using the "eval" function.  I'm trying to check two
> expressions for symbolic equality.  But, I run into a problem when I use the
> exponent operator.  Is this a valid use for the eval function?  Is there
> another way to check if two expressions are equal?  Thank you for any help
> you can provide!

Dear David,

The eval function does not work like in Maple.
Writing 
? eval("something")
has the same effect as 
? something.
so it is not useful with string constants.

> gp > a
> %1 = a
> gp > b
> %2 = b
> gp > c
> %3 = c
> gp > eval("(a/b)+c == (a-b)+c")

 gp> (a/b)+c == (a-b)+c
 would do the same thing faster.

> %4 = 0
> gp > eval("(c-b)+a == (a-b)+c")
> %5 = 1
> gp > eval("(a^b)+c == (a-b)+c")
>   ***   at top-level: eval("(a^b)+c == (a-b)+c")
>   ***                 ^--------------------------
>   ***   in function eval: (a^b)+c==(a-b)+c
>   ***                       ^--------------
>   *** _^_: domain error in gpow [irrational exponent]: valuation != 0

PARI/GP definitionf of ^ is likely not what you want in this example.
For example try
 gp> (1+a)^b
%2 = 1+b*a+(1/2*b^2-1/2*b)*a^2+(1/6*b^3-1/2*b^2+1/3*b)*a^3+(1/24*b^4-1/4*b^3+11/24*b^2-1/4*b)*a^4+(1/120*b^5-1/12*b^4+7/24*b^3-5/12*b^2+1/5*b)*a^5+(1/720*b^6-1/48*b^5+17/144*b^4-5/16*b^3+137/360*b^2-1/6*b)*a^6+(1/5040*b^7-1/240*b^6+5/144*b^5-7/48*b^4+29/90*b^3-7/20*b^2+1/7*b)*a^7+(1/40320*b^8-1/1440*b^7+23/2880*b^6-7/144*b^5+967/5760*b^4-469/1440*b^3+363/1120*b^2-1/8*b)*a^8+(1/362880*b^9-1/10080*b^8+13/8640*b^7-1/80*b^6+1069/17280*b^5-89/480*b^4+29531/90720*b^3-761/2520*b^2+1/9*b)*a^9+(1/3628800*b^10-1/80640*b^9+29/120960*b^8-1/384*b^7+3013/172800*b^6-19/256*b^5+4523/22680*b^4-1303/4032*b^3+7129/25200*b^2-1/10*b)*a^10+(1/39916800*b^11-1/725760*b^10+1/30240*b^9-11/24192*b^8+683/172800*b^7-781/34560*b^6+31063/362880*b^5-7645/36288*b^4+16103/50400*b^3-671/2520*b^2+1/11*b)*a^11+(1/479001600*b^12-1/7257600*b^11+1/248832*b^10-11/161280*b^9+10831/14515200*b^8-1903/345600*b^7+242537/8709120*b^6-139381/1451520*b^5+341747/1555200*b^4-190553/604800*b^3+83711/332640*b^2-1/12*b)*a^12+(1/6227020800*b^13-1/79833600*b^12+19/43545600*b^11-13/1451520*b^10+1747/14515200*b^9-299/268800*b^8+314617/43545600*b^7-9607/290304*b^6+1148963/10886400*b^5-412009/1814400*b^4+128977/415800*b^3-6617/27720*b^2+1/13*b)*a^13+(1/87178291200*b^14-1/958003200*b^13+41/958003200*b^12-13/12441600*b^11+491/29030400*b^10-793/4147200*b^9+944311/609638400*b^8-112879/12441600*b^7+1666393/43545600*b^6-355277/3110400*b^5+9301169/39916800*b^4-9061/29700*b^3+1145993/5045040*b^2-1/14*b)*a^14+(1/1307674368000*b^15-1/12454041600*b^14+1/261273600*b^13-1/9123840*b^12+2747/1306368000*b^11-71/2488320*b^10+515261/1828915200*b^9-35717/17418240*b^8+899683/81648000*b^7-22463/518400*b^6+21939781/179625600*b^5-406841/1710720*b^4+30946717/103194000*b^3-1171733/5405400*b^2+1/15*b)*a^15+O(a^16)

if you do

? (1+a)^(b+1)==(1+a)^b + a*(1+a)^b
%4 = 1

you get something sensible, but the check was only done modulo a^16, so this is not a formal proof of the identity.

It is the same issue as with
? sqrt(6)==sqrt(2)*sqrt(3)
%5 = 1
(which is only checked to 38 digits by default)

a^b fail because this equal to exp(b*log(a))
but log does not have a power series expansion at 0.

Cheers,
Bill.