# HG changeset patch
# User Nick Alexander <ncalexander@gmail.com>
# Date 1241908163 25200
# Branch symbolics_switch
# Node ID 93c1432d3662d8f2a3c7d3da42718377c059a908
# Parent  17d2af26a526c01729c9d26da41d90a4f8c079a6
[mq]: partial-functions.patch

diff -r 17d2af26a526 -r 93c1432d3662 sage/functions/hyperbolic.py
--- a/sage/functions/hyperbolic.py	Sat May 09 14:02:44 2009 -0700
+++ b/sage/functions/hyperbolic.py	Sat May 09 15:29:23 2009 -0700
@@ -32,7 +32,8 @@
             11.5487393572577
         """
         PrimitiveFunction.__init__(self, "sinh", latex=r"\sinh",
-                                   approx=math.sinh)
+                                   # approx=math.sinh
+                                   )
 
 sinh = Function_sinh()
 
@@ -53,7 +54,8 @@
             1.12762596520638
         """
         PrimitiveFunction.__init__(self, "cosh", latex=r"\cosh",
-                                   approx=math.cosh)
+                                   # approx=math.cosh
+                                   )
 
 cosh = Function_cosh()
         
@@ -88,7 +90,8 @@
             0.997524731976 - 0.002790687681*I        
         """
         PrimitiveFunction.__init__(self, "tanh", latex=r"\tanh",
-                                   approx=math.tanh)
+                                   # approx=math.tanh
+                                   )
 
 tanh = Function_tanh()
 
@@ -109,7 +112,8 @@
             1.00374187319732
         """
         PrimitiveFunction.__init__(self, "coth", latex=r"\coth",
-                                   approx=lambda x: 1/math.tanh(x))
+                                   # approx=lambda x: 1/math.tanh(x)
+                                   )
 
 coth = Function_coth()
 
@@ -130,7 +134,8 @@
             0.0862667383340544
         """
         PrimitiveFunction.__init__(self, "sech", latex=r"\sech",
-                                   approx=lambda x: 1/math.cosh(x))
+                                   # approx=lambda x: 1/math.cosh(x)
+                                   )
 
 sech = Function_sech()
 
@@ -152,7 +157,8 @@
             0.0865895375300470
         """
         PrimitiveFunction.__init__(self, "csch", latex=r"\text{csch}",
-                                   approx=lambda x: 1/math.sinh(x))
+                                   # approx=lambda x: 1/math.sinh(x)
+                                   )
 
 csch = Function_csch()
 
@@ -177,11 +183,11 @@
             sage: arcsinh(1 + I*1.0)
             1.06127506190504 + 0.666239432492515*I
             sage: arcsinh._approx_(0.5)
-            0.48121182505960347
+            0.481211825059603
 
         """
         PrimitiveFunction.__init__(self, "arcsinh", latex=r"\sinh^{-1}",
-                                   approx=lambda x: float(pari(float(x)).asinh()),
+                                   # approx=lambda x: float(pari(float(x)).asinh()),
                                    conversions=dict(maxima='asinh'))
         
 arcsinh = asinh = Function_arcsinh()
@@ -199,8 +205,10 @@
             1.06127506190504 + 0.904556894302381*I
             sage: float(arccosh(2))
             1.3169578969248168
-            sage: cosh(float(arccosh(2)))
-            2.0
+            sage: t = cosh(float(arccosh(2))); t
+            2.00000000000000
+            sage: parent(t)
+            Real Field with 53 bits of precision
 
         Warning: If the input is real the output will be real or NaN::
 
@@ -215,7 +223,7 @@
         
         """
         PrimitiveFunction.__init__(self, "arccosh", latex=r"\cosh^{-1}",
-                                   approx=lambda x: float(pari(float(x)).acosh()),
+                                   # approx=lambda x: float(pari(float(x)).acosh()),
                                    conversions=dict(maxima='acosh'))
 
 arccosh = acosh = Function_arccosh()
@@ -231,12 +239,14 @@
             0.549306144334055
             sage: arctanh(1/2)
             arctanh(1/2)
