@@ -67,23 +67,31 @@ def _reduced_ternary_form_eisenstein_with_matrix(a1, a2, a3, a23, a13, a12):
6767 sage: Q(M) == Qr
6868 True
6969 """
70- M = identity_matrix(3 )
70+ # M = identity_matrix(3)
71+ # M = matrix(ZZ, 3, [m11, m12, m13, m21, m22, m23, m31, m32, m33])
72+ m11, m12, m13, m21, m22, m23, m31, m32, m33 = 1 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1
7173
7274 loop = True
7375
7476 while loop:
7577
7678 # adjust
77- v = a1+ a2+ a23+ a13+ a12
78- if v < 0 :
79- M *= matrix(ZZ, 3 , [1 , 0 , 1 , 0 , 1 , 1 , 0 , 0 , 1 ])
79+ v = a1 + a2 + a23 + a13 + a12
80+ if (v < 0 ):
81+ # M *= matrix(ZZ, 3, [1, 0, 1, 0, 1, 1, 0, 0, 1])
82+ [m13] = [m11 + m12 + m13]
83+ [m23] = [m21 + m22 + m23]
84+ [m33] = [m31 + m32 + m33]
8085 a3 += v
81- a23 += a12+ 2 * a2
82- a13 += a12+ 2 * a1
86+ a23 += a12 + 2 * a2
87+ a13 += a12 + 2 * a1
8388
8489 # cuadred 12
8590 m = red_mfact(a1, a12)
86- M *= matrix(ZZ, 3 , [1 , m, 0 , 0 , 1 , 0 , 0 , 0 , 1 ])
91+ # M *= matrix(ZZ, 3, [1, m, 0, 0, 1, 0, 0, 0, 1])
92+ [m12] = [m* m11 + m12]
93+ [m22] = [m* m21 + m22]
94+ [m32] = [m* m31 + m32]
8795 t = a1* m
8896 a12 += t
8997 a2 += a12* m
@@ -92,7 +100,10 @@ def _reduced_ternary_form_eisenstein_with_matrix(a1, a2, a3, a23, a13, a12):
92100
93101 # cuadred 23
94102 m = red_mfact(a2, a23)
95- M *= matrix(ZZ, 3 , [1 , 0 , 0 , 0 , 1 , m, 0 , 0 , 1 ])
103+ # M *= matrix(ZZ, 3, [1, 0, 0, 0, 1, m, 0, 0, 1])
104+ [m13] = [m* m12 + m13]
105+ [m23] = [m* m22 + m23]
106+ [m33] = [m* m32 + m33]
96107 t = a2* m
97108 a23 += t
98109 a3 += a23* m
@@ -101,7 +112,10 @@ def _reduced_ternary_form_eisenstein_with_matrix(a1, a2, a3, a23, a13, a12):
101112
102113 # cuadred 13
103114 m = red_mfact(a1, a13)
104- M *= matrix(ZZ, 3 , [1 , 0 , m, 0 , 1 , 0 , 0 , 0 , 1 ])
115+ # M *= matrix(ZZ, 3, [1, 0, m, 0, 1, 0, 0, 0, 1])
116+ [m13] = [m* m11 + m13]
117+ [m23] = [m* m21 + m23]
118+ [m33] = [m* m31 + m33]
105119 t = a1* m
106120 a13 += t
107121 a3 += a13* m
@@ -110,130 +124,188 @@ def _reduced_ternary_form_eisenstein_with_matrix(a1, a2, a3, a23, a13, a12):
110124
111125 # order 12
112126 if a1 > a2 or (a1 == a2 and abs (a23) > abs (a13)):
113- M *= matrix(ZZ, 3 , [0 , - 1 , 0 , - 1 , 0 , 0 , 0 , 0 , - 1 ])
127+ # M *= matrix(ZZ, 3, [0, -1, 0, -1, 0, 0, 0, 0, -1])
128+ [m11, m12, m13] = [- m12, - m11, - m13]
129+ [m21, m22, m23] = [- m22, - m21, - m23]
130+ [m31, m32, m33] = [- m32, - m31, - m33]
114131 [a1, a2] = [a2, a1]
115132 [a13, a23] = [a23, a13]
116133
117134 # order 23
118135 if a2 > a3 or (a2 == a3 and abs (a13) > abs (a12)):
119- M *= matrix(ZZ, 3 , [- 1 , 0 , 0 , 0 , 0 , - 1 , 0 , - 1 , 0 ])
136+ # M *= matrix(ZZ, 3, [-1, 0, 0, 0, 0, -1, 0, -1, 0])
137+ [m11, m12, m13] = [- m11, - m13, - m12]
138+ [m21, m22, m23] = [- m21, - m23, - m22]
139+ [m31, m32, m33] = [- m31, - m33, - m32]
120140 [a2, a3] = [a3, a2]
121141 [a13, a12] = [a12, a13]
122142
123143 # order 12
124144 if a1 > a2 or (a1 == a2 and abs (a23) > abs (a13)):
125- M *= matrix(ZZ, 3 , [0 , - 1 , 0 , - 1 , 0 , 0 , 0 , 0 , - 1 ])
145+ # M *= matrix(ZZ, 3, [0, -1, 0, -1, 0, 0, 0, 0, -1])
146+ [m11, m12, m13] = [- m12, - m11, - m13]
147+ [m21, m22, m23] = [- m22, - m21, - m23]
148+ [m31, m32, m33] = [- m32, - m31, - m33]
126149 [a1, a2] = [a2, a1]
127150 [a13, a23] = [a23, a13]
128151
129152 # signs
130153 if a23* a13* a12 > 0 :
131154 # a23, a13, a12 positive
132155
133- if a23 < 0 :
134- M *= diagonal_matrix([- 1 , 1 , 1 ])
156+ if (a23 < 0 ):
157+ # M *= diagonal_matrix([-1, 1, 1])
158+ m11 = - m11
159+ m21 = - m21
160+ m31 = - m31
135161 a23 = - a23
136- if a13 < 0 :
137- M *= diagonal_matrix([1 , - 1 , 1 ])
162+ if (a13 < 0 ):
163+ # M *= diagonal_matrix([1, -1, 1])
164+ m12 = - m12
165+ m22 = - m22
166+ m32 = - m32
138167 a13 = - a13
139- if a12 < 0 :
140- M *= diagonal_matrix([1 , 1 , - 1 ])
168+ if (a12 < 0 ):
169+ # M *= diagonal_matrix([1, 1, -1])
170+ m13 = - m13
171+ m23 = - m23
172+ m33 = - m33
141173 a12 = - a12
142174
143175 else :
144176 # a23, a13, a12 nonpositive
145177
146178 [s1, s2, s3] = [a23 > 0 , a13 > 0 , a12 > 0 ]
147- if (s1+ s2 + s3) % 2 :
179+ if (s1 + s2 + s3) % 2 :
148180 if a23 == 0 :
149181 s1 = 1
150182 else :
151183 if a13 == 0 :
152184 s2 = 1
153185 else :
154- if a12 == 0 :
186+ if ( a12 == 0 ) :
155187 s3 = 1
156188 if s1:
157- M *= diagonal_matrix([- 1 , 1 , 1 ])
189+ # M *= diagonal_matrix([-1, 1, 1])
190+ m11 = - m11
191+ m21 = - m21
192+ m31 = - m31
158193 a23 = - a23
159194 if s2:
160- M *= diagonal_matrix([1 , - 1 , 1 ])
195+ # M *= diagonal_matrix([1, -1, 1])
196+ m12 = - m12
197+ m22 = - m22
198+ m32 = - m32
161199 a13 = - a13
162200 if s3:
163- M *= diagonal_matrix([1 , 1 , - 1 ])
201+ # M *= diagonal_matrix([1, 1, -1])
202+ m13 = - m13
203+ m23 = - m23
204+ m33 = - m33
164205 a12 = - a12
165206
166- loop = not (abs (a23) <= a2 and abs (a13) <= a1 and abs (a12) <= a1 and a1+ a2 + a23+ a13+ a12 >= 0 )
207+ loop = not (abs (a23) <= a2 and abs (a13) <= a1 and abs (a12) <= a1 and a1 + a2 + a23 + a13 + a12 >= 0 )
167208
168209 # adj 3
169- if a1+ a2+ a23+ a13+ a12 == 0 and 2 * a1+ 2 * a13+ a12 > 0 :
170- M *= matrix(ZZ, 3 , [- 1 , 0 , 1 , 0 , - 1 , 1 , 0 , 0 , 1 ])
171- # a3 += a1+a2+a23+a13+a12
172- a23 = - 2 * a2- a23- a12
173- a13 = - 2 * a1- a13- a12
210+ if a1 + a2 + a23 + a13 + a12 == 0 and 2 * a1 + 2 * a13 + a12 > 0 :
211+ # M *= matrix(ZZ, 3, [-1, 0, 1, 0, -1, 1, 0, 0, 1])
212+ [m11, m12, m13] = [- m11, - m12, m11 + m12 + m13]
213+ [m21, m22, m23] = [- m21, - m22, m21 + m22 + m23]
214+ [m31, m32, m33] = [- m31, - m32, m31 + m32 + m33]
215+ # a3 += a1+a2+a23+a13+a12 = 0
216+ a23 = - 2 * a2 - a23 - a12
217+ a13 = - 2 * a1 - a13 - a12
174218
175219 # adj 5.12
176220 if a1 == - a12 and a13 != 0 :
177- M *= matrix(ZZ, 3 , [- 1 , - 1 , 0 , 0 , - 1 , 0 , 0 , 0 , 1 ])
178- # a2 += a1+a12
179- a23 = - a23- a13
221+ # M *= matrix(ZZ, 3, [-1, -1, 0, 0, -1, 0, 0, 0, 1])
222+ [m11, m12] = [- m11, - m11 - m12]
223+ [m21, m22] = [- m21, - m21 - m22]
224+ [m31, m32] = [- m31, - m31 - m32]
225+ # a2 += a1 + a12 = 0
226+ a23 = - a23 - a13
180227 a13 = - a13
181- a12 = - a12 # = 2*a1+ a12
228+ a12 = - a12 # = 2*a1 + a12
182229
183230 # adj 5.13
184231 if a1 == - a13 and a12 != 0 :
185- M *= matrix(ZZ, 3 , [- 1 , 0 , - 1 , 0 , 1 , 0 , 0 , 0 , - 1 ])
186- # a3 += a1+a13
187- a23 = - a23- a12
188- a13 = - a13 # = 2*a1+a13
232+ # M *= matrix(ZZ, 3, [-1, 0, -1, 0, 1, 0, 0, 0, -1])
233+ [m11, m13] = [- m11, - m11 - m13]
234+ [m21, m23] = [- m21, - m21 - m23]
235+ [m31, m33] = [- m31, - m31 - m33]
236+ # a3 += a1 + a13 = 0
237+ a23 = - a23 - a12
238+ a13 = - a13 # = 2*a1 + a13
189239 a12 = - a12
190240
191241 # adj 5.23
192242 if a2 == - a23 and a12 != 0 :
193- M *= matrix(ZZ, 3 , [1 , 0 , 0 , 0 , - 1 , - 1 , 0 , 0 , - 1 ])
194- # a3 += a2+a23
195- a23 = - a23 # = 2*a2+a23
196- a13 = - a13- a12
243+ # M *= matrix(ZZ, 3, [1, 0, 0, 0, -1, -1, 0, 0, -1])
244+ [m12, m13] = [- m12, - m12 - m13]
245+ [m22, m23] = [- m22, - m22 - m23]
246+ [m32, m33] = [- m32, - m32 - m33]
247+ # a3 += a2 + a23 = 0
248+ a23 = - a23 # = 2*a2 + a23
249+ a13 = - a13 - a12
197250 a12 = - a12
198251
199252 # adj 4.12
200253 if a1 == a12 and a13 > 2 * a23:
201- M *= matrix(ZZ, 3 , [- 1 , - 1 , 0 , 0 , 1 , 0 , 0 , 0 , - 1 ])
202- # a 2 += a1-a12
254+ # M *= matrix(ZZ, 3, [-1, -1, 0, 0, 1, 0, 0, 0, -1])
255+ [m11, m12, m13] = [- m11, - m11 + m12, - m13]
256+ [m21, m22, m23] = [- m21, - m21 + m22, - m23]
257+ [m31, m32, m33] = [- m31, - m31 + m32, - m33]
258+ # a2 += a1 - a12 = 0
203259 a23 = - a23 + a13
204260 # a12 = 2*a1 - a12
205261
206262 # adj 4.13
207263 if a1 == a13 and a12 > 2 * a23:
208- M *= matrix(ZZ, 3 , [- 1 , 0 , - 1 , 0 , - 1 , 0 , 0 , 0 , 1 ])
209- # a3 += a1-a13
264+ # M *= matrix(ZZ, 3, [-1, 0, -1, 0, -1, 0, 0, 0, 1])
265+ [m11, m12, m13] = [- m11, - m12, - m11 + m13]
266+ [m21, m22, m23] = [- m21, - m22, - m21 + m23]
267+ [m31, m32, m33] = [- m31, - m32, - m31 + m33]
268+ # a3 += a1 - a13 = 0
210269 a23 = - a23 + a12
211270 # a13 = 2*a1 - a13
212271
213272 # adj 4.23
214273 if a2 == a23 and a12 > 2 * a13:
215- M *= matrix(ZZ, 3 , [- 1 , 0 , 0 , 0 , - 1 , - 1 , 0 , 0 , 1 ])
216- # a3 += a2-a23
274+ # M *= matrix(ZZ, 3, [-1, 0, 0, 0, -1, -1, 0, 0, 1])
275+ [m11, m12, m13] = [- m11, - m12, - m12 + m13]
276+ [m21, m22, m23] = [- m21, - m22, - m22 + m23]
277+ [m31, m32, m33] = [- m31, - m32, - m32 + m33]
278+ # a3 += a2 - a23 = 0
217279 # a23 = 2*a2 - a23
218280 a13 = - a13 + a12
219281
220282 # order 12
221283 if a1 == a2 and abs (a23) > abs (a13):
222- M *= matrix(ZZ, 3 , [0 , - 1 , 0 , - 1 , 0 , 0 , 0 , 0 , - 1 ])
284+ # M *= matrix(ZZ, 3, [0, -1, 0, -1, 0, 0, 0, 0, -1])
285+ [m11, m12, m13] = [- m12, - m11, - m13]
286+ [m21, m22, m23] = [- m22, - m21, - m23]
287+ [m31, m32, m33] = [- m32, - m31, - m33]
223288 [a1, a2] = [a2, a1]
224289 [a13, a23] = [a23, a13]
225290
226291 # order 23
227292 if a2 == a3 and abs (a13) > abs (a12):
228- M *= matrix(ZZ, 3 , [- 1 , 0 , 0 , 0 , 0 , - 1 , 0 , - 1 , 0 ])
293+ # M *= matrix(ZZ, 3, [-1, 0, 0, 0, 0, -1, 0, -1, 0])
294+ [m11, m12, m13] = [- m11, - m13, - m12]
295+ [m21, m22, m23] = [- m21, - m23, - m22]
296+ [m31, m32, m33] = [- m31, - m33, - m32]
229297 [a13, a12] = [a12, a13]
230298
231299 # order 12
232300 if a1 == a2 and abs (a23) > abs (a13):
233- M *= matrix(ZZ, 3 , [0 , - 1 , 0 , - 1 , 0 , 0 , 0 , 0 , - 1 ])
301+ # M *= matrix(ZZ, 3, [0, -1, 0, -1, 0, 0, 0, 0, -1])
302+ [m11, m12, m13] = [- m12, - m11, - m13]
303+ [m21, m22, m23] = [- m22, - m21, - m23]
304+ [m31, m32, m33] = [- m32, - m31, - m33]
234305 [a13, a23] = [a23, a13]
235306
236- return (a1, a2, a3, a23, a13, a12), M
307+ return (a1, a2, a3, a23, a13, a12), \
308+ matrix(ZZ, 3 , (m11, m12, m13, m21, m22, m23, m31, m32, m33))
237309
238310
239311def _reduced_ternary_form_eisenstein_without_matrix (a1 , a2 , a3 , a23 , a13 , a12 ):
0 commit comments