thegooglecodearchive / mpmath

Automatically exported from code.google.com/p/mpmath
Other
0 stars 0 forks source link

implement missing functions for intervals #67

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Currently, they all raise TypeErrors. mpi(2)**0.5 works however.

See http://conference.scipy.org/proceedings/SciPy2008/paper_3/full_text.pdf.

Original issue reported on code.google.com by Vinzent.Steinberg@gmail.com on 23 Sep 2008 at 7:57

GoogleCodeExporter commented 9 years ago
I thought I fixed exp, sqrt and log in
[http://code.google.com/p/mpmath/source/detail?r=569 r569]?

Original comment by fredrik....@gmail.com on 23 Sep 2008 at 8:42

GoogleCodeExporter commented 9 years ago
The following functions (and maybe a few others) should be nearly trivial to
implement in libmpi: sinh, cosh, tanh, coth, sech, csch, asin, acos, atan, acot,
asec, acsc, asinh, acosh, atanh, acoth, asech, acsch, erf, erfc, ei, li. They 
are all
essentially monotonic (save for one or two discontinuities or extremas) as
real-valued functions, so it's just a matter of writing down the formulas and
checking that all extremes are handled correctly.

The following require more work: sin, cos, tan, cot, sec, csc, gamma, zeta. I 
have an
idea how to implement them (and some half-started code).

Original comment by fredrik....@gmail.com on 23 Sep 2008 at 9:02

GoogleCodeExporter commented 9 years ago
Sorry, my svn copy was not up to date. exp, sqrt and log are fixed indeed.

Original comment by Vinzent.Steinberg@gmail.com on 24 Sep 2008 at 10:36

GoogleCodeExporter commented 9 years ago
I tried the examples from the pdf. The following ones have different results:

>>> 1/mpi(-2,4)
[-inf, +inf] # vs. interval([-inf, -0.5], [0.25, inf])
>>> log(mpi(-1,1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mpmath/mptypes.py", line 666, in g
    v = f(*args, **kwargs)
  File "mpmath/mptypes.py", line 836, in log
    return ln(x)
  File "mpmath/mptypes.py", line 696, in f
    return make_mpi(interval_f(x._val, prec))
  File "mpmath/libmpi.py", line 217, in mpi_log
    a = flog(sa, prec, round_floor)
  File "mpmath/lib.py", line 1996, in flog
    raise ComplexResult("logarithm of a negative number")
mpmath.lib.ComplexResult: logarithm of a negative number
# vs. interval([-inf, 0.0])
>>> tan(mpi(.25, .75))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mpmath/mptypes.py", line 697, in f
    raise NotImplementedError("%s of a %s" % (name, type(x)))
NotImplementedError: tan of a <class 'mpmath.mptypes.mpi'>
# vs. interval([-inf, -1.0], [1.0, inf])

Original comment by Vinzent.Steinberg@gmail.com on 24 Sep 2008 at 11:12

GoogleCodeExporter commented 9 years ago
The first one is due to multi-intervals not yet being implemented. The interval
computed by mpmath is correct; just too pessimistic.

The second one is handled erroneously by pyinterval, in my opinion. The result 
of an
interval operation should include the entire image range, and if part of the 
range is
complex, returning only the real part is wrong. I plan to support complex 
interval
arithmetic in mpmath.

Note that the function in the last example should tanpi, not tan.

Original comment by fredrik....@gmail.com on 24 Sep 2008 at 11:25

GoogleCodeExporter commented 9 years ago
There is no tanpi in mpmath, so I just took tan. :)

Original comment by Vinzent.Steinberg@gmail.com on 24 Sep 2008 at 12:13

GoogleCodeExporter commented 9 years ago
Basic support for interval trig functions committed.

Monotonicity and inclusion of minima/maxima depends on the quadrants of both
endpoints. There are 4*4 = 16 different cases; I've implemented to 6 most 
important
ones. The remaining ones should be straightforward, but tedious, to implement.

Original comment by fredrik....@gmail.com on 26 Sep 2008 at 12:52