
(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
(/ (fma -4.0 (* y (/ y x)) x) (+ x (* x (pow (/ y (/ x 2.0)) 2.0))))))
(if (<= t_0 1000000.0)
t_1
(if (<= t_0 5e+102)
(/ (- (* x x) t_0) (+ t_0 (* x x)))
(if (<= t_0 2e+261) t_1 (+ -1.0 (/ 0.5 (pow (/ y x) 2.0))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = fma(-4.0, (y * (y / x)), x) / (x + (x * pow((y / (x / 2.0)), 2.0)));
double tmp;
if (t_0 <= 1000000.0) {
tmp = t_1;
} else if (t_0 <= 5e+102) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} else if (t_0 <= 2e+261) {
tmp = t_1;
} else {
tmp = -1.0 + (0.5 / pow((y / x), 2.0));
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) t_1 = Float64(fma(-4.0, Float64(y * Float64(y / x)), x) / Float64(x + Float64(x * (Float64(y / Float64(x / 2.0)) ^ 2.0)))) tmp = 0.0 if (t_0 <= 1000000.0) tmp = t_1; elseif (t_0 <= 5e+102) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(t_0 + Float64(x * x))); elseif (t_0 <= 2e+261) tmp = t_1; else tmp = Float64(-1.0 + Float64(0.5 / (Float64(y / x) ^ 2.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[(-4.0 * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] / N[(x + N[(x * N[Power[N[(y / N[(x / 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1000000.0], t$95$1, If[LessEqual[t$95$0, 5e+102], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+261], t$95$1, N[(-1.0 + N[(0.5 / N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := \frac{\mathsf{fma}\left(-4, y \cdot \frac{y}{x}, x\right)}{x + x \cdot {\left(\frac{y}{\frac{x}{2}}\right)}^{2}}\\
\mathbf{if}\;t_0 \leq 1000000:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+102}:\\
\;\;\;\;\frac{x \cdot x - t_0}{t_0 + x \cdot x}\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+261}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;-1 + \frac{0.5}{{\left(\frac{y}{x}\right)}^{2}}\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 1e6 or 5e102 < (*.f64 (*.f64 y 4) y) < 1.9999999999999999e261Initial program 65.8%
Taylor expanded in x around inf 53.7%
cancel-sign-sub-inv53.7%
unpow253.7%
associate-*r/53.7%
*-commutative53.7%
unpow253.7%
associate-*r*53.7%
metadata-eval53.7%
unpow253.7%
associate-*r/53.7%
*-commutative53.7%
unpow253.7%
associate-*r*53.7%
Simplified53.7%
div-inv53.7%
add-sqr-sqrt24.1%
sqrt-unprod53.2%
swap-sqr53.2%
metadata-eval53.2%
metadata-eval53.2%
swap-sqr53.2%
sqrt-unprod29.1%
add-sqr-sqrt52.4%
associate-*r*52.4%
metadata-eval52.4%
distribute-rgt-neg-in52.4%
associate-*r*52.4%
cancel-sign-sub-inv52.4%
div-inv52.4%
Applied egg-rr59.9%
*-commutative59.9%
distribute-lft-in59.9%
*-rgt-identity59.9%
associate-/l*59.9%
associate-/l*60.6%
+-commutative60.6%
associate-/l*60.6%
*-commutative60.6%
distribute-lft-in60.6%
Simplified60.6%
expm1-log1p-u58.7%
expm1-udef58.7%
pow-pow58.7%
div-inv58.7%
metadata-eval58.7%
metadata-eval58.7%
Applied egg-rr58.7%
expm1-def58.8%
expm1-log1p60.6%
Simplified60.6%
Taylor expanded in x around 0 82.1%
fma-def82.1%
unpow282.1%
associate-*r/89.6%
Simplified89.6%
if 1e6 < (*.f64 (*.f64 y 4) y) < 5e102Initial program 95.0%
if 1.9999999999999999e261 < (*.f64 (*.f64 y 4) y) Initial program 14.8%
Taylor expanded in x around inf 4.9%
cancel-sign-sub-inv4.9%
unpow24.9%
associate-*r/4.9%
*-commutative4.9%
unpow24.9%
associate-*r*4.9%
metadata-eval4.9%
unpow24.9%
associate-*r/4.9%
*-commutative4.9%
unpow24.9%
associate-*r*4.9%
Simplified4.9%
div-inv4.9%
add-sqr-sqrt2.6%
sqrt-unprod3.9%
swap-sqr3.9%
metadata-eval3.9%
metadata-eval3.9%
swap-sqr3.9%
sqrt-unprod1.3%
add-sqr-sqrt2.6%
associate-*r*2.6%
metadata-eval2.6%
distribute-rgt-neg-in2.6%
associate-*r*2.6%
cancel-sign-sub-inv2.6%
div-inv2.6%
Applied egg-rr2.7%
*-commutative2.7%
distribute-lft-in2.7%
*-rgt-identity2.7%
associate-/l*2.7%
associate-/l*14.8%
+-commutative14.8%
associate-/l*14.8%
*-commutative14.8%
distribute-lft-in14.8%
Simplified14.8%
expm1-log1p-u4.7%
expm1-udef4.7%
pow-pow4.7%
div-inv4.7%
metadata-eval4.7%
metadata-eval4.7%
Applied egg-rr4.7%
expm1-def4.7%
expm1-log1p14.9%
Simplified14.9%
Taylor expanded in x around 0 76.6%
sub-neg76.6%
metadata-eval76.6%
+-commutative76.6%
associate-*r/76.6%
associate-/l*76.6%
unpow276.6%
unpow276.6%
times-frac87.1%
unpow287.1%
Simplified87.1%
Final simplification89.2%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= (* x x) 1e-220)
(+ -1.0 (/ 0.5 (pow (/ y x) 2.0)))
(if (<= (* x x) 5e+131)
(/ (- (* x x) t_0) (+ t_0 (* x x)))
(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 tmp;
if ((x * x) <= 1e-220) {
tmp = -1.0 + (0.5 / pow((y / x), 2.0));
} else if ((x * x) <= 5e+131) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} 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)) tmp = 0.0 if (Float64(x * x) <= 1e-220) tmp = Float64(-1.0 + Float64(0.5 / (Float64(y / x) ^ 2.0))); elseif (Float64(x * x) <= 5e+131) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(t_0 + Float64(x * x))); 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]}, If[LessEqual[N[(x * x), $MachinePrecision], 1e-220], N[(-1.0 + N[(0.5 / N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 5e+131], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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)\\
\mathbf{if}\;x \cdot x \leq 10^{-220}:\\
\;\;\;\;-1 + \frac{0.5}{{\left(\frac{y}{x}\right)}^{2}}\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+131}:\\
\;\;\;\;\frac{x \cdot x - t_0}{t_0 + x \cdot x}\\
\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) < 9.99999999999999992e-221Initial program 51.9%
Taylor expanded in x around inf 3.6%
cancel-sign-sub-inv3.6%
unpow23.6%
associate-*r/3.6%
*-commutative3.6%
unpow23.6%
associate-*r*3.6%
metadata-eval3.6%
unpow23.6%
associate-*r/3.6%
*-commutative3.6%
unpow23.6%
associate-*r*3.6%
Simplified3.6%
div-inv3.6%
add-sqr-sqrt1.4%
sqrt-unprod2.5%
swap-sqr2.5%
metadata-eval2.5%
metadata-eval2.5%
swap-sqr2.5%
sqrt-unprod1.0%
add-sqr-sqrt1.2%
associate-*r*1.2%
metadata-eval1.2%
distribute-rgt-neg-in1.2%
associate-*r*1.2%
cancel-sign-sub-inv1.2%
div-inv1.2%
Applied egg-rr11.3%
*-commutative11.3%
distribute-lft-in11.3%
*-rgt-identity11.3%
associate-/l*11.3%
associate-/l*12.3%
+-commutative12.3%
associate-/l*12.3%
*-commutative12.3%
distribute-lft-in12.3%
Simplified12.3%
expm1-log1p-u12.2%
expm1-udef12.1%
pow-pow12.1%
div-inv12.1%
metadata-eval12.1%
metadata-eval12.1%
Applied egg-rr12.1%
expm1-def12.2%
expm1-log1p12.3%
Simplified12.3%
Taylor expanded in x around 0 79.3%
sub-neg79.3%
metadata-eval79.3%
+-commutative79.3%
associate-*r/79.3%
associate-/l*79.3%
unpow279.3%
unpow279.3%
times-frac89.5%
unpow289.5%
Simplified89.5%
if 9.99999999999999992e-221 < (*.f64 x x) < 4.99999999999999995e131Initial program 83.6%
if 4.99999999999999995e131 < (*.f64 x x) Initial program 26.5%
Taylor expanded in x around inf 69.0%
associate--l+69.0%
distribute-rgt-out--69.0%
metadata-eval69.0%
*-commutative69.0%
+-commutative69.0%
*-commutative69.0%
fma-def69.0%
unpow269.0%
unpow269.0%
times-frac79.6%
Simplified79.6%
add-log-exp79.1%
pow279.1%
Applied egg-rr79.1%
Taylor expanded in y around 0 69.0%
unpow269.0%
unpow269.0%
times-frac80.7%
unpow280.7%
Simplified80.7%
unpow278.5%
clear-num78.5%
un-div-inv78.5%
Applied egg-rr80.7%
Final simplification85.1%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= (* x x) 1e-220)
(+ -1.0 (/ 0.5 (pow (/ y x) 2.0)))
(if (<= (* x x) 5e+131)
(/ (- (* x x) t_0) (+ t_0 (* x x)))
(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-220) {
tmp = -1.0 + (0.5 / pow((y / x), 2.0));
} else if ((x * x) <= 5e+131) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} 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-220) tmp = Float64(-1.0 + Float64(0.5 / (Float64(y / x) ^ 2.0))); elseif (Float64(x * x) <= 5e+131) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(t_0 + Float64(x * x))); 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-220], N[(-1.0 + N[(0.5 / N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 5e+131], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $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^{-220}:\\
\;\;\;\;-1 + \frac{0.5}{{\left(\frac{y}{x}\right)}^{2}}\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+131}:\\
\;\;\;\;\frac{x \cdot x - t_0}{t_0 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 9.99999999999999992e-221Initial program 51.9%
Taylor expanded in x around inf 3.6%
cancel-sign-sub-inv3.6%
unpow23.6%
associate-*r/3.6%
*-commutative3.6%
unpow23.6%
associate-*r*3.6%
metadata-eval3.6%
unpow23.6%
associate-*r/3.6%
*-commutative3.6%
unpow23.6%
associate-*r*3.6%
Simplified3.6%
div-inv3.6%
add-sqr-sqrt1.4%
sqrt-unprod2.5%
swap-sqr2.5%
metadata-eval2.5%
metadata-eval2.5%
swap-sqr2.5%
sqrt-unprod1.0%
add-sqr-sqrt1.2%
associate-*r*1.2%
metadata-eval1.2%
distribute-rgt-neg-in1.2%
associate-*r*1.2%
cancel-sign-sub-inv1.2%
div-inv1.2%
Applied egg-rr11.3%
*-commutative11.3%
distribute-lft-in11.3%
*-rgt-identity11.3%
associate-/l*11.3%
associate-/l*12.3%
+-commutative12.3%
associate-/l*12.3%
*-commutative12.3%
distribute-lft-in12.3%
Simplified12.3%
expm1-log1p-u12.2%
expm1-udef12.1%
pow-pow12.1%
div-inv12.1%
metadata-eval12.1%
metadata-eval12.1%
Applied egg-rr12.1%
expm1-def12.2%
expm1-log1p12.3%
Simplified12.3%
Taylor expanded in x around 0 79.3%
sub-neg79.3%
metadata-eval79.3%
+-commutative79.3%
associate-*r/79.3%
associate-/l*79.3%
unpow279.3%
unpow279.3%
times-frac89.5%
unpow289.5%
Simplified89.5%
if 9.99999999999999992e-221 < (*.f64 x x) < 4.99999999999999995e131Initial program 83.6%
if 4.99999999999999995e131 < (*.f64 x x) Initial program 26.5%
Taylor expanded in x around inf 69.0%
associate--l+69.0%
distribute-rgt-out--69.0%
metadata-eval69.0%
*-commutative69.0%
+-commutative69.0%
*-commutative69.0%
fma-def69.0%
unpow269.0%
unpow269.0%
times-frac79.6%
Simplified79.6%
Final simplification84.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= (* x x) 1e-220)
(+ -1.0 (/ 0.5 (pow (/ y x) 2.0)))
(if (<= (* x x) 1e+271)
(/ (- (* x x) t_0) (+ t_0 (* x x)))
(+ 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-220) {
tmp = -1.0 + (0.5 / pow((y / x), 2.0));
} else if ((x * x) <= 1e+271) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} 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-220) then
tmp = (-1.0d0) + (0.5d0 / ((y / x) ** 2.0d0))
else if ((x * x) <= 1d+271) then
tmp = ((x * x) - t_0) / (t_0 + (x * x))
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-220) {
tmp = -1.0 + (0.5 / Math.pow((y / x), 2.0));
} else if ((x * x) <= 1e+271) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} 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-220: tmp = -1.0 + (0.5 / math.pow((y / x), 2.0)) elif (x * x) <= 1e+271: tmp = ((x * x) - t_0) / (t_0 + (x * x)) 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-220) tmp = Float64(-1.0 + Float64(0.5 / (Float64(y / x) ^ 2.0))); elseif (Float64(x * x) <= 1e+271) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(t_0 + Float64(x * x))); 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-220) tmp = -1.0 + (0.5 / ((y / x) ^ 2.0)); elseif ((x * x) <= 1e+271) tmp = ((x * x) - t_0) / (t_0 + (x * x)); 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-220], N[(-1.0 + N[(0.5 / N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1e+271], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $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^{-220}:\\
\;\;\;\;-1 + \frac{0.5}{{\left(\frac{y}{x}\right)}^{2}}\\
\mathbf{elif}\;x \cdot x \leq 10^{+271}:\\
\;\;\;\;\frac{x \cdot x - t_0}{t_0 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 9.99999999999999992e-221Initial program 51.9%
Taylor expanded in x around inf 3.6%
cancel-sign-sub-inv3.6%
unpow23.6%
associate-*r/3.6%
*-commutative3.6%
unpow23.6%
associate-*r*3.6%
metadata-eval3.6%
unpow23.6%
associate-*r/3.6%
*-commutative3.6%
unpow23.6%
associate-*r*3.6%
Simplified3.6%
div-inv3.6%
add-sqr-sqrt1.4%
sqrt-unprod2.5%
swap-sqr2.5%
metadata-eval2.5%
metadata-eval2.5%
swap-sqr2.5%
sqrt-unprod1.0%
add-sqr-sqrt1.2%
associate-*r*1.2%
metadata-eval1.2%
distribute-rgt-neg-in1.2%
associate-*r*1.2%
cancel-sign-sub-inv1.2%
div-inv1.2%
Applied egg-rr11.3%
*-commutative11.3%
distribute-lft-in11.3%
*-rgt-identity11.3%
associate-/l*11.3%
associate-/l*12.3%
+-commutative12.3%
associate-/l*12.3%
*-commutative12.3%
distribute-lft-in12.3%
Simplified12.3%
expm1-log1p-u12.2%
expm1-udef12.1%
pow-pow12.1%
div-inv12.1%
metadata-eval12.1%
metadata-eval12.1%
Applied egg-rr12.1%
expm1-def12.2%
expm1-log1p12.3%
Simplified12.3%
Taylor expanded in x around 0 79.3%
sub-neg79.3%
metadata-eval79.3%
+-commutative79.3%
associate-*r/79.3%
associate-/l*79.3%
unpow279.3%
unpow279.3%
times-frac89.5%
unpow289.5%
Simplified89.5%
if 9.99999999999999992e-221 < (*.f64 x x) < 9.99999999999999953e270Initial program 80.6%
if 9.99999999999999953e270 < (*.f64 x x) Initial program 5.3%
Taylor expanded in x around inf 5.4%
unpow25.4%
Simplified5.4%
Taylor expanded in x around inf 66.8%
unpow266.8%
unpow266.8%
times-frac81.5%
unpow281.5%
Simplified81.5%
unpow281.5%
clear-num81.5%
un-div-inv81.5%
Applied egg-rr81.5%
Final simplification84.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= (* x x) 1e-220)
(+ -1.0 (* (/ x y) (/ x (* y 4.0))))
(if (<= (* x x) 1e+271)
(/ (- (* x x) t_0) (+ t_0 (* x x)))
(+ 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-220) {
tmp = -1.0 + ((x / y) * (x / (y * 4.0)));
} else if ((x * x) <= 1e+271) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} 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-220) then
tmp = (-1.0d0) + ((x / y) * (x / (y * 4.0d0)))
else if ((x * x) <= 1d+271) then
tmp = ((x * x) - t_0) / (t_0 + (x * x))
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-220) {
tmp = -1.0 + ((x / y) * (x / (y * 4.0)));
} else if ((x * x) <= 1e+271) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} 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-220: tmp = -1.0 + ((x / y) * (x / (y * 4.0))) elif (x * x) <= 1e+271: tmp = ((x * x) - t_0) / (t_0 + (x * x)) 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-220) tmp = Float64(-1.0 + Float64(Float64(x / y) * Float64(x / Float64(y * 4.0)))); elseif (Float64(x * x) <= 1e+271) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(t_0 + Float64(x * x))); 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-220) tmp = -1.0 + ((x / y) * (x / (y * 4.0))); elseif ((x * x) <= 1e+271) tmp = ((x * x) - t_0) / (t_0 + (x * x)); 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-220], N[(-1.0 + N[(N[(x / y), $MachinePrecision] * N[(x / N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1e+271], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $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^{-220}:\\
\;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y \cdot 4}\\
\mathbf{elif}\;x \cdot x \leq 10^{+271}:\\
\;\;\;\;\frac{x \cdot x - t_0}{t_0 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 9.99999999999999992e-221Initial program 51.9%
Taylor expanded in x around 0 50.0%
*-commutative50.0%
unpow250.0%
associate-*r*50.9%
Simplified50.9%
div-sub50.9%
times-frac50.9%
*-commutative50.9%
*-inverses89.4%
Applied egg-rr89.4%
if 9.99999999999999992e-221 < (*.f64 x x) < 9.99999999999999953e270Initial program 80.6%
if 9.99999999999999953e270 < (*.f64 x x) Initial program 5.3%
Taylor expanded in x around inf 5.4%
unpow25.4%
Simplified5.4%
Taylor expanded in x around inf 66.8%
unpow266.8%
unpow266.8%
times-frac81.5%
unpow281.5%
Simplified81.5%
unpow281.5%
clear-num81.5%
un-div-inv81.5%
Applied egg-rr81.5%
Final simplification84.4%
(FPCore (x y) :precision binary64 (if (or (<= x -206000000.0) (not (<= x 6.5e-7))) (+ 1.0 (* -4.0 (/ (/ y x) (/ x y)))) -1.0))
double code(double x, double y) {
double tmp;
if ((x <= -206000000.0) || !(x <= 6.5e-7)) {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
} 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 <= (-206000000.0d0)) .or. (.not. (x <= 6.5d-7))) then
tmp = 1.0d0 + ((-4.0d0) * ((y / x) / (x / y)))
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -206000000.0) || !(x <= 6.5e-7)) {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -206000000.0) or not (x <= 6.5e-7): tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -206000000.0) || !(x <= 6.5e-7)) tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -206000000.0) || ~((x <= 6.5e-7))) tmp = 1.0 + (-4.0 * ((y / x) / (x / y))); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -206000000.0], N[Not[LessEqual[x, 6.5e-7]], $MachinePrecision]], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -206000000 \lor \neg \left(x \leq 6.5 \cdot 10^{-7}\right):\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -2.06e8 or 6.50000000000000024e-7 < x Initial program 40.9%
Taylor expanded in x around inf 36.3%
unpow236.3%
Simplified36.3%
Taylor expanded in x around inf 68.3%
unpow268.3%
unpow268.3%
times-frac76.0%
unpow276.0%
Simplified76.0%
unpow276.0%
clear-num76.0%
un-div-inv76.0%
Applied egg-rr76.0%
if -2.06e8 < x < 6.50000000000000024e-7Initial program 60.2%
Taylor expanded in x around 0 82.9%
Final simplification79.9%
(FPCore (x y) :precision binary64 (if (<= (* x x) 4.25e+16) (+ -1.0 (* (/ x y) (/ x (* y 4.0)))) (+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))))
double code(double x, double y) {
double tmp;
if ((x * x) <= 4.25e+16) {
tmp = -1.0 + ((x / y) * (x / (y * 4.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) <= 4.25d+16) then
tmp = (-1.0d0) + ((x / y) * (x / (y * 4.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) <= 4.25e+16) {
tmp = -1.0 + ((x / y) * (x / (y * 4.0)));
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 4.25e+16: tmp = -1.0 + ((x / y) * (x / (y * 4.0))) else: tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 4.25e+16) tmp = Float64(-1.0 + Float64(Float64(x / y) * Float64(x / Float64(y * 4.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) <= 4.25e+16) tmp = -1.0 + ((x / y) * (x / (y * 4.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], 4.25e+16], N[(-1.0 + N[(N[(x / y), $MachinePrecision] * N[(x / N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $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}
\mathbf{if}\;x \cdot x \leq 4.25 \cdot 10^{+16}:\\
\;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y \cdot 4}\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 4.25e16Initial program 60.5%
Taylor expanded in x around 0 49.8%
*-commutative49.8%
unpow249.8%
associate-*r*50.5%
Simplified50.5%
div-sub50.3%
times-frac50.3%
*-commutative50.3%
*-inverses83.0%
Applied egg-rr83.0%
if 4.25e16 < (*.f64 x x) Initial program 40.3%
Taylor expanded in x around inf 35.8%
unpow235.8%
Simplified35.8%
Taylor expanded in x around inf 68.0%
unpow268.0%
unpow268.0%
times-frac75.7%
unpow275.7%
Simplified75.7%
unpow275.7%
clear-num75.7%
un-div-inv75.7%
Applied egg-rr75.7%
Final simplification79.9%
(FPCore (x y) :precision binary64 (if (<= x -1e+16) 1.0 (if (<= x 2.8e-7) -1.0 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -1e+16) {
tmp = 1.0;
} else if (x <= 2.8e-7) {
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+16)) then
tmp = 1.0d0
else if (x <= 2.8d-7) 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+16) {
tmp = 1.0;
} else if (x <= 2.8e-7) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1e+16: tmp = 1.0 elif x <= 2.8e-7: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1e+16) tmp = 1.0; elseif (x <= 2.8e-7) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1e+16) tmp = 1.0; elseif (x <= 2.8e-7) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1e+16], 1.0, If[LessEqual[x, 2.8e-7], -1.0, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+16}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-7}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1e16 or 2.80000000000000019e-7 < x Initial program 40.7%
Taylor expanded in x around inf 75.4%
if -1e16 < x < 2.80000000000000019e-7Initial program 60.1%
Taylor expanded in x around 0 82.5%
Final simplification79.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 51.9%
Taylor expanded in x around 0 57.7%
Final simplification57.7%
(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 2023173
(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))))