# HG changeset patch
# User Jeroen Demeyer <jdemeyer@cage.ugent.be>
# Date 1343383018 -7200
# Node ID 69b752a001c262d96d94934778ba16981c01b393
# Parent 698ec14c513f99fa5a3a7aeca982cc14fd249a89
Upgrade to mpc-1.0.
diff --git a/doc/en/developer/producing_spkgs.rst b/doc/en/developer/producing_spkgs.rst
a
|
b
|
|
194 | 194 | The ``spkg-install`` script should copy your files to the appropriate |
195 | 195 | place after doing any build that is necessary. Here is a template:: |
196 | 196 | |
197 | | #!/usr/bin/env bash |
| 197 | #!/usr/bin/env bash |
198 | 198 | |
199 | | if [ -z "$SAGE_LOCAL" ]; then |
200 | | echo >&2 "SAGE_LOCAL undefined ... exiting" |
201 | | echo >&2 "Maybe run 'sage --sh'?" |
202 | | exit 1 |
203 | | fi |
| 199 | if [ -z "$SAGE_LOCAL" ]; then |
| 200 | echo >&2 "SAGE_LOCAL undefined ... exiting" |
| 201 | echo >&2 "Maybe run 'sage --sh'?" |
| 202 | exit 1 |
| 203 | fi |
204 | 204 | |
205 | | cd src |
| 205 | cd src |
206 | 206 | |
207 | | # Apply patches. See SPKG.txt for information about what each patch |
208 | | # does. |
209 | | for patch in ../patches/*.patch; do |
210 | | patch -p1 <"$patch" |
211 | | if [ $? -ne 0 ]; then |
212 | | echo >&2 "Error applying '$patch'" |
213 | | exit 1 |
214 | | fi |
215 | | done |
| 207 | # Apply patches. See SPKG.txt for information about what each patch |
| 208 | # does. |
| 209 | for patch in ../patches/*.patch; do |
| 210 | [ -r "$patch" ] || continue # Skip non-existing or non-readable patches |
| 211 | patch -p1 <"$patch" |
| 212 | if [ $? -ne 0 ]; then |
| 213 | echo >&2 "Error applying '$patch'" |
| 214 | exit 1 |
| 215 | fi |
| 216 | done |
216 | 217 | |
217 | | ./configure --prefix="$SAGE_LOCAL" |
218 | | if [ $? -ne 0 ]; then |
219 | | echo >&2 "Error configuring PACKAGE_NAME." |
220 | | exit 1 |
221 | | fi |
| 218 | ./configure --prefix="$SAGE_LOCAL" |
| 219 | if [ $? -ne 0 ]; then |
| 220 | echo >&2 "Error configuring PACKAGE_NAME." |
| 221 | exit 1 |
| 222 | fi |
222 | 223 | |
223 | | $MAKE |
224 | | if [ $? -ne 0 ]; then |
225 | | echo >&2 "Error building PACKAGE_NAME." |
226 | | exit 1 |
227 | | fi |
| 224 | $MAKE |
| 225 | if [ $? -ne 0 ]; then |
| 226 | echo >&2 "Error building PACKAGE_NAME." |
| 227 | exit 1 |
| 228 | fi |
228 | 229 | |
229 | | $MAKE install |
230 | | if [ $? -ne 0 ]; then |
231 | | echo >&2 "Error installing PACKAGE_NAME." |
232 | | exit 1 |
233 | | fi |
| 230 | $MAKE install |
| 231 | if [ $? -ne 0 ]; then |
| 232 | echo >&2 "Error installing PACKAGE_NAME." |
| 233 | exit 1 |
| 234 | fi |
234 | 235 | |
235 | | if [ "$SAGE_SPKG_INSTALL_DOCS" = yes ] ; then |
236 | | # Before trying to build the documentation, check if any |
237 | | # needed programs are present. In the example below, we |
238 | | # check for 'latex', but this will depend on the package. |
239 | | # Some packages may need no extra tools installed, others |
240 | | # may require some. We use 'command -v' for testing this, |
241 | | # and not 'which' since 'which' is not portable, whereas |
242 | | # 'command -v' is defined by POSIX. |
| 236 | if [ "$SAGE_SPKG_INSTALL_DOCS" = yes ] ; then |
| 237 | # Before trying to build the documentation, check if any |
| 238 | # needed programs are present. In the example below, we |
| 239 | # check for 'latex', but this will depend on the package. |
| 240 | # Some packages may need no extra tools installed, others |
| 241 | # may require some. We use 'command -v' for testing this, |
| 242 | # and not 'which' since 'which' is not portable, whereas |
| 243 | # 'command -v' is defined by POSIX. |
243 | 244 | |
244 | | # if [ `command -v latex` ] ; then |
245 | | # echo "Good, latex was found, so building the documentation" |
246 | | # else |
247 | | # echo "Sorry, can't build the documentation for PACKAGE_NAME as latex is not installed" |
248 | | # exit 1 |
249 | | # fi |
| 245 | # if [ `command -v latex` ] ; then |
| 246 | # echo "Good, latex was found, so building the documentation" |
| 247 | # else |
| 248 | # echo "Sorry, can't build the documentation for PACKAGE_NAME as latex is not installed" |
| 249 | # exit 1 |
| 250 | # fi |
250 | 251 | |
251 | 252 | |
252 | | # make the documentation in a package-specific way |
253 | | # for example, we might have |
254 | | # cd doc |
255 | | # $MAKE html |
| 253 | # make the documentation in a package-specific way |
| 254 | # for example, we might have |
| 255 | # cd doc |
| 256 | # $MAKE html |
256 | 257 | |
257 | | if [ $? -ne 0 ]; then |
258 | | echo >&2 "Error building PACKAGE_NAME docs." |
259 | | exit 1 |
260 | | fi |
261 | | mkdir -p $SAGE_ROOT/local/share/doc/PACKAGE_NAME |
262 | | # assuming the docs are in doc/* |
263 | | cp -r doc/* $SAGE_ROOT/local/share/doc/PACKAGE_NAME/ |
264 | | fi |
| 258 | if [ $? -ne 0 ]; then |
| 259 | echo >&2 "Error building PACKAGE_NAME docs." |
| 260 | exit 1 |
| 261 | fi |
| 262 | mkdir -p "$SAGE_ROOT/local/share/doc/PACKAGE_NAME" |
| 263 | # assuming the docs are in doc/* |
| 264 | cp -R doc/* "$SAGE_ROOT/local/share/doc/PACKAGE_NAME" |
| 265 | fi |
265 | 266 | |
266 | 267 | |
267 | 268 | Note that the first line is ``#!/usr/bin/env bash``; this is important |
diff --git a/doc/en/reference/rings_numerical.rst b/doc/en/reference/rings_numerical.rst
a
|
b
|
|
27 | 27 | sage/rings/real_mpfr |
28 | 28 | sage/rings/complex_field |
29 | 29 | sage/rings/complex_number |
30 | | sage/rings/real_mpfi |
31 | | No newline at end of file |
| 30 | sage/rings/complex_mpc |
| 31 | sage/rings/real_mpfi |
diff --git a/sage/rings/all.py b/sage/rings/all.py
a
|
b
|
|
110 | 110 | |
111 | 111 | from complex_double import ComplexDoubleField, ComplexDoubleElement, CDF, is_ComplexDoubleElement |
112 | 112 | |
| 113 | from complex_mpc import MPComplexField |
| 114 | |
113 | 115 | # Power series rings |
114 | 116 | from power_series_ring import PowerSeriesRing, is_PowerSeriesRing |
115 | 117 | from power_series_ring_element import PowerSeries, is_PowerSeries |
diff --git a/sage/rings/complex_mpc.pyx b/sage/rings/complex_mpc.pyx
a
|
b
|
|
1 | 1 | """ |
2 | | Arbitrary Precision Complex Numbers |
| 2 | Arbitrary Precision Complex Numbers using GNU MPC |
3 | 3 | |
4 | 4 | This is a binding for the MPC arbitrary-precision floating point library. |
5 | 5 | It is adaptated from real_mpfr.pyx and complex_number.pyx. |
6 | 6 | |
7 | | We define a class \class{MPComplexField}, where each instance of |
8 | | \class{MPComplexField} specifies a field of floating-point complex numbers with |
| 7 | We define a class :class:`MPComplexField`, where each instance of |
| 8 | ``MPComplexField`` specifies a field of floating-point complex numbers with |
9 | 9 | a specified precision shared by the real and imaginary part and a rounding |
10 | 10 | mode stating the rounding mode directions specific to real and imaginary |
11 | 11 | parts. |
12 | 12 | |
13 | | Individual floating-point numbers are of class \class{MPComplexNumber}. |
| 13 | Individual floating-point numbers are of class :class:`MPComplexNumber`. |
14 | 14 | |
15 | 15 | For floating-point representation and rounding mode description see the |
16 | 16 | documentation for the module sage.rings.real_mpfr |
… |
… |
|
28 | 28 | |
29 | 29 | EXAMPLES:: |
30 | 30 | |
31 | | sage: from sage.rings.complex_mpc import * |
32 | 31 | sage: MPC = MPComplexField(42) |
33 | 32 | sage: a = MPC(12, '15.64E+32'); a |
34 | 33 | 12.0000000000 + 1.56400000000e33*I |
… |
… |
|
238 | 237 | |
239 | 238 | EXAMPLES:: |
240 | 239 | |
241 | | sage: from sage.rings.complex_mpc import MPComplexField |
242 | 240 | sage: MPComplexField() |
243 | 241 | Complex Field with 53 bits of precision |
244 | 242 | sage: MPComplexField(100) |
… |
… |
|
285 | 283 | |
286 | 284 | EXAMPLES:: |
287 | 285 | |
288 | | sage: from sage.rings.complex_mpc import MPComplexField |
289 | 286 | sage: MPComplexField(17) |
290 | 287 | Complex Field with 17 bits of precision |
291 | 288 | sage: MPComplexField() |
… |
… |
|
317 | 314 | |
318 | 315 | cdef MPComplexNumber _new(self): |
319 | 316 | """ |
320 | | Return a new complex number with parent self. |
| 317 | Return a new complex number with parent ``self`. |
321 | 318 | """ |
322 | 319 | cdef MPComplexNumber z |
323 | 320 | z = PY_NEW(MPComplexNumber) |
… |
… |
|
330 | 327 | """ |
331 | 328 | EXAMPLES:: |
332 | 329 | |
333 | | sage: from sage.rings.complex_mpc import MPComplexField |
334 | 330 | sage: MPComplexField(200, 'RNDDU') |
335 | 331 | Complex Field with 200 bits of precision and rounding RNDDU |
336 | 332 | """ |
… |
… |
|
343 | 339 | """ |
344 | 340 | EXAMPLES:: |
345 | 341 | |
346 | | sage: from sage.rings.complex_mpc import MPComplexField |
347 | 342 | sage: MPC = MPComplexField(10) |
348 | 343 | sage: latex(MPC) |
349 | 344 | \C |
… |
… |
|
356 | 351 | |
357 | 352 | EXAMPLES:: |
358 | 353 | |
359 | | sage: from sage.rings.complex_mpc import MPComplexField |
360 | 354 | sage: MPC = MPComplexField() |
361 | 355 | sage: MPC(2) |
362 | 356 | 2.00000000000000 |
… |
… |
|
380 | 374 | |
381 | 375 | EXAMPLES:: |
382 | 376 | |
383 | | sage: from sage.rings.complex_mpc import MPComplexField |
384 | 377 | sage: C20 = MPComplexField(20) |
385 | 378 | |
386 | 379 | The value can be set with a couple of reals:: |
… |
… |
|
440 | 433 | |
441 | 434 | EXAMPLES:: |
442 | 435 | |
443 | | sage: from sage.rings.complex_mpc import MPComplexField |
444 | 436 | sage: MPComplexField(100)(17, '4.2') + MPComplexField(20)('6.0', -23) |
445 | 437 | 23.000 - 18.800*I |
446 | 438 | sage: a = MPComplexField(100)(17, '4.2') + MPComplexField(20)('6.0', -23) |
… |
… |
|
475 | 467 | """ |
476 | 468 | EXAMPLES:: |
477 | 469 | |
478 | | sage: from sage.rings.complex_mpc import MPComplexField |
479 | 470 | sage: C = MPComplexField(prec=200, rnd='RNDDZ') |
480 | 471 | sage: loads(dumps(C)) == C |
481 | 472 | True |
… |
… |
|
486 | 477 | """ |
487 | 478 | EXAMPLES:: |
488 | 479 | |
489 | | sage: from sage.rings.complex_mpc import MPComplexField |
490 | 480 | sage: MPComplexField(10) == MPComplexField(11) |
491 | 481 | False |
492 | 482 | sage: MPComplexField(10) == MPComplexField(10) |
… |
… |
|
512 | 502 | |
513 | 503 | EXAMPLES:: |
514 | 504 | |
515 | | sage: from sage.rings.complex_mpc import MPComplexField |
516 | 505 | sage: MPComplexField(34).gen() |
517 | 506 | 1.00000000*I |
518 | 507 | """ |
… |
… |
|
527 | 516 | |
528 | 517 | EXAMPLES:: |
529 | 518 | |
530 | | sage: from sage.rings.complex_mpc import MPComplexField |
531 | 519 | sage: MPComplexField(34).ngens() |
532 | 520 | 1 |
533 | 521 | """ |
… |
… |
|
539 | 527 | |
540 | 528 | EXAMPLES:: |
541 | 529 | |
542 | | sage: from sage.rings.complex_mpc import MPComplexField |
543 | 530 | sage: MPC = MPComplexField(20) |
544 | 531 | sage: MPC._an_element_() |
545 | 532 | 1.0000*I |
… |
… |
|
553 | 540 | |
554 | 541 | EXAMPLES:: |
555 | 542 | |
556 | | sage: from sage.rings.complex_mpc import MPComplexField |
557 | 543 | sage: MPComplexField(100).random_element(-5, 10) # random |
558 | 544 | 1.9305310520925994224072377281 + 0.94745292506956219710477444855*I |
559 | 545 | sage: MPComplexField(10).random_element() # random |
… |
… |
|
576 | 562 | |
577 | 563 | EXAMPLES:: |
578 | 564 | |
579 | | sage: from sage.rings.complex_mpc import MPComplexField |
580 | 565 | sage: MPComplexField(42).is_atomic_repr() |
581 | 566 | False |
582 | 567 | """ |
… |
… |
|
591 | 576 | |
592 | 577 | EXAMPLES:: |
593 | 578 | |
594 | | sage: from sage.rings.complex_mpc import MPComplexField |
595 | 579 | sage: MPComplexField(17).is_finite() |
596 | 580 | False |
597 | 581 | """ |
… |
… |
|
603 | 587 | |
604 | 588 | EXAMPLES:: |
605 | 589 | |
606 | | sage: from sage.rings.complex_mpc import MPComplexField |
607 | 590 | sage: MPComplexField(42).characteristic() |
608 | 591 | 0 |
609 | 592 | """ |
… |
… |
|
615 | 598 | |
616 | 599 | EXAMPLES:: |
617 | 600 | |
618 | | sage: from sage.rings.complex_mpc import MPComplexField |
619 | 601 | sage: C = MPComplexField(10, 'RNDNZ'); C.name() |
620 | 602 | 'MPComplexField10_RNDNZ' |
621 | 603 | """ |
… |
… |
|
625 | 607 | """ |
626 | 608 | EXAMPLES:: |
627 | 609 | |
628 | | sage: from sage.rings.complex_mpc import MPComplexField |
629 | 610 | sage: MPC = MPComplexField() |
630 | 611 | sage: hash(MPC) % 2^32 == hash(MPC.name()) % 2^32 |
631 | 612 | True |
… |
… |
|
638 | 619 | |
639 | 620 | EXAMPLES:: |
640 | 621 | |
641 | | sage: from sage.rings.complex_mpc import MPComplexField |
642 | 622 | sage: MPComplexField().prec() |
643 | 623 | 53 |
644 | 624 | sage: MPComplexField(22).prec() |
… |
… |
|
652 | 632 | |
653 | 633 | EXAMPLES:: |
654 | 634 | |
655 | | sage: from sage.rings.complex_mpc import MPComplexField |
656 | 635 | sage: MPComplexField().rounding_mode() |
657 | 636 | 'RNDNN' |
658 | 637 | sage: MPComplexField(rnd='RNDZU').rounding_mode() |
… |
… |
|
666 | 645 | |
667 | 646 | EXAMPLES:: |
668 | 647 | |
669 | | sage: from sage.rings.complex_mpc import MPComplexField |
670 | 648 | sage: MPComplexField(rnd='RNDZU').rounding_mode_real() |
671 | 649 | 'RNDZ' |
672 | 650 | """ |
… |
… |
|
678 | 656 | |
679 | 657 | EXAMPLES:: |
680 | 658 | |
681 | | sage: from sage.rings.complex_mpc import MPComplexField |
682 | 659 | sage: MPComplexField(rnd='RNDZU').rounding_mode_imag() |
683 | 660 | 'RNDU' |
684 | 661 | """ |
… |
… |
|
690 | 667 | |
691 | 668 | EXAMPLES:: |
692 | 669 | |
693 | | sage: from sage.rings.complex_mpc import MPComplexField |
694 | 670 | sage: MPComplexField()._real_field() |
695 | 671 | Real Field with 53 bits of precision |
696 | 672 | """ |
… |
… |
|
702 | 678 | |
703 | 679 | EXAMPLES:: |
704 | 680 | |
705 | | sage: from sage.rings.complex_mpc import MPComplexField |
706 | 681 | sage: MPComplexField(prec=100)._imag_field() |
707 | 682 | Real Field with 100 bits of precision |
708 | 683 | """ |
… |
… |
|
722 | 697 | """ |
723 | 698 | cdef MPComplexNumber _new(self): |
724 | 699 | """ |
725 | | Return a new complex number with same parent as self. |
| 700 | Return a new complex number with same parent as ``self``. |
726 | 701 | """ |
727 | 702 | cdef MPComplexNumber z |
728 | 703 | z = PY_NEW(MPComplexNumber) |
… |
… |
|
745 | 720 | |
746 | 721 | EXAMPLES:: |
747 | 722 | |
748 | | sage: from sage.rings.complex_mpc import MPComplexField |
749 | 723 | sage: C200 = MPComplexField(200) |
750 | 724 | sage: C200(1/3, '0.6789') |
751 | 725 | 0.33333333333333333333333333333333333333333333333333333333333 + 0.67890000000000000000000000000000000000000000000000000000000*I |
… |
… |
|
781 | 755 | """ |
782 | 756 | EXAMPLES:: |
783 | 757 | |
784 | | sage: from sage.rings.complex_mpc import MPComplexField |
785 | 758 | sage: MPC = MPComplexField(100) |
786 | 759 | sage: r = RealField(100).pi() |
787 | 760 | sage: z = MPC(r); z |
… |
… |
|
879 | 852 | """ |
880 | 853 | EXAMPLES:: |
881 | 854 | |
882 | | sage: from sage.rings.complex_mpc import * |
883 | 855 | sage: C = MPComplexField(prec=200, rnd='RNDUU') |
884 | 856 | sage: b = C(393.39203845902384098234098230948209384028340) |
885 | 857 | sage: loads(dumps(b)) == b; |
… |
… |
|
910 | 882 | """ |
911 | 883 | EXAMPLES:: |
912 | 884 | |
913 | | sage: from sage.rings.complex_mpc import MPComplexField |
914 | 885 | sage: MPComplexField()(2, -3) |
915 | 886 | 2.00000000000000 - 3.00000000000000*I |
916 | 887 | """ |
… |
… |
|
920 | 891 | """ |
921 | 892 | EXAMPLES:: |
922 | 893 | |
923 | | sage: from sage.rings.complex_mpc import MPComplexField |
924 | 894 | sage: latex(MPComplexField()(2, -3)) |
925 | 895 | 2.00000000000000 - 3.00000000000000i |
926 | 896 | """ |
… |
… |
|
930 | 900 | |
931 | 901 | def __hash__(self): |
932 | 902 | """ |
933 | | Returns the hash of self, which coincides with the python |
| 903 | Returns the hash of ``self``, which coincides with the python |
934 | 904 | complex and float (and often int) types. |
935 | 905 | |
936 | 906 | This has the drawback that two very close high precision |
937 | 907 | numbers will have the same hash, but allows them to play |
938 | 908 | nicely with other real types. |
939 | 909 | |
940 | | EXAMPLE: |
941 | | sage: from sage.rings.complex_mpc import * |
| 910 | EXAMPLES:: |
| 911 | |
942 | 912 | sage: hash(MPComplexField()('1.2', 33)) == hash(complex(1.2, 33)) |
943 | 913 | True |
944 | 914 | """ |
… |
… |
|
946 | 916 | |
947 | 917 | def __getitem__(self, i): |
948 | 918 | r""" |
949 | | Returns either the real or imaginary component of self depending on |
950 | | the choice of i: real (i=0), imaginary (i=1) |
| 919 | Returns either the real or imaginary component of ``self`` |
| 920 | depending on the choice of i: real (i=0), imaginary (i=1). |
951 | 921 | |
952 | 922 | INPUTS: |
953 | 923 | |
… |
… |
|
959 | 929 | |
960 | 930 | EXAMPLES:: |
961 | 931 | |
962 | | sage: from sage.rings.complex_mpc import MPComplexField |
963 | 932 | sage: MPC = MPComplexField() |
964 | 933 | sage: a = MPC(2,1) |
965 | 934 | sage: a.__getitem__(0) |
… |
… |
|
987 | 956 | |
988 | 957 | EXAMPLES:: |
989 | 958 | |
990 | | sage: from sage.rings.complex_mpc import * |
991 | 959 | sage: i = MPComplexField(2000).0 |
992 | 960 | sage: i.prec() |
993 | 961 | 2000 |
… |
… |
|
996 | 964 | |
997 | 965 | def real(self): |
998 | 966 | """ |
999 | | Return the real part of self. |
| 967 | Return the real part of ``self``. |
1000 | 968 | |
1001 | 969 | EXAMPLES:: |
1002 | 970 | |
1003 | | sage: from sage.rings.complex_mpc import * |
1004 | 971 | sage: C = MPComplexField(100) |
1005 | 972 | sage: z = C(2, 3) |
1006 | 973 | sage: x = z.real(); x |
… |
… |
|
1015 | 982 | |
1016 | 983 | def imag(self): |
1017 | 984 | """ |
1018 | | Return imaginary part of self. |
| 985 | Return imaginary part of ``self``. |
1019 | 986 | |
1020 | 987 | EXAMPLES:: |
1021 | 988 | |
1022 | | sage: from sage.rings.complex_mpc import * |
1023 | 989 | sage: C = MPComplexField(100) |
1024 | 990 | sage: z = C(2, 3) |
1025 | 991 | sage: x = z.imag(); x |
… |
… |
|
1038 | 1004 | |
1039 | 1005 | EXAMPLES:: |
1040 | 1006 | |
1041 | | sage: from sage.rings.complex_mpc import * |
1042 | 1007 | sage: C = MPComplexField() |
1043 | 1008 | sage: a = C(1.2456, 987.654) |
1044 | 1009 | sage: a.parent() |
… |
… |
|
1056 | 1021 | |
1057 | 1022 | EXAMPLES:: |
1058 | 1023 | |
1059 | | sage: from sage.rings.complex_mpc import * |
1060 | 1024 | sage: MPC = MPComplexField(64) |
1061 | 1025 | sage: z = MPC(-4, 3)/7 |
1062 | 1026 | sage: z.str() |
… |
… |
|
1084 | 1048 | |
1085 | 1049 | def __copy__(self): |
1086 | 1050 | """ |
1087 | | Return copy of self -- since self is immutable, we just return self again. |
| 1051 | Return copy of ``self`` -- since ``self`` is immutable, we just |
| 1052 | return ``self`` again. |
1088 | 1053 | |
1089 | 1054 | EXAMPLES:: |
1090 | 1055 | |
1091 | | sage: from sage.rings.complex_mpc import * |
1092 | 1056 | sage: a = MPComplexField()(3.5, 3) |
1093 | 1057 | sage: copy(a) is a |
1094 | 1058 | True |
… |
… |
|
1104 | 1068 | |
1105 | 1069 | EXAMPLES:: |
1106 | 1070 | |
1107 | | sage: from sage.rings.complex_mpc import * |
1108 | 1071 | sage: MPC = MPComplexField() |
1109 | 1072 | sage: a = MPC(2,1) |
1110 | 1073 | sage: int(a) |
… |
… |
|
1127 | 1090 | |
1128 | 1091 | EXAMPLES:: |
1129 | 1092 | |
1130 | | sage: from sage.rings.complex_mpc import * |
1131 | 1093 | sage: MPC = MPComplexField() |
1132 | 1094 | sage: a = MPC(2,1) |
1133 | 1095 | sage: long(a) |
… |
… |
|
1149 | 1111 | |
1150 | 1112 | EXAMPLES:: |
1151 | 1113 | |
1152 | | sage: from sage.rings.complex_mpc import * |
1153 | 1114 | sage: MPC = MPComplexField() |
1154 | 1115 | sage: a = MPC(1, 0) |
1155 | 1116 | sage: float(a) |
… |
… |
|
1177 | 1138 | |
1178 | 1139 | EXAMPLES:: |
1179 | 1140 | |
1180 | | sage: from sage.rings.complex_mpc import * |
1181 | 1141 | sage: MPC = MPComplexField() |
1182 | 1142 | sage: a = MPC(2,1) |
1183 | 1143 | sage: complex(a) |
… |
… |
|
1196 | 1156 | r""" |
1197 | 1157 | EXAMPLES:: |
1198 | 1158 | |
1199 | | sage: from sage.rings.complex_mpc import * |
1200 | 1159 | sage: MPC = MPComplexField() |
1201 | 1160 | sage: a = MPC(2,1) |
1202 | 1161 | sage: b = MPC(1,2) |
… |
… |
|
1223 | 1182 | |
1224 | 1183 | def __nonzero__(self): |
1225 | 1184 | """ |
1226 | | Return True if self is not zero. This is an internal |
1227 | | function; use self.is_zero() instead. |
| 1185 | Return True if ``self`` is not zero. This is an internal |
| 1186 | function; use ``self.is_zero()`` instead. |
1228 | 1187 | |
1229 | 1188 | EXAMPLES:: |
1230 | 1189 | |
1231 | | sage: from sage.rings.complex_mpc import * |
1232 | 1190 | sage: MPC = MPComplexField() |
1233 | 1191 | sage: z = 1 + MPC(I) |
1234 | 1192 | sage: z.is_zero() |
… |
… |
|
1238 | 1196 | |
1239 | 1197 | def is_square(self): |
1240 | 1198 | """ |
1241 | | This function always returns true as $\C$ is algebraically closed. |
| 1199 | This function always returns true as `\CC` is algebraically closed. |
1242 | 1200 | |
1243 | 1201 | EXAMPLES:: |
1244 | 1202 | |
1245 | | sage: from sage.rings.complex_mpc import MPComplexField |
1246 | 1203 | sage: C200 = MPComplexField(200) |
1247 | 1204 | sage: a = C200(2,1) |
1248 | 1205 | sage: a.is_square() |
1249 | 1206 | True |
1250 | 1207 | |
1251 | | $\C$ is algebraically closed, hence every element is a square:: |
| 1208 | `\CC` is algebraically closed, hence every element is a square:: |
1252 | 1209 | |
1253 | 1210 | sage: b = C200(5) |
1254 | 1211 | sage: b.is_square() |
… |
… |
|
1258 | 1215 | |
1259 | 1216 | def is_real(self): |
1260 | 1217 | """ |
1261 | | Return True if self is real, i.e. has imaginary part zero. |
| 1218 | Return True if ``self`` is real, i.e. has imaginary part zero. |
1262 | 1219 | |
1263 | 1220 | EXAMPLES:: |
1264 | 1221 | |
1265 | | sage: from sage.rings.complex_mpc import MPComplexField |
1266 | 1222 | sage: C200 = MPComplexField(200) |
1267 | 1223 | sage: C200(1.23).is_real() |
1268 | 1224 | True |
… |
… |
|
1273 | 1229 | |
1274 | 1230 | def is_imaginary(self): |
1275 | 1231 | """ |
1276 | | Return True if self is imaginary, i.e. has real part zero. |
| 1232 | Return True if ``self`` is imaginary, i.e. has real part zero. |
1277 | 1233 | |
1278 | 1234 | EXAMPLES:: |
1279 | 1235 | |
1280 | | sage: from sage.rings.complex_mpc import MPComplexField |
1281 | 1236 | sage: C200 = MPComplexField(200) |
1282 | 1237 | sage: C200(1.23*i).is_imaginary() |
1283 | 1238 | True |
… |
… |
|
1301 | 1256 | |
1302 | 1257 | EXAMPLES:: |
1303 | 1258 | |
1304 | | sage: from sage.rings.complex_mpc import MPComplexField |
1305 | 1259 | sage: MPC = MPComplexField() |
1306 | 1260 | sage: z = (1/2)*(1 + sqrt(3.0) * MPC.0); z |
1307 | 1261 | 0.500000000000000 + 0.866025403784439*I |
… |
… |
|
1327 | 1281 | |
1328 | 1282 | EXAMPLES:: |
1329 | 1283 | |
1330 | | sage: from sage.rings.complex_mpc import MPComplexField |
1331 | 1284 | sage: MPC = MPComplexField(30) |
1332 | 1285 | sage: MPC(-1.5, 2) + MPC(0.2, 1) |
1333 | 1286 | -1.3000000 + 3.0000000*I |
… |
… |
|
1343 | 1296 | |
1344 | 1297 | EXAMPLES:: |
1345 | 1298 | |
1346 | | sage: from sage.rings.complex_mpc import MPComplexField |
1347 | 1299 | sage: MPC = MPComplexField(30) |
1348 | 1300 | sage: MPC(-1.5, 2) - MPC(0.2, 1) |
1349 | 1301 | -1.7000000 + 1.0000000*I |
… |
… |
|
1359 | 1311 | |
1360 | 1312 | EXAMPLES:: |
1361 | 1313 | |
1362 | | sage: from sage.rings.complex_mpc import MPComplexField |
1363 | 1314 | sage: MPC = MPComplexField(30) |
1364 | 1315 | sage: MPC(-1.5, 2) * MPC(0.2, 1) |
1365 | 1316 | -2.3000000 - 1.1000000*I |
… |
… |
|
1375 | 1326 | |
1376 | 1327 | EXAMPLES:: |
1377 | 1328 | |
1378 | | sage: from sage.rings.complex_mpc import MPComplexField |
1379 | 1329 | sage: MPC = MPComplexField(30) |
1380 | 1330 | sage: MPC(-1.5, 2) / MPC(0.2, 1) |
1381 | 1331 | 1.6346154 + 1.8269231*I |
… |
… |
|
1395 | 1345 | |
1396 | 1346 | EXAMPLES:: |
1397 | 1347 | |
1398 | | sage: from sage.rings.complex_mpc import MPComplexField |
1399 | 1348 | sage: MPC = MPComplexField(30) |
1400 | 1349 | sage: - MPC(-1.5, 2) |
1401 | 1350 | 1.5000000 - 2.0000000*I |
… |
… |
|
1413 | 1362 | |
1414 | 1363 | EXAMPLES:: |
1415 | 1364 | |
1416 | | sage: from sage.rings.complex_mpc import MPComplexField |
1417 | 1365 | sage: C = MPComplexField() |
1418 | 1366 | sage: a = ~C(5, 1) |
1419 | 1367 | sage: a * C(5, 1) |
… |
… |
|
1433 | 1381 | |
1434 | 1382 | EXAMPLES:: |
1435 | 1383 | |
1436 | | sage: from sage.rings.complex_mpc import MPComplexField |
1437 | 1384 | sage: MPC = MPComplexField() |
1438 | 1385 | sage: a = MPC(2,1) |
1439 | 1386 | sage: -a |
… |
… |
|
1448 | 1395 | |
1449 | 1396 | def __abs__(self): |
1450 | 1397 | r""" |
1451 | | Absolute value or modulus of this complex number. |
1452 | | |
1453 | | $|a + ib| = sqrt(a^2 + b^2)$ |
1454 | | |
1455 | | rounded with the rounding mode of the real part. |
| 1398 | Absolute value or modulus of this complex number, |
| 1399 | rounded with the rounding mode of the real part: |
| 1400 | |
| 1401 | .. MATH:: |
| 1402 | |
| 1403 | |a + ib| = \sqrt(a^2 + b^2). |
1456 | 1404 | |
1457 | 1405 | OUTPUT: |
1458 | 1406 | |
… |
… |
|
1464 | 1412 | Note that the absolute value of a complex number with imaginary |
1465 | 1413 | component equal to zero is the absolute value of the real component:: |
1466 | 1414 | |
1467 | | sage: from sage.rings.complex_mpc import * |
1468 | 1415 | sage: MPC = MPComplexField() |
1469 | 1416 | sage: a = MPC(2,1) |
1470 | 1417 | sage: abs(a) |
… |
… |
|
1489 | 1436 | |
1490 | 1437 | def norm(self): |
1491 | 1438 | r""" |
1492 | | Returns the norm of self. |
1493 | | |
1494 | | $norm(a + ib) = a^2 + b^2$ |
1495 | | |
1496 | | rounded with the rounding mode of the real part. |
| 1439 | Return the norm of a complex number, rounded with the rounding |
| 1440 | mode of the real part. The norm is the square of the absolute |
| 1441 | value: |
| 1442 | |
| 1443 | .. MATH:: |
| 1444 | |
| 1445 | \mathrm{norm}(a + ib) = a^2 + b^2. |
1497 | 1446 | |
1498 | 1447 | OUTPUT: |
1499 | 1448 | |
… |
… |
|
1505 | 1454 | This indeed acts as the square function when the imaginary |
1506 | 1455 | component of self is equal to zero:: |
1507 | 1456 | |
1508 | | sage: from sage.rings.complex_mpc import * |
1509 | 1457 | sage: MPC = MPComplexField() |
1510 | 1458 | sage: a = MPC(2,1) |
1511 | 1459 | sage: a.norm() |
… |
… |
|
1535 | 1483 | |
1536 | 1484 | EXAMPLES:: |
1537 | 1485 | |
1538 | | sage: from sage.rings.complex_mpc import MPComplexField |
1539 | 1486 | sage: MPC = MPComplexField() |
1540 | 1487 | sage: a = MPC(2, 2) |
1541 | 1488 | sage: a.__rdiv__(MPC(1)) |
… |
… |
|
1552 | 1499 | |
1553 | 1500 | EXAMPLES:: |
1554 | 1501 | |
1555 | | sage: from sage.rings.complex_mpc import MPComplexField |
1556 | 1502 | sage: MPC.<i> = MPComplexField(20) |
1557 | 1503 | sage: a = i^2; a |
1558 | 1504 | -1.0000 |
… |
… |
|
1591 | 1537 | ################################ |
1592 | 1538 | |
1593 | 1539 | def cos(self): |
1594 | | """ |
1595 | | Return the cosine of this complex number. |
1596 | | |
1597 | | $cos(a +ib) = cos a cosh b -i sin a sinh b$ |
| 1540 | r""" |
| 1541 | Return the cosine of this complex number: |
| 1542 | |
| 1543 | .. MATH:: |
| 1544 | |
| 1545 | \cos(a + ib) = \cos a \cosh b -i \sin a \sinh b. |
1598 | 1546 | |
1599 | 1547 | EXAMPLES:: |
1600 | 1548 | |
1601 | | sage: from sage.rings.complex_mpc import MPComplexField |
1602 | 1549 | sage: MPC = MPComplexField() |
1603 | 1550 | sage: u = MPC(2, 4) |
1604 | 1551 | sage: cos(u) |
… |
… |
|
1610 | 1557 | return z |
1611 | 1558 | |
1612 | 1559 | def sin(self): |
1613 | | """ |
1614 | | Return the sine of this complex number. |
1615 | | |
1616 | | $sin(a+ib) = sin a cosh b + i cos x sinh b$ |
| 1560 | r""" |
| 1561 | Return the sine of this complex number: |
| 1562 | |
| 1563 | .. MATH:: |
| 1564 | |
| 1565 | \sin(a + ib) = \sin a \cosh b + i \cos x \sinh b. |
1617 | 1566 | |
1618 | 1567 | EXAMPLES:: |
1619 | 1568 | |
1620 | | sage: from sage.rings.complex_mpc import MPComplexField |
1621 | 1569 | sage: MPC = MPComplexField() |
1622 | 1570 | sage: u = MPC(2, 4) |
1623 | 1571 | sage: sin(u) |
… |
… |
|
1629 | 1577 | return z |
1630 | 1578 | |
1631 | 1579 | def tan(self): |
1632 | | """ |
1633 | | Return the tangent of this complex number. |
1634 | | |
1635 | | $tan(a+ib) = (sin 2a +i sinh 2b)/(cos 2a + cosh 2b)$ |
| 1580 | r""" |
| 1581 | Return the tangent of this complex number: |
| 1582 | |
| 1583 | .. MATH:: |
| 1584 | |
| 1585 | \tan(a + ib) = (\sin 2a + i \sinh 2b)/(\cos 2a + \cosh 2b). |
1636 | 1586 | |
1637 | 1587 | EXAMPLES:: |
1638 | 1588 | |
1639 | | sage: from sage.rings.complex_mpc import MPComplexField |
1640 | 1589 | sage: MPC = MPComplexField() |
1641 | 1590 | sage: u = MPC(-2, 4) |
1642 | 1591 | sage: tan(u) |
… |
… |
|
1649 | 1598 | |
1650 | 1599 | def cosh(self): |
1651 | 1600 | """ |
1652 | | Return the hyperbolic cosine of this complex number. |
1653 | | |
1654 | | $cosh(a+ib) = cosh a cos b +i sinh a sin b$ |
| 1601 | Return the hyperbolic cosine of this complex number: |
| 1602 | |
| 1603 | .. MATH:: |
| 1604 | |
| 1605 | \cosh(a + ib) = \cosh a \cos b + i \sinh a \sin b. |
1655 | 1606 | |
1656 | 1607 | EXAMPLES:: |
1657 | 1608 | |
1658 | | sage: from sage.rings.complex_mpc import MPComplexField |
1659 | 1609 | sage: MPC = MPComplexField() |
1660 | 1610 | sage: u = MPC(2, 4) |
1661 | 1611 | sage: cosh(u) |
… |
… |
|
1668 | 1618 | |
1669 | 1619 | def sinh(self): |
1670 | 1620 | """ |
1671 | | Return the hyperbolic sine of this complex number. |
1672 | | |
1673 | | $sinh(a+ib) = sinh a cos b +i cosh a sin b$ |
| 1621 | Return the hyperbolic sine of this complex number: |
| 1622 | |
| 1623 | .. MATH:: |
| 1624 | |
| 1625 | \sinh(a + ib) = \sinh a \cos b + i \cosh a \sin b. |
1674 | 1626 | |
1675 | 1627 | EXAMPLES:: |
1676 | 1628 | |
1677 | | sage: from sage.rings.complex_mpc import MPComplexField |
1678 | 1629 | sage: MPC = MPComplexField() |
1679 | 1630 | sage: u = MPC(2, 4) |
1680 | 1631 | sage: sinh(u) |
… |
… |
|
1686 | 1637 | return z |
1687 | 1638 | |
1688 | 1639 | def tanh(self): |
1689 | | """ |
1690 | | Return the hyperbolic tangent of this complex number. |
1691 | | |
1692 | | $tanh(a+ib) = (sinh 2a +i sin 2b)/(cosh 2a + cos 2b)$ |
| 1640 | r""" |
| 1641 | Return the hyperbolic tangent of this complex number: |
| 1642 | |
| 1643 | .. MATH:: |
| 1644 | |
| 1645 | \tanh(a + ib) = (\sinh 2a + i \sin 2b)/(\cosh 2a + \cos 2b). |
1693 | 1646 | |
1694 | 1647 | EXAMPLES:: |
1695 | 1648 | |
1696 | | sage: from sage.rings.complex_mpc import MPComplexField |
1697 | 1649 | sage: MPC = MPComplexField() |
1698 | 1650 | sage: u = MPC(2, 4) |
1699 | 1651 | sage: tanh(u) |
… |
… |
|
1708 | 1660 | """ |
1709 | 1661 | EXAMPLES:: |
1710 | 1662 | |
1711 | | sage: from sage.rings.complex_mpc import MPComplexField |
1712 | 1663 | sage: MPC = MPComplexField() |
1713 | 1664 | sage: u = MPC(2, 4) |
1714 | 1665 | sage: arccos(u) |
… |
… |
|
1723 | 1674 | """ |
1724 | 1675 | EXAMPLES:: |
1725 | 1676 | |
1726 | | sage: from sage.rings.complex_mpc import MPComplexField |
1727 | 1677 | sage: MPC = MPComplexField() |
1728 | 1678 | sage: u = MPC(2, 4) |
1729 | 1679 | sage: arcsin(u) |
… |
… |
|
1738 | 1688 | """ |
1739 | 1689 | EXAMPLES:: |
1740 | 1690 | |
1741 | | sage: from sage.rings.complex_mpc import MPComplexField |
1742 | 1691 | sage: MPC = MPComplexField() |
1743 | 1692 | sage: u = MPC(-2, 4) |
1744 | 1693 | sage: arctan(u) |
… |
… |
|
1755 | 1704 | |
1756 | 1705 | EXAMPLES:: |
1757 | 1706 | |
1758 | | sage: from sage.rings.complex_mpc import MPComplexField |
1759 | 1707 | sage: MPC = MPComplexField() |
1760 | 1708 | sage: u = MPC(2, 4) |
1761 | 1709 | sage: arccosh(u) |
… |
… |
|
1772 | 1720 | |
1773 | 1721 | EXAMPLES:: |
1774 | 1722 | |
1775 | | sage: from sage.rings.complex_mpc import MPComplexField |
1776 | 1723 | sage: MPC = MPComplexField() |
1777 | 1724 | sage: u = MPC(2, 4) |
1778 | 1725 | sage: arcsinh(u) |
… |
… |
|
1789 | 1736 | |
1790 | 1737 | EXAMPLES:: |
1791 | 1738 | |
1792 | | sage: from sage.rings.complex_mpc import MPComplexField |
1793 | 1739 | sage: MPC = MPComplexField() |
1794 | 1740 | sage: u = MPC(2, 4) |
1795 | 1741 | sage: arctanh(u) |
… |
… |
|
1804 | 1750 | """ |
1805 | 1751 | EXAMPLES:: |
1806 | 1752 | |
1807 | | sage: from sage.rings.complex_mpc import MPComplexField |
1808 | 1753 | sage: MPC = MPComplexField(100) |
1809 | 1754 | sage: MPC(1,1).coth() |
1810 | 1755 | 0.86801414289592494863584920892 - 0.21762156185440268136513424361*I |
… |
… |
|
1815 | 1760 | """ |
1816 | 1761 | EXAMPLES:: |
1817 | 1762 | |
1818 | | sage: from sage.rings.complex_mpc import MPComplexField |
1819 | 1763 | sage: MPC = MPComplexField(100) |
1820 | 1764 | sage: MPC(1,1).arccoth() |
1821 | 1765 | 0.40235947810852509365018983331 - 0.55357435889704525150853273009*I |
… |
… |
|
1826 | 1770 | """ |
1827 | 1771 | EXAMPLES:: |
1828 | 1772 | |
1829 | | sage: from sage.rings.complex_mpc import MPComplexField |
1830 | 1773 | sage: MPC = MPComplexField(100) |
1831 | 1774 | sage: MPC(1,1).csc() |
1832 | 1775 | 0.62151801717042842123490780586 - 0.30393100162842645033448560451*I |
… |
… |
|
1837 | 1780 | """ |
1838 | 1781 | EXAMPLES:: |
1839 | 1782 | |
1840 | | sage: from sage.rings.complex_mpc import MPComplexField |
1841 | 1783 | sage: MPC = MPComplexField(100) |
1842 | 1784 | sage: MPC(1,1).csch() |
1843 | 1785 | 0.30393100162842645033448560451 - 0.62151801717042842123490780586*I |
… |
… |
|
1848 | 1790 | """ |
1849 | 1791 | EXAMPLES:: |
1850 | 1792 | |
1851 | | sage: from sage.rings.complex_mpc import MPComplexField |
1852 | 1793 | sage: MPC = MPComplexField(100) |
1853 | 1794 | sage: MPC(1,1).arccsch() |
1854 | 1795 | 0.53063753095251782601650945811 - 0.45227844715119068206365839783*I |
… |
… |
|
1859 | 1800 | """ |
1860 | 1801 | EXAMPLES:: |
1861 | 1802 | |
1862 | | sage: from sage.rings.complex_mpc import MPComplexField |
1863 | 1803 | sage: MPC = MPComplexField(100) |
1864 | 1804 | sage: MPC(1,1).sec() |
1865 | 1805 | 0.49833703055518678521380589177 + 0.59108384172104504805039169297*I |
… |
… |
|
1870 | 1810 | """ |
1871 | 1811 | EXAMPLES:: |
1872 | 1812 | |
1873 | | sage: from sage.rings.complex_mpc import MPComplexField |
1874 | 1813 | sage: MPC = MPComplexField(100) |
1875 | 1814 | sage: MPC(1,1).sech() |
1876 | 1815 | 0.49833703055518678521380589177 - 0.59108384172104504805039169297*I |
… |
… |
|
1881 | 1820 | """ |
1882 | 1821 | EXAMPLES:: |
1883 | 1822 | |
1884 | | sage: from sage.rings.complex_mpc import MPComplexField |
1885 | 1823 | sage: MPC = MPComplexField(100) |
1886 | 1824 | sage: MPC(1,1).arcsech() |
1887 | 1825 | 0.53063753095251782601650945811 - 1.1185178796437059371676632938*I |
… |
… |
|
1892 | 1830 | """ |
1893 | 1831 | EXAMPLES:: |
1894 | 1832 | |
1895 | | sage: from sage.rings.complex_mpc import MPComplexField |
1896 | 1833 | sage: MPC = MPComplexField(53) |
1897 | 1834 | sage: (1+MPC(I)).cotan() |
1898 | 1835 | 0.217621561854403 - 0.868014142895925*I |
… |
… |
|
1916 | 1853 | |
1917 | 1854 | EXAMPLES:: |
1918 | 1855 | |
1919 | | sage: from sage.rings.complex_mpc import * |
1920 | 1856 | sage: MPC = MPComplexField() |
1921 | 1857 | sage: i = MPC.0 |
1922 | 1858 | sage: (i^2).argument() |
… |
… |
|
1936 | 1872 | return x |
1937 | 1873 | |
1938 | 1874 | def conjugate(self): |
1939 | | """ |
1940 | | Return the complex conjugate of this complex number. |
1941 | | |
1942 | | $conjugate(a+ib) = a -ib$ |
| 1875 | r""" |
| 1876 | Return the complex conjugate of this complex number: |
| 1877 | |
| 1878 | .. MATH:: |
| 1879 | |
| 1880 | \mathrm{conjugate}(a + ib) = a - ib. |
1943 | 1881 | |
1944 | 1882 | EXAMPLES:: |
1945 | 1883 | |
1946 | | sage: from sage.rings.complex_mpc import * |
1947 | 1884 | sage: MPC = MPComplexField() |
1948 | 1885 | sage: i = MPC(0, 1) |
1949 | 1886 | sage: (1+i).conjugate() |
… |
… |
|
1956 | 1893 | |
1957 | 1894 | def sqr(self): |
1958 | 1895 | """ |
1959 | | Return the square. |
1960 | | |
1961 | | $sqr(a+ib) = a^2-b^2 +i 2ab$ |
| 1896 | Return the square of a complex number: |
| 1897 | |
| 1898 | .. MATH:: |
| 1899 | |
| 1900 | (a + ib)^2 = (a^2 - b^2) + 2iab. |
1962 | 1901 | |
1963 | 1902 | EXAMPLES:: |
1964 | 1903 | |
1965 | | sage: from sage.rings.complex_mpc import MPComplexField |
1966 | 1904 | sage: C = MPComplexField() |
1967 | 1905 | sage: a = C(5, 1) |
1968 | 1906 | sage: a.sqr() |
… |
… |
|
1974 | 1912 | return z |
1975 | 1913 | |
1976 | 1914 | def sqrt(self): |
1977 | | """ |
1978 | | Return the square root, taking the branch cut to be the negative real axis. |
1979 | | |
1980 | | $sqrt(a+ib) = sqrt(abs(a+ib))(cos(arg(a+ib)/2) + sin(arg(a+ib)/2))$ |
| 1915 | r""" |
| 1916 | Return the square root, taking the branch cut to be the negative real axis: |
| 1917 | |
| 1918 | .. MATH:: |
| 1919 | |
| 1920 | \sqrt z = \sqrt{|z|}(\cos(\arg(z)/2) + i \sin(\arg(z)/2)). |
1981 | 1921 | |
1982 | 1922 | EXAMPLES:: |
1983 | 1923 | |
1984 | | sage: from sage.rings.complex_mpc import MPComplexField |
1985 | 1924 | sage: C = MPComplexField() |
1986 | 1925 | sage: a = C(24, 10) |
1987 | 1926 | sage: a.sqrt() |
… |
… |
|
1994 | 1933 | |
1995 | 1934 | def exp(self): |
1996 | 1935 | """ |
1997 | | Return the exponential of this complex number. |
1998 | | |
1999 | | $exp(a+ib) = exp(a) (cos b +i sin b)$ |
| 1936 | Return the exponential of this complex number: |
| 1937 | |
| 1938 | .. MATH:: |
| 1939 | |
| 1940 | \exp(a + ib) = \exp(a) (\cos b + i \sin b). |
2000 | 1941 | |
2001 | 1942 | EXAMPLES:: |
2002 | 1943 | |
2003 | | sage: from sage.rings.complex_mpc import MPComplexField |
2004 | 1944 | sage: MPC = MPComplexField() |
2005 | 1945 | sage: u = MPC(2, 4) |
2006 | 1946 | sage: exp(u) |
… |
… |
|
2012 | 1952 | return z |
2013 | 1953 | |
2014 | 1954 | def log(self): |
2015 | | """ |
| 1955 | r""" |
2016 | 1956 | Return the logarithm of this complex number with the branch |
2017 | | cut on the negative real axis. |
2018 | | |
2019 | | $log(a+ib) = log(a^2+b^2)/2 + arg(a+ib)$ |
| 1957 | cut on the negative real axis: |
| 1958 | |
| 1959 | .. MATH:: |
| 1960 | |
| 1961 | \log(z) = \log |z| + i \arg(z). |
2020 | 1962 | |
2021 | 1963 | EXAMPLES:: |
2022 | 1964 | |
2023 | | sage: from sage.rings.complex_mpc import MPComplexField |
2024 | 1965 | sage: MPC = MPComplexField() |
2025 | 1966 | sage: u = MPC(2, 4) |
2026 | 1967 | sage: log(u) |
… |
… |
|
2037 | 1978 | |
2038 | 1979 | EXAMPLES:: |
2039 | 1980 | |
2040 | | sage: from sage.rings.complex_mpc import MPComplexField |
2041 | 1981 | sage: MPC = MPComplexField() |
2042 | 1982 | sage: u = MPC(2, 4) |
2043 | 1983 | sage: u<<2 |
… |
… |
|
2048 | 1988 | cdef MPComplexNumber z, x |
2049 | 1989 | x = <MPComplexNumber>self |
2050 | 1990 | z = x._new() |
2051 | | if n>=0: |
2052 | | mpc_mul_2exp(z.value , x.value, n, (<MPComplexField_class>x._parent).__rnd) |
2053 | | else: |
2054 | | mpc_div_2exp(z.value , x.value, -n, (<MPComplexField_class>x._parent).__rnd) |
| 1991 | mpc_mul_2si(z.value , x.value, n, (<MPComplexField_class>x._parent).__rnd) |
2055 | 1992 | return z |
2056 | 1993 | |
2057 | 1994 | def __rshift__(self, n): |
… |
… |
|
2060 | 1997 | |
2061 | 1998 | EXAMPLES:: |
2062 | 1999 | |
2063 | | sage: from sage.rings.complex_mpc import MPComplexField |
2064 | 2000 | sage: MPC = MPComplexField() |
2065 | 2001 | sage: u = MPC(2, 4) |
2066 | 2002 | sage: u>>2 |
… |
… |
|
2071 | 2007 | cdef MPComplexNumber z, x |
2072 | 2008 | x = <MPComplexNumber>self |
2073 | 2009 | z = x._new() |
2074 | | if n>=0: |
2075 | | mpc_div_2exp(z.value , x.value, n, (<MPComplexField_class>x._parent).__rnd) |
2076 | | else: |
2077 | | mpc_mul_2exp(z.value , x.value, -n, (<MPComplexField_class>x._parent).__rnd) |
| 2010 | mpc_div_2si(z.value , x.value, n, (<MPComplexField_class>x._parent).__rnd) |
2078 | 2011 | return z |
2079 | 2012 | |
2080 | 2013 | def nth_root(self, n, all=False): |
… |
… |
|
2088 | 2021 | |
2089 | 2022 | EXAMPLES:: |
2090 | 2023 | |
2091 | | sage: from sage.rings.complex_mpc import MPComplexField |
2092 | 2024 | sage: MPC = MPComplexField() |
2093 | 2025 | sage: a = MPC(27) |
2094 | 2026 | sage: a.nth_root(3) |
… |
… |
|
2133 | 2065 | |
2134 | 2066 | def dilog(self): |
2135 | 2067 | r""" |
2136 | | Returns the complex dilogarithm of self. The complex dilogarithm, |
| 2068 | Return the complex dilogarithm of ``self``. The complex dilogarithm, |
2137 | 2069 | or Spence's function, is defined by |
2138 | 2070 | |
2139 | | `Li_2(z) = - \int_0^z \frac{\log|1-\zeta|}{\zeta} d(\zeta)` |
2140 | | |
2141 | | `= \sum_{k=1}^\infty \frac{z^k}{k}` |
| 2071 | .. MATH:: |
| 2072 | |
| 2073 | Li_2(z) = - \int_0^z \frac{\log|1-\zeta|}{\zeta} d(\zeta) |
| 2074 | = \sum_{k=1}^\infty \frac{z^k}{k^2}. |
2142 | 2075 | |
2143 | 2076 | Note that the series definition can only be used for |
2144 | | `|z| < 1` |
| 2077 | `|z| < 1`. |
2145 | 2078 | |
2146 | 2079 | EXAMPLES:: |
2147 | 2080 | |
2148 | | sage: from sage.rings.complex_mpc import MPComplexField |
2149 | 2081 | sage: MPC = MPComplexField() |
2150 | 2082 | sage: a = MPC(1,0) |
2151 | 2083 | sage: a.dilog() |
… |
… |
|
2169 | 2101 | |
2170 | 2102 | def eta(self, omit_frac=False): |
2171 | 2103 | r""" |
2172 | | Return the value of the Dedekind `\eta` function on self, |
| 2104 | Return the value of the Dedekind `\eta` function on ``self``, |
2173 | 2105 | intelligently computed using `\mathbb{SL}(2,\ZZ)` |
2174 | 2106 | transformations. |
2175 | 2107 | |
… |
… |
|
2193 | 2125 | |
2194 | 2126 | ALGORITHM: Uses the PARI C library. |
2195 | 2127 | |
2196 | | EXAMPLES: |
2197 | | |
2198 | | sage: from sage.rings.complex_mpc import MPComplexField |
| 2128 | EXAMPLES:: |
| 2129 | |
2199 | 2130 | sage: MPC = MPComplexField() |
2200 | 2131 | sage: i = MPC.0 |
2201 | 2132 | sage: z = 1+i; z.eta() |
… |
… |
|
2212 | 2143 | |
2213 | 2144 | EXAMPLES:: |
2214 | 2145 | |
2215 | | sage: from sage.rings.complex_mpc import MPComplexField |
2216 | 2146 | sage: MPC = MPComplexField(30) |
2217 | 2147 | sage: i = MPC.0 |
2218 | 2148 | sage: (1+i).gamma() |
… |
… |
|
2241 | 2171 | |
2242 | 2172 | EXAMPLES:: |
2243 | 2173 | |
2244 | | sage: from sage.rings.complex_mpc import MPComplexField |
2245 | 2174 | sage: C, i = MPComplexField(30).objgen() |
2246 | 2175 | sage: (1+i).gamma_inc(2 + 3*i) |
2247 | 2176 | 0.0020969149 - 0.059981914*I |
… |
… |
|
2259 | 2188 | |
2260 | 2189 | EXAMPLES:: |
2261 | 2190 | |
2262 | | sage: from sage.rings.complex_mpc import MPComplexField |
2263 | 2191 | sage: i = MPComplexField(30).gen() |
2264 | 2192 | sage: z = 1 + i |
2265 | 2193 | sage: z.zeta() |
… |
… |
|
2269 | 2197 | |
2270 | 2198 | def agm(self, right, algorithm="optimal"): |
2271 | 2199 | """ |
2272 | | Returns the algebraic geometrc mean of self and right. |
| 2200 | Returns the algebraic geometrc mean of ``self`` and ``right``. |
2273 | 2201 | |
2274 | 2202 | EXAMPLES:: |
2275 | 2203 | |
2276 | | sage: from sage.rings.complex_mpc import MPComplexField |
2277 | 2204 | sage: MPC = MPComplexField() |
2278 | 2205 | sage: u = MPC(1, 4) |
2279 | 2206 | sage: v = MPC(-2,5) |
… |
… |
|
2338 | 2265 | mpc_sqrt(b.value, d.value, rnd) |
2339 | 2266 | |
2340 | 2267 | # a = s/2 |
2341 | | mpc_div_2exp(a.value, s.value, 1, rnd) |
| 2268 | mpc_div_2ui(a.value, s.value, 1, rnd) |
2342 | 2269 | |
2343 | 2270 | # d = a - b |
2344 | 2271 | mpc_sub(d.value, a.value, b.value, rnd) |
diff --git a/sage/rings/mpc.pxi b/sage/rings/mpc.pxi
a
|
b
|
|
99 | 99 | int mpc_fr_div (mpc_t, mpfr_t, mpc_t, mpc_rnd_t) |
100 | 100 | int mpc_div_ui (mpc_t, mpc_t, unsigned long int, mpc_rnd_t) |
101 | 101 | int mpc_ui_div (mpc_t, unsigned long int, mpc_t, mpc_rnd_t) |
102 | | int mpc_div_2exp (mpc_t, mpc_t, unsigned long int, mpc_rnd_t) |
103 | | int mpc_mul_2exp (mpc_t, mpc_t, unsigned long int, mpc_rnd_t) |
| 102 | int mpc_div_2ui (mpc_t, mpc_t, unsigned long int, mpc_rnd_t) |
| 103 | int mpc_div_2si (mpc_t, mpc_t, long int, mpc_rnd_t) |
| 104 | int mpc_mul_2ui (mpc_t, mpc_t, unsigned long int, mpc_rnd_t) |
| 105 | int mpc_mul_2si (mpc_t, mpc_t, long int, mpc_rnd_t) |
104 | 106 | # |
105 | 107 | int mpc_abs (mpfr_t, mpc_t, mp_rnd_t) |
106 | 108 | int mpc_norm (mpfr_t, mpc_t, mp_rnd_t) |
107 | 109 | |
108 | | int mpc_mul_2exp (mpc_t rop, mpc_t op1, unsigned long int op2, mpc_rnd_t rnd) |
109 | | int mpc_div_2exp (mpc_t rop, mpc_t op1, unsigned long int op2, mpc_rnd_t rnd) |
110 | 110 | |
111 | 111 | # Power functions and logarithm |
112 | 112 | int mpc_sqrt (mpc_t, mpc_t, mpc_rnd_t) |