Relates to http://trac.sagemath.org/sage_trac/ticket/8983 erf0.patch

# return 0.0 for different fields 
sage: erf(0)
0.0
sage: erf(0.0)
0.0
sage: erf(CC(0))
0.0
sage: erf(x)
erf(x)
sage: x=0; erf(x)
0.0

# The following are equivalent to those above?
sage: erf(CC(0.0))
0.0
sage: erf(RR(0.0))
0.0
sage: erf(RR(0))
0.0
sage: erf(ZZ(0))
0.0

# timing without application of patch 
sage: %timeit t = erf(0)
625 loops, best of 3: 89.2 µs per loop
sage: %timeit t = erf(0.0)
625 loops, best of 3: 166 µs per loop
sage: %timeit t = erf(CC(0))
625 loops, best of 3: 232 µs per loop
sage: %timeit t = erf(CC(0.0))
625 loops, best of 3: 253 µs per loop
sage: %timeit t = erf(RR(0.0))
625 loops, best of 3: 170 µs per loop
sage: %timeit t = erf(RR(0))
625 loops, best of 3: 158 µs per loop
sage: %timeit t = erf(ZZ(0))
625 loops, best of 3: 89 µs per loop
sage: %timeit t = erf(x)
625 loops, best of 3: 90.4 µs per loop

# timing after application of patch 
# ( testing for zero using is_zero() )

sage: %timeit t = erf(0)
625 loops, best of 3: 107 µs per loop
sage: %timeit t = erf(0.0)
625 loops, best of 3: 120 µs per loop
sage: %timeit t = erf(CC(0))
625 loops, best of 3: 198 µs per loop
sage: %timeit t = erf(CC(0.0))
625 loops, best of 3: 220 µs per loop
sage: %timeit t = erf(RR(0.0))
625 loops, best of 3: 122 µs per loop
sage: %timeit t = erf(RR(0))
625 loops, best of 3: 111 µs per loop
sage: %timeit t = erf(ZZ(0))
625 loops, best of 3: 113 µs per loop
sage: %timeit t = erf(x)
625 loops, best of 3: 106 µs per loop

# timing after application of patch
# ( testing for zero using "==0" )

sage: %timeit t = erf(0)
625 loops, best of 3: 135 µs per loop
sage: %timeit t = erf(0.0)
625 loops, best of 3: 148 µs per loop
sage: %timeit t = erf(CC(0))
625 loops, best of 3: 231 µs per loop
sage: %timeit t = erf(CC(0.0))
625 loops, best of 3: 253 µs per loop
sage: %timeit t = erf(RR(0.0))
625 loops, best of 3: 145 µs per loop
sage: %timeit t = erf(RR(0))
625 loops, best of 3: 130 µs per loop
sage: %timeit t = erf(ZZ(0))
625 loops, best of 3: 126 µs per loop
sage: %timeit t = erf(x)
625 loops, best of 3: 117 µs per loop

#
# The one failure is in expression.pyx 
#
[email protected]:~/sage-4.4.2$ ./sage -t  devel/sage/sage/symbolic/expression.pyx
sage -t  "devel/sage/sage/symbolic/expression.pyx"          
**********************************************************************
File "/home/rossk/sage-4.4.2/devel/sage/sage/symbolic/expression.pyx", line 7082:
    sage: (cos(theta) - erf(theta)).plot((theta,-2*pi,2*pi))
