Im working on computer algebra and im trying to make an interface for fields. Trying not to bore you with all the details this is whath im trying to get working:
class PrimeField():
prime = 2
def __init__(self,p):
self.prime = p
class element():
def __init__(self,n):
self.descriptor = n
def someFunctionOfNandP(self):
return 2*self.n % self.parrent.p
field = PrimeField(7)
el = field.element(5)
print(el.someFunctionOfNandP())
What im trying to achieve is that PrimeField creates a generator as you will that makes elements (which are objects) who's functions depend on the field the came from. Although I can think of workarounds that use different structures (for example making a general element class that takes two elements and a function in the field that inits these), something among the lines shown above would have preference due to its resemblance to the underlying mathematics and the program is written for somebody else who is a mathematician.
Can this be done, and if so, how?
Thank you