Post Reply 
CAS: overriding HOME variables, bug or feature? (for me, a feature!)
07-09-2021, 10:43 PM (This post was last modified: 07-09-2021 11:09 PM by ramon_ea1gth.)
Post: #1
CAS: overriding HOME variables, bug or feature? (for me, a feature!)
I was preparing a different post when I found this, that for me, it’s a cool feature.

While in CAS, enter, for example, this expression with single quotation marks (to avoid evaluation):
‘Z:=Z0·exp(i·β·z)’

Look at the symbols used: Z and Z0 are HOME vars, with predefined values, the first one typed as real and the second one, as complex. But for me, as engineer, the meaning is they are impedances (complex values), while z is a distance. So I would like to use these names when working in CAS to perform symbolic manipulations.

Now select by touching the quoted expression and press the soft-key simplify. The same effect is obtained by entering:
simplify(‘Z:=Z0·exp(i·β·z)’)

Now it happens! Z is converted into a CAS variable, overriding the HOME variable Z typed as real (great! I can save my own expression with the name I like!).

Next interesting step: now I want to assign a value to Z0, different from the HOME variable (and even a different type). So go and enter:
simplify(‘Z0:=50’)

So here you are! Now Z0 has a value of 50, different from the contents of the HOME variable Z (go to the HOME environment and check it). These new variables, Z and Z0 are displayed as CAS variables when pressing the VAR key.

So now, if you enter Z, the calculator retrieves the contents of Z, i.e., Z0·exp(i·β·z), but evaluated. Then, if you change the value of Z0, the retrieved value of Z will also change, as the internal expression Z0·exp(i·β·z) is evaluated.

The matter is that I wanted to be able to override HOME variables so I could use standard symbols that sometimes match the HOME variable names, as proposed in this post:
https://www.hpmuseum.org/forum/thread-16057.html

So I like this behaviour. Thus, in case the developers decide to change this behaviour, please, consider including an option in the CAS settings to disengage HOME variables from the CAS environment, as this find shows it is possible and it would be very useful to manipulate symbolic expressions that include any kind of symbols (even those used as names of HOME vars).

Enjoy the find!

(Edited: minor change to have a non-zero value of Z0 before retrieving Z).

Ramón
Valladolid, Spain
TI-50, Casio fx-180P, HP48GX, HP50g, HP Prime G2
Visit this user's website Find all posts by this user
Quote this message in a reply
07-11-2021, 02:05 PM
Post: #2
RE: CAS: overriding HOME variables, bug or feature? (for me, a feature!)
(07-09-2021 10:43 PM)ramon_ea1gth Wrote:  simplify(‘Z:=Z0·exp(i·β·z)’)

Now it happens! Z is converted into a CAS variable, overriding the HOME variable Z typed as real

If you do use simplify "feature", I suggest create CAS variables first.
This documented what HOME variables are being overrided.

CAS> simplify('[Z, Z0] := [0, 100]')
CAS> Z := Z0 * exp(i*β*z)

However, I would advise against doing this. With Undefined Behavior, Anything is Possible

Quote:(Edited: minor change to have a non-zero value of Z0 before retrieving Z).

Besides using undefined-behavior, Z0 cannot be symbolic, thus the need to assign it something.
(all overrided HOME variables have the same problem)

It might be safer to add a character before capitalized name.

We could use hard-space, " ", but that is just asking for trouble ...
On HP Prime emulator, I use "%". (maxima also use %, %i = √-1, %e = 2.718281828...)

CAS> %Z := %Z0 * exp(i*β*z)
CAS> diff(%Z, %Z0)                 // %Z0 is true variable

e^(i*β*z)

It would be nice if HP Prime truly separate HOME and CAS variables.
Find all posts by this user
Quote this message in a reply
07-11-2021, 10:17 PM (This post was last modified: 07-12-2021 12:09 PM by ramon_ea1gth.)
Post: #3
RE: CAS: overriding HOME variables, bug or feature? (for me, a feature!)
Dear Albert

As usual, your post is worth each line. So I would like to remark this, as I share it:
Quote:However, I would advise against doing this. With Undefined Behavior, Anything is Possible
(by the way, I like the image with the unicorn and the stuff around: you can feel the crazyness).

Said this, I will continue being naughty. I was thinking about a workflow to ‘properly’ use this ‘feature’ (unicorn flying around). My goal: doing some symbolic manipulations and afterwards, obtaining a numeric result. So this would be my way:
  • Use always single quoted ‘ ‘ expressions to avoid evaluation.
  • Apply Select&Simplify, by selecting the quoted expression and pressing the soft-key [simplify].
  • When symbolic operations are finished, initialize all the required variables with := and use the ‘overriding’ feature.

Example:
Code:

CAS> ‘Z = Z0 * exp(i*β*z)’                                // Example with quotation marks
Ans: Z = Z0 * exp(i*β*z)                                   // Output is not evaluated
CAS> ‘subst(Z = Z0 * exp(i*β*z),β=2*π/λeff)’    // Example of symbolic manipulation with quotation marks.
Ans: subst(Z = Z0 * exp(i*β*z),β=2*π/λeff)       // Output is not evaluated
CAS> simplify(‘subst(Z = Z0 * exp(i*β*z)),β=2*π/λeff’)            // Entered after Select&Simplify
Ans: Z = Z0 * exp(2*i*π*z/λeff)                        // Symbolic operation done. Now ready to give numbers
CAS> simplify('[Z, Z0] := [0, 100]')  // Initialize & override HOME variables
Ans: [0, 100]
CAS> Z := 'Z0 * exp(2*i*π*z/λeff)'      // Save Z with unevaluated contents
Ans: Z0 * exp(2*i*π*z/λeff)
CAS> [λeff, v, z, f, c] := [v/f, 0.66*c, 1, 1e9, 3e8]  // Initialize the rest of the variables as usual
Ans: [v/f, 0.66*c, 1, 1e9, 3e8]
CAS> Z                                        // Let's evaluate Z to obtain the numeric result we were looking for
Ans: 95.01+31.20*i

