
(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}
(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(Float64(x - y) / 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[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}
\end{array}
Initial program 67.5%
add-sqr-sqrt67.5%
times-frac67.5%
hypot-def67.5%
hypot-def99.9%
Applied egg-rr99.9%
clear-num99.9%
un-div-inv100.0%
Applied egg-rr100.0%
Final simplification100.0%
(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 67.5%
add-sqr-sqrt67.5%
times-frac67.5%
hypot-def67.5%
hypot-def99.9%
Applied egg-rr99.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 (fma 2.0 (* (/ 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 = fma(2.0, ((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 = fma(2.0, Float64(Float64(x / y) * Float64(x / y)), -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[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $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, \frac{x}{y} \cdot \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 99.9%
if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) Initial program 0.0%
associate-*r/3.1%
fma-def3.1%
Simplified3.1%
Taylor expanded in x around 0 55.4%
fma-neg55.4%
unpow255.4%
unpow255.4%
times-frac77.5%
metadata-eval77.5%
Simplified77.5%
Final simplification92.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) y) (/ y (- x 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) / y) / (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 = ((x - y) * (x + y)) / ((x * x) + (y * y))
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = ((x + y) / y) / (y / (x - 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) / y) / (y / (x - 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) / y) / (y / (x - 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(Float64(x + y) / y) / Float64(y / Float64(x - 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) / y) / (y / (x - 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[(N[(x + y), $MachinePrecision] / y), $MachinePrecision] / N[(y / N[(x - 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}:\\
\;\;\;\;\frac{\frac{x + y}{y}}{\frac{y}{x - y}}\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2Initial program 99.9%
if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) Initial program 0.0%
associate-*r/3.1%
fma-def3.1%
Simplified3.1%
Taylor expanded in x around 0 3.1%
unpow23.1%
Simplified3.1%
clear-num3.1%
un-div-inv3.1%
Applied egg-rr3.1%
associate-/l*0.0%
times-frac77.1%
Simplified77.1%
*-commutative77.1%
clear-num77.1%
un-div-inv77.1%
Applied egg-rr77.1%
Final simplification92.5%
(FPCore (x y)
:precision binary64
(if (<= y -6.1e-24)
-1.0
(if (or (<= y -1.6e-162) (not (<= y 5.6e-164)))
(* (- x y) (/ (+ x y) (+ (* x x) (* y y))))
(+ 1.0 (* -2.0 (* (/ y x) (/ y x)))))))
double code(double x, double y) {
double tmp;
if (y <= -6.1e-24) {
tmp = -1.0;
} else if ((y <= -1.6e-162) || !(y <= 5.6e-164)) {
tmp = (x - y) * ((x + y) / ((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 <= (-6.1d-24)) then
tmp = -1.0d0
else if ((y <= (-1.6d-162)) .or. (.not. (y <= 5.6d-164))) then
tmp = (x - y) * ((x + y) / ((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 <= -6.1e-24) {
tmp = -1.0;
} else if ((y <= -1.6e-162) || !(y <= 5.6e-164)) {
tmp = (x - y) * ((x + y) / ((x * x) + (y * y)));
} else {
tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.1e-24: tmp = -1.0 elif (y <= -1.6e-162) or not (y <= 5.6e-164): tmp = (x - y) * ((x + y) / ((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 <= -6.1e-24) tmp = -1.0; elseif ((y <= -1.6e-162) || !(y <= 5.6e-164)) tmp = Float64(Float64(x - y) * Float64(Float64(x + y) / 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 <= -6.1e-24) tmp = -1.0; elseif ((y <= -1.6e-162) || ~((y <= 5.6e-164))) tmp = (x - y) * ((x + y) / ((x * x) + (y * y))); else tmp = 1.0 + (-2.0 * ((y / x) * (y / x))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.1e-24], -1.0, If[Or[LessEqual[y, -1.6e-162], N[Not[LessEqual[y, 5.6e-164]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-2.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.1 \cdot 10^{-24}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq -1.6 \cdot 10^{-162} \lor \neg \left(y \leq 5.6 \cdot 10^{-164}\right):\\
\;\;\;\;\left(x - y\right) \cdot \frac{x + y}{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 < -6.10000000000000036e-24Initial program 53.1%
associate-*r/54.3%
fma-def54.3%
Simplified54.3%
Taylor expanded in x around 0 100.0%
if -6.10000000000000036e-24 < y < -1.59999999999999988e-162 or 5.6000000000000002e-164 < y Initial program 99.9%
associate-*r/96.8%
fma-def96.8%
Simplified96.8%
fma-def96.8%
+-commutative96.8%
Applied egg-rr96.8%
if -1.59999999999999988e-162 < y < 5.6000000000000002e-164Initial program 53.8%
associate-*r/54.5%
fma-def54.5%
Simplified54.5%
Taylor expanded in y around 0 53.8%
unpow253.8%
unpow253.8%
Simplified53.8%
times-frac79.1%
Applied egg-rr79.1%
Final simplification92.5%
(FPCore (x y) :precision binary64 (if (or (<= y -1.55e-169) (not (<= y 9.5e-153))) (+ (* (/ x y) (/ x y)) -1.0) (+ 1.0 (* -2.0 (* (/ y x) (/ y x))))))
double code(double x, double y) {
double tmp;
if ((y <= -1.55e-169) || !(y <= 9.5e-153)) {
tmp = ((x / y) * (x / y)) + -1.0;
} 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 <= (-1.55d-169)) .or. (.not. (y <= 9.5d-153))) then
tmp = ((x / y) * (x / y)) + (-1.0d0)
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 <= -1.55e-169) || !(y <= 9.5e-153)) {
tmp = ((x / y) * (x / y)) + -1.0;
} else {
tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.55e-169) or not (y <= 9.5e-153): tmp = ((x / y) * (x / y)) + -1.0 else: tmp = 1.0 + (-2.0 * ((y / x) * (y / x))) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.55e-169) || !(y <= 9.5e-153)) tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0); 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 <= -1.55e-169) || ~((y <= 9.5e-153))) tmp = ((x / y) * (x / y)) + -1.0; else tmp = 1.0 + (-2.0 * ((y / x) * (y / x))); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.55e-169], N[Not[LessEqual[y, 9.5e-153]], $MachinePrecision]], N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $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 -1.55 \cdot 10^{-169} \lor \neg \left(y \leq 9.5 \cdot 10^{-153}\right):\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\
\mathbf{else}:\\
\;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\end{array}
\end{array}
if y < -1.5500000000000001e-169 or 9.50000000000000031e-153 < y Initial program 72.2%
associate-*r/72.3%
fma-def72.3%
Simplified72.3%
Taylor expanded in x around 0 58.3%
unpow258.3%
Simplified58.3%
clear-num58.4%
un-div-inv58.5%
Applied egg-rr58.5%
associate-/l*58.3%
times-frac86.0%
Simplified86.0%
Taylor expanded in x around 0 84.8%
sub-neg84.8%
unpow284.8%
unpow284.8%
metadata-eval84.8%
Simplified84.8%
times-frac86.0%
Applied egg-rr86.0%
if -1.5500000000000001e-169 < y < 9.50000000000000031e-153Initial program 57.8%
associate-*r/57.0%
fma-def57.0%
Simplified57.0%
Taylor expanded in y around 0 55.2%
unpow255.2%
unpow255.2%
Simplified55.2%
times-frac79.5%
Applied egg-rr79.5%
Final simplification83.9%
(FPCore (x y)
:precision binary64
(if (<= y -1.95e-169)
(+ (* (/ x y) (/ x y)) -1.0)
(if (<= y 7.8e-153)
(+ 1.0 (* -2.0 (* (/ y x) (/ y x))))
(/ (/ (+ x y) y) (/ y (- x y))))))
double code(double x, double y) {
double tmp;
if (y <= -1.95e-169) {
tmp = ((x / y) * (x / y)) + -1.0;
} else if (y <= 7.8e-153) {
tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
} else {
tmp = ((x + y) / y) / (y / (x - 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.95d-169)) then
tmp = ((x / y) * (x / y)) + (-1.0d0)
else if (y <= 7.8d-153) then
tmp = 1.0d0 + ((-2.0d0) * ((y / x) * (y / x)))
else
tmp = ((x + y) / y) / (y / (x - y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.95e-169) {
tmp = ((x / y) * (x / y)) + -1.0;
} else if (y <= 7.8e-153) {
tmp = 1.0 + (-2.0 * ((y / x) * (y / x)));
} else {
tmp = ((x + y) / y) / (y / (x - y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.95e-169: tmp = ((x / y) * (x / y)) + -1.0 elif y <= 7.8e-153: tmp = 1.0 + (-2.0 * ((y / x) * (y / x))) else: tmp = ((x + y) / y) / (y / (x - y)) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.95e-169) tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0); elseif (y <= 7.8e-153) tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / x) * Float64(y / x)))); else tmp = Float64(Float64(Float64(x + y) / y) / Float64(y / Float64(x - y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.95e-169) tmp = ((x / y) * (x / y)) + -1.0; elseif (y <= 7.8e-153) tmp = 1.0 + (-2.0 * ((y / x) * (y / x))); else tmp = ((x + y) / y) / (y / (x - y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.95e-169], N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[y, 7.8e-153], N[(1.0 + N[(-2.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision] / N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{-169}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{-153}:\\
\;\;\;\;1 + -2 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x + y}{y}}{\frac{y}{x - y}}\\
\end{array}
\end{array}
if y < -1.94999999999999988e-169Initial program 64.4%
associate-*r/64.6%
fma-def64.6%
Simplified64.6%
Taylor expanded in x around 0 54.5%
unpow254.5%
Simplified54.5%
clear-num54.6%
un-div-inv54.6%
Applied egg-rr54.6%
associate-/l*54.3%
times-frac89.8%
Simplified89.8%
Taylor expanded in x around 0 88.4%
sub-neg88.4%
unpow288.4%
unpow288.4%
metadata-eval88.4%
Simplified88.4%
times-frac89.9%
Applied egg-rr89.9%
if -1.94999999999999988e-169 < y < 7.8000000000000004e-153Initial program 57.8%
associate-*r/57.0%
fma-def57.0%
Simplified57.0%
Taylor expanded in y around 0 55.2%
unpow255.2%
unpow255.2%
Simplified55.2%
times-frac79.5%
Applied egg-rr79.5%
if 7.8000000000000004e-153 < y Initial program 99.8%
associate-*r/99.5%
fma-def99.6%
Simplified99.6%
Taylor expanded in x around 0 72.0%
unpow272.0%
Simplified72.0%
clear-num72.0%
un-div-inv72.2%
Applied egg-rr72.2%
associate-/l*72.3%
times-frac72.3%
Simplified72.3%
*-commutative72.3%
clear-num72.3%
un-div-inv72.3%
Applied egg-rr72.3%
Final simplification83.9%
(FPCore (x y) :precision binary64 (if (or (<= y -4.9e-170) (not (<= y 1.52e-152))) (+ (* (/ x y) (/ x y)) -1.0) 1.0))
double code(double x, double y) {
double tmp;
if ((y <= -4.9e-170) || !(y <= 1.52e-152)) {
tmp = ((x / y) * (x / y)) + -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 <= (-4.9d-170)) .or. (.not. (y <= 1.52d-152))) then
tmp = ((x / y) * (x / y)) + (-1.0d0)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -4.9e-170) || !(y <= 1.52e-152)) {
tmp = ((x / y) * (x / y)) + -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.9e-170) or not (y <= 1.52e-152): tmp = ((x / y) * (x / y)) + -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.9e-170) || !(y <= 1.52e-152)) tmp = Float64(Float64(Float64(x / y) * Float64(x / y)) + -1.0); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -4.9e-170) || ~((y <= 1.52e-152))) tmp = ((x / y) * (x / y)) + -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.9e-170], N[Not[LessEqual[y, 1.52e-152]], $MachinePrecision]], N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.9 \cdot 10^{-170} \lor \neg \left(y \leq 1.52 \cdot 10^{-152}\right):\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y} + -1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.8999999999999996e-170 or 1.52000000000000009e-152 < y Initial program 72.2%
associate-*r/72.3%
fma-def72.3%
Simplified72.3%
Taylor expanded in x around 0 58.3%
unpow258.3%
Simplified58.3%
clear-num58.4%
un-div-inv58.5%
Applied egg-rr58.5%
associate-/l*58.3%
times-frac86.0%
Simplified86.0%
Taylor expanded in x around 0 84.8%
sub-neg84.8%
unpow284.8%
unpow284.8%
metadata-eval84.8%
Simplified84.8%
times-frac86.0%
Applied egg-rr86.0%
if -4.8999999999999996e-170 < y < 1.52000000000000009e-152Initial program 57.8%
associate-*r/57.0%
fma-def57.0%
Simplified57.0%
Taylor expanded in x around inf 78.0%
Final simplification83.4%
(FPCore (x y) :precision binary64 (if (<= y -1.6e-169) -1.0 (if (<= y 5.5e-151) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.6e-169) {
tmp = -1.0;
} else if (y <= 5.5e-151) {
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.6d-169)) then
tmp = -1.0d0
else if (y <= 5.5d-151) 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.6e-169) {
tmp = -1.0;
} else if (y <= 5.5e-151) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.6e-169: tmp = -1.0 elif y <= 5.5e-151: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.6e-169) tmp = -1.0; elseif (y <= 5.5e-151) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.6e-169) tmp = -1.0; elseif (y <= 5.5e-151) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.6e-169], -1.0, If[LessEqual[y, 5.5e-151], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{-169}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-151}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -1.59999999999999997e-169 or 5.4999999999999998e-151 < y Initial program 72.2%
associate-*r/72.3%
fma-def72.3%
Simplified72.3%
Taylor expanded in x around 0 85.1%
if -1.59999999999999997e-169 < y < 5.4999999999999998e-151Initial program 57.8%
associate-*r/57.0%
fma-def57.0%
Simplified57.0%
Taylor expanded in x around inf 78.0%
Final simplification82.8%
(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 67.5%
associate-*r/67.3%
fma-def67.3%
Simplified67.3%
Taylor expanded in x around 0 64.4%
Final simplification64.4%
(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 2023178
(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))))