I am currently working on library that keeps functions in unevaluated form, e.g.
In: a = RhoVariable[s]
Out: RhoVariable[s]
RhoVariable has some definition, namely (2-Sqrt[4-s])/(2+Sqrt[4-s]) and I want to be able to convert it to that form using Normal[ (*some object containing RhoVariable*) ].
Well, I can do that defining and UpValue for it:
RhoVariable/:Normal[RhoVariable[z_]] := (2-Sqrt[4-z])/(2+Sqrt[4-z]);
which works fine if I put it very explicitly
In: Normal[RhoVariable[t]]
Out: (2-Sqrt[4-t])/(2+Sqrt[4-t]);
but not in any other case
In: Normal[2 RhoVariable[t]]
Out: 2 RhoVariable[t]
and specifying Head does not change anything, not to mention is kinda not what I want, cos the usage of all Heads I'll have to convert later in development.
In: Normal[2 RhoVariable[t], RhoVariable]
Out: 2 RhoVariable[t]
How to make it behave like I expect (= change any occurrence of RhoVariable to expression inside normal blocks, kinda like instead of every Normal[ (*expressions with RhoVariables*) ] I'd invoke (*expressions with RhoVariables*) /. RhoVariable[z_]] :> (2-Sqrt[4-z])/(2+Sqrt[4-z]);
RhoVariablehas no definition. There will be loads of compositions and my goal was overloading "Normal" to make it possible to get maths formulas from these expression when possible. – fqrt Mar 16 '22 at 10:57RhoVariablein the final expression though! So do all your symbolic computation with undefinedRhoVariablethen, when you are done, usefinalResult /. RhoVariable[t_] :> (2-Sqrt[4-t])/(2+Sqrt[4-t])? You could package that up in a named transformation rule if you like. – MarcoB Mar 16 '22 at 15:48