
(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 12 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) / Float64(hypot(x, y) / 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[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{x - y}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Initial program 70.0%
add-sqr-sqrt70.0%
times-frac70.4%
hypot-define70.4%
hypot-define99.9%
Applied egg-rr99.9%
associate-*l/99.9%
clear-num99.9%
un-div-inv100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (* (- x y) (/ (/ (+ x y) (hypot x y)) (hypot x y))))
double code(double x, double y) {
return (x - y) * (((x + y) / hypot(x, y)) / hypot(x, y));
}
public static double code(double x, double y) {
return (x - y) * (((x + y) / Math.hypot(x, y)) / Math.hypot(x, y));
}
def code(x, y): return (x - y) * (((x + y) / math.hypot(x, y)) / math.hypot(x, y))
function code(x, y) return Float64(Float64(x - y) * Float64(Float64(Float64(x + y) / hypot(x, y)) / hypot(x, y))) end
function tmp = code(x, y) tmp = (x - y) * (((x + y) / hypot(x, y)) / hypot(x, y)); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] * N[(N[(N[(x + y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x - y\right) \cdot \frac{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Initial program 70.0%
associate-/l*70.2%
+-commutative70.2%
fma-define70.2%
Simplified70.2%
fma-undefine70.2%
+-commutative70.2%
add-cube-cbrt68.9%
add-sqr-sqrt68.9%
times-frac68.9%
pow268.9%
hypot-define68.9%
hypot-define97.7%
Applied egg-rr97.7%
associate-*l/97.7%
div-inv97.7%
associate-*r*97.7%
unpow297.7%
add-cube-cbrt99.7%
div-inv99.7%
Applied egg-rr99.7%
Final simplification99.7%
(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 70.0%
add-sqr-sqrt70.0%
times-frac70.4%
hypot-define70.4%
hypot-define99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))) (if (<= t_0 2.0) t_0 (fma 2.0 (/ (/ x y) (/ y x)) -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 = fma(2.0, ((x / y) / (y / x)), -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 = fma(2.0, Float64(Float64(x / y) / Float64(y / x)), -1.0); end return 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[(2.0 * N[(N[(x / y), $MachinePrecision] / N[(y / x), $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}:\\
\;\;\;\;\mathsf{fma}\left(2, \frac{\frac{x}{y}}{\frac{y}{x}}, -1\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2Initial program 99.6%
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-define99.9%
Applied egg-rr99.9%
associate-*l/99.9%
clear-num99.9%
un-div-inv99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 53.9%
fma-neg53.9%
unpow253.9%
unpow253.9%
times-frac82.4%
unpow282.4%
metadata-eval82.4%
Simplified82.4%
unpow282.4%
clear-num82.4%
un-div-inv82.4%
Applied egg-rr82.4%
Final simplification94.5%
(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 (/ y (- (+ y (* (/ x y) (- y x))) 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 / (y / ((y + ((x / y) * (y - x))) - x));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = (-1.0d0) / (y / ((y + ((x / y) * (y - x))) - 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 / (y / ((y + ((x / y) * (y - x))) - 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 / (y / ((y + ((x / y) * (y - x))) - 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(y / Float64(Float64(y + Float64(Float64(x / y) * Float64(y - x))) - 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 / (y / ((y + ((x / y) * (y - x))) - 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[(y / N[(N[(y + N[(N[(x / y), $MachinePrecision] * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $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}:\\
\;\;\;\;\frac{-1}{\frac{y}{\left(y + \frac{x}{y} \cdot \left(y - x\right)\right) - x}}\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2Initial program 99.6%
if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) Initial program 0.0%
associate-/l*3.1%
+-commutative3.1%
fma-define3.1%
Simplified3.1%
Taylor expanded in y around inf 80.6%
associate-*r/81.0%
clear-num81.0%
Applied egg-rr81.0%
distribute-rgt-in81.0%
*-un-lft-identity81.0%
associate-+l-81.0%
Applied egg-rr81.0%
Final simplification94.1%
(FPCore (x y) :precision binary64 (if (<= y 3.1e-169) (- 1.0 (/ (* 2.0 (* y (/ y x))) x)) (/ -1.0 (/ y (- (+ y (* (/ x y) (- y x))) x)))))
double code(double x, double y) {
double tmp;
if (y <= 3.1e-169) {
tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
} else {
tmp = -1.0 / (y / ((y + ((x / y) * (y - x))) - x));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 3.1d-169) then
tmp = 1.0d0 - ((2.0d0 * (y * (y / x))) / x)
else
tmp = (-1.0d0) / (y / ((y + ((x / y) * (y - x))) - x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.1e-169) {
tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
} else {
tmp = -1.0 / (y / ((y + ((x / y) * (y - x))) - x));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.1e-169: tmp = 1.0 - ((2.0 * (y * (y / x))) / x) else: tmp = -1.0 / (y / ((y + ((x / y) * (y - x))) - x)) return tmp
function code(x, y) tmp = 0.0 if (y <= 3.1e-169) tmp = Float64(1.0 - Float64(Float64(2.0 * Float64(y * Float64(y / x))) / x)); else tmp = Float64(-1.0 / Float64(y / Float64(Float64(y + Float64(Float64(x / y) * Float64(y - x))) - x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.1e-169) tmp = 1.0 - ((2.0 * (y * (y / x))) / x); else tmp = -1.0 / (y / ((y + ((x / y) * (y - x))) - x)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.1e-169], N[(1.0 - N[(N[(2.0 * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(-1.0 / N[(y / N[(N[(y + N[(N[(x / y), $MachinePrecision] * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.1 \cdot 10^{-169}:\\
\;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{y}{\left(y + \frac{x}{y} \cdot \left(y - x\right)\right) - x}}\\
\end{array}
\end{array}
if y < 3.1000000000000002e-169Initial program 63.5%
associate-/l*63.9%
+-commutative63.9%
fma-define63.9%
Simplified63.9%
Taylor expanded in x around -inf 37.7%
mul-1-neg37.7%
unsub-neg37.7%
Simplified38.2%
Taylor expanded in y around 0 37.7%
div-inv37.7%
unpow237.7%
associate-*r*38.6%
div-inv38.6%
Applied egg-rr38.6%
if 3.1000000000000002e-169 < y Initial program 94.4%
associate-/l*94.1%
+-commutative94.1%
fma-define94.1%
Simplified94.1%
Taylor expanded in y around inf 76.2%
associate-*r/76.3%
clear-num76.3%
Applied egg-rr76.3%
distribute-rgt-in76.4%
*-un-lft-identity76.4%
associate-+l-76.4%
Applied egg-rr76.4%
Final simplification46.5%
(FPCore (x y) :precision binary64 (if (<= y 2.2e-169) 1.0 (* (+ (/ x y) 1.0) (+ (/ x y) -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 2.2e-169) {
tmp = 1.0;
} else {
tmp = ((x / y) + 1.0) * ((x / y) + -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-169) then
tmp = 1.0d0
else
tmp = ((x / y) + 1.0d0) * ((x / y) + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.2e-169) {
tmp = 1.0;
} else {
tmp = ((x / y) + 1.0) * ((x / y) + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.2e-169: tmp = 1.0 else: tmp = ((x / y) + 1.0) * ((x / y) + -1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.2e-169) tmp = 1.0; else tmp = Float64(Float64(Float64(x / y) + 1.0) * Float64(Float64(x / y) + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.2e-169) tmp = 1.0; else tmp = ((x / y) + 1.0) * ((x / y) + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.2e-169], 1.0, N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.2 \cdot 10^{-169}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{x}{y} + 1\right) \cdot \left(\frac{x}{y} + -1\right)\\
\end{array}
\end{array}
if y < 2.20000000000000007e-169Initial program 63.5%
associate-/l*63.9%
+-commutative63.9%
fma-define63.9%
Simplified63.9%
Taylor expanded in x around inf 36.4%
if 2.20000000000000007e-169 < y Initial program 94.4%
associate-/l*94.1%
+-commutative94.1%
fma-define94.1%
Simplified94.1%
Taylor expanded in y around inf 76.2%
associate-*r/76.3%
Applied egg-rr76.3%
associate-/l*76.2%
Applied egg-rr76.2%
associate-*r/76.3%
*-commutative76.3%
associate-*r/76.4%
div-sub76.3%
sub-neg76.3%
*-inverses76.3%
metadata-eval76.3%
Simplified76.3%
Final simplification44.8%
(FPCore (x y) :precision binary64 (if (<= y 2.5e-169) (* (- x y) (/ (+ (/ y x) 1.0) x)) (* (+ (/ x y) 1.0) (+ (/ x y) -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 2.5e-169) {
tmp = (x - y) * (((y / x) + 1.0) / x);
} else {
tmp = ((x / y) + 1.0) * ((x / y) + -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.5d-169) then
tmp = (x - y) * (((y / x) + 1.0d0) / x)
else
tmp = ((x / y) + 1.0d0) * ((x / y) + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.5e-169) {
tmp = (x - y) * (((y / x) + 1.0) / x);
} else {
tmp = ((x / y) + 1.0) * ((x / y) + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.5e-169: tmp = (x - y) * (((y / x) + 1.0) / x) else: tmp = ((x / y) + 1.0) * ((x / y) + -1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.5e-169) tmp = Float64(Float64(x - y) * Float64(Float64(Float64(y / x) + 1.0) / x)); else tmp = Float64(Float64(Float64(x / y) + 1.0) * Float64(Float64(x / y) + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.5e-169) tmp = (x - y) * (((y / x) + 1.0) / x); else tmp = ((x / y) + 1.0) * ((x / y) + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.5e-169], N[(N[(x - y), $MachinePrecision] * N[(N[(N[(y / x), $MachinePrecision] + 1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.5 \cdot 10^{-169}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{\frac{y}{x} + 1}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{x}{y} + 1\right) \cdot \left(\frac{x}{y} + -1\right)\\
\end{array}
\end{array}
if y < 2.5000000000000001e-169Initial program 63.5%
associate-/l*63.9%
+-commutative63.9%
fma-define63.9%
Simplified63.9%
Taylor expanded in x around inf 37.8%
if 2.5000000000000001e-169 < y Initial program 94.4%
associate-/l*94.1%
+-commutative94.1%
fma-define94.1%
Simplified94.1%
Taylor expanded in y around inf 76.2%
associate-*r/76.3%
Applied egg-rr76.3%
associate-/l*76.2%
Applied egg-rr76.2%
associate-*r/76.3%
*-commutative76.3%
associate-*r/76.4%
div-sub76.3%
sub-neg76.3%
*-inverses76.3%
metadata-eval76.3%
Simplified76.3%
Final simplification45.9%
(FPCore (x y) :precision binary64 (if (<= y 1.2e-169) (- 1.0 (/ (* 2.0 (* y (/ y x))) x)) (* (+ (/ x y) 1.0) (+ (/ x y) -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 1.2e-169) {
tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
} else {
tmp = ((x / y) + 1.0) * ((x / y) + -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.2d-169) then
tmp = 1.0d0 - ((2.0d0 * (y * (y / x))) / x)
else
tmp = ((x / y) + 1.0d0) * ((x / y) + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.2e-169) {
tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
} else {
tmp = ((x / y) + 1.0) * ((x / y) + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.2e-169: tmp = 1.0 - ((2.0 * (y * (y / x))) / x) else: tmp = ((x / y) + 1.0) * ((x / y) + -1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.2e-169) tmp = Float64(1.0 - Float64(Float64(2.0 * Float64(y * Float64(y / x))) / x)); else tmp = Float64(Float64(Float64(x / y) + 1.0) * Float64(Float64(x / y) + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.2e-169) tmp = 1.0 - ((2.0 * (y * (y / x))) / x); else tmp = ((x / y) + 1.0) * ((x / y) + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.2e-169], N[(1.0 - N[(N[(2.0 * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.2 \cdot 10^{-169}:\\
\;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{x}{y} + 1\right) \cdot \left(\frac{x}{y} + -1\right)\\
\end{array}
\end{array}
if y < 1.20000000000000005e-169Initial program 63.5%
associate-/l*63.9%
+-commutative63.9%
fma-define63.9%
Simplified63.9%
Taylor expanded in x around -inf 37.7%
mul-1-neg37.7%
unsub-neg37.7%
Simplified38.2%
Taylor expanded in y around 0 37.7%
div-inv37.7%
unpow237.7%
associate-*r*38.6%
div-inv38.6%
Applied egg-rr38.6%
if 1.20000000000000005e-169 < y Initial program 94.4%
associate-/l*94.1%
+-commutative94.1%
fma-define94.1%
Simplified94.1%
Taylor expanded in y around inf 76.2%
associate-*r/76.3%
Applied egg-rr76.3%
associate-/l*76.2%
Applied egg-rr76.2%
associate-*r/76.3%
*-commutative76.3%
associate-*r/76.4%
div-sub76.3%
sub-neg76.3%
*-inverses76.3%
metadata-eval76.3%
Simplified76.3%
Final simplification46.5%
(FPCore (x y) :precision binary64 (if (<= y 2e-170) (- 1.0 (/ (* 2.0 (* y (/ y x))) x)) (/ (* (- x y) (+ (/ x y) 1.0)) y)))
double code(double x, double y) {
double tmp;
if (y <= 2e-170) {
tmp = 1.0 - ((2.0 * (y * (y / x))) / 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 <= 2d-170) then
tmp = 1.0d0 - ((2.0d0 * (y * (y / x))) / 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 <= 2e-170) {
tmp = 1.0 - ((2.0 * (y * (y / x))) / x);
} else {
tmp = ((x - y) * ((x / y) + 1.0)) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2e-170: tmp = 1.0 - ((2.0 * (y * (y / x))) / x) else: tmp = ((x - y) * ((x / y) + 1.0)) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 2e-170) tmp = Float64(1.0 - Float64(Float64(2.0 * Float64(y * Float64(y / x))) / x)); else tmp = Float64(Float64(Float64(x - y) * Float64(Float64(x / y) + 1.0)) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2e-170) tmp = 1.0 - ((2.0 * (y * (y / x))) / x); else tmp = ((x - y) * ((x / y) + 1.0)) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2e-170], N[(1.0 - N[(N[(2.0 * N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x - y), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{-170}:\\
\;\;\;\;1 - \frac{2 \cdot \left(y \cdot \frac{y}{x}\right)}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(\frac{x}{y} + 1\right)}{y}\\
\end{array}
\end{array}
if y < 1.99999999999999997e-170Initial program 63.5%
associate-/l*63.9%
+-commutative63.9%
fma-define63.9%
Simplified63.9%
Taylor expanded in x around -inf 37.7%
mul-1-neg37.7%
unsub-neg37.7%
Simplified38.2%
Taylor expanded in y around 0 37.7%
div-inv37.7%
unpow237.7%
associate-*r*38.6%
div-inv38.6%
Applied egg-rr38.6%
if 1.99999999999999997e-170 < y Initial program 94.4%
associate-/l*94.1%
+-commutative94.1%
fma-define94.1%
Simplified94.1%
Taylor expanded in y around inf 76.2%
associate-*r/76.3%
Applied egg-rr76.3%
Final simplification46.5%
(FPCore (x y) :precision binary64 (if (<= y 2e-169) 1.0 -1.0))
double code(double x, double y) {
double tmp;
if (y <= 2e-169) {
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-169) 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-169) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2e-169: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 2e-169) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2e-169) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2e-169], 1.0, -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{-169}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 2.00000000000000004e-169Initial program 63.5%
associate-/l*63.9%
+-commutative63.9%
fma-define63.9%
Simplified63.9%
Taylor expanded in x around inf 36.4%
if 2.00000000000000004e-169 < y Initial program 94.4%
associate-/l*94.1%
+-commutative94.1%
fma-define94.1%
Simplified94.1%
Taylor expanded in x around 0 75.2%
Final simplification44.6%
(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 70.0%
associate-/l*70.2%
+-commutative70.2%
fma-define70.2%
Simplified70.2%
Taylor expanded in x around 0 65.7%
Final simplification65.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 2024077
(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))))