2
$\begingroup$

I have an object in mathematica with the attributes Flat and OneIdentity. I also defined the following substitutions:

A[z___, x_Times /; ! FreeQ[x, b], y___] := 
 A[z, A@@ x, y]
A[z___, x_Plus /; ! FreeQ[x, b], y___] := 
 A[z, #, y] & /@ (x)

I need them so that all products inside A become part of the arguments of A, and the distributive property with respect to the sum holds.

I need to find a way to remove all the arguments that do not contain b pattern.

I tried with A[z___, a_?(FreeQ[#, b] &), y___] := a A[z, y] , but I get IterationLimit error.

I understand that the reason of the error is that mathematica will match A[a] as a with flat operators. But then what is the correct way to do that, in such a way that is compatible with the previous two conditions?

$\endgroup$

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.