
(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 9 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(x + y) / Float64(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[(x + y), $MachinePrecision] / N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] * 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{\mathsf{hypot}\left(x, y\right)}{x - y}}
\end{array}
Initial program 67.2%
add-sqr-sqrt67.2%
times-frac68.0%
hypot-def68.0%
hypot-def99.9%
Applied egg-rr99.9%
clear-num99.9%
frac-times100.0%
*-un-lft-identity100.0%
Applied egg-rr100.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-frac68.0%
hypot-def68.0%
hypot-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* (+ x y) (- x y)) (+ (* x x) (* y y)))))
(if (<= t_0 2.0)
t_0
(+ (* (/ x y) (/ x y)) (- -1.0 (/ (* x (/ 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) * (x / y)) + (-1.0 - ((x * (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) * (x / y)) + ((-1.0d0) - ((x * (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) * (x / y)) + (-1.0 - ((x * (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) * (x / y)) + (-1.0 - ((x * (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(x / y)) + Float64(-1.0 - Float64(Float64(x * Float64(x / Float64(-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) * (x / y)) + (-1.0 - ((x * (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[(x / y), $MachinePrecision]), $MachinePrecision] + N[(-1.0 - N[(N[(x * N[(x / (-y)), $MachinePrecision]), $MachinePrecision] / 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{x}{y} \cdot \frac{x}{y} + \left(-1 - \frac{x \cdot \frac{x}{-y}}{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%
associate-*r/3.1%
+-commutative3.1%
fma-def3.1%
Simplified3.1%
Taylor expanded in y around inf 59.5%
associate--l+59.5%
unpow259.5%
unpow259.5%
times-frac59.5%
distribute-rgt1-in59.5%
metadata-eval59.5%
mul0-lft59.5%
+-commutative59.5%
associate--r+59.5%
metadata-eval59.5%
unpow259.5%
unpow259.5%
associate-*r/59.5%
neg-mul-159.5%
associate-/r*86.8%
Simplified86.8%
Taylor expanded in x around 0 86.8%
*-commutative86.8%
unpow286.8%
*-lft-identity86.8%
*-lft-identity86.8%
associate-*r/87.8%
associate-*l*87.8%
metadata-eval87.8%
times-frac87.8%
*-rgt-identity87.8%
*-commutative87.8%
neg-mul-187.8%
Simplified87.8%
Final simplification96.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) (/ 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) * (x / y)) + -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 - y)) / ((x * x) + (y * y))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = ((x / y) * (x / y)) + (-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 tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = ((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) * (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) * 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) * (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[(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}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\
\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%
Taylor expanded in x around 0 59.5%
sub-neg59.5%
unpow259.5%
unpow259.5%
metadata-eval59.5%
Simplified59.5%
frac-times86.8%
Applied egg-rr86.8%
Final simplification95.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ (* (/ x y) (/ x y)) -1.0))
(t_1 (+ 1.0 (* -2.0 (* (/ y x) (/ y x))))))
(if (<= y -3.8e-191)
t_0
(if (<= y 5e-222)
t_1
(if (<= y 8e-216) -1.0 (if (<= y 5.7e-157) t_1 t_0))))))
double code(double x, double y) {
double t_0 = ((x / y) * (x / y)) + -1.0;
double t_1 = 1.0 + (-2.0 * ((y / x) * (y / x)));
double tmp;
if (y <= -3.8e-191) {
tmp = t_0;
} else if (y <= 5e-222) {
tmp = t_1;
} else if (y <= 8e-216) {
tmp = -1.0;
} else if (y <= 5.7e-157) {
tmp = t_1;
} else {
tmp = t_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)) + (-1.0d0)
t_1 = 1.0d0 + ((-2.0d0) * ((y / x) * (y / x)))
if (y <= (-3.8d-191)) then
tmp = t_0
else if (y <= 5d-222) then
tmp = t_1
else if (y <= 8d-216) then
tmp = -1.0d0
else if (y <= 5.7d-157) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = ((x / y) * (x / y)) + -1.0;
double t_1 = 1.0 + (-2.0 * ((y / x) * (y / x)));
double tmp;
if (y <= -3.8e-191) {
tmp = t_0;
} else if (y <= 5e-222) {
tmp = t_1;
} else if (y <= 8e-216) {
tmp = -1.0;
} else if (y <= 5.7e-157) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = ((x / y) * (x / y)) + -1.0 t_1 = 1.0 + (-2.0 * ((y / x) * (y / x))) tmp = 0 if y <= -3.8e-191: tmp = t_0 elif y <= 5e-222: tmp = t_1 elif y <= 8e-216: tmp = -1.0 elif y <= 5.7e-157: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0) t_1 = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / x) * Float64(y / x)))) tmp = 0.0 if (y <= -3.8e-191) tmp = t_0; elseif (y <= 5e-222) tmp = t_1; elseif (y <= 8e-216) tmp = -1.0; elseif (y <= 5.7e-157) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = ((x / y) * (x / y)) + -1.0; t_1 = 1.0 + (-2.0 * ((y / x) * (y / x))); tmp = 0.0; if (y <= -3.8e-191) tmp = t_0; elseif (y <= 5e-222) tmp = t_1; elseif (y <= 8e-216) tmp = -1.0; elseif (y <= 5.7e-157) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(-2.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.8e-191], t$95$0, If[LessEqual[y, 5e-222], t$95$1, If[LessEqual[y, 8e-216], -1.0, If[LessEqual[y, 5.7e-157], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y} \cdot \frac{x}{y} + -1\\
t_1 := 1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\mathbf{if}\;y \leq -3.8 \cdot 10^{-191}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-222}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-216}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 5.7 \cdot 10^{-157}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -3.7999999999999998e-191 or 5.69999999999999998e-157 < y Initial program 70.1%
associate-*r/70.7%
+-commutative70.7%
fma-def70.7%
Simplified70.7%
Taylor expanded in y around inf 59.1%
unpow259.1%
Simplified59.1%
Taylor expanded in x around 0 86.1%
sub-neg86.1%
unpow286.1%
unpow286.1%
metadata-eval86.1%
Simplified86.1%
frac-times88.3%
Applied egg-rr88.3%
if -3.7999999999999998e-191 < y < 5.00000000000000008e-222 or 8.0000000000000003e-216 < y < 5.69999999999999998e-157Initial program 64.3%
associate-*r/64.8%
+-commutative64.8%
fma-def64.8%
Simplified64.8%
Taylor expanded in y around 0 64.3%
unpow264.3%
unpow264.3%
Simplified64.3%
times-frac80.1%
Applied egg-rr80.1%
if 5.00000000000000008e-222 < y < 8.0000000000000003e-216Initial program 0.0%
associate-*r/3.1%
+-commutative3.1%
fma-def3.1%
Simplified3.1%
Taylor expanded in x around 0 100.0%
Final simplification86.3%
(FPCore (x y)
:precision binary64
(if (or (<= y -1.4e-192)
(not
(or (<= y 4.9e-222) (and (not (<= y 7.4e-190)) (<= y 2.9e-157)))))
(+ (* (/ x y) (/ x y)) -1.0)
1.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.4e-192) || !((y <= 4.9e-222) || (!(y <= 7.4e-190) && (y <= 2.9e-157)))) {
tmp = ((x / y) * (x / y)) + -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.4d-192)) .or. (.not. (y <= 4.9d-222) .or. (.not. (y <= 7.4d-190)) .and. (y <= 2.9d-157))) then
tmp = ((x / y) * (x / y)) + (-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.4e-192) || !((y <= 4.9e-222) || (!(y <= 7.4e-190) && (y <= 2.9e-157)))) {
tmp = ((x / y) * (x / y)) + -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.4e-192) or not ((y <= 4.9e-222) or (not (y <= 7.4e-190) and (y <= 2.9e-157))): tmp = ((x / y) * (x / y)) + -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.4e-192) || !((y <= 4.9e-222) || (!(y <= 7.4e-190) && (y <= 2.9e-157)))) tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.4e-192) || ~(((y <= 4.9e-222) || (~((y <= 7.4e-190)) && (y <= 2.9e-157))))) tmp = ((x / y) * (x / y)) + -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.4e-192], N[Not[Or[LessEqual[y, 4.9e-222], And[N[Not[LessEqual[y, 7.4e-190]], $MachinePrecision], LessEqual[y, 2.9e-157]]]], $MachinePrecision]], N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-192} \lor \neg \left(y \leq 4.9 \cdot 10^{-222} \lor \neg \left(y \leq 7.4 \cdot 10^{-190}\right) \land y \leq 2.9 \cdot 10^{-157}\right):\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.40000000000000002e-192 or 4.9e-222 < y < 7.4000000000000004e-190 or 2.89999999999999988e-157 < y Initial program 68.1%
associate-*r/68.7%
+-commutative68.7%
fma-def68.7%
Simplified68.7%
Taylor expanded in y around inf 57.0%
unpow257.0%
Simplified57.0%
Taylor expanded in x around 0 82.9%
sub-neg82.9%
unpow282.9%
unpow282.9%
metadata-eval82.9%
Simplified82.9%
frac-times88.3%
Applied egg-rr88.3%
if -1.40000000000000002e-192 < y < 4.9e-222 or 7.4000000000000004e-190 < y < 2.89999999999999988e-157Initial program 64.7%
associate-*r/65.1%
+-commutative65.1%
fma-def65.1%
Simplified65.1%
Taylor expanded in x around inf 79.4%
Final simplification85.9%
(FPCore (x y)
:precision binary64
(if (or (<= y -2.65e-191)
(not
(or (<= y 2.2e-222) (and (not (<= y 6.5e-188)) (<= y 4.2e-157)))))
(+ (* (/ x y) (/ x y)) -1.0)
(+ (/ y x) (- 1.0 (/ y x)))))
double code(double x, double y) {
double tmp;
if ((y <= -2.65e-191) || !((y <= 2.2e-222) || (!(y <= 6.5e-188) && (y <= 4.2e-157)))) {
tmp = ((x / y) * (x / y)) + -1.0;
} else {
tmp = (y / x) + (1.0 - (y / x));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-2.65d-191)) .or. (.not. (y <= 2.2d-222) .or. (.not. (y <= 6.5d-188)) .and. (y <= 4.2d-157))) then
tmp = ((x / y) * (x / y)) + (-1.0d0)
else
tmp = (y / x) + (1.0d0 - (y / x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.65e-191) || !((y <= 2.2e-222) || (!(y <= 6.5e-188) && (y <= 4.2e-157)))) {
tmp = ((x / y) * (x / y)) + -1.0;
} else {
tmp = (y / x) + (1.0 - (y / x));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.65e-191) or not ((y <= 2.2e-222) or (not (y <= 6.5e-188) and (y <= 4.2e-157))): tmp = ((x / y) * (x / y)) + -1.0 else: tmp = (y / x) + (1.0 - (y / x)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.65e-191) || !((y <= 2.2e-222) || (!(y <= 6.5e-188) && (y <= 4.2e-157)))) tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0); else tmp = Float64(Float64(y / x) + Float64(1.0 - Float64(y / x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.65e-191) || ~(((y <= 2.2e-222) || (~((y <= 6.5e-188)) && (y <= 4.2e-157))))) tmp = ((x / y) * (x / y)) + -1.0; else tmp = (y / x) + (1.0 - (y / x)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.65e-191], N[Not[Or[LessEqual[y, 2.2e-222], And[N[Not[LessEqual[y, 6.5e-188]], $MachinePrecision], LessEqual[y, 4.2e-157]]]], $MachinePrecision]], N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(y / x), $MachinePrecision] + N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.65 \cdot 10^{-191} \lor \neg \left(y \leq 2.2 \cdot 10^{-222} \lor \neg \left(y \leq 6.5 \cdot 10^{-188}\right) \land y \leq 4.2 \cdot 10^{-157}\right):\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{x} + \left(1 - \frac{y}{x}\right)\\
\end{array}
\end{array}
if y < -2.64999999999999993e-191 or 2.2e-222 < y < 6.4999999999999998e-188 or 4.2e-157 < y Initial program 68.1%
associate-*r/68.7%
+-commutative68.7%
fma-def68.7%
Simplified68.7%
Taylor expanded in y around inf 57.0%
unpow257.0%
Simplified57.0%
Taylor expanded in x around 0 82.9%
sub-neg82.9%
unpow282.9%
unpow282.9%
metadata-eval82.9%
Simplified82.9%
frac-times88.3%
Applied egg-rr88.3%
if -2.64999999999999993e-191 < y < 2.2e-222 or 6.4999999999999998e-188 < y < 4.2e-157Initial program 64.7%
associate-*r/65.1%
+-commutative65.1%
fma-def65.1%
Simplified65.1%
Taylor expanded in x around inf 79.6%
mul-1-neg79.6%
unsub-neg79.6%
Simplified79.6%
Final simplification86.0%
(FPCore (x y)
:precision binary64
(if (<= y -2e-191)
-1.0
(if (<= y 5e-222)
1.0
(if (<= y 1.76e-215) -1.0 (if (<= y 5e-157) 1.0 -1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -2e-191) {
tmp = -1.0;
} else if (y <= 5e-222) {
tmp = 1.0;
} else if (y <= 1.76e-215) {
tmp = -1.0;
} else if (y <= 5e-157) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2d-191)) then
tmp = -1.0d0
else if (y <= 5d-222) then
tmp = 1.0d0
else if (y <= 1.76d-215) then
tmp = -1.0d0
else if (y <= 5d-157) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2e-191) {
tmp = -1.0;
} else if (y <= 5e-222) {
tmp = 1.0;
} else if (y <= 1.76e-215) {
tmp = -1.0;
} else if (y <= 5e-157) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2e-191: tmp = -1.0 elif y <= 5e-222: tmp = 1.0 elif y <= 1.76e-215: tmp = -1.0 elif y <= 5e-157: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2e-191) tmp = -1.0; elseif (y <= 5e-222) tmp = 1.0; elseif (y <= 1.76e-215) tmp = -1.0; elseif (y <= 5e-157) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2e-191) tmp = -1.0; elseif (y <= 5e-222) tmp = 1.0; elseif (y <= 1.76e-215) tmp = -1.0; elseif (y <= 5e-157) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2e-191], -1.0, If[LessEqual[y, 5e-222], 1.0, If[LessEqual[y, 1.76e-215], -1.0, If[LessEqual[y, 5e-157], 1.0, -1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-191}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-222}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.76 \cdot 10^{-215}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-157}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -2e-191 or 5.00000000000000008e-222 < y < 1.75999999999999992e-215 or 5.0000000000000002e-157 < y Initial program 68.3%
associate-*r/68.8%
+-commutative68.8%
fma-def68.8%
Simplified68.8%
Taylor expanded in x around 0 88.1%
if -2e-191 < y < 5.00000000000000008e-222 or 1.75999999999999992e-215 < y < 5.0000000000000002e-157Initial program 64.3%
associate-*r/64.8%
+-commutative64.8%
fma-def64.8%
Simplified64.8%
Taylor expanded in x around inf 78.6%
Final simplification85.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.7%
+-commutative67.7%
fma-def67.7%
Simplified67.7%
Taylor expanded in x around 0 69.5%
Final simplification69.5%
(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 2023174
(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))))