Ideas
Follow


Would a General Hold/Release Functionality be a Good Feature for the Symbolic Toolbox?

Paul on 12 Dec 2024
Latest activity Reply by Walter Roberson on 15 Dec 2024

The int function in the Symbolic Toolbox has a hold/release functionality wherein the expression can be held to delay evaluation
syms x I
eqn = I == int(x,x,'Hold',true)
eqn = 
which allows one to show the integral, and then use release to show the result
release(eqn)
ans = 
I think I already submitted an enhancement request for the same functionality for symsum.
Maybe it would be nice to be able to hold/release any symbolic expression to delay the engine from doing evaluations/simplifications that it typically does. For example:
x*(x+1)/x, sin(sym(pi)/3)
ans = 
ans = 
If I'm trying to show a sequence of steps to develop a result, maybe I want to explicitly keep the x/x in the first case and then say "now the x in the numerator and denominator cancel and the result is ..." followed by the release command to get the final result.
Perhaps held expressions could even be nested to show a sequence of results upon subsequent releases.
Held expressions might be subject to other limitations, like maybe they can't be fplotted.
Seems like such a capability might not be useful for problem solving, but might be useful for exposition, instruction, etc.
Walter Roberson
Walter Roberson on 12 Dec 2024
x*(x+1)/x
When passed that expression as a parameter, the first thing MATLAB is going to do is evaluate that expression. Evaluation of the expression inside the symbolic toolbox is going to result in the x in the numerator and denominator canceling out. This is going to happen before any function being called gets control. For example, a hypothetical
hold(x*(x+1)/x)
is going to evaluate x*(x+1)/x first and pass the result to hold() . By which time it would be too late.
What could potentially work is something along the lines of
hold(x*(x+1))/x
Paul
Paul on 12 Dec 2024
Do you think it would be useful if it could be implemented?
Walter Roberson
Walter Roberson on 15 Dec 2024
I have sometimes wished for hold() -- but in a fairly different context. The context is the processing of symbolic expressions, typically by pattern matching. For example for extending the functionality of int() by matching a particular pattern and coding the solution to that pattern. It is common when processing symbolic expressions that you want to hold() a partial result. For example you might want to hold(x^3+x^2+x+1) to prevent a (-x) from acting on it immediately so that you can factor() the x^3 expression.

Tags

No tags entered yet.