
(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 15 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)) (/ (hypot x y) (+ x y))))
double code(double x, double y) {
return ((x - y) / hypot(x, y)) / (hypot(x, y) / (x + y));
}
public static double code(double x, double y) {
return ((x - y) / Math.hypot(x, y)) / (Math.hypot(x, y) / (x + y));
}
def code(x, y): return ((x - y) / math.hypot(x, y)) / (math.hypot(x, y) / (x + y))
function code(x, y) return Float64(Float64(Float64(x - y) / hypot(x, y)) / Float64(hypot(x, y) / Float64(x + y))) end
function tmp = code(x, y) tmp = ((x - y) / hypot(x, y)) / (hypot(x, y) / (x + y)); end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}
\end{array}
Initial program 68.7%
fma-define68.7%
add-sqr-sqrt68.7%
times-frac68.8%
fma-define68.8%
hypot-define68.8%
fma-define68.8%
hypot-define100.0%
Applied egg-rr100.0%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
Final simplification100.0%
(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 (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 = fma(2.0, 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 = fma(2.0, (Float64(x / y) ^ 2.0), -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[Power[N[(x / y), $MachinePrecision], 2.0], $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, {\left(\frac{x}{y}\right)}^{2}, -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%
fma-define0.0%
add-sqr-sqrt0.0%
times-frac3.1%
fma-define3.1%
hypot-define3.1%
fma-define3.1%
hypot-define99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 52.5%
fma-neg52.5%
unpow252.5%
unpow252.5%
times-frac80.2%
unpow280.2%
metadata-eval80.2%
Simplified80.2%
Final simplification93.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))) (if (<= t_0 0.5) t_0 (fma (pow (/ y x) 2.0) -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 <= 0.5) {
tmp = t_0;
} else {
tmp = fma(pow((y / x), 2.0), -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 <= 0.5) tmp = t_0; else tmp = fma((Float64(y / x) ^ 2.0), -2.0, 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, 0.5], t$95$0, N[(N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision] * -2.0 + 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 0.5:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\left(\frac{y}{x}\right)}^{2}, -2, 1\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 0.5Initial program 100.0%
if 0.5 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) Initial program 43.7%
fma-define43.7%
add-sqr-sqrt43.7%
times-frac44.7%
fma-define44.7%
hypot-define44.8%
fma-define44.8%
hypot-define100.0%
Applied egg-rr100.0%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 44.6%
+-commutative44.6%
*-commutative44.6%
fma-define44.6%
unpow244.6%
unpow244.6%
times-frac56.4%
unpow256.4%
Simplified56.4%
Final simplification75.8%
(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 68.7%
fma-define68.7%
add-sqr-sqrt68.7%
times-frac68.8%
fma-define68.8%
hypot-define68.8%
fma-define68.8%
hypot-define100.0%
Applied egg-rr100.0%
Final simplification100.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) (/ (+ 1.0 (- (/ x y) (pow (/ x y) 2.0))) y)))))
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) * ((1.0 + ((x / y) - pow((x / y), 2.0))) / 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 = ((x - y) * (x + y)) / ((x * x) + (y * y))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = (x - y) * ((1.0d0 + ((x / y) - ((x / y) ** 2.0d0))) / y)
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 = (x - y) * ((1.0 + ((x / y) - Math.pow((x / y), 2.0))) / y);
}
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) * ((1.0 + ((x / y) - math.pow((x / y), 2.0))) / y) 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(x - y) * Float64(Float64(1.0 + Float64(Float64(x / y) - (Float64(x / y) ^ 2.0))) / y)); 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) * ((1.0 + ((x / y) - ((x / y) ^ 2.0))) / y); 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[(x - y), $MachinePrecision] * N[(N[(1.0 + N[(N[(x / y), $MachinePrecision] - N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $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}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{1 + \left(\frac{x}{y} - {\left(\frac{x}{y}\right)}^{2}\right)}{y}\\
\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%
associate-/l*3.1%
fma-define3.1%
Simplified3.1%
*-un-lft-identity3.1%
add-sqr-sqrt3.1%
times-frac3.1%
fma-define3.1%
hypot-define3.1%
fma-define3.1%
hypot-define99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 52.4%
+-commutative52.4%
mul-1-neg52.4%
unsub-neg52.4%
unpow252.4%
unpow252.4%
times-frac78.9%
unpow278.9%
Simplified78.9%
Final simplification93.4%
(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 (/ (hypot x y) (- x y))) (+ 1.0 (/ x y))))))
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 / (hypot(x, y) / (x - y))) * (1.0 + (x / y));
}
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 = (1.0 / (Math.hypot(x, y) / (x - y))) * (1.0 + (x / y));
}
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 / (math.hypot(x, y) / (x - y))) * (1.0 + (x / y)) 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(1.0 / Float64(hypot(x, y) / Float64(x - y))) * Float64(1.0 + Float64(x / y))); 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 / (hypot(x, y) / (x - y))) * (1.0 + (x / y)); 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[(1.0 / N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(x / y), $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{\mathsf{hypot}\left(x, y\right)}{x - y}} \cdot \left(1 + \frac{x}{y}\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%
fma-define0.0%
add-sqr-sqrt0.0%
times-frac3.1%
fma-define3.1%
hypot-define3.1%
fma-define3.1%
hypot-define99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 14.1%
+-commutative14.1%
Simplified14.1%
clear-num14.1%
inv-pow14.1%
Applied egg-rr14.1%
unpow-114.1%
Simplified14.1%
Final simplification73.1%
(FPCore (x y) :precision binary64 (if (<= x 4.3e-161) (* (/ (- x y) (hypot x y)) (+ 1.0 (/ x y))) (* (- x y) (/ (+ x y) (fma x x (* y y))))))
double code(double x, double y) {
double tmp;
if (x <= 4.3e-161) {
tmp = ((x - y) / hypot(x, y)) * (1.0 + (x / y));
} else {
tmp = (x - y) * ((x + y) / fma(x, x, (y * y)));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= 4.3e-161) tmp = Float64(Float64(Float64(x - y) / hypot(x, y)) * Float64(1.0 + Float64(x / y))); else tmp = Float64(Float64(x - y) * Float64(Float64(x + y) / fma(x, x, Float64(y * y)))); end return tmp end
code[x_, y_] := If[LessEqual[x, 4.3e-161], N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / N[(x * x + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.3 \cdot 10^{-161}:\\
\;\;\;\;\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(1 + \frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}\\
\end{array}
\end{array}
if x < 4.29999999999999967e-161Initial program 53.0%
fma-define53.0%
add-sqr-sqrt53.0%
times-frac53.3%
fma-define53.3%
hypot-define53.3%
fma-define53.3%
hypot-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 24.4%
+-commutative24.4%
Simplified24.4%
if 4.29999999999999967e-161 < x Initial program 82.0%
associate-/l*81.5%
fma-define81.5%
Simplified81.5%
Final simplification55.4%
(FPCore (x y) :precision binary64 (if (<= x 2.7e-61) (* (- x y) (/ (+ 1.0 (/ x y)) y)) (* (/ (- x y) (hypot x y)) (+ (/ y x) 1.0))))
double code(double x, double y) {
double tmp;
if (x <= 2.7e-61) {
tmp = (x - y) * ((1.0 + (x / y)) / y);
} else {
tmp = ((x - y) / hypot(x, y)) * ((y / x) + 1.0);
}
return tmp;
}
public static double code(double x, double y) {
double tmp;
if (x <= 2.7e-61) {
tmp = (x - y) * ((1.0 + (x / y)) / y);
} else {
tmp = ((x - y) / Math.hypot(x, y)) * ((y / x) + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 2.7e-61: tmp = (x - y) * ((1.0 + (x / y)) / y) else: tmp = ((x - y) / math.hypot(x, y)) * ((y / x) + 1.0) return tmp
function code(x, y) tmp = 0.0 if (x <= 2.7e-61) tmp = Float64(Float64(x - y) * Float64(Float64(1.0 + Float64(x / y)) / y)); else tmp = Float64(Float64(Float64(x - y) / hypot(x, y)) * Float64(Float64(y / x) + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 2.7e-61) tmp = (x - y) * ((1.0 + (x / y)) / y); else tmp = ((x - y) / hypot(x, y)) * ((y / x) + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 2.7e-61], N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(y / x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.7 \cdot 10^{-61}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(\frac{y}{x} + 1\right)\\
\end{array}
\end{array}
if x < 2.69999999999999993e-61Initial program 65.2%
associate-/l*64.9%
fma-define64.9%
Simplified64.9%
Taylor expanded in y around inf 76.5%
if 2.69999999999999993e-61 < x Initial program 83.6%
fma-define83.7%
add-sqr-sqrt83.7%
times-frac84.2%
fma-define84.2%
hypot-define84.2%
fma-define84.2%
hypot-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 65.4%
Final simplification74.4%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (- x y) (hypot x y)))) (if (<= y 5.2e-198) (* t_0 (+ (/ y x) 1.0)) (* t_0 (+ 1.0 (/ x y))))))
double code(double x, double y) {
double t_0 = (x - y) / hypot(x, y);
double tmp;
if (y <= 5.2e-198) {
tmp = t_0 * ((y / x) + 1.0);
} else {
tmp = t_0 * (1.0 + (x / y));
}
return tmp;
}
public static double code(double x, double y) {
double t_0 = (x - y) / Math.hypot(x, y);
double tmp;
if (y <= 5.2e-198) {
tmp = t_0 * ((y / x) + 1.0);
} else {
tmp = t_0 * (1.0 + (x / y));
}
return tmp;
}
def code(x, y): t_0 = (x - y) / math.hypot(x, y) tmp = 0 if y <= 5.2e-198: tmp = t_0 * ((y / x) + 1.0) else: tmp = t_0 * (1.0 + (x / y)) return tmp
function code(x, y) t_0 = Float64(Float64(x - y) / hypot(x, y)) tmp = 0.0 if (y <= 5.2e-198) tmp = Float64(t_0 * Float64(Float64(y / x) + 1.0)); else tmp = Float64(t_0 * Float64(1.0 + Float64(x / y))); end return tmp end
function tmp_2 = code(x, y) t_0 = (x - y) / hypot(x, y); tmp = 0.0; if (y <= 5.2e-198) tmp = t_0 * ((y / x) + 1.0); else tmp = t_0 * (1.0 + (x / y)); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 5.2e-198], N[(t$95$0 * N[(N[(y / x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{\mathsf{hypot}\left(x, y\right)}\\
\mathbf{if}\;y \leq 5.2 \cdot 10^{-198}:\\
\;\;\;\;t\_0 \cdot \left(\frac{y}{x} + 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(1 + \frac{x}{y}\right)\\
\end{array}
\end{array}
if y < 5.20000000000000014e-198Initial program 64.2%
fma-define64.2%
add-sqr-sqrt64.2%
times-frac64.2%
fma-define64.2%
hypot-define64.3%
fma-define64.3%
hypot-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 35.1%
if 5.20000000000000014e-198 < y Initial program 85.4%
fma-define85.4%
add-sqr-sqrt85.4%
times-frac85.4%
fma-define85.4%
hypot-define85.5%
fma-define85.5%
hypot-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 72.8%
+-commutative72.8%
Simplified72.8%
Final simplification43.2%
(FPCore (x y) :precision binary64 (if (<= x 1.2e-60) (* (- x y) (/ (+ 1.0 (/ x y)) y)) (+ 1.0 (* (pow (/ y x) 2.0) -1.5))))
double code(double x, double y) {
double tmp;
if (x <= 1.2e-60) {
tmp = (x - y) * ((1.0 + (x / y)) / y);
} else {
tmp = 1.0 + (pow((y / x), 2.0) * -1.5);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 1.2d-60) then
tmp = (x - y) * ((1.0d0 + (x / y)) / y)
else
tmp = 1.0d0 + (((y / x) ** 2.0d0) * (-1.5d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.2e-60) {
tmp = (x - y) * ((1.0 + (x / y)) / y);
} else {
tmp = 1.0 + (Math.pow((y / x), 2.0) * -1.5);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.2e-60: tmp = (x - y) * ((1.0 + (x / y)) / y) else: tmp = 1.0 + (math.pow((y / x), 2.0) * -1.5) return tmp
function code(x, y) tmp = 0.0 if (x <= 1.2e-60) tmp = Float64(Float64(x - y) * Float64(Float64(1.0 + Float64(x / y)) / y)); else tmp = Float64(1.0 + Float64((Float64(y / x) ^ 2.0) * -1.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.2e-60) tmp = (x - y) * ((1.0 + (x / y)) / y); else tmp = 1.0 + (((y / x) ^ 2.0) * -1.5); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.2e-60], N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[Power[N[(y / x), $MachinePrecision], 2.0], $MachinePrecision] * -1.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.2 \cdot 10^{-60}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{x}{y}}{y}\\
\mathbf{else}:\\
\;\;\;\;1 + {\left(\frac{y}{x}\right)}^{2} \cdot -1.5\\
\end{array}
\end{array}
if x < 1.20000000000000005e-60Initial program 65.2%
associate-/l*64.9%
fma-define64.9%
Simplified64.9%
Taylor expanded in y around inf 76.5%
if 1.20000000000000005e-60 < x Initial program 83.6%
fma-define83.7%
add-sqr-sqrt83.7%
times-frac84.2%
fma-define84.2%
hypot-define84.2%
fma-define84.2%
hypot-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 65.4%
Taylor expanded in x around inf 64.9%
+-commutative64.9%
associate-+r+64.9%
distribute-rgt-out64.9%
metadata-eval64.9%
*-commutative64.9%
associate-+l+64.9%
unpow264.9%
unpow264.9%
times-frac64.9%
unpow264.9%
distribute-rgt1-in64.9%
metadata-eval64.9%
mul0-lft65.0%
Simplified65.0%
Final simplification74.3%
(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) (/ (+ -1.0 (* x (+ (/ 1.0 y) (/ 2.0 x)))) y)))))
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) * ((-1.0 + (x * ((1.0 / y) + (2.0 / 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 = ((x - y) * (x + y)) / ((x * x) + (y * y))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = (x - y) * (((-1.0d0) + (x * ((1.0d0 / y) + (2.0d0 / x)))) / y)
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 = (x - y) * ((-1.0 + (x * ((1.0 / y) + (2.0 / x)))) / y);
}
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) * ((-1.0 + (x * ((1.0 / y) + (2.0 / x)))) / y) 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(x - y) * Float64(Float64(-1.0 + Float64(x * Float64(Float64(1.0 / y) + Float64(2.0 / x)))) / y)); 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) * ((-1.0 + (x * ((1.0 / y) + (2.0 / x)))) / y); 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[(x - y), $MachinePrecision] * N[(N[(-1.0 + N[(x * N[(N[(1.0 / y), $MachinePrecision] + N[(2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $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}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{-1 + x \cdot \left(\frac{1}{y} + \frac{2}{x}\right)}{y}\\
\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%
associate-/l*3.1%
fma-define3.1%
Simplified3.1%
Taylor expanded in y around inf 79.0%
expm1-log1p-u78.4%
expm1-undefine78.4%
Applied egg-rr78.4%
sub-neg78.4%
log1p-undefine78.4%
rem-exp-log79.0%
associate-+r+79.0%
metadata-eval79.0%
metadata-eval79.0%
Simplified79.0%
Taylor expanded in x around inf 78.7%
+-commutative78.7%
associate-*r/78.7%
metadata-eval78.7%
Simplified78.7%
Final simplification93.3%
(FPCore (x y) :precision binary64 (if (<= x 2.3e-162) (/ (- x y) y) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
double code(double x, double y) {
double tmp;
if (x <= 2.3e-162) {
tmp = (x - y) / y;
} else {
tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 2.3d-162) then
tmp = (x - y) / y
else
tmp = ((x - y) * (x + y)) / ((x * x) + (y * y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 2.3e-162) {
tmp = (x - y) / y;
} else {
tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 2.3e-162: tmp = (x - y) / y else: tmp = ((x - y) * (x + y)) / ((x * x) + (y * y)) return tmp
function code(x, y) tmp = 0.0 if (x <= 2.3e-162) tmp = Float64(Float64(x - y) / y); else tmp = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 2.3e-162) tmp = (x - y) / y; else tmp = ((x - y) * (x + y)) / ((x * x) + (y * y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 2.3e-162], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], 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}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.3 \cdot 10^{-162}:\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\end{array}
\end{array}
if x < 2.2999999999999998e-162Initial program 53.0%
associate-/l*53.0%
fma-define53.0%
Simplified53.0%
Taylor expanded in x around 0 84.9%
un-div-inv85.2%
Applied egg-rr85.2%
if 2.2999999999999998e-162 < x Initial program 82.0%
Final simplification83.5%
(FPCore (x y) :precision binary64 (if (<= x 1.95e-60) -1.0 (/ (- x y) x)))
double code(double x, double y) {
double tmp;
if (x <= 1.95e-60) {
tmp = -1.0;
} else {
tmp = (x - y) / x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 1.95d-60) then
tmp = -1.0d0
else
tmp = (x - y) / x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.95e-60) {
tmp = -1.0;
} else {
tmp = (x - y) / x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.95e-60: tmp = -1.0 else: tmp = (x - y) / x return tmp
function code(x, y) tmp = 0.0 if (x <= 1.95e-60) tmp = -1.0; else tmp = Float64(Float64(x - y) / x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.95e-60) tmp = -1.0; else tmp = (x - y) / x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.95e-60], -1.0, N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.95 \cdot 10^{-60}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y}{x}\\
\end{array}
\end{array}
if x < 1.9500000000000001e-60Initial program 65.2%
associate-/l*64.9%
fma-define64.9%
Simplified64.9%
Taylor expanded in x around 0 75.9%
if 1.9500000000000001e-60 < x Initial program 83.6%
associate-/l*83.7%
fma-define83.8%
Simplified83.8%
Taylor expanded in x around inf 63.6%
un-div-inv63.7%
Applied egg-rr63.7%
Final simplification73.6%
(FPCore (x y) :precision binary64 (/ (- x y) y))
double code(double x, double y) {
return (x - y) / y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x - y) / y
end function
public static double code(double x, double y) {
return (x - y) / y;
}
def code(x, y): return (x - y) / y
function code(x, y) return Float64(Float64(x - y) / y) end
function tmp = code(x, y) tmp = (x - y) / y; end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{y}
\end{array}
Initial program 68.7%
associate-/l*68.5%
fma-define68.5%
Simplified68.5%
Taylor expanded in x around 0 68.1%
un-div-inv68.2%
Applied egg-rr68.2%
Final simplification68.2%
(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 68.7%
associate-/l*68.5%
fma-define68.5%
Simplified68.5%
Taylor expanded in x around 0 68.2%
Final simplification68.2%
(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 2024066
(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))))