4
$\begingroup$

For example: Can we declare a function that works on pairs? Like $f(\{x,y\})$ or define an operation on pairs like $\{x,y\}\circ \{X,Y\}$?

I tried to look at f@@ but it doesn't seems to be what I want. I could declare a function such as

f[x_, y_, X_, Y_] := {x \[Theta][y] X, y Y}

And then compute

f @@ {a, b, c, d}

But this is not too "natural". Given what I know, If I want to compute, for example $\{x,y\} \circ \{x',y'\} \circ \{x'',y''\}$, I'd have to make a set $\{x,y,x',y'\}$, use f@@ which would yield another set of two elements, and now to compute the remaining operation, I'd have to construct a set with $\{i,j,x'',y''\}$ and then apply f@@ again. This is rather cumbersome.I'd like to construct an operation where I could really type $\{x,y\} \circ \{x',y'\} \circ \{x'',y''\}$ and it would work.

$\endgroup$

1 Answer 1

7
$\begingroup$

Edit

SetAttributes[CircleDot, {Flat, OneIdentity}]; 
CircleDot[{x_, y_}, {a_, b_}] := {x ** θ[y] ** a, y ** b};
 {g1,h1}⊙{g2, h2}⊙{g3, h3}

{g1 ** θ[h1] ** g2 ** θ[h1 ** h2] ** g3, h1 ** h2 ** h3}

Update

SetAttributes[CircleDot, {Orderless, Flat, OneIdentity}];
CircleDot[{x_, y_}, {a_, b_}] := {x*θ[y]*a, y*b}
{g1, h1}⊙{g2, h2}⊙{g3, h3}

{g1 g2 g3 θ[h2] θ[h1 h2], h1 h2 h3}

SetAttributes[
  CircleDot, {NumericFunction, Orderless, Flat, OneIdentity}];
CircleDot[{x_, y_}, {a_, b_}] := {a*x, b*y};
{x, y}⊙{a, b}⊙{m, n}

{a m x, b n y}

$\endgroup$
8
  • 1
    $\begingroup$ This is really nice! I am doing the following and it seems to be assuming that things associate and commute. Can we stop that? $\endgroup$
    – Red Banana
    Commented Mar 12, 2021 at 1:13
  • 1
    $\begingroup$ @BillyRubina What is $\theta$? You can edit you question and add the new code about $\theta$ $\endgroup$
    – cvgmt
    Commented Mar 12, 2021 at 2:22
  • 1
    $\begingroup$ It is a function but I'd like to leave it unevaluated in the form $\theta(x)$. The trouble is that Mathematica changes the order, I don't know why. $\endgroup$
    – Red Banana
    Commented Mar 12, 2021 at 2:29
  • 1
    $\begingroup$ @ SetAttributes[CircleDot, {Orderless, Flat, OneIdentity}]; CircleDot[{x_, y_}, {a_, b_}] := {x*θ[y]*a, y*b} {g1, h1}⊙{g2, h2}⊙{g3, h3} ? $\endgroup$
    – cvgmt
    Commented Mar 12, 2021 at 2:46
  • 1
    $\begingroup$ @BillyRubina SetAttributes[CircleDot, {Flat, OneIdentity}]; CircleDot[{x_, y_}, {a_, b_}] := {x ** \[Theta][y] ** a, y ** b}; {g1, h1}\[CircleDot]{g2, h2}\[CircleDot]{g3, h3} $\endgroup$
    – cvgmt
    Commented Mar 12, 2021 at 3:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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