simon-git: spigot (master): spigot.git
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Sat Oct 15 15:48:59 BST 2016
TL;DR:
1780688 Implement a one-input spigot_quadratic().
89a8873 Use the new quadratic evaluator for x^2 and x^-2.
Repository: https://git.tartarus.org/simon/spigot.git
On the web: https://git.tartarus.org/?p=simon/spigot.git
Branch updated: master
Committer: spigot.git
Date: 2016-10-15 15:48:59
commit 17806881d77608cac2a01aa29f5a4fc168d9506b
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=17806881d77608cac2a01aa29f5a4fc168d9506b;hp=0daf1647529fb3963fbc09a3b2f9faa0d47d3673
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 15 15:25:36 2016 +0100
Implement a one-input spigot_quadratic().
This evaluates an arbitrary quadratic polynomial in its input, by
instantiating a Core2 with a special flag that causes the two inputs
to be the same input. It's not currently exposed to the outside world,
but it's used internally for various trig and log functions that
previously had to square a number by doing spigot_mul(x, x->clone())
and hence did all the work of evaluating x twice. The 'arbitrary
quadratic' part, rather than just squaring, is also handy because of
the various trig and hyperbolic functions that need things like
sqrt(1-x^2) or sqrt(x^2+1).
This is a much simpler and more restricted feature than the full-scale
'arbitrary polynomial core' idea I had in the TODO file. I had a try
at the full version recently just to see what would happen, and I
found that what did happen was that I got to the point of trying to
fill in PolyCore::endpoints() and then realised it was not at all
obvious how to quickly and easily produce a bounding interval for an
arbitrary polynomial in x given an interval for x - you can't just
evaluate the polynomial at the interval endpoints, because it might
have turning points inside the interval, but finding those becomes
nightmarish, so instead you want some sort of conservative estimate,
but in the general case it wasn't clear how to come up with one that
would guarantee the interval size converging to zero adequately fast.
So I decided the full polynomial core was too much effort and I'd do
the really simple approach instead.
(In the approach I've used, a conservative estimate is arranged by the
fact that Core2::endpoints() still thinks it's evaluating a function
of _two_ variables varying independently, so that it evaluates all of
f(amin,amin), f(amin,amax), f(amax,amin) and f(amax,amax). But if you
extended that idea to a polynomial of arbitrary degree n, you'd end up
with 2^n endpoints, which would get painful.)
TODO.txt | 35 ----------------------------------
arithmetic.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
exp.cpp | 12 ++++--------
funcs.h | 2 ++
trig.cpp | 9 +++------
5 files changed, 60 insertions(+), 57 deletions(-)
commit 89a88738265d3b805d618358932d88fa5a383408
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=89a88738265d3b805d618358932d88fa5a383408;hp=17806881d77608cac2a01aa29f5a4fc168d9506b
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Oct 15 15:28:12 2016 +0100
Use the new quadratic evaluator for x^2 and x^-2.
Now user expressions such as 'pi^2' can take advantage of the new
ability to not have to do all the work of doubly evaluating the number
being squared.
The difference can be quite striking in some cases (though admittedly
barely perceptible in others) - I see a reduction from 41.6 seconds to
3.1 seconds in the running time reported by the command
time ./spigot -d750 'eulergamma^2'
I've added just one new test, of raising something to the power -2
(which is also special-cased by the new system). Existing tests seem
adequate to exercise all the other places I've changed in this commit
and the previous one.
arithmetic.cpp | 35 +++++++++++++++++++++++++++++++++++
exp.cpp | 12 ++++++++++++
funcs.h | 1 +
test.sh | 1 +
4 files changed, 49 insertions(+)
More information about the tartarus-commits
mailing list