Skip to content

Commit 14e1500

Browse files
committed
Fix Polynomial_real_arb tests
1 parent 290bc7c commit 14e1500

File tree

1 file changed

+67
-90
lines changed

1 file changed

+67
-90
lines changed

src/sage/rings/polynomial/polynomial_real_arb.pyx

Lines changed: 67 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ from cysignals.signals cimport sig_on, sig_off
2525

2626
from sage.libs.flint.arb cimport *
2727
from sage.libs.flint.fmpz cimport *
28+
from sage.libs.flint.arb_poly_macros cimport arb_poly_get_coeff_ptr
2829
from sage.rings.integer cimport Integer, smallInteger
2930
from sage.rings.real_arb cimport RealBall
3031
from sage.structure.element cimport Element
@@ -46,19 +47,19 @@ cdef class Polynomial_real_arb(Polynomial):
4647
sage: type(x)
4748
<class 'sage.rings.polynomial.polynomial_real_arb.Polynomial_real_arb'>
4849
49-
sage: Pol(), Pol(1), Pol([0,1,2]), Pol({1: pi, 3: i}) # needs sage.symbolic
50+
sage: Pol(), Pol(1), Pol([0,1,2]), Pol({1: pi, 3: e}) # needs sage.symbolic # abs tol 1e-15
5051
(0,
5152
1.000000000000000,
5253
2.000000000000000*x^2 + x,
53-
I*x^3 + ([3.141592653589793 +/- ...e-16])*x)
54+
[2.718281828459045 +/- 5.41e-16]*x^3 + [3.141592653589793 +/- 3.39e-16]*x)
5455
5556
sage: Pol("x - 2/3")
5657
x + [-0.666666666666667 +/- ...e-16]
5758
sage: Pol(polygen(QQ))
5859
x
5960
6061
sage: all(Pol.has_coerce_map_from(P) for P in
61-
....: (QQ['x'], QuadraticField(-1), RealBallField(100)))
62+
....: (QQ['x'], QuadraticField(2), RealBallField(100)))
6263
True
6364
sage: any(Pol.has_coerce_map_from(P) for P in
6465
....: (QQ['y'], RR, CC, RDF, CDF, RIF, CIF, RealBallField(20)))
@@ -119,13 +120,15 @@ cdef class Polynomial_real_arb(Polynomial):
119120
sage: Polynomial_real_arb(Pol, (1,))
120121
1.000000000000000
121122
sage: Polynomial_real_arb(Pol, (RBF(i), 1)) # needs sage.symbolic
122-
x + I
123+
Traceback (most recent call last):
124+
...
125+
ValueError: nonzero imaginary part
123126
sage: Polynomial_real_arb(Pol, polygen(QQ,'y')+2)
124127
x + 2.000000000000000
125128
sage: Polynomial_real_arb(Pol, QQ['x'](0))
126129
0
127-
sage: Polynomial_real_arb(Pol, {10: pi}) # needs sage.symbolic
128-
([3.141592653589793 +/- ...e-16])*x^10
130+
sage: Polynomial_real_arb(Pol, {10: pi}) # needs sage.symbolic # abs tol 1e-15
131+
[3.141592653589793 +/- 3.39e-16]*x^10
129132
sage: Polynomial_real_arb(Pol, pi) # needs sage.symbolic
130133
[3.141592653589793 +/- ...e-16]
131134
"""
@@ -220,8 +223,8 @@ cdef class Polynomial_real_arb(Polynomial):
220223
sage: Pol.<x> = RBF[]
221224
sage: (x^2 + 1).degree()
222225
2
223-
sage: pol = (x/3 + 1) - x/3; pol
224-
([+/- ...e-16])*x + 1.000000000000000
226+
sage: pol = (x/3 + 1) - x/3; pol # abs tol 1e-15
227+
[+/- 1.12e-16]*x + 1.000000000000000
225228
sage: pol.degree()
226229
1
227230
sage: Pol([1, 0, 0, 0]).degree()
@@ -276,8 +279,8 @@ cdef class Polynomial_real_arb(Polynomial):
276279
EXAMPLES::
277280
278281
sage: Pol.<x> = RBF[]
279-
sage: (x + 1) + (x/3 - 2)
280-
([1.333333333333333 +/- ...e-16])*x - 1.000000000000000
282+
sage: (x + 1) + (x/3 - 2) # abs tol 1e-15
283+
[1.333333333333333 +/- 5.37e-16]*x - 1.000000000000000
281284
"""
282285
cdef Polynomial_real_arb res = self._new()
283286
sig_on()
@@ -296,8 +299,8 @@ cdef class Polynomial_real_arb(Polynomial):
296299
EXAMPLES::
297300
298301
sage: Pol.<x> = RBF[]
299-
sage: -(x/3 - 2)
300-
([-0.3333333333333333 +/- ...e-17])*x + 2.000000000000000
302+
sage: -(x/3 - 2) # abs tol 1e-15
303+
[-0.3333333333333333 +/- 7.04e-17]*x + 2.000000000000000
301304
"""
302305
cdef Polynomial_real_arb res = self._new()
303306
sig_on()
@@ -312,8 +315,8 @@ cdef class Polynomial_real_arb(Polynomial):
312315
EXAMPLES::
313316
314317
sage: Pol.<x> = RBF[]
315-
sage: (x + 1) - (x/3 - 2)
316-
([0.666666666666667 +/- ...e-16])*x + 3.000000000000000
318+
sage: (x + 1) - (x/3 - 2) # abs tol 1e-15
319+
[0.666666666666667 +/- 5.37e-16]*x + 3.000000000000000
317320
"""
318321
cdef Polynomial_real_arb res = self._new()
319322
sig_on()
@@ -332,9 +335,8 @@ cdef class Polynomial_real_arb(Polynomial):
332335
EXAMPLES::
333336
334337
sage: Pol.<x> = RBF[]
335-
sage: (x + 1)*(x/3 - 2)
336-
([0.3333333333333333 +/- ...e-17])*x^2
337-
+ ([-1.666666666666667 +/- ...e-16])*x - 2.000000000000000
338+
sage: (x + 1)*(x/3 - 2) # abs tol 1e-15
339+
[0.3333333333333333 +/- 7.04e-17]*x^2 + [-1.666666666666667 +/- 7.59e-16]*x - 2.000000000000000
338340
"""
339341
cdef Polynomial_real_arb res = self._new()
340342
sig_on()
@@ -353,8 +355,8 @@ cdef class Polynomial_real_arb(Polynomial):
353355
sage: Pol.<x> = RBF[]
354356
sage: (x + 1)._lmul_(RBF(3))
355357
3.000000000000000*x + 3.000000000000000
356-
sage: (1 + x)*(1/3)
357-
([0.3333333333333333 +/- ...e-17])*x + [0.3333333333333333 +/- ...e-17]
358+
sage: (1 + x)*(1/3) # abs tol 1e-15
359+
[0.3333333333333333 +/- 7.04e-17]*x + [0.3333333333333333 +/- 7.04e-17]
358360
sage: (1 + x)*GF(2)(1)
359361
Traceback (most recent call last):
360362
...
@@ -373,8 +375,8 @@ cdef class Polynomial_real_arb(Polynomial):
373375
sage: Pol.<x> = RBF[]
374376
sage: (x + 1)._rmul_(RBF(3))
375377
3.000000000000000*x + 3.000000000000000
376-
sage: (1/3)*(1 + x)
377-
([0.3333333333333333 +/- ...e-17])*x + [0.3333333333333333 +/- ...e-17]
378+
sage: (1/3)*(1 + x) # abs tol 1e-15
379+
[0.3333333333333333 +/- 7.04e-17]*x + [0.3333333333333333 +/- 7.04e-17]
378380
"""
379381
return self._lmul_(a)
380382

