# CAS integration bug - Hewlett Packard

This is a discussion on CAS integration bug - Hewlett Packard ; Here's a strange CAS bug I ran across in class this week. Set the calculator in EXACT, REAL, RECTANGULAR modes Put the following on the stack: 4: 0 3: pi 2: 'SIN(X)^3' 1: 'X' Do a definite integral (RS-TAN). You ...

1. ## CAS integration bug

Here's a strange CAS bug I ran across in class this week.

Set the calculator in EXACT, REAL, RECTANGULAR modes
Put the following on the stack:

4: 0
3: pi
2: 'SIN(X)^3'
1: 'X'

Do a definite integral (RS-TAN). You should get 4/3 which is the

Press UNDO and switch the mode from RECTANGULAR to either CYLINDRICAL
(Polar) or SPHERICAL and do the definite integral again. I get 3/2,
and REAL mode has changed to COMPLEX.

Press UNDO again redo the same integral without changing anything and
you get 4/3 again. The difference seems to be that the calculator in
now in COMPLEX mode.

Interestingly, it does not have this behavior when using the symbolic
expression 'integral(0,pi,SIN(X)^3,X)' or entering it in ALG mode.

If using RISCH or INTVX on 'SIN(X)^3', you get a different symbolic
result for each of the four combinations of REAL/COMPLEX mode and RECT/
CYLIN mode. Three of the four are equivalent and are correct, but the
REAL/CYLIN combination gives a different, incorrect result.

Anybody know what's going on here?

-wes

2. ## Re: CAS integration bug

On Apr 15, 2:23*pm, Wes wrote:
> Set the calculator in EXACT, REAL, RECTANGULAR modes
> Put the following on the stack:
>
> 4: 0
> 3: pi
> 2: 'SIN(X)^3'
> 1: 'X'
>
> Do a definite integral (RS-TAN). *You should get 4/3 which is the

Interesting, but I can't duplicate this on my 49G+ with v2.09. The
calc switches to approximate mode and I get 1.33... in all versions
except complex. Are there some flag settings that might be affecting
this?

Regards,
Bill

3. ## Re: CAS integration bug

On Apr 17, 4:49 pm, Bill Markwick wrote:
> On Apr 15, 2:23 pm, Wes wrote:
>
> > Set the calculator in EXACT, REAL, RECTANGULAR modes
> > Put the following on the stack:

>
> > 4: 0
> > 3: pi
> > 2: 'SIN(X)^3'
> > 1: 'X'

>
> > Do a definite integral (RS-TAN). You should get 4/3 which is the

>
> Interesting, but I can't duplicate this on my 49G+ with v2.09. The
> calc switches to approximate mode and I get 1.33... in all versions
> except complex. Are there some flag settings that might be affecting
> this?
>
> Regards,
> Bill

I've got the same ROM on my 50g. I get the same results with EMU48
with the 2.09 emulator ROM. I don't have my 50g in front of me, but
my EMU flags are:

