With SetAttributes[f, Flat], f[a_] can get matched to f of any number arguments. How can I make it that calling it with exactly one argument f[x] returns x?
I'm trying to have an operation just like NonCommutativeMultiply but without the "Possible Issues" it has. It is important to me that if the result of some simplification is a "product" of one term it is no longer treated as such.
I especially want to avoid infinite loops like
f[a_] := a
f[a__] /; AnyTrue[{a}, FreeQ[_Symbol]] := "free"
f[a, a]
$IterationLimit::itlim: Iteration limit of 4096 exceeded. >>
SetAttributes[f, Flat]afterf[a_] := a? – kglr Mar 10 '20 at 10:44