@@ -391,11 +393,9 @@ cdef class Polynomial_real_arb(Polynomial):
391393
392394
sage: Pol.<x> = RBF[]
393395
394-
sage: (x^3/7 - RBF(i)).quo_rem(x + RBF(pi)) # needs sage.symbolic
395-
(([0.1428571428571428 +/- ...e-17])*x^2
396-
+ ([-0.448798950512828 +/- ...e-16])*x
397-
+ [1.409943485869908 +/- ...e-16],
398-
[-4.42946809718569 +/- ...e-15] - I)
396+
sage: (x^3/7 - 2).quo_rem(x + 3) # abs tol 1e-14
397+
([0.1428571428571428 +/- 7.70e-17]*x^2 + [-0.428571428571429 +/- 5.36e-16]*x + [1.285714285714286 +/- 8.85e-16],
398+
[-5.85714285714286 +/- 4.66e-15])
399399
400400
sage: Pol(0).quo_rem(x + 1)
401401
(0, 0)
@@ -405,13 +405,12 @@ cdef class Polynomial_real_arb(Polynomial):
405405
...
406406
ZeroDivisionError: ('cannot divide by this polynomial', 0)
407407
408-
sage: div = (x^2/3 + x + 1) - x^2/3; div
409-
([+/- ...e-16])*x^2 + x + 1.000000000000000
408+
sage: div = (x^2/3 + x + 1) - x^2/3; div # abs tol 1e-15
409+
[+/- 1.12e-16]*x^2 + x + 1.000000000000000
410410
sage: (x + 1).quo_rem(div)
411411
Traceback (most recent call last):
412412
...
413-
ZeroDivisionError: ('cannot divide by this polynomial',
414-
([+/- ...e-16])*x^2 + x + 1.000000000000000)
413+
ZeroDivisionError: ('cannot divide by this polynomial', [+/- 1.12e-16]*x^2 + x + 1.000000000000000)
415414
"""
416415
cdef Polynomial_real_arb div = <Polynomial_real_arb> divisor
417416
cdef Polynomial_real_arb quo = self._new()
@@ -568,12 +567,12 @@ cdef class Polynomial_real_arb(Polynomial):
568567
EXAMPLES::
569568
570569
sage: Pol.<x> = RBF[]
571-
sage: (1 - x/3).inverse_series_trunc(3)
572-
([0.1111111111111111 +/- ...e-17])*x^2 + ([0.3333333333333333 +/- ...e-17])*x + 1.000000000000000
570+
sage: (1 - x/3).inverse_series_trunc(3) # abs tol 1e-15
571+
[0.1111111111111111 +/- 5.99e-17]*x^2 + [0.3333333333333333 +/- 7.04e-17]*x + 1.000000000000000
573572
sage: x.inverse_series_trunc(1)
574573
nan
575574
sage: Pol(0).inverse_series_trunc(2)
576-
(nan + nan*I)*x + nan + nan*I
575+
nan*x + nan
577576
578577
TESTS::
579578
@@ -632,25 +631,16 @@ cdef class Polynomial_real_arb(Polynomial):
632631
EXAMPLES::
633632
634633
sage: Pol.<x> = RBF[]
635-
sage: (1 + x/3)._log_series(3)
636-
([-0.0555555555555555 +/- ...e-17])*x^2 + ([0.3333333333333333 +/- ...e-17])*x
637-
sage: (-1 + x)._log_series(3)
638-
-0.5000000000000000*x^2 - x + [3.141592653589793 +/- ...e-16]*I
639-
640-
An example where the constant term crosses the branch cut of the
641-
logarithm::
642-
643-
sage: pol = RBF(-1, RBF(0, rad=.01)) + x; pol
644-
x - 1.000000000000000 + [+/- 0.0101]*I
645-
sage: pol._log_series(2)
646-
([-1.000 +/- ...e-4] + [+/- 0.0101]*I)*x + [+/- ...e-5] + [+/- 3.15]*I
634+
sage: (1 + x/3)._log_series(3) # abs tol 1e-15
635+
[-0.0555555555555555 +/- 7.10e-17]*x^2 + [0.3333333333333333 +/- 7.04e-17]*x
647636
648637
Some cases where the result is not defined::
649-
638+
sage: (-1 + x)._log_series(3) # the result's constant term is pi*I, not real
639+
nan*x^2 + nan*x + nan
650640
sage: x._log_series(1)
651-
nan + nan*I
641+
nan
652642
sage: Pol(0)._log_series(1)
653-
nan + nan*I
643+
nan
654644
"""
655645
cdef Polynomial_real_arb res = self._new()
656646
if n < 0:
@@ -670,11 +660,8 @@ cdef class Polynomial_real_arb(Polynomial):
670660
sage: Pol.<x> = RBF[]
671661
sage: x._exp_series(3)
672662
0.5000000000000000*x^2 + x + 1.000000000000000
673-
sage: (1 + x/3)._log_series(3)._exp_series(3)
674-
([+/- ...e-17])*x^2 + ([0.3333333333333333 +/- ...e-17])*x + 1.000000000000000
675-
sage: (RBF(0, pi) + x)._exp_series(4) # needs sage.symbolic
676-
([-0.166...] + [+/- ...]*I)*x^3 + ([-0.500...] + [+/- ...]*I)*x^2
677-
+ ([-1.000...] + [+/- ...]*I)*x + [-1.000...] + [+/- ...]*I
663+
sage: (1 + x/3)._log_series(3)._exp_series(3) # abs tol 1e-15
664+
[+/- 4.79e-17]*x^2 + [0.3333333333333333 +/- 7.04e-17]*x + 1.000000000000000
678665
"""
679666
cdef Polynomial_real_arb res = self._new()
680667
if n < 0:
@@ -694,12 +681,8 @@ cdef class Polynomial_real_arb(Polynomial):
694681
sage: Pol.<x> = RBF[]
695682
sage: (1 + x)._sqrt_series(3)
696683
-0.1250000000000000*x^2 + 0.5000000000000000*x + 1.000000000000000
697-
sage: pol = RBF(-1, RBF(0, rad=.01)) + x; pol
698-
x - 1.000000000000000 + [+/- 0.0101]*I
699-
sage: pol._sqrt_series(2)
700-
([+/- ...e-3] + [+/- 0.501]*I)*x + [+/- ...e-3] + [+/- 1.01]*I
701684
sage: x._sqrt_series(2)
702-
(nan + nan*I)*x
685+
nan*x
703686
"""
704687
cdef Polynomial_real_arb res = self._new()
705688
if n < 0:
@@ -717,8 +700,8 @@ cdef class Polynomial_real_arb(Polynomial):
717700
EXAMPLES::
718701
719702
sage: Pol.<x> = RBF[]
720-
sage: (1 + x)._gamma_series(3)
721-
([0.98905599532797...])*x^2 + ([-0.57721566490153...])*x + 1.000000000000000
703+
sage: (1 + x)._gamma_series(3) # abs tol 1e-12
704+
[0.989055995327973 +/- 6.12e-16]*x^2 + [-0.577215664901533 +/- 3.58e-16]*x + 1.000000000000000
722705
"""
723706
cdef Polynomial_real_arb res = self._new()
724707
if n < 0:
@@ -736,8 +719,8 @@ cdef class Polynomial_real_arb(Polynomial):
736719
EXAMPLES::
737720
738721
sage: Pol.<x> = RBF[]
739-
sage: (1000 + x)._lgamma_series(3)
740-
([0.00050025008333331...])*x^2 + ([6.9072551956488...])*x + [5905.2204232091...]
722+
sage: (1000 + x)._lgamma_series(3) # abs tol 1e-15
723+
[0.000500250083333317 +/- 4.84e-19]*x^2 + [6.90725519564881 +/- 2.90e-15]*x + [5905.220423209181 +/- 2.49e-13]
741724
"""
742725
cdef Polynomial_real_arb res = self._new()
743726
if n < 0:
@@ -755,8 +738,8 @@ cdef class Polynomial_real_arb(Polynomial):
755738
EXAMPLES::
756739
757740
sage: Pol.<x> = RBF[]
758-
sage: (-1 + x)._rgamma_series(4)
759-
([1.23309373642178...])*x^3 + ([0.422784335098467...])*x^2 - x
741+
sage: (-1 + x)._rgamma_series(4) # abs tol 1e-15
742+
[1.233093736421787 +/- 5.71e-16]*x^3 + [0.4227843350984671 +/- 9.09e-17]*x^2 - x
760743
"""
761744
cdef Polynomial_real_arb res = self._new()
762745
if n < 0:
@@ -774,27 +757,23 @@ cdef class Polynomial_real_arb(Polynomial):
774757
EXAMPLES::
775758
776759
sage: Pol.<x> = RBF[]
777-
sage: (1 + x)._lambert_w_series(3)
778-
([-0.10727032...])*x^2 + ([0.36189625...])*x + [0.56714329...]
779-
sage: (RBF(1, 1) + x)._lambert_w_series(2)
780-
([0.26651990...] + [-0.15238505...]*I)*x + [0.65696606...] + [0.32545033...]*I
781-
sage: (1 + x)._lambert_w_series(2, branch=3)
782-
([1.00625557...] + [0.05775573...]*I)*x + [-2.85358175...] + [17.1135355...]*I
783-
sage: (1 + x)._lambert_w_series(2, branch=-3)
784-
([1.00625557...] + [-0.05775573...]*I)*x + [-2.85358175...] + [-17.1135355...]*I
785-
sage: (1 + x)._lambert_w_series(2, branch=2^100)
786-
([1.00000000...] + [1.25551112...]*I)*x + [-71.1525951...] + [7.96488362...]*I
787-
"""
788-
cdef fmpz_t _branch
789-
fmpz_init(_branch)
790-
fmpz_set_mpz(_branch, (<Integer> Integer(branch)).value)
760+
sage: (1 + x)._lambert_w_series(3) # abs tol 1e-14
761+
[-0.107270323141072 +/- 7.79e-16]*x^2 + [0.361896256634889 +/- 2.99e-16]*x + [0.567143290409784 +/- 2.72e-16]
762+
sage: (-1/4 + x)._lambert_w_series(2, branch=-1) # abs tol 1e-14
763+
[-7.46833129610253 +/- 3.12e-15]*x + [-2.153292364110349 +/- 8.59e-16]
764+
"""
765+
if branch == 0:
766+
flags = 0
767+
elif branch == -1:
768+
flags = 1
769+
else:
770+
raise ValueError("for other branches, use polynomials over CBF")
791771
cdef Polynomial_real_arb res = self._new()
792772
if n < 0:
793773
n = 0
794774
sig_on()
795-
arb_poly_lambertw_series(res._poly, self._poly, _branch, 0, n, prec(self))
775+
arb_poly_lambertw_series(res._poly, self._poly, flags, n, prec(self))
796776
sig_off()
797-
fmpz_clear(_branch)
798777
return res
799778

800779
def _zeta_series(self, long n, a=1, deflate=False):
@@ -810,12 +789,10 @@ cdef class Polynomial_real_arb(Polynomial):
810789
EXAMPLES::
811790
812791
sage: Pol.<x> = RBF[]
813-
sage: (RBF(1/2, 1) + x)._zeta_series(2)
814-
([0.55898247...] + [-0.64880821...]*I)*x + [0.14393642...] + [-0.72209974...]*I
815-
sage: (1/2 + x^2)._zeta_series(3, a=1/3)
816-
([-2.13199508...])*x^2 + [-0.11808332...]
817-
sage: (1 + x)._zeta_series(2, deflate=True)
818-
([0.07281584...])*x + [0.57721566...]
792+
sage: (1/2 + x^2)._zeta_series(3, a=1/3) # abs tol 1e-15
793+
[-2.13199508553675 +/- 2.90e-15]*x^2 + [-0.118083327934222 +/- 5.54e-16]
794+
sage: (1 + x)._zeta_series(2, deflate=True) # abs tol 1e-15
795+
[0.0728158454836767 +/- 2.97e-17]*x + [0.5772156649015329 +/- 4.09e-17]
819796
"""
820797
if n < 0:
821798
n = 0
@@ -839,8 +816,8 @@ cdef class Polynomial_real_arb(Polynomial):
839816
-3.000000000000000*x^3 - x^2 + x
840817
sage: pol.compose_trunc(1 + x, 4)
841818
x^3 + x^2
842-
sage: pol.compose_trunc(2 + x/3, 2)
843-
([1.666666666666667 +/- ...e-16])*x + 2.000000000000000
819+
sage: pol.compose_trunc(2 + x/3, 2) # abs tol 1e-15
820+
[1.666666666666667 +/- 9.81e-16]*x + 2.000000000000000
844821
sage: pol.compose_trunc(2 + x/3, 0)
845822
0
846823
sage: pol.compose_trunc(2 + x/3, -1)
@@ -887,8 +864,8 @@ cdef class Polynomial_real_arb(Polynomial):
887864
sage: (2*x).revert_series(5)
888865
0.5000000000000000*x
889866
890-
sage: (x + x^3/6 + x^5/120).revert_series(6)
891-
([0.075000000000000 +/- ...e-17])*x^5 + ([-0.166666666666667 +/- ...e-16])*x^3 + x
867+
sage: (x + x^3/6 + x^5/120).revert_series(6) # abs tol 1e-15
868+
[0.075000000000000 +/- 9.96e-17]*x^5 + [-0.166666666666667 +/- 4.45e-16]*x^3 + x
892869
893870
sage: (1 + x).revert_series(6)
894871
Traceback (most recent call last):

0 commit comments

Comments
 (0)