
(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 8 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}
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (/ (- x y) (+ (* x (/ x (+ x y))) (* y (/ y (+ x y))))))
y = abs(y);
double code(double x, double y) {
return (x - y) / ((x * (x / (x + y))) + (y * (y / (x + y))));
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x - y) / ((x * (x / (x + y))) + (y * (y / (x + y))))
end function
y = Math.abs(y);
public static double code(double x, double y) {
return (x - y) / ((x * (x / (x + y))) + (y * (y / (x + y))));
}
y = abs(y) def code(x, y): return (x - y) / ((x * (x / (x + y))) + (y * (y / (x + y))))
y = abs(y) function code(x, y) return Float64(Float64(x - y) / Float64(Float64(x * Float64(x / Float64(x + y))) + Float64(y * Float64(y / Float64(x + y))))) end
y = abs(y) function tmp = code(x, y) tmp = (x - y) / ((x * (x / (x + y))) + (y * (y / (x + y)))); end
NOTE: y should be positive before calling this function code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(N[(x * N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y * N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{x - y}{x \cdot \frac{x}{x + y} + y \cdot \frac{y}{x + y}}
\end{array}
Initial program 67.2%
+-commutative67.2%
+-commutative67.2%
associate-*r/67.1%
+-commutative67.1%
+-commutative67.1%
fma-def67.1%
Simplified67.1%
associate-*r/67.2%
associate-/l*67.3%
Applied egg-rr67.3%
div-inv67.0%
*-commutative67.0%
fma-udef67.0%
distribute-rgt-in67.0%
div-inv67.1%
div-inv67.3%
flip-+66.9%
flip--66.2%
associate-/r/66.2%
times-frac66.9%
*-inverses90.9%
/-rgt-identity90.9%
Applied egg-rr90.9%
associate-/l*100.0%
associate-/r/100.0%
+-commutative100.0%
Applied egg-rr100.0%
Final simplification100.0%
NOTE: y should be positive before calling this function (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 = abs(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;
}
return tmp;
}
NOTE: y should be positive before calling this function
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
end if
code = tmp
end function
y = Math.abs(y);
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;
}
return tmp;
}
y = abs(y) 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 return tmp
y = abs(y) 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) / y); end return tmp end
y = abs(y) 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; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function
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] / y), $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\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}{y}\\
\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%
+-commutative0.0%
associate-*r/3.1%
+-commutative3.1%
+-commutative3.1%
fma-def3.1%
Simplified3.1%
Taylor expanded in x around 0 71.1%
Taylor expanded in x around 0 71.2%
*-inverses71.2%
div-sub71.2%
Simplified71.2%
Final simplification90.5%
NOTE: y should be positive before calling this function (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 x) (* 2.0 (* x (/ x y))))))))
y = abs(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 - x) + (2.0 * (x * (x / y))));
}
return tmp;
}
NOTE: y should be positive before calling this function
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 - x) + (2.0d0 * (x * (x / y))))
end if
code = tmp
end function
y = Math.abs(y);
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 - x) + (2.0 * (x * (x / y))));
}
return tmp;
}
y = abs(y) 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 - x) + (2.0 * (x * (x / y)))) return tmp
y = abs(y) 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(y - x) + Float64(2.0 * Float64(x * Float64(x / y))))); end return tmp end
y = abs(y) 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 - x) + (2.0 * (x * (x / y)))); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function
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[(y - x), $MachinePrecision] + N[(2.0 * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\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}{\left(y - x\right) + 2 \cdot \left(x \cdot \frac{x}{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%
+-commutative0.0%
+-commutative0.0%
associate-*r/3.1%
+-commutative3.1%
+-commutative3.1%
fma-def3.1%
Simplified3.1%
associate-*r/0.0%
associate-/l*3.1%
Applied egg-rr3.1%
Taylor expanded in x around 0 71.6%
mul-1-neg71.6%
associate-+r+71.6%
sub-neg71.6%
unpow271.6%
associate-*r/72.6%
Simplified72.6%
Final simplification91.0%
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(if (<= y 1.5e-190)
1.0
(if (or (<= y 2e-138) (not (<= y 1.75e-122)))
(/ (- x y) y)
(+ 1.0 (* -2.0 (/ (* y y) (* x x)))))))y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 1.5e-190) {
tmp = 1.0;
} else if ((y <= 2e-138) || !(y <= 1.75e-122)) {
tmp = (x - y) / y;
} else {
tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 1.5d-190) then
tmp = 1.0d0
else if ((y <= 2d-138) .or. (.not. (y <= 1.75d-122))) then
tmp = (x - y) / y
else
tmp = 1.0d0 + ((-2.0d0) * ((y * y) / (x * x)))
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if (y <= 1.5e-190) {
tmp = 1.0;
} else if ((y <= 2e-138) || !(y <= 1.75e-122)) {
tmp = (x - y) / y;
} else {
tmp = 1.0 + (-2.0 * ((y * y) / (x * x)));
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 1.5e-190: tmp = 1.0 elif (y <= 2e-138) or not (y <= 1.75e-122): tmp = (x - y) / y else: tmp = 1.0 + (-2.0 * ((y * y) / (x * x))) return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 1.5e-190) tmp = 1.0; elseif ((y <= 2e-138) || !(y <= 1.75e-122)) tmp = Float64(Float64(x - y) / y); else tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y * y) / Float64(x * x)))); end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.5e-190) tmp = 1.0; elseif ((y <= 2e-138) || ~((y <= 1.75e-122))) tmp = (x - y) / y; else tmp = 1.0 + (-2.0 * ((y * y) / (x * x))); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 1.5e-190], 1.0, If[Or[LessEqual[y, 2e-138], N[Not[LessEqual[y, 1.75e-122]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], N[(1.0 + N[(-2.0 * N[(N[(y * y), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.5 \cdot 10^{-190}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-138} \lor \neg \left(y \leq 1.75 \cdot 10^{-122}\right):\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{else}:\\
\;\;\;\;1 + -2 \cdot \frac{y \cdot y}{x \cdot x}\\
\end{array}
\end{array}
if y < 1.4999999999999999e-190Initial program 61.7%
+-commutative61.7%
+-commutative61.7%
associate-*r/61.9%
+-commutative61.9%
+-commutative61.9%
fma-def61.9%
Simplified61.9%
Taylor expanded in x around inf 37.7%
if 1.4999999999999999e-190 < y < 2.00000000000000013e-138 or 1.7500000000000001e-122 < y Initial program 87.5%
+-commutative87.5%
+-commutative87.5%
associate-*r/86.2%
+-commutative86.2%
+-commutative86.2%
fma-def86.2%
Simplified86.2%
Taylor expanded in x around 0 68.8%
Taylor expanded in x around 0 68.8%
*-inverses68.8%
div-sub68.8%
Simplified68.8%
if 2.00000000000000013e-138 < y < 1.7500000000000001e-122Initial program 100.0%
+-commutative100.0%
+-commutative100.0%
associate-*r/99.6%
+-commutative99.6%
+-commutative99.6%
fma-def99.6%
Simplified99.6%
Taylor expanded in y around 0 75.8%
unpow275.8%
unpow275.8%
Simplified75.8%
Final simplification44.1%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (or (<= y 6e-189) (and (not (<= y 1.2e-135)) (<= y 3.5e-122))) (+ 1.0 (/ (/ (* y -2.0) (/ x y)) x)) (/ (- x y) y)))
y = abs(y);
double code(double x, double y) {
double tmp;
if ((y <= 6e-189) || (!(y <= 1.2e-135) && (y <= 3.5e-122))) {
tmp = 1.0 + (((y * -2.0) / (x / y)) / x);
} else {
tmp = (x - y) / y;
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= 6d-189) .or. (.not. (y <= 1.2d-135)) .and. (y <= 3.5d-122)) then
tmp = 1.0d0 + (((y * (-2.0d0)) / (x / y)) / x)
else
tmp = (x - y) / y
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if ((y <= 6e-189) || (!(y <= 1.2e-135) && (y <= 3.5e-122))) {
tmp = 1.0 + (((y * -2.0) / (x / y)) / x);
} else {
tmp = (x - y) / y;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if (y <= 6e-189) or (not (y <= 1.2e-135) and (y <= 3.5e-122)): tmp = 1.0 + (((y * -2.0) / (x / y)) / x) else: tmp = (x - y) / y return tmp
y = abs(y) function code(x, y) tmp = 0.0 if ((y <= 6e-189) || (!(y <= 1.2e-135) && (y <= 3.5e-122))) tmp = Float64(1.0 + Float64(Float64(Float64(y * -2.0) / Float64(x / y)) / x)); else tmp = Float64(Float64(x - y) / y); end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 6e-189) || (~((y <= 1.2e-135)) && (y <= 3.5e-122))) tmp = 1.0 + (((y * -2.0) / (x / y)) / x); else tmp = (x - y) / y; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[Or[LessEqual[y, 6e-189], And[N[Not[LessEqual[y, 1.2e-135]], $MachinePrecision], LessEqual[y, 3.5e-122]]], N[(1.0 + N[(N[(N[(y * -2.0), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6 \cdot 10^{-189} \lor \neg \left(y \leq 1.2 \cdot 10^{-135}\right) \land y \leq 3.5 \cdot 10^{-122}:\\
\;\;\;\;1 + \frac{\frac{y \cdot -2}{\frac{x}{y}}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y}{y}\\
\end{array}
\end{array}
if y < 6e-189 or 1.1999999999999999e-135 < y < 3.5000000000000001e-122Initial program 62.5%
+-commutative62.5%
+-commutative62.5%
associate-*r/62.6%
+-commutative62.6%
+-commutative62.6%
fma-def62.6%
Simplified62.6%
Taylor expanded in y around 0 28.7%
unpow228.7%
unpow228.7%
Simplified28.7%
associate-/r*39.7%
associate-*r/39.7%
associate-/l*40.3%
associate-*r/40.3%
*-commutative40.3%
Applied egg-rr40.3%
if 6e-189 < y < 1.1999999999999999e-135 or 3.5000000000000001e-122 < y Initial program 87.5%
+-commutative87.5%
+-commutative87.5%
associate-*r/86.2%
+-commutative86.2%
+-commutative86.2%
fma-def86.2%
Simplified86.2%
Taylor expanded in x around 0 68.8%
Taylor expanded in x around 0 68.8%
*-inverses68.8%
div-sub68.8%
Simplified68.8%
Final simplification45.7%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 5e-189) 1.0 (if (or (<= y 1.55e-134) (not (<= y 1.8e-120))) (/ (- x y) y) 1.0)))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 5e-189) {
tmp = 1.0;
} else if ((y <= 1.55e-134) || !(y <= 1.8e-120)) {
tmp = (x - y) / y;
} else {
tmp = 1.0;
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 5d-189) then
tmp = 1.0d0
else if ((y <= 1.55d-134) .or. (.not. (y <= 1.8d-120))) then
tmp = (x - y) / y
else
tmp = 1.0d0
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if (y <= 5e-189) {
tmp = 1.0;
} else if ((y <= 1.55e-134) || !(y <= 1.8e-120)) {
tmp = (x - y) / y;
} else {
tmp = 1.0;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 5e-189: tmp = 1.0 elif (y <= 1.55e-134) or not (y <= 1.8e-120): tmp = (x - y) / y else: tmp = 1.0 return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 5e-189) tmp = 1.0; elseif ((y <= 1.55e-134) || !(y <= 1.8e-120)) tmp = Float64(Float64(x - y) / y); else tmp = 1.0; end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 5e-189) tmp = 1.0; elseif ((y <= 1.55e-134) || ~((y <= 1.8e-120))) tmp = (x - y) / y; else tmp = 1.0; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 5e-189], 1.0, If[Or[LessEqual[y, 1.55e-134], N[Not[LessEqual[y, 1.8e-120]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], 1.0]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5 \cdot 10^{-189}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-134} \lor \neg \left(y \leq 1.8 \cdot 10^{-120}\right):\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < 4.9999999999999997e-189 or 1.55000000000000003e-134 < y < 1.8000000000000001e-120Initial program 62.3%
+-commutative62.3%
+-commutative62.3%
associate-*r/62.5%
+-commutative62.5%
+-commutative62.5%
fma-def62.5%
Simplified62.5%
Taylor expanded in x around inf 38.1%
if 4.9999999999999997e-189 < y < 1.55000000000000003e-134 or 1.8000000000000001e-120 < y Initial program 87.8%
+-commutative87.8%
+-commutative87.8%
associate-*r/86.5%
+-commutative86.5%
+-commutative86.5%
fma-def86.5%
Simplified86.5%
Taylor expanded in x around 0 67.5%
Taylor expanded in x around 0 67.6%
*-inverses67.6%
div-sub67.6%
Simplified67.6%
Final simplification43.8%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 6.8e-189) 1.0 (if (<= y 8e-157) -1.0 (if (<= y 2e-122) 1.0 -1.0))))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 6.8e-189) {
tmp = 1.0;
} else if (y <= 8e-157) {
tmp = -1.0;
} else if (y <= 2e-122) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 6.8d-189) then
tmp = 1.0d0
else if (y <= 8d-157) then
tmp = -1.0d0
else if (y <= 2d-122) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if (y <= 6.8e-189) {
tmp = 1.0;
} else if (y <= 8e-157) {
tmp = -1.0;
} else if (y <= 2e-122) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 6.8e-189: tmp = 1.0 elif y <= 8e-157: tmp = -1.0 elif y <= 2e-122: tmp = 1.0 else: tmp = -1.0 return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 6.8e-189) tmp = 1.0; elseif (y <= 8e-157) tmp = -1.0; elseif (y <= 2e-122) tmp = 1.0; else tmp = -1.0; end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 6.8e-189) tmp = 1.0; elseif (y <= 8e-157) tmp = -1.0; elseif (y <= 2e-122) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 6.8e-189], 1.0, If[LessEqual[y, 8e-157], -1.0, If[LessEqual[y, 2e-122], 1.0, -1.0]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.8 \cdot 10^{-189}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-157}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-122}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 6.8000000000000002e-189 or 7.99999999999999955e-157 < y < 2.00000000000000012e-122Initial program 63.4%
+-commutative63.4%
+-commutative63.4%
associate-*r/63.5%
+-commutative63.5%
+-commutative63.5%
fma-def63.5%
Simplified63.5%
Taylor expanded in x around inf 39.4%
if 6.8000000000000002e-189 < y < 7.99999999999999955e-157 or 2.00000000000000012e-122 < y Initial program 86.0%
+-commutative86.0%
+-commutative86.0%
associate-*r/84.7%
+-commutative84.7%
+-commutative84.7%
fma-def84.7%
Simplified84.7%
Taylor expanded in x around 0 72.5%
Final simplification45.0%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 -1.0)
y = abs(y);
double code(double x, double y) {
return -1.0;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
y = Math.abs(y);
public static double code(double x, double y) {
return -1.0;
}
y = abs(y) def code(x, y): return -1.0
y = abs(y) function code(x, y) return -1.0 end
y = abs(y) function tmp = code(x, y) tmp = -1.0; end
NOTE: y should be positive before calling this function code[x_, y_] := -1.0
\begin{array}{l}
y = |y|\\
\\
-1
\end{array}
Initial program 67.2%
+-commutative67.2%
+-commutative67.2%
associate-*r/67.1%
+-commutative67.1%
+-commutative67.1%
fma-def67.1%
Simplified67.1%
Taylor expanded in x around 0 62.7%
Final simplification62.7%
(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 2023297
(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))))