
(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) (/ (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 66.0%
associate-/l*66.9%
fma-def66.9%
Simplified66.9%
fma-def66.9%
div-inv66.7%
add-sqr-sqrt66.7%
associate-*l*66.8%
hypot-def66.8%
hypot-def99.7%
Applied egg-rr99.7%
expm1-log1p-u97.9%
expm1-udef97.9%
un-div-inv98.0%
Applied egg-rr98.0%
expm1-def98.0%
expm1-log1p99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) 2.0) (/ (- (* x x) (* y y)) (pow (hypot x y) 2.0)) (fma 2.0 (pow (/ x y) 2.0) -1.0)))
double code(double x, double y) {
double tmp;
if ((((x - y) * (x + y)) / ((x * x) + (y * y))) <= 2.0) {
tmp = ((x * x) - (y * y)) / pow(hypot(x, y), 2.0);
} else {
tmp = fma(2.0, pow((x / y), 2.0), -1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) <= 2.0) tmp = Float64(Float64(Float64(x * x) - Float64(y * y)) / (hypot(x, y) ^ 2.0)); else tmp = fma(2.0, (Float64(x / y) ^ 2.0), -1.0); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], N[(N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision] / N[Power[N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \leq 2:\\
\;\;\;\;\frac{x \cdot x - y \cdot y}{{\left(\mathsf{hypot}\left(x, y\right)\right)}^{2}}\\
\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%
associate-*r/99.4%
+-commutative99.4%
fma-def99.4%
Simplified99.4%
associate-*r/100.0%
fma-udef100.0%
+-commutative100.0%
*-commutative100.0%
difference-of-squares100.0%
add-sqr-sqrt100.0%
pow2100.0%
hypot-def100.0%
Applied egg-rr100.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 x around 0 56.3%
fma-neg56.3%
unpow256.3%
unpow256.3%
times-frac83.3%
unpow283.3%
metadata-eval83.3%
Simplified83.3%
Final simplification94.3%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))) (if (<= t_0 2.0) t_0 (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%
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 x around 0 56.3%
fma-neg56.3%
unpow256.3%
unpow256.3%
times-frac83.3%
unpow283.3%
metadata-eval83.3%
Simplified83.3%
Final simplification94.3%
(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 66.0%
add-sqr-sqrt66.0%
times-frac67.0%
hypot-def67.0%
hypot-def99.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(Float64(x + y) * 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[(N[(x + y), $MachinePrecision] * N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) \cdot \frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Initial program 66.0%
add-sqr-sqrt66.0%
times-frac67.0%
hypot-def67.0%
hypot-def99.9%
Applied egg-rr99.9%
associate-*r/99.9%
+-commutative99.9%
Simplified99.9%
Final simplification99.9%
(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 y) (/ (/ x y) 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) * ((1.0 / y) + ((x / y) / 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 = ((x - y) * (x + y)) / ((x * x) + (y * y))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = (x - y) * ((1.0d0 / y) + ((x / y) / y))
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 / y) + ((x / y) / y));
}
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 / y) + ((x / y) / y)) return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(Float64(x - y) * Float64(Float64(1.0 / y) + Float64(Float64(x / y) / y))); 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 / y) + ((x / y) / y)); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 / y), $MachinePrecision] + N[(N[(x / y), $MachinePrecision] / y), $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}:\\
\;\;\;\;\left(x - y\right) \cdot \left(\frac{1}{y} + \frac{\frac{x}{y}}{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%
associate-*r/3.1%
+-commutative3.1%
fma-def3.1%
Simplified3.1%
Taylor expanded in x around 0 57.3%
unpow257.3%
Simplified57.3%
*-un-lft-identity57.3%
times-frac82.4%
Applied egg-rr82.4%
associate-*l/82.4%
*-lft-identity82.4%
Simplified82.4%
Final simplification94.0%
(FPCore (x y)
:precision binary64
(if (<= y -1.32e-149)
(+ -1.0 (/ (* x x) (* y y)))
(if (<= y 3.6e-190)
(+ 1.0 (* -2.0 (* (/ y x) (/ y x))))
(* (- x y) (+ (/ 1.0 y) (/ (/ x y) y))))))
double code(double x, double y) {
double tmp;
if (y <= -1.32e-149) {
tmp = -1.0 + ((x * x) / (y * y));
} else if (y <= 3.6e-190) {
tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
} else {
tmp = (x - y) * ((1.0 / y) + ((x / y) / y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.32d-149)) then
tmp = (-1.0d0) + ((x * x) / (y * y))
else if (y <= 3.6d-190) then
tmp = 1.0d0 + ((-2.0d0) * ((y / x) * (y / x)))
else
tmp = (x - y) * ((1.0d0 / y) + ((x / y) / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.32e-149) {
tmp = -1.0 + ((x * x) / (y * y));
} else if (y <= 3.6e-190) {
tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
} else {
tmp = (x - y) * ((1.0 / y) + ((x / y) / y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.32e-149: tmp = -1.0 + ((x * x) / (y * y)) elif y <= 3.6e-190: tmp = 1.0 + (-2.0 * ((y / x) * (y / x))) else: tmp = (x - y) * ((1.0 / y) + ((x / y) / y)) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.32e-149) tmp = Float64(-1.0 + Float64(Float64(x * x) / Float64(y * y))); elseif (y <= 3.6e-190) tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / x) * Float64(y / x)))); else tmp = Float64(Float64(x - y) * Float64(Float64(1.0 / y) + Float64(Float64(x / y) / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.32e-149) tmp = -1.0 + ((x * x) / (y * y)); elseif (y <= 3.6e-190) tmp = 1.0 + (-2.0 * ((y / x) * (y / x))); else tmp = (x - y) * ((1.0 / y) + ((x / y) / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.32e-149], N[(-1.0 + N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.6e-190], N[(1.0 + N[(-2.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 / y), $MachinePrecision] + N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.32 \cdot 10^{-149}:\\
\;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-190}:\\
\;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - y\right) \cdot \left(\frac{1}{y} + \frac{\frac{x}{y}}{y}\right)\\
\end{array}
\end{array}
if y < -1.3200000000000001e-149Initial program 59.8%
associate-*r/60.8%
+-commutative60.8%
fma-def60.8%
Simplified60.8%
Taylor expanded in x around 0 93.5%
unpow293.5%
Simplified93.5%
Taylor expanded in x around 0 93.8%
sub-neg93.8%
unpow293.8%
unpow293.8%
metadata-eval93.8%
Simplified93.8%
if -1.3200000000000001e-149 < y < 3.60000000000000007e-190Initial program 58.4%
associate-*r/59.2%
+-commutative59.2%
fma-def59.2%
Simplified59.2%
Taylor expanded in y around 0 57.2%
unpow257.2%
unpow257.2%
Simplified57.2%
times-frac76.7%
Applied egg-rr76.7%
if 3.60000000000000007e-190 < y Initial program 89.4%
associate-*r/89.3%
+-commutative89.3%
fma-def89.4%
Simplified89.4%
Taylor expanded in x around 0 61.6%
unpow261.6%
Simplified61.6%
*-un-lft-identity61.6%
times-frac71.8%
Applied egg-rr71.8%
associate-*l/71.8%
*-lft-identity71.8%
Simplified71.8%
Final simplification83.8%
(FPCore (x y) :precision binary64 (if (or (<= y -7.8e-150) (not (<= y 5.3e-151))) (+ -1.0 (/ (* x x) (* y y))) (+ 1.0 (* -2.0 (* (/ y x) (/ y x))))))
double code(double x, double y) {
double tmp;
if ((y <= -7.8e-150) || !(y <= 5.3e-151)) {
tmp = -1.0 + ((x * x) / (y * y));
} 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 <= (-7.8d-150)) .or. (.not. (y <= 5.3d-151))) then
tmp = (-1.0d0) + ((x * x) / (y * y))
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 <= -7.8e-150) || !(y <= 5.3e-151)) {
tmp = -1.0 + ((x * x) / (y * y));
} else {
tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.8e-150) or not (y <= 5.3e-151): tmp = -1.0 + ((x * x) / (y * y)) else: tmp = 1.0 + (-2.0 * ((y / x) * (y / x))) return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.8e-150) || !(y <= 5.3e-151)) tmp = Float64(-1.0 + Float64(Float64(x * x) / Float64(y * y))); 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 <= -7.8e-150) || ~((y <= 5.3e-151))) tmp = -1.0 + ((x * x) / (y * y)); else tmp = 1.0 + (-2.0 * ((y / x) * (y / x))); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.8e-150], N[Not[LessEqual[y, 5.3e-151]], $MachinePrecision]], N[(-1.0 + N[(N[(x * x), $MachinePrecision] / N[(y * y), $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 -7.8 \cdot 10^{-150} \lor \neg \left(y \leq 5.3 \cdot 10^{-151}\right):\\
\;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\end{array}
\end{array}
if y < -7.8000000000000004e-150 or 5.29999999999999978e-151 < y Initial program 70.8%
associate-*r/71.4%
+-commutative71.4%
fma-def71.4%
Simplified71.4%
Taylor expanded in x around 0 88.6%
unpow288.6%
Simplified88.6%
Taylor expanded in x around 0 88.8%
sub-neg88.8%
unpow288.8%
unpow288.8%
metadata-eval88.8%
Simplified88.8%
if -7.8000000000000004e-150 < y < 5.29999999999999978e-151Initial program 56.8%
associate-*r/57.7%
+-commutative57.7%
fma-def57.7%
Simplified57.7%
Taylor expanded in y around 0 55.7%
unpow255.7%
unpow255.7%
Simplified55.7%
times-frac73.3%
Applied egg-rr73.3%
Final simplification83.5%
(FPCore (x y) :precision binary64 (if (or (<= y -2.85e-149) (not (<= y 4.6e-149))) (+ -1.0 (/ (* x x) (* y y))) (- 1.0 (* (/ y x) (/ y x)))))
double code(double x, double y) {
double tmp;
if ((y <= -2.85e-149) || !(y <= 4.6e-149)) {
tmp = -1.0 + ((x * x) / (y * y));
} else {
tmp = 1.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.85d-149)) .or. (.not. (y <= 4.6d-149))) then
tmp = (-1.0d0) + ((x * x) / (y * y))
else
tmp = 1.0d0 - ((y / x) * (y / x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.85e-149) || !(y <= 4.6e-149)) {
tmp = -1.0 + ((x * x) / (y * y));
} else {
tmp = 1.0 - ((y / x) * (y / x));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.85e-149) or not (y <= 4.6e-149): tmp = -1.0 + ((x * x) / (y * y)) else: tmp = 1.0 - ((y / x) * (y / x)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.85e-149) || !(y <= 4.6e-149)) tmp = Float64(-1.0 + Float64(Float64(x * x) / Float64(y * y))); else tmp = Float64(1.0 - Float64(Float64(y / x) * Float64(y / x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.85e-149) || ~((y <= 4.6e-149))) tmp = -1.0 + ((x * x) / (y * y)); else tmp = 1.0 - ((y / x) * (y / x)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.85e-149], N[Not[LessEqual[y, 4.6e-149]], $MachinePrecision]], N[(-1.0 + N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.85 \cdot 10^{-149} \lor \neg \left(y \leq 4.6 \cdot 10^{-149}\right):\\
\;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{y}{x} \cdot \frac{y}{x}\\
\end{array}
\end{array}
if y < -2.8499999999999999e-149 or 4.5999999999999999e-149 < y Initial program 70.8%
associate-*r/71.4%
+-commutative71.4%
fma-def71.4%
Simplified71.4%
Taylor expanded in x around 0 88.6%
unpow288.6%
Simplified88.6%
Taylor expanded in x around 0 88.8%
sub-neg88.8%
unpow288.8%
unpow288.8%
metadata-eval88.8%
Simplified88.8%
if -2.8499999999999999e-149 < y < 4.5999999999999999e-149Initial program 56.8%
associate-*r/57.7%
+-commutative57.7%
fma-def57.7%
Simplified57.7%
Taylor expanded in x around inf 56.8%
+-commutative56.8%
unpow256.8%
Simplified56.8%
Taylor expanded in y around 0 55.7%
associate-*r/55.7%
mul-1-neg55.7%
unpow255.7%
unpow255.7%
Simplified55.7%
distribute-lft-neg-in55.7%
times-frac72.6%
Applied egg-rr72.6%
Final simplification83.2%
(FPCore (x y) :precision binary64 (if (<= y -1.05e-149) (+ -1.0 (/ (* x x) (* y y))) (if (<= y 3.5e-190) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.05e-149) {
tmp = -1.0 + ((x * x) / (y * y));
} else if (y <= 3.5e-190) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.05d-149)) then
tmp = (-1.0d0) + ((x * x) / (y * y))
else if (y <= 3.5d-190) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.05e-149) {
tmp = -1.0 + ((x * x) / (y * y));
} else if (y <= 3.5e-190) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.05e-149: tmp = -1.0 + ((x * x) / (y * y)) elif y <= 3.5e-190: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.05e-149) tmp = Float64(-1.0 + Float64(Float64(x * x) / Float64(y * y))); elseif (y <= 3.5e-190) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.05e-149) tmp = -1.0 + ((x * x) / (y * y)); elseif (y <= 3.5e-190) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.05e-149], N[(-1.0 + N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.5e-190], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-149}:\\
\;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-190}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -1.05000000000000005e-149Initial program 59.8%
associate-*r/60.8%
+-commutative60.8%
fma-def60.8%
Simplified60.8%
Taylor expanded in x around 0 93.5%
unpow293.5%
Simplified93.5%
Taylor expanded in x around 0 93.8%
sub-neg93.8%
unpow293.8%
unpow293.8%
metadata-eval93.8%
Simplified93.8%
if -1.05000000000000005e-149 < y < 3.4999999999999999e-190Initial program 58.4%
associate-*r/59.2%
+-commutative59.2%
fma-def59.2%
Simplified59.2%
Taylor expanded in x around inf 74.6%
if 3.4999999999999999e-190 < y Initial program 89.4%
associate-*r/89.3%
+-commutative89.3%
fma-def89.4%
Simplified89.4%
Taylor expanded in x around 0 70.4%
Final simplification82.8%
(FPCore (x y) :precision binary64 (if (<= y -8.8e-150) -1.0 (if (<= y 3e-190) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -8.8e-150) {
tmp = -1.0;
} else if (y <= 3e-190) {
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 <= (-8.8d-150)) then
tmp = -1.0d0
else if (y <= 3d-190) 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 <= -8.8e-150) {
tmp = -1.0;
} else if (y <= 3e-190) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8.8e-150: tmp = -1.0 elif y <= 3e-190: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -8.8e-150) tmp = -1.0; elseif (y <= 3e-190) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -8.8e-150) tmp = -1.0; elseif (y <= 3e-190) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8.8e-150], -1.0, If[LessEqual[y, 3e-190], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{-150}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-190}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -8.7999999999999997e-150 or 2.9999999999999998e-190 < y Initial program 69.2%
associate-*r/69.9%
+-commutative69.9%
fma-def69.9%
Simplified69.9%
Taylor expanded in x around 0 86.1%
if -8.7999999999999997e-150 < y < 2.9999999999999998e-190Initial program 58.4%
associate-*r/59.2%
+-commutative59.2%
fma-def59.2%
Simplified59.2%
Taylor expanded in x around inf 74.6%
Final simplification82.6%
(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 66.0%
associate-*r/66.7%
+-commutative66.7%
fma-def66.7%
Simplified66.7%
Taylor expanded in x around 0 67.1%
Final simplification67.1%
(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 2023171
(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))))