-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.sage
108 lines (98 loc) · 3.57 KB
/
utilities.sage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#*****************************************************************************
# Copyright (C) 2018 Anna Somoza <anna.somoza.henares@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#*****************************************************************************
#### SAGE UTILITIES
#TODO:
# Add documentation
##Functions to transform an anti-hermitian matrix:
def transformation(E,X,i,j,k,lst=None):
E = E.with_added_multiple_of_row(i,j,k);
E = E.with_added_multiple_of_column(i,j,k.conjugate());
X = X.with_added_multiple_of_row(i,j,k);
if lst != None:
lst.append(['T',i,j,k])
return E, X, lst
return E, X
def swap(E,X,i,j,lst=None):
E.swap_rows(i,j);
E.swap_columns(i,j);
X.swap_rows(i,j);
if lst != None:
lst.append(['S',i,j])
return E, X, lst
return E, X
def rescale(E,X,i,k,lst=None):
E = E.with_rescaled_row(i,k)
E = E.with_rescaled_col(i,k.conjugate())
X = X.with_rescaled_row(i,k)
if lst != None:
lst.append(['R',i,k])
return E, X, lst
return E,X
def chain_of_trans(E,X,lst):
for L in lst:
if L[0] == 'T':
E,X = transformation(E,X,L[1],L[2],L[3])
elif L[0] == 'S':
E,X = swap(E,X,L[1],L[2])
elif L[0] == 'R':
E,X = rescale(E,X,L[1],L[2])
else:
raise TypeError('Char should be T, S or R')
return E, X
##Functions to embed
def embed(x, z, k=None):
l = fnc(x)
xC = sum([l[i]*z^i for i in range(4)])
if k!=None:
assert abs(xC.n(100) - K.embeddings(ComplexField(100))[k](x)) < 1e-3
return xC.expand()
##Functions in relation to binary quintics
#Reference:
#Théorie des formes binaires (by Francesco Faà di Bruno, 1825-1888)
def canonical_form(P):
assert P.is_homogeneous(), 'It is not a binary quintic'
(x, y) = P.parent().gens()
CC = P.base_ring()
R.<X> = PolynomialRing(CC)
C, M = (P.coefficients(), P.monomials())
V = [0 for i in range(6)]
for i in range(6):
try:
k = M.index(y^i*x^(5-i))
V[i] = C[k]/binomial(5,i)
except ValueError:
V[i] = 0
N = matrix(R,4,[[1, X, X^2, X^3], V[:4], V[1:5], V[2:6]])
try:
K.<g> = N.determinant().splitting_field()
(alpha, beta, gamma) = [a[0] for a in N.determinant().base_extend(K).roots()]
L = matrix(K, 3, [[z^i for z in [alpha, beta, gamma]] for i in range(3)])
l = vector(K,3,V[:3])
except NotImplementedError:
(alpha, beta, gamma) = N.determinant().complex_roots()
L = matrix(CC, 3, [[z^i for z in [alpha, beta, gamma]] for i in range(3)])
l = vector(CC,3,V[:3])
(p,q,r) = L\l
(l,m,n) = (p/(gamma-beta)^5, q/(alpha-gamma)^5, r/(alpha-beta)^5)
return l,m,n
def invariants((l,m,n)):
I4 = (l*m + l*n + m*n)^2 - 4*l*m*n^2
I8 = l^2*m^2*n^2*(l*m-l*n-m*n)
I12 = l^4*m^4*n^4
I18 = 4*l^5*m^5*n^5*(l-m)*(l+n)*(m+n)
return I4, I8, I12, I18