
(FPCore (x y) :precision binary64 (let* ((t_0 (* (* y 4.0) y))) (/ (- (* x x) t_0) (+ (* x x) t_0))))
double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
t_0 = (y * 4.0d0) * y
code = ((x * x) - t_0) / ((x * x) + t_0)
end function
public static double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
def code(x, y): t_0 = (y * 4.0) * y return ((x * x) - t_0) / ((x * x) + t_0)
function code(x, y) t_0 = Float64(Float64(y * 4.0) * y) return Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) end
function tmp = code(x, y) t_0 = (y * 4.0) * y; tmp = ((x * x) - t_0) / ((x * x) + t_0); end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot y\\
\frac{x \cdot x - t_0}{x \cdot x + t_0}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (let* ((t_0 (* (* y 4.0) y))) (/ (- (* x x) t_0) (+ (* x x) t_0))))
double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
t_0 = (y * 4.0d0) * y
code = ((x * x) - t_0) / ((x * x) + t_0)
end function
public static double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
def code(x, y): t_0 = (y * 4.0) * y return ((x * x) - t_0) / ((x * x) + t_0)
function code(x, y) t_0 = Float64(Float64(y * 4.0) * y) return Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) end
function tmp = code(x, y) t_0 = (y * 4.0) * y; tmp = ((x * x) - t_0) / ((x * x) + t_0); end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot y\\
\frac{x \cdot x - t_0}{x \cdot x + t_0}
\end{array}
\end{array}
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= (* x x) 1e-296)
(+ (* 0.5 (/ (/ x y) (/ y x))) -1.0)
(if (<= (* x x) 1e+269)
(pow (/ (fma x x t_0) (- (* x x) t_0)) -1.0)
(fma (* (/ y x) (/ y x)) -8.0 1.0)))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if ((x * x) <= 1e-296) {
tmp = (0.5 * ((x / y) / (y / x))) + -1.0;
} else if ((x * x) <= 1e+269) {
tmp = pow((fma(x, x, t_0) / ((x * x) - t_0)), -1.0);
} else {
tmp = fma(((y / x) * (y / x)), -8.0, 1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (Float64(x * x) <= 1e-296) tmp = Float64(Float64(0.5 * Float64(Float64(x / y) / Float64(y / x))) + -1.0); elseif (Float64(x * x) <= 1e+269) tmp = Float64(fma(x, x, t_0) / Float64(Float64(x * x) - t_0)) ^ -1.0; else tmp = fma(Float64(Float64(y / x) * Float64(y / x)), -8.0, 1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 1e-296], N[(N[(0.5 * N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1e+269], N[Power[N[(N[(x * x + t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision], N[(N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;x \cdot x \leq 10^{-296}:\\
\;\;\;\;0.5 \cdot \frac{\frac{x}{y}}{\frac{y}{x}} + -1\\
\mathbf{elif}\;x \cdot x \leq 10^{+269}:\\
\;\;\;\;{\left(\frac{\mathsf{fma}\left(x, x, t_0\right)}{x \cdot x - t_0}\right)}^{-1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 1e-296Initial program 51.2%
Taylor expanded in x around 0 72.8%
fma-neg72.8%
unpow272.8%
unpow272.8%
times-frac87.5%
metadata-eval87.5%
Simplified87.5%
fma-udef87.5%
pow287.5%
Applied egg-rr87.5%
unpow287.5%
clear-num87.5%
un-div-inv87.5%
Applied egg-rr87.5%
if 1e-296 < (*.f64 x x) < 1e269Initial program 83.9%
clear-num83.9%
inv-pow83.9%
fma-def83.9%
*-commutative83.9%
sub-neg83.9%
+-commutative83.9%
*-commutative83.9%
distribute-rgt-neg-in83.9%
fma-def83.9%
distribute-rgt-neg-in83.9%
metadata-eval83.9%
Applied egg-rr83.9%
add-sqr-sqrt41.9%
sqrt-unprod69.0%
swap-sqr69.0%
metadata-eval69.0%
metadata-eval69.0%
swap-sqr69.0%
sqrt-unprod27.0%
add-sqr-sqrt53.8%
fma-def53.8%
*-commutative53.8%
+-commutative53.8%
*-commutative53.8%
add-sqr-sqrt27.0%
sqrt-unprod69.0%
swap-sqr69.0%
metadata-eval69.0%
metadata-eval69.0%
swap-sqr69.0%
sqrt-unprod41.9%
add-sqr-sqrt83.9%
associate-*r*83.9%
metadata-eval83.9%
distribute-rgt-neg-in83.9%
associate-*r*83.9%
Applied egg-rr83.9%
if 1e269 < (*.f64 x x) Initial program 11.5%
Taylor expanded in x around inf 82.1%
associate--l+82.1%
distribute-rgt-out--82.1%
metadata-eval82.1%
*-commutative82.1%
+-commutative82.1%
*-commutative82.1%
fma-def82.1%
unpow282.1%
unpow282.1%
times-frac88.4%
Simplified88.4%
Final simplification86.2%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= (* x x) 1e-296)
(+ (* 0.5 (/ (/ x y) (/ y x))) -1.0)
(if (<= (* x x) 1e+269)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(fma (* (/ y x) (/ y x)) -8.0 1.0)))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if ((x * x) <= 1e-296) {
tmp = (0.5 * ((x / y) / (y / x))) + -1.0;
} else if ((x * x) <= 1e+269) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = fma(((y / x) * (y / x)), -8.0, 1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (Float64(x * x) <= 1e-296) tmp = Float64(Float64(0.5 * Float64(Float64(x / y) / Float64(y / x))) + -1.0); elseif (Float64(x * x) <= 1e+269) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = fma(Float64(Float64(y / x) * Float64(y / x)), -8.0, 1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 1e-296], N[(N[(0.5 * N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1e+269], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;x \cdot x \leq 10^{-296}:\\
\;\;\;\;0.5 \cdot \frac{\frac{x}{y}}{\frac{y}{x}} + -1\\
\mathbf{elif}\;x \cdot x \leq 10^{+269}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 1e-296Initial program 51.2%
Taylor expanded in x around 0 72.8%
fma-neg72.8%
unpow272.8%
unpow272.8%
times-frac87.5%
metadata-eval87.5%
Simplified87.5%
fma-udef87.5%
pow287.5%
Applied egg-rr87.5%
unpow287.5%
clear-num87.5%
un-div-inv87.5%
Applied egg-rr87.5%
if 1e-296 < (*.f64 x x) < 1e269Initial program 83.9%
if 1e269 < (*.f64 x x) Initial program 11.5%
Taylor expanded in x around inf 82.1%
associate--l+82.1%
distribute-rgt-out--82.1%
metadata-eval82.1%
*-commutative82.1%
+-commutative82.1%
*-commutative82.1%
fma-def82.1%
unpow282.1%
unpow282.1%
times-frac88.4%
Simplified88.4%
Final simplification86.2%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))) (t_1 (* -4.0 (/ (/ y x) (/ x y)))))
(if (<= (* x x) 1e-296)
(+ (* 0.5 (/ (/ x y) (/ y x))) -1.0)
(if (<= (* x x) 1e+269)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(+ t_1 (+ 1.0 t_1))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = -4.0 * ((y / x) / (x / y));
double tmp;
if ((x * x) <= 1e-296) {
tmp = (0.5 * ((x / y) / (y / x))) + -1.0;
} else if ((x * x) <= 1e+269) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = t_1 + (1.0 + t_1);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = y * (y * 4.0d0)
t_1 = (-4.0d0) * ((y / x) / (x / y))
if ((x * x) <= 1d-296) then
tmp = (0.5d0 * ((x / y) / (y / x))) + (-1.0d0)
else if ((x * x) <= 1d+269) then
tmp = ((x * x) - t_0) / ((x * x) + t_0)
else
tmp = t_1 + (1.0d0 + t_1)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = -4.0 * ((y / x) / (x / y));
double tmp;
if ((x * x) <= 1e-296) {
tmp = (0.5 * ((x / y) / (y / x))) + -1.0;
} else if ((x * x) <= 1e+269) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = t_1 + (1.0 + t_1);
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) t_1 = -4.0 * ((y / x) / (x / y)) tmp = 0 if (x * x) <= 1e-296: tmp = (0.5 * ((x / y) / (y / x))) + -1.0 elif (x * x) <= 1e+269: tmp = ((x * x) - t_0) / ((x * x) + t_0) else: tmp = t_1 + (1.0 + t_1) return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) t_1 = Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y))) tmp = 0.0 if (Float64(x * x) <= 1e-296) tmp = Float64(Float64(0.5 * Float64(Float64(x / y) / Float64(y / x))) + -1.0); elseif (Float64(x * x) <= 1e+269) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = Float64(t_1 + Float64(1.0 + t_1)); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (y * 4.0); t_1 = -4.0 * ((y / x) / (x / y)); tmp = 0.0; if ((x * x) <= 1e-296) tmp = (0.5 * ((x / y) / (y / x))) + -1.0; elseif ((x * x) <= 1e+269) tmp = ((x * x) - t_0) / ((x * x) + t_0); else tmp = t_1 + (1.0 + t_1); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 1e-296], N[(N[(0.5 * N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1e+269], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(1.0 + t$95$1), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\mathbf{if}\;x \cdot x \leq 10^{-296}:\\
\;\;\;\;0.5 \cdot \frac{\frac{x}{y}}{\frac{y}{x}} + -1\\
\mathbf{elif}\;x \cdot x \leq 10^{+269}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;t_1 + \left(1 + t_1\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 1e-296Initial program 51.2%
Taylor expanded in x around 0 72.8%
fma-neg72.8%
unpow272.8%
unpow272.8%
times-frac87.5%
metadata-eval87.5%
Simplified87.5%
fma-udef87.5%
pow287.5%
Applied egg-rr87.5%
unpow287.5%
clear-num87.5%
un-div-inv87.5%
Applied egg-rr87.5%
if 1e-296 < (*.f64 x x) < 1e269Initial program 83.9%
if 1e269 < (*.f64 x x) Initial program 11.5%
clear-num11.5%
inv-pow11.5%
fma-def11.5%
*-commutative11.5%
sub-neg11.5%
+-commutative11.5%
*-commutative11.5%
distribute-rgt-neg-in11.5%
fma-def11.5%
distribute-rgt-neg-in11.5%
metadata-eval11.5%
Applied egg-rr11.5%
Taylor expanded in x around inf 82.1%
cancel-sign-sub-inv82.1%
metadata-eval82.1%
unpow282.1%
unpow282.1%
times-frac82.1%
unpow282.1%
unpow282.1%
unpow282.1%
times-frac88.4%
unpow288.4%
Simplified88.4%
unpow288.3%
clear-num88.3%
un-div-inv88.3%
Applied egg-rr88.4%
unpow288.3%
clear-num88.3%
un-div-inv88.3%
Applied egg-rr88.4%
Final simplification86.2%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= (* x x) 1e-296)
(+ (* 0.5 (/ (/ x y) (/ y x))) -1.0)
(if (<= (* x x) 1e+269)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if ((x * x) <= 1e-296) {
tmp = (0.5 * ((x / y) / (y / x))) + -1.0;
} else if ((x * x) <= 1e+269) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = y * (y * 4.0d0)
if ((x * x) <= 1d-296) then
tmp = (0.5d0 * ((x / y) / (y / x))) + (-1.0d0)
else if ((x * x) <= 1d+269) then
tmp = ((x * x) - t_0) / ((x * x) + t_0)
else
tmp = 1.0d0 + ((-4.0d0) * ((y / x) / (x / y)))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if ((x * x) <= 1e-296) {
tmp = (0.5 * ((x / y) / (y / x))) + -1.0;
} else if ((x * x) <= 1e+269) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) tmp = 0 if (x * x) <= 1e-296: tmp = (0.5 * ((x / y) / (y / x))) + -1.0 elif (x * x) <= 1e+269: tmp = ((x * x) - t_0) / ((x * x) + t_0) else: tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (Float64(x * x) <= 1e-296) tmp = Float64(Float64(0.5 * Float64(Float64(x / y) / Float64(y / x))) + -1.0); elseif (Float64(x * x) <= 1e+269) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (y * 4.0); tmp = 0.0; if ((x * x) <= 1e-296) tmp = (0.5 * ((x / y) / (y / x))) + -1.0; elseif ((x * x) <= 1e+269) tmp = ((x * x) - t_0) / ((x * x) + t_0); else tmp = 1.0 + (-4.0 * ((y / x) / (x / y))); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 1e-296], N[(N[(0.5 * N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1e+269], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;x \cdot x \leq 10^{-296}:\\
\;\;\;\;0.5 \cdot \frac{\frac{x}{y}}{\frac{y}{x}} + -1\\
\mathbf{elif}\;x \cdot x \leq 10^{+269}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 1e-296Initial program 51.2%
Taylor expanded in x around 0 72.8%
fma-neg72.8%
unpow272.8%
unpow272.8%
times-frac87.5%
metadata-eval87.5%
Simplified87.5%
fma-udef87.5%
pow287.5%
Applied egg-rr87.5%
unpow287.5%
clear-num87.5%
un-div-inv87.5%
Applied egg-rr87.5%
if 1e-296 < (*.f64 x x) < 1e269Initial program 83.9%
if 1e269 < (*.f64 x x) Initial program 11.5%
Taylor expanded in x around inf 11.6%
unpow211.6%
Simplified11.6%
Taylor expanded in x around inf 82.1%
unpow282.1%
unpow282.1%
times-frac88.3%
unpow288.3%
Simplified88.3%
unpow288.3%
clear-num88.3%
un-div-inv88.3%
Applied egg-rr88.3%
Final simplification86.2%
(FPCore (x y) :precision binary64 (if (<= (* x x) 5e-126) (+ (* 0.5 (/ (/ x y) (/ y x))) -1.0) (+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))))
double code(double x, double y) {
double tmp;
if ((x * x) <= 5e-126) {
tmp = (0.5 * ((x / y) / (y / x))) + -1.0;
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x * x) <= 5d-126) then
tmp = (0.5d0 * ((x / y) / (y / x))) + (-1.0d0)
else
tmp = 1.0d0 + ((-4.0d0) * ((y / x) / (x / y)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x * x) <= 5e-126) {
tmp = (0.5 * ((x / y) / (y / x))) + -1.0;
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 5e-126: tmp = (0.5 * ((x / y) / (y / x))) + -1.0 else: tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 5e-126) tmp = Float64(Float64(0.5 * Float64(Float64(x / y) / Float64(y / x))) + -1.0); else tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x * x) <= 5e-126) tmp = (0.5 * ((x / y) / (y / x))) + -1.0; else tmp = 1.0 + (-4.0 * ((y / x) / (x / y))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 5e-126], N[(N[(0.5 * N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-126}:\\
\;\;\;\;0.5 \cdot \frac{\frac{x}{y}}{\frac{y}{x}} + -1\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 5.00000000000000006e-126Initial program 61.0%
Taylor expanded in x around 0 71.4%
fma-neg71.4%
unpow271.4%
unpow271.4%
times-frac80.9%
metadata-eval80.9%
Simplified80.9%
fma-udef80.9%
pow280.9%
Applied egg-rr80.9%
unpow280.9%
clear-num80.9%
un-div-inv80.9%
Applied egg-rr80.9%
if 5.00000000000000006e-126 < (*.f64 x x) Initial program 48.3%
Taylor expanded in x around inf 37.6%
unpow237.6%
Simplified37.6%
Taylor expanded in x around inf 74.0%
unpow274.0%
unpow274.0%
times-frac77.2%
unpow277.2%
Simplified77.2%
unpow277.2%
clear-num77.2%
un-div-inv77.2%
Applied egg-rr77.2%
Final simplification78.7%
(FPCore (x y) :precision binary64 (if (<= x 5.5e-63) -1.0 (+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))))
double code(double x, double y) {
double tmp;
if (x <= 5.5e-63) {
tmp = -1.0;
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 5.5d-63) then
tmp = -1.0d0
else
tmp = 1.0d0 + ((-4.0d0) * ((y / x) / (x / y)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 5.5e-63) {
tmp = -1.0;
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 5.5e-63: tmp = -1.0 else: tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) return tmp
function code(x, y) tmp = 0.0 if (x <= 5.5e-63) tmp = -1.0; else tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 5.5e-63) tmp = -1.0; else tmp = 1.0 + (-4.0 * ((y / x) / (x / y))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 5.5e-63], -1.0, N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{-63}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if x < 5.50000000000000043e-63Initial program 56.1%
Taylor expanded in x around 0 52.6%
if 5.50000000000000043e-63 < x Initial program 46.4%
Taylor expanded in x around inf 32.9%
unpow232.9%
Simplified32.9%
Taylor expanded in x around inf 67.3%
unpow267.3%
unpow267.3%
times-frac71.0%
unpow271.0%
Simplified71.0%
unpow271.0%
clear-num71.0%
un-div-inv71.0%
Applied egg-rr71.0%
Final simplification57.7%
(FPCore (x y) :precision binary64 (if (<= x 5e-27) -1.0 1.0))
double code(double x, double y) {
double tmp;
if (x <= 5e-27) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 5d-27) then
tmp = -1.0d0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 5e-27) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 5e-27: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= 5e-27) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 5e-27) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 5e-27], -1.0, 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{-27}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 5.0000000000000002e-27Initial program 56.7%
Taylor expanded in x around 0 53.3%
if 5.0000000000000002e-27 < x Initial program 43.9%
Taylor expanded in x around inf 73.5%
Final simplification58.5%
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
return -1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
public static double code(double x, double y) {
return -1.0;
}
def code(x, y): return -1.0
function code(x, y) return -1.0 end
function tmp = code(x, y) tmp = -1.0; end
code[x_, y_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 53.4%
Taylor expanded in x around 0 46.2%
Final simplification46.2%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (* y y) 4.0))
(t_1 (+ (* x x) t_0))
(t_2 (/ t_0 t_1))
(t_3 (* (* y 4.0) y)))
(if (< (/ (- (* x x) t_3) (+ (* x x) t_3)) 0.9743233849626781)
(- (/ (* x x) t_1) t_2)
(- (pow (/ x (sqrt t_1)) 2.0) t_2))))
double code(double x, double y) {
double t_0 = (y * y) * 4.0;
double t_1 = (x * x) + t_0;
double t_2 = t_0 / t_1;
double t_3 = (y * 4.0) * y;
double tmp;
if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781) {
tmp = ((x * x) / t_1) - t_2;
} else {
tmp = pow((x / sqrt(t_1)), 2.0) - t_2;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = (y * y) * 4.0d0
t_1 = (x * x) + t_0
t_2 = t_0 / t_1
t_3 = (y * 4.0d0) * y
if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781d0) then
tmp = ((x * x) / t_1) - t_2
else
tmp = ((x / sqrt(t_1)) ** 2.0d0) - t_2
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y * y) * 4.0;
double t_1 = (x * x) + t_0;
double t_2 = t_0 / t_1;
double t_3 = (y * 4.0) * y;
double tmp;
if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781) {
tmp = ((x * x) / t_1) - t_2;
} else {
tmp = Math.pow((x / Math.sqrt(t_1)), 2.0) - t_2;
}
return tmp;
}
def code(x, y): t_0 = (y * y) * 4.0 t_1 = (x * x) + t_0 t_2 = t_0 / t_1 t_3 = (y * 4.0) * y tmp = 0 if (((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781: tmp = ((x * x) / t_1) - t_2 else: tmp = math.pow((x / math.sqrt(t_1)), 2.0) - t_2 return tmp
function code(x, y) t_0 = Float64(Float64(y * y) * 4.0) t_1 = Float64(Float64(x * x) + t_0) t_2 = Float64(t_0 / t_1) t_3 = Float64(Float64(y * 4.0) * y) tmp = 0.0 if (Float64(Float64(Float64(x * x) - t_3) / Float64(Float64(x * x) + t_3)) < 0.9743233849626781) tmp = Float64(Float64(Float64(x * x) / t_1) - t_2); else tmp = Float64((Float64(x / sqrt(t_1)) ^ 2.0) - t_2); end return tmp end
function tmp_2 = code(x, y) t_0 = (y * y) * 4.0; t_1 = (x * x) + t_0; t_2 = t_0 / t_1; t_3 = (y * 4.0) * y; tmp = 0.0; if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781) tmp = ((x * x) / t_1) - t_2; else tmp = ((x / sqrt(t_1)) ^ 2.0) - t_2; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * y), $MachinePrecision] * 4.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, If[Less[N[(N[(N[(x * x), $MachinePrecision] - t$95$3), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$3), $MachinePrecision]), $MachinePrecision], 0.9743233849626781], N[(N[(N[(x * x), $MachinePrecision] / t$95$1), $MachinePrecision] - t$95$2), $MachinePrecision], N[(N[Power[N[(x / N[Sqrt[t$95$1], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] - t$95$2), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot y\right) \cdot 4\\
t_1 := x \cdot x + t_0\\
t_2 := \frac{t_0}{t_1}\\
t_3 := \left(y \cdot 4\right) \cdot y\\
\mathbf{if}\;\frac{x \cdot x - t_3}{x \cdot x + t_3} < 0.9743233849626781:\\
\;\;\;\;\frac{x \cdot x}{t_1} - t_2\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{x}{\sqrt{t_1}}\right)}^{2} - t_2\\
\end{array}
\end{array}
herbie shell --seed 2023200
(FPCore (x y)
:name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
:precision binary64
:herbie-target
(if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))
(/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))