Ticket #1275: qqbar-sqrt-golden.patch
| File qqbar-sqrt-golden.patch, 4.5 kB (added by robertwb, 1 year ago) |
|---|
-
a/sage/functions/constants.py
old new 694 694 return R('1.61803398874989484820458683436563811772030917980576286213544862') 695 695 696 696 def _mpfr_(self,R): #is this OK for _mpfr_ ? 697 return (R(1)+R(5).sqrt())*R(0.5)697 return (R(1)+R(5).sqrt())*R(0.5) 698 698 699 699 def _algebraic_(self, field): 700 import sage.rings.qqbar 701 return field(sage.rings.qqbar.get_AA_golden_ratio()) 700 return field( (1+field(5).sqrt()) / 2) 702 701 703 702 golden_ratio = GoldenRatio() 704 703 -
a/sage/rings/complex_interval.pyx
old new 599 599 [0.00000000000000000 .. 0.00000000000000000] 600 600 sage: CIF(-2).argument() 601 601 [3.1415926535897931 .. 3.1415926535897936] 602 sage: CIF(2).argument().is_exact() 603 True 602 604 """ 603 605 if mpfi_has_zero(self.__re) and mpfi_has_zero(self.__im): 604 606 … … 647 649 648 650 fld = self.parent()._real_field() 649 651 652 if mpfr_zero_p(&self.__im.left) and mpfr_zero_p(&self.__im.right): 653 if mpfi_is_strictly_pos(self.__re): 654 return fld(0) 655 else: 656 return fld.pi() 650 657 if mpfi_is_strictly_pos(self.__im): 651 658 return (-self.real() / self.imag()).atan() + fld.pi()/2 652 659 if mpfi_is_strictly_neg(self.__im): … … 738 745 theta = self.argument() 739 746 rho = abs(self) 740 747 return ComplexIntervalFieldElement(self._parent, rho.log(), theta) 748 749 def sqrt(self, bint all=False, **kwds): 750 """ 751 The square root function. 752 753 Branch cut along negative real axis, with sqrt(-r^2) = i*r for real r. 754 755 INPUT: 756 all -- bool (default: False); if True, return a list 757 of all square roots. 758 759 EXAMPLES: 760 sage: a = CIF(-1).sqrt()^2; a 761 [-1.0000000000000003 .. -0.99999999999999966] + [-0.00000000000000032162452993532733 .. 0.00000000000000012246467991473533]*I 762 sage: sqrt(CIF(2)) 763 [1.4142135623730949 .. 1.4142135623730952] 764 sage: sqrt(CIF(-1)) 765 [-0.00000000000000016081226496766367 .. 0.000000000000000061232339957367661] + [0.99999999999999988 .. 1.0000000000000000]*I 766 sage: sqrt(CIF(2-I))^2 767 [1.9999999999999980 .. 2.0000000000000014] - [0.99999999999999877 .. 1.0000000000000012]*I 768 sage: CC(-2-I).sqrt()^2 769 -2.00000000000000 - 1.00000000000000*I 770 """ 771 if self.is_zero(): 772 return [self] if all else self 773 theta = self.argument()/2 774 rho = abs(self).sqrt() 775 x = ComplexIntervalFieldElement(self._parent, rho*theta.cos(), rho*theta.sin()) 776 if all: 777 return [x, -x] 778 else: 779 return x 780 741 781 742 782 def is_square(self): 743 783 """ -
a/sage/rings/qqbar.py
old new 4031 4031 4032 4032 QQbar_hash_offset = AlgebraicNumber(ANExtensionElement(QQbar_I_generator, ~ZZ(123456789) + QQbar_I_nf.gen()/ZZ(987654321))) 4033 4033 4034 ZZX_x = ZZ['x'].gen()4035 4036 # This is used in the _algebraic_ method of the golden_ratio constant,4037 # in sage/functions/constants.py4038 AA_golden_ratio = None4039 4040 def get_AA_golden_ratio():4041 global AA_golden_ratio4042 if AA_golden_ratio is None:4043 AA_golden_ratio_nf = NumberField(ZZX_x**2 - ZZX_x - 1, 'phi')4044 AA_golden_ratio_generator = AlgebraicGenerator(AA_golden_ratio_nf, ANRoot(AAPoly.gen()**2 - AAPoly.gen() - 1, RIF(1.618, 1.6181)))4045 AA_golden_ratio = AlgebraicReal(ANExtensionElement(AA_golden_ratio_generator, AA_golden_ratio_nf.gen()))4046 return AA_golden_ratio