Suppose that we define UpValues for different symbols


I would like to make the following definition

func_?isSpecialFunction[]:= func[t,x]

such that every time I write e.g. func[] Mathematica substitutes it with func[t,x] only if isSpecialFunction[func]==True.

However, func_?isSpecialFunction[]:= func[t,x] is not a good definition because I get the error SetDelayed: "func_?isSpecialFunction[] does not contain a symbol to attach a rule to. What is the proper procedure to give the aforementioned definition for symbols with UpValues defined in this way?

Please, keep in mind that I want to use the fact that these symbols have UpValues. That's because I am using a package (xCoba), which defines ScalarFunctions with these UpValues and I want to substitute all the ScalarFunctions that appear as func[] with func[t,x].


1 Answer 1


isSpecialFunction[N1] ^= True;
isSpecialFunction[N2] ^= True;
isSpecialFunction[N3] ^= True;

Define a replacement RuleDelayed

rule = func_?isSpecialFunction[] :> func[t, x];

Add application of the rule to $Pre

$Pre := # /. rule &;


{N1[], N2[], N3[], N4[]}

(* {N1[t, x], N2[t, x], N3[t, x], N4[]} *)

To clear $Pre

$Pre =.
  • $\begingroup$ Thank you! I didn't know about $Pre! It's very useful! $\endgroup$
    – apt45
    Dec 5, 2020 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.