
(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}
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (/ (* (/ (- x y) (hypot x y)) (+ x y)) (hypot x y)))
y = abs(y);
double code(double x, double y) {
return (((x - y) / hypot(x, y)) * (x + y)) / hypot(x, y);
}
y = Math.abs(y);
public static double code(double x, double y) {
return (((x - y) / Math.hypot(x, y)) * (x + y)) / Math.hypot(x, y);
}
y = abs(y) def code(x, y): return (((x - y) / math.hypot(x, y)) * (x + y)) / math.hypot(x, y)
y = abs(y) function code(x, y) return Float64(Float64(Float64(Float64(x - y) / hypot(x, y)) * Float64(x + y)) / hypot(x, y)) end
y = abs(y) function tmp = code(x, y) tmp = (((x - y) / hypot(x, y)) * (x + y)) / hypot(x, y); end
NOTE: y should be positive before calling this function code[x_, y_] := N[(N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(x + y\right)}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Initial program 62.5%
add-sqr-sqrt62.5%
times-frac63.2%
hypot-def63.2%
hypot-def99.9%
Applied egg-rr99.9%
associate-*r/100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))) (if (<= t_0 2.0) t_0 (/ (- (* x (* (/ x y) 1.5)) y) (hypot x y)))))
y = abs(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 * ((x / y) * 1.5)) - y) / hypot(x, y);
}
return tmp;
}
y = Math.abs(y);
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 * ((x / y) * 1.5)) - y) / Math.hypot(x, y);
}
return tmp;
}
y = abs(y) 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 * ((x / y) * 1.5)) - y) / math.hypot(x, y) return tmp
y = abs(y) 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 * Float64(Float64(x / y) * 1.5)) - y) / hypot(x, y)); end return tmp end
y = abs(y) 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 * ((x / y) * 1.5)) - y) / hypot(x, y); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function
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 * N[(N[(x / y), $MachinePrecision] * 1.5), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\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 \cdot \left(\frac{x}{y} \cdot 1.5\right) - y}{\mathsf{hypot}\left(x, 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%
add-sqr-sqrt0.0%
times-frac3.1%
hypot-def3.1%
hypot-def99.9%
Applied egg-rr99.9%
associate-*r/99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in y around inf 14.2%
cancel-sign-sub-inv14.2%
associate-+r+14.2%
+-commutative14.2%
neg-mul-114.2%
sub-neg14.2%
associate-+r+14.2%
sub-neg14.2%
neg-mul-114.2%
associate-+r+14.4%
distribute-lft1-in14.4%
metadata-eval14.4%
mul0-lft14.4%
neg-mul-114.4%
sub-neg14.4%
neg-sub014.4%
unpow214.4%
associate-/l*14.5%
metadata-eval14.5%
unpow214.5%
associate-/l*14.6%
Simplified14.6%
Taylor expanded in y around 0 14.4%
distribute-rgt1-in14.4%
metadata-eval14.4%
+-commutative14.4%
metadata-eval14.4%
unpow214.4%
associate-*r/14.6%
distribute-rgt1-in14.6%
*-commutative14.6%
fma-udef14.6%
mul-1-neg14.6%
unsub-neg14.6%
fma-udef14.6%
*-commutative14.6%
*-lft-identity14.6%
distribute-rgt-out14.6%
metadata-eval14.6%
associate-*l*14.6%
Simplified14.6%
Final simplification68.0%
NOTE: y should be positive before calling this function
(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)))))y = abs(y);
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;
}
NOTE: y should be positive before calling this function
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
y = Math.abs(y);
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;
}
y = abs(y) 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
y = abs(y) 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
y = abs(y) 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
NOTE: y should be positive before calling this function
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}
y = |y|\\
\\
\begin{array}{l}
t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
t_1 := \frac{x}{y} \cdot \frac{x}{y}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1 + \left(t_1 + -1\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2Initial program 100.0%
if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) Initial program 0.0%
add-sqr-sqrt0.0%
times-frac3.1%
hypot-def3.1%
hypot-def99.9%
Applied egg-rr99.9%
associate-*r/99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in y around inf 53.1%
associate--l+53.1%
unpow253.1%
unpow253.1%
times-frac53.1%
distribute-rgt1-in53.1%
metadata-eval53.1%
mul0-lft53.1%
neg-sub053.1%
+-commutative53.1%
mul-1-neg53.1%
unsub-neg53.1%
unpow253.1%
unpow253.1%
times-frac81.7%
Simplified81.7%
Final simplification93.1%
NOTE: y should be positive before calling this function (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))))
y = abs(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;
}
return tmp;
}
NOTE: y should be positive before calling this function
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
y = Math.abs(y);
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;
}
y = abs(y) 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
y = abs(y) 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
y = abs(y) 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
NOTE: y should be positive before calling this function
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}
y = |y|\\
\\
\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%
Taylor expanded in x around 0 0.0%
unpow20.0%
Simplified0.0%
Taylor expanded in x around 0 53.1%
sub-neg53.1%
unpow253.1%
unpow253.1%
times-frac81.1%
metadata-eval81.1%
Simplified81.1%
Final simplification92.9%
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(if (<= y 1.3e-180)
1.0
(if (<= y 9.2e-150)
(+ (* (/ x y) (/ x y)) -1.0)
(if (<= y 5.5e-131)
(+ 1.0 (* -2.0 (/ (* y y) (* x x))))
(* (/ (+ x y) y) (+ (/ x y) -1.0))))))y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 1.3e-180) {
tmp = 1.0;
} else if (y <= 9.2e-150) {
tmp = ((x / y) * (x / y)) + -1.0;
} else if (y <= 5.5e-131) {
tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
} else {
tmp = ((x + y) / y) * ((x / y) + -1.0);
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 1.3d-180) then
tmp = 1.0d0
else if (y <= 9.2d-150) then
tmp = ((x / y) * (x / y)) + (-1.0d0)
else if (y <= 5.5d-131) then
tmp = 1.0d0 + ((-2.0d0) * ((y * y) / (x * x)))
else
tmp = ((x + y) / y) * ((x / y) + (-1.0d0))
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if (y <= 1.3e-180) {
tmp = 1.0;
} else if (y <= 9.2e-150) {
tmp = ((x / y) * (x / y)) + -1.0;
} else if (y <= 5.5e-131) {
tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
} else {
tmp = ((x + y) / y) * ((x / y) + -1.0);
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 1.3e-180: tmp = 1.0 elif y <= 9.2e-150: tmp = ((x / y) * (x / y)) + -1.0 elif y <= 5.5e-131: tmp = 1.0 + (-2.0 * ((y * y) / (x * x))) else: tmp = ((x + y) / y) * ((x / y) + -1.0) return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 1.3e-180) tmp = 1.0; elseif (y <= 9.2e-150) tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0); elseif (y <= 5.5e-131) tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y * y) / Float64(x * x)))); else tmp = Float64(Float64(Float64(x + y) / y) * Float64(Float64(x / y) + -1.0)); end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.3e-180) tmp = 1.0; elseif (y <= 9.2e-150) tmp = ((x / y) * (x / y)) + -1.0; elseif (y <= 5.5e-131) tmp = 1.0 + (-2.0 * ((y * y) / (x * x))); else tmp = ((x + y) / y) * ((x / y) + -1.0); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 1.3e-180], 1.0, If[LessEqual[y, 9.2e-150], N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[y, 5.5e-131], N[(1.0 + N[(-2.0 * N[(N[(y * y), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.3 \cdot 10^{-180}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 9.2 \cdot 10^{-150}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-131}:\\
\;\;\;\;1 + -2 \cdot \frac{y \cdot y}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{y} \cdot \left(\frac{x}{y} + -1\right)\\
\end{array}
\end{array}
if y < 1.2999999999999999e-180Initial program 57.1%
associate-*r/57.6%
+-commutative57.6%
fma-def57.6%
Simplified57.6%
Taylor expanded in x around inf 33.5%
if 1.2999999999999999e-180 < y < 9.20000000000000011e-150Initial program 64.3%
Taylor expanded in x around 0 22.9%
unpow222.9%
Simplified22.9%
Taylor expanded in x around 0 22.9%
sub-neg22.9%
unpow222.9%
unpow222.9%
times-frac57.4%
metadata-eval57.4%
Simplified57.4%
if 9.20000000000000011e-150 < y < 5.4999999999999997e-131Initial program 100.0%
associate-*r/100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
unpow2100.0%
unpow2100.0%
Simplified100.0%
if 5.4999999999999997e-131 < y Initial program 99.9%
Taylor expanded in x around 0 81.3%
unpow281.3%
Simplified81.3%
*-commutative81.3%
times-frac81.3%
div-sub81.3%
pow181.3%
pow181.3%
pow-div81.3%
metadata-eval81.3%
metadata-eval81.3%
Applied egg-rr81.3%
Final simplification40.6%
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (* -2.0 (/ (/ y (/ x y)) x)))))
(if (<= y 1.1e-179)
t_0
(if (<= y 4.2e-149)
(+ (* (/ x y) (/ x y)) -1.0)
(if (<= y 6.8e-130) t_0 (* (/ (+ x y) y) (+ (/ x y) -1.0)))))))y = abs(y);
double code(double x, double y) {
double t_0 = 1.0 + (-2.0 * ((y / (x / y)) / x));
double tmp;
if (y <= 1.1e-179) {
tmp = t_0;
} else if (y <= 4.2e-149) {
tmp = ((x / y) * (x / y)) + -1.0;
} else if (y <= 6.8e-130) {
tmp = t_0;
} else {
tmp = ((x + y) / y) * ((x / y) + -1.0);
}
return tmp;
}
NOTE: y should be positive before calling this function
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 = 1.0d0 + ((-2.0d0) * ((y / (x / y)) / x))
if (y <= 1.1d-179) then
tmp = t_0
else if (y <= 4.2d-149) then
tmp = ((x / y) * (x / y)) + (-1.0d0)
else if (y <= 6.8d-130) then
tmp = t_0
else
tmp = ((x + y) / y) * ((x / y) + (-1.0d0))
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double t_0 = 1.0 + (-2.0 * ((y / (x / y)) / x));
double tmp;
if (y <= 1.1e-179) {
tmp = t_0;
} else if (y <= 4.2e-149) {
tmp = ((x / y) * (x / y)) + -1.0;
} else if (y <= 6.8e-130) {
tmp = t_0;
} else {
tmp = ((x + y) / y) * ((x / y) + -1.0);
}
return tmp;
}
y = abs(y) def code(x, y): t_0 = 1.0 + (-2.0 * ((y / (x / y)) / x)) tmp = 0 if y <= 1.1e-179: tmp = t_0 elif y <= 4.2e-149: tmp = ((x / y) * (x / y)) + -1.0 elif y <= 6.8e-130: tmp = t_0 else: tmp = ((x + y) / y) * ((x / y) + -1.0) return tmp
y = abs(y) function code(x, y) t_0 = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / Float64(x / y)) / x))) tmp = 0.0 if (y <= 1.1e-179) tmp = t_0; elseif (y <= 4.2e-149) tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0); elseif (y <= 6.8e-130) tmp = t_0; else tmp = Float64(Float64(Float64(x + y) / y) * Float64(Float64(x / y) + -1.0)); end return tmp end
y = abs(y) function tmp_2 = code(x, y) t_0 = 1.0 + (-2.0 * ((y / (x / y)) / x)); tmp = 0.0; if (y <= 1.1e-179) tmp = t_0; elseif (y <= 4.2e-149) tmp = ((x / y) * (x / y)) + -1.0; elseif (y <= 6.8e-130) tmp = t_0; else tmp = ((x + y) / y) * ((x / y) + -1.0); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(-2.0 * N[(N[(y / N[(x / y), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 1.1e-179], t$95$0, If[LessEqual[y, 4.2e-149], N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[y, 6.8e-130], t$95$0, N[(N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := 1 + -2 \cdot \frac{\frac{y}{\frac{x}{y}}}{x}\\
\mathbf{if}\;y \leq 1.1 \cdot 10^{-179}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-149}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-130}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{y} \cdot \left(\frac{x}{y} + -1\right)\\
\end{array}
\end{array}
if y < 1.10000000000000002e-179 or 4.20000000000000022e-149 < y < 6.8000000000000001e-130Initial program 57.5%
associate-*r/58.0%
+-commutative58.0%
fma-def58.0%
Simplified58.0%
Taylor expanded in y around 0 27.1%
unpow227.1%
unpow227.1%
Simplified27.1%
associate-/r*35.5%
div-inv35.5%
Applied egg-rr35.5%
associate-*r/35.5%
unpow235.5%
*-rgt-identity35.5%
unpow235.5%
associate-/l*36.4%
Simplified36.4%
if 1.10000000000000002e-179 < y < 4.20000000000000022e-149Initial program 64.3%
Taylor expanded in x around 0 22.9%
unpow222.9%
Simplified22.9%
Taylor expanded in x around 0 22.9%
sub-neg22.9%
unpow222.9%
unpow222.9%
times-frac57.4%
metadata-eval57.4%
Simplified57.4%
if 6.8000000000000001e-130 < y Initial program 99.9%
Taylor expanded in x around 0 81.3%
unpow281.3%
Simplified81.3%
*-commutative81.3%
times-frac81.3%
div-sub81.3%
pow181.3%
pow181.3%
pow-div81.3%
metadata-eval81.3%
metadata-eval81.3%
Applied egg-rr81.3%
Final simplification42.4%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 1e-180) 1.0 (if (<= y 5.1e-148) -1.0 (if (<= y 2.25e-125) 1.0 (/ (- x y) y)))))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 1e-180) {
tmp = 1.0;
} else if (y <= 5.1e-148) {
tmp = -1.0;
} else if (y <= 2.25e-125) {
tmp = 1.0;
} else {
tmp = (x - y) / y;
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 1d-180) then
tmp = 1.0d0
else if (y <= 5.1d-148) then
tmp = -1.0d0
else if (y <= 2.25d-125) then
tmp = 1.0d0
else
tmp = (x - y) / y
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if (y <= 1e-180) {
tmp = 1.0;
} else if (y <= 5.1e-148) {
tmp = -1.0;
} else if (y <= 2.25e-125) {
tmp = 1.0;
} else {
tmp = (x - y) / y;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 1e-180: tmp = 1.0 elif y <= 5.1e-148: tmp = -1.0 elif y <= 2.25e-125: tmp = 1.0 else: tmp = (x - y) / y return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 1e-180) tmp = 1.0; elseif (y <= 5.1e-148) tmp = -1.0; elseif (y <= 2.25e-125) tmp = 1.0; else tmp = Float64(Float64(x - y) / y); end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1e-180) tmp = 1.0; elseif (y <= 5.1e-148) tmp = -1.0; elseif (y <= 2.25e-125) tmp = 1.0; else tmp = (x - y) / y; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 1e-180], 1.0, If[LessEqual[y, 5.1e-148], -1.0, If[LessEqual[y, 2.25e-125], 1.0, N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 10^{-180}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.1 \cdot 10^{-148}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 2.25 \cdot 10^{-125}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y}{y}\\
\end{array}
\end{array}
if y < 1e-180 or 5.1e-148 < y < 2.25000000000000006e-125Initial program 57.5%
associate-*r/58.0%
+-commutative58.0%
fma-def58.0%
Simplified58.0%
Taylor expanded in x around inf 34.1%
if 1e-180 < y < 5.1e-148Initial program 64.3%
associate-*r/64.3%
+-commutative64.3%
fma-def64.3%
Simplified64.3%
Taylor expanded in x around 0 56.4%
if 2.25000000000000006e-125 < y Initial program 99.9%
associate-/l*99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around 0 81.1%
Final simplification40.5%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 1.45e-180) 1.0 (+ (* (/ x y) (/ x y)) -1.0)))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 1.45e-180) {
tmp = 1.0;
} else {
tmp = ((x / y) * (x / y)) + -1.0;
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 1.45d-180) then
tmp = 1.0d0
else
tmp = ((x / y) * (x / y)) + (-1.0d0)
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if (y <= 1.45e-180) {
tmp = 1.0;
} else {
tmp = ((x / y) * (x / y)) + -1.0;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 1.45e-180: tmp = 1.0 else: tmp = ((x / y) * (x / y)) + -1.0 return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 1.45e-180) tmp = 1.0; else tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0); end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.45e-180) tmp = 1.0; else tmp = ((x / y) * (x / y)) + -1.0; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 1.45e-180], 1.0, N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.45 \cdot 10^{-180}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\
\end{array}
\end{array}
if y < 1.4499999999999999e-180Initial program 57.1%
associate-*r/57.6%
+-commutative57.6%
fma-def57.6%
Simplified57.6%
Taylor expanded in x around inf 33.5%
if 1.4499999999999999e-180 < y Initial program 88.6%
Taylor expanded in x around 0 59.3%
unpow259.3%
Simplified59.3%
Taylor expanded in x around 0 59.3%
sub-neg59.3%
unpow259.3%
unpow259.3%
times-frac70.3%
metadata-eval70.3%
Simplified70.3%
Final simplification39.8%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 1.5e-179) 1.0 (if (<= y 1e-149) -1.0 (if (<= y 2e-132) 1.0 -1.0))))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 1.5e-179) {
tmp = 1.0;
} else if (y <= 1e-149) {
tmp = -1.0;
} else if (y <= 2e-132) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 1.5d-179) then
tmp = 1.0d0
else if (y <= 1d-149) then
tmp = -1.0d0
else if (y <= 2d-132) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if (y <= 1.5e-179) {
tmp = 1.0;
} else if (y <= 1e-149) {
tmp = -1.0;
} else if (y <= 2e-132) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 1.5e-179: tmp = 1.0 elif y <= 1e-149: tmp = -1.0 elif y <= 2e-132: tmp = 1.0 else: tmp = -1.0 return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 1.5e-179) tmp = 1.0; elseif (y <= 1e-149) tmp = -1.0; elseif (y <= 2e-132) tmp = 1.0; else tmp = -1.0; end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.5e-179) tmp = 1.0; elseif (y <= 1e-149) tmp = -1.0; elseif (y <= 2e-132) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 1.5e-179], 1.0, If[LessEqual[y, 1e-149], -1.0, If[LessEqual[y, 2e-132], 1.0, -1.0]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.5 \cdot 10^{-179}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 10^{-149}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-132}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.50000000000000003e-179 or 9.99999999999999979e-150 < y < 2e-132Initial program 57.3%
associate-*r/57.8%
+-commutative57.8%
fma-def57.8%
Simplified57.8%
Taylor expanded in x around inf 33.8%
if 1.50000000000000003e-179 < y < 9.99999999999999979e-150 or 2e-132 < y Initial program 88.3%
associate-*r/88.1%
+-commutative88.1%
fma-def88.1%
Simplified88.1%
Taylor expanded in x around 0 70.7%
Final simplification40.0%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 -1.0)
y = abs(y);
double code(double x, double y) {
return -1.0;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
y = Math.abs(y);
public static double code(double x, double y) {
return -1.0;
}
y = abs(y) def code(x, y): return -1.0
y = abs(y) function code(x, y) return -1.0 end
y = abs(y) function tmp = code(x, y) tmp = -1.0; end
NOTE: y should be positive before calling this function code[x_, y_] := -1.0
\begin{array}{l}
y = |y|\\
\\
-1
\end{array}
Initial program 62.5%
associate-*r/62.9%
+-commutative62.9%
fma-def62.9%
Simplified62.9%
Taylor expanded in x around 0 66.5%
Final simplification66.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 2023257
(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))))