0
$\begingroup$

I'm having problems setting an upvalue for a symbol that is supposed to ignore Inactive:

IgnoringInactive[f[g[x]]] ^:= match;

Then for some reason, this fails to match:

f[Inactive[g][x]]

enter image description here

I also tried TagSet, as in g /: IgnoringInactive[f[g[x]]] := match but that didn't work either.

What is the intended way to assign a rule to g while ignoring possible Inactive wrapper around g?

$\endgroup$
  • $\begingroup$ Since g is inactive, no rules associated with it are used. What about tag set for f? $\endgroup$ – Kuba May 27 '18 at 19:50
  • $\begingroup$ It does set an upvalue, but perhaps @Kuba is saying that the upvalue is not invoked, so you don't get the result of f[Inactive[g][x]] /. UpValues[g], which yields match. I think it's worth reporting to WRI. Either you should get the result or the attempt to set the upvalue should give an error. Or at worst, there could be this sort of example added to the possible issues section of the docs for IgnoringInactive. $\endgroup$ – Michael E2 May 27 '18 at 20:48
  • 1
    $\begingroup$ To add my take on Kuba's comment: The upvalue is not invoked because g is too deep in the expression f[Inactive[g][x]]. When reaching g, the evaluator looks for upvalue matching Inactive[g], of which there isn't one. So it goes on its merry way. It wasn't redesigned to go up one more level in the case when it gets Inactive[symbol] to see if there are IgnoringInactive upvalue rules that match. But that's just guess. $\endgroup$ – Michael E2 May 27 '18 at 20:51
  • $\begingroup$ @MichaelE2 I think it is correct though it could be confusing at first. My opinion is that example is not a use case for IgnoringInactive. I would arguee with error on set upvalue because Inactive[f][g[x]] will be matched well. $\endgroup$ – Kuba May 27 '18 at 20:52
  • $\begingroup$ @MichaelE2 about your second comment, I didn't thought about this and it makes more sense. I should probably delete my previous comments. $\endgroup$ – Kuba May 27 '18 at 20:54

Your Answer

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

Browse other questions tagged or ask your own question.