(FPCore (x y) :precision binary64 (- x (sqrt (- (pow y 2.0) x))))
double code(double x, double y) { return x - sqrt((pow(y, 2.0) - x)); }
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y code = x - sqrt(((y ** 2.0d0) - x)) end function
public static double code(double x, double y) { return x - Math.sqrt((Math.pow(y, 2.0) - x)); }
def code(x, y): return x - math.sqrt((math.pow(y, 2.0) - x))
function code(x, y) return Float64(x - sqrt(Float64((y ^ 2.0) - x))) end
function tmp = code(x, y) tmp = x - sqrt(((y ^ 2.0) - x)); end
code[x_, y_] := N[(x - N[Sqrt[N[(N[Power[y, 2.0], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ x - \sqrt{{y}^{2} - x} \end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x y) :precision binary64 (- x (sqrt (- (pow y 2.0) x))))
double code(double x, double y) { return x - sqrt((pow(y, 2.0) - x)); }
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y code = x - sqrt(((y ** 2.0d0) - x)) end function
public static double code(double x, double y) { return x - Math.sqrt((Math.pow(y, 2.0) - x)); }
def code(x, y): return x - math.sqrt((math.pow(y, 2.0) - x))
function code(x, y) return Float64(x - sqrt(Float64((y ^ 2.0) - x))) end
function tmp = code(x, y) tmp = x - sqrt(((y ^ 2.0) - x)); end
code[x_, y_] := N[(x - N[Sqrt[N[(N[Power[y, 2.0], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ x - \sqrt{{y}^{2} - x} \end{array}
(FPCore (x y) :precision binary64 (- x (sqrt (- (pow y 2.0) x))))
double code(double x, double y) { return x - sqrt((pow(y, 2.0) - x)); }
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y code = x - sqrt(((y ** 2.0d0) - x)) end function
public static double code(double x, double y) { return x - Math.sqrt((Math.pow(y, 2.0) - x)); }
def code(x, y): return x - math.sqrt((math.pow(y, 2.0) - x))
function code(x, y) return Float64(x - sqrt(Float64((y ^ 2.0) - x))) end
function tmp = code(x, y) tmp = x - sqrt(((y ^ 2.0) - x)); end
code[x_, y_] := N[(x - N[Sqrt[N[(N[Power[y, 2.0], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ x - \sqrt{{y}^{2} - x} \end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 (if (<= (pow y 2.0) 1e-223) (- x (sqrt (- x))) (- x (fma (/ x y) -0.5 y))))
double code(double x, double y) { double tmp; if (pow(y, 2.0) <= 1e-223) { tmp = x - sqrt(-x); } else { tmp = x - fma((x / y), -0.5, y); } return tmp; }
function code(x, y) tmp = 0.0 if ((y ^ 2.0) <= 1e-223) tmp = Float64(x - sqrt(Float64(-x))); else tmp = Float64(x - fma(Float64(x / y), -0.5, y)); end return tmp end
code[x_, y_] := If[LessEqual[N[Power[y, 2.0], $MachinePrecision], 1e-223], N[(x - N[Sqrt[(-x)], $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(x / y), $MachinePrecision] * -0.5 + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{y}^{2} \leq 10^{-223}:\\ \;\;\;\;x - \sqrt{-x}\\ \mathbf{else}:\\ \;\;\;\;x - \mathsf{fma}\left(\frac{x}{y}, -0.5, y\right)\\ \end{array} \end{array}
if (pow.f64 y #s(literal 2 binary64)) < 9.9999999999999997e-224
Initial program 100.0%
Taylor expanded in x around inf
mul-1-neg
N/A
lower-neg.f64
94.1
Applied rewrites94.1%
if 9.9999999999999997e-224 < (pow.f64 y #s(literal 2 binary64))
Initial program 100.0%
Taylor expanded in x around 0
+-commutative
N/A
*-commutative
N/A
lower-fma.f64
N/A
lower-/.f64
41.6
Applied rewrites41.6%
(FPCore (x y) :precision binary64 (if (<= (pow y 2.0) 1e-223) (- x (sqrt (- x))) (- x (sqrt (* y y)))))
double code(double x, double y) { double tmp; if (pow(y, 2.0) <= 1e-223) { tmp = x - sqrt(-x); } else { tmp = x - sqrt((y * y)); } return tmp; }
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y real(8) :: tmp if ((y ** 2.0d0) <= 1d-223) then tmp = x - sqrt(-x) else tmp = x - sqrt((y * y)) end if code = tmp end function
public static double code(double x, double y) { double tmp; if (Math.pow(y, 2.0) <= 1e-223) { tmp = x - Math.sqrt(-x); } else { tmp = x - Math.sqrt((y * y)); } return tmp; }
def code(x, y): tmp = 0 if math.pow(y, 2.0) <= 1e-223: tmp = x - math.sqrt(-x) else: tmp = x - math.sqrt((y * y)) return tmp
function code(x, y) tmp = 0.0 if ((y ^ 2.0) <= 1e-223) tmp = Float64(x - sqrt(Float64(-x))); else tmp = Float64(x - sqrt(Float64(y * y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y ^ 2.0) <= 1e-223) tmp = x - sqrt(-x); else tmp = x - sqrt((y * y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[Power[y, 2.0], $MachinePrecision], 1e-223], N[(x - N[Sqrt[(-x)], $MachinePrecision]), $MachinePrecision], N[(x - N[Sqrt[N[(y * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{y}^{2} \leq 10^{-223}:\\ \;\;\;\;x - \sqrt{-x}\\ \mathbf{else}:\\ \;\;\;\;x - \sqrt{y \cdot y}\\ \end{array} \end{array}
if (pow.f64 y #s(literal 2 binary64)) < 9.9999999999999997e-224
Initial program 100.0%
Taylor expanded in x around inf
mul-1-neg
N/A
lower-neg.f64
94.1
Applied rewrites94.1%
if 9.9999999999999997e-224 < (pow.f64 y #s(literal 2 binary64))
Initial program 100.0%
Taylor expanded in x around 0
unpow2
N/A
lower-*.f64
81.5
Applied rewrites81.5%
(FPCore (x y) :precision binary64 (if (<= (pow y 2.0) 1e-223) (- x (sqrt (- x))) (- y)))
double code(double x, double y) { double tmp; if (pow(y, 2.0) <= 1e-223) { tmp = x - sqrt(-x); } else { tmp = -y; } return tmp; }
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y real(8) :: tmp if ((y ** 2.0d0) <= 1d-223) then tmp = x - sqrt(-x) else tmp = -y end if code = tmp end function
public static double code(double x, double y) { double tmp; if (Math.pow(y, 2.0) <= 1e-223) { tmp = x - Math.sqrt(-x); } else { tmp = -y; } return tmp; }
def code(x, y): tmp = 0 if math.pow(y, 2.0) <= 1e-223: tmp = x - math.sqrt(-x) else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if ((y ^ 2.0) <= 1e-223) tmp = Float64(x - sqrt(Float64(-x))); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y ^ 2.0) <= 1e-223) tmp = x - sqrt(-x); else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[Power[y, 2.0], $MachinePrecision], 1e-223], N[(x - N[Sqrt[(-x)], $MachinePrecision]), $MachinePrecision], (-y)]
\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{y}^{2} \leq 10^{-223}:\\ \;\;\;\;x - \sqrt{-x}\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \end{array}
if (pow.f64 y #s(literal 2 binary64)) < 9.9999999999999997e-224
Initial program 100.0%
Taylor expanded in x around inf
mul-1-neg
N/A
lower-neg.f64
94.1
Applied rewrites94.1%
if 9.9999999999999997e-224 < (pow.f64 y #s(literal 2 binary64))
Initial program 100.0%
Taylor expanded in x around 0
mul-1-neg
N/A
lower-neg.f64
40.9
Applied rewrites40.9%
(FPCore (x y) :precision binary64 (- x (sqrt (fma y y (- x)))))
double code(double x, double y) { return x - sqrt(fma(y, y, -x)); }
function code(x, y) return Float64(x - sqrt(fma(y, y, Float64(-x)))) end
code[x_, y_] := N[(x - N[Sqrt[N[(y * y + (-x)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ x - \sqrt{\mathsf{fma}\left(y, y, -x\right)} \end{array}
Initial program 100.0%
lift--.f64
N/A
sub-neg
N/A
lift-pow.f64
N/A
unpow2
N/A
lower-fma.f64
N/A
lower-neg.f64
99.9
Applied rewrites99.9%
(FPCore (x y) :precision binary64 (- y))
double code(double x, double y) { return -y; }
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y code = -y end function
public static double code(double x, double y) { return -y; }
def code(x, y): return -y
function code(x, y) return Float64(-y) end
function tmp = code(x, y) tmp = -y; end
code[x_, y_] := (-y)
\begin{array}{l} \\ -y \end{array}
Initial program 100.0%
Taylor expanded in x around 0
mul-1-neg
N/A
lower-neg.f64
24.0
Applied rewrites24.0%
herbie shell --seed 1
(FPCore (x y)
:name "x - sqrt(pow(y, 2) - x)"
:precision binary64
:pre (and (and (<= -1000.0 x) (<= x 1000.0)) (and (<= -1000.0 y) (<= y 1000.0)))
(- x (sqrt (- (pow y 2.0) x))))