Exception raised:
    Traceback (most recent call last):
      File "/home/rossk/sage-4.4.2/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/home/rossk/sage-4.4.2/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/home/rossk/sage-4.4.2/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_162[5]>", line 1, in <module>
        (cos(theta) - erf(theta)).plot((theta,-Integer(2)*pi,Integer(2)*pi))###line 7082:
    sage: (cos(theta) - erf(theta)).plot((theta,-2*pi,2*pi))
      File "expression.pyx", line 7161, in sage.symbolic.expression.Expression.plot (sage/symbolic/expression.cpp:28597)
      File "/home/rossk/sage-4.4.2/local/lib/python/site-packages/sage/plot/misc.py", line 283, in wrapper
        return func(*args, **kwds)
      File "/home/rossk/sage-4.4.2/local/lib/python/site-packages/sage/plot/misc.py", line 138, in wrapper
        return func(*args, **options)
      File "/home/rossk/sage-4.4.2/local/lib/python/site-packages/sage/plot/plot.py", line 2501, in plot
        G = _plot(funcs, *args, **kwds)
      File "/home/rossk/sage-4.4.2/local/lib/python/site-packages/sage/plot/plot.py", line 2608, in _plot
        data = generate_plot_points(f, xrange, plot_points, adaptive_tolerance, adaptive_recursion, randomize)
      File "/home/rossk/sage-4.4.2/local/lib/python/site-packages/sage/plot/plot.py", line 3596, in generate_plot_points
        data[i] = (float(xi), float(f(xi)))
      File "fast_eval.pyx", line 628, in sage.ext.fast_eval.FastDoubleFunc.__call__ (sage/ext/fast_eval.c:4495)
      File "fast_eval.pyx", line 636, in sage.ext.fast_eval.FastDoubleFunc._call_c (sage/ext/fast_eval.c:4575)
      File "fast_eval.pyx", line 432, in sage.ext.fast_eval.process_op (sage/ext/fast_eval.c:3058)
      File "function.pyx", line 431, in sage.symbolic.function.Function.__call__ (sage/symbolic/function.cpp:4528)
      File "/home/rossk/sage-4.4.2/local/lib/python/site-packages/sage/functions/other.py", line 71, in _eval_
        if x.is_zero():
    AttributeError: 'float' object has no attribute 'is_zero'
**********************************************************************
File "/home/rossk/sage-4.4.2/devel/sage/sage/symbolic/expression.pyx", line 2255:
    sage: v1=var('v1'); a = (2*erf(2*v1*arcsech(0))/v1); ~a
Exception raised:
    Traceback (most recent call last):
      File "/home/rossk/sage-4.4.2/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/home/rossk/sage-4.4.2/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/home/rossk/sage-4.4.2/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_59[4]>", line 1, in <module>
        v1=var('v1'); a = (Integer(2)*erf(Integer(2)*v1*arcsech(Integer(0)))/v1); ~a###line 2255:
    sage: v1=var('v1'); a = (2*erf(2*v1*arcsech(0))/v1); ~a
      File "function.pyx", line 431, in sage.symbolic.function.Function.__call__ (sage/symbolic/function.cpp:4528)
      File "/home/rossk/sage-4.4.2/local/lib/python/site-packages/sage/functions/other.py", line 71, in _eval_
        if x.is_zero():
      File "element.pyx", line 750, in sage.structure.element.Element.is_zero (sage/structure/element.c:5729)
      File "expression.pyx", line 1640, in sage.symbolic.expression.Expression.__nonzero__ (sage/symbolic/expression.cpp:8117)
      File "expression.pyx", line 1634, in sage.symbolic.expression.Expression.__nonzero__ (sage/symbolic/expression.cpp:8049)
      File "/home/rossk/sage-4.4.2/local/lib/python/site-packages/sage/symbolic/relation.py", line 381, in test_relation_maxima
        m = relation._maxima_()
      File "expression.pyx", line 433, in sage.symbolic.expression.Expression._maxima_ (sage/symbolic/expression.cpp:3382)
      File "sage_object.pyx", line 386, in sage.structure.sage_object.SageObject._interface_ (sage/structure/sage_object.c:3501)
      File "/home/rossk/sage-4.4.2/local/lib/python/site-packages/sage/interfaces/expect.py", line 1032, in __call__
        return cls(self, x, name=name)
      File "/home/rossk/sage-4.4.2/local/lib/python/site-packages/sage/interfaces/expect.py", line 1451, in __init__
        raise TypeError, x
    TypeError: Error executing code in Maxima
    CODE:
        sage934 : (v1)*(asech(0))*(2) = 0$
    Maxima ERROR:
        
    The number 0 isn't in the domain of asech
     -- an error. To debug this try: debugmode(true);

**********************************************************************
2 items had failures:
   1 of  15 in __main__.example_162
   1 of   5 in __main__.example_59
***Test Failed*** 2 failures.
For whitespace errors, see the file /home/rossk/.sage//tmp/.doctest_expression.py
         [105.6 s]
 
----------------------------------------------------------------------
The following tests failed:


        sage -t  "devel/sage/sage/symbolic/expression.pyx"
Total time for all tests: 105.6 seconds


--------------------------------

# the errors above seem to be contradicted by the statements below

# The error of "The number 0 isn't in the domain of asech" seems contradicted by
sage: asech(0)
arcsech(0)
sage: asech(0.0)
+infinity

# The error of "'float' object has no attribute 'is_zero'" seems contradicted by
sage: (0.0).is_zero()
True
sage: RR(0).is_zero()
True

symbolics/erf (last edited 2010-05-28 12:49:25 by RossKyprianou)