Attachment 'flipper_nf_conversion.py'
Download 1 r"""
2 This module provides a simple function to convert flipper
3 number field elements into Sage number field elements.
4
5 EXAMPLES::
6
7 sage: import flipper
8 sage: import flipper_nf_conversion
9
10 sage: S = flipper.load('S_2_1')
11 sage: h = S.mapping_class('acBD')
12 sage: F = h.flat_structure()
13 sage: x = F.edge_vectors.values()[0].x
14 sage: flipper_nf_conversion.flipper_nf_element_to_sage(x)
15 2*a^3 - 14*a^2 + 26*a - 14
16 """
17
18 from sage.rings.all import ZZ, QQ, AA, RIF, NumberField
19
20 def flipper_nf_to_sage(K, name='a'):
21 r"""
22 Convert a flipper number field to Sage.
23
24 .. NOTE::
25
26 Currently, the code is not careful at all with root isolation.
27 """
28 r = K.lmbda.interval_approximation()
29 l = r.lower * ZZ(10)**(-r.precision)
30 u = r.upper * ZZ(10)**(-r.precision)
31
32 p = QQ['x'](K.polynomial.coefficients)
33 s = AA.polynomial_root(p, RIF(l,u))
34 return NumberField(p, name, embedding=s)
35
36 def flipper_nf_element_to_sage(x):
37 r"""
38 Convert a flipper nf element to Sage.
39 """
40 return flipper_nf_to_sage(x.number_field)(x.linear_combination)
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.