
(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 12 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) / 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 69.9%
add-sqr-sqrt69.9%
times-frac70.2%
hypot-define70.3%
hypot-define100.0%
Applied egg-rr100.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 (pow (/ x y) 2.0) -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, pow((x / y), 2.0), -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(x / y) ^ 2.0), -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[Power[N[(x / y), $MachinePrecision], 2.0], $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, {\left(\frac{x}{y}\right)}^{2}, -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%
sub-neg0.0%
distribute-lft-in0.0%
Applied egg-rr0.0%
Taylor expanded in x around 0 55.8%
fma-neg55.8%
unpow255.8%
unpow255.8%
times-frac79.7%
unpow279.7%
metadata-eval79.7%
Simplified79.7%
(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) (hypot 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) / hypot(x, y)) * ((x / y) + 1.0);
}
return tmp;
}
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) / Math.hypot(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) / math.hypot(x, y)) * ((x / y) + 1.0) return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(Float64(Float64(x - y) / hypot(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) / hypot(x, y)) * ((x / y) + 1.0); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + 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}\\
\mathbf{if}\;t\_0 \leq 2:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(\frac{x}{y} + 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-define3.1%
hypot-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 14.0%
Final simplification74.1%
(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) -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) + -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) + (-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) + -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) + -1.0) return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(Float64(Float64(x / y) + 1.0) * 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) + -1.0); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -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}\\
\mathbf{if}\;t\_0 \leq 2:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{x}{y} + 1\right) \cdot \left(\frac{x}{y} + -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-define3.1%
hypot-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 14.0%
Taylor expanded in x around 0 79.2%
Final simplification93.7%
(FPCore (x y)
:precision binary64
(if (<= y 1.65e-154)
(- 1.0 (/ y x))
(if (or (<= y 1.16e-132) (not (<= y 7.5e-124)))
(* (- x y) (/ (+ (/ x y) 1.0) y))
(- (/ x x) (/ y x)))))
double code(double x, double y) {
double tmp;
if (y <= 1.65e-154) {
tmp = 1.0 - (y / x);
} else if ((y <= 1.16e-132) || !(y <= 7.5e-124)) {
tmp = (x - y) * (((x / y) + 1.0) / y);
} else {
tmp = (x / 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 <= 1.65d-154) then
tmp = 1.0d0 - (y / x)
else if ((y <= 1.16d-132) .or. (.not. (y <= 7.5d-124))) then
tmp = (x - y) * (((x / y) + 1.0d0) / y)
else
tmp = (x / x) - (y / x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.65e-154) {
tmp = 1.0 - (y / x);
} else if ((y <= 1.16e-132) || !(y <= 7.5e-124)) {
tmp = (x - y) * (((x / y) + 1.0) / y);
} else {
tmp = (x / x) - (y / x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.65e-154: tmp = 1.0 - (y / x) elif (y <= 1.16e-132) or not (y <= 7.5e-124): tmp = (x - y) * (((x / y) + 1.0) / y) else: tmp = (x / x) - (y / x) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.65e-154) tmp = Float64(1.0 - Float64(y / x)); elseif ((y <= 1.16e-132) || !(y <= 7.5e-124)) tmp = Float64(Float64(x - y) * Float64(Float64(Float64(x / y) + 1.0) / y)); else tmp = Float64(Float64(x / x) - Float64(y / x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.65e-154) tmp = 1.0 - (y / x); elseif ((y <= 1.16e-132) || ~((y <= 7.5e-124))) tmp = (x - y) * (((x / y) + 1.0) / y); else tmp = (x / x) - (y / x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.65e-154], N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.16e-132], N[Not[LessEqual[y, 7.5e-124]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(N[(x / x), $MachinePrecision] - N[(y / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.65 \cdot 10^{-154}:\\
\;\;\;\;1 - \frac{y}{x}\\
\mathbf{elif}\;y \leq 1.16 \cdot 10^{-132} \lor \neg \left(y \leq 7.5 \cdot 10^{-124}\right):\\
\;\;\;\;\left(x - y\right) \cdot \frac{\frac{x}{y} + 1}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x} - \frac{y}{x}\\
\end{array}
\end{array}
if y < 1.65000000000000014e-154Initial program 63.6%
associate-/l*63.8%
+-commutative63.8%
fma-define63.8%
Simplified63.8%
Taylor expanded in x around inf 32.4%
un-div-inv32.4%
Applied egg-rr32.4%
Taylor expanded in x around inf 32.4%
neg-mul-132.4%
sub-neg32.4%
Simplified32.4%
if 1.65000000000000014e-154 < y < 1.1599999999999999e-132 or 7.4999999999999996e-124 < y Initial program 100.0%
associate-/l*99.7%
+-commutative99.7%
fma-define99.6%
Simplified99.6%
Taylor expanded in y around inf 79.6%
if 1.1599999999999999e-132 < y < 7.4999999999999996e-124Initial program 100.0%
associate-/l*99.5%
+-commutative99.5%
fma-define99.5%
Simplified99.5%
Taylor expanded in x around inf 99.5%
un-div-inv100.0%
div-sub100.0%
Applied egg-rr100.0%
Final simplification41.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ (/ x y) 1.0)))
(if (<= y 9e-155)
(- 1.0 (/ y x))
(if (<= y 5.8e-132)
(* (- x y) (/ t_0 y))
(if (<= y 6.9e-124) (- (/ x x) (/ y x)) (* t_0 (+ (/ x y) -1.0)))))))
double code(double x, double y) {
double t_0 = (x / y) + 1.0;
double tmp;
if (y <= 9e-155) {
tmp = 1.0 - (y / x);
} else if (y <= 5.8e-132) {
tmp = (x - y) * (t_0 / y);
} else if (y <= 6.9e-124) {
tmp = (x / x) - (y / x);
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (x / y) + 1.0d0
if (y <= 9d-155) then
tmp = 1.0d0 - (y / x)
else if (y <= 5.8d-132) then
tmp = (x - y) * (t_0 / y)
else if (y <= 6.9d-124) then
tmp = (x / x) - (y / x)
else
tmp = t_0 * ((x / y) + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x / y) + 1.0;
double tmp;
if (y <= 9e-155) {
tmp = 1.0 - (y / x);
} else if (y <= 5.8e-132) {
tmp = (x - y) * (t_0 / y);
} else if (y <= 6.9e-124) {
tmp = (x / x) - (y / x);
} else {
tmp = t_0 * ((x / y) + -1.0);
}
return tmp;
}
def code(x, y): t_0 = (x / y) + 1.0 tmp = 0 if y <= 9e-155: tmp = 1.0 - (y / x) elif y <= 5.8e-132: tmp = (x - y) * (t_0 / y) elif y <= 6.9e-124: tmp = (x / x) - (y / x) else: tmp = t_0 * ((x / y) + -1.0) return tmp
function code(x, y) t_0 = Float64(Float64(x / y) + 1.0) tmp = 0.0 if (y <= 9e-155) tmp = Float64(1.0 - Float64(y / x)); elseif (y <= 5.8e-132) tmp = Float64(Float64(x - y) * Float64(t_0 / y)); elseif (y <= 6.9e-124) tmp = Float64(Float64(x / x) - Float64(y / x)); else tmp = Float64(t_0 * Float64(Float64(x / y) + -1.0)); end return tmp end
function tmp_2 = code(x, y) t_0 = (x / y) + 1.0; tmp = 0.0; if (y <= 9e-155) tmp = 1.0 - (y / x); elseif (y <= 5.8e-132) tmp = (x - y) * (t_0 / y); elseif (y <= 6.9e-124) tmp = (x / x) - (y / x); else tmp = t_0 * ((x / y) + -1.0); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[y, 9e-155], N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.8e-132], N[(N[(x - y), $MachinePrecision] * N[(t$95$0 / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.9e-124], N[(N[(x / x), $MachinePrecision] - N[(y / x), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y} + 1\\
\mathbf{if}\;y \leq 9 \cdot 10^{-155}:\\
\;\;\;\;1 - \frac{y}{x}\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{-132}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{t\_0}{y}\\
\mathbf{elif}\;y \leq 6.9 \cdot 10^{-124}:\\
\;\;\;\;\frac{x}{x} - \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(\frac{x}{y} + -1\right)\\
\end{array}
\end{array}
if y < 9.0000000000000007e-155Initial program 63.6%
associate-/l*63.8%
+-commutative63.8%
fma-define63.8%
Simplified63.8%
Taylor expanded in x around inf 32.4%
un-div-inv32.4%
Applied egg-rr32.4%
Taylor expanded in x around inf 32.4%
neg-mul-132.4%
sub-neg32.4%
Simplified32.4%
if 9.0000000000000007e-155 < y < 5.79999999999999967e-132Initial program 100.0%
associate-/l*100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around inf 62.7%
if 5.79999999999999967e-132 < y < 6.9e-124Initial program 100.0%
associate-/l*99.5%
+-commutative99.5%
fma-define99.5%
Simplified99.5%
Taylor expanded in x around inf 99.5%
un-div-inv100.0%
div-sub100.0%
Applied egg-rr100.0%
if 6.9e-124 < y Initial program 100.0%
add-sqr-sqrt99.9%
times-frac99.8%
hypot-define99.8%
hypot-define99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 82.6%
Taylor expanded in x around 0 82.2%
Final simplification41.0%
(FPCore (x y) :precision binary64 (if (<= y 1.14e-154) (- 1.0 (/ y x)) (if (<= y 7.4e-133) -1.0 (if (<= y 6.9e-124) (- (/ x x) (/ y x)) -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 1.14e-154) {
tmp = 1.0 - (y / x);
} else if (y <= 7.4e-133) {
tmp = -1.0;
} else if (y <= 6.9e-124) {
tmp = (x / x) - (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 <= 1.14d-154) then
tmp = 1.0d0 - (y / x)
else if (y <= 7.4d-133) then
tmp = -1.0d0
else if (y <= 6.9d-124) then
tmp = (x / x) - (y / x)
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.14e-154) {
tmp = 1.0 - (y / x);
} else if (y <= 7.4e-133) {
tmp = -1.0;
} else if (y <= 6.9e-124) {
tmp = (x / x) - (y / x);
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.14e-154: tmp = 1.0 - (y / x) elif y <= 7.4e-133: tmp = -1.0 elif y <= 6.9e-124: tmp = (x / x) - (y / x) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.14e-154) tmp = Float64(1.0 - Float64(y / x)); elseif (y <= 7.4e-133) tmp = -1.0; elseif (y <= 6.9e-124) tmp = Float64(Float64(x / x) - Float64(y / x)); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.14e-154) tmp = 1.0 - (y / x); elseif (y <= 7.4e-133) tmp = -1.0; elseif (y <= 6.9e-124) tmp = (x / x) - (y / x); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.14e-154], N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.4e-133], -1.0, If[LessEqual[y, 6.9e-124], N[(N[(x / x), $MachinePrecision] - N[(y / x), $MachinePrecision]), $MachinePrecision], -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.14 \cdot 10^{-154}:\\
\;\;\;\;1 - \frac{y}{x}\\
\mathbf{elif}\;y \leq 7.4 \cdot 10^{-133}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 6.9 \cdot 10^{-124}:\\
\;\;\;\;\frac{x}{x} - \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.13999999999999993e-154Initial program 63.6%
associate-/l*63.8%
+-commutative63.8%
fma-define63.8%
Simplified63.8%
Taylor expanded in x around inf 32.4%
un-div-inv32.4%
Applied egg-rr32.4%
Taylor expanded in x around inf 32.4%
neg-mul-132.4%
sub-neg32.4%
Simplified32.4%
if 1.13999999999999993e-154 < y < 7.40000000000000071e-133 or 6.9e-124 < y Initial program 100.0%
associate-/l*99.7%
+-commutative99.7%
fma-define99.6%
Simplified99.6%
Taylor expanded in x around 0 78.8%
if 7.40000000000000071e-133 < y < 6.9e-124Initial program 100.0%
associate-/l*99.5%
+-commutative99.5%
fma-define99.5%
Simplified99.5%
Taylor expanded in x around inf 99.5%
un-div-inv100.0%
div-sub100.0%
Applied egg-rr100.0%
(FPCore (x y) :precision binary64 (if (or (<= y 1.65e-154) (and (not (<= y 2.25e-132)) (<= y 7.3e-124))) (- 1.0 (/ y x)) -1.0))
double code(double x, double y) {
double tmp;
if ((y <= 1.65e-154) || (!(y <= 2.25e-132) && (y <= 7.3e-124))) {
tmp = 1.0 - (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 <= 1.65d-154) .or. (.not. (y <= 2.25d-132)) .and. (y <= 7.3d-124)) then
tmp = 1.0d0 - (y / x)
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 1.65e-154) || (!(y <= 2.25e-132) && (y <= 7.3e-124))) {
tmp = 1.0 - (y / x);
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 1.65e-154) or (not (y <= 2.25e-132) and (y <= 7.3e-124)): tmp = 1.0 - (y / x) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= 1.65e-154) || (!(y <= 2.25e-132) && (y <= 7.3e-124))) tmp = Float64(1.0 - Float64(y / x)); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 1.65e-154) || (~((y <= 2.25e-132)) && (y <= 7.3e-124))) tmp = 1.0 - (y / x); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 1.65e-154], And[N[Not[LessEqual[y, 2.25e-132]], $MachinePrecision], LessEqual[y, 7.3e-124]]], N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.65 \cdot 10^{-154} \lor \neg \left(y \leq 2.25 \cdot 10^{-132}\right) \land y \leq 7.3 \cdot 10^{-124}:\\
\;\;\;\;1 - \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.65000000000000014e-154Initial program 63.6%
associate-/l*63.8%
+-commutative63.8%
fma-define63.8%
Simplified63.8%
Taylor expanded in x around inf 32.4%
un-div-inv32.4%
Applied egg-rr32.4%
Taylor expanded in x around inf 32.4%
neg-mul-132.4%
sub-neg32.4%
Simplified32.4%
if 1.65000000000000014e-154 < y < 2.25e-132 or 7.3e-124 < y Initial program 100.0%
associate-/l*99.7%
+-commutative99.7%
fma-define99.6%
Simplified99.6%
Taylor expanded in x around 0 78.8%
if 2.25e-132 < y < 7.3e-124Initial program 100.0%
associate-/l*99.5%
+-commutative99.5%
fma-define99.5%
Simplified99.5%
Taylor expanded in x around inf 99.5%
un-div-inv100.0%
div-sub100.0%
Applied egg-rr100.0%
sub-neg100.0%
*-inverses100.0%
+-commutative100.0%
distribute-neg-frac100.0%
Applied egg-rr100.0%
Final simplification40.9%
(FPCore (x y) :precision binary64 (if (or (<= y 1.55e-154) (and (not (<= y 6.7e-133)) (<= y 6.9e-124))) (- 1.0 (/ y x)) -1.0))
double code(double x, double y) {
double tmp;
if ((y <= 1.55e-154) || (!(y <= 6.7e-133) && (y <= 6.9e-124))) {
tmp = 1.0 - (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 <= 1.55d-154) .or. (.not. (y <= 6.7d-133)) .and. (y <= 6.9d-124)) then
tmp = 1.0d0 - (y / x)
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 1.55e-154) || (!(y <= 6.7e-133) && (y <= 6.9e-124))) {
tmp = 1.0 - (y / x);
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 1.55e-154) or (not (y <= 6.7e-133) and (y <= 6.9e-124)): tmp = 1.0 - (y / x) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= 1.55e-154) || (!(y <= 6.7e-133) && (y <= 6.9e-124))) tmp = Float64(1.0 - Float64(y / x)); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 1.55e-154) || (~((y <= 6.7e-133)) && (y <= 6.9e-124))) tmp = 1.0 - (y / x); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 1.55e-154], And[N[Not[LessEqual[y, 6.7e-133]], $MachinePrecision], LessEqual[y, 6.9e-124]]], N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.55 \cdot 10^{-154} \lor \neg \left(y \leq 6.7 \cdot 10^{-133}\right) \land y \leq 6.9 \cdot 10^{-124}:\\
\;\;\;\;1 - \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.54999999999999991e-154 or 6.7000000000000002e-133 < y < 6.9e-124Initial program 64.7%
associate-/l*64.8%
+-commutative64.8%
fma-define64.8%
Simplified64.8%
Taylor expanded in x around inf 34.2%
un-div-inv34.3%
Applied egg-rr34.3%
Taylor expanded in x around inf 34.3%
neg-mul-134.3%
sub-neg34.3%
Simplified34.3%
if 1.54999999999999991e-154 < y < 6.7000000000000002e-133 or 6.9e-124 < y Initial program 100.0%
associate-/l*99.7%
+-commutative99.7%
fma-define99.6%
Simplified99.6%
Taylor expanded in x around 0 78.8%
Final simplification40.9%
(FPCore (x y) :precision binary64 (if (<= y 1.14e-154) (- 1.0 (/ y x)) (if (<= y 1.6e-132) -1.0 (if (<= y 6.9e-124) (/ (- x y) x) -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 1.14e-154) {
tmp = 1.0 - (y / x);
} else if (y <= 1.6e-132) {
tmp = -1.0;
} else if (y <= 6.9e-124) {
tmp = (x - 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 <= 1.14d-154) then
tmp = 1.0d0 - (y / x)
else if (y <= 1.6d-132) then
tmp = -1.0d0
else if (y <= 6.9d-124) then
tmp = (x - y) / x
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.14e-154) {
tmp = 1.0 - (y / x);
} else if (y <= 1.6e-132) {
tmp = -1.0;
} else if (y <= 6.9e-124) {
tmp = (x - y) / x;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.14e-154: tmp = 1.0 - (y / x) elif y <= 1.6e-132: tmp = -1.0 elif y <= 6.9e-124: tmp = (x - y) / x else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.14e-154) tmp = Float64(1.0 - Float64(y / x)); elseif (y <= 1.6e-132) tmp = -1.0; elseif (y <= 6.9e-124) tmp = Float64(Float64(x - y) / x); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.14e-154) tmp = 1.0 - (y / x); elseif (y <= 1.6e-132) tmp = -1.0; elseif (y <= 6.9e-124) tmp = (x - y) / x; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.14e-154], N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.6e-132], -1.0, If[LessEqual[y, 6.9e-124], N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision], -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.14 \cdot 10^{-154}:\\
\;\;\;\;1 - \frac{y}{x}\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{-132}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 6.9 \cdot 10^{-124}:\\
\;\;\;\;\frac{x - y}{x}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.13999999999999993e-154Initial program 63.6%
associate-/l*63.8%
+-commutative63.8%
fma-define63.8%
Simplified63.8%
Taylor expanded in x around inf 32.4%
un-div-inv32.4%
Applied egg-rr32.4%
Taylor expanded in x around inf 32.4%
neg-mul-132.4%
sub-neg32.4%
Simplified32.4%
if 1.13999999999999993e-154 < y < 1.6000000000000001e-132 or 6.9e-124 < y Initial program 100.0%
associate-/l*99.7%
+-commutative99.7%
fma-define99.6%
Simplified99.6%
Taylor expanded in x around 0 78.8%
if 1.6000000000000001e-132 < y < 6.9e-124Initial program 100.0%
associate-/l*99.5%
+-commutative99.5%
fma-define99.5%
Simplified99.5%
Taylor expanded in x around inf 99.5%
un-div-inv100.0%
Applied egg-rr100.0%
(FPCore (x y) :precision binary64 (if (<= y 3.2e-163) 1.0 -1.0))
double code(double x, double y) {
double tmp;
if (y <= 3.2e-163) {
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 <= 3.2d-163) 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 <= 3.2e-163) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.2e-163: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 3.2e-163) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.2e-163) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.2e-163], 1.0, -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.2 \cdot 10^{-163}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 3.19999999999999988e-163Initial program 63.1%
associate-/l*63.7%
+-commutative63.7%
fma-define63.7%
Simplified63.7%
Taylor expanded in x around inf 32.7%
if 3.19999999999999988e-163 < y Initial program 100.0%
associate-/l*97.9%
+-commutative97.9%
fma-define97.8%
Simplified97.8%
Taylor expanded in x around 0 68.2%
(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 69.9%
associate-/l*70.0%
+-commutative70.0%
fma-define70.0%
Simplified70.0%
Taylor expanded in x around 0 67.3%
(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 2024103
(FPCore (x y)
:name "Kahan p9 Example"
:precision binary64
:pre (and (and (< 0.0 x) (< x 1.0)) (< y 1.0))
:alt
(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))))