compile error when using override

Ho Yeung Lee jobmattcon at gmail.com
Fri Dec 2 19:01:49 EST 2016


from __future__ import division 
from sympy import * 
x, y, z, t = symbols('x y z t') 
k, m, n = symbols('k m n', integer=True) 
f, g, h = symbols('f g h', cls=Function) 

class AA(object): 
    @staticmethod 
    def __additionFunction__(a1, a2): 
        return a1*a2 #Put what you want instead of this 
    def __multiplyFunction__(a1, a2): 
        return a1*a2+a1 #Put what you want instead of this 
    def __divideFunction__(a1, a2): 
        return a1*a1*a2 #Put what you want instead of this 
    def __init__(self, value): 
        self.value = value 
    def __add__(self, other): 
        return self.value*other.value 
    def __mul__(self, other): 
        return self.value*other.value + other.value 
    def __div__(self, other): 
        return self.value*other.value*other.value 

solve([AA(x)*AA(y) + AA(-1), AA(x) + AA(-2)], x, y) 

>>> solve([AA(x)*AA(y) + AA(-1), AA(x) + AA(-2)], x, y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'Add' and 'AA'


still error, 

actually i invented 3 valued logic algebraic operation which is quintessential and would replace into it if this succeed


On Friday, December 2, 2016 at 1:02:19 PM UTC+8, Steve D'Aprano wrote:
> On Fri, 2 Dec 2016 01:35 pm, Ho Yeung Lee wrote:
> 
> > from __future__ import division
> > import ast
> > from sympy import *
> > x, y, z, t = symbols('x y z t')
> > k, m, n = symbols('k m n', integer=True)
> > f, g, h = symbols('f g h', cls=Function)
> > import inspect
> 
> Neither ast nor inspect is used. Why import them?
> 
> The only symbols you are using are x and y.
> 
> 
> > def op2(a,b):
> >     return a*b+a
> 
> This doesn't seem to be used. Get rid of it.
> 
> 
> > class AA(object):
> >     @staticmethod
> >     def __additionFunction__(a1, a2):
> >         return a1*a2 #Put what you want instead of this
> >     def __multiplyFunction__(a1, a2):
> >         return a1*a2+a1 #Put what you want instead of this
> >     def __divideFunction__(a1, a2):
> >         return a1*a1*a2 #Put what you want instead of this
> 
> None of those methods are used. Get rid of them.
> 
> >     def __init__(self, value):
> >         self.value = value
> >     def __add__(self, other):
> >         return self.value*other.value
> 
> Sorry, you want AA(5) + AA(2) to return 10?
> 
> >     def __mul__(self, other):
> >         return self.value*other.value + other.value
> >     def __div__(self, other):
> >         return self.value*other.value*other.value
> > 
> > solve([AA(x)*AA(y) + AA(-1), AA(x) + AA(-2)], x, y)
> 
> I don't understand what you are trying to do here. What result are you
> execting?
> 
> Maybe you just want this?
> 
> from sympy import solve, symbols
> x, y = symbols('x y')
> print( solve([x*y - 1, x - 2], x, y) )
> 
> which prints the result:
> [(2, 1/2)]
> 
> 
> Perhaps if you explain what you are trying to do, we can help better.
> 
> But please, cut down your code to only code that is being used!
> 
> 
> 
> 
> -- 
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.




More information about the Python-list mailing list