I have an object called f (basically a vector of functions) and a predicate called MemberQR(actually its with subscript R).

MemberQR[f]:=True I.e. I set the predicate to true.

Now I want to apply a Transformation on f, and the result still should have the predicate set to True.

So for fooFunction[f_?MemberQR]:= 2 f; the result should also yield true when tested for MemberQR.

Of course, I do not know what exactly the components of f are, they might be different each time.

I have tried the use of % but was not sucessful. fooFunction is not supposed to produce output, it just transforms f.

  • $\begingroup$ You may represent your object by a list. The first n elements are your functions, and the last element the predicate. Then you must define MemberQR and fooFunction so that they take this object as input. Note, if you want to define MemberQR[f_] so that it changes f, you must use the attribute HoldFirst or HoldAll. More niftly, you may even define an indexed variable like: myObject[fun1,fun2,..,predicate] $\endgroup$ Jan 4, 2021 at 21:33
  • $\begingroup$ Can you just set another rule for MemberQR as a side effect of fooFunction? eg fooFunction[f_?MemberQR] := Module[{res = 2 f}, MemberQR[res] = True; res] $\endgroup$ Jan 4, 2021 at 21:39
  • $\begingroup$ @DanielHuber I cannot modify 'f', I can only modify fooFunction. $\endgroup$
    – NG98
    Jan 4, 2021 at 22:49
  • $\begingroup$ @SimonWoods your suggestion looks good, I will see, if I can modify this for my needs. $\endgroup$
    – NG98
    Jan 4, 2021 at 22:49

2 Answers 2


Use TagSetDelayed to associate the property with f

MemberQR /: MemberQR[f] := True;

fooFunction[g_?MemberQR] := 2 g;


fooFunction /@ {f, g}

(* {2 f, fooFunction[g]} *)


MemberQR /: MemberQR[fooFunction[f_?MemberQR]] := True

MemberQR[fooFunction[#]] & /@ {f, g}

(* {True, MemberQR[fooFunction[g]]} *)
  • $\begingroup$ Does not work for me. MemberQR[2f] is not True. $\endgroup$
    – NG98
    Jan 5, 2021 at 17:00
  • $\begingroup$ That is not the problem that you described. If you also want to handle multiples of f use MemberQR /: MemberQR[a_. * f] := True; $\endgroup$
    – Bob Hanlon
    Jan 5, 2021 at 17:22
  • $\begingroup$ What I tried to express in the question post is, that MemberQR[fooFunction[f]] should be true, whenever MemberQR[f] is true. $\endgroup$
    – NG98
    Jan 5, 2021 at 18:25

As Simon Woods suggested,

fooFunction[f_?MemberQR] := Module[{res = 2 f}, MemberQR[res] = True; res]



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.