
(FPCore (x y) :precision binary64 (let* ((t_0 (* (* y 4.0) y))) (/ (- (* x x) t_0) (+ (* x x) t_0))))
double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
t_0 = (y * 4.0d0) * y
code = ((x * x) - t_0) / ((x * x) + t_0)
end function
public static double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
def code(x, y): t_0 = (y * 4.0) * y return ((x * x) - t_0) / ((x * x) + t_0)
function code(x, y) t_0 = Float64(Float64(y * 4.0) * y) return Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) end
function tmp = code(x, y) t_0 = (y * 4.0) * y; tmp = ((x * x) - t_0) / ((x * x) + t_0); end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot y\\
\frac{x \cdot x - t_0}{x \cdot x + t_0}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (let* ((t_0 (* (* y 4.0) y))) (/ (- (* x x) t_0) (+ (* x x) t_0))))
double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
t_0 = (y * 4.0d0) * y
code = ((x * x) - t_0) / ((x * x) + t_0)
end function
public static double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
def code(x, y): t_0 = (y * 4.0) * y return ((x * x) - t_0) / ((x * x) + t_0)
function code(x, y) t_0 = Float64(Float64(y * 4.0) * y) return Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) end
function tmp = code(x, y) t_0 = (y * 4.0) * y; tmp = ((x * x) - t_0) / ((x * x) + t_0); end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot y\\
\frac{x \cdot x - t_0}{x \cdot x + t_0}
\end{array}
\end{array}
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= t_0 0.0)
1.0
(if (<= t_0 2e+260)
(pow (/ (fma x x t_0) (fma y (* y -4.0) (* x x))) -1.0)
(fma 0.5 (* (/ x y) (/ x y)) -1.0)))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (t_0 <= 0.0) {
tmp = 1.0;
} else if (t_0 <= 2e+260) {
tmp = pow((fma(x, x, t_0) / fma(y, (y * -4.0), (x * x))), -1.0);
} else {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (t_0 <= 0.0) tmp = 1.0; elseif (t_0 <= 2e+260) tmp = Float64(fma(x, x, t_0) / fma(y, Float64(y * -4.0), Float64(x * x))) ^ -1.0; else tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], 1.0, If[LessEqual[t$95$0, 2e+260], N[Power[N[(N[(x * x + t$95$0), $MachinePrecision] / N[(y * N[(y * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t_0 \leq 0:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+260}:\\
\;\;\;\;{\left(\frac{\mathsf{fma}\left(x, x, t_0\right)}{\mathsf{fma}\left(y, y \cdot -4, x \cdot x\right)}\right)}^{-1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 0.0Initial program 48.4%
Taylor expanded in x around inf 85.7%
if 0.0 < (*.f64 (*.f64 y 4) y) < 2.00000000000000013e260Initial program 78.8%
clear-num78.8%
inv-pow78.8%
fma-def78.8%
*-commutative78.8%
sub-neg78.8%
+-commutative78.8%
*-commutative78.8%
distribute-rgt-neg-in78.8%
fma-def78.8%
distribute-rgt-neg-in78.8%
metadata-eval78.8%
Applied egg-rr78.8%
if 2.00000000000000013e260 < (*.f64 (*.f64 y 4) y) Initial program 5.6%
Taylor expanded in x around 0 76.1%
fma-neg76.1%
unpow276.1%
unpow276.1%
times-frac93.4%
metadata-eval93.4%
Simplified93.4%
Final simplification84.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= t_0 0.0)
1.0
(if (<= t_0 2e+260)
(/ (- (* x x) t_0) (fma (* y 4.0) y (* x x)))
(fma 0.5 (* (/ x y) (/ x y)) -1.0)))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (t_0 <= 0.0) {
tmp = 1.0;
} else if (t_0 <= 2e+260) {
tmp = ((x * x) - t_0) / fma((y * 4.0), y, (x * x));
} else {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (t_0 <= 0.0) tmp = 1.0; elseif (t_0 <= 2e+260) tmp = Float64(Float64(Float64(x * x) - t_0) / fma(Float64(y * 4.0), y, Float64(x * x))); else tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], 1.0, If[LessEqual[t$95$0, 2e+260], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(y * 4.0), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t_0 \leq 0:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+260}:\\
\;\;\;\;\frac{x \cdot x - t_0}{\mathsf{fma}\left(y \cdot 4, y, x \cdot x\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 0.0Initial program 48.4%
Taylor expanded in x around inf 85.7%
if 0.0 < (*.f64 (*.f64 y 4) y) < 2.00000000000000013e260Initial program 78.8%
+-commutative78.8%
fma-def78.8%
Applied egg-rr78.8%
if 2.00000000000000013e260 < (*.f64 (*.f64 y 4) y) Initial program 5.6%
Taylor expanded in x around 0 76.1%
fma-neg76.1%
unpow276.1%
unpow276.1%
times-frac93.4%
metadata-eval93.4%
Simplified93.4%
Final simplification84.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= t_0 0.0)
1.0
(if (<= t_0 2e+260)
(/ (- (* x x) t_0) (+ t_0 (* x x)))
(fma 0.5 (* (/ x y) (/ x y)) -1.0)))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (t_0 <= 0.0) {
tmp = 1.0;
} else if (t_0 <= 2e+260) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} else {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (t_0 <= 0.0) tmp = 1.0; elseif (t_0 <= 2e+260) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(t_0 + Float64(x * x))); else tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], 1.0, If[LessEqual[t$95$0, 2e+260], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t_0 \leq 0:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+260}:\\
\;\;\;\;\frac{x \cdot x - t_0}{t_0 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 0.0Initial program 48.4%
Taylor expanded in x around inf 85.7%
if 0.0 < (*.f64 (*.f64 y 4) y) < 2.00000000000000013e260Initial program 78.8%
if 2.00000000000000013e260 < (*.f64 (*.f64 y 4) y) Initial program 5.6%
Taylor expanded in x around 0 76.1%
fma-neg76.1%
unpow276.1%
unpow276.1%
times-frac93.4%
metadata-eval93.4%
Simplified93.4%
Final simplification84.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= t_0 0.0)
1.0
(if (<= t_0 2e+260)
(/ (- (* x x) t_0) (+ t_0 (* x x)))
(+ -1.0 (* (/ x y) (/ x (* y 4.0))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (t_0 <= 0.0) {
tmp = 1.0;
} else if (t_0 <= 2e+260) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} else {
tmp = -1.0 + ((x / y) * (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) :: tmp
t_0 = y * (y * 4.0d0)
if (t_0 <= 0.0d0) then
tmp = 1.0d0
else if (t_0 <= 2d+260) then
tmp = ((x * x) - t_0) / (t_0 + (x * x))
else
tmp = (-1.0d0) + ((x / y) * (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 tmp;
if (t_0 <= 0.0) {
tmp = 1.0;
} else if (t_0 <= 2e+260) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} else {
tmp = -1.0 + ((x / y) * (x / (y * 4.0)));
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) tmp = 0 if t_0 <= 0.0: tmp = 1.0 elif t_0 <= 2e+260: tmp = ((x * x) - t_0) / (t_0 + (x * x)) else: tmp = -1.0 + ((x / y) * (x / (y * 4.0))) return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (t_0 <= 0.0) tmp = 1.0; elseif (t_0 <= 2e+260) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(t_0 + Float64(x * x))); else tmp = Float64(-1.0 + Float64(Float64(x / y) * Float64(x / Float64(y * 4.0)))); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (y * 4.0); tmp = 0.0; if (t_0 <= 0.0) tmp = 1.0; elseif (t_0 <= 2e+260) tmp = ((x * x) - t_0) / (t_0 + (x * x)); else tmp = -1.0 + ((x / y) * (x / (y * 4.0))); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], 1.0, If[LessEqual[t$95$0, 2e+260], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(N[(x / y), $MachinePrecision] * N[(x / N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t_0 \leq 0:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+260}:\\
\;\;\;\;\frac{x \cdot x - t_0}{t_0 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y \cdot 4}\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 0.0Initial program 48.4%
Taylor expanded in x around inf 85.7%
if 0.0 < (*.f64 (*.f64 y 4) y) < 2.00000000000000013e260Initial program 78.8%
if 2.00000000000000013e260 < (*.f64 (*.f64 y 4) y) Initial program 5.6%
Taylor expanded in x around 0 5.7%
*-commutative5.7%
unpow25.7%
associate-*r*5.7%
Simplified5.7%
div-sub5.7%
times-frac5.7%
*-commutative5.7%
pow15.7%
pow15.7%
pow-div93.1%
metadata-eval93.1%
metadata-eval93.1%
Applied egg-rr93.1%
Final simplification84.4%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= t_0 1e-147)
1.0
(if (or (<= t_0 5e-31) (not (<= t_0 2e+58)))
(+ -1.0 (* (/ x y) (/ x (* y 4.0))))
(+ 1.0 (* -4.0 (* y (/ y (* x x)))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (t_0 <= 1e-147) {
tmp = 1.0;
} else if ((t_0 <= 5e-31) || !(t_0 <= 2e+58)) {
tmp = -1.0 + ((x / y) * (x / (y * 4.0)));
} else {
tmp = 1.0 + (-4.0 * (y * (y / (x * x))));
}
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 (t_0 <= 1d-147) then
tmp = 1.0d0
else if ((t_0 <= 5d-31) .or. (.not. (t_0 <= 2d+58))) then
tmp = (-1.0d0) + ((x / y) * (x / (y * 4.0d0)))
else
tmp = 1.0d0 + ((-4.0d0) * (y * (y / (x * x))))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (t_0 <= 1e-147) {
tmp = 1.0;
} else if ((t_0 <= 5e-31) || !(t_0 <= 2e+58)) {
tmp = -1.0 + ((x / y) * (x / (y * 4.0)));
} else {
tmp = 1.0 + (-4.0 * (y * (y / (x * x))));
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) tmp = 0 if t_0 <= 1e-147: tmp = 1.0 elif (t_0 <= 5e-31) or not (t_0 <= 2e+58): tmp = -1.0 + ((x / y) * (x / (y * 4.0))) else: tmp = 1.0 + (-4.0 * (y * (y / (x * x)))) return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (t_0 <= 1e-147) tmp = 1.0; elseif ((t_0 <= 5e-31) || !(t_0 <= 2e+58)) tmp = Float64(-1.0 + Float64(Float64(x / y) * Float64(x / Float64(y * 4.0)))); else tmp = Float64(1.0 + Float64(-4.0 * Float64(y * Float64(y / Float64(x * x))))); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (y * 4.0); tmp = 0.0; if (t_0 <= 1e-147) tmp = 1.0; elseif ((t_0 <= 5e-31) || ~((t_0 <= 2e+58))) tmp = -1.0 + ((x / y) * (x / (y * 4.0))); else tmp = 1.0 + (-4.0 * (y * (y / (x * x)))); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-147], 1.0, If[Or[LessEqual[t$95$0, 5e-31], N[Not[LessEqual[t$95$0, 2e+58]], $MachinePrecision]], 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[(y * N[(y / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t_0 \leq 10^{-147}:\\
\;\;\;\;1\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{-31} \lor \neg \left(t_0 \leq 2 \cdot 10^{+58}\right):\\
\;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y \cdot 4}\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \left(y \cdot \frac{y}{x \cdot x}\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 9.9999999999999997e-148Initial program 62.1%
Taylor expanded in x around inf 77.7%
if 9.9999999999999997e-148 < (*.f64 (*.f64 y 4) y) < 5e-31 or 1.99999999999999989e58 < (*.f64 (*.f64 y 4) y) Initial program 41.3%
Taylor expanded in x around 0 35.6%
*-commutative35.6%
unpow235.6%
associate-*r*35.6%
Simplified35.6%
div-sub35.6%
times-frac35.7%
*-commutative35.7%
pow135.7%
pow135.7%
pow-div82.3%
metadata-eval82.3%
metadata-eval82.3%
Applied egg-rr82.3%
if 5e-31 < (*.f64 (*.f64 y 4) y) < 1.99999999999999989e58Initial program 59.8%
Taylor expanded in x around inf 23.7%
unpow223.7%
Simplified23.7%
Taylor expanded in x around inf 64.7%
unpow264.7%
unpow264.7%
associate-*r/64.7%
Simplified64.7%
Final simplification79.1%
(FPCore (x y)
:precision binary64
(if (<= y 7e-51)
1.0
(if (<= y 2.9e-16)
-1.0
(if (<= y 1.2e+29) (+ 1.0 (* -4.0 (* y (/ y (* x x))))) -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 7e-51) {
tmp = 1.0;
} else if (y <= 2.9e-16) {
tmp = -1.0;
} else if (y <= 1.2e+29) {
tmp = 1.0 + (-4.0 * (y * (y / (x * x))));
} 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 (y <= 7d-51) then
tmp = 1.0d0
else if (y <= 2.9d-16) then
tmp = -1.0d0
else if (y <= 1.2d+29) then
tmp = 1.0d0 + ((-4.0d0) * (y * (y / (x * x))))
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 7e-51) {
tmp = 1.0;
} else if (y <= 2.9e-16) {
tmp = -1.0;
} else if (y <= 1.2e+29) {
tmp = 1.0 + (-4.0 * (y * (y / (x * x))));
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 7e-51: tmp = 1.0 elif y <= 2.9e-16: tmp = -1.0 elif y <= 1.2e+29: tmp = 1.0 + (-4.0 * (y * (y / (x * x)))) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 7e-51) tmp = 1.0; elseif (y <= 2.9e-16) tmp = -1.0; elseif (y <= 1.2e+29) tmp = Float64(1.0 + Float64(-4.0 * Float64(y * Float64(y / Float64(x * x))))); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 7e-51) tmp = 1.0; elseif (y <= 2.9e-16) tmp = -1.0; elseif (y <= 1.2e+29) tmp = 1.0 + (-4.0 * (y * (y / (x * x)))); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 7e-51], 1.0, If[LessEqual[y, 2.9e-16], -1.0, If[LessEqual[y, 1.2e+29], N[(1.0 + N[(-4.0 * N[(y * N[(y / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7 \cdot 10^{-51}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{-16}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{+29}:\\
\;\;\;\;1 + -4 \cdot \left(y \cdot \frac{y}{x \cdot x}\right)\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 6.9999999999999995e-51Initial program 51.1%
Taylor expanded in x around inf 56.3%
if 6.9999999999999995e-51 < y < 2.8999999999999998e-16 or 1.2e29 < y Initial program 50.0%
Taylor expanded in x around 0 86.9%
if 2.8999999999999998e-16 < y < 1.2e29Initial program 58.2%
Taylor expanded in x around inf 17.7%
unpow217.7%
Simplified17.7%
Taylor expanded in x around inf 60.7%
unpow260.7%
unpow260.7%
associate-*r/60.7%
Simplified60.7%
Final simplification63.9%
(FPCore (x y) :precision binary64 (if (<= y 8.5e-51) 1.0 (if (<= y 3.8e-16) -1.0 (if (<= y 7.6e+28) 1.0 -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 8.5e-51) {
tmp = 1.0;
} else if (y <= 3.8e-16) {
tmp = -1.0;
} else if (y <= 7.6e+28) {
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 (y <= 8.5d-51) then
tmp = 1.0d0
else if (y <= 3.8d-16) then
tmp = -1.0d0
else if (y <= 7.6d+28) 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 (y <= 8.5e-51) {
tmp = 1.0;
} else if (y <= 3.8e-16) {
tmp = -1.0;
} else if (y <= 7.6e+28) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 8.5e-51: tmp = 1.0 elif y <= 3.8e-16: tmp = -1.0 elif y <= 7.6e+28: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 8.5e-51) tmp = 1.0; elseif (y <= 3.8e-16) tmp = -1.0; elseif (y <= 7.6e+28) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 8.5e-51) tmp = 1.0; elseif (y <= 3.8e-16) tmp = -1.0; elseif (y <= 7.6e+28) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 8.5e-51], 1.0, If[LessEqual[y, 3.8e-16], -1.0, If[LessEqual[y, 7.6e+28], 1.0, -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.5 \cdot 10^{-51}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-16}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{+28}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 8.50000000000000036e-51 or 3.80000000000000012e-16 < y < 7.5999999999999998e28Initial program 51.5%
Taylor expanded in x around inf 56.5%
if 8.50000000000000036e-51 < y < 3.80000000000000012e-16 or 7.5999999999999998e28 < y Initial program 50.0%
Taylor expanded in x around 0 86.9%
Final simplification63.8%
(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.1%
Taylor expanded in x around 0 54.3%
Final simplification54.3%
(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 2023224
(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))))