{ # 700000820521CFF0h # 101h # 89010020A000000h # 0h }

-wes

4. ## Re: CAS integration bug

On Apr 17, 11:28*am, Wes wrote:
> On Apr 17, 4:49 pm, Bill Markwick wrote:
>
>
>
>
>
> > On Apr 15, 2:23 pm, Wes wrote:

>
> > > Set the calculator in EXACT, REAL, RECTANGULAR modes
> > > Put the following on the stack:

>
> > > 4: 0
> > > 3: pi
> > > 2: 'SIN(X)^3'
> > > 1: 'X'

>
> > > Do a definite integral (RS-TAN). *You should get 4/3 which is the

>
> > Interesting, but I can't duplicate this on my 49G+ with v2.09. *The
> > calc switches to approximate mode and I get 1.33... in all versions
> > except complex. *Are there some flag settings that might be affecting
> > this?

>
> > Regards,
> > Bill

>
> I've got the same ROM on my 50g. *I get the same results with EMU48
> with the 2.09 emulator ROM. *I don't have my 50g in front of me, but
> my EMU flags are:
>
> { # 700000820521CFF0h # 101h # 89010020A000000h # 0h }
>

Hi. I installed your flags and managed to duplicate the oddity.
However, it turned out that it wasn't the flags at all - it was the
fact that I had entered pi as a number, which made the calc revert to
Approximate mode. Once I changed it to a symbol it behaved as you
described it.

I'm not sure what's going on. I'll experiment with it tonight.

Bill

5. ## Re: CAS integration bug

After some tinkering, I found you could boil it down to the fact that
in cylindrical or spherical mode (plus Real mode), you get different
answers from the stack version and the algebraic expression version.
Another symptom is that the calculator doesn't switch from Real to
Complex until the calculation is over. If you switch to Complex before
you start, the problem doesn't come up.

And just to confuse things further, it only happens if the exponent of
SIN(X) is an odd number. Try it with any even exponent and it works
fine.

This is a peculiar one.

Bill

6. ## Re: CAS integration bug

On Apr 19, 4:11 pm, Bill Markwick wrote:
> After some tinkering, I found you could boil it down to the fact that
> in cylindrical or spherical mode (plus Real mode), you get different
> answers from the stack version and the algebraic expression version.
> Another symptom is that the calculator doesn't switch from Real to
> Complex until the calculation is over. If you switch to Complex before
> you start, the problem doesn't come up.
>
> And just to confuse things further, it only happens if the exponent of
> SIN(X) is an odd number. Try it with any even exponent and it works
> fine.
>
> This is a peculiar one.
>
> Bill

Yes, it is peculiar. And equally peculiar that no one has noticed it
before. (At least I could not find any reference to it either here or
bugs.hpcalc.org) It seems a rather common integral to have such a
problem.

I finally had some time to sit and play with it a bit. The problem
affects both sine and cosine raised to any integer power (odd or even)
greater than 1. The reason it showed up only with odds in the my
earlier example was because the limits 0 to pi make the error drop out
for even powers.

For example, in REAL/CYLIN modes, << 'SIN(X)^2' INTVX >>
incorrectly returns '-1/(4*EXP(i*(pi/2)))*COS(2*X)+X/2'
which simplifies to 'i/4*COS(2*X)+X/2'.

The other three mode combinations (REAL/RECT, COMPLEX/RECT, COMPLEX/
CYLIN) each give different, albeit equivalent, results.

REAL/RECT:
'-(1/4*SIN(2*X))+X/2'

COMPLEX/RECT:
'-(i/8*EXP(-(2*i*X)))+-2*X/(2*i*(2*i))+i/8*EXP(2*i*X)'

COMPLEX/CYLIN: '-1/(8*EXP(-(i*(pi/2))))*EXP(2*EXP(-(i*(pi/2)))*X)+-2*X/
(2*i*(2*i))+-1/(8*EXP(i*(pi/2)))*EXP(2*EXP(i*(pi/2))*X)'

I don't see anything in the User's Guide or the AUR about flag
settings with INTVX. It appears that something like TSIMP is used,
causing the following expansions to be made:

COMPLEX/RECT:
SIN(X) becomes '(EXP(i*X)-1/EXP(i*X))/(2*i)'.
This is equivalent to the identity: 'SIN(X)=SINH(i*X)/i'.

COMPLEX/CYLIN:
Same as COMPLEX/RECT, but each 'i' is replaced with 'EXP(i*pi/2)'.
So 'EXP(2*i*X)' becomes 'EXP(2*EXP(i*pi/2)*X'.

I find it very interesting that when in REAL/CYLIN mode,
<< 'SIN(X)^2' INTVX >> returns an incorrect result, while
'INTVX(SIN(X)^2)' returns the correct result.
Any ideas what would cause this discrepancy?

-wes