
(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 (hypot x (* y 2.0)))) (* (/ (fma y 2.0 x) t_0) (/ (- x (* y 2.0)) t_0))))
double code(double x, double y) {
double t_0 = hypot(x, (y * 2.0));
return (fma(y, 2.0, x) / t_0) * ((x - (y * 2.0)) / t_0);
}
function code(x, y) t_0 = hypot(x, Float64(y * 2.0)) return Float64(Float64(fma(y, 2.0, x) / t_0) * Float64(Float64(x - Float64(y * 2.0)) / t_0)) end
code[x_, y_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[(y * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, N[(N[(N[(y * 2.0 + x), $MachinePrecision] / t$95$0), $MachinePrecision] * N[(N[(x - N[(y * 2.0), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, y \cdot 2\right)\\
\frac{\mathsf{fma}\left(y, 2, x\right)}{t_0} \cdot \frac{x - y \cdot 2}{t_0}
\end{array}
\end{array}
Initial program 48.8%
sub-neg48.8%
+-commutative48.8%
distribute-rgt-neg-in48.8%
fma-def48.8%
Applied egg-rr48.8%
fma-udef48.8%
distribute-rgt-neg-in48.8%
+-commutative48.8%
sub-neg48.8%
add-sqr-sqrt48.8%
difference-of-squares48.8%
*-commutative48.8%
associate-*r*48.8%
sqrt-prod48.8%
sqrt-unprod21.0%
add-sqr-sqrt31.9%
metadata-eval31.9%
*-commutative31.9%
associate-*r*31.9%
sqrt-prod31.9%
sqrt-unprod21.0%
add-sqr-sqrt48.8%
metadata-eval48.8%
Applied egg-rr48.8%
*-commutative48.8%
fma-udef48.8%
add-sqr-sqrt48.8%
times-frac50.4%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0)))
(t_1 (+ (* x x) t_0))
(t_2 (+ (/ (/ (/ x y) (/ y x)) 4.0) -1.0)))
(if (<= (* x x) 2e-298)
t_2
(if (<= (* x x) 2e+31)
(- (/ (* x x) t_1) (/ t_0 t_1))
(if (<= (* x x) 4e+151)
t_2
(if (<= (* x x) 1e+204)
(/ (- (* x x) t_0) t_1)
(if (<= (* x x) 1e+263)
(fma 0.5 (* (/ x y) (/ x y)) -1.0)
(+ 1.0 (* -8.0 (/ (/ y x) (/ x y)))))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = (x * x) + t_0;
double t_2 = (((x / y) / (y / x)) / 4.0) + -1.0;
double tmp;
if ((x * x) <= 2e-298) {
tmp = t_2;
} else if ((x * x) <= 2e+31) {
tmp = ((x * x) / t_1) - (t_0 / t_1);
} else if ((x * x) <= 4e+151) {
tmp = t_2;
} else if ((x * x) <= 1e+204) {
tmp = ((x * x) - t_0) / t_1;
} else if ((x * x) <= 1e+263) {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
} else {
tmp = 1.0 + (-8.0 * ((y / x) / (x / y)));
}
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(Float64(Float64(Float64(x / y) / Float64(y / x)) / 4.0) + -1.0) tmp = 0.0 if (Float64(x * x) <= 2e-298) tmp = t_2; elseif (Float64(x * x) <= 2e+31) tmp = Float64(Float64(Float64(x * x) / t_1) - Float64(t_0 / t_1)); elseif (Float64(x * x) <= 4e+151) tmp = t_2; elseif (Float64(x * x) <= 1e+204) tmp = Float64(Float64(Float64(x * x) - t_0) / t_1); elseif (Float64(x * x) <= 1e+263) tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); else tmp = Float64(1.0 + Float64(-8.0 * Float64(Float64(y / x) / Float64(x / y)))); 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[(N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 2e-298], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 2e+31], N[(N[(N[(x * x), $MachinePrecision] / t$95$1), $MachinePrecision] - N[(t$95$0 / t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+151], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 1e+204], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 1e+263], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 + N[(-8.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)\\
t_1 := x \cdot x + t_0\\
t_2 := \frac{\frac{\frac{x}{y}}{\frac{y}{x}}}{4} + -1\\
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-298}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+31}:\\
\;\;\;\;\frac{x \cdot x}{t_1} - \frac{t_0}{t_1}\\
\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+151}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 10^{+204}:\\
\;\;\;\;\frac{x \cdot x - t_0}{t_1}\\
\mathbf{elif}\;x \cdot x \leq 10^{+263}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{else}:\\
\;\;\;\;1 + -8 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 1.99999999999999982e-298 or 1.9999999999999999e31 < (*.f64 x x) < 4.00000000000000007e151Initial program 48.2%
Taylor expanded in x around 0 38.9%
*-commutative38.9%
unpow238.9%
associate-*r*38.9%
Simplified38.9%
div-sub38.8%
associate-*r*38.8%
associate-/r*38.8%
frac-times38.8%
pow238.8%
*-commutative38.8%
*-inverses85.1%
Applied egg-rr85.1%
unpow285.1%
clear-num85.1%
un-div-inv85.1%
Applied egg-rr85.1%
if 1.99999999999999982e-298 < (*.f64 x x) < 1.9999999999999999e31Initial program 88.2%
div-sub88.2%
sub-neg88.2%
associate-/l*88.2%
+-commutative88.2%
*-commutative88.2%
fma-udef88.2%
*-commutative88.2%
associate-/l*88.5%
+-commutative88.5%
*-commutative88.5%
fma-udef88.5%
Applied egg-rr88.5%
sub-neg88.5%
associate-/r/88.5%
associate-*l/88.6%
fma-def88.6%
+-commutative88.6%
fma-def88.6%
associate-/r/88.4%
associate-*l/88.2%
fma-def88.2%
+-commutative88.2%
fma-def88.2%
Simplified88.2%
fma-udef88.2%
*-commutative88.2%
+-commutative88.2%
*-commutative88.2%
Applied egg-rr88.2%
fma-udef88.2%
*-commutative88.2%
+-commutative88.2%
*-commutative88.2%
Applied egg-rr88.2%
if 4.00000000000000007e151 < (*.f64 x x) < 9.99999999999999989e203Initial program 91.7%
if 9.99999999999999989e203 < (*.f64 x x) < 1.00000000000000002e263Initial program 41.4%
Taylor expanded in x around 0 73.2%
fma-neg73.2%
unpow273.2%
unpow273.2%
times-frac73.2%
metadata-eval73.2%
Simplified73.2%
if 1.00000000000000002e263 < (*.f64 x x) Initial program 11.1%
sub-neg11.1%
+-commutative11.1%
distribute-rgt-neg-in11.1%
fma-def11.1%
Applied egg-rr11.1%
Taylor expanded in y around 0 71.6%
unpow271.6%
unpow271.6%
times-frac83.9%
unpow283.9%
Simplified83.9%
unpow283.9%
clear-num83.9%
un-div-inv83.9%
Applied egg-rr83.9%
Final simplification85.3%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0)))
(t_1 (+ (* x x) t_0))
(t_2 (+ (/ (/ (/ x y) (/ y x)) 4.0) -1.0)))
(if (<= (* x x) 2e-298)
t_2
(if (<= (* x x) 2e+31)
(- (/ (* x x) t_1) (/ t_0 t_1))
(if (<= (* x x) 4e+151) t_2 (+ 1.0 (* -8.0 (/ (/ y x) (/ x y)))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = (x * x) + t_0;
double t_2 = (((x / y) / (y / x)) / 4.0) + -1.0;
double tmp;
if ((x * x) <= 2e-298) {
tmp = t_2;
} else if ((x * x) <= 2e+31) {
tmp = ((x * x) / t_1) - (t_0 / t_1);
} else if ((x * x) <= 4e+151) {
tmp = t_2;
} else {
tmp = 1.0 + (-8.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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = y * (y * 4.0d0)
t_1 = (x * x) + t_0
t_2 = (((x / y) / (y / x)) / 4.0d0) + (-1.0d0)
if ((x * x) <= 2d-298) then
tmp = t_2
else if ((x * x) <= 2d+31) then
tmp = ((x * x) / t_1) - (t_0 / t_1)
else if ((x * x) <= 4d+151) then
tmp = t_2
else
tmp = 1.0d0 + ((-8.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 t_1 = (x * x) + t_0;
double t_2 = (((x / y) / (y / x)) / 4.0) + -1.0;
double tmp;
if ((x * x) <= 2e-298) {
tmp = t_2;
} else if ((x * x) <= 2e+31) {
tmp = ((x * x) / t_1) - (t_0 / t_1);
} else if ((x * x) <= 4e+151) {
tmp = t_2;
} else {
tmp = 1.0 + (-8.0 * ((y / x) / (x / y)));
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) t_1 = (x * x) + t_0 t_2 = (((x / y) / (y / x)) / 4.0) + -1.0 tmp = 0 if (x * x) <= 2e-298: tmp = t_2 elif (x * x) <= 2e+31: tmp = ((x * x) / t_1) - (t_0 / t_1) elif (x * x) <= 4e+151: tmp = t_2 else: tmp = 1.0 + (-8.0 * ((y / x) / (x / y))) 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(Float64(Float64(Float64(x / y) / Float64(y / x)) / 4.0) + -1.0) tmp = 0.0 if (Float64(x * x) <= 2e-298) tmp = t_2; elseif (Float64(x * x) <= 2e+31) tmp = Float64(Float64(Float64(x * x) / t_1) - Float64(t_0 / t_1)); elseif (Float64(x * x) <= 4e+151) tmp = t_2; else tmp = Float64(1.0 + Float64(-8.0 * Float64(Float64(y / x) / Float64(x / y)))); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (y * 4.0); t_1 = (x * x) + t_0; t_2 = (((x / y) / (y / x)) / 4.0) + -1.0; tmp = 0.0; if ((x * x) <= 2e-298) tmp = t_2; elseif ((x * x) <= 2e+31) tmp = ((x * x) / t_1) - (t_0 / t_1); elseif ((x * x) <= 4e+151) tmp = t_2; else tmp = 1.0 + (-8.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]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 2e-298], t$95$2, If[LessEqual[N[(x * x), $MachinePrecision], 2e+31], N[(N[(N[(x * x), $MachinePrecision] / t$95$1), $MachinePrecision] - N[(t$95$0 / t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+151], t$95$2, N[(1.0 + N[(-8.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)\\
t_1 := x \cdot x + t_0\\
t_2 := \frac{\frac{\frac{x}{y}}{\frac{y}{x}}}{4} + -1\\
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-298}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+31}:\\
\;\;\;\;\frac{x \cdot x}{t_1} - \frac{t_0}{t_1}\\
\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+151}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;1 + -8 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 1.99999999999999982e-298 or 1.9999999999999999e31 < (*.f64 x x) < 4.00000000000000007e151Initial program 48.2%
Taylor expanded in x around 0 38.9%
*-commutative38.9%
unpow238.9%
associate-*r*38.9%
Simplified38.9%
div-sub38.8%
associate-*r*38.8%
associate-/r*38.8%
frac-times38.8%
pow238.8%
*-commutative38.8%
*-inverses85.1%
Applied egg-rr85.1%
unpow285.1%
clear-num85.1%
un-div-inv85.1%
Applied egg-rr85.1%
if 1.99999999999999982e-298 < (*.f64 x x) < 1.9999999999999999e31Initial program 88.2%
div-sub88.2%
sub-neg88.2%
associate-/l*88.2%
+-commutative88.2%
*-commutative88.2%
fma-udef88.2%
*-commutative88.2%
associate-/l*88.5%
+-commutative88.5%
*-commutative88.5%
fma-udef88.5%
Applied egg-rr88.5%
sub-neg88.5%
associate-/r/88.5%
associate-*l/88.6%
fma-def88.6%
+-commutative88.6%
fma-def88.6%
associate-/r/88.4%
associate-*l/88.2%
fma-def88.2%
+-commutative88.2%
fma-def88.2%
Simplified88.2%
fma-udef88.2%
*-commutative88.2%
+-commutative88.2%
*-commutative88.2%
Applied egg-rr88.2%
fma-udef88.2%
*-commutative88.2%
+-commutative88.2%
*-commutative88.2%
Applied egg-rr88.2%
if 4.00000000000000007e151 < (*.f64 x x) Initial program 23.8%
sub-neg23.8%
+-commutative23.8%
distribute-rgt-neg-in23.8%
fma-def23.8%
Applied egg-rr23.8%
Taylor expanded in y around 0 67.3%
unpow267.3%
unpow267.3%
times-frac76.8%
unpow276.8%
Simplified76.8%
unpow276.8%
clear-num76.8%
un-div-inv76.8%
Applied egg-rr76.8%
Final simplification82.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))) (t_1 (+ (/ (/ (/ x y) (/ y x)) 4.0) -1.0)))
(if (<= (* x x) 2e-298)
t_1
(if (<= (* x x) 2e+31)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(if (<= (* x x) 4e+151) t_1 (+ 1.0 (* -8.0 (/ (/ y x) (/ x y)))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = (((x / y) / (y / x)) / 4.0) + -1.0;
double tmp;
if ((x * x) <= 2e-298) {
tmp = t_1;
} else if ((x * x) <= 2e+31) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else if ((x * x) <= 4e+151) {
tmp = t_1;
} else {
tmp = 1.0 + (-8.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) :: t_1
real(8) :: tmp
t_0 = y * (y * 4.0d0)
t_1 = (((x / y) / (y / x)) / 4.0d0) + (-1.0d0)
if ((x * x) <= 2d-298) then
tmp = t_1
else if ((x * x) <= 2d+31) then
tmp = ((x * x) - t_0) / ((x * x) + t_0)
else if ((x * x) <= 4d+151) then
tmp = t_1
else
tmp = 1.0d0 + ((-8.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 t_1 = (((x / y) / (y / x)) / 4.0) + -1.0;
double tmp;
if ((x * x) <= 2e-298) {
tmp = t_1;
} else if ((x * x) <= 2e+31) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else if ((x * x) <= 4e+151) {
tmp = t_1;
} else {
tmp = 1.0 + (-8.0 * ((y / x) / (x / y)));
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) t_1 = (((x / y) / (y / x)) / 4.0) + -1.0 tmp = 0 if (x * x) <= 2e-298: tmp = t_1 elif (x * x) <= 2e+31: tmp = ((x * x) - t_0) / ((x * x) + t_0) elif (x * x) <= 4e+151: tmp = t_1 else: tmp = 1.0 + (-8.0 * ((y / x) / (x / y))) return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) t_1 = Float64(Float64(Float64(Float64(x / y) / Float64(y / x)) / 4.0) + -1.0) tmp = 0.0 if (Float64(x * x) <= 2e-298) tmp = t_1; elseif (Float64(x * x) <= 2e+31) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); elseif (Float64(x * x) <= 4e+151) tmp = t_1; else tmp = Float64(1.0 + Float64(-8.0 * Float64(Float64(y / x) / Float64(x / y)))); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (y * 4.0); t_1 = (((x / y) / (y / x)) / 4.0) + -1.0; tmp = 0.0; if ((x * x) <= 2e-298) tmp = t_1; elseif ((x * x) <= 2e+31) tmp = ((x * x) - t_0) / ((x * x) + t_0); elseif ((x * x) <= 4e+151) tmp = t_1; else tmp = 1.0 + (-8.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]}, Block[{t$95$1 = N[(N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 2e-298], t$95$1, If[LessEqual[N[(x * x), $MachinePrecision], 2e+31], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+151], t$95$1, N[(1.0 + N[(-8.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)\\
t_1 := \frac{\frac{\frac{x}{y}}{\frac{y}{x}}}{4} + -1\\
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-298}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+31}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+151}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;1 + -8 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 1.99999999999999982e-298 or 1.9999999999999999e31 < (*.f64 x x) < 4.00000000000000007e151Initial program 48.2%
Taylor expanded in x around 0 38.9%
*-commutative38.9%
unpow238.9%
associate-*r*38.9%
Simplified38.9%
div-sub38.8%
associate-*r*38.8%
associate-/r*38.8%
frac-times38.8%
pow238.8%
*-commutative38.8%
*-inverses85.1%
Applied egg-rr85.1%
unpow285.1%
clear-num85.1%
un-div-inv85.1%
Applied egg-rr85.1%
if 1.99999999999999982e-298 < (*.f64 x x) < 1.9999999999999999e31Initial program 88.2%
if 4.00000000000000007e151 < (*.f64 x x) Initial program 23.8%
sub-neg23.8%
+-commutative23.8%
distribute-rgt-neg-in23.8%
fma-def23.8%
Applied egg-rr23.8%
Taylor expanded in y around 0 67.3%
unpow267.3%
unpow267.3%
times-frac76.8%
unpow276.8%
Simplified76.8%
unpow276.8%
clear-num76.8%
un-div-inv76.8%
Applied egg-rr76.8%
Final simplification82.5%
(FPCore (x y) :precision binary64 (if (<= (* y (* y 4.0)) 1e+61) (+ 1.0 (* -8.0 (/ (/ y x) (/ x y)))) (+ (/ (/ (/ x y) (/ y x)) 4.0) -1.0)))
double code(double x, double y) {
double tmp;
if ((y * (y * 4.0)) <= 1e+61) {
tmp = 1.0 + (-8.0 * ((y / x) / (x / y)));
} else {
tmp = (((x / y) / (y / x)) / 4.0) + -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 * (y * 4.0d0)) <= 1d+61) then
tmp = 1.0d0 + ((-8.0d0) * ((y / x) / (x / y)))
else
tmp = (((x / y) / (y / x)) / 4.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * (y * 4.0)) <= 1e+61) {
tmp = 1.0 + (-8.0 * ((y / x) / (x / y)));
} else {
tmp = (((x / y) / (y / x)) / 4.0) + -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * (y * 4.0)) <= 1e+61: tmp = 1.0 + (-8.0 * ((y / x) / (x / y))) else: tmp = (((x / y) / (y / x)) / 4.0) + -1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(y * Float64(y * 4.0)) <= 1e+61) tmp = Float64(1.0 + Float64(-8.0 * Float64(Float64(y / x) / Float64(x / y)))); else tmp = Float64(Float64(Float64(Float64(x / y) / Float64(y / x)) / 4.0) + -1.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * (y * 4.0)) <= 1e+61) tmp = 1.0 + (-8.0 * ((y / x) / (x / y))); else tmp = (((x / y) / (y / x)) / 4.0) + -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision], 1e+61], N[(1.0 + N[(-8.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot \left(y \cdot 4\right) \leq 10^{+61}:\\
\;\;\;\;1 + -8 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{x}{y}}{\frac{y}{x}}}{4} + -1\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 9.99999999999999949e60Initial program 61.1%
sub-neg61.1%
+-commutative61.1%
distribute-rgt-neg-in61.1%
fma-def61.1%
Applied egg-rr61.1%
Taylor expanded in y around 0 67.0%
unpow267.0%
unpow267.0%
times-frac71.4%
unpow271.4%
Simplified71.4%
unpow271.4%
clear-num71.4%
un-div-inv71.4%
Applied egg-rr71.4%
if 9.99999999999999949e60 < (*.f64 (*.f64 y 4) y) Initial program 36.0%
Taylor expanded in x around 0 33.4%
*-commutative33.4%
unpow233.4%
associate-*r*33.4%
Simplified33.4%
div-sub33.4%
associate-*r*33.4%
associate-/r*33.4%
frac-times33.4%
pow233.4%
*-commutative33.4%
*-inverses79.4%
Applied egg-rr79.4%
unpow279.4%
clear-num79.4%
un-div-inv79.4%
Applied egg-rr79.4%
Final simplification75.3%
(FPCore (x y) :precision binary64 (if (<= y 6e+33) (+ 1.0 (* -8.0 (/ (/ y x) (/ x y)))) -1.0))
double code(double x, double y) {
double tmp;
if (y <= 6e+33) {
tmp = 1.0 + (-8.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 (y <= 6d+33) then
tmp = 1.0d0 + ((-8.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 (y <= 6e+33) {
tmp = 1.0 + (-8.0 * ((y / x) / (x / y)));
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6e+33: tmp = 1.0 + (-8.0 * ((y / x) / (x / y))) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 6e+33) tmp = Float64(1.0 + Float64(-8.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 (y <= 6e+33) tmp = 1.0 + (-8.0 * ((y / x) / (x / y))); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6e+33], N[(1.0 + N[(-8.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6 \cdot 10^{+33}:\\
\;\;\;\;1 + -8 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 5.99999999999999967e33Initial program 54.9%
sub-neg54.9%
+-commutative54.9%
distribute-rgt-neg-in54.9%
fma-def54.9%
Applied egg-rr54.9%
Taylor expanded in y around 0 51.5%
unpow251.5%
unpow251.5%
times-frac55.7%
unpow255.7%
Simplified55.7%
unpow255.7%
clear-num55.7%
un-div-inv55.7%
Applied egg-rr55.7%
if 5.99999999999999967e33 < y Initial program 29.5%
Taylor expanded in x around 0 79.4%
Final simplification61.4%
(FPCore (x y) :precision binary64 (if (<= y 1.3e-10) 1.0 -1.0))
double code(double x, double y) {
double tmp;
if (y <= 1.3e-10) {
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 <= 1.3d-10) 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 <= 1.3e-10) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.3e-10: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.3e-10) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.3e-10) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.3e-10], 1.0, -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.3 \cdot 10^{-10}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.29999999999999991e-10Initial program 54.2%
Taylor expanded in x around inf 55.0%
if 1.29999999999999991e-10 < y Initial program 33.3%
Taylor expanded in x around 0 79.5%
Final simplification61.3%
(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 48.8%
Taylor expanded in x around 0 54.2%
Final simplification54.2%
(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 2023271
(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))))