(FPCore (r x) :precision binary64 (sqrt (- (pow r 2.0) (pow x 2.0))))
double code(double r, double x) { return sqrt((pow(r, 2.0) - pow(x, 2.0))); }
real(8) function code(r, x) real(8), intent (in) :: r real(8), intent (in) :: x code = sqrt(((r ** 2.0d0) - (x ** 2.0d0))) end function
public static double code(double r, double x) { return Math.sqrt((Math.pow(r, 2.0) - Math.pow(x, 2.0))); }
def code(r, x): return math.sqrt((math.pow(r, 2.0) - math.pow(x, 2.0)))
function code(r, x) return sqrt(Float64((r ^ 2.0) - (x ^ 2.0))) end
function tmp = code(r, x) tmp = sqrt(((r ^ 2.0) - (x ^ 2.0))); end
code[r_, x_] := N[Sqrt[N[(N[Power[r, 2.0], $MachinePrecision] - N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \sqrt{{r}^{2} - {x}^{2}} \end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (r x) :precision binary64 (sqrt (- (pow r 2.0) (pow x 2.0))))
double code(double r, double x) { return sqrt((pow(r, 2.0) - pow(x, 2.0))); }
real(8) function code(r, x) real(8), intent (in) :: r real(8), intent (in) :: x code = sqrt(((r ** 2.0d0) - (x ** 2.0d0))) end function
public static double code(double r, double x) { return Math.sqrt((Math.pow(r, 2.0) - Math.pow(x, 2.0))); }
def code(r, x): return math.sqrt((math.pow(r, 2.0) - math.pow(x, 2.0)))
function code(r, x) return sqrt(Float64((r ^ 2.0) - (x ^ 2.0))) end
function tmp = code(r, x) tmp = sqrt(((r ^ 2.0) - (x ^ 2.0))); end
code[r_, x_] := N[Sqrt[N[(N[Power[r, 2.0], $MachinePrecision] - N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \sqrt{{r}^{2} - {x}^{2}} \end{array}
(FPCore (r x) :precision binary64 (sqrt (fma r r (* (- x) x))))
double code(double r, double x) { return sqrt(fma(r, r, (-x * x))); }
function code(r, x) return sqrt(fma(r, r, Float64(Float64(-x) * x))) end
code[r_, x_] := N[Sqrt[N[(r * r + N[((-x) * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \sqrt{\mathsf{fma}\left(r, r, \left(-x\right) \cdot x\right)} \end{array}
Initial program 99.7%
lift--.f64
N/A
sub-neg
N/A
lift-pow.f64
N/A
unpow2
N/A
lower-fma.f64
N/A
lift-pow.f64
N/A
unpow2
N/A
distribute-lft-neg-in
N/A
lower-*.f64
N/A
lower-neg.f64
99.8
Applied rewrites99.8%
(FPCore (r x) :precision binary64 (sqrt (* (- r x) (+ x r))))
double code(double r, double x) { return sqrt(((r - x) * (x + r))); }
real(8) function code(r, x) real(8), intent (in) :: r real(8), intent (in) :: x code = sqrt(((r - x) * (x + r))) end function
public static double code(double r, double x) { return Math.sqrt(((r - x) * (x + r))); }
def code(r, x): return math.sqrt(((r - x) * (x + r)))
function code(r, x) return sqrt(Float64(Float64(r - x) * Float64(x + r))) end
function tmp = code(r, x) tmp = sqrt(((r - x) * (x + r))); end
code[r_, x_] := N[Sqrt[N[(N[(r - x), $MachinePrecision] * N[(x + r), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \sqrt{\left(r - x\right) \cdot \left(x + r\right)} \end{array}
Initial program 99.7%
lift--.f64
N/A
lift-pow.f64
N/A
unpow2
N/A
lift-pow.f64
N/A
unpow2
N/A
difference-of-squares
N/A
*-commutative
N/A
lower-*.f64
N/A
lower--.f64
N/A
+-commutative
N/A
lower-+.f64
99.8
Applied rewrites99.8%
(FPCore (r x) :precision binary64 r)
double code(double r, double x) { return r; }
real(8) function code(r, x) real(8), intent (in) :: r real(8), intent (in) :: x code = r end function
public static double code(double r, double x) { return r; }
def code(r, x): return r
function code(r, x) return r end
function tmp = code(r, x) tmp = r; end
code[r_, x_] := r
\begin{array}{l} \\ r \end{array}
Initial program 99.7%
lift-sqrt.f64
N/A
pow1/2
N/A
lift--.f64
N/A
lift-pow.f64
N/A
unpow2
N/A
lift-pow.f64
N/A
unpow2
N/A
difference-of-squares
N/A
*-commutative
N/A
unpow-prod-down
N/A
lower-*.f64
N/A
pow1/2
N/A
lower-sqrt.f64
N/A
lower--.f64
N/A
pow1/2
N/A
lower-sqrt.f64
N/A
+-commutative
N/A
lower-+.f64
99.5
Applied rewrites99.5%
Taylor expanded in r around inf
+-commutative
N/A
associate-*r/
N/A
distribute-rgt1-in
N/A
metadata-eval
N/A
associate-*r*
N/A
metadata-eval
N/A
associate-*r/
N/A
mul0-lft
N/A
metadata-eval
N/A
*-rgt-identity
60.0
Applied rewrites60.0%
herbie shell --seed 1
(FPCore (r x)
:name "sqrt(r^2-x^2)"
:precision binary64
:pre (and (and (<= 1e-10 r) (<= r 100.0)) (and (<= 1e-10 x) (<= x 100.0)))
(sqrt (- (pow r 2.0) (pow x 2.0))))