def test_dup_ext_factor(): h = [QQ(1), QQ(0), QQ(1)] K = QQ.algebraic_field(I) assert dup_ext_factor([], K) == (ANP([], h, QQ), []) f = [ANP([QQ(1)], h, QQ), ANP([QQ(1)], h, QQ)] assert dup_ext_factor(f, K) == (ANP([QQ(1)], h, QQ), [(f, 1)]) g = [ANP([QQ(2)], h, QQ), ANP([QQ(2)], h, QQ)] assert dup_ext_factor(g, K) == (ANP([QQ(2)], h, QQ), [(f, 1)]) f = [ ANP([QQ(7)], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([QQ(1, 1)], h, QQ) ] g = [ ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([QQ(1, 7)], h, QQ) ] assert dup_ext_factor(f, K) == (ANP([QQ(7)], h, QQ), [(g, 1)]) f = [ ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([QQ(1)], h, QQ) ] assert dup_ext_factor(f, K) == \ (ANP([QQ(1,1)], h, QQ), [ ([ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([QQ(-1),QQ(0)], h, QQ)], 1), ([ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([QQ( 1),QQ(0)], h, QQ)], 1), ]) f = [ ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([QQ(1)], h, QQ) ] assert dup_ext_factor(f, K) == \ (ANP([QQ(1,1)], h, QQ), [ ([ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([QQ(-1),QQ(0)], h, QQ)], 1), ([ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([QQ( 1),QQ(0)], h, QQ)], 1), ]) h = [QQ(1), QQ(0), QQ(-2)] K = QQ.algebraic_field(sqrt(2)) f = [ ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([QQ(1, 1)], h, QQ) ] assert dup_ext_factor(f, K) == \ (ANP([QQ(1)], h, QQ), [ ([ANP([QQ(1)], h, QQ), ANP([QQ(-1),QQ(0)], h, QQ), ANP([QQ(1)], h, QQ)], 1), ([ANP([QQ(1)], h, QQ), ANP([QQ( 1),QQ(0)], h, QQ), ANP([QQ(1)], h, QQ)], 1), ]) f = [ANP([QQ(1, 1)], h, QQ), ANP([2, 0], h, QQ), ANP([QQ(2, 1)], h, QQ)] assert dup_ext_factor(f, K) == \ (ANP([QQ(1,1)], h, QQ), [ ([ANP([1], h, QQ), ANP([1,0], h, QQ)], 2), ]) assert dup_ext_factor(dup_pow(f, 3, K), K) == \ (ANP([QQ(1,1)], h, QQ), [ ([ANP([1], h, QQ), ANP([1,0], h, QQ)], 6), ]) f = dup_mul_ground(f, ANP([QQ(2, 1)], h, QQ), K) assert dup_ext_factor(f, K) == \ (ANP([QQ(2,1)], h, QQ), [ ([ANP([1], h, QQ), ANP([1,0], h, QQ)], 2), ]) assert dup_ext_factor(dup_pow(f, 3, K), K) == \ (ANP([QQ(8,1)], h, QQ), [ ([ANP([1], h, QQ), ANP([1,0], h, QQ)], 6), ]) h = [QQ(1, 1), QQ(0, 1), QQ(1, 1)] K = QQ.algebraic_field(I) f = [ANP([QQ(4, 1)], h, QQ), ANP([], h, QQ), ANP([QQ(9, 1)], h, QQ)] assert dup_ext_factor(f, K) == \ (ANP([QQ(4,1)], h, QQ), [ ([ANP([QQ(1,1)], h, QQ), ANP([-QQ(3,2), QQ(0,1)], h, QQ)], 1), ([ANP([QQ(1,1)], h, QQ), ANP([ QQ(3,2), QQ(0,1)], h, QQ)], 1), ]) f = [ ANP([QQ(4, 1)], h, QQ), ANP([QQ(8, 1)], h, QQ), ANP([QQ(77, 1)], h, QQ), ANP([QQ(18, 1)], h, QQ), ANP([QQ(153, 1)], h, QQ) ] assert dup_ext_factor(f, K) == \ (ANP([QQ(4,1)], h, QQ), [ ([ANP([QQ(1,1)], h, QQ), ANP([-QQ(4,1), QQ(1,1)], h, QQ)], 1), ([ANP([QQ(1,1)], h, QQ), ANP([-QQ(3,2), QQ(0,1)], h, QQ)], 1), ([ANP([QQ(1,1)], h, QQ), ANP([ QQ(3,2), QQ(0,1)], h, QQ)], 1), ([ANP([QQ(1,1)], h, QQ), ANP([ QQ(4,1), QQ(1,1)], h, QQ)], 1), ])
def test_dup_ext_factor(): h = [QQ(1),QQ(0),QQ(1)] K = QQ.algebraic_field(I) assert dup_ext_factor([], K) == (ANP([], h, QQ), []) f = [ANP([QQ(1)], h, QQ), ANP([QQ(1)], h, QQ)] assert dup_ext_factor(f, K) == (ANP([QQ(1)], h, QQ), [(f, 1)]) g = [ANP([QQ(2)], h, QQ), ANP([QQ(2)], h, QQ)] assert dup_ext_factor(g, K) == (ANP([QQ(2)], h, QQ), [(f, 1)]) f = [ANP([QQ(7)], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([QQ(1,1)], h, QQ)] g = [ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([QQ(1,7)], h, QQ)] assert dup_ext_factor(f, K) == (ANP([QQ(7)], h, QQ), [(g, 1)]) f = [ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([QQ(1)], h, QQ)] assert dup_ext_factor(f, K) == \ (ANP([QQ(1,1)], h, QQ), [ ([ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([QQ(-1),QQ(0)], h, QQ)], 1), ([ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([QQ( 1),QQ(0)], h, QQ)], 1), ]) f = [ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([QQ(1)], h, QQ)] assert dup_ext_factor(f, K) == \ (ANP([QQ(1,1)], h, QQ), [ ([ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([QQ(-1),QQ(0)], h, QQ)], 1), ([ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([QQ( 1),QQ(0)], h, QQ)], 1), ]) h = [QQ(1),QQ(0),QQ(-2)] K = QQ.algebraic_field(sqrt(2)) f = [ANP([QQ(1)], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([], h, QQ), ANP([QQ(1,1)], h, QQ)] assert dup_ext_factor(f, K) == \ (ANP([QQ(1)], h, QQ), [ ([ANP([QQ(1)], h, QQ), ANP([QQ(-1),QQ(0)], h, QQ), ANP([QQ(1)], h, QQ)], 1), ([ANP([QQ(1)], h, QQ), ANP([QQ( 1),QQ(0)], h, QQ), ANP([QQ(1)], h, QQ)], 1), ]) f = [ANP([QQ(1,1)], h, QQ), ANP([2,0], h, QQ), ANP([QQ(2,1)], h, QQ)] assert dup_ext_factor(f, K) == \ (ANP([QQ(1,1)], h, QQ), [ ([ANP([1], h, QQ), ANP([1,0], h, QQ)], 2), ]) assert dup_ext_factor(dup_pow(f, 3, K), K) == \ (ANP([QQ(1,1)], h, QQ), [ ([ANP([1], h, QQ), ANP([1,0], h, QQ)], 6), ]) f = dup_mul_ground(f, ANP([QQ(2,1)], h, QQ), K) assert dup_ext_factor(f, K) == \ (ANP([QQ(2,1)], h, QQ), [ ([ANP([1], h, QQ), ANP([1,0], h, QQ)], 2), ]) assert dup_ext_factor(dup_pow(f, 3, K), K) == \ (ANP([QQ(8,1)], h, QQ), [ ([ANP([1], h, QQ), ANP([1,0], h, QQ)], 6), ]) h = [QQ(1,1), QQ(0,1), QQ(1,1)] K = QQ.algebraic_field(I) f = [ANP([QQ(4,1)], h, QQ), ANP([], h, QQ), ANP([QQ(9,1)], h, QQ)] assert dup_ext_factor(f, K) == \ (ANP([QQ(4,1)], h, QQ), [ ([ANP([QQ(1,1)], h, QQ), ANP([-QQ(3,2), QQ(0,1)], h, QQ)], 1), ([ANP([QQ(1,1)], h, QQ), ANP([ QQ(3,2), QQ(0,1)], h, QQ)], 1), ]) f = [ANP([QQ(4,1)], h, QQ), ANP([QQ(8,1)], h, QQ), ANP([QQ(77,1)], h, QQ), ANP([QQ(18,1)], h, QQ), ANP([QQ(153,1)], h, QQ)] assert dup_ext_factor(f, K) == \ (ANP([QQ(4,1)], h, QQ), [ ([ANP([QQ(1,1)], h, QQ), ANP([-QQ(4,1), QQ(1,1)], h, QQ)], 1), ([ANP([QQ(1,1)], h, QQ), ANP([-QQ(3,2), QQ(0,1)], h, QQ)], 1), ([ANP([QQ(1,1)], h, QQ), ANP([ QQ(3,2), QQ(0,1)], h, QQ)], 1), ([ANP([QQ(1,1)], h, QQ), ANP([ QQ(4,1), QQ(1,1)], h, QQ)], 1), ])