I have defined the CirclePlus operator as follows:

SetAttributes[CirclePlus, {Orderless, Flat, OneIdentity}];
CirclePlus[a_ : Except[_CirclePlus]] := a;
CirclePlus[a_?MatrixQ, b_?MatrixQ, c___] := CirclePlus[Plus[a, b], c]
CirclePlus[a_?VectorQ, b_?VectorQ, c___] := CirclePlus[Plus[a, b], c]
CirclePlus[a_?MatrixQ, b_?NumberQ, c___] := 
 CirclePlus[Plus[a, DiagonalMatrix[Table[b, Length[a]]]], c]

Yet, it does not work as expected for the single argument case:

In: CirclePlus[1]
Out: CirclePlus[1]

I expected Out: 1. If I remove the Except[_CirclePlus], I get recursion errors for other operations, but get the desired result in the above case. How can I solve this issue?

Note: Changing it to the in the comments suggested

CirclePlus[a : Except[_CirclePlus]] := a;

Leads to an infinite recursion again:

Message[$IterationLimit::itlim, 4096]


Browse other questions tagged or ask your own question.