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]
.
$\begingroup$
$\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$– MarcoBCommented 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$– martinCommented Jun 19, 2015 at 12:38
-
1$\begingroup$ I think Karsten took care of that below :-) $\endgroup$– MarcoBCommented Jun 19, 2015 at 12:46
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
4
CircleDot[a_, b_] := (a + b) a b
Now
4⊙3
84
-
$\begingroup$ ha! I didn't think it would be that simple - I thought the operator would have to preceed the arguments - thank you! :) $\endgroup$– martinCommented 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, thata~CircleDot~b
is the same asCircleDot[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$– LLlAMnYPCommented Jun 19, 2015 at 13:06 -
$\begingroup$ @LLlAMnYP ah, I see - much like
~Join~
$\endgroup$– martinCommented Jun 19, 2015 at 13:07 -
1$\begingroup$ @martin precisely. When in doubt, always check the
FullForm
:) $\endgroup$– LLlAMnYPCommented Jun 19, 2015 at 13:08