+            sage: arctanh(1/2).n(53)
+            0.549306144334055
             sage: arctanh(1 + I*1.0)
             0.402359478108525 + 1.01722196789785*I
 
         """
         PrimitiveFunction.__init__(self, "arctanh", latex=r"\tanh^{-1}",
-                                   approx=lambda x: float(pari(float(x)).atanh()),
+                                   # approx=lambda x: float(pari(float(x)).atanh()),
                                    conversions=dict(maxima='atanh'))
 
 arctanh = atanh = Function_arctanh()
@@ -256,7 +266,7 @@
             0.402359478108525 - 0.553574358897045*I
         """
         PrimitiveFunction.__init__(self, "arccoth", latex=r"\coth^{-1}",
-                                   approx=lambda x: float(pari(float(1/x)).atanh()),
+                                   # approx=lambda x: float(pari(float(1/x)).atanh()),
                                    conversions=dict(maxima='acoth'))
 
     def evalf(self, x, prec=0):
@@ -285,7 +295,7 @@
             -0.530637530952518 + 1.11851787964371*I
         """
         PrimitiveFunction.__init__(self, "arcsech", latex=r"\text{sech}^{-1}",
-                                   approx=lambda x: float(pari(float(1/x)).acosh()),
+                                   # approx=lambda x: float(pari(float(1/x)).acosh()),
                                    conversions=dict(maxima='asech'))
 
     def evalf(self, x, prec=0):
@@ -314,7 +324,7 @@
             0.530637530952518 - 0.452278447151191*I
         """
         PrimitiveFunction.__init__(self, "arccsch", latex=r"\text{csch}^{-1}",
-                                   approx=lambda x: float(pari(float(1/x)).arcsinh()),
+                                   # approx=lambda x: float(pari(float(1/x)).arcsinh()),
                                    conversions=dict(maxima='acsch'))
 
     def evalf(self, x, prec=0):
diff -r 17d2af26a526 -r 93c1432d3662 sage/functions/log.py
--- a/sage/functions/log.py	Sat May 09 14:02:44 2009 -0700
+++ b/sage/functions/log.py	Sat May 09 15:29:23 2009 -0700
@@ -32,7 +32,7 @@
             0.999896315728952
         """
         PrimitiveFunction.__init__(self, 'log', latex=r'\log',
-                                   approx=math.log)
+                                   ) # approx=math.log)
 
 function_log = Function_log()
 
@@ -252,6 +252,7 @@
         pi^2/6
         sage: polylog(2,x^2+1)
         polylog(2, x^2 + 1)
+        sage: polylog(4, 1/2)
         sage: polylog(4,0.5)
         polylog(4, 0.5)
         sage: float(polylog(4,0.5))
diff -r 17d2af26a526 -r 93c1432d3662 sage/functions/other.py
--- a/sage/functions/other.py	Sat May 09 14:02:44 2009 -0700
+++ b/sage/functions/other.py	Sat May 09 15:29:23 2009 -0700
@@ -20,7 +20,7 @@
         PARI) when the input is real.
         """
         PrimitiveFunction.__init__(self, "erf", latex=r"\text{erf}",
-                                   approx=lambda x: float(1 - pari(float(x)).erfc()))
+                                   ) # approx=lambda x: float(1 - pari(float(x)).erfc()))
 
 erf = Function_erf()
 
@@ -45,7 +45,7 @@
             sqrt(x)
         """
         PrimitiveFunction.__init__(self, "abs", latex=r"\mathrm{abs}",
-                                   approx=lambda x: float(x.__abs__()))
+                                   ) # approx=lambda x: float(x.__abs__()))
 
     def _latex_composition(self, x):
         """
