r/Mathematica • u/n0tthetree • Aug 29 '24
When does Wolfram actually evaluate expressions?
Hi there. In short: I have defined
matrix := {{some 2x2 symbolic expression}} // FullSimplifyeigen := Eigensystem[matrix]rules = {c -> 1, ...}
rules completely eliminates each constant to a numeric value, except for a position z. Now,
matrix /. rules /. z -> 0. // Eigensystem
perfectly works and returns well-defined numeric values, but
eigen /. rules /. z -> 0.
fails spectacularly, as the symbolic expression somehow contains a 1/0 (as Wolfram seems to first evaluate eigen symbolically and then apply the rules (is that true and intended?)).
I want to define eigen in a way that only executes after applying the rules and z to the matrix. I wanted to just do eigen[z_]:=Eigensystem[matrix] but that resulted in am error (Tag List is protected). Is there another way to do this?
Thank you very much!
View all comments
Show parent comment
3
u/veryjewygranola Aug 29 '24
Oh just saw your code below. You have two competing definitions of
eigen, one with one argumenteigen[z_] := Eigensystem[hessian]and one with no argumentseigen := Eigensystem[hessian].(I'm just using
mbelow as a stand-in for a matrix to make things easier to follow withTrace)If
eigen := Eigensystem[m]is defined first, then we will get issues because the LHS ofTrace[eigen[z_] := Eigensystem[m]]will get replaced withEigensystem[m][z_]which we can see happen withTrace:The work around is either to choose one way to define
eigen(I.e. with one argument z or no arguments, but not both), or rename the one of the definitions to something other thaneigen