
(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 6 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))
(t_2 (+ -1.0 (/ 0.5 (/ (/ y x) (/ x y))))))
(if (<= (* x x) 2e-161)
t_2
(if (<= (* x x) 100000000000.0)
(/ t_1 (+ (* x x) t_0))
(if (<= (* x x) 1e+119)
t_2
(if (<= (* x x) 5e+295)
(/ t_1 (fma (* y 4.0) y (pow x 2.0)))
(+ 1.0 (* -8.0 (* (/ y x) (/ y x))))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = (x * x) - t_0;
double t_2 = -1.0 + (0.5 / ((y / x) / (x / y)));
double tmp;
if ((x * x) <= 2e-161) {
tmp = t_2;
} else if ((x * x) <= 100000000000.0) {
tmp = t_1 / ((x * x) + t_0);
} else if ((x * x) <= 1e+119) {
tmp = t_2;
} else if ((x * x) <= 5e+295) {
tmp = t_1 / fma((y * 4.0), y, pow(x, 2.0));
} else {
tmp = 1.0 + (-8.0 * ((y / x) * (y / x)));
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) t_1 = Float64(Float64(x * x) - t_0) t_2 = Float64(-1.0 + Float64(0.5 / Float64(Float64(y / x) / Float64(x / y)))) tmp = 0.0 if (Float64(x * x) <= 2e-161) tmp = t_2; elseif (Float64(x * x) <= 100000000000.0) tmp = Float64(t_1 / Float64(Float64(x * x) + t_0)); elseif (Float64(x * x) <= 1e+119) tmp = t_2; elseif (Float64(x * x) <= 5e+295) tmp = Float64(t_1 / fma(Float64(y * 4.0), y, (x ^ 2.0))); else tmp = Float64(1.0 + Float64(-8.0 * Float64(Float64(y / x) * Float64(y / x)))); 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[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(-1.0 + N[(0.5 / N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 2e-161], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 100000000000.0], N[(t$95$1 / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1e+119], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 5e+295], N[(t$95$1 / N[(N[(y * 4.0), $MachinePrecision] * y + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-8.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := x \cdot x - t_0\\
t_2 := -1 + \frac{0.5}{\frac{\frac{y}{x}}{\frac{x}{y}}}\\
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-161}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 100000000000:\\
\;\;\;\;\frac{t_1}{x \cdot x + t_0}\\
\mathbf{elif}\;x \cdot x \leq 10^{+119}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+295}:\\
\;\;\;\;\frac{t_1}{\mathsf{fma}\left(y \cdot 4, y, {x}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;1 + -8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 2.00000000000000006e-161 or 1e11 < (*.f64 x x) < 9.99999999999999944e118Initial program 54.1%
+-commutative54.1%
fma-def54.1%
pow254.1%
Applied egg-rr54.1%
Taylor expanded in x around 0 81.1%
sub-neg81.1%
metadata-eval81.1%
+-commutative81.1%
associate-*r/81.1%
associate-/l*81.1%
unpow281.1%
unpow281.1%
times-frac87.8%
unpow287.8%
Simplified87.8%
pow287.8%
clear-num87.8%
un-div-inv87.8%
Applied egg-rr87.8%
if 2.00000000000000006e-161 < (*.f64 x x) < 1e11Initial program 78.4%
if 9.99999999999999944e118 < (*.f64 x x) < 4.99999999999999991e295Initial program 86.0%
+-commutative86.0%
fma-def86.0%
pow286.0%
Applied egg-rr86.0%
if 4.99999999999999991e295 < (*.f64 x x) Initial program 1.5%
Taylor expanded in y around 0 71.7%
pow271.7%
unpow271.7%
times-frac86.0%
Applied egg-rr86.0%
Final simplification85.7%
(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 (/ 0.5 (/ (/ y x) (/ x y))))))
(if (<= (* x x) 2e-161)
t_2
(if (<= (* x x) 100000000000.0)
t_1
(if (<= (* x x) 1e+119)
t_2
(if (<= (* x x) 5e+295) t_1 (+ 1.0 (* -8.0 (* (/ y x) (/ y x))))))))))
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 + (0.5 / ((y / x) / (x / y)));
double tmp;
if ((x * x) <= 2e-161) {
tmp = t_2;
} else if ((x * x) <= 100000000000.0) {
tmp = t_1;
} else if ((x * x) <= 1e+119) {
tmp = t_2;
} else if ((x * x) <= 5e+295) {
tmp = t_1;
} else {
tmp = 1.0 + (-8.0 * ((y / x) * (y / 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) :: 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) + (0.5d0 / ((y / x) / (x / y)))
if ((x * x) <= 2d-161) then
tmp = t_2
else if ((x * x) <= 100000000000.0d0) then
tmp = t_1
else if ((x * x) <= 1d+119) then
tmp = t_2
else if ((x * x) <= 5d+295) then
tmp = t_1
else
tmp = 1.0d0 + ((-8.0d0) * ((y / x) * (y / x)))
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 + (0.5 / ((y / x) / (x / y)));
double tmp;
if ((x * x) <= 2e-161) {
tmp = t_2;
} else if ((x * x) <= 100000000000.0) {
tmp = t_1;
} else if ((x * x) <= 1e+119) {
tmp = t_2;
} else if ((x * x) <= 5e+295) {
tmp = t_1;
} else {
tmp = 1.0 + (-8.0 * ((y / x) * (y / x)));
}
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 + (0.5 / ((y / x) / (x / y))) tmp = 0 if (x * x) <= 2e-161: tmp = t_2 elif (x * x) <= 100000000000.0: tmp = t_1 elif (x * x) <= 1e+119: tmp = t_2 elif (x * x) <= 5e+295: tmp = t_1 else: tmp = 1.0 + (-8.0 * ((y / x) * (y / x))) 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(0.5 / Float64(Float64(y / x) / Float64(x / y)))) tmp = 0.0 if (Float64(x * x) <= 2e-161) tmp = t_2; elseif (Float64(x * x) <= 100000000000.0) tmp = t_1; elseif (Float64(x * x) <= 1e+119) tmp = t_2; elseif (Float64(x * x) <= 5e+295) tmp = t_1; else tmp = Float64(1.0 + Float64(-8.0 * Float64(Float64(y / x) * Float64(y / x)))); 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 + (0.5 / ((y / x) / (x / y))); tmp = 0.0; if ((x * x) <= 2e-161) tmp = t_2; elseif ((x * x) <= 100000000000.0) tmp = t_1; elseif ((x * x) <= 1e+119) tmp = t_2; elseif ((x * x) <= 5e+295) tmp = t_1; else tmp = 1.0 + (-8.0 * ((y / x) * (y / x))); 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[(0.5 / N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 2e-161], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 100000000000.0], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 1e+119], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 5e+295], t$95$1, N[(1.0 + N[(-8.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $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{0.5}{\frac{\frac{y}{x}}{\frac{x}{y}}}\\
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-161}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 100000000000:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot x \leq 10^{+119}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+295}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;1 + -8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 2.00000000000000006e-161 or 1e11 < (*.f64 x x) < 9.99999999999999944e118Initial program 54.1%
+-commutative54.1%
fma-def54.1%
pow254.1%
Applied egg-rr54.1%
Taylor expanded in x around 0 81.1%
sub-neg81.1%
metadata-eval81.1%
+-commutative81.1%
associate-*r/81.1%
associate-/l*81.1%
unpow281.1%
unpow281.1%
times-frac87.8%
unpow287.8%
Simplified87.8%
pow287.8%
clear-num87.8%
un-div-inv87.8%
Applied egg-rr87.8%
if 2.00000000000000006e-161 < (*.f64 x x) < 1e11 or 9.99999999999999944e118 < (*.f64 x x) < 4.99999999999999991e295Initial program 82.5%
if 4.99999999999999991e295 < (*.f64 x x) Initial program 1.5%
Taylor expanded in y around 0 71.7%
pow271.7%
unpow271.7%
times-frac86.0%
Applied egg-rr86.0%
Final simplification85.7%
(FPCore (x y) :precision binary64 (if (or (<= x 1.55e-18) (and (not (<= x 1.5e-11)) (<= x 2.8e+59))) (+ -1.0 (/ 0.5 (/ (/ y x) (/ x y)))) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= 1.55e-18) || (!(x <= 1.5e-11) && (x <= 2.8e+59))) {
tmp = -1.0 + (0.5 / ((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 <= 1.55d-18) .or. (.not. (x <= 1.5d-11)) .and. (x <= 2.8d+59)) then
tmp = (-1.0d0) + (0.5d0 / ((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 <= 1.55e-18) || (!(x <= 1.5e-11) && (x <= 2.8e+59))) {
tmp = -1.0 + (0.5 / ((y / x) / (x / y)));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= 1.55e-18) or (not (x <= 1.5e-11) and (x <= 2.8e+59)): tmp = -1.0 + (0.5 / ((y / x) / (x / y))) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= 1.55e-18) || (!(x <= 1.5e-11) && (x <= 2.8e+59))) tmp = Float64(-1.0 + Float64(0.5 / 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 <= 1.55e-18) || (~((x <= 1.5e-11)) && (x <= 2.8e+59))) tmp = -1.0 + (0.5 / ((y / x) / (x / y))); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, 1.55e-18], And[N[Not[LessEqual[x, 1.5e-11]], $MachinePrecision], LessEqual[x, 2.8e+59]]], N[(-1.0 + N[(0.5 / N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.55 \cdot 10^{-18} \lor \neg \left(x \leq 1.5 \cdot 10^{-11}\right) \land x \leq 2.8 \cdot 10^{+59}:\\
\;\;\;\;-1 + \frac{0.5}{\frac{\frac{y}{x}}{\frac{x}{y}}}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.55000000000000003e-18 or 1.5e-11 < x < 2.7999999999999998e59Initial program 54.2%
+-commutative54.2%
fma-def54.2%
pow254.2%
Applied egg-rr54.2%
Taylor expanded in x around 0 59.1%
sub-neg59.1%
metadata-eval59.1%
+-commutative59.1%
associate-*r/59.1%
associate-/l*59.1%
unpow259.1%
unpow259.1%
times-frac64.4%
unpow264.4%
Simplified64.4%
pow264.4%
clear-num64.4%
un-div-inv64.4%
Applied egg-rr64.4%
if 1.55000000000000003e-18 < x < 1.5e-11 or 2.7999999999999998e59 < x Initial program 30.9%
Taylor expanded in x around inf 81.4%
Final simplification68.1%
(FPCore (x y) :precision binary64 (if (or (<= x 3.6e-22) (and (not (<= x 1.5e-11)) (<= x 7.8e+61))) (+ -1.0 (/ 0.5 (/ (/ y x) (/ x y)))) (+ 1.0 (* -8.0 (* (/ y x) (/ y x))))))
double code(double x, double y) {
double tmp;
if ((x <= 3.6e-22) || (!(x <= 1.5e-11) && (x <= 7.8e+61))) {
tmp = -1.0 + (0.5 / ((y / x) / (x / y)));
} else {
tmp = 1.0 + (-8.0 * ((y / x) * (y / x)));
}
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-22) .or. (.not. (x <= 1.5d-11)) .and. (x <= 7.8d+61)) then
tmp = (-1.0d0) + (0.5d0 / ((y / x) / (x / y)))
else
tmp = 1.0d0 + ((-8.0d0) * ((y / x) * (y / x)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= 3.6e-22) || (!(x <= 1.5e-11) && (x <= 7.8e+61))) {
tmp = -1.0 + (0.5 / ((y / x) / (x / y)));
} else {
tmp = 1.0 + (-8.0 * ((y / x) * (y / x)));
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= 3.6e-22) or (not (x <= 1.5e-11) and (x <= 7.8e+61)): tmp = -1.0 + (0.5 / ((y / x) / (x / y))) else: tmp = 1.0 + (-8.0 * ((y / x) * (y / x))) return tmp
function code(x, y) tmp = 0.0 if ((x <= 3.6e-22) || (!(x <= 1.5e-11) && (x <= 7.8e+61))) tmp = Float64(-1.0 + Float64(0.5 / Float64(Float64(y / x) / Float64(x / y)))); else tmp = Float64(1.0 + Float64(-8.0 * Float64(Float64(y / x) * Float64(y / x)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= 3.6e-22) || (~((x <= 1.5e-11)) && (x <= 7.8e+61))) tmp = -1.0 + (0.5 / ((y / x) / (x / y))); else tmp = 1.0 + (-8.0 * ((y / x) * (y / x))); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, 3.6e-22], And[N[Not[LessEqual[x, 1.5e-11]], $MachinePrecision], LessEqual[x, 7.8e+61]]], N[(-1.0 + N[(0.5 / N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-8.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.6 \cdot 10^{-22} \lor \neg \left(x \leq 1.5 \cdot 10^{-11}\right) \land x \leq 7.8 \cdot 10^{+61}:\\
\;\;\;\;-1 + \frac{0.5}{\frac{\frac{y}{x}}{\frac{x}{y}}}\\
\mathbf{else}:\\
\;\;\;\;1 + -8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\end{array}
\end{array}
if x < 3.5999999999999998e-22 or 1.5e-11 < x < 7.79999999999999975e61Initial program 54.0%
+-commutative54.0%
fma-def54.0%
pow254.0%
Applied egg-rr54.0%
Taylor expanded in x around 0 59.4%
sub-neg59.4%
metadata-eval59.4%
+-commutative59.4%
associate-*r/59.4%
associate-/l*59.4%
unpow259.4%
unpow259.4%
times-frac64.7%
unpow264.7%
Simplified64.7%
pow264.7%
clear-num64.7%
un-div-inv64.7%
Applied egg-rr64.7%
if 3.5999999999999998e-22 < x < 1.5e-11 or 7.79999999999999975e61 < x Initial program 32.1%
Taylor expanded in y around 0 73.7%
pow273.7%
unpow273.7%
times-frac83.3%
Applied egg-rr83.3%
Final simplification68.8%
(FPCore (x y) :precision binary64 (if (<= x 1.55e-18) -1.0 (if (<= x 1e-11) 1.0 (if (<= x 1.9e+60) -1.0 1.0))))
double code(double x, double y) {
double tmp;
if (x <= 1.55e-18) {
tmp = -1.0;
} else if (x <= 1e-11) {
tmp = 1.0;
} else if (x <= 1.9e+60) {
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 <= 1.55d-18) then
tmp = -1.0d0
else if (x <= 1d-11) then
tmp = 1.0d0
else if (x <= 1.9d+60) 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 <= 1.55e-18) {
tmp = -1.0;
} else if (x <= 1e-11) {
tmp = 1.0;
} else if (x <= 1.9e+60) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.55e-18: tmp = -1.0 elif x <= 1e-11: tmp = 1.0 elif x <= 1.9e+60: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= 1.55e-18) tmp = -1.0; elseif (x <= 1e-11) tmp = 1.0; elseif (x <= 1.9e+60) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.55e-18) tmp = -1.0; elseif (x <= 1e-11) tmp = 1.0; elseif (x <= 1.9e+60) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.55e-18], -1.0, If[LessEqual[x, 1e-11], 1.0, If[LessEqual[x, 1.9e+60], -1.0, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.55 \cdot 10^{-18}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 10^{-11}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{+60}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.55000000000000003e-18 or 9.99999999999999939e-12 < x < 1.90000000000000005e60Initial program 54.2%
Taylor expanded in x around 0 63.2%
if 1.55000000000000003e-18 < x < 9.99999999999999939e-12 or 1.90000000000000005e60 < x Initial program 30.9%
Taylor expanded in x around inf 81.4%
Final simplification67.1%
(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 49.2%
Taylor expanded in x around 0 53.4%
Final simplification53.4%
(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 2023311
(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))))