#NEWLINE# def test_dispersion( ) : #NEWLINE# #INDENT# x = Symbol ( 'x' ) #NEWLINE# a = Symbol ( 'a' ) #NEWLINE# fp = poly ( S ( 0 ) , x ) #NEWLINE# assert ( sorted ( dispersionset ( fp ) ) == [ 0 ] ) #NEWLINE# fp = poly ( S ( 2 ) , x ) #NEWLINE# assert ( sorted ( dispersionset ( fp ) ) == [ 0 ] ) #NEWLINE# fp = poly ( ( x + 1 ) , x ) #NEWLINE# assert ( sorted ( dispersionset ( fp ) ) == [ 0 ] ) #NEWLINE# assert ( dispersion ( fp ) == 0 ) #NEWLINE# fp = poly ( ( ( x + 1 ) * ( x + 2 ) ) , x ) #NEWLINE# assert ( sorted ( dispersionset ( fp ) ) == [ 0 , 1 ] ) #NEWLINE# assert ( dispersion ( fp ) == 1 ) #NEWLINE# fp = poly ( ( x * ( x + 3 ) ) , x ) #NEWLINE# assert ( sorted ( dispersionset ( fp ) ) == [ 0 , 3 ] ) #NEWLINE# assert ( dispersion ( fp ) == 3 ) #NEWLINE# fp = poly ( ( ( x - 3 ) * ( x + 3 ) ) , x ) #NEWLINE# assert ( sorted ( dispersionset ( fp ) ) == [ 0 , 6 ] ) #NEWLINE# assert ( dispersion ( fp ) == 6 ) #NEWLINE# fp = poly ( ( ( ( x ** 4 ) - ( 3 * ( x ** 2 ) ) ) + 1 ) , x ) #NEWLINE# gp = fp . shift ( ( - 3 ) ) #NEWLINE# assert ( sorted ( dispersionset ( fp , gp ) ) == [ 2 , 3 , 4 ] ) #NEWLINE# assert ( dispersion ( fp , gp ) == 4 ) #NEWLINE# assert ( sorted ( dispersionset ( gp , fp ) ) == [ ] ) #NEWLINE# assert ( dispersion ( gp , fp ) == ( - oo ) ) #NEWLINE# fp = poly ( ( ( ( x * ( ( 3 * ( x ** 2 ) ) + a ) ) * ( x - 2536 ) ) * ( ( x ** 3 ) + a ) ) , x ) #NEWLINE# gp = fp . as_expr ( ) . subs ( x , ( x - 345 ) ) . as_poly ( x ) #NEWLINE# assert ( sorted ( dispersionset ( fp , gp ) ) == [ 345 , 2881 ] ) #NEWLINE# assert ( sorted ( dispersionset ( gp , fp ) ) == [ 2191 ] ) #NEWLINE# gp = poly ( ( ( ( ( x - 2 ) ** 2 ) * ( ( x - 3 ) ** 3 ) ) * ( ( x - 5 ) ** 3 ) ) , x ) #NEWLINE# assert ( sorted ( dispersionset ( gp ) ) == [ 0 , 1 , 2 , 3 ] ) #NEWLINE# assert ( sorted ( dispersionset ( gp , ( ( gp + 4 ) ** 2 ) ) ) == [ 1 , 2 ] ) #NEWLINE# fp = poly ( ( ( x * ( x + 2 ) ) * ( x - 1 ) ) , x ) #NEWLINE# assert ( sorted ( dispersionset ( fp ) ) == [ 0 , 1 , 2 , 3 ] ) #NEWLINE# fp = poly ( ( ( ( x ** 2 ) + ( sqrt ( 5 ) * x ) ) - 1 ) , x , domain = 'QQ<sqrt(5)>' ) #NEWLINE# gp = poly ( ( ( ( x ** 2 ) + ( ( 2 + sqrt ( 5 ) ) * x ) ) + sqrt ( 5 ) ) , x , domain = 'QQ<sqrt(5)>' ) #NEWLINE# assert ( sorted ( dispersionset ( fp , gp ) ) == [ 2 ] ) #NEWLINE# assert ( sorted ( dispersionset ( gp , fp ) ) == [ 1 , 4 ] ) #NEWLINE# fp = poly ( ( ( ( ( 4 * ( x ** 4 ) ) + ( ( ( 4 * a ) + 8 ) * ( x ** 3 ) ) ) + ( ( ( ( a ** 2 ) + ( 6 * a ) ) + 4 ) * ( x ** 2 ) ) ) + ( ( ( a ** 2 ) + ( 2 * a ) ) * x ) ) , x ) #NEWLINE# assert ( sorted ( dispersionset ( fp ) ) == [ 0 , 1 ] ) #NEWLINE# fp = poly ( ( ( ( a ** 2 ) * ( x ** 3 ) ) + ( ( ( ( ( a ** 3 ) + ( a ** 2 ) ) + a ) + 1 ) * x ) ) , x ) #NEWLINE# gp = fp . as_expr ( ) . subs ( x , ( x - ( 3 * a ) ) ) . as_poly ( x ) #NEWLINE# assert ( sorted ( dispersionset ( fp , gp ) ) == [ ] ) #NEWLINE# fpa = fp . as_expr ( ) . subs ( a , 2 ) . as_poly ( x ) #NEWLINE# gpa = gp . as_expr ( ) . subs ( a , 2 ) . as_poly ( x ) #NEWLINE# assert ( sorted ( dispersionset ( fpa , gpa ) ) == [ 6 ] ) #NEWLINE# f = ( ( x + 1 ) * ( x + 2 ) ) #NEWLINE# assert ( sorted ( dispersionset ( f ) ) == [ 0 , 1 ] ) #NEWLINE# assert ( dispersion ( f ) == 1 ) #NEWLINE# f = ( ( ( x ** 4 ) - ( 3 * ( x ** 2 ) ) ) + 1 ) #NEWLINE# g = ( ( ( ( ( x ** 4 ) - ( 12 * ( x ** 3 ) ) ) + ( 51 * ( x ** 2 ) ) ) - ( 90 * x ) ) + 55 ) #NEWLINE# assert ( sorted ( dispersionset ( f , g ) ) == [ 2 , 3 , 4 ] ) #NEWLINE# assert ( dispersion ( f , g ) == 4 ) #NEWLINE# f = ( ( x + 1 ) * ( x + 2 ) ) #NEWLINE# assert ( sorted ( dispersionset ( f , None , x ) ) == [ 0 , 1 ] ) #NEWLINE# assert ( dispersion ( f , None , x ) == 1 ) #NEWLINE# f = ( ( ( x ** 4 ) - ( 3 * ( x ** 2 ) ) ) + 1 ) #NEWLINE# g = ( ( ( ( ( x ** 4 ) - ( 12 * ( x ** 3 ) ) ) + ( 51 * ( x ** 2 ) ) ) - ( 90 * x ) ) + 55 ) #NEWLINE# assert ( sorted ( dispersionset ( f , g , x ) ) == [ 2 , 3 , 4 ] ) #NEWLINE# assert ( dispersion ( f , g , x ) == 4 )