def test__diff__1(self): ring = PolyRing('x,y,v,w', True) ring.ext_num_field('t^2 + 1') x, y, v, w, a0 = ring.coerce('x,y,v,w,a0') assert ring.diff(w - a0, w, 1) == 1
def test__diff__2(self): ring = PolyRing('x,y,v,w', True) ring.ext_num_field('t^2 + 1') x, y, v, w, a0 = ring.coerce('x,y,v,w,a0') assert ring.diff(x**3 - a0, x, 3) == 6
def test__quo( self ): ring = PolyRing( 'x,y,z', True ) ring.ext_num_field( 't^2 + 1' ) ring.ext_num_field( 't^3 + a0' ) ls = LinearSeries( ['x^2', 'x + x^2'], ring ) assert str( ls.quo( 'x' ) ) == '{ 2, <<x, x + 1>>, QQ( <a0|t^2 + 1>, <a1|t^2 + a0*t - 1> )[x, y, z] }'
def test__aux_gcd(self): ring = PolyRing('x,y,z', True) ring.ext_num_field('t^2 + t + 1') ring.ext_num_field('t^3 + t + a0 + 3') agcd = ring.aux_gcd('[x*y^2 + a1*y^3, y^5, x^5*y^5]') assert str(agcd) == '([(y, 2)], [x + a1*y, y^3, x^5*y^3])'
def test__diff( self ): ring = PolyRing( 'x,y,z', True ) ring.ext_num_field( 't^2 + 1' ) ring.ext_num_field( 't^3 + a0' ) ls = LinearSeries( ['a0*x^2+y^3*z^3', 'x+z+z^3*y^4'], ring ) xls = ls.copy().chart( ['x'] ) assert str( xls.diff( 3, 2 ).pol_lst ) == '[36*z, 144*y*z]'
def test__diff__3(self): ring = PolyRing('x,y,v,w', True) ring.ext_num_field('t^2 + 1') x, y, v, w, a0 = ring.coerce('x,y,v,w,a0') d1 = ring.diff(y**2 * x**3 - a0, x, 2) d2 = ring.diff(d1, y, 2) assert d1 == 6 * y**2 * x assert d2 == 12 * x
def test__chart( self ): ring = PolyRing( 'x,y,z', True ) ring.ext_num_field( 't^2 + 1' ) ring.ext_num_field( 't^3 + a0' ) ls = LinearSeries( ['x^2+a0*y*z', 'x+y+a1*z '], ring ) xls = ls.copy().chart( ['x'] ) assert str( xls.pol_lst ) == '[a0*y*z + 1, y + a1*z + 1]'
def test__resultant(self): ring = PolyRing('x,y,z', True) ring.ext_num_field('t^2 + t + 1') ring.ext_num_field('t^3 + t + a0 + 3') pol1 = ring.coerce('(x+1)*(x^2+a0+1)') pol2 = ring.coerce('x^5 + x + a0 + 3') x = ring.coerce('x') r = ring.resultant(pol1, pol2, x) assert str(r) == '7*a0 + 2'
def test__quo(self): ring = PolyRing('x,y,z', True) ring.ext_num_field('t^2 + t + 1') ring.ext_num_field('t^3 + t + a0 + 3') pol1 = ring.coerce('(x+1)*(x^2+a0+1)') pol2 = ring.coerce('(x+1)') assert str(pol1) == 'x^3 + x^2 + (a0 + 1)*x + a0 + 1' q = ring.quo(pol1, pol2) assert str(q) == 'x^2 + a0 + 1'
def test__blow_up_origin( self ): ring = PolyRing( 'x,y,z', True ) ring.ext_num_field( 't^2 + 1' ) ring.ext_num_field( 't^3 + a0' ) ls = LinearSeries( ['x^2', 'x*z + y^2'], ring ) zls = ls.copy().chart( ['z'] ) zls, m = zls.blow_up_origin( 's' ) assert str( zls ) == '{ 2, <<x, x*y^2 + 1>>, QQ( <a0|t^2 + 1>, <a1|t^2 + a0*t - 1> )[x, y] }' assert m == 1
def test__factor(self): ring = PolyRing('x,y,z', True) ring.ext_num_field('t^2 + t + 1') ring.ext_num_field('t^3 + t + a0 + 3') pol = ring.coerce('(x+1)*(x^2+a0+1)') assert str(pol) == 'x^3 + x^2 + (a0 + 1)*x + a0 + 1' assert str(sage_factor(pol)) == '(x + 1) * (x + a0) * (x - a0)' con = ring.coerce('a0') assert str(sage_factor(con)) == 'a0'
def test__translate_to_origin( self ): ring = PolyRing( 'x,y,z', True ) ring.ext_num_field( 't^2 + 1' ) ring.ext_num_field( 't^3 + a0' ) ls = LinearSeries( ['y^2', 'y*x'], ring ) xls = ls.copy().chart( ['x'] ) a0, a1 = ring.coerce( 'a0,a1' ) xls.translate_to_origin( ( a0 + 1, a1 + a0 ) ) assert str( xls ) == '{ 2, <<y^2 + (2*a0 + 2)*y + 2*a0, y + a0 + 1>>, QQ( <a0|t^2 + 1>, <a1|t^2 + a0*t - 1> )[y, z] }'
def test__get_base_point_tree(self): ring = PolyRing('x,y,z', True) ring.ext_num_field('t^2 + 1') ring.ext_num_field('t^3 + a0') ls = LinearSeries(['x^2+a0*y*z', 'y+a1*z+x'], ring) out = str(ls.get_bp_tree()) chk = """ { 2, <<x^2 + a0*y*z, x + y + a1*z>>, QQ( <a0|t^2 + 1>, <a1|t^2 + a0*t - 1>, <a2|t^2 - a0*t - a0*a1> )[x, y, z] } chart=z, depth=0, mult=1, sol=(-a2 + a0, a2 - a1 - a0), { 2, <<x^2 + a0*y, x + y + a1>>, QQ( <a0|t^2 + 1>, <a1|t^2 + a0*t - 1>, <a2|t^2 - a0*t - a0*a1> )[x, y] } chart=z, depth=0, mult=1, sol=(a2, -a2 - a1), { 2, <<x^2 + a0*y, x + y + a1>>, QQ( <a0|t^2 + 1>, <a1|t^2 + a0*t - 1>, <a2|t^2 - a0*t - a0*a1> )[x, y] } """ assert self.equal_output_strings(out, chk)
def test__get_linear_series__6(self): ring = PolyRing('x,y,v,w', True) ring.ext_num_field('t^2 + 1') a0 = ring.root_gens()[0] bp_tree_1 = BasePointTree(['xv', 'xw', 'yv', 'yw']) bp = bp_tree_1.add('xv', (a0, -a0), 2) bp_tree_2 = LinearSeries.get([2, 2], bp_tree_1).get_bp_tree() bp_tree_2_str = bp_tree_2.alt_str() bp_tree_2_str = bp_tree_2_str.replace('(a0)', 'a0') bp_tree_2_str = bp_tree_2_str.replace('(-a0)', '-a0') assert self.equal_output_strings(bp_tree_1.alt_str(), bp_tree_2_str)
def test__subs( self ): ring = PolyRing( 'x,y,z', True ) ring.ext_num_field( 't^2 + 1' ) ring.ext_num_field( 't^3 + a0' ) a0, a1 = ring.root_gens() x, y, z = ring.gens() pol_lst = [x ** 2 + a0 * y * z, y + a1 * z + x ] ls = LinearSeries( pol_lst, ring ) assert str( ls.pol_lst ) == '[x^2 + a0*y*z, x + y + a1*z]' ls.subs( {x: x + 1} ) assert str( ls.pol_lst ) == '[x^2 + a0*y*z + 2*x + 1, x + y + a1*z + 1]'
def test__approx_QQ_coef__2(self): ring = PolyRing('x,y,v,w', True) ring.ext_num_field('t^2 - 3') ring.ext_num_field('t^2 + 1') ring.ext_num_field('t^2 + 2/7*a0*a1 + 3/7') ring.ext_num_field('t^2 - 2/7*a0*a1 + 3/7') a0, a1, a2, a3 = ring.root_gens() q2 = sage_QQ(1) / 2 a = 2 * a0 / 3 b = (-a0 * a1 / 3 - q2) * a3 c = (a0 * a1 / 3 - q2) * a2 d = (a1 / 2 - a0 / 3) * a3 e = (-a1 / 2 - a0 / 3) * a2 ci_idx = 5 # index for complex embedding C1 = -(b + c - d - e) C2 = -(b + c + d + e) for lbl, elt in [('a0', a0), ('C1', C1), ('C2', C2)]: print(lbl + ' = ' + str(elt.abs())) for ci in elt.complex_embeddings(): print('\t\t' + str(ci)) s = str(elt.complex_embeddings()[ci_idx]) print(lbl + '.complex_embedding()[' + str(ci_idx) + '] = ' + s) # C1 print('--- C1 ---') out = OrbRing.approx_QQ_coef(C1, ci_idx) print(out) print(sage_n(out)) chk = -sage_QQ(3687885631267691) / 2251799813685248 assert out == chk # C2 print('--- C2 ---') out = OrbRing.approx_QQ_coef(C2, ci_idx) print(out) print(sage_n(out)) chk = sage_QQ(2749869658604311) / 4503599627370496 assert out == chk
def test__ext_num_field(self): ring = PolyRing('x,y,z', True) assert str(ring) == 'QQ[x, y, z]' ring.ext_num_field('t^2 + t + 1') assert str(ring) == 'QQ( <a0|t^2 + t + 1> )[x, y, z]' ring.ext_num_field('t^3 + t + a0 + 3') assert str( ring ) == 'QQ( <a0|t^2 + t + 1>, <a1|t^3 + t + a0 + 3>, <a2|t^2 + a1*t + a1^2 + 1> )[x, y, z]' a = ring.root_gens() x, y, z = ring.gens() pol = x**3 + x + a[0] + 3 assert str(sage_factor(pol)) == '(x - a2) * (x - a1) * (x + a2 + a1)' mat = list(pol.sylvester_matrix(y**2 + x**2, x)) assert str( mat ) == '[(1, 0, 1, a0 + 3, 0), (0, 1, 0, 1, a0 + 3), (1, 0, y^2, 0, 0), (0, 1, 0, y^2, 0), (0, 0, 1, 0, y^2)]'