
(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 (let* ((t_0 (hypot x (* 2.0 y)))) (* (/ (fma 2.0 y x) t_0) (/ (+ x (* y -2.0)) t_0))))
double code(double x, double y) {
double t_0 = hypot(x, (2.0 * y));
return (fma(2.0, y, x) / t_0) * ((x + (y * -2.0)) / t_0);
}
function code(x, y) t_0 = hypot(x, Float64(2.0 * y)) return Float64(Float64(fma(2.0, y, 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[(2.0 * y), $MachinePrecision] ^ 2], $MachinePrecision]}, N[(N[(N[(2.0 * y + 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, 2 \cdot y\right)\\
\frac{\mathsf{fma}\left(2, y, x\right)}{t_0} \cdot \frac{x + y \cdot -2}{t_0}
\end{array}
\end{array}
Initial program 53.1%
add-sqr-sqrt53.1%
difference-of-squares53.1%
*-commutative53.1%
associate-*r*53.1%
sqrt-prod53.1%
sqrt-unprod21.4%
add-sqr-sqrt37.9%
metadata-eval37.9%
*-commutative37.9%
associate-*r*37.9%
sqrt-prod37.9%
sqrt-unprod21.4%
add-sqr-sqrt53.1%
metadata-eval53.1%
Applied egg-rr53.1%
add-sqr-sqrt53.1%
times-frac54.2%
+-commutative54.2%
*-commutative54.2%
fma-def54.2%
add-sqr-sqrt54.2%
hypot-def54.2%
sqrt-prod21.7%
*-commutative21.7%
sqrt-prod21.7%
metadata-eval21.7%
associate-*r*21.7%
add-sqr-sqrt54.2%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0)))
(t_1 (+ (* 0.5 (* (/ x y) (/ x y))) -1.0))
(t_2 (+ (* x x) t_0)))
(if (<= x 7e-161)
t_1
(if (<= x 1.22e-50)
(/ (- (* x x) t_0) t_2)
(if (<= x 6.5e-14)
t_1
(if (<= x 5e+93)
(/ (* (+ x (* 2.0 y)) (- x (* 2.0 y))) t_2)
(+ 1.0 (/ -8.0 (/ (/ x y) (/ y x))))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = (0.5 * ((x / y) * (x / y))) + -1.0;
double t_2 = (x * x) + t_0;
double tmp;
if (x <= 7e-161) {
tmp = t_1;
} else if (x <= 1.22e-50) {
tmp = ((x * x) - t_0) / t_2;
} else if (x <= 6.5e-14) {
tmp = t_1;
} else if (x <= 5e+93) {
tmp = ((x + (2.0 * y)) * (x - (2.0 * y))) / t_2;
} else {
tmp = 1.0 + (-8.0 / ((x / y) / (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 = (0.5d0 * ((x / y) * (x / y))) + (-1.0d0)
t_2 = (x * x) + t_0
if (x <= 7d-161) then
tmp = t_1
else if (x <= 1.22d-50) then
tmp = ((x * x) - t_0) / t_2
else if (x <= 6.5d-14) then
tmp = t_1
else if (x <= 5d+93) then
tmp = ((x + (2.0d0 * y)) * (x - (2.0d0 * y))) / t_2
else
tmp = 1.0d0 + ((-8.0d0) / ((x / y) / (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 = (0.5 * ((x / y) * (x / y))) + -1.0;
double t_2 = (x * x) + t_0;
double tmp;
if (x <= 7e-161) {
tmp = t_1;
} else if (x <= 1.22e-50) {
tmp = ((x * x) - t_0) / t_2;
} else if (x <= 6.5e-14) {
tmp = t_1;
} else if (x <= 5e+93) {
tmp = ((x + (2.0 * y)) * (x - (2.0 * y))) / t_2;
} else {
tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) t_1 = (0.5 * ((x / y) * (x / y))) + -1.0 t_2 = (x * x) + t_0 tmp = 0 if x <= 7e-161: tmp = t_1 elif x <= 1.22e-50: tmp = ((x * x) - t_0) / t_2 elif x <= 6.5e-14: tmp = t_1 elif x <= 5e+93: tmp = ((x + (2.0 * y)) * (x - (2.0 * y))) / t_2 else: tmp = 1.0 + (-8.0 / ((x / y) / (y / x))) return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) t_1 = Float64(Float64(0.5 * Float64(Float64(x / y) * Float64(x / y))) + -1.0) t_2 = Float64(Float64(x * x) + t_0) tmp = 0.0 if (x <= 7e-161) tmp = t_1; elseif (x <= 1.22e-50) tmp = Float64(Float64(Float64(x * x) - t_0) / t_2); elseif (x <= 6.5e-14) tmp = t_1; elseif (x <= 5e+93) tmp = Float64(Float64(Float64(x + Float64(2.0 * y)) * Float64(x - Float64(2.0 * y))) / t_2); else tmp = Float64(1.0 + Float64(-8.0 / Float64(Float64(x / y) / Float64(y / x)))); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (y * 4.0); t_1 = (0.5 * ((x / y) * (x / y))) + -1.0; t_2 = (x * x) + t_0; tmp = 0.0; if (x <= 7e-161) tmp = t_1; elseif (x <= 1.22e-50) tmp = ((x * x) - t_0) / t_2; elseif (x <= 6.5e-14) tmp = t_1; elseif (x <= 5e+93) tmp = ((x + (2.0 * y)) * (x - (2.0 * y))) / t_2; else tmp = 1.0 + (-8.0 / ((x / y) / (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[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]}, If[LessEqual[x, 7e-161], t$95$1, If[LessEqual[x, 1.22e-50], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / t$95$2), $MachinePrecision], If[LessEqual[x, 6.5e-14], t$95$1, If[LessEqual[x, 5e+93], N[(N[(N[(x + N[(2.0 * y), $MachinePrecision]), $MachinePrecision] * N[(x - N[(2.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision], N[(1.0 + N[(-8.0 / N[(N[(x / y), $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 := 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\
t_2 := x \cdot x + t_0\\
\mathbf{if}\;x \leq 7 \cdot 10^{-161}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.22 \cdot 10^{-50}:\\
\;\;\;\;\frac{x \cdot x - t_0}{t_2}\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{-14}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+93}:\\
\;\;\;\;\frac{\left(x + 2 \cdot y\right) \cdot \left(x - 2 \cdot y\right)}{t_2}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{-8}{\frac{\frac{x}{y}}{\frac{y}{x}}}\\
\end{array}
\end{array}
if x < 7.00000000000000039e-161 or 1.22000000000000007e-50 < x < 6.5000000000000001e-14Initial program 52.0%
Taylor expanded in x around 0 50.9%
pow250.9%
unpow250.9%
times-frac61.7%
Applied egg-rr61.7%
if 7.00000000000000039e-161 < x < 1.22000000000000007e-50Initial program 86.2%
if 6.5000000000000001e-14 < x < 5.0000000000000001e93Initial program 92.5%
add-sqr-sqrt92.5%
difference-of-squares92.5%
*-commutative92.5%
associate-*r*92.5%
sqrt-prod92.5%
sqrt-unprod48.1%
add-sqr-sqrt70.7%
metadata-eval70.7%
*-commutative70.7%
associate-*r*70.7%
sqrt-prod70.7%
sqrt-unprod48.1%
add-sqr-sqrt92.5%
metadata-eval92.5%
Applied egg-rr92.5%
if 5.0000000000000001e93 < x Initial program 18.5%
add-sqr-sqrt18.5%
difference-of-squares18.5%
*-commutative18.5%
associate-*r*18.5%
sqrt-prod18.5%
sqrt-unprod0.0%
add-sqr-sqrt18.5%
metadata-eval18.5%
*-commutative18.5%
associate-*r*18.5%
sqrt-prod18.5%
sqrt-unprod0.0%
add-sqr-sqrt18.5%
metadata-eval18.5%
Applied egg-rr18.5%
Taylor expanded in y around 0 63.3%
associate-*r/63.3%
associate-/l*63.3%
unpow263.3%
unpow263.3%
times-frac72.1%
unpow272.1%
Simplified72.1%
pow272.1%
clear-num72.1%
un-div-inv72.1%
Applied egg-rr72.1%
Final simplification69.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0)))
(t_1 (/ (- (* x x) t_0) (+ (* x x) t_0)))
(t_2 (+ (* 0.5 (* (/ x y) (/ x y))) -1.0)))
(if (<= x 1.5e-161)
t_2
(if (<= x 3.7e-51)
t_1
(if (<= x 1.28e-14)
t_2
(if (<= x 4.5e+93) t_1 (+ 1.0 (/ -8.0 (/ (/ x y) (/ 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 = (0.5 * ((x / y) * (x / y))) + -1.0;
double tmp;
if (x <= 1.5e-161) {
tmp = t_2;
} else if (x <= 3.7e-51) {
tmp = t_1;
} else if (x <= 1.28e-14) {
tmp = t_2;
} else if (x <= 4.5e+93) {
tmp = t_1;
} else {
tmp = 1.0 + (-8.0 / ((x / y) / (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 = (0.5d0 * ((x / y) * (x / y))) + (-1.0d0)
if (x <= 1.5d-161) then
tmp = t_2
else if (x <= 3.7d-51) then
tmp = t_1
else if (x <= 1.28d-14) then
tmp = t_2
else if (x <= 4.5d+93) then
tmp = t_1
else
tmp = 1.0d0 + ((-8.0d0) / ((x / y) / (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 = (0.5 * ((x / y) * (x / y))) + -1.0;
double tmp;
if (x <= 1.5e-161) {
tmp = t_2;
} else if (x <= 3.7e-51) {
tmp = t_1;
} else if (x <= 1.28e-14) {
tmp = t_2;
} else if (x <= 4.5e+93) {
tmp = t_1;
} else {
tmp = 1.0 + (-8.0 / ((x / y) / (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 = (0.5 * ((x / y) * (x / y))) + -1.0 tmp = 0 if x <= 1.5e-161: tmp = t_2 elif x <= 3.7e-51: tmp = t_1 elif x <= 1.28e-14: tmp = t_2 elif x <= 4.5e+93: tmp = t_1 else: tmp = 1.0 + (-8.0 / ((x / y) / (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(Float64(0.5 * Float64(Float64(x / y) * Float64(x / y))) + -1.0) tmp = 0.0 if (x <= 1.5e-161) tmp = t_2; elseif (x <= 3.7e-51) tmp = t_1; elseif (x <= 1.28e-14) tmp = t_2; elseif (x <= 4.5e+93) tmp = t_1; else tmp = Float64(1.0 + Float64(-8.0 / Float64(Float64(x / y) / 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 = (0.5 * ((x / y) * (x / y))) + -1.0; tmp = 0.0; if (x <= 1.5e-161) tmp = t_2; elseif (x <= 3.7e-51) tmp = t_1; elseif (x <= 1.28e-14) tmp = t_2; elseif (x <= 4.5e+93) tmp = t_1; else tmp = 1.0 + (-8.0 / ((x / y) / (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[(N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[x, 1.5e-161], t$95$2, If[LessEqual[x, 3.7e-51], t$95$1, If[LessEqual[x, 1.28e-14], t$95$2, If[LessEqual[x, 4.5e+93], t$95$1, N[(1.0 + N[(-8.0 / N[(N[(x / y), $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 := 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\
\mathbf{if}\;x \leq 1.5 \cdot 10^{-161}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-51}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.28 \cdot 10^{-14}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{+93}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{-8}{\frac{\frac{x}{y}}{\frac{y}{x}}}\\
\end{array}
\end{array}
if x < 1.49999999999999994e-161 or 3.69999999999999973e-51 < x < 1.28e-14Initial program 52.0%
Taylor expanded in x around 0 50.9%
pow250.9%
unpow250.9%
times-frac61.7%
Applied egg-rr61.7%
if 1.49999999999999994e-161 < x < 3.69999999999999973e-51 or 1.28e-14 < x < 4.49999999999999991e93Initial program 89.3%
if 4.49999999999999991e93 < x Initial program 18.5%
add-sqr-sqrt18.5%
difference-of-squares18.5%
*-commutative18.5%
associate-*r*18.5%
sqrt-prod18.5%
sqrt-unprod0.0%
add-sqr-sqrt18.5%
metadata-eval18.5%
*-commutative18.5%
associate-*r*18.5%
sqrt-prod18.5%
sqrt-unprod0.0%
add-sqr-sqrt18.5%
metadata-eval18.5%
Applied egg-rr18.5%
Taylor expanded in y around 0 63.3%
associate-*r/63.3%
associate-/l*63.3%
unpow263.3%
unpow263.3%
times-frac72.1%
unpow272.1%
Simplified72.1%
pow272.1%
clear-num72.1%
un-div-inv72.1%
Applied egg-rr72.1%
Final simplification69.9%
(FPCore (x y) :precision binary64 (if (or (<= y 9.8e-73) (and (not (<= y 1.55e-57)) (<= y 3600.0))) (+ 1.0 (/ -8.0 (/ (/ x y) (/ y x)))) -1.0))
double code(double x, double y) {
double tmp;
if ((y <= 9.8e-73) || (!(y <= 1.55e-57) && (y <= 3600.0))) {
tmp = 1.0 + (-8.0 / ((x / y) / (y / 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 <= 9.8d-73) .or. (.not. (y <= 1.55d-57)) .and. (y <= 3600.0d0)) then
tmp = 1.0d0 + ((-8.0d0) / ((x / y) / (y / x)))
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 9.8e-73) || (!(y <= 1.55e-57) && (y <= 3600.0))) {
tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 9.8e-73) or (not (y <= 1.55e-57) and (y <= 3600.0)): tmp = 1.0 + (-8.0 / ((x / y) / (y / x))) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= 9.8e-73) || (!(y <= 1.55e-57) && (y <= 3600.0))) tmp = Float64(1.0 + Float64(-8.0 / Float64(Float64(x / y) / Float64(y / x)))); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 9.8e-73) || (~((y <= 1.55e-57)) && (y <= 3600.0))) tmp = 1.0 + (-8.0 / ((x / y) / (y / x))); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 9.8e-73], And[N[Not[LessEqual[y, 1.55e-57]], $MachinePrecision], LessEqual[y, 3600.0]]], N[(1.0 + N[(-8.0 / N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.8 \cdot 10^{-73} \lor \neg \left(y \leq 1.55 \cdot 10^{-57}\right) \land y \leq 3600:\\
\;\;\;\;1 + \frac{-8}{\frac{\frac{x}{y}}{\frac{y}{x}}}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 9.80000000000000057e-73 or 1.54999999999999988e-57 < y < 3600Initial program 55.4%
add-sqr-sqrt55.4%
difference-of-squares55.4%
*-commutative55.4%
associate-*r*55.4%
sqrt-prod55.4%
sqrt-unprod15.3%
add-sqr-sqrt36.2%
metadata-eval36.2%
*-commutative36.2%
associate-*r*36.2%
sqrt-prod36.2%
sqrt-unprod15.3%
add-sqr-sqrt55.4%
metadata-eval55.4%
Applied egg-rr55.4%
Taylor expanded in y around 0 51.4%
associate-*r/51.4%
associate-/l*51.4%
unpow251.4%
unpow251.4%
times-frac57.2%
unpow257.2%
Simplified57.2%
pow257.2%
clear-num57.2%
un-div-inv57.2%
Applied egg-rr57.2%
if 9.80000000000000057e-73 < y < 1.54999999999999988e-57 or 3600 < y Initial program 44.4%
Taylor expanded in x around 0 81.7%
Final simplification62.3%
(FPCore (x y) :precision binary64 (if (<= x 3.7e-12) (+ (* 0.5 (* (/ x y) (/ x y))) -1.0) (+ 1.0 (/ -8.0 (/ (/ x y) (/ y x))))))
double code(double x, double y) {
double tmp;
if (x <= 3.7e-12) {
tmp = (0.5 * ((x / y) * (x / y))) + -1.0;
} else {
tmp = 1.0 + (-8.0 / ((x / y) / (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.7d-12) then
tmp = (0.5d0 * ((x / y) * (x / y))) + (-1.0d0)
else
tmp = 1.0d0 + ((-8.0d0) / ((x / y) / (y / x)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 3.7e-12) {
tmp = (0.5 * ((x / y) * (x / y))) + -1.0;
} else {
tmp = 1.0 + (-8.0 / ((x / y) / (y / x)));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 3.7e-12: tmp = (0.5 * ((x / y) * (x / y))) + -1.0 else: tmp = 1.0 + (-8.0 / ((x / y) / (y / x))) return tmp
function code(x, y) tmp = 0.0 if (x <= 3.7e-12) tmp = Float64(Float64(0.5 * Float64(Float64(x / y) * Float64(x / y))) + -1.0); else tmp = Float64(1.0 + Float64(-8.0 / Float64(Float64(x / y) / Float64(y / x)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 3.7e-12) tmp = (0.5 * ((x / y) * (x / y))) + -1.0; else tmp = 1.0 + (-8.0 / ((x / y) / (y / x))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 3.7e-12], N[(N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 + N[(-8.0 / N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.7 \cdot 10^{-12}:\\
\;\;\;\;0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{-8}{\frac{\frac{x}{y}}{\frac{y}{x}}}\\
\end{array}
\end{array}
if x < 3.69999999999999999e-12Initial program 57.7%
Taylor expanded in x around 0 54.1%
pow254.1%
unpow254.1%
times-frac63.1%
Applied egg-rr63.1%
if 3.69999999999999999e-12 < x Initial program 43.2%
add-sqr-sqrt43.2%
difference-of-squares43.2%
*-commutative43.2%
associate-*r*43.2%
sqrt-prod43.2%
sqrt-unprod16.0%
add-sqr-sqrt35.9%
metadata-eval35.9%
*-commutative35.9%
associate-*r*35.9%
sqrt-prod35.9%
sqrt-unprod16.0%
add-sqr-sqrt43.2%
metadata-eval43.2%
Applied egg-rr43.2%
Taylor expanded in y around 0 63.9%
associate-*r/63.9%
associate-/l*63.9%
unpow263.9%
unpow263.9%
times-frac69.8%
unpow269.8%
Simplified69.8%
pow269.8%
clear-num69.8%
un-div-inv69.8%
Applied egg-rr69.8%
Final simplification65.2%
(FPCore (x y) :precision binary64 (if (<= y 2e-73) 1.0 (if (<= y 1.25e-57) -1.0 (if (<= y 15000.0) 1.0 -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 2e-73) {
tmp = 1.0;
} else if (y <= 1.25e-57) {
tmp = -1.0;
} else if (y <= 15000.0) {
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 <= 2d-73) then
tmp = 1.0d0
else if (y <= 1.25d-57) then
tmp = -1.0d0
else if (y <= 15000.0d0) 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 <= 2e-73) {
tmp = 1.0;
} else if (y <= 1.25e-57) {
tmp = -1.0;
} else if (y <= 15000.0) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2e-73: tmp = 1.0 elif y <= 1.25e-57: tmp = -1.0 elif y <= 15000.0: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 2e-73) tmp = 1.0; elseif (y <= 1.25e-57) tmp = -1.0; elseif (y <= 15000.0) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2e-73) tmp = 1.0; elseif (y <= 1.25e-57) tmp = -1.0; elseif (y <= 15000.0) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2e-73], 1.0, If[LessEqual[y, 1.25e-57], -1.0, If[LessEqual[y, 15000.0], 1.0, -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{-73}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-57}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 15000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.99999999999999999e-73 or 1.25e-57 < y < 15000Initial program 55.4%
Taylor expanded in x around inf 55.5%
if 1.99999999999999999e-73 < y < 1.25e-57 or 15000 < y Initial program 44.4%
Taylor expanded in x around 0 81.7%
Final simplification61.0%
(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 53.1%
Taylor expanded in x around 0 52.5%
Final simplification52.5%
(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 2023322
(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))))