Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Small bugfixes to ensure right coercion.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeitel committed Mar 20, 2014
1 parent b2fb5cc commit 3c0999f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
47 changes: 37 additions & 10 deletions src/sage/rings/invariant_theory.py
Expand Up @@ -249,6 +249,33 @@ def diff(p, d):
jac = [diff(p,d) for p,d in args]
return matrix(self._ring, jac).det()

def base_ring(self):
"""
Return the base ring.
OUTPUT:
The lowest base ring.
EXAMPLES::
sage: R.<x,y,t> = QQ[]
sage: quartic = invariant_theory.binary_quartic(x^4+y^4+t*x^2*y^2, [x,y])
sage: quartic.base_ring()
Rational Field
sage: S.<t> = QQ[]
sage: R.<x,y> = S[]
sage: quartic = invariant_theory.binary_quartic(x^4+y^4+t*x^2*y^2)
sage: quartic.ring().base_ring()
Univariate Polynomial Ring in t over Rational Field
sage: quartic.base_ring()
Rational Field
"""
F = self._ring.base_ring()
while not F is F.base_ring():
F = F.base_ring()
return F

def ring(self):
"""
Expand Down Expand Up @@ -489,7 +516,7 @@ def _check_covariant(self, method_name, g=None, invariant=False):
assert self._homogeneous
from sage.matrix.constructor import vector, random_matrix
if g is None:
F = self._ring.base_ring()
F = self.base_ring()
g = random_matrix(F, self._n, algorithm='unimodular')
v = vector(self.variables())
g_v = g*v
Expand Down Expand Up @@ -1557,7 +1584,7 @@ def scaled_coeffs(self):
sage: invariant_theory.ternary_quadratic(p.subs(z=1), x, y).scaled_coeffs()
(a20, a02, a00, 1/2*a11, 1/2*a10, 1/2*a01)
"""
F = self._ring.base_ring()
F = self.base_ring()
a200, a020, a002, a110, a101, a011 = self.coeffs()
return (a200, a020, a002, a110/F(2), a101/F(2), a011/F(2))

Expand Down Expand Up @@ -1749,7 +1776,7 @@ def scaled_coeffs(self):
(a30, a03, a00, 1/3*a21, 1/3*a20, 1/3*a12, 1/3*a02, 1/3*a10, 1/3*a01, 1/6*a11)
"""
a = self.coeffs()
F = self._ring.base_ring()
F = self.base_ring()
return (a[0], a[1], a[2],
F(1)/F(3)*a[3], F(1)/F(3)*a[4], F(1)/F(3)*a[5],
F(1)/F(3)*a[6], F(1)/F(3)*a[7], F(1)/F(3)*a[8],
Expand Down Expand Up @@ -1864,7 +1891,7 @@ def polar_conic(self):
x,y,z = self.variables()
else:
x,y,z = (self._x, self._y, 1)
F = self._ring.base_ring()
F = self.base_ring()
A00 = 3*x*a30 + y*a21 + z*a20
A11 = x*a12 + 3*y*a03 + z*a02
A22 = x*a10 + y*a01 + 3*z*a00
Expand Down Expand Up @@ -1909,7 +1936,7 @@ def Hessian(self):
Uyz = x*a11 + 2*y*a02 + 2*z*a01
Uzz = 2*x*a10 + 2*y*a01 + 6*z*a00
H = matrix(self._ring, [[Uxx, Uxy, Uxz],[Uxy, Uyy, Uyz],[Uxz, Uyz, Uzz]])
F = self._ring.base_ring()
F = self.base_ring()
return F(1)/F(216) * H.det()


Expand Down Expand Up @@ -1944,7 +1971,7 @@ def Theta_covariant(self):
H_coeffs = ( H_conic[0,0], H_conic[1,1], H_conic[2,2],
H_conic[0,1], H_conic[0,2], H_conic[1,2] )
quadratic = TernaryQuadratic(3, 2, self._ring.zero(), self.variables())
F = self._ring.base_ring()
F = self.base_ring()
return F(1)/F(9) * _covariant_conic(U_coeffs, H_coeffs, quadratic.monomials())


Expand All @@ -1964,8 +1991,8 @@ def J_covariant(self):
sage: cubic.J_covariant()
x^6*y^3 - x^3*y^6 - x^6 + y^6 + x^3 - y^3
"""
F = self._ring.base_ring()
return 1 / F(9) * self._jacobian_determinant(
F = self.base_ring()
return F(1) / F(9) * self._jacobian_determinant(
[self.form(), 3],
[self.Hessian(), 3],
[self.Theta_covariant(), 6])
Expand Down Expand Up @@ -2227,7 +2254,7 @@ def _check_covariant(self, method_name, g=None, invariant=False):
assert self._homogeneous
from sage.matrix.constructor import vector, random_matrix
if g is None:
F = self._ring.base_ring()
F = self.base_ring()
g = random_matrix(F, self._n, algorithm='unimodular')
v = vector(self.variables())
g_v = g*v
Expand Down Expand Up @@ -2628,7 +2655,7 @@ def J_covariant(self):
z * y * x * w * (a3*A2 - a2*A3) * (a3*A1 - a1*A3) * (-a2*A1 + a1*A2)
* (a3*A0 - a0*A3) * (-a2*A0 + a0*A2) * (-a1*A0 + a0*A1)
"""
F = self._ring.base_ring()
F = self.base_ring()
return F(1)/F(16) * self._jacobian_determinant(
[self.first().form(), 2],
[self.second().form(), 2],
Expand Down
2 changes: 2 additions & 0 deletions src/sage/schemes/toric/weierstrass.py
Expand Up @@ -822,6 +822,8 @@ def WeierstrassForm_P2(polynomial, variables=None):
x, y, z = _check_polynomial_P2(polynomial, variables)
cubic = invariant_theory.ternary_cubic(polynomial, x, y, z)
F = polynomial.base_ring()
while not F is F.base_ring():
F = F.base_ring()
S = cubic.S_invariant()
T = cubic.T_invariant()
return (F(27)*S, -F(27)/F(4)*T)
Expand Down

0 comments on commit 3c0999f

Please sign in to comment.