Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doubt regarding Finite Field Addition method implementation #25

Closed
rajarshimaitra opened this issue Aug 20, 2018 · 1 comment
Closed

Comments

@rajarshimaitra
Copy link

I am new to python and the double underscore is a little bit confusing to me. I have implemented the addition method for two field elements as below :
def add(self, other):
if self.prime != other.prime:
raise RuntimeError('cannot add fields of different primes')
num = (self.num + other.num) % self.prime
return self.class(num, self.prime)

but while executing print(a+b==c) I am getting the following error
TypeError: unsupported operand type(s) for +: 'instance' and 'instance'

what is happening here? and how do i run the add method on two field elements?

PS: I am not sure if github issues are the right place to ask such doubts, but let me know if there is any other discussion forum where these types are being discussed.

Thank you.

@rajarshimaitra
Copy link
Author

Ok it seems like it was my fault. importing the class again fixes the problem, and python is interpreting "add" as "+" command automatically. Which is cool and something i didn't know. Anyway this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant