Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Finish the implementation of __ne__(), __add__() in Point class class Point: def __init__(self, x, y, a, b): self.a = a self.b = b self.x =

Finish the implementation of __ne__(), __add__() in Point class

class Point:

def __init__(self, x, y, a, b):

self.a = a

self.b = b

self.x = x

self.y = y

# end::source1[]

# tag::source2[]

if self.x is None and self.y is None: # <1>

return

# end::source2[]

# tag::source1[]

if self.y**2 != self.x**3 + a * x + b: # <1>

raise ValueError('({}, {}) is not on the curve'.format(x, y))

def __eq__(self, other): # <2>

return self.x == other.x and self.y == other.y \

and self.a == other.a and self.b == other.b

# end::source1[]

def __ne__(self, other):

# this should be the inverse of the == operator

raise NotImplementedError

def __repr__(self):

if self.x is None:

return 'Point(infinity)'

else:

return 'Point({},{})_{}_{}'.format(self.x, self.y, self.a, self.b)

# tag::source3[]

def __add__(self, other): # <2>

if self.a != other.a or self.b != other.b:

raise TypeError('Points {}, {} are not on the same curve'.format

(self, other))

if self.x is None: # <3>

return other

if other.x is None: # <4>

return self

# end::source3[]

# Case 1: self.x == other.x, self.y != other.y

# Result is point at infinity

# Case 2: self.x other.x

# Formula (x3,y3)==(x1,y1)+(x2,y2)

# s=(y2-y1)/(x2-x1)

# x3=s**2-x1-x2

# y3=s*(x1-x3)-y1

# Case 3: self == other

# Formula (x3,y3)=(x1,y1)+(x1,y1)

# s=(3*x1**2+a)/(2*y1)

# x3=s**2-2*x1

# y3=s*(x1-x3)-y1

raise NotImplementedError

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Is there a clear hierarchy of points in my outline?

Answered: 1 week ago

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago