
(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}
y_m = (fabs.f64 y) (FPCore (x y_m) :precision binary64 (/ (* (+ x y_m) (/ (- y_m x) (hypot x y_m))) (- (hypot x y_m))))
y_m = fabs(y);
double code(double x, double y_m) {
return ((x + y_m) * ((y_m - x) / hypot(x, y_m))) / -hypot(x, y_m);
}
y_m = Math.abs(y);
public static double code(double x, double y_m) {
return ((x + y_m) * ((y_m - x) / Math.hypot(x, y_m))) / -Math.hypot(x, y_m);
}
y_m = math.fabs(y) def code(x, y_m): return ((x + y_m) * ((y_m - x) / math.hypot(x, y_m))) / -math.hypot(x, y_m)
y_m = abs(y) function code(x, y_m) return Float64(Float64(Float64(x + y_m) * Float64(Float64(y_m - x) / hypot(x, y_m))) / Float64(-hypot(x, y_m))) end
y_m = abs(y); function tmp = code(x, y_m) tmp = ((x + y_m) * ((y_m - x) / hypot(x, y_m))) / -hypot(x, y_m); end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_] := N[(N[(N[(x + y$95$m), $MachinePrecision] * N[(N[(y$95$m - x), $MachinePrecision] / N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
y_m = \left|y\right|
\\
\frac{\left(x + y_m\right) \cdot \frac{y_m - x}{\mathsf{hypot}\left(x, y_m\right)}}{-\mathsf{hypot}\left(x, y_m\right)}
\end{array}
Initial program 61.5%
add-sqr-sqrt61.5%
times-frac62.2%
hypot-def62.2%
hypot-def100.0%
Applied egg-rr100.0%
frac-2neg100.0%
associate-*r/100.0%
Applied egg-rr100.0%
Final simplification100.0%
y_m = (fabs.f64 y) (FPCore (x y_m) :precision binary64 (* (/ (- x y_m) (hypot x y_m)) (/ (+ x y_m) (hypot x y_m))))
y_m = fabs(y);
double code(double x, double y_m) {
return ((x - y_m) / hypot(x, y_m)) * ((x + y_m) / hypot(x, y_m));
}
y_m = Math.abs(y);
public static double code(double x, double y_m) {
return ((x - y_m) / Math.hypot(x, y_m)) * ((x + y_m) / Math.hypot(x, y_m));
}
y_m = math.fabs(y) def code(x, y_m): return ((x - y_m) / math.hypot(x, y_m)) * ((x + y_m) / math.hypot(x, y_m))
y_m = abs(y) function code(x, y_m) return Float64(Float64(Float64(x - y_m) / hypot(x, y_m)) * Float64(Float64(x + y_m) / hypot(x, y_m))) end
y_m = abs(y); function tmp = code(x, y_m) tmp = ((x - y_m) / hypot(x, y_m)) * ((x + y_m) / hypot(x, y_m)); end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_] := N[(N[(N[(x - y$95$m), $MachinePrecision] / N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(x + y$95$m), $MachinePrecision] / N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y_m = \left|y\right|
\\
\frac{x - y_m}{\mathsf{hypot}\left(x, y_m\right)} \cdot \frac{x + y_m}{\mathsf{hypot}\left(x, y_m\right)}
\end{array}
Initial program 61.5%
add-sqr-sqrt61.5%
times-frac62.2%
hypot-def62.2%
hypot-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
y_m = (fabs.f64 y) (FPCore (x y_m) :precision binary64 (/ (+ x y_m) (* (hypot x y_m) (/ (hypot x y_m) (- x y_m)))))
y_m = fabs(y);
double code(double x, double y_m) {
return (x + y_m) / (hypot(x, y_m) * (hypot(x, y_m) / (x - y_m)));
}
y_m = Math.abs(y);
public static double code(double x, double y_m) {
return (x + y_m) / (Math.hypot(x, y_m) * (Math.hypot(x, y_m) / (x - y_m)));
}
y_m = math.fabs(y) def code(x, y_m): return (x + y_m) / (math.hypot(x, y_m) * (math.hypot(x, y_m) / (x - y_m)))
y_m = abs(y) function code(x, y_m) return Float64(Float64(x + y_m) / Float64(hypot(x, y_m) * Float64(hypot(x, y_m) / Float64(x - y_m)))) end
y_m = abs(y); function tmp = code(x, y_m) tmp = (x + y_m) / (hypot(x, y_m) * (hypot(x, y_m) / (x - y_m))); end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_] := N[(N[(x + y$95$m), $MachinePrecision] / N[(N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision] * N[(N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision] / N[(x - y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y_m = \left|y\right|
\\
\frac{x + y_m}{\mathsf{hypot}\left(x, y_m\right) \cdot \frac{\mathsf{hypot}\left(x, y_m\right)}{x - y_m}}
\end{array}
Initial program 61.5%
add-sqr-sqrt61.5%
times-frac62.2%
hypot-def62.2%
hypot-def100.0%
Applied egg-rr100.0%
*-commutative100.0%
clear-num100.0%
frac-times100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
y_m = (fabs.f64 y) (FPCore (x y_m) :precision binary64 (let* ((t_0 (/ (* (- x y_m) (+ x y_m)) (+ (* x x) (* y_m y_m))))) (if (<= t_0 2.0) t_0 (* (/ (+ x y_m) (hypot x y_m)) (+ (/ x y_m) -1.0)))))
y_m = fabs(y);
double code(double x, double y_m) {
double t_0 = ((x - y_m) * (x + y_m)) / ((x * x) + (y_m * y_m));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = ((x + y_m) / hypot(x, y_m)) * ((x / y_m) + -1.0);
}
return tmp;
}
y_m = Math.abs(y);
public static double code(double x, double y_m) {
double t_0 = ((x - y_m) * (x + y_m)) / ((x * x) + (y_m * y_m));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = ((x + y_m) / Math.hypot(x, y_m)) * ((x / y_m) + -1.0);
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m): t_0 = ((x - y_m) * (x + y_m)) / ((x * x) + (y_m * y_m)) tmp = 0 if t_0 <= 2.0: tmp = t_0 else: tmp = ((x + y_m) / math.hypot(x, y_m)) * ((x / y_m) + -1.0) return tmp
y_m = abs(y) function code(x, y_m) t_0 = Float64(Float64(Float64(x - y_m) * Float64(x + y_m)) / Float64(Float64(x * x) + Float64(y_m * y_m))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(Float64(Float64(x + y_m) / hypot(x, y_m)) * Float64(Float64(x / y_m) + -1.0)); end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m) t_0 = ((x - y_m) * (x + y_m)) / ((x * x) + (y_m * y_m)); tmp = 0.0; if (t_0 <= 2.0) tmp = t_0; else tmp = ((x + y_m) / hypot(x, y_m)) * ((x / y_m) + -1.0); end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_] := Block[{t$95$0 = N[(N[(N[(x - y$95$m), $MachinePrecision] * N[(x + y$95$m), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(N[(N[(x + y$95$m), $MachinePrecision] / N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(x / y$95$m), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_0 := \frac{\left(x - y_m\right) \cdot \left(x + y_m\right)}{x \cdot x + y_m \cdot y_m}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y_m}{\mathsf{hypot}\left(x, y_m\right)} \cdot \left(\frac{x}{y_m} + -1\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2Initial program 99.6%
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-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 13.7%
Final simplification66.7%
y_m = (fabs.f64 y)
(FPCore (x y_m)
:precision binary64
(if (or (<= y_m 5.4e-197)
(and (not (<= y_m 2.65e-171))
(or (<= y_m 3.6e-140)
(and (not (<= y_m 1.5e-130)) (<= y_m 2.95e-111)))))
(* (- 1.0 (/ y_m x)) (+ 1.0 (/ y_m x)))
(/ (- x y_m) y_m)))y_m = fabs(y);
double code(double x, double y_m) {
double tmp;
if ((y_m <= 5.4e-197) || (!(y_m <= 2.65e-171) && ((y_m <= 3.6e-140) || (!(y_m <= 1.5e-130) && (y_m <= 2.95e-111))))) {
tmp = (1.0 - (y_m / x)) * (1.0 + (y_m / x));
} else {
tmp = (x - y_m) / y_m;
}
return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8) :: tmp
if ((y_m <= 5.4d-197) .or. (.not. (y_m <= 2.65d-171)) .and. (y_m <= 3.6d-140) .or. (.not. (y_m <= 1.5d-130)) .and. (y_m <= 2.95d-111)) then
tmp = (1.0d0 - (y_m / x)) * (1.0d0 + (y_m / x))
else
tmp = (x - y_m) / y_m
end if
code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m) {
double tmp;
if ((y_m <= 5.4e-197) || (!(y_m <= 2.65e-171) && ((y_m <= 3.6e-140) || (!(y_m <= 1.5e-130) && (y_m <= 2.95e-111))))) {
tmp = (1.0 - (y_m / x)) * (1.0 + (y_m / x));
} else {
tmp = (x - y_m) / y_m;
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m): tmp = 0 if (y_m <= 5.4e-197) or (not (y_m <= 2.65e-171) and ((y_m <= 3.6e-140) or (not (y_m <= 1.5e-130) and (y_m <= 2.95e-111)))): tmp = (1.0 - (y_m / x)) * (1.0 + (y_m / x)) else: tmp = (x - y_m) / y_m return tmp
y_m = abs(y) function code(x, y_m) tmp = 0.0 if ((y_m <= 5.4e-197) || (!(y_m <= 2.65e-171) && ((y_m <= 3.6e-140) || (!(y_m <= 1.5e-130) && (y_m <= 2.95e-111))))) tmp = Float64(Float64(1.0 - Float64(y_m / x)) * Float64(1.0 + Float64(y_m / x))); else tmp = Float64(Float64(x - y_m) / y_m); end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m) tmp = 0.0; if ((y_m <= 5.4e-197) || (~((y_m <= 2.65e-171)) && ((y_m <= 3.6e-140) || (~((y_m <= 1.5e-130)) && (y_m <= 2.95e-111))))) tmp = (1.0 - (y_m / x)) * (1.0 + (y_m / x)); else tmp = (x - y_m) / y_m; end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_] := If[Or[LessEqual[y$95$m, 5.4e-197], And[N[Not[LessEqual[y$95$m, 2.65e-171]], $MachinePrecision], Or[LessEqual[y$95$m, 3.6e-140], And[N[Not[LessEqual[y$95$m, 1.5e-130]], $MachinePrecision], LessEqual[y$95$m, 2.95e-111]]]]], N[(N[(1.0 - N[(y$95$m / x), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(y$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - y$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y_m \leq 5.4 \cdot 10^{-197} \lor \neg \left(y_m \leq 2.65 \cdot 10^{-171}\right) \land \left(y_m \leq 3.6 \cdot 10^{-140} \lor \neg \left(y_m \leq 1.5 \cdot 10^{-130}\right) \land y_m \leq 2.95 \cdot 10^{-111}\right):\\
\;\;\;\;\left(1 - \frac{y_m}{x}\right) \cdot \left(1 + \frac{y_m}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y_m}{y_m}\\
\end{array}
\end{array}
if y < 5.40000000000000034e-197 or 2.65000000000000009e-171 < y < 3.6e-140 or 1.49999999999999993e-130 < y < 2.95e-111Initial program 58.3%
add-sqr-sqrt58.3%
times-frac59.1%
hypot-def59.1%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 41.2%
Taylor expanded in x around inf 40.7%
mul-1-neg40.7%
unsub-neg40.7%
Simplified40.7%
if 5.40000000000000034e-197 < y < 2.65000000000000009e-171 or 3.6e-140 < y < 1.49999999999999993e-130 or 2.95e-111 < y Initial program 82.4%
associate-/l*82.8%
remove-double-neg82.8%
sub-neg82.8%
+-commutative82.8%
fma-def82.8%
sub-neg82.8%
remove-double-neg82.8%
Simplified82.8%
Taylor expanded in y around inf 81.6%
Final simplification46.2%
y_m = (fabs.f64 y) (FPCore (x y_m) :precision binary64 (let* ((t_0 (/ (* (- x y_m) (+ x y_m)) (+ (* x x) (* y_m y_m))))) (if (<= t_0 2.0) t_0 (+ (* 2.0 (/ (/ x y_m) (/ y_m x))) -1.0))))
y_m = fabs(y);
double code(double x, double y_m) {
double t_0 = ((x - y_m) * (x + y_m)) / ((x * x) + (y_m * y_m));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = (2.0 * ((x / y_m) / (y_m / x))) + -1.0;
}
return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8) :: t_0
real(8) :: tmp
t_0 = ((x - y_m) * (x + y_m)) / ((x * x) + (y_m * y_m))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = (2.0d0 * ((x / y_m) / (y_m / x))) + (-1.0d0)
end if
code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m) {
double t_0 = ((x - y_m) * (x + y_m)) / ((x * x) + (y_m * y_m));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = (2.0 * ((x / y_m) / (y_m / x))) + -1.0;
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m): t_0 = ((x - y_m) * (x + y_m)) / ((x * x) + (y_m * y_m)) tmp = 0 if t_0 <= 2.0: tmp = t_0 else: tmp = (2.0 * ((x / y_m) / (y_m / x))) + -1.0 return tmp
y_m = abs(y) function code(x, y_m) t_0 = Float64(Float64(Float64(x - y_m) * Float64(x + y_m)) / Float64(Float64(x * x) + Float64(y_m * y_m))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(Float64(2.0 * Float64(Float64(x / y_m) / Float64(y_m / x))) + -1.0); end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m) t_0 = ((x - y_m) * (x + y_m)) / ((x * x) + (y_m * y_m)); tmp = 0.0; if (t_0 <= 2.0) tmp = t_0; else tmp = (2.0 * ((x / y_m) / (y_m / x))) + -1.0; end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_] := Block[{t$95$0 = N[(N[(N[(x - y$95$m), $MachinePrecision] * N[(x + y$95$m), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(N[(2.0 * N[(N[(x / y$95$m), $MachinePrecision] / N[(y$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
t_0 := \frac{\left(x - y_m\right) \cdot \left(x + y_m\right)}{x \cdot x + y_m \cdot y_m}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \frac{\frac{x}{y_m}}{\frac{y_m}{x}} + -1\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2Initial program 99.6%
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-def100.0%
Applied egg-rr100.0%
frac-2neg100.0%
associate-*r/100.0%
Applied egg-rr100.0%
Taylor expanded in y around -inf 55.1%
sub-neg55.1%
Simplified79.6%
unpow279.6%
clear-num79.6%
un-div-inv79.6%
Applied egg-rr79.6%
Final simplification91.9%
y_m = (fabs.f64 y)
(FPCore (x y_m)
:precision binary64
(if (<= y_m 3.5e-197)
1.0
(if (or (<= y_m 4e-171)
(not
(or (<= y_m 5e-140)
(and (not (<= y_m 1.45e-130)) (<= y_m 1.32e-111)))))
(/ (- x y_m) y_m)
1.0)))y_m = fabs(y);
double code(double x, double y_m) {
double tmp;
if (y_m <= 3.5e-197) {
tmp = 1.0;
} else if ((y_m <= 4e-171) || !((y_m <= 5e-140) || (!(y_m <= 1.45e-130) && (y_m <= 1.32e-111)))) {
tmp = (x - y_m) / y_m;
} else {
tmp = 1.0;
}
return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8) :: tmp
if (y_m <= 3.5d-197) then
tmp = 1.0d0
else if ((y_m <= 4d-171) .or. (.not. (y_m <= 5d-140) .or. (.not. (y_m <= 1.45d-130)) .and. (y_m <= 1.32d-111))) then
tmp = (x - y_m) / y_m
else
tmp = 1.0d0
end if
code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m) {
double tmp;
if (y_m <= 3.5e-197) {
tmp = 1.0;
} else if ((y_m <= 4e-171) || !((y_m <= 5e-140) || (!(y_m <= 1.45e-130) && (y_m <= 1.32e-111)))) {
tmp = (x - y_m) / y_m;
} else {
tmp = 1.0;
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m): tmp = 0 if y_m <= 3.5e-197: tmp = 1.0 elif (y_m <= 4e-171) or not ((y_m <= 5e-140) or (not (y_m <= 1.45e-130) and (y_m <= 1.32e-111))): tmp = (x - y_m) / y_m else: tmp = 1.0 return tmp
y_m = abs(y) function code(x, y_m) tmp = 0.0 if (y_m <= 3.5e-197) tmp = 1.0; elseif ((y_m <= 4e-171) || !((y_m <= 5e-140) || (!(y_m <= 1.45e-130) && (y_m <= 1.32e-111)))) tmp = Float64(Float64(x - y_m) / y_m); else tmp = 1.0; end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m) tmp = 0.0; if (y_m <= 3.5e-197) tmp = 1.0; elseif ((y_m <= 4e-171) || ~(((y_m <= 5e-140) || (~((y_m <= 1.45e-130)) && (y_m <= 1.32e-111))))) tmp = (x - y_m) / y_m; else tmp = 1.0; end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_] := If[LessEqual[y$95$m, 3.5e-197], 1.0, If[Or[LessEqual[y$95$m, 4e-171], N[Not[Or[LessEqual[y$95$m, 5e-140], And[N[Not[LessEqual[y$95$m, 1.45e-130]], $MachinePrecision], LessEqual[y$95$m, 1.32e-111]]]], $MachinePrecision]], N[(N[(x - y$95$m), $MachinePrecision] / y$95$m), $MachinePrecision], 1.0]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y_m \leq 3.5 \cdot 10^{-197}:\\
\;\;\;\;1\\
\mathbf{elif}\;y_m \leq 4 \cdot 10^{-171} \lor \neg \left(y_m \leq 5 \cdot 10^{-140} \lor \neg \left(y_m \leq 1.45 \cdot 10^{-130}\right) \land y_m \leq 1.32 \cdot 10^{-111}\right):\\
\;\;\;\;\frac{x - y_m}{y_m}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < 3.4999999999999998e-197 or 3.9999999999999999e-171 < y < 5.00000000000000015e-140 or 1.45e-130 < y < 1.32e-111Initial program 58.3%
Taylor expanded in x around inf 39.3%
if 3.4999999999999998e-197 < y < 3.9999999999999999e-171 or 5.00000000000000015e-140 < y < 1.45e-130 or 1.32e-111 < y Initial program 82.4%
associate-/l*82.8%
remove-double-neg82.8%
sub-neg82.8%
+-commutative82.8%
fma-def82.8%
sub-neg82.8%
remove-double-neg82.8%
Simplified82.8%
Taylor expanded in y around inf 81.6%
Final simplification44.9%
y_m = (fabs.f64 y)
(FPCore (x y_m)
:precision binary64
(if (<= y_m 1.5e-187)
1.0
(if (<= y_m 3.5e-171)
-1.0
(if (<= y_m 6.8e-137)
1.0
(if (<= y_m 1.5e-130) -1.0 (if (<= y_m 1.55e-111) 1.0 -1.0))))))y_m = fabs(y);
double code(double x, double y_m) {
double tmp;
if (y_m <= 1.5e-187) {
tmp = 1.0;
} else if (y_m <= 3.5e-171) {
tmp = -1.0;
} else if (y_m <= 6.8e-137) {
tmp = 1.0;
} else if (y_m <= 1.5e-130) {
tmp = -1.0;
} else if (y_m <= 1.55e-111) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8) :: tmp
if (y_m <= 1.5d-187) then
tmp = 1.0d0
else if (y_m <= 3.5d-171) then
tmp = -1.0d0
else if (y_m <= 6.8d-137) then
tmp = 1.0d0
else if (y_m <= 1.5d-130) then
tmp = -1.0d0
else if (y_m <= 1.55d-111) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m) {
double tmp;
if (y_m <= 1.5e-187) {
tmp = 1.0;
} else if (y_m <= 3.5e-171) {
tmp = -1.0;
} else if (y_m <= 6.8e-137) {
tmp = 1.0;
} else if (y_m <= 1.5e-130) {
tmp = -1.0;
} else if (y_m <= 1.55e-111) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
y_m = math.fabs(y) def code(x, y_m): tmp = 0 if y_m <= 1.5e-187: tmp = 1.0 elif y_m <= 3.5e-171: tmp = -1.0 elif y_m <= 6.8e-137: tmp = 1.0 elif y_m <= 1.5e-130: tmp = -1.0 elif y_m <= 1.55e-111: tmp = 1.0 else: tmp = -1.0 return tmp
y_m = abs(y) function code(x, y_m) tmp = 0.0 if (y_m <= 1.5e-187) tmp = 1.0; elseif (y_m <= 3.5e-171) tmp = -1.0; elseif (y_m <= 6.8e-137) tmp = 1.0; elseif (y_m <= 1.5e-130) tmp = -1.0; elseif (y_m <= 1.55e-111) tmp = 1.0; else tmp = -1.0; end return tmp end
y_m = abs(y); function tmp_2 = code(x, y_m) tmp = 0.0; if (y_m <= 1.5e-187) tmp = 1.0; elseif (y_m <= 3.5e-171) tmp = -1.0; elseif (y_m <= 6.8e-137) tmp = 1.0; elseif (y_m <= 1.5e-130) tmp = -1.0; elseif (y_m <= 1.55e-111) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_] := If[LessEqual[y$95$m, 1.5e-187], 1.0, If[LessEqual[y$95$m, 3.5e-171], -1.0, If[LessEqual[y$95$m, 6.8e-137], 1.0, If[LessEqual[y$95$m, 1.5e-130], -1.0, If[LessEqual[y$95$m, 1.55e-111], 1.0, -1.0]]]]]
\begin{array}{l}
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;y_m \leq 1.5 \cdot 10^{-187}:\\
\;\;\;\;1\\
\mathbf{elif}\;y_m \leq 3.5 \cdot 10^{-171}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y_m \leq 6.8 \cdot 10^{-137}:\\
\;\;\;\;1\\
\mathbf{elif}\;y_m \leq 1.5 \cdot 10^{-130}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y_m \leq 1.55 \cdot 10^{-111}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.50000000000000002e-187 or 3.49999999999999994e-171 < y < 6.80000000000000028e-137 or 1.49999999999999993e-130 < y < 1.55000000000000007e-111Initial program 58.4%
Taylor expanded in x around inf 39.1%
if 1.50000000000000002e-187 < y < 3.49999999999999994e-171 or 6.80000000000000028e-137 < y < 1.49999999999999993e-130 or 1.55000000000000007e-111 < y Initial program 81.8%
Taylor expanded in x around 0 79.6%
Final simplification44.4%
y_m = (fabs.f64 y) (FPCore (x y_m) :precision binary64 -1.0)
y_m = fabs(y);
double code(double x, double y_m) {
return -1.0;
}
y_m = abs(y)
real(8) function code(x, y_m)
real(8), intent (in) :: x
real(8), intent (in) :: y_m
code = -1.0d0
end function
y_m = Math.abs(y);
public static double code(double x, double y_m) {
return -1.0;
}
y_m = math.fabs(y) def code(x, y_m): return -1.0
y_m = abs(y) function code(x, y_m) return -1.0 end
y_m = abs(y); function tmp = code(x, y_m) tmp = -1.0; end
y_m = N[Abs[y], $MachinePrecision] code[x_, y$95$m_] := -1.0
\begin{array}{l}
y_m = \left|y\right|
\\
-1
\end{array}
Initial program 61.5%
Taylor expanded in x around 0 63.8%
Final simplification63.8%
(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 2024020
(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))))