@@ -137,7 +137,7 @@
     """
     def __init__(self):
         PrimitiveFunction.__init__(self, "ceil", latex=r"\text{ceil}",
-                                   approx=math.ceil,
+                                   # approx=math.ceil,
                                    conversions=dict(maxima='ceiling'))
                                    
     def _latex_composition(self, x):
@@ -245,7 +245,7 @@
             99999999999999999999999999999999999999999999999999
         """
         PrimitiveFunction.__init__(self, "floor", latex=r"\text{floor}",
-                                   approx=math.floor)
+                                   ) # approx=math.floor)
         
     def _latex_composition(self, x):
         r"""
@@ -323,8 +323,7 @@
             sage: gamma(I)
             gamma(I)
             sage: gamma(x/2)(x=5)
-            3*sqrt(pi)/4
-            sage. plot(gamma(x),(x,1,5))
+            3/4*sqrt(pi)
 
         TESTS: We verify that we can convert this function to Maxima and
         convert back to Sage.
@@ -441,7 +440,7 @@
             7.173269190187...
         """
         PrimitiveFunction.__init__(self, "factorial", latex="!",
-                                   approx=lambda x: gamma(x+1))
+                                   ) # approx=lambda x: gamma(x+1))
         
 
     def _latex_composition(self, n):
@@ -511,7 +510,7 @@
             12.1824939607
         """
         PrimitiveFunction.__init__(self, "exp", latex=r"\exp",
-                                   approx=math.exp)
+                                   ) # approx=math.exp)
     
     def __call__(self, x, prec=None):
         """
@@ -558,7 +557,7 @@
             sqrt(x^2)
         """
         PrimitiveFunction.__init__(self, "sqrt", latex=r"\sqrt",
-                                   approx=math.sqrt)
+                                   ) # approx=math.sqrt)
 
     def evalf(self, x, prec=0):
         """
diff -r 17d2af26a526 -r 93c1432d3662 sage/functions/transcendental.py
--- a/sage/functions/transcendental.py	Sat May 09 14:02:44 2009 -0700
+++ b/sage/functions/transcendental.py	Sat May 09 15:29:23 2009 -0700
@@ -407,7 +407,7 @@
       Mathematics of Computation, Vol. 53, No. 187 (1989).
     """
     def __init__(self):
-      PrimitiveFunction.__init__(self, "dickman_rho", approx=self.approximate)
+      PrimitiveFunction.__init__(self, "dickman_rho") # approx=self.approximate)
       self._cur_prec = 0
     
     def __call__(self, x):
diff -r 17d2af26a526 -r 93c1432d3662 sage/functions/trig.py
--- a/sage/functions/trig.py	Sat May 09 14:02:44 2009 -0700
+++ b/sage/functions/trig.py	Sat May 09 15:29:23 2009 -0700
@@ -11,7 +11,7 @@
         """
         PrimitiveFunction.__init__(self, "sin", latex=r"\sin",
                                    conversions=dict(mathematica='Sin'),
-                                   approx=math.sin)
+                                   ) # approx=math.sin)
 sin = Function_sin()
 
 class Function_cos(PrimitiveFunction):
@@ -21,7 +21,7 @@
         """
         PrimitiveFunction.__init__(self, "cos", latex=r"\cos",
                                    conversions=dict(mathematica='Cos'),
-                                   approx=math.cos,)
+                                   ) # approx=math.cos,)
 
 cos = Function_cos()
 
@@ -46,7 +46,7 @@
             0.546302489843790
         """
         PrimitiveFunction.__init__(self, "tan", latex=r"\tan",
-                                   approx=math.tan)
+                                   ) # approx=math.tan)
 tan = Function_tan()
 
 class Function_sec(PrimitiveFunction):
@@ -68,7 +68,7 @@
             1.13949392732455
         """
         PrimitiveFunction.__init__(self, "sec", latex=r"\sec",
-                                   approx=lambda x: 1/math.cos(x))
+                                   ) # approx=lambda x: 1/math.cos(x))
 
     def evalf(self, x, prec=0):
         """
@@ -100,7 +100,7 @@
             2.08582964293349        
         """
         PrimitiveFunction.__init__(self, "csc", latex=r"\csc",
-                                   approx=lambda x: 1/math.sin(x))
+                                   ) # approx=lambda x: 1/math.sin(x))
 
     def evalf(self, x, prec=0):
         """
