Skip to content

Commit

Permalink
field imaginary unit, epsilon element and patched sqrt to work on int…
Browse files Browse the repository at this point in the history
…egers but within field.
  • Loading branch information
GDeLaurentis committed Mar 28, 2024
1 parent 2aa0fe6 commit c5fc76a
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions syngular/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,26 @@ def singular_notation(self):
else:
return None

@property
def sqrt(self):
def sqrt(self, val):
if self.name == "finite field":
return finite_field_sqrt
if not isinstance(val, ModP):
val = self(val)
return finite_field_sqrt(val)
elif self.name == "padic":
return padic_sqrt
if not isinstance(val, PAdic):
val = self(val)
return padic_sqrt(val)
elif self.name == "mpc":
return mpmath.sqrt
return mpmath.sqrt(val)
else:
raise Exception(f"Field not understood: {self.field.name}")

@property
def j(self):
return self.sqrt(-1)

i = I = j

def random_element(self, shape=(1, )):
if shape == (1, ):
if self.name == "padic":
Expand All @@ -135,6 +144,22 @@ def random_element(self, shape=(1, )):
else:
raise NotImplementedError

def epsilon(self, shape=(1, ), ):
if shape == (1, ):
if self.name == "padic":
return self.characteristic
elif self.name == "finite field":
raise ValueError("Finite field infinitesimal does not exist.")
elif self.name == "mpc":
return mpmath.mpf('1e-30')
else:
raise NotImplementedError
else:
raise NotImplementedError

def ε(self, *args, **kwargs):
return self.epsilon(*args, **kwargs)


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

Expand Down

0 comments on commit c5fc76a

Please sign in to comment.