Post Reply 
HP-50g Local variable and Global variable confusion
04-10-2017, 10:30 AM
Post: #4
RE: HP-50g Local variable and Global variable confusion
Thank you for your replies.

Yes, I knew about compiled local variables, but I didn't realize that they where automatic compiled do LAMs. But their name are awkward

Also I didn't remember DEFINE, but this mean defining a new function, when I'm inside one (I'll try to explain what I'm trying to do)

I was investigating the HP50g programming model which is interesting because it is unusual. But as the same time it is so confusing

What I was try to do, was to explore the IFTE bug in the Plot functions, in hp50g version 2.15. I'm writing the following code by memory, so there may be errors

the following function
Y1(X) = IFTE(X>=0, X^2, COS(X)) donĀ“t plot because of the IFTE bug

So I changed the IFTE into a custom function, MYIF:
Y1(X) = MYIF(X>=0, X^2, COS(X))

<< -> T V1 V2 << T V1 V2 IFTE >> >> 'MYIF' STO

The above don't plot either. But I could see what was going on, by logging:

{} 'log' STO
<< -> T V1 V2 << log T + V1 + V2 + 'log' STO T V1 V2 IFTE >> >> 'MYIF' STO

I realize that the plot system invoke the function with X as an argument, and if the result is an algebraic it will use that algebraic and never call the function again. I guess this speed up the plotting. The above function was called only once because it return an algebraic, 'IFTE(...,...,...)' and the bug still exists

So I changed to: (removed the log part)
<< -> T V1 V2 << IF T THEN V1 ELSE V2 END >> >> 'MYIF' STO

This new MYIF function errors when T cannot be evaluated, so the plot system realized that the function has to be called for every X. But this function plots correctly but it is quite slow

So I wanted the above MYIF function not to error when X was used as an argument, but to return a special version of it, in algebraic form, that the plot system could then plot directly and correctly

So I changed it to, or to something similar to this:

<< -> T V1 V2 << IFERR

I realize the above didn't work out, I dont remember what happend, but I think T, V1, V2 weren't replaced inside the algebraic, so I tried to use EVAL, and the algebraic errored...

The only way I managed it to work was to use a string, something like this:
<< -> T V1 V2 << IFERR
"'IFTE(" T + "," + V1 + "," V2 + ")" + STR->

This returned the algebraic correctly, but in some situations was returned like this:
'IFTE(...,...,...) | (X=X)'. I don't remember when this happen

When this was latter plotted it plotted random numbers. This is confusing, and was related to the | operator.
Investigating a little more (I created another function MY2IF - similar to MYIF - , to work simultaneous with the MYIF: First MYIF was called by the plot System, with X as argument. MYIF return the following algebraic 'MY2IF(...,...,..)'. This, I don't know why is transformed into 'MY2IF(...,...,...)|(X=X)". Then the plot system invoke this new function MY2IF. But a random number appear in place of X.
MY2IF received the following argument as T: '0.51453455'>=0
V1: '0.51453455' ^2
V2: COS('0.51453455')
I realize this is the way the | operator work. It uses a random number as the substituting value. But it is not a number, it is a symbol whose name is a number, decompiling T : ID 0.51453455 %0 x>=
so the number is treated as a symbol and it don't return true of false when evalutated
At the end of the function the OS replaces the value 0.51453455 with the correct value

Opening a parethesis:
the way the | operator work: imagine the following simple function << -> X <<X^2>>>> 'F' STO
now call 'F(X)|(X=W)' EVAL
put some HALT happen
inside F, X is not W, but it is for example '.4533232' (a symbol, not a number). then it is squared: '.4533232 ^2'
This algebraic is returned at the end, but on the stack appears W^2... this suggest that the OS change the "number" correctly to "W"
End of parenthesis

Returning to MY2F: then T is evaluated, it will error and the error trap returned a string 'MY2IF( 0.51453455>=0, '0.51453455^2, COS(0.51453455))'
so the random symbol name is plotted like a number...

So I want if to be able to create an algebraic but keeping '0.51453455' as a symbol, not a number...lolol
What a mess...lolol
Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: HP-50g Local variable and Global variable confusion - rui.c.sousa.99 - 04-10-2017 10:30 AM

User(s) browsing this thread: 1 Guest(s)