Prevent TI BASIC expression expansion

279 views Asked by At

I'm coding a function for my TI-Nspire CAS calculator. I have two parts of an expression: (x+2)^2 and +3. When the expressions are joined the result is expanded to x^2+4x+7 while I need it to remain as (x+2)^2+3.

I've tried making both parts strings and them converting them back to expressions after joining but, this results in the same unwanted expansion.
The best I can do is return the two strings (each term) concatenated, which is gosh ugly: "(x+2)^2" + "3"

Is there anyway to prevent this expansion?
It undermines the entire function (which completes the square)!

For the record, the expression is expanded even if concatenated with a string.

(x+2)^2 + "3"  

returns

x^2 + 2x + "3" + 4  

(which I found really bizarre)

1

There are 1 answers

0
soegaard On

What you are seeing here is the automatic simplifier at work. And that means there is no easy way to turn it off.

In most symbolic algebra systems (x+1)^2 and (x+1)^2+3 are not automatically expanded. NSpire however gladly expands the latter. There are no way to prevent this behaviour.

In Mathematica one can write Hold(expr) in order to signal, that expr should not be simplified - that functionality is missing from NSpire however.

In some sense you have found the weak spot of NSpire: symbolic manipuation of expressions (as an example: there is no way to define functions using pattern matching). [When compared to Mathematica, Maple, Maxima etc.]

What the best work-around is depends on what you are trying to do with the expressions. If it is part of an algorithm, you could represent a sum expression as a list of terms. That requires you write custom functions to perform sums , products, etc.