
(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 9 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))) (t_1 (/ (- (* x x) t_0) (+ (* x x) t_0))))
(if (<= (* x x) 5e-245)
(fma 0.5 (* (/ x y) (/ x y)) -1.0)
(if (<= (* x x) 2e-88)
t_1
(if (<= (* x x) 2e+90)
(+ -1.0 (/ (/ (* x (/ x y)) y) 4.0))
(if (<= (* x x) 4e+277)
t_1
(fma (* 3.0 (log (cbrt (+ 1.0 (pow (/ y x) 2.0))))) -8.0 1.0)))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
double tmp;
if ((x * x) <= 5e-245) {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
} else if ((x * x) <= 2e-88) {
tmp = t_1;
} else if ((x * x) <= 2e+90) {
tmp = -1.0 + (((x * (x / y)) / y) / 4.0);
} else if ((x * x) <= 4e+277) {
tmp = t_1;
} else {
tmp = fma((3.0 * log(cbrt((1.0 + pow((y / x), 2.0))))), -8.0, 1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) t_1 = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) tmp = 0.0 if (Float64(x * x) <= 5e-245) tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); elseif (Float64(x * x) <= 2e-88) tmp = t_1; elseif (Float64(x * x) <= 2e+90) tmp = Float64(-1.0 + Float64(Float64(Float64(x * Float64(x / y)) / y) / 4.0)); elseif (Float64(x * x) <= 4e+277) tmp = t_1; else tmp = fma(Float64(3.0 * log(cbrt(Float64(1.0 + (Float64(y / x) ^ 2.0))))), -8.0, 1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-245], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 2e-88], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 2e+90], N[(-1.0 + N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+277], t$95$1, N[(N[(3.0 * N[Log[N[Power[N[(1.0 + N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\
\;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\
\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3 \cdot \log \left(\sqrt[3]{1 + {\left(\frac{y}{x}\right)}^{2}}\right), -8, 1\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 4.9999999999999997e-245Initial program 48.1%
Taylor expanded in x around 0 75.5%
fma-neg75.5%
unpow275.5%
unpow275.5%
times-frac83.7%
metadata-eval83.7%
Simplified83.7%
if 4.9999999999999997e-245 < (*.f64 x x) < 1.99999999999999987e-88 or 1.99999999999999993e90 < (*.f64 x x) < 4.00000000000000001e277Initial program 83.0%
if 1.99999999999999987e-88 < (*.f64 x x) < 1.99999999999999993e90Initial program 60.6%
Taylor expanded in x around 0 34.5%
*-commutative34.5%
unpow234.5%
associate-*r*34.5%
Simplified34.5%
div-sub33.9%
associate-*r*33.9%
associate-/r*33.9%
frac-times33.9%
pow233.9%
*-commutative33.9%
*-inverses73.9%
Applied egg-rr73.9%
unpow273.9%
associate-*r/73.9%
Applied egg-rr73.9%
if 4.00000000000000001e277 < (*.f64 x x) Initial program 8.4%
Taylor expanded in x around inf 82.0%
associate--l+82.0%
distribute-rgt-out--82.0%
metadata-eval82.0%
*-commutative82.0%
+-commutative82.0%
*-commutative82.0%
fma-def82.0%
unpow282.0%
unpow282.0%
times-frac89.1%
Simplified89.1%
add-log-exp88.8%
pow288.8%
Applied egg-rr88.8%
Taylor expanded in y around 0 82.0%
unpow282.0%
unpow282.0%
times-frac89.8%
unpow289.8%
Simplified89.8%
add-cube-cbrt89.8%
log-prod89.8%
pow289.8%
Applied egg-rr89.8%
log-pow89.8%
distribute-lft1-in89.8%
metadata-eval89.8%
Simplified89.8%
Final simplification84.3%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))) (t_1 (/ (- (* x x) t_0) (+ (* x x) t_0))))
(if (<= (* x x) 5e-245)
(fma 0.5 (* (/ x y) (/ x y)) -1.0)
(if (<= (* x x) 2e-88)
t_1
(if (<= (* x x) 2e+90)
(+ -1.0 (/ (/ (* x (/ x y)) y) 4.0))
(if (<= (* x x) 4e+277)
t_1
(fma (log (+ 1.0 (/ (/ y x) (/ x y)))) -8.0 1.0)))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
double tmp;
if ((x * x) <= 5e-245) {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
} else if ((x * x) <= 2e-88) {
tmp = t_1;
} else if ((x * x) <= 2e+90) {
tmp = -1.0 + (((x * (x / y)) / y) / 4.0);
} else if ((x * x) <= 4e+277) {
tmp = t_1;
} else {
tmp = fma(log((1.0 + ((y / x) / (x / y)))), -8.0, 1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) t_1 = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) tmp = 0.0 if (Float64(x * x) <= 5e-245) tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); elseif (Float64(x * x) <= 2e-88) tmp = t_1; elseif (Float64(x * x) <= 2e+90) tmp = Float64(-1.0 + Float64(Float64(Float64(x * Float64(x / y)) / y) / 4.0)); elseif (Float64(x * x) <= 4e+277) tmp = t_1; else tmp = fma(log(Float64(1.0 + Float64(Float64(y / x) / Float64(x / y)))), -8.0, 1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-245], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 2e-88], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 2e+90], N[(-1.0 + N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+277], t$95$1, N[(N[Log[N[(1.0 + N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * -8.0 + 1.0), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\
\;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\
\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log \left(1 + \frac{\frac{y}{x}}{\frac{x}{y}}\right), -8, 1\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 4.9999999999999997e-245Initial program 48.1%
Taylor expanded in x around 0 75.5%
fma-neg75.5%
unpow275.5%
unpow275.5%
times-frac83.7%
metadata-eval83.7%
Simplified83.7%
if 4.9999999999999997e-245 < (*.f64 x x) < 1.99999999999999987e-88 or 1.99999999999999993e90 < (*.f64 x x) < 4.00000000000000001e277Initial program 83.0%
if 1.99999999999999987e-88 < (*.f64 x x) < 1.99999999999999993e90Initial program 60.6%
Taylor expanded in x around 0 34.5%
*-commutative34.5%
unpow234.5%
associate-*r*34.5%
Simplified34.5%
div-sub33.9%
associate-*r*33.9%
associate-/r*33.9%
frac-times33.9%
pow233.9%
*-commutative33.9%
*-inverses73.9%
Applied egg-rr73.9%
unpow273.9%
associate-*r/73.9%
Applied egg-rr73.9%
if 4.00000000000000001e277 < (*.f64 x x) Initial program 8.4%
Taylor expanded in x around inf 82.0%
associate--l+82.0%
distribute-rgt-out--82.0%
metadata-eval82.0%
*-commutative82.0%
+-commutative82.0%
*-commutative82.0%
fma-def82.0%
unpow282.0%
unpow282.0%
times-frac89.1%
Simplified89.1%
add-log-exp88.8%
pow288.8%
Applied egg-rr88.8%
Taylor expanded in y around 0 82.0%
unpow282.0%
unpow282.0%
times-frac89.8%
unpow289.8%
Simplified89.8%
unpow289.0%
clear-num89.0%
un-div-inv89.0%
Applied egg-rr89.8%
Final simplification84.3%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))) (t_1 (/ (- (* x x) t_0) (+ (* x x) t_0))))
(if (<= (* x x) 5e-245)
(fma 0.5 (* (/ x y) (/ x y)) -1.0)
(if (<= (* x x) 2e-88)
t_1
(if (<= (* x x) 2e+90)
(+ -1.0 (/ (/ (* x (/ x y)) y) 4.0))
(if (<= (* x x) 4e+277) t_1 (fma (* (/ y x) (/ y x)) -8.0 1.0)))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
double tmp;
if ((x * x) <= 5e-245) {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
} else if ((x * x) <= 2e-88) {
tmp = t_1;
} else if ((x * x) <= 2e+90) {
tmp = -1.0 + (((x * (x / y)) / y) / 4.0);
} else if ((x * x) <= 4e+277) {
tmp = t_1;
} 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)) t_1 = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) tmp = 0.0 if (Float64(x * x) <= 5e-245) tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); elseif (Float64(x * x) <= 2e-88) tmp = t_1; elseif (Float64(x * x) <= 2e+90) tmp = Float64(-1.0 + Float64(Float64(Float64(x * Float64(x / y)) / y) / 4.0)); elseif (Float64(x * x) <= 4e+277) tmp = t_1; 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]}, Block[{t$95$1 = N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-245], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 2e-88], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 2e+90], N[(-1.0 + N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+277], t$95$1, 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)\\
t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\
\;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\
\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 4.9999999999999997e-245Initial program 48.1%
Taylor expanded in x around 0 75.5%
fma-neg75.5%
unpow275.5%
unpow275.5%
times-frac83.7%
metadata-eval83.7%
Simplified83.7%
if 4.9999999999999997e-245 < (*.f64 x x) < 1.99999999999999987e-88 or 1.99999999999999993e90 < (*.f64 x x) < 4.00000000000000001e277Initial program 83.0%
if 1.99999999999999987e-88 < (*.f64 x x) < 1.99999999999999993e90Initial program 60.6%
Taylor expanded in x around 0 34.5%
*-commutative34.5%
unpow234.5%
associate-*r*34.5%
Simplified34.5%
div-sub33.9%
associate-*r*33.9%
associate-/r*33.9%
frac-times33.9%
pow233.9%
*-commutative33.9%
*-inverses73.9%
Applied egg-rr73.9%
unpow273.9%
associate-*r/73.9%
Applied egg-rr73.9%
if 4.00000000000000001e277 < (*.f64 x x) Initial program 8.4%
Taylor expanded in x around inf 82.0%
associate--l+82.0%
distribute-rgt-out--82.0%
metadata-eval82.0%
*-commutative82.0%
+-commutative82.0%
*-commutative82.0%
fma-def82.0%
unpow282.0%
unpow282.0%
times-frac89.1%
Simplified89.1%
Final simplification84.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))) (t_1 (/ (- (* x x) t_0) (+ (* x x) t_0))))
(if (<= (* x x) 5e-245)
(fma 0.5 (* (/ x y) (/ x y)) -1.0)
(if (<= (* x x) 2e-88)
t_1
(if (<= (* x x) 2e+90)
(+ -1.0 (/ (/ (* x (/ x y)) y) 4.0))
(if (<= (* x x) 4e+277) t_1 (+ 1.0 (* (/ (/ y x) (/ x y)) -4.0))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
double tmp;
if ((x * x) <= 5e-245) {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
} else if ((x * x) <= 2e-88) {
tmp = t_1;
} else if ((x * x) <= 2e+90) {
tmp = -1.0 + (((x * (x / y)) / y) / 4.0);
} else if ((x * x) <= 4e+277) {
tmp = t_1;
} else {
tmp = 1.0 + (((y / x) / (x / y)) * -4.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) t_1 = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) tmp = 0.0 if (Float64(x * x) <= 5e-245) tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); elseif (Float64(x * x) <= 2e-88) tmp = t_1; elseif (Float64(x * x) <= 2e+90) tmp = Float64(-1.0 + Float64(Float64(Float64(x * Float64(x / y)) / y) / 4.0)); elseif (Float64(x * x) <= 4e+277) tmp = t_1; else tmp = Float64(1.0 + Float64(Float64(Float64(y / x) / Float64(x / y)) * -4.0)); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-245], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 2e-88], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 2e+90], N[(-1.0 + N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+277], t$95$1, N[(1.0 + N[(N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\
\;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\
\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{\frac{y}{x}}{\frac{x}{y}} \cdot -4\\
\end{array}
\end{array}
if (*.f64 x x) < 4.9999999999999997e-245Initial program 48.1%
Taylor expanded in x around 0 75.5%
fma-neg75.5%
unpow275.5%
unpow275.5%
times-frac83.7%
metadata-eval83.7%
Simplified83.7%
if 4.9999999999999997e-245 < (*.f64 x x) < 1.99999999999999987e-88 or 1.99999999999999993e90 < (*.f64 x x) < 4.00000000000000001e277Initial program 83.0%
if 1.99999999999999987e-88 < (*.f64 x x) < 1.99999999999999993e90Initial program 60.6%
Taylor expanded in x around 0 34.5%
*-commutative34.5%
unpow234.5%
associate-*r*34.5%
Simplified34.5%
div-sub33.9%
associate-*r*33.9%
associate-/r*33.9%
frac-times33.9%
pow233.9%
*-commutative33.9%
*-inverses73.9%
Applied egg-rr73.9%
unpow273.9%
associate-*r/73.9%
Applied egg-rr73.9%
if 4.00000000000000001e277 < (*.f64 x x) Initial program 8.4%
Taylor expanded in x around inf 8.5%
unpow28.5%
Simplified8.5%
Taylor expanded in x around inf 82.0%
unpow282.0%
unpow282.0%
times-frac89.0%
unpow289.0%
Simplified89.0%
unpow289.0%
clear-num89.0%
un-div-inv89.0%
Applied egg-rr89.0%
Final simplification84.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0)))
(t_1 (/ (- (* x x) t_0) (+ (* x x) t_0)))
(t_2 (+ -1.0 (/ (/ (* x (/ x y)) y) 4.0))))
(if (<= (* x x) 5e-245)
t_2
(if (<= (* x x) 2e-88)
t_1
(if (<= (* x x) 2e+90)
t_2
(if (<= (* x x) 4e+277) t_1 (+ 1.0 (* (/ (/ y x) (/ x y)) -4.0))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
double t_2 = -1.0 + (((x * (x / y)) / y) / 4.0);
double tmp;
if ((x * x) <= 5e-245) {
tmp = t_2;
} else if ((x * x) <= 2e-88) {
tmp = t_1;
} else if ((x * x) <= 2e+90) {
tmp = t_2;
} else if ((x * x) <= 4e+277) {
tmp = t_1;
} else {
tmp = 1.0 + (((y / x) / (x / y)) * -4.0);
}
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) :: tmp
t_0 = y * (y * 4.0d0)
t_1 = ((x * x) - t_0) / ((x * x) + t_0)
t_2 = (-1.0d0) + (((x * (x / y)) / y) / 4.0d0)
if ((x * x) <= 5d-245) then
tmp = t_2
else if ((x * x) <= 2d-88) then
tmp = t_1
else if ((x * x) <= 2d+90) then
tmp = t_2
else if ((x * x) <= 4d+277) then
tmp = t_1
else
tmp = 1.0d0 + (((y / x) / (x / y)) * (-4.0d0))
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) / ((x * x) + t_0);
double t_2 = -1.0 + (((x * (x / y)) / y) / 4.0);
double tmp;
if ((x * x) <= 5e-245) {
tmp = t_2;
} else if ((x * x) <= 2e-88) {
tmp = t_1;
} else if ((x * x) <= 2e+90) {
tmp = t_2;
} else if ((x * x) <= 4e+277) {
tmp = t_1;
} else {
tmp = 1.0 + (((y / x) / (x / y)) * -4.0);
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) t_1 = ((x * x) - t_0) / ((x * x) + t_0) t_2 = -1.0 + (((x * (x / y)) / y) / 4.0) tmp = 0 if (x * x) <= 5e-245: tmp = t_2 elif (x * x) <= 2e-88: tmp = t_1 elif (x * x) <= 2e+90: tmp = t_2 elif (x * x) <= 4e+277: tmp = t_1 else: tmp = 1.0 + (((y / x) / (x / y)) * -4.0) return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) t_1 = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) t_2 = Float64(-1.0 + Float64(Float64(Float64(x * Float64(x / y)) / y) / 4.0)) tmp = 0.0 if (Float64(x * x) <= 5e-245) tmp = t_2; elseif (Float64(x * x) <= 2e-88) tmp = t_1; elseif (Float64(x * x) <= 2e+90) tmp = t_2; elseif (Float64(x * x) <= 4e+277) tmp = t_1; else tmp = Float64(1.0 + Float64(Float64(Float64(y / x) / Float64(x / y)) * -4.0)); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (y * 4.0); t_1 = ((x * x) - t_0) / ((x * x) + t_0); t_2 = -1.0 + (((x * (x / y)) / y) / 4.0); tmp = 0.0; if ((x * x) <= 5e-245) tmp = t_2; elseif ((x * x) <= 2e-88) tmp = t_1; elseif ((x * x) <= 2e+90) tmp = t_2; elseif ((x * x) <= 4e+277) tmp = t_1; else tmp = 1.0 + (((y / x) / (x / y)) * -4.0); 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[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(-1.0 + N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 5e-245], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 2e-88], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 2e+90], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 4e+277], t$95$1, N[(1.0 + N[(N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
t_2 := -1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-245}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-88}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+90}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+277}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{\frac{y}{x}}{\frac{x}{y}} \cdot -4\\
\end{array}
\end{array}
if (*.f64 x x) < 4.9999999999999997e-245 or 1.99999999999999987e-88 < (*.f64 x x) < 1.99999999999999993e90Initial program 51.7%
Taylor expanded in x around 0 40.6%
*-commutative40.6%
unpow240.6%
associate-*r*40.7%
Simplified40.7%
div-sub40.4%
associate-*r*40.4%
associate-/r*40.4%
frac-times40.4%
pow240.4%
*-commutative40.4%
*-inverses80.8%
Applied egg-rr80.8%
unpow280.8%
associate-*r/80.8%
Applied egg-rr80.8%
if 4.9999999999999997e-245 < (*.f64 x x) < 1.99999999999999987e-88 or 1.99999999999999993e90 < (*.f64 x x) < 4.00000000000000001e277Initial program 83.0%
if 4.00000000000000001e277 < (*.f64 x x) Initial program 8.4%
Taylor expanded in x around inf 8.5%
unpow28.5%
Simplified8.5%
Taylor expanded in x around inf 82.0%
unpow282.0%
unpow282.0%
times-frac89.0%
unpow289.0%
Simplified89.0%
unpow289.0%
clear-num89.0%
un-div-inv89.0%
Applied egg-rr89.0%
Final simplification84.0%
(FPCore (x y) :precision binary64 (if (<= (* x x) 2e+101) (+ -1.0 (/ (/ (* x (/ x y)) y) 4.0)) (+ 1.0 (* (/ (/ y x) (/ x y)) -4.0))))
double code(double x, double y) {
double tmp;
if ((x * x) <= 2e+101) {
tmp = -1.0 + (((x * (x / y)) / y) / 4.0);
} else {
tmp = 1.0 + (((y / x) / (x / y)) * -4.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x * x) <= 2d+101) then
tmp = (-1.0d0) + (((x * (x / y)) / y) / 4.0d0)
else
tmp = 1.0d0 + (((y / x) / (x / y)) * (-4.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x * x) <= 2e+101) {
tmp = -1.0 + (((x * (x / y)) / y) / 4.0);
} else {
tmp = 1.0 + (((y / x) / (x / y)) * -4.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 2e+101: tmp = -1.0 + (((x * (x / y)) / y) / 4.0) else: tmp = 1.0 + (((y / x) / (x / y)) * -4.0) return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 2e+101) tmp = Float64(-1.0 + Float64(Float64(Float64(x * Float64(x / y)) / y) / 4.0)); else tmp = Float64(1.0 + Float64(Float64(Float64(y / x) / Float64(x / y)) * -4.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x * x) <= 2e+101) tmp = -1.0 + (((x * (x / y)) / y) / 4.0); else tmp = 1.0 + (((y / x) / (x / y)) * -4.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e+101], N[(-1.0 + N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+101}:\\
\;\;\;\;-1 + \frac{\frac{x \cdot \frac{x}{y}}{y}}{4}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{\frac{y}{x}}{\frac{x}{y}} \cdot -4\\
\end{array}
\end{array}
if (*.f64 x x) < 2e101Initial program 58.7%
Taylor expanded in x around 0 41.2%
*-commutative41.2%
unpow241.2%
associate-*r*41.2%
Simplified41.2%
div-sub40.9%
associate-*r*40.9%
associate-/r*40.9%
frac-times40.9%
pow240.9%
*-commutative40.9%
*-inverses76.0%
Applied egg-rr76.0%
unpow276.0%
associate-*r/76.0%
Applied egg-rr76.0%
if 2e101 < (*.f64 x x) Initial program 27.4%
Taylor expanded in x around inf 25.1%
unpow225.1%
Simplified25.1%
Taylor expanded in x around inf 79.3%
unpow279.3%
unpow279.3%
times-frac84.4%
unpow284.4%
Simplified84.4%
unpow284.4%
clear-num84.4%
un-div-inv84.4%
Applied egg-rr84.4%
Final simplification79.7%
(FPCore (x y) :precision binary64 (if (<= x 3.6e+50) -1.0 (+ 1.0 (* (/ (/ y x) (/ x y)) -4.0))))
double code(double x, double y) {
double tmp;
if (x <= 3.6e+50) {
tmp = -1.0;
} else {
tmp = 1.0 + (((y / x) / (x / y)) * -4.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 3.6d+50) then
tmp = -1.0d0
else
tmp = 1.0d0 + (((y / x) / (x / y)) * (-4.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 3.6e+50) {
tmp = -1.0;
} else {
tmp = 1.0 + (((y / x) / (x / y)) * -4.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 3.6e+50: tmp = -1.0 else: tmp = 1.0 + (((y / x) / (x / y)) * -4.0) return tmp
function code(x, y) tmp = 0.0 if (x <= 3.6e+50) tmp = -1.0; else tmp = Float64(1.0 + Float64(Float64(Float64(y / x) / Float64(x / y)) * -4.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 3.6e+50) tmp = -1.0; else tmp = 1.0 + (((y / x) / (x / y)) * -4.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 3.6e+50], -1.0, N[(1.0 + N[(N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.6 \cdot 10^{+50}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{\frac{y}{x}}{\frac{x}{y}} \cdot -4\\
\end{array}
\end{array}
if x < 3.59999999999999986e50Initial program 50.2%
Taylor expanded in x around 0 58.7%
if 3.59999999999999986e50 < x Initial program 25.5%
Taylor expanded in x around inf 23.8%
unpow223.8%
Simplified23.8%
Taylor expanded in x around inf 80.3%
unpow280.3%
unpow280.3%
times-frac88.0%
unpow288.0%
Simplified88.0%
unpow288.0%
clear-num88.0%
un-div-inv88.0%
Applied egg-rr88.0%
Final simplification65.0%
(FPCore (x y) :precision binary64 (if (<= x 1e+51) -1.0 1.0))
double code(double x, double y) {
double tmp;
if (x <= 1e+51) {
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 <= 1d+51) 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 <= 1e+51) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1e+51: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= 1e+51) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1e+51) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1e+51], -1.0, 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+51}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1e51Initial program 50.2%
Taylor expanded in x around 0 58.7%
if 1e51 < x Initial program 25.5%
Taylor expanded in x around inf 87.5%
Final simplification64.9%
(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 44.9%
Taylor expanded in x around 0 49.1%
Final simplification49.1%
(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 2023215
(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))))