Ticket #3955 (new enhancement)

Opened 3 months ago

Last modified 3 months ago

make find_minimum_on_interval use _fast_float_

Reported by: was Assigned to: burcin
Priority: major Milestone: sage-3.2.2
Component: calculus Keywords:
Cc:

Description


On Tue, Aug 26, 2008 at 2:07 AM, Stan Schymanski <schymans@gmail.com> wrote:
>
> Dear William,
>
> On Aug 25, 6:48 pm, "William Stein" <wst...@gmail.com> wrote:
>
>> If you call _fast_float_ as illustrated below on your functions, find_* will
>> work, and also be much much faster:
>>
>> sage: find_maximum_on_interval((-x^2)._fast_float_(x),-1,1)
>> (-7.7037197775489434e-34, -2.77555756156e-17)
>> sage: find_minimum_on_interval((-x^2)._fast_float_(x),-1,1)
>> (-0.99999992595132459, -0.999999962976)
>>
>> find_* doesn't do this already since (1) _fast_float_ was written
>> after find_*, and (2) nobody has had the time to change find_*
>> to use _fast_float_.
>
> That's amazing, thank you! I didn't find any information about the
> _fast_float_. Can it be used for other purposes, too?

Yes.  It takes any polynomial or symbolic expression and turns
it into a very fast callable function that has input and output floats.
It should get used automatically by functions like find_min* but
we haven't pushed this through enough yet. 

Change History

08/26/2008 02:12:38 AM changed by was

  • owner changed from tbd to burcin.
  • component changed from algebra to calculus.

09/01/2008 07:30:34 PM changed by jwmerrill

fast_float doesn't look like a win here in 3.1.2.alpha2, at least not in the cases I tried

sage: timeit('find_minimum_on_interval(x*sin(x)^2,3,3.4)')
25 loops, best of 3: 24.5 ms per loop
sage: sage: timeit('find_minimum_on_interval((x*sin(x)^2)._fast_float_(x),3,3.4)')
5 loops, best of 3: 109 ms per loop

# not sure what goes wrong here
sage: find_maximum_on_interval(-x^2,-1,1)
Traceback (most recent call last):
...
TypeError: cannot coerce type '<class 'sage.calculus.equations.SymbolicEquation'>' into a SymbolicExpression.

sage: timeit('(-x^2).find_maximum_on_interval(-1,1)')
5 loops, best of 3: 22.4 ms per loop
sage: timeit('find_maximum_on_interval((-x^2)._fast_float_(x),-1,1)')
5 loops, best of 3: 61.5 ms per loop

09/01/2008 07:37:49 PM changed by jwmerrill

I guess what is going on is that the time to compile the function to fast_float form swamps the time to find the minimum, at least in these cases.

sage: timeit('f = (-x^2)._fast_float_()')
5 loops, best of 3: 82.6 ms per loop
sage: timeit('find_maximum_on_interval(f,-1,1)')
625 loops, best of 3: 690 µs per loop

09/01/2008 08:07:25 PM changed by jwmerrill

I notice that fast_float was sneaked into find_root in the first patch at #2703, which was nominally a doctest coverage patch. It doesn't look like any kind of benchmarking was done there.

09/01/2008 08:08:35 PM changed by jwmerrill

Oops, it was #2073.

09/01/2008 11:26:15 PM changed by jwmerrill

See #3622 for a discussion of timings with fast_float. Based on that discussion, this probably is worth doing.