TransWikia.com

How can I set a certain predicate for the result of a function to true?

Mathematica Asked by NG98 on February 28, 2021

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.

2 Answers

As Simon Woods suggested,

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

works.

Correct answer by NG98 on February 28, 2021

ClearAll["Global`*"]

Use TagSetDelayed to associate the property with f

MemberQR /: MemberQR[f] := True;

fooFunction[g_?MemberQR] := 2 g;

Testing

fooFunction /@ {f, g}

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

EDIT:

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

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

(* {True, MemberQR[fooFunction[g]]} *)

Answered by Bob Hanlon on February 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP