
(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
double code(double x, double y) {
return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x - y) * (x + y)) / ((x * x) + (y * y))
end function
public static double code(double x, double y) {
return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
def code(x, y): return ((x - y) * (x + y)) / ((x * x) + (y * y))
function code(x, y) return Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) end
function tmp = code(x, y) tmp = ((x - y) * (x + y)) / ((x * x) + (y * y)); end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
double code(double x, double y) {
return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x - y) * (x + y)) / ((x * x) + (y * y))
end function
public static double code(double x, double y) {
return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
def code(x, y): return ((x - y) * (x + y)) / ((x * x) + (y * y))
function code(x, y) return Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) end
function tmp = code(x, y) tmp = ((x - y) * (x + y)) / ((x * x) + (y * y)); end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\end{array}
(FPCore (x y) :precision binary64 (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y))))
double code(double x, double y) {
return ((x - y) / hypot(x, y)) * ((x + y) / hypot(x, y));
}
public static double code(double x, double y) {
return ((x - y) / Math.hypot(x, y)) * ((x + y) / Math.hypot(x, y));
}
def code(x, y): return ((x - y) / math.hypot(x, y)) * ((x + y) / math.hypot(x, y))
function code(x, y) return Float64(Float64(Float64(x - y) / hypot(x, y)) * Float64(Float64(x + y) / hypot(x, y))) end
function tmp = code(x, y) tmp = ((x - y) / hypot(x, y)) * ((x + y) / hypot(x, y)); end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Initial program 67.6%
add-sqr-sqrt67.6%
times-frac67.9%
hypot-define67.9%
hypot-define100.0%
Applied egg-rr100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))) (if (<= t_0 2.0) t_0 (* (/ (+ x y) (hypot x y)) (+ (/ x y) -1.0)))))
double code(double x, double y) {
double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = ((x + y) / hypot(x, y)) * ((x / y) + -1.0);
}
return tmp;
}
public static double code(double x, double y) {
double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = ((x + y) / Math.hypot(x, y)) * ((x / y) + -1.0);
}
return tmp;
}
def code(x, y): t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y)) tmp = 0 if t_0 <= 2.0: tmp = t_0 else: tmp = ((x + y) / math.hypot(x, y)) * ((x / y) + -1.0) return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(Float64(Float64(x + y) / hypot(x, y)) * Float64(Float64(x / y) + -1.0)); end return tmp end
function tmp_2 = code(x, y) t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y)); tmp = 0.0; if (t_0 <= 2.0) tmp = t_0; else tmp = ((x + y) / hypot(x, y)) * ((x / y) + -1.0); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(N[(N[(x + y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\mathbf{if}\;t\_0 \leq 2:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(\frac{x}{y} + -1\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2Initial program 100.0%
if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) Initial program 0.0%
add-sqr-sqrt0.0%
times-frac3.1%
hypot-define3.1%
hypot-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 12.2%
Final simplification71.5%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))) (if (<= t_0 2.0) t_0 (+ (* 2.0 (pow (/ x y) 2.0)) -1.0))))
double code(double x, double y) {
double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = (2.0 * pow((x / y), 2.0)) + -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = (2.0d0 * ((x / y) ** 2.0d0)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = (2.0 * Math.pow((x / y), 2.0)) + -1.0;
}
return tmp;
}
def code(x, y): t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y)) tmp = 0 if t_0 <= 2.0: tmp = t_0 else: tmp = (2.0 * math.pow((x / y), 2.0)) + -1.0 return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(Float64(2.0 * (Float64(x / y) ^ 2.0)) + -1.0); end return tmp end
function tmp_2 = code(x, y) t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y)); tmp = 0.0; if (t_0 <= 2.0) tmp = t_0; else tmp = (2.0 * ((x / y) ^ 2.0)) + -1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(N[(2.0 * N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\mathbf{if}\;t\_0 \leq 2:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;2 \cdot {\left(\frac{x}{y}\right)}^{2} + -1\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2Initial program 100.0%
if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) Initial program 0.0%
add-sqr-sqrt0.0%
times-frac3.1%
hypot-define3.1%
hypot-define100.0%
Applied egg-rr100.0%
div-sub100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 55.4%
fma-neg55.4%
unpow255.4%
unpow255.4%
times-frac74.9%
unpow274.9%
metadata-eval74.9%
Simplified74.9%
fma-undefine74.9%
Applied egg-rr74.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ -1.0 (* 2.0 (/ x (* y (/ y x))))))
(t_1 (/ (- x y) (+ x (* y (+ -1.0 (/ y x)))))))
(if (<= y 1.3e-169)
t_1
(if (<= y 2.7e-101)
t_0
(if (<= y 6.8e-99)
t_1
(if (<= y 5.8e-27)
(/ (+ (- x y) (* (- x y) (/ x y))) y)
(if (<= y 6e-27) 1.0 t_0)))))))
double code(double x, double y) {
double t_0 = -1.0 + (2.0 * (x / (y * (y / x))));
double t_1 = (x - y) / (x + (y * (-1.0 + (y / x))));
double tmp;
if (y <= 1.3e-169) {
tmp = t_1;
} else if (y <= 2.7e-101) {
tmp = t_0;
} else if (y <= 6.8e-99) {
tmp = t_1;
} else if (y <= 5.8e-27) {
tmp = ((x - y) + ((x - y) * (x / y))) / y;
} else if (y <= 6e-27) {
tmp = 1.0;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (-1.0d0) + (2.0d0 * (x / (y * (y / x))))
t_1 = (x - y) / (x + (y * ((-1.0d0) + (y / x))))
if (y <= 1.3d-169) then
tmp = t_1
else if (y <= 2.7d-101) then
tmp = t_0
else if (y <= 6.8d-99) then
tmp = t_1
else if (y <= 5.8d-27) then
tmp = ((x - y) + ((x - y) * (x / y))) / y
else if (y <= 6d-27) then
tmp = 1.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = -1.0 + (2.0 * (x / (y * (y / x))));
double t_1 = (x - y) / (x + (y * (-1.0 + (y / x))));
double tmp;
if (y <= 1.3e-169) {
tmp = t_1;
} else if (y <= 2.7e-101) {
tmp = t_0;
} else if (y <= 6.8e-99) {
tmp = t_1;
} else if (y <= 5.8e-27) {
tmp = ((x - y) + ((x - y) * (x / y))) / y;
} else if (y <= 6e-27) {
tmp = 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = -1.0 + (2.0 * (x / (y * (y / x)))) t_1 = (x - y) / (x + (y * (-1.0 + (y / x)))) tmp = 0 if y <= 1.3e-169: tmp = t_1 elif y <= 2.7e-101: tmp = t_0 elif y <= 6.8e-99: tmp = t_1 elif y <= 5.8e-27: tmp = ((x - y) + ((x - y) * (x / y))) / y elif y <= 6e-27: tmp = 1.0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(-1.0 + Float64(2.0 * Float64(x / Float64(y * Float64(y / x))))) t_1 = Float64(Float64(x - y) / Float64(x + Float64(y * Float64(-1.0 + Float64(y / x))))) tmp = 0.0 if (y <= 1.3e-169) tmp = t_1; elseif (y <= 2.7e-101) tmp = t_0; elseif (y <= 6.8e-99) tmp = t_1; elseif (y <= 5.8e-27) tmp = Float64(Float64(Float64(x - y) + Float64(Float64(x - y) * Float64(x / y))) / y); elseif (y <= 6e-27) tmp = 1.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = -1.0 + (2.0 * (x / (y * (y / x)))); t_1 = (x - y) / (x + (y * (-1.0 + (y / x)))); tmp = 0.0; if (y <= 1.3e-169) tmp = t_1; elseif (y <= 2.7e-101) tmp = t_0; elseif (y <= 6.8e-99) tmp = t_1; elseif (y <= 5.8e-27) tmp = ((x - y) + ((x - y) * (x / y))) / y; elseif (y <= 6e-27) tmp = 1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(-1.0 + N[(2.0 * N[(x / N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x - y), $MachinePrecision] / N[(x + N[(y * N[(-1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 1.3e-169], t$95$1, If[LessEqual[y, 2.7e-101], t$95$0, If[LessEqual[y, 6.8e-99], t$95$1, If[LessEqual[y, 5.8e-27], N[(N[(N[(x - y), $MachinePrecision] + N[(N[(x - y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 6e-27], 1.0, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + 2 \cdot \frac{x}{y \cdot \frac{y}{x}}\\
t_1 := \frac{x - y}{x + y \cdot \left(-1 + \frac{y}{x}\right)}\\
\mathbf{if}\;y \leq 1.3 \cdot 10^{-169}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-101}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-99}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{-27}:\\
\;\;\;\;\frac{\left(x - y\right) + \left(x - y\right) \cdot \frac{x}{y}}{y}\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-27}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < 1.30000000000000007e-169 or 2.7000000000000002e-101 < y < 6.80000000000000014e-99Initial program 61.9%
associate-/l*62.4%
+-commutative62.4%
fma-define62.4%
Simplified62.4%
Taylor expanded in x around inf 37.6%
clear-num37.6%
un-div-inv37.7%
Applied egg-rr37.7%
Taylor expanded in y around 0 37.0%
if 1.30000000000000007e-169 < y < 2.7000000000000002e-101 or 6.0000000000000002e-27 < y Initial program 100.0%
add-sqr-sqrt100.0%
times-frac96.0%
hypot-define96.2%
hypot-define100.0%
Applied egg-rr100.0%
div-sub100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 76.9%
fma-neg76.9%
unpow276.9%
unpow276.9%
times-frac77.2%
unpow277.2%
metadata-eval77.2%
Simplified77.2%
fma-undefine77.2%
Applied egg-rr77.2%
unpow277.2%
clear-num77.2%
frac-times77.2%
*-un-lft-identity77.2%
Applied egg-rr77.2%
if 6.80000000000000014e-99 < y < 5.80000000000000008e-27Initial program 100.0%
associate-/l*99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around inf 92.1%
associate-*r/92.1%
Applied egg-rr92.1%
distribute-rgt-in92.1%
*-un-lft-identity92.1%
Applied egg-rr92.1%
if 5.80000000000000008e-27 < y < 6.0000000000000002e-27Initial program 100.0%
associate-/l*100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Final simplification43.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))) (if (<= t_0 2.0) t_0 (+ -1.0 (* 2.0 (/ x (* y (/ y x))))))))
double code(double x, double y) {
double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = -1.0 + (2.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) :: tmp
t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = (-1.0d0) + (2.0d0 * (x / (y * (y / x))))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = -1.0 + (2.0 * (x / (y * (y / x))));
}
return tmp;
}
def code(x, y): t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y)) tmp = 0 if t_0 <= 2.0: tmp = t_0 else: tmp = -1.0 + (2.0 * (x / (y * (y / x)))) return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(-1.0 + Float64(2.0 * Float64(x / Float64(y * Float64(y / x))))); end return tmp end
function tmp_2 = code(x, y) t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y)); tmp = 0.0; if (t_0 <= 2.0) tmp = t_0; else tmp = -1.0 + (2.0 * (x / (y * (y / x)))); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(-1.0 + N[(2.0 * N[(x / N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\mathbf{if}\;t\_0 \leq 2:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-1 + 2 \cdot \frac{x}{y \cdot \frac{y}{x}}\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2Initial program 100.0%
if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) Initial program 0.0%
add-sqr-sqrt0.0%
times-frac3.1%
hypot-define3.1%
hypot-define100.0%
Applied egg-rr100.0%
div-sub100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 55.4%
fma-neg55.4%
unpow255.4%
unpow255.4%
times-frac74.9%
unpow274.9%
metadata-eval74.9%
Simplified74.9%
fma-undefine74.9%
Applied egg-rr74.9%
unpow274.9%
clear-num74.9%
frac-times74.7%
*-un-lft-identity74.7%
Applied egg-rr74.7%
Final simplification91.8%
(FPCore (x y)
:precision binary64
(if (<= y 4e-160)
1.0
(if (<= y 7.5e-123)
-1.0
(if (<= y 1.15e-122)
1.0
(if (<= y 9.5e-45) -1.0 (if (<= y 9.8e-45) 1.0 -1.0))))))
double code(double x, double y) {
double tmp;
if (y <= 4e-160) {
tmp = 1.0;
} else if (y <= 7.5e-123) {
tmp = -1.0;
} else if (y <= 1.15e-122) {
tmp = 1.0;
} else if (y <= 9.5e-45) {
tmp = -1.0;
} else if (y <= 9.8e-45) {
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 <= 4d-160) then
tmp = 1.0d0
else if (y <= 7.5d-123) then
tmp = -1.0d0
else if (y <= 1.15d-122) then
tmp = 1.0d0
else if (y <= 9.5d-45) then
tmp = -1.0d0
else if (y <= 9.8d-45) 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 <= 4e-160) {
tmp = 1.0;
} else if (y <= 7.5e-123) {
tmp = -1.0;
} else if (y <= 1.15e-122) {
tmp = 1.0;
} else if (y <= 9.5e-45) {
tmp = -1.0;
} else if (y <= 9.8e-45) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4e-160: tmp = 1.0 elif y <= 7.5e-123: tmp = -1.0 elif y <= 1.15e-122: tmp = 1.0 elif y <= 9.5e-45: tmp = -1.0 elif y <= 9.8e-45: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 4e-160) tmp = 1.0; elseif (y <= 7.5e-123) tmp = -1.0; elseif (y <= 1.15e-122) tmp = 1.0; elseif (y <= 9.5e-45) tmp = -1.0; elseif (y <= 9.8e-45) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4e-160) tmp = 1.0; elseif (y <= 7.5e-123) tmp = -1.0; elseif (y <= 1.15e-122) tmp = 1.0; elseif (y <= 9.5e-45) tmp = -1.0; elseif (y <= 9.8e-45) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4e-160], 1.0, If[LessEqual[y, 7.5e-123], -1.0, If[LessEqual[y, 1.15e-122], 1.0, If[LessEqual[y, 9.5e-45], -1.0, If[LessEqual[y, 9.8e-45], 1.0, -1.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4 \cdot 10^{-160}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{-123}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{-122}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{-45}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 9.8 \cdot 10^{-45}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 4e-160 or 7.50000000000000011e-123 < y < 1.15000000000000003e-122 or 9.5000000000000002e-45 < y < 9.7999999999999996e-45Initial program 61.8%
associate-/l*62.1%
+-commutative62.1%
fma-define62.1%
Simplified62.1%
Taylor expanded in x around inf 36.2%
if 4e-160 < y < 7.50000000000000011e-123 or 1.15000000000000003e-122 < y < 9.5000000000000002e-45 or 9.7999999999999996e-45 < y Initial program 100.0%
associate-/l*98.0%
+-commutative98.0%
fma-define98.0%
Simplified98.0%
Taylor expanded in x around 0 79.8%
(FPCore (x y) :precision binary64 (if (<= y 1.3e-197) (+ 1.0 (* -1.5 (/ (/ y x) (/ x y)))) (+ -1.0 (* 2.0 (/ x (* y (/ y x)))))))
double code(double x, double y) {
double tmp;
if (y <= 1.3e-197) {
tmp = 1.0 + (-1.5 * ((y / x) / (x / y)));
} else {
tmp = -1.0 + (2.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 (y <= 1.3d-197) then
tmp = 1.0d0 + ((-1.5d0) * ((y / x) / (x / y)))
else
tmp = (-1.0d0) + (2.0d0 * (x / (y * (y / x))))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.3e-197) {
tmp = 1.0 + (-1.5 * ((y / x) / (x / y)));
} else {
tmp = -1.0 + (2.0 * (x / (y * (y / x))));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.3e-197: tmp = 1.0 + (-1.5 * ((y / x) / (x / y))) else: tmp = -1.0 + (2.0 * (x / (y * (y / x)))) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.3e-197) tmp = Float64(1.0 + Float64(-1.5 * Float64(Float64(y / x) / Float64(x / y)))); else tmp = Float64(-1.0 + Float64(2.0 * Float64(x / Float64(y * Float64(y / x))))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.3e-197) tmp = 1.0 + (-1.5 * ((y / x) / (x / y))); else tmp = -1.0 + (2.0 * (x / (y * (y / x)))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.3e-197], N[(1.0 + N[(-1.5 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(2.0 * N[(x / N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.3 \cdot 10^{-197}:\\
\;\;\;\;1 + -1.5 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\mathbf{else}:\\
\;\;\;\;-1 + 2 \cdot \frac{x}{y \cdot \frac{y}{x}}\\
\end{array}
\end{array}
if y < 1.3000000000000001e-197Initial program 62.1%
add-sqr-sqrt62.1%
times-frac62.9%
hypot-define62.9%
hypot-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 37.9%
Taylor expanded in y around 0 27.2%
+-commutative27.2%
fma-define27.2%
unpow227.2%
unpow227.2%
times-frac37.4%
unpow237.4%
Simplified37.4%
fma-undefine37.4%
Applied egg-rr37.4%
unpow237.4%
clear-num37.4%
un-div-inv37.4%
Applied egg-rr37.4%
if 1.3000000000000001e-197 < y Initial program 93.3%
add-sqr-sqrt93.3%
times-frac91.3%
hypot-define91.4%
hypot-define100.0%
Applied egg-rr100.0%
div-sub100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 69.9%
fma-neg69.9%
unpow269.9%
unpow269.9%
times-frac76.9%
unpow276.9%
metadata-eval76.9%
Simplified76.9%
fma-undefine76.9%
Applied egg-rr76.9%
unpow276.9%
clear-num76.9%
frac-times76.9%
*-un-lft-identity76.9%
Applied egg-rr76.9%
Final simplification44.4%
(FPCore (x y) :precision binary64 (if (<= y 1.3e-197) (+ 1.0 (* -1.5 (/ (/ y x) (/ x y)))) (* (- x y) (/ (+ (/ x y) 1.0) y))))
double code(double x, double y) {
double tmp;
if (y <= 1.3e-197) {
tmp = 1.0 + (-1.5 * ((y / x) / (x / y)));
} else {
tmp = (x - y) * (((x / y) + 1.0) / y);
}
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-197) then
tmp = 1.0d0 + ((-1.5d0) * ((y / x) / (x / y)))
else
tmp = (x - y) * (((x / y) + 1.0d0) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.3e-197) {
tmp = 1.0 + (-1.5 * ((y / x) / (x / y)));
} else {
tmp = (x - y) * (((x / y) + 1.0) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.3e-197: tmp = 1.0 + (-1.5 * ((y / x) / (x / y))) else: tmp = (x - y) * (((x / y) + 1.0) / y) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.3e-197) tmp = Float64(1.0 + Float64(-1.5 * Float64(Float64(y / x) / Float64(x / y)))); else tmp = Float64(Float64(x - y) * Float64(Float64(Float64(x / y) + 1.0) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.3e-197) tmp = 1.0 + (-1.5 * ((y / x) / (x / y))); else tmp = (x - y) * (((x / y) + 1.0) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.3e-197], N[(1.0 + N[(-1.5 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.3 \cdot 10^{-197}:\\
\;\;\;\;1 + -1.5 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\mathbf{else}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{\frac{x}{y} + 1}{y}\\
\end{array}
\end{array}
if y < 1.3000000000000001e-197Initial program 62.1%
add-sqr-sqrt62.1%
times-frac62.9%
hypot-define62.9%
hypot-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 37.9%
Taylor expanded in y around 0 27.2%
+-commutative27.2%
fma-define27.2%
unpow227.2%
unpow227.2%
times-frac37.4%
unpow237.4%
Simplified37.4%
fma-undefine37.4%
Applied egg-rr37.4%
unpow237.4%
clear-num37.4%
un-div-inv37.4%
Applied egg-rr37.4%
if 1.3000000000000001e-197 < y Initial program 93.3%
associate-/l*91.0%
+-commutative91.0%
fma-define91.0%
Simplified91.0%
Taylor expanded in y around inf 76.7%
Final simplification44.3%
(FPCore (x y) :precision binary64 (if (<= y 1.3e-197) (* (+ 1.0 (/ y x)) (- 1.0 (/ y x))) (* (- x y) (/ (+ (/ x y) 1.0) y))))
double code(double x, double y) {
double tmp;
if (y <= 1.3e-197) {
tmp = (1.0 + (y / x)) * (1.0 - (y / x));
} else {
tmp = (x - y) * (((x / y) + 1.0) / y);
}
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-197) then
tmp = (1.0d0 + (y / x)) * (1.0d0 - (y / x))
else
tmp = (x - y) * (((x / y) + 1.0d0) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.3e-197) {
tmp = (1.0 + (y / x)) * (1.0 - (y / x));
} else {
tmp = (x - y) * (((x / y) + 1.0) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.3e-197: tmp = (1.0 + (y / x)) * (1.0 - (y / x)) else: tmp = (x - y) * (((x / y) + 1.0) / y) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.3e-197) tmp = Float64(Float64(1.0 + Float64(y / x)) * Float64(1.0 - Float64(y / x))); else tmp = Float64(Float64(x - y) * Float64(Float64(Float64(x / y) + 1.0) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.3e-197) tmp = (1.0 + (y / x)) * (1.0 - (y / x)); else tmp = (x - y) * (((x / y) + 1.0) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.3e-197], N[(N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.3 \cdot 10^{-197}:\\
\;\;\;\;\left(1 + \frac{y}{x}\right) \cdot \left(1 - \frac{y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{\frac{x}{y} + 1}{y}\\
\end{array}
\end{array}
if y < 1.3000000000000001e-197Initial program 62.1%
associate-/l*62.6%
+-commutative62.6%
fma-define62.6%
Simplified62.6%
Taylor expanded in x around inf 37.3%
clear-num37.3%
un-div-inv37.4%
Applied egg-rr37.4%
div-inv37.3%
clear-num37.3%
Applied egg-rr37.3%
associate-*r/37.4%
associate-*l/37.4%
*-commutative37.4%
div-sub37.4%
*-inverses37.4%
Simplified37.4%
if 1.3000000000000001e-197 < y Initial program 93.3%
associate-/l*91.0%
+-commutative91.0%
fma-define91.0%
Simplified91.0%
Taylor expanded in y around inf 76.7%
Final simplification44.3%
(FPCore (x y) :precision binary64 (if (<= y 2.2e-181) (* (+ 1.0 (/ y x)) (- 1.0 (/ y x))) -1.0))
double code(double x, double y) {
double tmp;
if (y <= 2.2e-181) {
tmp = (1.0 + (y / x)) * (1.0 - (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 <= 2.2d-181) then
tmp = (1.0d0 + (y / x)) * (1.0d0 - (y / x))
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.2e-181) {
tmp = (1.0 + (y / x)) * (1.0 - (y / x));
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.2e-181: tmp = (1.0 + (y / x)) * (1.0 - (y / x)) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 2.2e-181) tmp = Float64(Float64(1.0 + Float64(y / x)) * Float64(1.0 - Float64(y / x))); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.2e-181) tmp = (1.0 + (y / x)) * (1.0 - (y / x)); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.2e-181], N[(N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.2 \cdot 10^{-181}:\\
\;\;\;\;\left(1 + \frac{y}{x}\right) \cdot \left(1 - \frac{y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 2.19999999999999997e-181Initial program 61.9%
associate-/l*62.4%
+-commutative62.4%
fma-define62.4%
Simplified62.4%
Taylor expanded in x around inf 37.6%
clear-num37.6%
un-div-inv37.7%
Applied egg-rr37.7%
div-inv37.6%
clear-num37.6%
Applied egg-rr37.6%
associate-*r/37.7%
associate-*l/37.7%
*-commutative37.7%
div-sub37.7%
*-inverses37.7%
Simplified37.7%
if 2.19999999999999997e-181 < y Initial program 97.6%
associate-/l*94.9%
+-commutative94.9%
fma-define94.9%
Simplified94.9%
Taylor expanded in x around 0 78.4%
(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 67.6%
associate-/l*67.6%
+-commutative67.6%
fma-define67.6%
Simplified67.6%
Taylor expanded in x around 0 66.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (fabs (/ x y))))
(if (and (< 0.5 t_0) (< t_0 2.0))
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
(- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))))
double code(double x, double y) {
double t_0 = fabs((x / y));
double tmp;
if ((0.5 < t_0) && (t_0 < 2.0)) {
tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
} else {
tmp = 1.0 - (2.0 / (1.0 + ((x / y) * (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) :: tmp
t_0 = abs((x / y))
if ((0.5d0 < t_0) .and. (t_0 < 2.0d0)) then
tmp = ((x - y) * (x + y)) / ((x * x) + (y * y))
else
tmp = 1.0d0 - (2.0d0 / (1.0d0 + ((x / y) * (x / y))))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = Math.abs((x / y));
double tmp;
if ((0.5 < t_0) && (t_0 < 2.0)) {
tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
} else {
tmp = 1.0 - (2.0 / (1.0 + ((x / y) * (x / y))));
}
return tmp;
}
def code(x, y): t_0 = math.fabs((x / y)) tmp = 0 if (0.5 < t_0) and (t_0 < 2.0): tmp = ((x - y) * (x + y)) / ((x * x) + (y * y)) else: tmp = 1.0 - (2.0 / (1.0 + ((x / y) * (x / y)))) return tmp
function code(x, y) t_0 = abs(Float64(x / y)) tmp = 0.0 if ((0.5 < t_0) && (t_0 < 2.0)) tmp = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))); else tmp = Float64(1.0 - Float64(2.0 / Float64(1.0 + Float64(Float64(x / y) * Float64(x / y))))); end return tmp end
function tmp_2 = code(x, y) t_0 = abs((x / y)); tmp = 0.0; if ((0.5 < t_0) && (t_0 < 2.0)) tmp = ((x - y) * (x + y)) / ((x * x) + (y * y)); else tmp = 1.0 - (2.0 / (1.0 + ((x / y) * (x / y)))); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision]}, If[And[Less[0.5, t$95$0], Less[t$95$0, 2.0]], N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(2.0 / N[(1.0 + N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{x}{y}\right|\\
\mathbf{if}\;0.5 < t\_0 \land t\_0 < 2:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{2}{1 + \frac{x}{y} \cdot \frac{x}{y}}\\
\end{array}
\end{array}
herbie shell --seed 2024107
(FPCore (x y)
:name "Kahan p9 Example"
:precision binary64
:pre (and (and (< 0.0 x) (< x 1.0)) (< y 1.0))
:alt
(if (and (< 0.5 (fabs (/ x y))) (< (fabs (/ x y)) 2.0)) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))