Now I feel like stealing some chocolates from the cupboard while the HP Prime parents are away. I will try to put an innocent face when they come back and ask ‘what were you doing??’ :-)

Quote: It would be nice if HP Prime truly separate HOME and CAS variables.

I agree. Let's hope it is in the roadmap to avoid these unicorns.

Edited. This line in the code:
CAS> Z := 'Z0 * exp(2*i*π*z/λeff)' // Save Z with unevaluated contents
was originally this way, but it was too much feature abuse:
CAS> simplify('Z := Z0 * exp(2*i*π*z/λeff)') // Save Z with unevaluated contents

Ramón
Valladolid, Spain
TI-50, Casio fx-180P, HP48GX, HP50g, HP Prime G2
Visit this user's website Find all posts by this user
Quote this message in a reply
07-12-2021, 01:43 PM (This post was last modified: 07-12-2021 01:43 PM by Albert Chan.)
Post: #4
RE: CAS: overriding HOME variables, bug or feature? (for me, a feature!)
(07-11-2021 02:05 PM)Albert Chan Wrote:  It would be nice if HP Prime truly separate HOME and CAS variables.

After some thought, separation of HOME and CAS variable may break old code.
A better way is patch code *only* for display purpose. Say, ZZ → Z

if we type "ZZ := ZZ0 * exp(i*β*z)", output as "Z := Z0 * exp(i*β*z)"
Find all posts by this user
Quote this message in a reply
07-12-2021, 02:07 PM
Post: #5
RE: CAS: overriding HOME variables, bug or feature? (for me, a feature!)
Quote:After some thought, separation of HOME and CAS variable may break old code.
I understand this point. Another option, as not everybody will need this feature, is to include an option in the CAS Settings to override HOME vars, not active by default.

Ramón
Valladolid, Spain
TI-50, Casio fx-180P, HP48GX, HP50g, HP Prime G2
Visit this user's website Find all posts by this user
Quote this message in a reply
01-20-2023, 03:10 AM (This post was last modified: 01-20-2023 03:16 AM by jte.)
Post: #6
RE: CAS: overriding HOME variables, bug or feature? (for me, a feature!)
(07-11-2021 02:05 PM)Albert Chan Wrote:  
It might be safer to add a character before capitalized name.

We could use hard-space, " ", but that is just asking for trouble ...
On HP Prime emulator, I use "%". (maxima also use %, %i = √-1, %e = 2.718281828...)

I've added a few posts recently regarding the handling of invisible characters by the HP Prime's parser for its built-in language (https://www.hpmuseum.org/forum/thread-99...#pid168514 , https://www.hpmuseum.org/forum/thread-80...#pid168515 , https://www.hpmuseum.org/forum/thread-16...#pid168516).

When I copied and pasted a chunk of the post I'm replying to, the Unicode viewer I used reported a standard space (U+0020) as being what was within the quotes; I'm guessing another code point was intended.

The recent change (that of revision 14638) rules out the use of typical whitespace code points (namely, code points U+00A0, U+1680, U+2000 … U+200A, U+202F, U+205F, and +U3000) from being used in identifiers — just as the standard space (U+0020) itself is. So, yes: “that is just asking for trouble”.

% can still be used as the first letter of an identifier.
Find all posts by this user
Quote this message in a reply
01-20-2023, 06:13 AM
Post: #7
RE: CAS: overriding HOME variables, bug or feature? (for me, a feature!)
Bonjour

Concernant cette mise à jour 14638, celle-ci est elle accessible ?
ou le sera-t-elle bientôt ?

Hello

Concerning this update 14638, is it accessible?
or will it be available soon?

Sorry for my english
Find all posts by this user
Quote this message in a reply
01-20-2023, 08:37 AM
Post: #8
RE: CAS: overriding HOME variables, bug or feature? (for me, a feature!)
(01-20-2023 06:13 AM)Tyann Wrote:  Bonjour

Concernant cette mise à jour 14638, celle-ci est elle accessible ?
ou le sera-t-elle bientôt ?

Hello

Concerning this update 14638, is it accessible?
or will it be available soon?

Tyann,

Thank you for posting. I now see that my mentioning a specific revision number could be misleading. I apologize for any confusion. I mentioned the specific revision number as there was a change in the parser (even if the change is very focused, and one that shouldn’t affect the vast majority of programs — perhaps even none in actual use [i.e., beyond little experiments by users to test / explore the boundaries of the system]); versions with greater revision numbers would include this change.

There is no public release; the revision number in this case only refers to an internal development version.

Jeff

* * *

Tyann,

Merci d’avoir posté. Je vois maintenant que ma mention d’un numéro de révision spécifique pourrait être trompeuse. Je m’excuse pour toute confusion. J’ai mentionné le numéro de révision spécifique car il y a eu un changement dans l’analyseur syntaxique (même si le changement est très ciblé et ne devrait pas affecter la grande majorité des programmes - peut-être même aucun qui est réellement utilisé [c'est-à-dire, au-delà de petites expériences par les utilisateurs pour tester / explorer les limites du système]) ; les versions avec des numéros de révision plus grands incluraient aussi ce changement.

Il n’y a pas de version publique ; le numéro de révision dans ce cas ne fait référence qu’à une version de développement interne.

Jeff
Find all posts by this user
Quote this message in a reply
Post Reply 




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