
(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)) (/ (+ 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 71.9%
add-sqr-sqrt71.9%
times-frac71.2%
hypot-def71.3%
hypot-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(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(x - y) * Float64(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[(x - y), $MachinePrecision] * N[(N[(N[(x + y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x - y\right) \cdot \frac{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Initial program 71.9%
associate-*r/70.9%
+-commutative70.9%
fma-def71.0%
Simplified71.0%
fma-udef70.9%
+-commutative70.9%
*-un-lft-identity70.9%
add-sqr-sqrt71.0%
times-frac71.1%
hypot-def71.2%
hypot-def99.8%
Applied egg-rr99.8%
associate-*l/99.8%
*-lft-identity99.8%
+-commutative99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))) (if (<= t_0 2.0) t_0 (+ (* 2.0 (/ (/ x y) (/ y x))) -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 = (2.0 * ((x / y) / (y / x))) + -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 = (2.0d0 * ((x / y) / (y / x))) + (-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 = (2.0 * ((x / y) / (y / x))) + -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 = (2.0 * ((x / y) / (y / x))) + -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(2.0 * Float64(Float64(x / y) / Float64(y / x))) + -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 = (2.0 * ((x / y) / (y / x))) + -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[(2.0 * N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $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}:\\
\;\;\;\;2 \cdot \frac{\frac{x}{y}}{\frac{y}{x}} + -1\\
\end{array}
\end{array}
if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 2Initial program 100.0%
if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) Initial program 0.0%
add-sqr-sqrt0.0%
times-frac3.1%
hypot-def3.1%
hypot-def99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 54.2%
fma-neg54.2%
unpow254.2%
unpow254.2%
times-frac77.8%
metadata-eval77.8%
Simplified77.8%
fma-udef77.8%
*-commutative77.8%
pow277.8%
Applied egg-rr77.8%
unpow277.8%
clear-num77.8%
un-div-inv77.8%
Applied egg-rr77.8%
Final simplification93.7%
(FPCore (x y)
:precision binary64
(if (or (<= y -7.5e-127)
(not
(or (<= y -1.52e-149)
(and (not (<= y -1.22e-182)) (<= y 3.6e-109)))))
(+ -1.0 (* (/ x y) (/ x y)))
1.0))
double code(double x, double y) {
double tmp;
if ((y <= -7.5e-127) || !((y <= -1.52e-149) || (!(y <= -1.22e-182) && (y <= 3.6e-109)))) {
tmp = -1.0 + ((x / y) * (x / y));
} 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 <= (-7.5d-127)) .or. (.not. (y <= (-1.52d-149)) .or. (.not. (y <= (-1.22d-182))) .and. (y <= 3.6d-109))) then
tmp = (-1.0d0) + ((x / y) * (x / y))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -7.5e-127) || !((y <= -1.52e-149) || (!(y <= -1.22e-182) && (y <= 3.6e-109)))) {
tmp = -1.0 + ((x / y) * (x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.5e-127) or not ((y <= -1.52e-149) or (not (y <= -1.22e-182) and (y <= 3.6e-109))): tmp = -1.0 + ((x / y) * (x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.5e-127) || !((y <= -1.52e-149) || (!(y <= -1.22e-182) && (y <= 3.6e-109)))) tmp = Float64(-1.0 + Float64(Float64(x / y) * Float64(x / y))); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7.5e-127) || ~(((y <= -1.52e-149) || (~((y <= -1.22e-182)) && (y <= 3.6e-109))))) tmp = -1.0 + ((x / y) * (x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.5e-127], N[Not[Or[LessEqual[y, -1.52e-149], And[N[Not[LessEqual[y, -1.22e-182]], $MachinePrecision], LessEqual[y, 3.6e-109]]]], $MachinePrecision]], N[(-1.0 + N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-127} \lor \neg \left(y \leq -1.52 \cdot 10^{-149} \lor \neg \left(y \leq -1.22 \cdot 10^{-182}\right) \land y \leq 3.6 \cdot 10^{-109}\right):\\
\;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -7.5000000000000004e-127 or -1.5199999999999999e-149 < y < -1.22e-182 or 3.6000000000000001e-109 < y Initial program 72.8%
associate-*r/72.6%
+-commutative72.6%
fma-def72.6%
Simplified72.6%
Taylor expanded in y around inf 63.6%
unpow263.6%
Simplified63.6%
Taylor expanded in x around 0 88.5%
sub-neg88.5%
metadata-eval88.5%
unpow288.5%
unpow288.5%
times-frac91.1%
Simplified91.1%
if -7.5000000000000004e-127 < y < -1.5199999999999999e-149 or -1.22e-182 < y < 3.6000000000000001e-109Initial program 70.4%
associate-*r/68.3%
+-commutative68.3%
fma-def68.3%
Simplified68.3%
Taylor expanded in x around inf 80.7%
Final simplification87.1%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (+ (/ x y) 1.0) (+ (/ x y) -1.0))))
(if (<= y -7.6e-126)
t_0
(if (<= y -1.45e-152)
1.0
(if (<= y -5e-184)
t_0
(if (<= y 3.6e-109) 1.0 (+ -1.0 (* (/ x y) (/ x y)))))))))
double code(double x, double y) {
double t_0 = ((x / y) + 1.0) * ((x / y) + -1.0);
double tmp;
if (y <= -7.6e-126) {
tmp = t_0;
} else if (y <= -1.45e-152) {
tmp = 1.0;
} else if (y <= -5e-184) {
tmp = t_0;
} else if (y <= 3.6e-109) {
tmp = 1.0;
} else {
tmp = -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 = ((x / y) + 1.0d0) * ((x / y) + (-1.0d0))
if (y <= (-7.6d-126)) then
tmp = t_0
else if (y <= (-1.45d-152)) then
tmp = 1.0d0
else if (y <= (-5d-184)) then
tmp = t_0
else if (y <= 3.6d-109) then
tmp = 1.0d0
else
tmp = (-1.0d0) + ((x / y) * (x / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = ((x / y) + 1.0) * ((x / y) + -1.0);
double tmp;
if (y <= -7.6e-126) {
tmp = t_0;
} else if (y <= -1.45e-152) {
tmp = 1.0;
} else if (y <= -5e-184) {
tmp = t_0;
} else if (y <= 3.6e-109) {
tmp = 1.0;
} else {
tmp = -1.0 + ((x / y) * (x / y));
}
return tmp;
}
def code(x, y): t_0 = ((x / y) + 1.0) * ((x / y) + -1.0) tmp = 0 if y <= -7.6e-126: tmp = t_0 elif y <= -1.45e-152: tmp = 1.0 elif y <= -5e-184: tmp = t_0 elif y <= 3.6e-109: tmp = 1.0 else: tmp = -1.0 + ((x / y) * (x / y)) return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x / y) + 1.0) * Float64(Float64(x / y) + -1.0)) tmp = 0.0 if (y <= -7.6e-126) tmp = t_0; elseif (y <= -1.45e-152) tmp = 1.0; elseif (y <= -5e-184) tmp = t_0; elseif (y <= 3.6e-109) tmp = 1.0; else tmp = Float64(-1.0 + Float64(Float64(x / y) * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y) t_0 = ((x / y) + 1.0) * ((x / y) + -1.0); tmp = 0.0; if (y <= -7.6e-126) tmp = t_0; elseif (y <= -1.45e-152) tmp = 1.0; elseif (y <= -5e-184) tmp = t_0; elseif (y <= 3.6e-109) tmp = 1.0; else tmp = -1.0 + ((x / y) * (x / y)); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7.6e-126], t$95$0, If[LessEqual[y, -1.45e-152], 1.0, If[LessEqual[y, -5e-184], t$95$0, If[LessEqual[y, 3.6e-109], 1.0, N[(-1.0 + N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\frac{x}{y} + 1\right) \cdot \left(\frac{x}{y} + -1\right)\\
\mathbf{if}\;y \leq -7.6 \cdot 10^{-126}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.45 \cdot 10^{-152}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -5 \cdot 10^{-184}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-109}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y}\\
\end{array}
\end{array}
if y < -7.5999999999999997e-126 or -1.4500000000000001e-152 < y < -5.00000000000000003e-184Initial program 65.6%
associate-*r/65.5%
+-commutative65.5%
fma-def65.5%
Simplified65.5%
Taylor expanded in y around inf 57.7%
unpow257.7%
Simplified57.7%
Taylor expanded in x around 0 89.0%
sub-neg89.0%
metadata-eval89.0%
unpow289.0%
unpow289.0%
times-frac92.3%
Simplified92.3%
difference-of-sqr--192.3%
sub-neg92.3%
metadata-eval92.3%
Applied egg-rr92.3%
if -7.5999999999999997e-126 < y < -1.4500000000000001e-152 or -5.00000000000000003e-184 < y < 3.6000000000000001e-109Initial program 70.4%
associate-*r/68.3%
+-commutative68.3%
fma-def68.3%
Simplified68.3%
Taylor expanded in x around inf 80.7%
if 3.6000000000000001e-109 < y Initial program 99.9%
associate-*r/99.5%
+-commutative99.5%
fma-def99.6%
Simplified99.6%
Taylor expanded in y around inf 86.1%
unpow286.1%
Simplified86.1%
Taylor expanded in x around 0 86.3%
sub-neg86.3%
metadata-eval86.3%
unpow286.3%
unpow286.3%
times-frac86.3%
Simplified86.3%
Final simplification87.1%
(FPCore (x y) :precision binary64 (if (or (<= y -7.5e-127) (not (<= y 3.6e-109))) (+ (* 2.0 (/ (/ x y) (/ y x))) -1.0) (+ 1.0 (* -2.0 (/ y (/ x (/ y x)))))))
double code(double x, double y) {
double tmp;
if ((y <= -7.5e-127) || !(y <= 3.6e-109)) {
tmp = (2.0 * ((x / y) / (y / x))) + -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 <= (-7.5d-127)) .or. (.not. (y <= 3.6d-109))) then
tmp = (2.0d0 * ((x / y) / (y / x))) + (-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 <= -7.5e-127) || !(y <= 3.6e-109)) {
tmp = (2.0 * ((x / y) / (y / x))) + -1.0;
} else {
tmp = 1.0 + (-2.0 * (y / (x / (y / x))));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.5e-127) or not (y <= 3.6e-109): tmp = (2.0 * ((x / y) / (y / x))) + -1.0 else: tmp = 1.0 + (-2.0 * (y / (x / (y / x)))) return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.5e-127) || !(y <= 3.6e-109)) tmp = Float64(Float64(2.0 * Float64(Float64(x / y) / Float64(y / x))) + -1.0); else tmp = Float64(1.0 + Float64(-2.0 * Float64(y / Float64(x / Float64(y / x))))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7.5e-127) || ~((y <= 3.6e-109))) tmp = (2.0 * ((x / y) / (y / x))) + -1.0; else tmp = 1.0 + (-2.0 * (y / (x / (y / x)))); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.5e-127], N[Not[LessEqual[y, 3.6e-109]], $MachinePrecision]], N[(N[(2.0 * N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 + N[(-2.0 * N[(y / N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-127} \lor \neg \left(y \leq 3.6 \cdot 10^{-109}\right):\\
\;\;\;\;2 \cdot \frac{\frac{x}{y}}{\frac{y}{x}} + -1\\
\mathbf{else}:\\
\;\;\;\;1 + -2 \cdot \frac{y}{\frac{x}{\frac{y}{x}}}\\
\end{array}
\end{array}
if y < -7.5000000000000004e-127 or 3.6000000000000001e-109 < y Initial program 73.3%
add-sqr-sqrt73.3%
times-frac74.1%
hypot-def74.1%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 93.1%
fma-neg93.1%
unpow293.1%
unpow293.1%
times-frac93.1%
metadata-eval93.1%
Simplified93.1%
fma-udef93.1%
*-commutative93.1%
pow293.1%
Applied egg-rr93.1%
unpow293.1%
clear-num93.1%
un-div-inv93.1%
Applied egg-rr93.1%
if -7.5000000000000004e-127 < y < 3.6000000000000001e-109Initial program 70.0%
associate-*r/67.1%
+-commutative67.1%
fma-def67.1%
Simplified67.1%
Taylor expanded in y around 0 60.5%
unpow260.5%
unpow260.5%
Simplified60.5%
associate-/l*61.0%
div-inv61.0%
Applied egg-rr61.0%
associate-*r/61.0%
*-rgt-identity61.0%
associate-/l*76.8%
Simplified76.8%
Final simplification86.1%
(FPCore (x y)
:precision binary64
(if (<= y -9e-127)
(* (+ (/ x y) 1.0) (+ (/ x y) -1.0))
(if (<= y 3.7e-109)
(+ 1.0 (* -2.0 (/ y (/ x (/ y x)))))
(+ -1.0 (* (/ x y) (/ x y))))))
double code(double x, double y) {
double tmp;
if (y <= -9e-127) {
tmp = ((x / y) + 1.0) * ((x / y) + -1.0);
} else if (y <= 3.7e-109) {
tmp = 1.0 + (-2.0 * (y / (x / (y / x))));
} else {
tmp = -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) :: tmp
if (y <= (-9d-127)) then
tmp = ((x / y) + 1.0d0) * ((x / y) + (-1.0d0))
else if (y <= 3.7d-109) then
tmp = 1.0d0 + ((-2.0d0) * (y / (x / (y / x))))
else
tmp = (-1.0d0) + ((x / y) * (x / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -9e-127) {
tmp = ((x / y) + 1.0) * ((x / y) + -1.0);
} else if (y <= 3.7e-109) {
tmp = 1.0 + (-2.0 * (y / (x / (y / x))));
} else {
tmp = -1.0 + ((x / y) * (x / y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9e-127: tmp = ((x / y) + 1.0) * ((x / y) + -1.0) elif y <= 3.7e-109: tmp = 1.0 + (-2.0 * (y / (x / (y / x)))) else: tmp = -1.0 + ((x / y) * (x / y)) return tmp
function code(x, y) tmp = 0.0 if (y <= -9e-127) tmp = Float64(Float64(Float64(x / y) + 1.0) * Float64(Float64(x / y) + -1.0)); elseif (y <= 3.7e-109) tmp = Float64(1.0 + Float64(-2.0 * Float64(y / Float64(x / Float64(y / x))))); else tmp = Float64(-1.0 + Float64(Float64(x / y) * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -9e-127) tmp = ((x / y) + 1.0) * ((x / y) + -1.0); elseif (y <= 3.7e-109) tmp = 1.0 + (-2.0 * (y / (x / (y / x)))); else tmp = -1.0 + ((x / y) * (x / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9e-127], N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.7e-109], N[(1.0 + N[(-2.0 * N[(y / N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-127}:\\
\;\;\;\;\left(\frac{x}{y} + 1\right) \cdot \left(\frac{x}{y} + -1\right)\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{-109}:\\
\;\;\;\;1 + -2 \cdot \frac{y}{\frac{x}{\frac{y}{x}}}\\
\mathbf{else}:\\
\;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y}\\
\end{array}
\end{array}
if y < -8.9999999999999998e-127Initial program 65.5%
associate-*r/66.3%
+-commutative66.3%
fma-def66.3%
Simplified66.3%
Taylor expanded in y around inf 61.1%
unpow261.1%
Simplified61.1%
Taylor expanded in x around 0 94.8%
sub-neg94.8%
metadata-eval94.8%
unpow294.8%
unpow294.8%
times-frac94.8%
Simplified94.8%
difference-of-sqr--194.8%
sub-neg94.8%
metadata-eval94.8%
Applied egg-rr94.8%
if -8.9999999999999998e-127 < y < 3.69999999999999981e-109Initial program 70.0%
associate-*r/67.1%
+-commutative67.1%
fma-def67.1%
Simplified67.1%
Taylor expanded in y around 0 60.5%
unpow260.5%
unpow260.5%
Simplified60.5%
associate-/l*61.0%
div-inv61.0%
Applied egg-rr61.0%
associate-*r/61.0%
*-rgt-identity61.0%
associate-/l*76.8%
Simplified76.8%
if 3.69999999999999981e-109 < y Initial program 99.9%
associate-*r/99.5%
+-commutative99.5%
fma-def99.6%
Simplified99.6%
Taylor expanded in y around inf 86.1%
unpow286.1%
Simplified86.1%
Taylor expanded in x around 0 86.3%
sub-neg86.3%
metadata-eval86.3%
unpow286.3%
unpow286.3%
times-frac86.3%
Simplified86.3%
Final simplification86.0%
(FPCore (x y) :precision binary64 (if (<= y -7.6e-126) -1.0 (if (<= y 3.6e-109) 1.0 (/ (- x y) y))))
double code(double x, double y) {
double tmp;
if (y <= -7.6e-126) {
tmp = -1.0;
} else if (y <= 3.6e-109) {
tmp = 1.0;
} else {
tmp = (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 <= (-7.6d-126)) then
tmp = -1.0d0
else if (y <= 3.6d-109) then
tmp = 1.0d0
else
tmp = (x - y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -7.6e-126) {
tmp = -1.0;
} else if (y <= 3.6e-109) {
tmp = 1.0;
} else {
tmp = (x - y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.6e-126: tmp = -1.0 elif y <= 3.6e-109: tmp = 1.0 else: tmp = (x - y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= -7.6e-126) tmp = -1.0; elseif (y <= 3.6e-109) tmp = 1.0; else tmp = Float64(Float64(x - y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.6e-126) tmp = -1.0; elseif (y <= 3.6e-109) tmp = 1.0; else tmp = (x - y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.6e-126], -1.0, If[LessEqual[y, 3.6e-109], 1.0, N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.6 \cdot 10^{-126}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-109}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y}{y}\\
\end{array}
\end{array}
if y < -7.5999999999999997e-126Initial program 65.5%
associate-*r/66.3%
+-commutative66.3%
fma-def66.3%
Simplified66.3%
Taylor expanded in x around 0 94.6%
if -7.5999999999999997e-126 < y < 3.6000000000000001e-109Initial program 70.0%
associate-*r/67.1%
+-commutative67.1%
fma-def67.1%
Simplified67.1%
Taylor expanded in x around inf 75.7%
if 3.6000000000000001e-109 < y Initial program 99.9%
associate-/l*99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around 0 85.6%
Final simplification85.3%
(FPCore (x y) :precision binary64 (if (<= y -4.4e-126) -1.0 (if (<= y 5e-109) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -4.4e-126) {
tmp = -1.0;
} else if (y <= 5e-109) {
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 <= (-4.4d-126)) then
tmp = -1.0d0
else if (y <= 5d-109) 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 <= -4.4e-126) {
tmp = -1.0;
} else if (y <= 5e-109) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.4e-126: tmp = -1.0 elif y <= 5e-109: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -4.4e-126) tmp = -1.0; elseif (y <= 5e-109) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.4e-126) tmp = -1.0; elseif (y <= 5e-109) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.4e-126], -1.0, If[LessEqual[y, 5e-109], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{-126}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-109}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -4.40000000000000029e-126 or 5.0000000000000002e-109 < y Initial program 73.3%
associate-*r/73.8%
+-commutative73.8%
fma-def73.8%
Simplified73.8%
Taylor expanded in x around 0 92.5%
if -4.40000000000000029e-126 < y < 5.0000000000000002e-109Initial program 70.0%
associate-*r/67.1%
+-commutative67.1%
fma-def67.1%
Simplified67.1%
Taylor expanded in x around inf 75.7%
Final simplification85.3%
(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 71.9%
associate-*r/70.9%
+-commutative70.9%
fma-def71.0%
Simplified71.0%
Taylor expanded in x around 0 63.3%
Final simplification63.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 2023192
(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))))