how to add extra operator for algebra

181 views
Skip to first unread message

meInvent bbird

unread,
May 27, 2016, 10:53:20 AM5/27/16
to sympy
if i define a new custom multiply operator and would like to add to existing algebra system in python

how can i extend this function?

Alan Bromborsky

unread,
May 27, 2016, 5:20:06 PM5/27/16
to sy...@googlegroups.com
Be more specific.  What are you multiplying? What is the output.  If you define a class for your operands you can overload *.

On Fri, May 27, 2016 at 4:15 AM, meInvent bbird <jobma...@gmail.com> wrote:
if i define a new custom multiply operator and would like to add to existing algebra system in python

how can i extend this function?

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/e4678ef9-a787-4a05-aa10-78d60a65ebba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

meInvent bbird

unread,
Jun 2, 2016, 3:04:32 PM6/2/16
to sympy
beside traditional addition and multiply,

i had extra 5 operator for a new algebra called AA

because i am using logic 0,1,2 - 3 valued more than binary loic 0,1 only 2 valued

so i call the operation when deal with 2 are AA algebra

you can assume one of operation is 
def op3(a, b)
 return a*b+1 

op3(2,3) = 7

op3(2*aa, 3*aa) = 7*aa

Alan Bromborsky

unread,
Jun 2, 2016, 6:13:59 PM6/2/16
to sy...@googlegroups.com

the binary operators you can overload are
+,-,*,|,^,&,<,>,<<, and >> (I may have forgotten one or two operators).  The link
shows how to overload and operator.  Because of python's fixed operator precedence using parenthesis in expressions with your
overloaded operators is essential to enforce the sequence of operation expression that you wish to occur.

Reply all
Reply to author
Forward
0 new messages