1
$\begingroup$

Suppose that we define UpValues for different symbols

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

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].

$\endgroup$
1
$\begingroup$
Clear["Global`*"]

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 &;

Testing,

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

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

To clear $Pre

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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