5
$\begingroup$

I'm a bit lost with the way how e.g. the + operator is implemented in Mathematica as binary (infix) and unary (prefix) operator depending on the context, since I would like to define a similiar behaviour e.g. for the CirclePlus operator.

If one uses the $+$ operator as $+a$ then one gets the expected result $a$.

Since $+$ is by definition a Binary operator the expression $a+b$ is translated into $Plus[a,b]$.

Now how could I specify a similar behavior for e.g the $\oplus$ binary operator? Obviously $a \oplus b$ is translating nicely into CirclePlus[a,b] as expected.

However if I try $\oplus a$ I get a syntax error "$\oplus a$ is incomplete; more input is needed."

I'm sure I miss here some additional definition or rule necessary to get this behavior.

$\endgroup$
  • $\begingroup$ There could be something of use in the Notation package. I've never defined a unary operator, only binary infix, but this looks helpful $\endgroup$ – Histograms May 16 '15 at 16:37
  • 1
    $\begingroup$ Plus has the OneIdentity attribute, that's why Plus[a] = a. Try setting that attribute for CirclePlus. Or more generally, just define what CirclePlus[a] should be, as it doesn't have any built-in meaning. $\endgroup$ – Marius Ladegård Meyer May 16 '15 at 17:03
  • 1
    $\begingroup$ @MariusLadegårdMeyer: Both approaches are unfortunately not working. The error still persists. $\endgroup$ – Rainer May 16 '15 at 18:25
  • $\begingroup$ Rainer, are you sure of that? Because if I set CirclePlus[x_]=x on my machine, then evaluate CirclePlus[a], I obtain a as the output, which I thought is what you want. $\endgroup$ – MarcoB May 16 '15 at 21:09
  • $\begingroup$ Try this: MakeExpression[RowBox[{"[CirclePlus]", x_}], StandardForm] := MakeExpression[RowBox[{x}], StandardForm] $\endgroup$ – jamtype7 May 16 '15 at 21:13

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.