(FPCore (x y) :precision binary64 (sqrt (- (* x x) (* y y))))
double code(double x, double y) { return sqrt(((x * x) - (y * y))); }
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y code = sqrt(((x * x) - (y * y))) end function
public static double code(double x, double y) { return Math.sqrt(((x * x) - (y * y))); }
def code(x, y): return math.sqrt(((x * x) - (y * y)))
function code(x, y) return sqrt(Float64(Float64(x * x) - Float64(y * y))) end
function tmp = code(x, y) tmp = sqrt(((x * x) - (y * y))); end
code[x_, y_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \sqrt{x \cdot x - y \cdot y} \end{array}
Sampling outcomes in binary64 precision:
Herbie found 2 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x y) :precision binary64 (sqrt (- (* x x) (* y y))))
double code(double x, double y) { return sqrt(((x * x) - (y * y))); }
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y code = sqrt(((x * x) - (y * y))) end function
public static double code(double x, double y) { return Math.sqrt(((x * x) - (y * y))); }
def code(x, y): return math.sqrt(((x * x) - (y * y)))
function code(x, y) return sqrt(Float64(Float64(x * x) - Float64(y * y))) end
function tmp = code(x, y) tmp = sqrt(((x * x) - (y * y))); end
code[x_, y_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \sqrt{x \cdot x - y \cdot y} \end{array}
x_m = (fabs.f64 x) (FPCore (x_m y) :precision binary64 (fma (* (/ -0.5 x_m) y) y x_m))
x_m = fabs(x); double code(double x_m, double y) { return fma(((-0.5 / x_m) * y), y, x_m); }
x_m = abs(x) function code(x_m, y) return fma(Float64(Float64(-0.5 / x_m) * y), y, x_m) end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_] := N[(N[(N[(-0.5 / x$95$m), $MachinePrecision] * y), $MachinePrecision] * y + x$95$m), $MachinePrecision]
\begin{array}{l} x_m = \left|x\right| \\ \mathsf{fma}\left(\frac{-0.5}{x\_m} \cdot y, y, x\_m\right) \end{array}
Initial program 52.4%
Taylor expanded in y around 0
+-commutative
N/A
associate-*r/
N/A
associate-*l/
N/A
metadata-eval
N/A
distribute-neg-frac
N/A
metadata-eval
N/A
associate-*r/
N/A
unpow2
N/A
associate-*r*
N/A
lower-fma.f64
N/A
lower-*.f64
N/A
associate-*r/
N/A
metadata-eval
N/A
distribute-neg-frac
N/A
metadata-eval
N/A
lower-/.f64
49.0
Applied rewrites49.0%
Final simplification49.0%
x_m = (fabs.f64 x) (FPCore (x_m y) :precision binary64 x_m)
x_m = fabs(x); double code(double x_m, double y) { return x_m; }
x_m = abs(x) real(8) function code(x_m, y) real(8), intent (in) :: x_m real(8), intent (in) :: y code = x_m end function
x_m = Math.abs(x); public static double code(double x_m, double y) { return x_m; }
x_m = math.fabs(x) def code(x_m, y): return x_m
x_m = abs(x) function code(x_m, y) return x_m end
x_m = abs(x); function tmp = code(x_m, y) tmp = x_m; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_] := x$95$m
\begin{array}{l} x_m = \left|x\right| \\ x\_m \end{array}
Initial program 52.4%
lift--.f64
N/A
lift-*.f64
N/A
lift-*.f64
N/A
difference-of-squares
N/A
*-commutative
N/A
lower-*.f64
N/A
lower--.f64
N/A
+-commutative
N/A
lower-+.f64
53.0
Applied rewrites53.0%
Taylor expanded in x around inf
+-commutative
N/A
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
48.9
Applied rewrites48.9%
herbie shell --seed 1
(FPCore (x y)
:name "sqrt(x*x-y*y)"
:precision binary64
:pre (and (and (<= -1.79e+308 x) (<= x 1.79e+308)) (and (<= -1.79e+308 y) (<= y 1.79e+308)))
(sqrt (- (* x x) (* y y))))