
(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 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
double code(double x, double y) {
return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x - y) * (x + y)) / ((x * x) + (y * y))
end function
public static double code(double x, double y) {
return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
def code(x, y): return ((x - y) * (x + y)) / ((x * x) + (y * y))
function code(x, y) return Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) end
function tmp = code(x, y) tmp = ((x - y) * (x + y)) / ((x * x) + (y * y)); end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\end{array}
(FPCore (x y) :precision binary64 (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y))))
double code(double x, double y) {
return ((x - y) / hypot(x, y)) * ((x + y) / hypot(x, y));
}
public static double code(double x, double y) {
return ((x - y) / Math.hypot(x, y)) * ((x + y) / Math.hypot(x, y));
}
def code(x, y): return ((x - y) / math.hypot(x, y)) * ((x + y) / math.hypot(x, y))
function code(x, y) return Float64(Float64(Float64(x - y) / hypot(x, y)) * Float64(Float64(x + y) / hypot(x, y))) end
function tmp = code(x, y) tmp = ((x - y) / hypot(x, y)) * ((x + y) / hypot(x, y)); end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Initial program 64.4%
add-sqr-sqrt64.4%
times-frac65.2%
hypot-define65.2%
hypot-define100.0%
Applied egg-rr100.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 64.4%
associate-/l*64.9%
+-commutative64.9%
fma-define64.9%
Simplified64.9%
fma-undefine64.9%
+-commutative64.9%
*-un-lft-identity64.9%
add-sqr-sqrt64.9%
times-frac65.0%
hypot-define65.1%
hypot-define99.7%
Applied egg-rr99.7%
associate-*l/99.8%
*-un-lft-identity99.8%
Applied egg-rr99.8%
(FPCore (x y) :precision binary64 (if (<= y 1.6e-162) (- 1.0 (/ (* (* y 2.0) (/ y x)) x)) (if (<= y 4e-35) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) -1.0)))
double code(double x, double y) {
double tmp;
if (y <= 1.6e-162) {
tmp = 1.0 - (((y * 2.0) * (y / x)) / x);
} else if (y <= 4e-35) {
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 <= 1.6d-162) then
tmp = 1.0d0 - (((y * 2.0d0) * (y / x)) / x)
else if (y <= 4d-35) 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 <= 1.6e-162) {
tmp = 1.0 - (((y * 2.0) * (y / x)) / x);
} else if (y <= 4e-35) {
tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.6e-162: tmp = 1.0 - (((y * 2.0) * (y / x)) / x) elif y <= 4e-35: tmp = ((x - y) * (x + y)) / ((x * x) + (y * y)) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.6e-162) tmp = Float64(1.0 - Float64(Float64(Float64(y * 2.0) * Float64(y / x)) / x)); elseif (y <= 4e-35) tmp = Float64(Float64(Float64(x - y) * 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 <= 1.6e-162) tmp = 1.0 - (((y * 2.0) * (y / x)) / x); elseif (y <= 4e-35) tmp = ((x - y) * (x + y)) / ((x * x) + (y * y)); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.6e-162], N[(1.0 - N[(N[(N[(y * 2.0), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4e-35], N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.6 \cdot 10^{-162}:\\
\;\;\;\;1 - \frac{\left(y \cdot 2\right) \cdot \frac{y}{x}}{x}\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-35}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.59999999999999988e-162Initial program 58.4%
associate-/l*59.0%
+-commutative59.0%
fma-define59.0%
Simplified59.0%
Taylor expanded in x around -inf 34.6%
Simplified35.4%
unpow235.4%
Applied egg-rr35.4%
associate-*r*35.4%
*-un-lft-identity35.4%
times-frac35.9%
Applied egg-rr35.9%
/-rgt-identity35.9%
Simplified35.9%
if 1.59999999999999988e-162 < y < 4.00000000000000003e-35Initial program 99.9%
if 4.00000000000000003e-35 < y Initial program 100.0%
associate-/l*99.7%
+-commutative99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around 0 100.0%
Final simplification45.1%
(FPCore (x y) :precision binary64 (if (<= y 6.4e-145) (- 1.0 (/ (* (* y 2.0) (/ y x)) x)) (/ (* (- x y) (+ 1.0 (/ x y))) y)))
double code(double x, double y) {
double tmp;
if (y <= 6.4e-145) {
tmp = 1.0 - (((y * 2.0) * (y / x)) / x);
} else {
tmp = ((x - y) * (1.0 + (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 (y <= 6.4d-145) then
tmp = 1.0d0 - (((y * 2.0d0) * (y / x)) / x)
else
tmp = ((x - y) * (1.0d0 + (x / y))) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 6.4e-145) {
tmp = 1.0 - (((y * 2.0) * (y / x)) / x);
} else {
tmp = ((x - y) * (1.0 + (x / y))) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6.4e-145: tmp = 1.0 - (((y * 2.0) * (y / x)) / x) else: tmp = ((x - y) * (1.0 + (x / y))) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 6.4e-145) tmp = Float64(1.0 - Float64(Float64(Float64(y * 2.0) * Float64(y / x)) / x)); else tmp = Float64(Float64(Float64(x - y) * Float64(1.0 + Float64(x / y))) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 6.4e-145) tmp = 1.0 - (((y * 2.0) * (y / x)) / x); else tmp = ((x - y) * (1.0 + (x / y))) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6.4e-145], N[(1.0 - N[(N[(N[(y * 2.0), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x - y), $MachinePrecision] * N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.4 \cdot 10^{-145}:\\
\;\;\;\;1 - \frac{\left(y \cdot 2\right) \cdot \frac{y}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(1 + \frac{x}{y}\right)}{y}\\
\end{array}
\end{array}
if y < 6.40000000000000017e-145Initial program 58.6%
associate-/l*59.2%
+-commutative59.2%
fma-define59.2%
Simplified59.2%
Taylor expanded in x around -inf 34.9%
Simplified35.7%
unpow235.7%
Applied egg-rr35.7%
associate-*r*35.7%
*-un-lft-identity35.7%
times-frac36.2%
Applied egg-rr36.2%
/-rgt-identity36.2%
Simplified36.2%
if 6.40000000000000017e-145 < y Initial program 100.0%
associate-/l*99.5%
+-commutative99.5%
fma-define99.5%
Simplified99.5%
Taylor expanded in y around inf 83.3%
associate-*r/83.4%
Applied egg-rr83.4%
Final simplification42.8%
(FPCore (x y) :precision binary64 (if (<= y 2.2e-143) (- 1.0 (/ (* (* y 2.0) (/ y x)) x)) (* (+ 1.0 (/ x y)) (+ -1.0 (/ x y)))))
double code(double x, double y) {
double tmp;
if (y <= 2.2e-143) {
tmp = 1.0 - (((y * 2.0) * (y / x)) / x);
} else {
tmp = (1.0 + (x / y)) * (-1.0 + (x / y));
}
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-143) then
tmp = 1.0d0 - (((y * 2.0d0) * (y / x)) / x)
else
tmp = (1.0d0 + (x / y)) * ((-1.0d0) + (x / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.2e-143) {
tmp = 1.0 - (((y * 2.0) * (y / x)) / x);
} else {
tmp = (1.0 + (x / y)) * (-1.0 + (x / y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.2e-143: tmp = 1.0 - (((y * 2.0) * (y / x)) / x) else: tmp = (1.0 + (x / y)) * (-1.0 + (x / y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.2e-143) tmp = Float64(1.0 - Float64(Float64(Float64(y * 2.0) * Float64(y / x)) / x)); else tmp = Float64(Float64(1.0 + Float64(x / y)) * Float64(-1.0 + Float64(x / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.2e-143) tmp = 1.0 - (((y * 2.0) * (y / x)) / x); else tmp = (1.0 + (x / y)) * (-1.0 + (x / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.2e-143], N[(1.0 - N[(N[(N[(y * 2.0), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision] * N[(-1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.2 \cdot 10^{-143}:\\
\;\;\;\;1 - \frac{\left(y \cdot 2\right) \cdot \frac{y}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \frac{x}{y}\right) \cdot \left(-1 + \frac{x}{y}\right)\\
\end{array}
\end{array}
if y < 2.19999999999999989e-143Initial program 58.6%
associate-/l*59.2%
+-commutative59.2%
fma-define59.2%
Simplified59.2%
Taylor expanded in x around -inf 34.9%
Simplified35.7%
unpow235.7%
Applied egg-rr35.7%
associate-*r*35.7%
*-un-lft-identity35.7%
times-frac36.2%
Applied egg-rr36.2%
/-rgt-identity36.2%
Simplified36.2%
if 2.19999999999999989e-143 < y Initial program 100.0%
associate-/l*99.5%
+-commutative99.5%
fma-define99.5%
Simplified99.5%
Taylor expanded in y around inf 83.3%
associate-*r/83.4%
Applied egg-rr83.4%
associate-/l*83.3%
Applied egg-rr83.3%
associate-*r/83.4%
*-commutative83.4%
associate-*r/83.4%
div-sub83.4%
sub-neg83.4%
*-inverses83.4%
metadata-eval83.4%
Simplified83.4%
Final simplification42.8%
(FPCore (x y) :precision binary64 (if (<= y 6.5e-145) (* (/ (- x y) x) (/ (+ x y) x)) (* (+ 1.0 (/ x y)) (+ -1.0 (/ x y)))))
double code(double x, double y) {
double tmp;
if (y <= 6.5e-145) {
tmp = ((x - y) / x) * ((x + y) / x);
} else {
tmp = (1.0 + (x / y)) * (-1.0 + (x / y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 6.5d-145) then
tmp = ((x - y) / x) * ((x + y) / x)
else
tmp = (1.0d0 + (x / y)) * ((-1.0d0) + (x / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 6.5e-145) {
tmp = ((x - y) / x) * ((x + y) / x);
} else {
tmp = (1.0 + (x / y)) * (-1.0 + (x / y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6.5e-145: tmp = ((x - y) / x) * ((x + y) / x) else: tmp = (1.0 + (x / y)) * (-1.0 + (x / y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 6.5e-145) tmp = Float64(Float64(Float64(x - y) / x) * Float64(Float64(x + y) / x)); else tmp = Float64(Float64(1.0 + Float64(x / y)) * Float64(-1.0 + Float64(x / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 6.5e-145) tmp = ((x - y) / x) * ((x + y) / x); else tmp = (1.0 + (x / y)) * (-1.0 + (x / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6.5e-145], N[(N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision] * N[(-1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.5 \cdot 10^{-145}:\\
\;\;\;\;\frac{x - y}{x} \cdot \frac{x + y}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \frac{x}{y}\right) \cdot \left(-1 + \frac{x}{y}\right)\\
\end{array}
\end{array}
if y < 6.5000000000000002e-145Initial program 58.6%
add-sqr-sqrt58.6%
times-frac59.5%
hypot-define59.5%
hypot-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 36.5%
Taylor expanded in x around inf 36.0%
if 6.5000000000000002e-145 < y Initial program 100.0%
associate-/l*99.5%
+-commutative99.5%
fma-define99.5%
Simplified99.5%
Taylor expanded in y around inf 83.3%
associate-*r/83.4%
Applied egg-rr83.4%
associate-/l*83.3%
Applied egg-rr83.3%
associate-*r/83.4%
*-commutative83.4%
associate-*r/83.4%
div-sub83.4%
sub-neg83.4%
*-inverses83.4%
metadata-eval83.4%
Simplified83.4%
Final simplification42.7%
(FPCore (x y) :precision binary64 (if (<= y 8.5e-145) (* (- x y) (/ (+ 1.0 (/ y x)) x)) (* (+ 1.0 (/ x y)) (+ -1.0 (/ x y)))))
double code(double x, double y) {
double tmp;
if (y <= 8.5e-145) {
tmp = (x - y) * ((1.0 + (y / x)) / x);
} else {
tmp = (1.0 + (x / y)) * (-1.0 + (x / y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 8.5d-145) then
tmp = (x - y) * ((1.0d0 + (y / x)) / x)
else
tmp = (1.0d0 + (x / y)) * ((-1.0d0) + (x / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 8.5e-145) {
tmp = (x - y) * ((1.0 + (y / x)) / x);
} else {
tmp = (1.0 + (x / y)) * (-1.0 + (x / y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 8.5e-145: tmp = (x - y) * ((1.0 + (y / x)) / x) else: tmp = (1.0 + (x / y)) * (-1.0 + (x / y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 8.5e-145) tmp = Float64(Float64(x - y) * Float64(Float64(1.0 + Float64(y / x)) / x)); else tmp = Float64(Float64(1.0 + Float64(x / y)) * Float64(-1.0 + Float64(x / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 8.5e-145) tmp = (x - y) * ((1.0 + (y / x)) / x); else tmp = (1.0 + (x / y)) * (-1.0 + (x / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 8.5e-145], N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision] * N[(-1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.5 \cdot 10^{-145}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{y}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \frac{x}{y}\right) \cdot \left(-1 + \frac{x}{y}\right)\\
\end{array}
\end{array}
if y < 8.50000000000000043e-145Initial program 58.6%
associate-/l*59.2%
+-commutative59.2%
fma-define59.2%
Simplified59.2%
Taylor expanded in x around inf 35.9%
if 8.50000000000000043e-145 < y Initial program 100.0%
associate-/l*99.5%
+-commutative99.5%
fma-define99.5%
Simplified99.5%
Taylor expanded in y around inf 83.3%
associate-*r/83.4%
Applied egg-rr83.4%
associate-/l*83.3%
Applied egg-rr83.3%
associate-*r/83.4%
*-commutative83.4%
associate-*r/83.4%
div-sub83.4%
sub-neg83.4%
*-inverses83.4%
metadata-eval83.4%
Simplified83.4%
Final simplification42.5%
(FPCore (x y) :precision binary64 (if (<= y 1.35e-143) 1.0 (* (+ 1.0 (/ x y)) (+ -1.0 (/ x y)))))
double code(double x, double y) {
double tmp;
if (y <= 1.35e-143) {
tmp = 1.0;
} else {
tmp = (1.0 + (x / y)) * (-1.0 + (x / 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.35d-143) then
tmp = 1.0d0
else
tmp = (1.0d0 + (x / y)) * ((-1.0d0) + (x / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.35e-143) {
tmp = 1.0;
} else {
tmp = (1.0 + (x / y)) * (-1.0 + (x / y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.35e-143: tmp = 1.0 else: tmp = (1.0 + (x / y)) * (-1.0 + (x / y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.35e-143) tmp = 1.0; else tmp = Float64(Float64(1.0 + Float64(x / y)) * Float64(-1.0 + Float64(x / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.35e-143) tmp = 1.0; else tmp = (1.0 + (x / y)) * (-1.0 + (x / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.35e-143], 1.0, N[(N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision] * N[(-1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{-143}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \frac{x}{y}\right) \cdot \left(-1 + \frac{x}{y}\right)\\
\end{array}
\end{array}
if y < 1.35000000000000005e-143Initial program 58.6%
associate-/l*59.2%
+-commutative59.2%
fma-define59.2%
Simplified59.2%
Taylor expanded in x around inf 34.5%
if 1.35000000000000005e-143 < y Initial program 100.0%
associate-/l*99.5%
+-commutative99.5%
fma-define99.5%
Simplified99.5%
Taylor expanded in y around inf 83.3%
associate-*r/83.4%
Applied egg-rr83.4%
associate-/l*83.3%
Applied egg-rr83.3%
associate-*r/83.4%
*-commutative83.4%
associate-*r/83.4%
div-sub83.4%
sub-neg83.4%
*-inverses83.4%
metadata-eval83.4%
Simplified83.4%
Final simplification41.4%
(FPCore (x y) :precision binary64 (if (<= y 1.45e-144) 1.0 -1.0))
double code(double x, double y) {
double tmp;
if (y <= 1.45e-144) {
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 <= 1.45d-144) 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 <= 1.45e-144) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.45e-144: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.45e-144) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.45e-144) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.45e-144], 1.0, -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.45 \cdot 10^{-144}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.4500000000000001e-144Initial program 58.6%
associate-/l*59.2%
+-commutative59.2%
fma-define59.2%
Simplified59.2%
Taylor expanded in x around inf 34.5%
if 1.4500000000000001e-144 < y Initial program 100.0%
associate-/l*99.5%
+-commutative99.5%
fma-define99.5%
Simplified99.5%
Taylor expanded in x around 0 82.3%
(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 64.4%
associate-/l*64.9%
+-commutative64.9%
fma-define64.9%
Simplified64.9%
Taylor expanded in x around 0 68.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 2024131
(FPCore (x y)
:name "Kahan p9 Example"
:precision binary64
:pre (and (and (< 0.0 x) (< x 1.0)) (< y 1.0))
:alt
(! :herbie-platform default (if (< 1/2 (fabs (/ x y)) 2) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1 (/ 2 (+ 1 (* (/ x y) (/ x y)))))))
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))