
(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 7 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
(if (<= (* x x) 4e-108)
(log1p (+ (* 0.5 (* (pow (/ x y) 2.0) (exp -1.0))) (expm1 -1.0)))
(if (<= (* x x) 5e+69)
(pow
(/ (+ (pow x 2.0) (* (pow y 2.0) 4.0)) (fma y (* y -4.0) (pow x 2.0)))
-1.0)
(+ 1.0 (/ -8.0 (* (/ x y) (/ x y)))))))
double code(double x, double y) {
double tmp;
if ((x * x) <= 4e-108) {
tmp = log1p(((0.5 * (pow((x / y), 2.0) * exp(-1.0))) + expm1(-1.0)));
} else if ((x * x) <= 5e+69) {
tmp = pow(((pow(x, 2.0) + (pow(y, 2.0) * 4.0)) / fma(y, (y * -4.0), pow(x, 2.0))), -1.0);
} else {
tmp = 1.0 + (-8.0 / ((x / y) * (x / y)));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 4e-108) tmp = log1p(Float64(Float64(0.5 * Float64((Float64(x / y) ^ 2.0) * exp(-1.0))) + expm1(-1.0))); elseif (Float64(x * x) <= 5e+69) tmp = Float64(Float64((x ^ 2.0) + Float64((y ^ 2.0) * 4.0)) / fma(y, Float64(y * -4.0), (x ^ 2.0))) ^ -1.0; else tmp = Float64(1.0 + Float64(-8.0 / Float64(Float64(x / y) * Float64(x / y)))); end return tmp end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 4e-108], N[Log[1 + N[(N[(0.5 * N[(N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision] * N[Exp[-1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(Exp[-1.0] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 5e+69], N[Power[N[(N[(N[Power[x, 2.0], $MachinePrecision] + N[(N[Power[y, 2.0], $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision] / N[(y * N[(y * -4.0), $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision], N[(1.0 + N[(-8.0 / N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4 \cdot 10^{-108}:\\
\;\;\;\;\mathsf{log1p}\left(0.5 \cdot \left({\left(\frac{x}{y}\right)}^{2} \cdot e^{-1}\right) + \mathsf{expm1}\left(-1\right)\right)\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+69}:\\
\;\;\;\;{\left(\frac{{x}^{2} + {y}^{2} \cdot 4}{\mathsf{fma}\left(y, y \cdot -4, {x}^{2}\right)}\right)}^{-1}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{-8}{\frac{x}{y} \cdot \frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 4.00000000000000016e-108Initial program 60.4%
clear-num60.4%
inv-pow60.4%
+-commutative60.4%
*-commutative60.4%
associate-*l*60.4%
fma-def60.4%
pow260.4%
pow260.4%
sub-neg60.4%
+-commutative60.4%
*-commutative60.4%
distribute-rgt-neg-in60.4%
fma-def60.4%
distribute-rgt-neg-in60.4%
metadata-eval60.4%
pow260.4%
Applied egg-rr60.4%
Taylor expanded in x around 0 62.5%
associate--l+62.5%
*-commutative62.5%
fma-def62.5%
unpow262.5%
unpow262.5%
times-frac62.5%
unpow262.5%
fma-neg62.5%
Simplified87.5%
log1p-expm1-u87.5%
unpow-187.5%
Applied egg-rr87.5%
Taylor expanded in x around 0 80.0%
+-commutative80.0%
associate--l+80.0%
associate-/l*80.0%
associate-/r/80.0%
unpow280.0%
unpow280.0%
times-frac88.9%
unpow288.9%
expm1-def88.9%
Simplified88.9%
if 4.00000000000000016e-108 < (*.f64 x x) < 5.00000000000000036e69Initial program 86.0%
clear-num86.0%
inv-pow86.0%
+-commutative86.0%
*-commutative86.0%
associate-*l*86.0%
fma-def86.0%
pow286.0%
pow286.0%
sub-neg86.0%
+-commutative86.0%
*-commutative86.0%
distribute-rgt-neg-in86.0%
fma-def86.0%
distribute-rgt-neg-in86.0%
metadata-eval86.0%
pow286.0%
Applied egg-rr86.0%
fma-udef86.0%
+-commutative86.0%
*-commutative86.0%
Applied egg-rr86.0%
if 5.00000000000000036e69 < (*.f64 x x) Initial program 26.8%
clear-num26.8%
inv-pow26.8%
+-commutative26.8%
*-commutative26.8%
associate-*l*26.8%
fma-def26.8%
pow226.8%
pow226.8%
sub-neg26.8%
+-commutative26.8%
*-commutative26.8%
distribute-rgt-neg-in26.8%
fma-def26.8%
distribute-rgt-neg-in26.8%
metadata-eval26.8%
pow226.8%
Applied egg-rr26.8%
Taylor expanded in y around 0 77.2%
associate-*r/77.2%
associate-/l*77.2%
unpow277.2%
unpow277.2%
times-frac82.6%
unpow282.6%
Simplified82.6%
Taylor expanded in x around inf 77.2%
associate-*r/77.2%
associate-/l*77.2%
unpow277.2%
unpow277.2%
times-frac83.0%
unpow283.0%
Simplified83.0%
pow283.0%
Applied egg-rr83.0%
Final simplification85.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= (* x x) 4e-108)
(log1p (+ (* 0.5 (* (pow (/ x y) 2.0) (exp -1.0))) (expm1 -1.0)))
(if (<= (* x x) 5e+69)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(+ 1.0 (/ -8.0 (* (/ x y) (/ x y))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if ((x * x) <= 4e-108) {
tmp = log1p(((0.5 * (pow((x / y), 2.0) * exp(-1.0))) + expm1(-1.0)));
} else if ((x * x) <= 5e+69) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = 1.0 + (-8.0 / ((x / y) * (x / y)));
}
return tmp;
}
public static double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if ((x * x) <= 4e-108) {
tmp = Math.log1p(((0.5 * (Math.pow((x / y), 2.0) * Math.exp(-1.0))) + Math.expm1(-1.0)));
} else if ((x * x) <= 5e+69) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = 1.0 + (-8.0 / ((x / y) * (x / y)));
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) tmp = 0 if (x * x) <= 4e-108: tmp = math.log1p(((0.5 * (math.pow((x / y), 2.0) * math.exp(-1.0))) + math.expm1(-1.0))) elif (x * x) <= 5e+69: tmp = ((x * x) - t_0) / ((x * x) + t_0) else: tmp = 1.0 + (-8.0 / ((x / y) * (x / y))) return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (Float64(x * x) <= 4e-108) tmp = log1p(Float64(Float64(0.5 * Float64((Float64(x / y) ^ 2.0) * exp(-1.0))) + expm1(-1.0))); elseif (Float64(x * x) <= 5e+69) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = Float64(1.0 + Float64(-8.0 / Float64(Float64(x / y) * Float64(x / y)))); 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], 4e-108], N[Log[1 + N[(N[(0.5 * N[(N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision] * N[Exp[-1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(Exp[-1.0] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 5e+69], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-8.0 / N[(N[(x / y), $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 4 \cdot 10^{-108}:\\
\;\;\;\;\mathsf{log1p}\left(0.5 \cdot \left({\left(\frac{x}{y}\right)}^{2} \cdot e^{-1}\right) + \mathsf{expm1}\left(-1\right)\right)\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+69}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{-8}{\frac{x}{y} \cdot \frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 4.00000000000000016e-108Initial program 60.4%
clear-num60.4%
inv-pow60.4%
+-commutative60.4%
*-commutative60.4%
associate-*l*60.4%
fma-def60.4%
pow260.4%
pow260.4%
sub-neg60.4%
+-commutative60.4%
*-commutative60.4%
distribute-rgt-neg-in60.4%
fma-def60.4%
distribute-rgt-neg-in60.4%
metadata-eval60.4%
pow260.4%
Applied egg-rr60.4%
Taylor expanded in x around 0 62.5%
associate--l+62.5%
*-commutative62.5%
fma-def62.5%
unpow262.5%
unpow262.5%
times-frac62.5%
unpow262.5%
fma-neg62.5%
Simplified87.5%
log1p-expm1-u87.5%
unpow-187.5%
Applied egg-rr87.5%
Taylor expanded in x around 0 80.0%
+-commutative80.0%
associate--l+80.0%
associate-/l*80.0%
associate-/r/80.0%
unpow280.0%
unpow280.0%
times-frac88.9%
unpow288.9%
expm1-def88.9%
Simplified88.9%
if 4.00000000000000016e-108 < (*.f64 x x) < 5.00000000000000036e69Initial program 86.0%
if 5.00000000000000036e69 < (*.f64 x x) Initial program 26.8%
clear-num26.8%
inv-pow26.8%
+-commutative26.8%
*-commutative26.8%
associate-*l*26.8%
fma-def26.8%
pow226.8%
pow226.8%
sub-neg26.8%
+-commutative26.8%
*-commutative26.8%
distribute-rgt-neg-in26.8%
fma-def26.8%
distribute-rgt-neg-in26.8%
metadata-eval26.8%
pow226.8%
Applied egg-rr26.8%
Taylor expanded in y around 0 77.2%
associate-*r/77.2%
associate-/l*77.2%
unpow277.2%
unpow277.2%
times-frac82.6%
unpow282.6%
Simplified82.6%
Taylor expanded in x around inf 77.2%
associate-*r/77.2%
associate-/l*77.2%
unpow277.2%
unpow277.2%
times-frac83.0%
unpow283.0%
Simplified83.0%
pow283.0%
Applied egg-rr83.0%
Final simplification85.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))) (t_1 (* (/ x y) (/ x y))))
(if (<= (* x x) 2e-276)
(+ -1.0 (* 0.5 t_1))
(if (<= (* x x) 5e+69)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(+ 1.0 (/ -8.0 t_1))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = (x / y) * (x / y);
double tmp;
if ((x * x) <= 2e-276) {
tmp = -1.0 + (0.5 * t_1);
} else if ((x * x) <= 5e+69) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = 1.0 + (-8.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 = (x / y) * (x / y)
if ((x * x) <= 2d-276) then
tmp = (-1.0d0) + (0.5d0 * t_1)
else if ((x * x) <= 5d+69) then
tmp = ((x * x) - t_0) / ((x * x) + t_0)
else
tmp = 1.0d0 + ((-8.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 = (x / y) * (x / y);
double tmp;
if ((x * x) <= 2e-276) {
tmp = -1.0 + (0.5 * t_1);
} else if ((x * x) <= 5e+69) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = 1.0 + (-8.0 / t_1);
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) t_1 = (x / y) * (x / y) tmp = 0 if (x * x) <= 2e-276: tmp = -1.0 + (0.5 * t_1) elif (x * x) <= 5e+69: tmp = ((x * x) - t_0) / ((x * x) + t_0) else: tmp = 1.0 + (-8.0 / t_1) return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) t_1 = Float64(Float64(x / y) * Float64(x / y)) tmp = 0.0 if (Float64(x * x) <= 2e-276) tmp = Float64(-1.0 + Float64(0.5 * t_1)); elseif (Float64(x * x) <= 5e+69) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = Float64(1.0 + Float64(-8.0 / t_1)); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (y * 4.0); t_1 = (x / y) * (x / y); tmp = 0.0; if ((x * x) <= 2e-276) tmp = -1.0 + (0.5 * t_1); elseif ((x * x) <= 5e+69) tmp = ((x * x) - t_0) / ((x * x) + t_0); else tmp = 1.0 + (-8.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[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 2e-276], N[(-1.0 + N[(0.5 * t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 5e+69], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-8.0 / t$95$1), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := \frac{x}{y} \cdot \frac{x}{y}\\
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-276}:\\
\;\;\;\;-1 + 0.5 \cdot t_1\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+69}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{-8}{t_1}\\
\end{array}
\end{array}
if (*.f64 x x) < 2e-276Initial program 54.3%
Taylor expanded in x around 0 82.9%
unpow282.9%
unpow282.9%
times-frac94.8%
Applied egg-rr94.8%
if 2e-276 < (*.f64 x x) < 5.00000000000000036e69Initial program 81.0%
if 5.00000000000000036e69 < (*.f64 x x) Initial program 26.8%
clear-num26.8%
inv-pow26.8%
+-commutative26.8%
*-commutative26.8%
associate-*l*26.8%
fma-def26.8%
pow226.8%
pow226.8%
sub-neg26.8%
+-commutative26.8%
*-commutative26.8%
distribute-rgt-neg-in26.8%
fma-def26.8%
distribute-rgt-neg-in26.8%
metadata-eval26.8%
pow226.8%
Applied egg-rr26.8%
Taylor expanded in y around 0 77.2%
associate-*r/77.2%
associate-/l*77.2%
unpow277.2%
unpow277.2%
times-frac82.6%
unpow282.6%
Simplified82.6%
Taylor expanded in x around inf 77.2%
associate-*r/77.2%
associate-/l*77.2%
unpow277.2%
unpow277.2%
times-frac83.0%
unpow283.0%
Simplified83.0%
pow283.0%
Applied egg-rr83.0%
Final simplification85.6%
(FPCore (x y)
:precision binary64
(if (<= x 1.1e-39)
-1.0
(if (or (<= x 3.3) (not (<= x 2.15e+20)))
(+ 1.0 (/ -8.0 (* (/ x y) (/ x y))))
-1.0)))
double code(double x, double y) {
double tmp;
if (x <= 1.1e-39) {
tmp = -1.0;
} else if ((x <= 3.3) || !(x <= 2.15e+20)) {
tmp = 1.0 + (-8.0 / ((x / y) * (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 <= 1.1d-39) then
tmp = -1.0d0
else if ((x <= 3.3d0) .or. (.not. (x <= 2.15d+20))) then
tmp = 1.0d0 + ((-8.0d0) / ((x / y) * (x / y)))
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.1e-39) {
tmp = -1.0;
} else if ((x <= 3.3) || !(x <= 2.15e+20)) {
tmp = 1.0 + (-8.0 / ((x / y) * (x / y)));
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.1e-39: tmp = -1.0 elif (x <= 3.3) or not (x <= 2.15e+20): tmp = 1.0 + (-8.0 / ((x / y) * (x / y))) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= 1.1e-39) tmp = -1.0; elseif ((x <= 3.3) || !(x <= 2.15e+20)) tmp = Float64(1.0 + Float64(-8.0 / Float64(Float64(x / y) * Float64(x / y)))); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.1e-39) tmp = -1.0; elseif ((x <= 3.3) || ~((x <= 2.15e+20))) tmp = 1.0 + (-8.0 / ((x / y) * (x / y))); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.1e-39], -1.0, If[Or[LessEqual[x, 3.3], N[Not[LessEqual[x, 2.15e+20]], $MachinePrecision]], N[(1.0 + N[(-8.0 / N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.1 \cdot 10^{-39}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 3.3 \lor \neg \left(x \leq 2.15 \cdot 10^{+20}\right):\\
\;\;\;\;1 + \frac{-8}{\frac{x}{y} \cdot \frac{x}{y}}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < 1.1e-39 or 3.2999999999999998 < x < 2.15e20Initial program 55.4%
Taylor expanded in x around 0 62.4%
if 1.1e-39 < x < 3.2999999999999998 or 2.15e20 < x Initial program 36.1%
clear-num36.1%
inv-pow36.1%
+-commutative36.1%
*-commutative36.1%
associate-*l*36.1%
fma-def36.1%
pow236.1%
pow236.1%
sub-neg36.1%
+-commutative36.1%
*-commutative36.1%
distribute-rgt-neg-in36.1%
fma-def36.1%
distribute-rgt-neg-in36.1%
metadata-eval36.1%
pow236.1%
Applied egg-rr36.1%
Taylor expanded in y around 0 74.1%
associate-*r/74.1%
associate-/l*74.1%
unpow274.1%
unpow274.1%
times-frac79.7%
unpow279.7%
Simplified79.7%
Taylor expanded in x around inf 74.2%
associate-*r/74.2%
associate-/l*74.2%
unpow274.2%
unpow274.2%
times-frac80.2%
unpow280.2%
Simplified80.2%
pow280.2%
Applied egg-rr80.2%
Final simplification67.4%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (/ x y) (/ x y))))
(if (or (<= x 8e-39) (and (not (<= x 0.92)) (<= x 2.2e+23)))
(+ -1.0 (* 0.5 t_0))
(+ 1.0 (/ -8.0 t_0)))))
double code(double x, double y) {
double t_0 = (x / y) * (x / y);
double tmp;
if ((x <= 8e-39) || (!(x <= 0.92) && (x <= 2.2e+23))) {
tmp = -1.0 + (0.5 * t_0);
} else {
tmp = 1.0 + (-8.0 / t_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) :: tmp
t_0 = (x / y) * (x / y)
if ((x <= 8d-39) .or. (.not. (x <= 0.92d0)) .and. (x <= 2.2d+23)) then
tmp = (-1.0d0) + (0.5d0 * t_0)
else
tmp = 1.0d0 + ((-8.0d0) / t_0)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x / y) * (x / y);
double tmp;
if ((x <= 8e-39) || (!(x <= 0.92) && (x <= 2.2e+23))) {
tmp = -1.0 + (0.5 * t_0);
} else {
tmp = 1.0 + (-8.0 / t_0);
}
return tmp;
}
def code(x, y): t_0 = (x / y) * (x / y) tmp = 0 if (x <= 8e-39) or (not (x <= 0.92) and (x <= 2.2e+23)): tmp = -1.0 + (0.5 * t_0) else: tmp = 1.0 + (-8.0 / t_0) return tmp
function code(x, y) t_0 = Float64(Float64(x / y) * Float64(x / y)) tmp = 0.0 if ((x <= 8e-39) || (!(x <= 0.92) && (x <= 2.2e+23))) tmp = Float64(-1.0 + Float64(0.5 * t_0)); else tmp = Float64(1.0 + Float64(-8.0 / t_0)); end return tmp end
function tmp_2 = code(x, y) t_0 = (x / y) * (x / y); tmp = 0.0; if ((x <= 8e-39) || (~((x <= 0.92)) && (x <= 2.2e+23))) tmp = -1.0 + (0.5 * t_0); else tmp = 1.0 + (-8.0 / t_0); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[x, 8e-39], And[N[Not[LessEqual[x, 0.92]], $MachinePrecision], LessEqual[x, 2.2e+23]]], N[(-1.0 + N[(0.5 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-8.0 / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y} \cdot \frac{x}{y}\\
\mathbf{if}\;x \leq 8 \cdot 10^{-39} \lor \neg \left(x \leq 0.92\right) \land x \leq 2.2 \cdot 10^{+23}:\\
\;\;\;\;-1 + 0.5 \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{-8}{t_0}\\
\end{array}
\end{array}
if x < 7.99999999999999943e-39 or 0.92000000000000004 < x < 2.20000000000000008e23Initial program 55.4%
Taylor expanded in x around 0 57.9%
unpow257.9%
unpow257.9%
times-frac63.7%
Applied egg-rr63.7%
if 7.99999999999999943e-39 < x < 0.92000000000000004 or 2.20000000000000008e23 < x Initial program 36.1%
clear-num36.1%
inv-pow36.1%
+-commutative36.1%
*-commutative36.1%
associate-*l*36.1%
fma-def36.1%
pow236.1%
pow236.1%
sub-neg36.1%
+-commutative36.1%
*-commutative36.1%
distribute-rgt-neg-in36.1%
fma-def36.1%
distribute-rgt-neg-in36.1%
metadata-eval36.1%
pow236.1%
Applied egg-rr36.1%
Taylor expanded in y around 0 74.1%
associate-*r/74.1%
associate-/l*74.1%
unpow274.1%
unpow274.1%
times-frac79.7%
unpow279.7%
Simplified79.7%
Taylor expanded in x around inf 74.2%
associate-*r/74.2%
associate-/l*74.2%
unpow274.2%
unpow274.2%
times-frac80.2%
unpow280.2%
Simplified80.2%
pow280.2%
Applied egg-rr80.2%
Final simplification68.3%
(FPCore (x y) :precision binary64 (if (<= x 4e-42) -1.0 (if (<= x 0.05) 1.0 (if (<= x 2e+20) -1.0 1.0))))
double code(double x, double y) {
double tmp;
if (x <= 4e-42) {
tmp = -1.0;
} else if (x <= 0.05) {
tmp = 1.0;
} else if (x <= 2e+20) {
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 <= 4d-42) then
tmp = -1.0d0
else if (x <= 0.05d0) then
tmp = 1.0d0
else if (x <= 2d+20) 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 <= 4e-42) {
tmp = -1.0;
} else if (x <= 0.05) {
tmp = 1.0;
} else if (x <= 2e+20) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 4e-42: tmp = -1.0 elif x <= 0.05: tmp = 1.0 elif x <= 2e+20: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= 4e-42) tmp = -1.0; elseif (x <= 0.05) tmp = 1.0; elseif (x <= 2e+20) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 4e-42) tmp = -1.0; elseif (x <= 0.05) tmp = 1.0; elseif (x <= 2e+20) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 4e-42], -1.0, If[LessEqual[x, 0.05], 1.0, If[LessEqual[x, 2e+20], -1.0, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{-42}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 0.05:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+20}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 4.00000000000000015e-42 or 0.050000000000000003 < x < 2e20Initial program 55.4%
Taylor expanded in x around 0 62.4%
if 4.00000000000000015e-42 < x < 0.050000000000000003 or 2e20 < x Initial program 36.1%
Taylor expanded in x around inf 79.5%
Final simplification67.2%
(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 50.0%
Taylor expanded in x around 0 50.8%
Final simplification50.8%
(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 2024013
(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))))