(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 2 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 (* (- 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.8%
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.8%
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%
Taylor expanded in r around inf
associate-*r/
N/A
distribute-rgt1-in
N/A
metadata-eval
N/A
mul0-lft
N/A
metadata-eval
N/A
mul0-lft
N/A
associate-*r/
N/A
mul0-lft
N/A
metadata-eval
N/A
*-rgt-identity
64.9
Applied rewrites64.9%
herbie shell --seed 1
(FPCore (r x)
:name "sqrt(r^2-x^2)"
:precision binary64
:pre (and (and (<= 1e-13 r) (<= r 100.0)) (and (<= 1e-13 x) (<= x 100.0)))
(sqrt (- (pow r 2.0) (pow x 2.0))))