..nodoctest
Polynomials¶
x.__init__(...) initializes x; see help(type(x)) for signature
-
recip.polynomials.
my_round
(x)¶ Rounds x to the nearest element in ZZ.
-
recip.polynomials.
recognize_polynomial
(pol_n, K=None, N=None, M=None, emb=None, poly_gen=None, solution=None, check=True)¶ Given a polynomial pol_n over the real or complex numbers, guesses a polynomial over number field K close to it. Note, K must be embedded into the real or complex numbers.
INPUT:
- \(pol_n\) – a polynomial over a real or complex field \(A\)
- \(K\) – a number field
- \(N\) (default:None) – a positive number or None, weigh the output minus pol_n by this factor. If None, determine one from the precision of pol_n (and assume pol_n is accurate to nearly its precision). Actually, the value for N=None is pretty arbitrary.
- \(M\) (default:None) – a positive number or None, weigh the coefficients of the output by this factor. If None, determine one from the precision of pol_n (and assume pol_n is accurate to nearly its precision). Actually, the value for M=None is pretty arbitrary.
- \(emb\) (default:None) – an embedding of \(K\) into a complex or real field, use this to embed \(K\) into \(A\). If None, then try to coerce.
- \(poly_gen\) (default:None) – a polynomial ring generator to use for the output, or a string, or None. If a string, create a new polynomial ring over \(K\) with that string as variable name. If None, use variable name \(y\).
- \(solution\) (default:None) – a pair (pol, den), where pol is a correct polynomial over \(K\) such that pol_n approximates pol/den . For debugging purposes only.
EXAMPLES:
sage: from recip import * sage: Q.<y> = QQ[] sage: K.<a> = NumberField(y^2+y-7) sage: P.<x> = K[] sage: R.<X> = RR[] sage: emb = K.embeddings(RR)[0] sage: pol_n = emb(a+4)*X^2 + emb(5*a-7/32)*X + emb((7*a-8)/29) sage: recognize_polynomial(pol_n, emb=emb) (a + 4)*y^2 + (5*a - 7/32)*y + 7/29*a - 8/29 sage: P.<x> = QQ[] sage: K.<a> = NumberField(x^4+13*x^2+41) sage: emb = K.embeddings(CC)[0] sage: P.<X> = PolynomialRing(CC) sage: pol_n = emb(a/8+a^2/7+53)*X^5 + emb(a+5)*X^4 - 11/13*X + 83; pol_n (51.9117094301786 - 0.345009827503822*I)*X^5 + (5.00000000000000 - 2.76007862003058*I)*X^4 - 0.846153846153846*X + 83.0000000000000 sage: recognize_polynomial(pol_n, K, emb=emb) (1/7*a^2 + 1/8*a + 53)*y^5 + (a + 5)*y^4 - 11/13*y + 83
Larger example:
sage: P.<y> = PolynomialRing(Rationals()) sage: kr = NumberField(y^4+26*y^2+5,'a') sage: poly = y^2 - 3669057/256*y + 3255076125/64 sage: s = poly.roots(kr)[1][0]; s -56133/1024*a^2 + 6608385/1024 sage: C = ComplexField(500) sage: emb = kr.embeddings(C)[1] sage: emb(s) 6464.12192808629278258077515091885499223178761073356317753629949149850565866041944398811655264025009640104066290246943889048395671706574175947746682694 sage: r = recognize_polynomial(emb(s), kr, emb=emb)[0] sage: r == s True
-
recip.polynomials.
short_interpolation
(a, b)¶ Given lists a and b of the same lengths, returns the polynomial
P = sum_i b[i] prod_{j!=i} (x-a[j])which satisfies P(a[i]) = b[i] * H’(a[i]), where H = prod (x-a[i]).
EXAMPLES:
sage: from recip import * sage: p = short_interpolation([3],[3]); p 3 sage: p.parent() Univariate Polynomial Ring in x over Integer Ring sage: p = short_interpolation([1,3],[2,3.]); p 5.00000000000000*x - 9.00000000000000 sage: p.parent() Univariate Polynomial Ring in x over Real Field with 53 bits of precision