1
$\begingroup$

I have looked here which describes how to define operators. I was wondering whether there was a way to assign thes operators to special characters? eg Let $\odot:=(a+b)(ab),$ so 4\[CircleDot]3 would yield 84? It is really a stylistic / display issue - of course the same could be achieved with cd[a_,b_]:=(a+b) a b, implemented with cd[a,b].

$\endgroup$
3
  • 1
    $\begingroup$ Take a look at this question, see if my answer there might help you along: How to assign symbols to functions $\endgroup$
    – MarcoB
    Commented Jun 19, 2015 at 12:32
  • $\begingroup$ @MarcoB I have taken a look at the link, but usure on syntax when it comes to applying it to the example above $\endgroup$
    – martin
    Commented Jun 19, 2015 at 12:38
  • 1
    $\begingroup$ I think Karsten took care of that below :-) $\endgroup$
    – MarcoB
    Commented Jun 19, 2015 at 12:46

1 Answer 1

4
$\begingroup$
CircleDot[a_, b_] := (a + b) a b

Now

4⊙3 
84
$\endgroup$
4
  • $\begingroup$ ha! I didn't think it would be that simple - I thought the operator would have to preceed the arguments - thank you! :) $\endgroup$
    – martin
    Commented Jun 19, 2015 at 12:47
  • 3
    $\begingroup$ @martin 4⊙3//FullForm may shed some light on your confusion. Some operators are infix, meaning is the same as ~CircleDot~ and we know, that a~CircleDot~b is the same as CircleDot[a,b]. But in fact, you could just as easily set like so: a_⊙b_:=(a + b) a b, MMA would interpret this just like the full form that Karsten showed in this answer. $\endgroup$
    – LLlAMnYP
    Commented Jun 19, 2015 at 13:06
  • $\begingroup$ @LLlAMnYP ah, I see - much like ~Join~ $\endgroup$
    – martin
    Commented Jun 19, 2015 at 13:07
  • 1
    $\begingroup$ @martin precisely. When in doubt, always check the FullForm :) $\endgroup$
    – LLlAMnYP
    Commented Jun 19, 2015 at 13:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.