0
$\begingroup$

I have defined my own algebra using the unused operators $\oplus$ and $\otimes$. During evaluation, lists pop up which have the structure

{a__,{b_\[CirclePlus]c_},d__}  

which I would like to expand to

{a__,b_,d__}\[CirclePlus]{a__,c_,d__}

I tried

{a_, {b_\[CirclePlus]c_}, d_} := {a, b, d}\[CirclePlus]{a, c, d}

but this returns the error

SetDelayed::shape: Lists {a__,{b_\[CirclePlus]c_},d__} and {a,b,d}\[CirclePlus]{a,c,d} are not the same shape.

How can I define such an expansion rule?

$\endgroup$
1
  • $\begingroup$ That's a specific problem with List. It will work with most other heads, e.g., list[a_, list[b_\[CirclePlus]c_], d_] := list[a, b, d]\[CirclePlus]list[a, c, d] is fine... $\endgroup$ Mar 10, 2018 at 10:45

1 Answer 1

0
$\begingroup$

This works:

CirclePlus /: {a__, b_\[CirclePlus]c_, d__} := {a, b, d}\[CirclePlus]{a, c, d}

Without the internal list though.

$\endgroup$

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.