def canonical_representation(a, d, DE):
 l = Poly((1 / d.LC()), DE.t)
 (a, d) = (a.mul(l), d.mul(l))
 (q, r) = a.div(d)
 (dn, ds) = splitfactor(d, DE)
 (b, c) = gcdex_diophantine(dn.as_poly(DE.t), ds.as_poly(DE.t), r.as_poly(DE.t))
 (b, c) = (b.as_poly(DE.t), c.as_poly(DE.t))
 return (q, (b, ds), (c, dn))

def canonical_representation ( a , d , DE ) : l = Poly ( ( 1 / d . LC ( ) ) , DE . t ) ( a , d ) = ( a . mul ( l ) , d . mul ( l ) ) ( q , r ) = a . div ( d ) ( dn , ds ) = splitfactor ( d , DE ) ( b , c ) = gcdex_diophantine ( dn . as_poly ( DE . t ) , ds . as_poly ( DE . t ) , r . as_poly ( DE . t ) ) ( b , c ) = ( b . as_poly ( DE . t ) , c . as_poly ( DE . t ) ) return ( q , ( b , ds ) , ( c , dn ) )
canonical representation .