#2392 is (equal (...)) with realpart

open
nobody
None
5
2012-11-18
2012-04-08
No

with 5.26.0 gcl (windows)

(%i1) display2d:false$

(%i2) bex : 1/sqrt(sin(x));
(%o2) 1/sqrt(sin(x))

(%i3) realpart(bex);
(%o3) cos(atan2(0,sin(x))/2)/sqrt(abs(sin(x)))

(%i4) imagpart(bex);
(%o4) -sin(atan2(0,sin(x))/2)/sqrt(abs(sin(x)))

(%i5) is (equal (bex, realpart(bex)));
(%o5) true <== wrong!

(%i6) is (equal (bex, imagpart(bex)));
(%o6) false <== correct

Here we also show that if a calling program (test)
gets the wrong "true" answer from is(equal(...)),
and then calls a subprogram (test1), an incorrect
evaluation of realpart(expr) is found in test1.

This occurs in both 5.26.0gcl and 5.25.1gcl.

program:

test1(bex) :=
block([bexr],
print (" test1 "),
print(" bex = ",bex),
bexr : realpart(bex),
print(" bexr = ",bexr),
bexr)$

test(aex) :=
block([aexr,ans1,isr],
print(" test "),
print(" aex = ",aex),

aexr : realpart(aex),
print(" aexr = ",aexr),

isr : is(equal(aex,realpart(aex))),
print(" isr = ",isr),

ans1 : test1(aex),
ans1)$

display2d:false$

demonstration of problem :

(%i1) load(test);
(%o1) "c:/work2/test.mac"

(%i2) test(1/sqrt(sin(x)));

test
aex = 1/sqrt(sin(x))
aexr = cos(atan2(0,sin(x))/2)/sqrt(abs(sin(x)))
isr = t

test1
bex = 1/sqrt(sin(x))
bexr = 1/sqrt(sin(x))
(%o2) 1/sqrt(sin(x))

(%i3) realpart(1/sqrt(sin(x)));
(%o3) cos(atan2(0,sin(x))/2)/sqrt(abs(sin(x)))

(%i4) is(equal(1/sqrt(sin(x)), realpart(1/sqrt(sin(x)))));
(%o4) true

(%i5) build_info();
Maxima version: 5.26.0
Maxima build date: 22:48 1/15/2012
Host type: i686-pc-mingw32
Lisp implementation type: GNU Common Lisp (GCL)
Lisp implementation version: GCL 2.6.8

Discussion

  • Barton Willis

    Barton Willis - 2012-06-11

    This is due to a bug in sign:

    (%i24) sign((sqrt(abs(sin(x)))-cos(atan2(0,sin(x))/2)*sqrt(sin(x)))/(sqrt(sin(x))*sqrt(abs(sin(x)))));
    (%o24) zero

    But (for example)

    (%i25) subst(x=4,(sqrt(abs(sin(x)))-cos(atan2(0,sin(x))/2)*sqrt(sin(x)))/(sqrt(sin(x))*sqrt(abs(sin(x)))));
    (%o25) 1/sqrt(sin(4))

     
  • Barton Willis

    Barton Willis - 2012-06-11

    Possible fix: in meqp-by-csign insert (clearsign) just before the first call to $csign.
    That doesn't fix the bug in sign mentioned in the first posting.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks