
(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)) (/ 1.0 (/ (hypot x y) (+ x y)))))
double code(double x, double y) {
return ((x - y) / hypot(x, y)) * (1.0 / (hypot(x, y) / (x + y)));
}
public static double code(double x, double y) {
return ((x - y) / Math.hypot(x, y)) * (1.0 / (Math.hypot(x, y) / (x + y)));
}
def code(x, y): return ((x - y) / math.hypot(x, y)) * (1.0 / (math.hypot(x, y) / (x + y)))
function code(x, y) return Float64(Float64(Float64(x - y) / hypot(x, y)) * Float64(1.0 / Float64(hypot(x, y) / Float64(x + y)))) end
function tmp = code(x, y) tmp = ((x - y) / hypot(x, y)) * (1.0 / (hypot(x, y) / (x + y))); end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}
\end{array}
Initial program 67.2%
add-sqr-sqrt67.2%
times-frac67.7%
hypot-def67.7%
hypot-def100.0%
Applied egg-rr100.0%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
Final simplification100.0%
(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.2%
add-sqr-sqrt67.2%
times-frac67.7%
hypot-def67.7%
hypot-def100.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 (* (/ 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 = fma(2.0, ((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 = fma(2.0, Float64(Float64(x / y) * Float64(x / y)), -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[(x / y), $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{x}{y} \cdot \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%
associate-*r/3.1%
+-commutative3.1%
fma-def3.1%
Simplified3.1%
Taylor expanded in x around 0 54.8%
fma-neg54.8%
unpow254.8%
unpow254.8%
times-frac78.1%
metadata-eval78.1%
Simplified78.1%
Final simplification92.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
(t_1 (* (/ x y) (/ x y))))
(if (<= t_0 2.0) t_0 (+ t_1 (+ t_1 -1.0)))))
double code(double x, double y) {
double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
double t_1 = (x / y) * (x / y);
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = t_1 + (t_1 + -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) :: t_1
real(8) :: tmp
t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y))
t_1 = (x / y) * (x / y)
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = t_1 + (t_1 + (-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 t_1 = (x / y) * (x / y);
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = t_1 + (t_1 + -1.0);
}
return tmp;
}
def code(x, y): t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y)) t_1 = (x / y) * (x / y) tmp = 0 if t_0 <= 2.0: tmp = t_0 else: tmp = t_1 + (t_1 + -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))) t_1 = Float64(Float64(x / y) * Float64(x / y)) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(t_1 + Float64(t_1 + -1.0)); end return tmp end
function tmp_2 = code(x, y) t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y)); t_1 = (x / y) * (x / y); tmp = 0.0; if (t_0 <= 2.0) tmp = t_0; else tmp = t_1 + (t_1 + -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]}, Block[{t$95$1 = N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(t$95$1 + N[(t$95$1 + -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}\\
t_1 := \frac{x}{y} \cdot \frac{x}{y}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1 + \left(t_1 + -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-def3.1%
hypot-def99.9%
Applied egg-rr99.9%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
Taylor expanded in y around inf 54.8%
distribute-rgt1-in54.8%
metadata-eval54.8%
mul0-lft54.8%
associate-+r-54.8%
neg-sub054.8%
unpow254.8%
unpow254.8%
times-frac54.8%
+-commutative54.8%
distribute-neg-in54.8%
metadata-eval54.8%
mul-1-neg54.8%
remove-double-neg54.8%
unpow254.8%
unpow254.8%
times-frac78.0%
Simplified78.0%
Final simplification92.8%
(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 (/ y (- 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) * (1.0 / (y / (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) * (1.0d0 / (y / (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) * (1.0 / (y / (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) * (1.0 / (y / (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(Float64(x + y) * Float64(1.0 / Float64(y / 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) * (1.0 / (y / (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[(N[(x + y), $MachinePrecision] * N[(1.0 / N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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{\left(x + y\right) \cdot \frac{1}{\frac{y}{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-*r/3.1%
+-commutative3.1%
fma-def3.1%
Simplified3.1%
Taylor expanded in y around inf 3.1%
unpow23.1%
Simplified3.1%
associate-*r/0.0%
Applied egg-rr0.0%
times-frac77.3%
associate-*r/77.3%
Simplified77.3%
clear-num77.3%
inv-pow77.3%
Applied egg-rr77.3%
unpow-177.3%
Simplified77.3%
Final simplification92.5%
(FPCore (x y) :precision binary64 (if (<= y 8.6e-159) (+ 1.0 (/ (* y -2.0) (/ x (/ y x)))) (if (<= y 0.005) (* (- x y) (/ (+ x y) (+ (* x x) (* y y)))) -1.0)))
double code(double x, double y) {
double tmp;
if (y <= 8.6e-159) {
tmp = 1.0 + ((y * -2.0) / (x / (y / x)));
} else if (y <= 0.005) {
tmp = (x - y) * ((x + y) / ((x * x) + (y * y)));
} 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 <= 8.6d-159) then
tmp = 1.0d0 + ((y * (-2.0d0)) / (x / (y / x)))
else if (y <= 0.005d0) then
tmp = (x - y) * ((x + y) / ((x * x) + (y * y)))
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 8.6e-159) {
tmp = 1.0 + ((y * -2.0) / (x / (y / x)));
} else if (y <= 0.005) {
tmp = (x - y) * ((x + y) / ((x * x) + (y * y)));
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 8.6e-159: tmp = 1.0 + ((y * -2.0) / (x / (y / x))) elif y <= 0.005: tmp = (x - y) * ((x + y) / ((x * x) + (y * y))) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 8.6e-159) tmp = Float64(1.0 + Float64(Float64(y * -2.0) / Float64(x / Float64(y / x)))); elseif (y <= 0.005) tmp = Float64(Float64(x - y) * Float64(Float64(x + y) / Float64(Float64(x * x) + Float64(y * y)))); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 8.6e-159) tmp = 1.0 + ((y * -2.0) / (x / (y / x))); elseif (y <= 0.005) tmp = (x - y) * ((x + y) / ((x * x) + (y * y))); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 8.6e-159], N[(1.0 + N[(N[(y * -2.0), $MachinePrecision] / N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.005], N[(N[(x - y), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.6 \cdot 10^{-159}:\\
\;\;\;\;1 + \frac{y \cdot -2}{\frac{x}{\frac{y}{x}}}\\
\mathbf{elif}\;y \leq 0.005:\\
\;\;\;\;\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 8.6e-159Initial program 59.2%
associate-*r/59.6%
+-commutative59.6%
fma-def59.6%
Simplified59.6%
Taylor expanded in y around 0 26.3%
unpow226.3%
unpow226.3%
Simplified26.3%
times-frac35.8%
unpow235.8%
*-commutative35.8%
unpow235.8%
times-frac26.3%
associate-/l*26.6%
associate-*l/26.6%
associate-/l*35.8%
Applied egg-rr35.8%
if 8.6e-159 < y < 0.0050000000000000001Initial program 99.9%
associate-*r/99.2%
+-commutative99.2%
fma-def99.2%
Simplified99.2%
fma-udef99.2%
Applied egg-rr99.2%
if 0.0050000000000000001 < y Initial program 100.0%
associate-*r/100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification48.2%
(FPCore (x y) :precision binary64 (if (<= y 1.85e-112) (+ 1.0 (/ (* y -2.0) (/ x (/ y x)))) (/ (- (* x (/ x y)) y) y)))
double code(double x, double y) {
double tmp;
if (y <= 1.85e-112) {
tmp = 1.0 + ((y * -2.0) / (x / (y / x)));
} else {
tmp = ((x * (x / y)) - y) / 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.85d-112) then
tmp = 1.0d0 + ((y * (-2.0d0)) / (x / (y / x)))
else
tmp = ((x * (x / y)) - y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.85e-112) {
tmp = 1.0 + ((y * -2.0) / (x / (y / x)));
} else {
tmp = ((x * (x / y)) - y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.85e-112: tmp = 1.0 + ((y * -2.0) / (x / (y / x))) else: tmp = ((x * (x / y)) - y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.85e-112) tmp = Float64(1.0 + Float64(Float64(y * -2.0) / Float64(x / Float64(y / x)))); else tmp = Float64(Float64(Float64(x * Float64(x / y)) - y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.85e-112) tmp = 1.0 + ((y * -2.0) / (x / (y / x))); else tmp = ((x * (x / y)) - y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.85e-112], N[(1.0 + N[(N[(y * -2.0), $MachinePrecision] / N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.85 \cdot 10^{-112}:\\
\;\;\;\;1 + \frac{y \cdot -2}{\frac{x}{\frac{y}{x}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \frac{x}{y} - y}{y}\\
\end{array}
\end{array}
if y < 1.8499999999999999e-112Initial program 62.8%
associate-*r/63.1%
+-commutative63.1%
fma-def63.1%
Simplified63.1%
Taylor expanded in y around 0 29.4%
unpow229.4%
unpow229.4%
Simplified29.4%
times-frac38.1%
unpow238.1%
*-commutative38.1%
unpow238.1%
times-frac29.4%
associate-/l*29.7%
associate-*l/29.7%
associate-/l*38.1%
Applied egg-rr38.1%
if 1.8499999999999999e-112 < y Initial program 99.9%
associate-*r/99.4%
+-commutative99.4%
fma-def99.4%
Simplified99.4%
Taylor expanded in y around inf 79.8%
unpow279.8%
Simplified79.8%
associate-*r/80.3%
Applied egg-rr80.3%
times-frac80.3%
associate-*r/80.3%
Simplified80.3%
clear-num80.3%
inv-pow80.3%
Applied egg-rr80.3%
unpow-180.3%
Simplified80.3%
Taylor expanded in y around 0 80.3%
neg-mul-180.3%
neg-mul-180.3%
associate-+r+80.3%
distribute-neg-in80.3%
unpow280.3%
associate-*l/80.3%
associate-/r/80.3%
associate-+r+80.3%
distribute-neg-in80.3%
associate-+r+80.3%
+-commutative80.3%
associate-+r+80.3%
neg-mul-180.3%
distribute-lft1-in80.3%
metadata-eval80.3%
mul0-lft80.3%
sub-neg80.3%
neg-sub080.3%
associate-/r/80.3%
associate-*l/80.3%
unpow280.3%
Simplified80.3%
Final simplification43.0%
(FPCore (x y) :precision binary64 (if (<= y 1.85e-112) 1.0 (+ (* (/ x y) (/ x y)) -1.0)))
double code(double x, double y) {
double tmp;
if (y <= 1.85e-112) {
tmp = 1.0;
} else {
tmp = ((x / y) * (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.85d-112) then
tmp = 1.0d0
else
tmp = ((x / y) * (x / y)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.85e-112) {
tmp = 1.0;
} else {
tmp = ((x / y) * (x / y)) + -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.85e-112: tmp = 1.0 else: tmp = ((x / y) * (x / y)) + -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.85e-112) tmp = 1.0; else tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.85e-112) tmp = 1.0; else tmp = ((x / y) * (x / y)) + -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.85e-112], 1.0, N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.85 \cdot 10^{-112}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\
\end{array}
\end{array}
if y < 1.8499999999999999e-112Initial program 62.8%
associate-*r/63.1%
+-commutative63.1%
fma-def63.1%
Simplified63.1%
Taylor expanded in x around inf 36.5%
if 1.8499999999999999e-112 < y Initial program 99.9%
associate-*r/99.4%
+-commutative99.4%
fma-def99.4%
Simplified99.4%
Taylor expanded in y around inf 79.8%
unpow279.8%
Simplified79.8%
associate-*r/80.3%
Applied egg-rr80.3%
times-frac80.3%
Simplified80.3%
Taylor expanded in x around 0 80.3%
sub-neg80.3%
remove-double-neg80.3%
mul-1-neg80.3%
distribute-neg-in80.3%
+-commutative80.3%
distribute-neg-in80.3%
metadata-eval80.3%
mul-1-neg80.3%
remove-double-neg80.3%
unpow280.3%
unpow280.3%
times-frac80.3%
Simplified80.3%
Final simplification41.6%
(FPCore (x y) :precision binary64 (if (<= y 1.85e-112) 1.0 (/ (- (* x (/ x y)) y) y)))
double code(double x, double y) {
double tmp;
if (y <= 1.85e-112) {
tmp = 1.0;
} else {
tmp = ((x * (x / y)) - y) / 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.85d-112) then
tmp = 1.0d0
else
tmp = ((x * (x / y)) - y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.85e-112) {
tmp = 1.0;
} else {
tmp = ((x * (x / y)) - y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.85e-112: tmp = 1.0 else: tmp = ((x * (x / y)) - y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.85e-112) tmp = 1.0; else tmp = Float64(Float64(Float64(x * Float64(x / y)) - y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.85e-112) tmp = 1.0; else tmp = ((x * (x / y)) - y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.85e-112], 1.0, N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.85 \cdot 10^{-112}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \frac{x}{y} - y}{y}\\
\end{array}
\end{array}
if y < 1.8499999999999999e-112Initial program 62.8%
associate-*r/63.1%
+-commutative63.1%
fma-def63.1%
Simplified63.1%
Taylor expanded in x around inf 36.5%
if 1.8499999999999999e-112 < y Initial program 99.9%
associate-*r/99.4%
+-commutative99.4%
fma-def99.4%
Simplified99.4%
Taylor expanded in y around inf 79.8%
unpow279.8%
Simplified79.8%
associate-*r/80.3%
Applied egg-rr80.3%
times-frac80.3%
associate-*r/80.3%
Simplified80.3%
clear-num80.3%
inv-pow80.3%
Applied egg-rr80.3%
unpow-180.3%
Simplified80.3%
Taylor expanded in y around 0 80.3%
neg-mul-180.3%
neg-mul-180.3%
associate-+r+80.3%
distribute-neg-in80.3%
unpow280.3%
associate-*l/80.3%
associate-/r/80.3%
associate-+r+80.3%
distribute-neg-in80.3%
associate-+r+80.3%
+-commutative80.3%
associate-+r+80.3%
neg-mul-180.3%
distribute-lft1-in80.3%
metadata-eval80.3%
mul0-lft80.3%
sub-neg80.3%
neg-sub080.3%
associate-/r/80.3%
associate-*l/80.3%
unpow280.3%
Simplified80.3%
Final simplification41.6%
(FPCore (x y) :precision binary64 (if (<= y 2.6e-112) 1.0 -1.0))
double code(double x, double y) {
double tmp;
if (y <= 2.6e-112) {
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 <= 2.6d-112) 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 <= 2.6e-112) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.6e-112: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 2.6e-112) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.6e-112) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.6e-112], 1.0, -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.6 \cdot 10^{-112}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 2.59999999999999992e-112Initial program 62.8%
associate-*r/63.1%
+-commutative63.1%
fma-def63.1%
Simplified63.1%
Taylor expanded in x around inf 36.5%
if 2.59999999999999992e-112 < y Initial program 99.9%
associate-*r/99.4%
+-commutative99.4%
fma-def99.4%
Simplified99.4%
Taylor expanded in x around 0 79.3%
Final simplification41.5%
(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.2%
associate-*r/67.4%
+-commutative67.4%
fma-def67.4%
Simplified67.4%
Taylor expanded in x around 0 65.8%
Final simplification65.8%
(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 2023238
(FPCore (x y)
:name "Kahan p9 Example"
:precision binary64
:pre (and (and (< 0.0 x) (< x 1.0)) (< y 1.0))
:herbie-target
(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))))