
(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)) (/ (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 71.1%
+-commutative71.1%
associate-*r/71.0%
+-commutative71.0%
fma-def71.0%
Simplified71.0%
*-un-lft-identity71.0%
add-sqr-sqrt71.0%
times-frac71.1%
fma-def71.1%
hypot-def71.1%
fma-def71.1%
hypot-def99.7%
Applied egg-rr99.7%
associate-*r*99.7%
div-inv99.9%
clear-num100.0%
un-div-inv100.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 71.1%
fma-def71.1%
add-sqr-sqrt71.1%
times-frac71.3%
fma-def71.3%
hypot-def71.3%
fma-def71.3%
hypot-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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(x - y) / Float64(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[(x - y), $MachinePrecision] / N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(N[(x + y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{\frac{\mathsf{hypot}\left(x, y\right)}{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}}
\end{array}
Initial program 71.1%
+-commutative71.1%
associate-*r/71.0%
+-commutative71.0%
fma-def71.0%
Simplified71.0%
*-un-lft-identity71.0%
add-sqr-sqrt71.0%
times-frac71.1%
fma-def71.1%
hypot-def71.1%
fma-def71.1%
hypot-def99.7%
Applied egg-rr99.7%
associate-*r*99.7%
div-inv99.9%
associate-*l/100.0%
associate-/l*100.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) (/ y x)) -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) / (y / x)), -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(y / x)), -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[(y / x), $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{\frac{x}{y}}{\frac{y}{x}}, -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%
+-commutative0.0%
associate-*r/3.1%
+-commutative3.1%
fma-def3.1%
Simplified3.1%
*-un-lft-identity3.1%
add-sqr-sqrt3.1%
times-frac3.1%
fma-def3.1%
hypot-def3.1%
fma-def3.1%
hypot-def99.7%
Applied egg-rr99.7%
associate-*r*99.7%
div-inv99.9%
associate-*l/99.9%
associate-/l*99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 54.1%
fma-neg54.1%
unpow254.1%
unpow254.1%
times-frac80.4%
unpow280.4%
metadata-eval80.4%
Simplified80.4%
unpow280.4%
clear-num80.4%
un-div-inv80.4%
Applied egg-rr80.4%
Final simplification94.3%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))) (if (<= t_0 2.0) t_0 (+ (/ x y) (+ -1.0 (* (/ x 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) + (-1.0 + ((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) + ((-1.0d0) + ((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) + (-1.0 + ((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) + (-1.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 = Float64(Float64(x / y) + Float64(-1.0 + Float64(Float64(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) + (-1.0 + ((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[(x / y), $MachinePrecision] + N[(-1.0 + N[(N[(x / y), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $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} + \left(-1 + \frac{x}{y} \cdot \left(\frac{x}{y} + -1\right)\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-def0.0%
add-sqr-sqrt0.0%
times-frac3.1%
fma-def3.1%
hypot-def3.1%
fma-def3.1%
hypot-def99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 16.6%
Taylor expanded in x around 0 79.4%
distribute-rgt-in79.4%
*-un-lft-identity79.4%
associate-+l-79.4%
sub-neg79.4%
metadata-eval79.4%
Applied egg-rr79.4%
Final simplification94.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ (/ x y) -1.0)) (t_1 (+ 1.0 (* -2.0 (* (/ y x) (/ y x))))))
(if (<= y 1.05e-238)
t_1
(if (<= y 1.3e-223)
(* t_0 (+ (/ x y) 1.0))
(if (<= y 2.6e-139) t_1 (+ (/ x y) (+ -1.0 (* (/ x y) t_0))))))))
double code(double x, double y) {
double t_0 = (x / y) + -1.0;
double t_1 = 1.0 + (-2.0 * ((y / x) * (y / x)));
double tmp;
if (y <= 1.05e-238) {
tmp = t_1;
} else if (y <= 1.3e-223) {
tmp = t_0 * ((x / y) + 1.0);
} else if (y <= 2.6e-139) {
tmp = t_1;
} else {
tmp = (x / y) + (-1.0 + ((x / y) * 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) + (-1.0d0)
t_1 = 1.0d0 + ((-2.0d0) * ((y / x) * (y / x)))
if (y <= 1.05d-238) then
tmp = t_1
else if (y <= 1.3d-223) then
tmp = t_0 * ((x / y) + 1.0d0)
else if (y <= 2.6d-139) then
tmp = t_1
else
tmp = (x / y) + ((-1.0d0) + ((x / y) * t_0))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x / y) + -1.0;
double t_1 = 1.0 + (-2.0 * ((y / x) * (y / x)));
double tmp;
if (y <= 1.05e-238) {
tmp = t_1;
} else if (y <= 1.3e-223) {
tmp = t_0 * ((x / y) + 1.0);
} else if (y <= 2.6e-139) {
tmp = t_1;
} else {
tmp = (x / y) + (-1.0 + ((x / y) * t_0));
}
return tmp;
}
def code(x, y): t_0 = (x / y) + -1.0 t_1 = 1.0 + (-2.0 * ((y / x) * (y / x))) tmp = 0 if y <= 1.05e-238: tmp = t_1 elif y <= 1.3e-223: tmp = t_0 * ((x / y) + 1.0) elif y <= 2.6e-139: tmp = t_1 else: tmp = (x / y) + (-1.0 + ((x / y) * t_0)) return tmp
function code(x, y) t_0 = Float64(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 <= 1.05e-238) tmp = t_1; elseif (y <= 1.3e-223) tmp = Float64(t_0 * Float64(Float64(x / y) + 1.0)); elseif (y <= 2.6e-139) tmp = t_1; else tmp = Float64(Float64(x / y) + Float64(-1.0 + Float64(Float64(x / y) * t_0))); end return tmp end
function tmp_2 = code(x, y) t_0 = (x / y) + -1.0; t_1 = 1.0 + (-2.0 * ((y / x) * (y / x))); tmp = 0.0; if (y <= 1.05e-238) tmp = t_1; elseif (y <= 1.3e-223) tmp = t_0 * ((x / y) + 1.0); elseif (y <= 2.6e-139) tmp = t_1; else tmp = (x / y) + (-1.0 + ((x / y) * t_0)); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x / y), $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, 1.05e-238], t$95$1, If[LessEqual[y, 1.3e-223], N[(t$95$0 * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.6e-139], t$95$1, N[(N[(x / y), $MachinePrecision] + N[(-1.0 + N[(N[(x / y), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y} + -1\\
t_1 := 1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\mathbf{if}\;y \leq 1.05 \cdot 10^{-238}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-223}:\\
\;\;\;\;t_0 \cdot \left(\frac{x}{y} + 1\right)\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-139}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y} + \left(-1 + \frac{x}{y} \cdot t_0\right)\\
\end{array}
\end{array}
if y < 1.0500000000000001e-238 or 1.3e-223 < y < 2.5999999999999998e-139Initial program 66.5%
+-commutative66.5%
associate-*r/66.4%
+-commutative66.4%
fma-def66.4%
Simplified66.4%
Taylor expanded in y around 0 29.3%
unpow229.3%
unpow229.3%
times-frac36.7%
Applied egg-rr36.7%
if 1.0500000000000001e-238 < y < 1.3e-223Initial program 0.0%
fma-def0.0%
add-sqr-sqrt0.0%
times-frac3.1%
fma-def3.1%
hypot-def3.1%
fma-def3.1%
hypot-def99.5%
Applied egg-rr99.5%
Taylor expanded in x around 0 80.5%
Taylor expanded in x around 0 80.0%
if 2.5999999999999998e-139 < y Initial program 100.0%
fma-def100.0%
add-sqr-sqrt100.0%
times-frac100.0%
fma-def100.0%
hypot-def100.0%
fma-def100.0%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 84.3%
Taylor expanded in x around 0 84.0%
distribute-rgt-in84.0%
*-un-lft-identity84.0%
associate-+l-84.0%
sub-neg84.0%
metadata-eval84.0%
Applied egg-rr84.0%
Final simplification46.4%
(FPCore (x y)
:precision binary64
(if (<= y 1.05e-238)
1.0
(if (or (<= y 1.3e-223) (not (<= y 3.1e-172)))
(* (+ (/ x y) -1.0) (+ (/ x y) 1.0))
1.0)))
double code(double x, double y) {
double tmp;
if (y <= 1.05e-238) {
tmp = 1.0;
} else if ((y <= 1.3e-223) || !(y <= 3.1e-172)) {
tmp = ((x / y) + -1.0) * ((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.05d-238) then
tmp = 1.0d0
else if ((y <= 1.3d-223) .or. (.not. (y <= 3.1d-172))) then
tmp = ((x / y) + (-1.0d0)) * ((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.05e-238) {
tmp = 1.0;
} else if ((y <= 1.3e-223) || !(y <= 3.1e-172)) {
tmp = ((x / y) + -1.0) * ((x / y) + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.05e-238: tmp = 1.0 elif (y <= 1.3e-223) or not (y <= 3.1e-172): tmp = ((x / y) + -1.0) * ((x / y) + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.05e-238) tmp = 1.0; elseif ((y <= 1.3e-223) || !(y <= 3.1e-172)) tmp = Float64(Float64(Float64(x / y) + -1.0) * Float64(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.05e-238) tmp = 1.0; elseif ((y <= 1.3e-223) || ~((y <= 3.1e-172))) tmp = ((x / y) + -1.0) * ((x / y) + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.05e-238], 1.0, If[Or[LessEqual[y, 1.3e-223], N[Not[LessEqual[y, 3.1e-172]], $MachinePrecision]], N[(N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.05 \cdot 10^{-238}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-223} \lor \neg \left(y \leq 3.1 \cdot 10^{-172}\right):\\
\;\;\;\;\left(\frac{x}{y} + -1\right) \cdot \left(\frac{x}{y} + 1\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < 1.0500000000000001e-238 or 1.3e-223 < y < 3.1000000000000003e-172Initial program 65.4%
+-commutative65.4%
associate-*r/65.4%
+-commutative65.4%
fma-def65.4%
Simplified65.4%
Taylor expanded in x around inf 34.2%
if 1.0500000000000001e-238 < y < 1.3e-223 or 3.1000000000000003e-172 < y Initial program 88.7%
fma-def88.7%
add-sqr-sqrt88.7%
times-frac89.0%
fma-def89.0%
hypot-def89.0%
fma-def89.0%
hypot-def99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 80.1%
Taylor expanded in x around 0 79.8%
Final simplification45.3%
(FPCore (x y) :precision binary64 (if (or (<= y 1.05e-238) (and (not (<= y 1.3e-223)) (<= y 8.2e-140))) (+ 1.0 (* -2.0 (* (/ y x) (/ y x)))) (* (+ (/ x y) -1.0) (+ (/ x y) 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= 1.05e-238) || (!(y <= 1.3e-223) && (y <= 8.2e-140))) {
tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
} else {
tmp = ((x / y) + -1.0) * ((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.05d-238) .or. (.not. (y <= 1.3d-223)) .and. (y <= 8.2d-140)) then
tmp = 1.0d0 + ((-2.0d0) * ((y / x) * (y / x)))
else
tmp = ((x / y) + (-1.0d0)) * ((x / y) + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 1.05e-238) || (!(y <= 1.3e-223) && (y <= 8.2e-140))) {
tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
} else {
tmp = ((x / y) + -1.0) * ((x / y) + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 1.05e-238) or (not (y <= 1.3e-223) and (y <= 8.2e-140)): tmp = 1.0 + (-2.0 * ((y / x) * (y / x))) else: tmp = ((x / y) + -1.0) * ((x / y) + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= 1.05e-238) || (!(y <= 1.3e-223) && (y <= 8.2e-140))) tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / x) * Float64(y / x)))); else tmp = Float64(Float64(Float64(x / y) + -1.0) * Float64(Float64(x / y) + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 1.05e-238) || (~((y <= 1.3e-223)) && (y <= 8.2e-140))) tmp = 1.0 + (-2.0 * ((y / x) * (y / x))); else tmp = ((x / y) + -1.0) * ((x / y) + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 1.05e-238], And[N[Not[LessEqual[y, 1.3e-223]], $MachinePrecision], LessEqual[y, 8.2e-140]]], N[(1.0 + N[(-2.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.05 \cdot 10^{-238} \lor \neg \left(y \leq 1.3 \cdot 10^{-223}\right) \land y \leq 8.2 \cdot 10^{-140}:\\
\;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{x}{y} + -1\right) \cdot \left(\frac{x}{y} + 1\right)\\
\end{array}
\end{array}
if y < 1.0500000000000001e-238 or 1.3e-223 < y < 8.2000000000000003e-140Initial program 66.5%
+-commutative66.5%
associate-*r/66.4%
+-commutative66.4%
fma-def66.4%
Simplified66.4%
Taylor expanded in y around 0 29.3%
unpow229.3%
unpow229.3%
times-frac36.7%
Applied egg-rr36.7%
if 1.0500000000000001e-238 < y < 1.3e-223 or 8.2000000000000003e-140 < y Initial program 88.6%
fma-def88.6%
add-sqr-sqrt88.6%
times-frac89.0%
fma-def89.0%
hypot-def89.0%
fma-def89.0%
hypot-def99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 83.9%
Taylor expanded in x around 0 83.6%
Final simplification46.4%
(FPCore (x y) :precision binary64 (if (<= y 1.05e-238) 1.0 (if (<= y 1.3e-223) -1.0 (if (<= y 4e-172) 1.0 -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 1.05e-238) {
tmp = 1.0;
} else if (y <= 1.3e-223) {
tmp = -1.0;
} else if (y <= 4e-172) {
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.05d-238) then
tmp = 1.0d0
else if (y <= 1.3d-223) then
tmp = -1.0d0
else if (y <= 4d-172) 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.05e-238) {
tmp = 1.0;
} else if (y <= 1.3e-223) {
tmp = -1.0;
} else if (y <= 4e-172) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.05e-238: tmp = 1.0 elif y <= 1.3e-223: tmp = -1.0 elif y <= 4e-172: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.05e-238) tmp = 1.0; elseif (y <= 1.3e-223) tmp = -1.0; elseif (y <= 4e-172) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.05e-238) tmp = 1.0; elseif (y <= 1.3e-223) tmp = -1.0; elseif (y <= 4e-172) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.05e-238], 1.0, If[LessEqual[y, 1.3e-223], -1.0, If[LessEqual[y, 4e-172], 1.0, -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.05 \cdot 10^{-238}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-223}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-172}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.0500000000000001e-238 or 1.3e-223 < y < 4.0000000000000002e-172Initial program 65.4%
+-commutative65.4%
associate-*r/65.4%
+-commutative65.4%
fma-def65.4%
Simplified65.4%
Taylor expanded in x around inf 34.2%
if 1.0500000000000001e-238 < y < 1.3e-223 or 4.0000000000000002e-172 < y Initial program 88.7%
+-commutative88.7%
associate-*r/88.6%
+-commutative88.6%
fma-def88.6%
Simplified88.6%
Taylor expanded in x around 0 78.9%
Final simplification45.1%
(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 71.1%
+-commutative71.1%
associate-*r/71.0%
+-commutative71.0%
fma-def71.0%
Simplified71.0%
Taylor expanded in x around 0 69.4%
Final simplification69.4%
(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 2024018
(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))))