
(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)) (/ (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 (* (/ (- 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) (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%
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%
Final simplification73.1%
(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) 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) / 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) / 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) / 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) / 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) / 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) / 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] / y), $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}{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 x around 0 78.2%
un-div-inv78.4%
Applied egg-rr78.4%
Final simplification93.2%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (- x y) x)))
(if (<= y 5.2e-198)
t_0
(if (<= y 3.9e-149)
(/ (- x y) y)
(if (<= y 1.4e-134) t_0 (* (- x y) (/ (+ (/ x y) 1.0) y)))))))
double code(double x, double y) {
double t_0 = (x - y) / x;
double tmp;
if (y <= 5.2e-198) {
tmp = t_0;
} else if (y <= 3.9e-149) {
tmp = (x - y) / y;
} else if (y <= 1.4e-134) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (x - y) / x
if (y <= 5.2d-198) then
tmp = t_0
else if (y <= 3.9d-149) then
tmp = (x - y) / y
else if (y <= 1.4d-134) then
tmp = t_0
else
tmp = (x - y) * (((x / y) + 1.0d0) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x - y) / x;
double tmp;
if (y <= 5.2e-198) {
tmp = t_0;
} else if (y <= 3.9e-149) {
tmp = (x - y) / y;
} else if (y <= 1.4e-134) {
tmp = t_0;
} else {
tmp = (x - y) * (((x / y) + 1.0) / y);
}
return tmp;
}
def code(x, y): t_0 = (x - y) / x tmp = 0 if y <= 5.2e-198: tmp = t_0 elif y <= 3.9e-149: tmp = (x - y) / y elif y <= 1.4e-134: tmp = t_0 else: tmp = (x - y) * (((x / y) + 1.0) / y) return tmp
function code(x, y) t_0 = Float64(Float64(x - y) / x) tmp = 0.0 if (y <= 5.2e-198) tmp = t_0; elseif (y <= 3.9e-149) tmp = Float64(Float64(x - y) / y); elseif (y <= 1.4e-134) tmp = t_0; else tmp = Float64(Float64(x - y) * Float64(Float64(Float64(x / y) + 1.0) / y)); end return tmp end
function tmp_2 = code(x, y) t_0 = (x - y) / x; tmp = 0.0; if (y <= 5.2e-198) tmp = t_0; elseif (y <= 3.9e-149) tmp = (x - y) / y; elseif (y <= 1.4e-134) tmp = t_0; else tmp = (x - y) * (((x / y) + 1.0) / y); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision]}, If[LessEqual[y, 5.2e-198], t$95$0, If[LessEqual[y, 3.9e-149], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 1.4e-134], t$95$0, N[(N[(x - y), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{x}\\
\mathbf{if}\;y \leq 5.2 \cdot 10^{-198}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.9 \cdot 10^{-149}:\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-134}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{\frac{x}{y} + 1}{y}\\
\end{array}
\end{array}
if y < 5.20000000000000014e-198 or 3.9000000000000002e-149 < y < 1.3999999999999999e-134Initial program 65.2%
associate-/l*65.0%
fma-define65.0%
Simplified65.0%
Taylor expanded in x around inf 33.4%
un-div-inv33.5%
Applied egg-rr33.5%
if 5.20000000000000014e-198 < y < 3.9000000000000002e-149Initial program 27.3%
associate-/l*27.3%
fma-define27.3%
Simplified27.3%
Taylor expanded in x around 0 68.3%
un-div-inv68.3%
Applied egg-rr68.3%
if 1.3999999999999999e-134 < y Initial program 100.0%
associate-/l*99.6%
fma-define99.6%
Simplified99.6%
Taylor expanded in y around inf 82.8%
Final simplification42.3%
(FPCore (x y)
:precision binary64
(if (<= y 4.8e-198)
(* (- x y) (/ (+ 1.0 (/ y x)) x))
(if (<= y 1.05e-148)
(/ (- x y) y)
(if (<= y 7.8e-132) (/ (- x y) x) (* (- x y) (/ (+ (/ x y) 1.0) y))))))
double code(double x, double y) {
double tmp;
if (y <= 4.8e-198) {
tmp = (x - y) * ((1.0 + (y / x)) / x);
} else if (y <= 1.05e-148) {
tmp = (x - y) / y;
} else if (y <= 7.8e-132) {
tmp = (x - 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 <= 4.8d-198) then
tmp = (x - y) * ((1.0d0 + (y / x)) / x)
else if (y <= 1.05d-148) then
tmp = (x - y) / y
else if (y <= 7.8d-132) then
tmp = (x - 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 <= 4.8e-198) {
tmp = (x - y) * ((1.0 + (y / x)) / x);
} else if (y <= 1.05e-148) {
tmp = (x - y) / y;
} else if (y <= 7.8e-132) {
tmp = (x - y) / x;
} else {
tmp = (x - y) * (((x / y) + 1.0) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.8e-198: tmp = (x - y) * ((1.0 + (y / x)) / x) elif y <= 1.05e-148: tmp = (x - y) / y elif y <= 7.8e-132: tmp = (x - y) / x else: tmp = (x - y) * (((x / y) + 1.0) / y) return tmp
function code(x, y) tmp = 0.0 if (y <= 4.8e-198) tmp = Float64(Float64(x - y) * Float64(Float64(1.0 + Float64(y / x)) / x)); elseif (y <= 1.05e-148) tmp = Float64(Float64(x - y) / y); elseif (y <= 7.8e-132) tmp = Float64(Float64(x - 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 <= 4.8e-198) tmp = (x - y) * ((1.0 + (y / x)) / x); elseif (y <= 1.05e-148) tmp = (x - y) / y; elseif (y <= 7.8e-132) tmp = (x - y) / x; else tmp = (x - y) * (((x / y) + 1.0) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.8e-198], N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.05e-148], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 7.8e-132], N[(N[(x - y), $MachinePrecision] / x), $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 4.8 \cdot 10^{-198}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{y}{x}}{x}\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-148}:\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{-132}:\\
\;\;\;\;\frac{x - y}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{\frac{x}{y} + 1}{y}\\
\end{array}
\end{array}
if y < 4.79999999999999973e-198Initial program 64.2%
associate-/l*63.9%
fma-define63.9%
Simplified63.9%
Taylor expanded in x around inf 34.4%
if 4.79999999999999973e-198 < y < 1.05e-148Initial program 27.3%
associate-/l*27.3%
fma-define27.3%
Simplified27.3%
Taylor expanded in x around 0 68.3%
un-div-inv68.3%
Applied egg-rr68.3%
if 1.05e-148 < y < 7.79999999999999964e-132Initial program 99.5%
associate-/l*99.7%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around inf 72.9%
un-div-inv72.9%
Applied egg-rr72.9%
if 7.79999999999999964e-132 < y Initial program 100.0%
associate-/l*99.6%
fma-define99.6%
Simplified99.6%
Taylor expanded in y around inf 82.8%
Final simplification44.0%
(FPCore (x y)
:precision binary64
(if (<= y 5.2e-198)
(+ 1.0 (* -1.5 (/ (/ y x) (/ x y))))
(if (<= y 5.6e-149)
(/ (- x y) y)
(if (<= y 3.7e-134) (/ (- x y) x) (* (- x y) (/ (+ (/ x y) 1.0) y))))))
double code(double x, double y) {
double tmp;
if (y <= 5.2e-198) {
tmp = 1.0 + (-1.5 * ((y / x) / (x / y)));
} else if (y <= 5.6e-149) {
tmp = (x - y) / y;
} else if (y <= 3.7e-134) {
tmp = (x - 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 <= 5.2d-198) then
tmp = 1.0d0 + ((-1.5d0) * ((y / x) / (x / y)))
else if (y <= 5.6d-149) then
tmp = (x - y) / y
else if (y <= 3.7d-134) then
tmp = (x - 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 <= 5.2e-198) {
tmp = 1.0 + (-1.5 * ((y / x) / (x / y)));
} else if (y <= 5.6e-149) {
tmp = (x - y) / y;
} else if (y <= 3.7e-134) {
tmp = (x - y) / x;
} else {
tmp = (x - y) * (((x / y) + 1.0) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5.2e-198: tmp = 1.0 + (-1.5 * ((y / x) / (x / y))) elif y <= 5.6e-149: tmp = (x - y) / y elif y <= 3.7e-134: tmp = (x - y) / x else: tmp = (x - y) * (((x / y) + 1.0) / y) return tmp
function code(x, y) tmp = 0.0 if (y <= 5.2e-198) tmp = Float64(1.0 + Float64(-1.5 * Float64(Float64(y / x) / Float64(x / y)))); elseif (y <= 5.6e-149) tmp = Float64(Float64(x - y) / y); elseif (y <= 3.7e-134) tmp = Float64(Float64(x - 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 <= 5.2e-198) tmp = 1.0 + (-1.5 * ((y / x) / (x / y))); elseif (y <= 5.6e-149) tmp = (x - y) / y; elseif (y <= 3.7e-134) tmp = (x - y) / x; else tmp = (x - y) * (((x / y) + 1.0) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5.2e-198], N[(1.0 + N[(-1.5 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.6e-149], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 3.7e-134], N[(N[(x - y), $MachinePrecision] / x), $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 5.2 \cdot 10^{-198}:\\
\;\;\;\;1 + -1.5 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{-149}:\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{-134}:\\
\;\;\;\;\frac{x - y}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{\frac{x}{y} + 1}{y}\\
\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%
Taylor expanded in x around inf 26.3%
+-commutative26.3%
associate-+r+26.3%
distribute-rgt-out26.3%
metadata-eval26.3%
*-commutative26.3%
associate-+l+26.3%
unpow226.3%
unpow226.3%
times-frac34.0%
unpow234.0%
distribute-rgt1-in34.0%
metadata-eval34.0%
mul0-lft34.6%
Simplified34.6%
unpow234.6%
clear-num34.6%
un-div-inv34.6%
Applied egg-rr34.6%
if 5.20000000000000014e-198 < y < 5.5999999999999997e-149Initial program 27.3%
associate-/l*27.3%
fma-define27.3%
Simplified27.3%
Taylor expanded in x around 0 68.3%
un-div-inv68.3%
Applied egg-rr68.3%
if 5.5999999999999997e-149 < y < 3.7e-134Initial program 99.5%
associate-/l*99.7%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around inf 72.9%
un-div-inv72.9%
Applied egg-rr72.9%
if 3.7e-134 < y Initial program 100.0%
associate-/l*99.6%
fma-define99.6%
Simplified99.6%
Taylor expanded in y around inf 82.8%
Final simplification44.1%
(FPCore (x y) :precision binary64 (if (or (<= y 3e-198) (and (not (<= y 6.8e-149)) (<= y 6.4e-134))) (/ (- x y) x) -1.0))
double code(double x, double y) {
double tmp;
if ((y <= 3e-198) || (!(y <= 6.8e-149) && (y <= 6.4e-134))) {
tmp = (x - 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 <= 3d-198) .or. (.not. (y <= 6.8d-149)) .and. (y <= 6.4d-134)) then
tmp = (x - y) / x
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 3e-198) || (!(y <= 6.8e-149) && (y <= 6.4e-134))) {
tmp = (x - y) / x;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 3e-198) or (not (y <= 6.8e-149) and (y <= 6.4e-134)): tmp = (x - y) / x else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= 3e-198) || (!(y <= 6.8e-149) && (y <= 6.4e-134))) tmp = Float64(Float64(x - y) / x); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 3e-198) || (~((y <= 6.8e-149)) && (y <= 6.4e-134))) tmp = (x - y) / x; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 3e-198], And[N[Not[LessEqual[y, 6.8e-149]], $MachinePrecision], LessEqual[y, 6.4e-134]]], N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{-198} \lor \neg \left(y \leq 6.8 \cdot 10^{-149}\right) \land y \leq 6.4 \cdot 10^{-134}:\\
\;\;\;\;\frac{x - y}{x}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 3.0000000000000001e-198 or 6.7999999999999998e-149 < y < 6.4000000000000003e-134Initial program 65.2%
associate-/l*65.0%
fma-define65.0%
Simplified65.0%
Taylor expanded in x around inf 33.4%
un-div-inv33.5%
Applied egg-rr33.5%
if 3.0000000000000001e-198 < y < 6.7999999999999998e-149 or 6.4000000000000003e-134 < y Initial program 83.6%
associate-/l*83.4%
fma-define83.4%
Simplified83.4%
Taylor expanded in x around 0 78.5%
Final simplification42.1%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (- x y) x)))
(if (<= y 5.2e-198)
t_0
(if (<= y 4.3e-149) (/ (- x y) y) (if (<= y 6.4e-131) t_0 -1.0)))))
double code(double x, double y) {
double t_0 = (x - y) / x;
double tmp;
if (y <= 5.2e-198) {
tmp = t_0;
} else if (y <= 4.3e-149) {
tmp = (x - y) / y;
} else if (y <= 6.4e-131) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (x - y) / x
if (y <= 5.2d-198) then
tmp = t_0
else if (y <= 4.3d-149) then
tmp = (x - y) / y
else if (y <= 6.4d-131) then
tmp = t_0
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x - y) / x;
double tmp;
if (y <= 5.2e-198) {
tmp = t_0;
} else if (y <= 4.3e-149) {
tmp = (x - y) / y;
} else if (y <= 6.4e-131) {
tmp = t_0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): t_0 = (x - y) / x tmp = 0 if y <= 5.2e-198: tmp = t_0 elif y <= 4.3e-149: tmp = (x - y) / y elif y <= 6.4e-131: tmp = t_0 else: tmp = -1.0 return tmp
function code(x, y) t_0 = Float64(Float64(x - y) / x) tmp = 0.0 if (y <= 5.2e-198) tmp = t_0; elseif (y <= 4.3e-149) tmp = Float64(Float64(x - y) / y); elseif (y <= 6.4e-131) tmp = t_0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x - y) / x; tmp = 0.0; if (y <= 5.2e-198) tmp = t_0; elseif (y <= 4.3e-149) tmp = (x - y) / y; elseif (y <= 6.4e-131) tmp = t_0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision]}, If[LessEqual[y, 5.2e-198], t$95$0, If[LessEqual[y, 4.3e-149], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 6.4e-131], t$95$0, -1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{x}\\
\mathbf{if}\;y \leq 5.2 \cdot 10^{-198}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-149}:\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{-131}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 5.20000000000000014e-198 or 4.30000000000000037e-149 < y < 6.3999999999999999e-131Initial program 65.2%
associate-/l*65.0%
fma-define65.0%
Simplified65.0%
Taylor expanded in x around inf 33.4%
un-div-inv33.5%
Applied egg-rr33.5%
if 5.20000000000000014e-198 < y < 4.30000000000000037e-149Initial program 27.3%
associate-/l*27.3%
fma-define27.3%
Simplified27.3%
Taylor expanded in x around 0 68.3%
un-div-inv68.3%
Applied egg-rr68.3%
if 6.3999999999999999e-131 < y Initial program 100.0%
associate-/l*99.6%
fma-define99.6%
Simplified99.6%
Taylor expanded in x around 0 81.7%
Final simplification42.1%
(FPCore (x y) :precision binary64 (if (<= y 5.12e-186) 1.0 (if (<= y 7.2e-149) -1.0 (if (<= y 6e-134) 1.0 -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 5.12e-186) {
tmp = 1.0;
} else if (y <= 7.2e-149) {
tmp = -1.0;
} else if (y <= 6e-134) {
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 <= 5.12d-186) then
tmp = 1.0d0
else if (y <= 7.2d-149) then
tmp = -1.0d0
else if (y <= 6d-134) 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 <= 5.12e-186) {
tmp = 1.0;
} else if (y <= 7.2e-149) {
tmp = -1.0;
} else if (y <= 6e-134) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5.12e-186: tmp = 1.0 elif y <= 7.2e-149: tmp = -1.0 elif y <= 6e-134: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 5.12e-186) tmp = 1.0; elseif (y <= 7.2e-149) tmp = -1.0; elseif (y <= 6e-134) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 5.12e-186) tmp = 1.0; elseif (y <= 7.2e-149) tmp = -1.0; elseif (y <= 6e-134) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5.12e-186], 1.0, If[LessEqual[y, 7.2e-149], -1.0, If[LessEqual[y, 6e-134], 1.0, -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.12 \cdot 10^{-186}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{-149}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-134}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 5.1199999999999997e-186 or 7.2000000000000004e-149 < y < 6e-134Initial program 64.0%
associate-/l*63.8%
fma-define63.8%
Simplified63.8%
Taylor expanded in x around inf 33.9%
if 5.1199999999999997e-186 < y < 7.2000000000000004e-149 or 6e-134 < y Initial program 91.1%
associate-/l*90.5%
fma-define90.5%
Simplified90.5%
Taylor expanded in x around 0 78.8%
Final simplification41.8%
(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))))