@@ -130,7 +130,7 @@
             1.83048772171245        
         """
         PrimitiveFunction.__init__(self, "cot", latex=r"\cot",
-                                   approx=lambda x: 1/math.tan(x))
+                                   ) # approx=lambda x: 1/math.tan(x))
 
     def evalf(self, x, prec=0):
         """
@@ -163,7 +163,7 @@
             1.06127506190504 + 0.666239432492515*I
         """
         PrimitiveFunction.__init__(self, 'arcsin', latex=r"\sin^{-1}",
-                                   approx=math.asin,
+                                   # approx=math.asin,
                                    conversions=dict(maxima='asin'))
 arcsin = asin = Function_arcsin()
 
@@ -182,7 +182,7 @@
             0.904556894302381 - 1.06127506190504*I
         """
         PrimitiveFunction.__init__(self, 'arccos', latex=r"\cos^{-1}",
-                                   approx=math.acos,
+                                   # approx=math.acos,
                                    conversions=dict(maxima='acos'))
 
     def evalf(self, x, prec=0):
@@ -211,7 +211,7 @@
             arctan(I + 1)
         """
         PrimitiveFunction.__init__(self, "arctan", latex=r'\tan^{-1}',
-                                   approx=math.atan,
+                                   # approx=math.atan,
                                    conversions=dict(maxima='atan'))
 
     def evalf(self, x, prec=0):
@@ -240,7 +240,7 @@
             arccot(I + 1)
         """
         PrimitiveFunction.__init__(self, "arccot", latex=r'\cot^{-1}',
-                                   approx=lambda x: math.pi/2 - math.atan(x),
+                                   # approx=lambda x: math.pi/2 - math.atan(x),
                                    conversions=dict(maxima='acot'))
 
     def evalf(self, x, prec=0):
@@ -270,7 +270,7 @@
             arccsc(I + 1)
         """        
         PrimitiveFunction.__init__(self, "arccsc", latex=r'\csc^{-1}',
-                                   approx=lambda x: math.asin(1/x),
+                                   # approx=lambda x: math.asin(1/x),
                                    conversions=dict(maxima='acsc'))
 
     def evalf(self, x, prec=0):
@@ -299,7 +299,7 @@
             arcsec(I + 1)
         """        
         PrimitiveFunction.__init__(self, "arcsec", latex=r'\sec^{-1}',
-                                   approx=lambda x: math.acos(1/x),
+                                   # approx=lambda x: math.acos(1/x),
                                    conversions=dict(maxima='asec'))
 
     def evalf(self, x, prec=0):
diff -r 17d2af26a526 -r 93c1432d3662 sage/symbolic/function.pyx
--- a/sage/symbolic/function.pyx	Sat May 09 14:02:44 2009 -0700
+++ b/sage/symbolic/function.pyx	Sat May 09 15:29:23 2009 -0700
@@ -813,7 +813,7 @@
         else:
             return self.name()
 
-    def _generic_approx_(self, x):
+    def _generic_approx_(self, x, prec=53):
         """
         Returns the results of numerically evaluating this function at
         *x*.  This is a default implementation which tries to do the
@@ -824,18 +824,22 @@
             sage: from sage.symbolic.function import PrimitiveFunction
             sage: s = PrimitiveFunction('sin'); s
             sin
-            sage: s._generic_approx_(0)
+            sage: s._generic_approx_(0, 53)
             0.0
         """
-        from sage.rings.all import RR
+        from sage.rings.all import RealField
+#         try:
+            # convert argument to appropriate field, evaluate self,
+            # and ensure output parent is correct
+        R = RealField(prec)
+        return R(self(R(x)))
+#         except TypeError:
+#             print "XXX"
+#             pass
+        
         from sage.calculus.calculus import maxima
-        try:
-            return float(self(RR(x)))         
-        except TypeError:
-            pass
-        
         s = '%s(%s), numer'%(self._maxima_init_(), float(x))
-        return float(maxima.eval(s))
+        return float(maxima.eval(s)) # XXX precision in maxima?
 
     def _complex_approx_(self, x): # must be called with Python complex float as iput
         """
