
(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) (+ 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) / Float64(hypot(x, y) / 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[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{x - y}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Initial program 65.2%
add-sqr-sqrt65.2%
times-frac66.1%
hypot-def66.1%
hypot-def99.9%
Applied egg-rr99.9%
log1p-expm1-u99.9%
Applied egg-rr99.9%
log1p-expm1-u99.9%
associate-*r/99.9%
associate-/r/99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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 65.2%
add-sqr-sqrt65.2%
times-frac66.1%
hypot-def66.1%
hypot-def99.9%
Applied egg-rr99.9%
*-commutative99.9%
clear-num99.9%
frac-times99.9%
*-un-lft-identity99.9%
Applied egg-rr99.9%
*-un-lft-identity99.9%
frac-times99.9%
clear-num99.9%
div-inv99.7%
associate-*l*99.7%
Applied egg-rr99.7%
associate-*l/99.7%
*-un-lft-identity99.7%
Applied egg-rr99.7%
Final simplification99.7%
(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 65.2%
add-sqr-sqrt65.2%
times-frac66.1%
hypot-def66.1%
hypot-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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 65.2%
add-sqr-sqrt65.2%
times-frac66.1%
hypot-def66.1%
hypot-def99.9%
Applied egg-rr99.9%
*-commutative99.9%
clear-num99.9%
frac-times99.9%
*-un-lft-identity99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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%
associate-*r/3.1%
fma-def3.1%
Simplified3.1%
Taylor expanded in y around inf 55.1%
associate--l+55.1%
unpow255.1%
unpow255.1%
times-frac55.1%
distribute-rgt1-in55.1%
metadata-eval55.1%
mul0-lft55.1%
+-commutative55.1%
associate--r+55.1%
metadata-eval55.1%
unpow255.1%
unpow255.1%
associate-*r/55.1%
associate-*r*55.1%
*-commutative55.1%
times-frac77.2%
Simplified77.2%
Final simplification92.1%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))) (if (<= t_0 2.0) t_0 (+ -1.0 (/ x (* y (/ y x)))))))
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 = -1.0 + (x / (y * (y / x)));
}
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 = (-1.0d0) + (x / (y * (y / x)))
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 = -1.0 + (x / (y * (y / x)));
}
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 = -1.0 + (x / (y * (y / x))) 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(-1.0 + Float64(x / Float64(y * Float64(y / x)))); 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 = -1.0 + (x / (y * (y / x))); 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[(-1.0 + N[(x / N[(y * N[(y / x), $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}:\\
\;\;\;\;-1 + \frac{x}{y \cdot \frac{y}{x}}\\
\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%
fma-def3.1%
Simplified3.1%
Taylor expanded in x around 0 56.1%
unpow256.1%
associate-/r*75.8%
Simplified75.8%
Taylor expanded in x around 0 55.1%
sub-neg55.1%
unpow255.1%
unpow255.1%
metadata-eval55.1%
Simplified55.1%
associate-/l*55.9%
div-inv55.9%
associate-/l*75.9%
Applied egg-rr75.9%
associate-*r/76.1%
*-rgt-identity76.1%
remove-double-neg76.1%
associate-/r/76.1%
distribute-rgt-neg-out76.1%
*-commutative76.1%
distribute-lft-neg-out76.1%
remove-double-neg76.1%
Simplified76.1%
Final simplification91.7%
(FPCore (x y) :precision binary64 (if (or (<= y -2.25e-153) (not (<= y 5.5e-199))) (+ -1.0 (/ x (* y (/ y x)))) (+ 1.0 (* -2.0 (* (/ y x) (/ y x))))))
double code(double x, double y) {
double tmp;
if ((y <= -2.25e-153) || !(y <= 5.5e-199)) {
tmp = -1.0 + (x / (y * (y / x)));
} else {
tmp = 1.0 + (-2.0 * ((y / x) * (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.25d-153)) .or. (.not. (y <= 5.5d-199))) then
tmp = (-1.0d0) + (x / (y * (y / x)))
else
tmp = 1.0d0 + ((-2.0d0) * ((y / x) * (y / x)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.25e-153) || !(y <= 5.5e-199)) {
tmp = -1.0 + (x / (y * (y / x)));
} else {
tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.25e-153) or not (y <= 5.5e-199): tmp = -1.0 + (x / (y * (y / x))) else: tmp = 1.0 + (-2.0 * ((y / x) * (y / x))) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.25e-153) || !(y <= 5.5e-199)) tmp = Float64(-1.0 + Float64(x / Float64(y * Float64(y / x)))); else tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / x) * Float64(y / x)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.25e-153) || ~((y <= 5.5e-199))) tmp = -1.0 + (x / (y * (y / x))); else tmp = 1.0 + (-2.0 * ((y / x) * (y / x))); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.25e-153], N[Not[LessEqual[y, 5.5e-199]], $MachinePrecision]], N[(-1.0 + N[(x / N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-2.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.25 \cdot 10^{-153} \lor \neg \left(y \leq 5.5 \cdot 10^{-199}\right):\\
\;\;\;\;-1 + \frac{x}{y \cdot \frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\end{array}
\end{array}
if y < -2.25e-153 or 5.5000000000000001e-199 < y Initial program 68.7%
associate-*r/69.3%
fma-def69.3%
Simplified69.3%
Taylor expanded in x around 0 84.1%
unpow284.1%
associate-/r*87.5%
Simplified87.5%
Taylor expanded in x around 0 84.2%
sub-neg84.2%
unpow284.2%
unpow284.2%
metadata-eval84.2%
Simplified84.2%
associate-/l*84.2%
div-inv84.2%
associate-/l*87.7%
Applied egg-rr87.7%
associate-*r/87.7%
*-rgt-identity87.7%
remove-double-neg87.7%
associate-/r/87.7%
distribute-rgt-neg-out87.7%
*-commutative87.7%
distribute-lft-neg-out87.7%
remove-double-neg87.7%
Simplified87.7%
if -2.25e-153 < y < 5.5000000000000001e-199Initial program 56.8%
associate-*r/57.3%
fma-def57.3%
Simplified57.3%
Taylor expanded in y around 0 56.8%
unpow256.8%
unpow256.8%
Simplified56.8%
times-frac83.9%
Applied egg-rr83.9%
Final simplification86.6%
(FPCore (x y) :precision binary64 (if (or (<= y -8.2e-157) (not (<= y 2.8e-199))) (+ -1.0 (/ x (* y (/ y x)))) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -8.2e-157) || !(y <= 2.8e-199)) {
tmp = -1.0 + (x / (y * (y / x)));
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-8.2d-157)) .or. (.not. (y <= 2.8d-199))) then
tmp = (-1.0d0) + (x / (y * (y / x)))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -8.2e-157) || !(y <= 2.8e-199)) {
tmp = -1.0 + (x / (y * (y / x)));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -8.2e-157) or not (y <= 2.8e-199): tmp = -1.0 + (x / (y * (y / x))) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -8.2e-157) || !(y <= 2.8e-199)) tmp = Float64(-1.0 + Float64(x / Float64(y * Float64(y / x)))); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -8.2e-157) || ~((y <= 2.8e-199))) tmp = -1.0 + (x / (y * (y / x))); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -8.2e-157], N[Not[LessEqual[y, 2.8e-199]], $MachinePrecision]], N[(-1.0 + N[(x / N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.2 \cdot 10^{-157} \lor \neg \left(y \leq 2.8 \cdot 10^{-199}\right):\\
\;\;\;\;-1 + \frac{x}{y \cdot \frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -8.2000000000000004e-157 or 2.80000000000000018e-199 < y Initial program 68.7%
associate-*r/69.3%
fma-def69.3%
Simplified69.3%
Taylor expanded in x around 0 84.1%
unpow284.1%
associate-/r*87.5%
Simplified87.5%
Taylor expanded in x around 0 84.2%
sub-neg84.2%
unpow284.2%
unpow284.2%
metadata-eval84.2%
Simplified84.2%
associate-/l*84.2%
div-inv84.2%
associate-/l*87.7%
Applied egg-rr87.7%
associate-*r/87.7%
*-rgt-identity87.7%
remove-double-neg87.7%
associate-/r/87.7%
distribute-rgt-neg-out87.7%
*-commutative87.7%
distribute-lft-neg-out87.7%
remove-double-neg87.7%
Simplified87.7%
if -8.2000000000000004e-157 < y < 2.80000000000000018e-199Initial program 56.8%
associate-*r/57.3%
fma-def57.3%
Simplified57.3%
Taylor expanded in x around inf 82.4%
Final simplification86.2%
(FPCore (x y) :precision binary64 (if (or (<= y -6.8e-157) (not (<= y 5.5e-199))) (+ -1.0 (/ x (* y (/ y x)))) (- (+ (/ y x) 1.0) (/ y x))))
double code(double x, double y) {
double tmp;
if ((y <= -6.8e-157) || !(y <= 5.5e-199)) {
tmp = -1.0 + (x / (y * (y / x)));
} 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 <= (-6.8d-157)) .or. (.not. (y <= 5.5d-199))) then
tmp = (-1.0d0) + (x / (y * (y / x)))
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 <= -6.8e-157) || !(y <= 5.5e-199)) {
tmp = -1.0 + (x / (y * (y / x)));
} else {
tmp = ((y / x) + 1.0) - (y / x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -6.8e-157) or not (y <= 5.5e-199): tmp = -1.0 + (x / (y * (y / x))) else: tmp = ((y / x) + 1.0) - (y / x) return tmp
function code(x, y) tmp = 0.0 if ((y <= -6.8e-157) || !(y <= 5.5e-199)) tmp = Float64(-1.0 + Float64(x / Float64(y * Float64(y / x)))); else tmp = Float64(Float64(Float64(y / x) + 1.0) - Float64(y / x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -6.8e-157) || ~((y <= 5.5e-199))) tmp = -1.0 + (x / (y * (y / x))); else tmp = ((y / x) + 1.0) - (y / x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -6.8e-157], N[Not[LessEqual[y, 5.5e-199]], $MachinePrecision]], N[(-1.0 + N[(x / N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y / x), $MachinePrecision] + 1.0), $MachinePrecision] - N[(y / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-157} \lor \neg \left(y \leq 5.5 \cdot 10^{-199}\right):\\
\;\;\;\;-1 + \frac{x}{y \cdot \frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{y}{x} + 1\right) - \frac{y}{x}\\
\end{array}
\end{array}
if y < -6.79999999999999955e-157 or 5.5000000000000001e-199 < y Initial program 68.7%
associate-*r/69.3%
fma-def69.3%
Simplified69.3%
Taylor expanded in x around 0 84.1%
unpow284.1%
associate-/r*87.5%
Simplified87.5%
Taylor expanded in x around 0 84.2%
sub-neg84.2%
unpow284.2%
unpow284.2%
metadata-eval84.2%
Simplified84.2%
associate-/l*84.2%
div-inv84.2%
associate-/l*87.7%
Applied egg-rr87.7%
associate-*r/87.7%
*-rgt-identity87.7%
remove-double-neg87.7%
associate-/r/87.7%
distribute-rgt-neg-out87.7%
*-commutative87.7%
distribute-lft-neg-out87.7%
remove-double-neg87.7%
Simplified87.7%
if -6.79999999999999955e-157 < y < 5.5000000000000001e-199Initial program 56.8%
add-sqr-sqrt56.8%
times-frac57.6%
hypot-def57.6%
hypot-def99.9%
Applied egg-rr99.9%
Taylor expanded in x around inf 82.5%
associate-+r+82.5%
mul-1-neg82.5%
unsub-neg82.5%
+-commutative82.5%
Simplified82.5%
Final simplification86.2%
(FPCore (x y) :precision binary64 (if (<= y -6.9e-155) -1.0 (if (<= y 5.5e-199) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -6.9e-155) {
tmp = -1.0;
} else if (y <= 5.5e-199) {
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 <= (-6.9d-155)) then
tmp = -1.0d0
else if (y <= 5.5d-199) 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 <= -6.9e-155) {
tmp = -1.0;
} else if (y <= 5.5e-199) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.9e-155: tmp = -1.0 elif y <= 5.5e-199: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -6.9e-155) tmp = -1.0; elseif (y <= 5.5e-199) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6.9e-155) tmp = -1.0; elseif (y <= 5.5e-199) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.9e-155], -1.0, If[LessEqual[y, 5.5e-199], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.9 \cdot 10^{-155}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-199}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -6.89999999999999975e-155 or 5.5000000000000001e-199 < y Initial program 68.7%
associate-*r/69.3%
fma-def69.3%
Simplified69.3%
Taylor expanded in x around 0 87.0%
if -6.89999999999999975e-155 < y < 5.5000000000000001e-199Initial program 56.8%
associate-*r/57.3%
fma-def57.3%
Simplified57.3%
Taylor expanded in x around inf 82.4%
Final simplification85.7%
(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 65.2%
associate-*r/65.9%
fma-def65.9%
Simplified65.9%
Taylor expanded in x around 0 66.7%
Final simplification66.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 2023195
(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))))