
(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 9 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 (* (expm1 (log1p (/ (- x y) (hypot x y)))) (/ (+ x y) (hypot x y))))
y = abs(y);
double code(double x, double y) {
return expm1(log1p(((x - y) / hypot(x, y)))) * ((x + y) / hypot(x, y));
}
y = Math.abs(y);
public static double code(double x, double y) {
return Math.expm1(Math.log1p(((x - y) / Math.hypot(x, y)))) * ((x + y) / Math.hypot(x, y));
}
y = abs(y) def code(x, y): return math.expm1(math.log1p(((x - y) / math.hypot(x, y)))) * ((x + y) / math.hypot(x, y))
y = abs(y) function code(x, y) return Float64(expm1(log1p(Float64(Float64(x - y) / hypot(x, y)))) * Float64(Float64(x + y) / hypot(x, y))) end
NOTE: y should be positive before calling this function code[x_, y_] := N[(N[(Exp[N[Log[1 + N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x - y}{\mathsf{hypot}\left(x, y\right)}\right)\right) \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Initial program 69.0%
add-sqr-sqrt69.0%
times-frac69.2%
hypot-def69.2%
hypot-def100.0%
Applied egg-rr100.0%
expm1-log1p-u100.0%
Applied egg-rr100.0%
Final simplification100.0%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y))))
y = abs(y);
double code(double x, double y) {
return ((x - y) / hypot(x, y)) * ((x + y) / hypot(x, y));
}
y = Math.abs(y);
public static double code(double x, double y) {
return ((x - y) / Math.hypot(x, y)) * ((x + y) / Math.hypot(x, y));
}
y = abs(y) def code(x, y): return ((x - y) / math.hypot(x, y)) * ((x + y) / math.hypot(x, y))
y = abs(y) function code(x, y) return Float64(Float64(Float64(x - y) / hypot(x, y)) * Float64(Float64(x + y) / hypot(x, y))) end
y = abs(y) function tmp = code(x, y) tmp = ((x - y) / hypot(x, y)) * ((x + y) / hypot(x, y)); end
NOTE: y should be positive before calling this function 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}
y = |y|\\
\\
\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Initial program 69.0%
add-sqr-sqrt69.0%
times-frac69.2%
hypot-def69.2%
hypot-def100.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 99.8%
if 2 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) Initial program 0.0%
associate-/l*3.1%
+-commutative3.1%
remove-double-neg3.1%
sub-neg3.1%
+-commutative3.1%
fma-def3.1%
sub-neg3.1%
remove-double-neg3.1%
Simplified3.1%
Taylor expanded in x around 0 77.9%
Final simplification93.1%
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(if (<= y 2.8e-167)
1.0
(if (or (<= y 1.65e-123) (not (<= y 1.35e-115)))
(+ -1.0 (/ 2.0 (/ y (* x (/ x y)))))
1.0)))y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 2.8e-167) {
tmp = 1.0;
} else if ((y <= 1.65e-123) || !(y <= 1.35e-115)) {
tmp = -1.0 + (2.0 / (y / (x * (x / 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 <= 2.8d-167) then
tmp = 1.0d0
else if ((y <= 1.65d-123) .or. (.not. (y <= 1.35d-115))) then
tmp = (-1.0d0) + (2.0d0 / (y / (x * (x / 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 <= 2.8e-167) {
tmp = 1.0;
} else if ((y <= 1.65e-123) || !(y <= 1.35e-115)) {
tmp = -1.0 + (2.0 / (y / (x * (x / y))));
} else {
tmp = 1.0;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 2.8e-167: tmp = 1.0 elif (y <= 1.65e-123) or not (y <= 1.35e-115): tmp = -1.0 + (2.0 / (y / (x * (x / y)))) else: tmp = 1.0 return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 2.8e-167) tmp = 1.0; elseif ((y <= 1.65e-123) || !(y <= 1.35e-115)) tmp = Float64(-1.0 + Float64(2.0 / Float64(y / Float64(x * Float64(x / y))))); else tmp = 1.0; end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.8e-167) tmp = 1.0; elseif ((y <= 1.65e-123) || ~((y <= 1.35e-115))) tmp = -1.0 + (2.0 / (y / (x * (x / 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, 2.8e-167], 1.0, If[Or[LessEqual[y, 1.65e-123], N[Not[LessEqual[y, 1.35e-115]], $MachinePrecision]], N[(-1.0 + N[(2.0 / N[(y / N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.8 \cdot 10^{-167}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{-123} \lor \neg \left(y \leq 1.35 \cdot 10^{-115}\right):\\
\;\;\;\;-1 + \frac{2}{\frac{y}{x \cdot \frac{x}{y}}}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < 2.79999999999999986e-167 or 1.6500000000000001e-123 < y < 1.35e-115Initial program 64.4%
Taylor expanded in x around inf 35.6%
if 2.79999999999999986e-167 < y < 1.6500000000000001e-123 or 1.35e-115 < y Initial program 94.9%
add-sqr-sqrt94.9%
times-frac94.3%
hypot-def94.3%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 87.6%
sub-neg87.6%
metadata-eval87.6%
+-commutative87.6%
associate-*r/87.6%
associate-/l*87.6%
unpow287.6%
unpow287.6%
times-frac92.7%
unpow292.7%
Simplified92.7%
unpow292.7%
clear-num92.7%
frac-times92.7%
*-un-lft-identity92.7%
Applied egg-rr92.7%
Final simplification44.3%
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ y (* x (/ x y)))))
(if (<= y 1.65e-167)
(+ 1.0 (* -2.0 t_0))
(if (or (<= y 1.8e-123) (not (<= y 6.8e-115)))
(+ -1.0 (/ 2.0 t_0))
1.0))))y = abs(y);
double code(double x, double y) {
double t_0 = y / (x * (x / y));
double tmp;
if (y <= 1.65e-167) {
tmp = 1.0 + (-2.0 * t_0);
} else if ((y <= 1.8e-123) || !(y <= 6.8e-115)) {
tmp = -1.0 + (2.0 / t_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) :: t_0
real(8) :: tmp
t_0 = y / (x * (x / y))
if (y <= 1.65d-167) then
tmp = 1.0d0 + ((-2.0d0) * t_0)
else if ((y <= 1.8d-123) .or. (.not. (y <= 6.8d-115))) then
tmp = (-1.0d0) + (2.0d0 / t_0)
else
tmp = 1.0d0
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double t_0 = y / (x * (x / y));
double tmp;
if (y <= 1.65e-167) {
tmp = 1.0 + (-2.0 * t_0);
} else if ((y <= 1.8e-123) || !(y <= 6.8e-115)) {
tmp = -1.0 + (2.0 / t_0);
} else {
tmp = 1.0;
}
return tmp;
}
y = abs(y) def code(x, y): t_0 = y / (x * (x / y)) tmp = 0 if y <= 1.65e-167: tmp = 1.0 + (-2.0 * t_0) elif (y <= 1.8e-123) or not (y <= 6.8e-115): tmp = -1.0 + (2.0 / t_0) else: tmp = 1.0 return tmp
y = abs(y) function code(x, y) t_0 = Float64(y / Float64(x * Float64(x / y))) tmp = 0.0 if (y <= 1.65e-167) tmp = Float64(1.0 + Float64(-2.0 * t_0)); elseif ((y <= 1.8e-123) || !(y <= 6.8e-115)) tmp = Float64(-1.0 + Float64(2.0 / t_0)); else tmp = 1.0; end return tmp end
y = abs(y) function tmp_2 = code(x, y) t_0 = y / (x * (x / y)); tmp = 0.0; if (y <= 1.65e-167) tmp = 1.0 + (-2.0 * t_0); elseif ((y <= 1.8e-123) || ~((y <= 6.8e-115))) tmp = -1.0 + (2.0 / t_0); else tmp = 1.0; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(y / N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 1.65e-167], N[(1.0 + N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.8e-123], N[Not[LessEqual[y, 6.8e-115]], $MachinePrecision]], N[(-1.0 + N[(2.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 1.0]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := \frac{y}{x \cdot \frac{x}{y}}\\
\mathbf{if}\;y \leq 1.65 \cdot 10^{-167}:\\
\;\;\;\;1 + -2 \cdot t_0\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{-123} \lor \neg \left(y \leq 6.8 \cdot 10^{-115}\right):\\
\;\;\;\;-1 + \frac{2}{t_0}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < 1.64999999999999998e-167Initial program 64.0%
add-sqr-sqrt64.0%
times-frac64.4%
hypot-def64.4%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 29.0%
unpow229.0%
unpow229.0%
times-frac36.8%
unpow236.8%
Simplified36.8%
unpow266.5%
clear-num66.5%
frac-times66.5%
*-un-lft-identity66.5%
Applied egg-rr36.8%
if 1.64999999999999998e-167 < y < 1.7999999999999998e-123 or 6.7999999999999996e-115 < y Initial program 94.9%
add-sqr-sqrt94.9%
times-frac94.3%
hypot-def94.3%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 87.6%
sub-neg87.6%
metadata-eval87.6%
+-commutative87.6%
associate-*r/87.6%
associate-/l*87.6%
unpow287.6%
unpow287.6%
times-frac92.7%
unpow292.7%
Simplified92.7%
unpow292.7%
clear-num92.7%
frac-times92.7%
*-un-lft-identity92.7%
Applied egg-rr92.7%
if 1.7999999999999998e-123 < y < 6.7999999999999996e-115Initial program 100.0%
Taylor expanded in x around inf 100.0%
Final simplification45.8%
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(if (<= y 5.5e-167)
1.0
(if (<= y 4.9e-126)
(/ (- x y) y)
(if (<= y 3.6e-116) 1.0 (/ 1.0 (/ y (- x y)))))))y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 5.5e-167) {
tmp = 1.0;
} else if (y <= 4.9e-126) {
tmp = (x - y) / y;
} else if (y <= 3.6e-116) {
tmp = 1.0;
} else {
tmp = 1.0 / (y / (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) :: tmp
if (y <= 5.5d-167) then
tmp = 1.0d0
else if (y <= 4.9d-126) then
tmp = (x - y) / y
else if (y <= 3.6d-116) then
tmp = 1.0d0
else
tmp = 1.0d0 / (y / (x - y))
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if (y <= 5.5e-167) {
tmp = 1.0;
} else if (y <= 4.9e-126) {
tmp = (x - y) / y;
} else if (y <= 3.6e-116) {
tmp = 1.0;
} else {
tmp = 1.0 / (y / (x - y));
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 5.5e-167: tmp = 1.0 elif y <= 4.9e-126: tmp = (x - y) / y elif y <= 3.6e-116: tmp = 1.0 else: tmp = 1.0 / (y / (x - y)) return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 5.5e-167) tmp = 1.0; elseif (y <= 4.9e-126) tmp = Float64(Float64(x - y) / y); elseif (y <= 3.6e-116) tmp = 1.0; else tmp = Float64(1.0 / Float64(y / Float64(x - y))); end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 5.5e-167) tmp = 1.0; elseif (y <= 4.9e-126) tmp = (x - y) / y; elseif (y <= 3.6e-116) tmp = 1.0; else tmp = 1.0 / (y / (x - y)); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 5.5e-167], 1.0, If[LessEqual[y, 4.9e-126], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 3.6e-116], 1.0, N[(1.0 / N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.5 \cdot 10^{-167}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4.9 \cdot 10^{-126}:\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-116}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{y}{x - y}}\\
\end{array}
\end{array}
if y < 5.5000000000000003e-167 or 4.9000000000000001e-126 < y < 3.59999999999999975e-116Initial program 64.4%
Taylor expanded in x around inf 35.6%
if 5.5000000000000003e-167 < y < 4.9000000000000001e-126Initial program 81.8%
associate-/l*79.8%
+-commutative79.8%
remove-double-neg79.8%
sub-neg79.8%
+-commutative79.8%
fma-def79.8%
sub-neg79.8%
remove-double-neg79.8%
Simplified79.8%
Taylor expanded in x around 0 82.9%
if 3.59999999999999975e-116 < y Initial program 100.0%
associate-/l*99.8%
+-commutative99.8%
remove-double-neg99.8%
sub-neg99.8%
+-commutative99.8%
fma-def99.8%
sub-neg99.8%
remove-double-neg99.8%
Simplified99.8%
Taylor expanded in x around 0 95.2%
add-cbrt-cube95.2%
Applied egg-rr95.2%
associate-*l*95.2%
Simplified95.2%
associate-*r*95.2%
add-cbrt-cube95.2%
clear-num95.2%
Applied egg-rr95.2%
Final simplification44.1%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 1.6e-168) 1.0 (if (or (<= y 9e-124) (not (<= y 3.6e-116))) (/ (- x y) y) 1.0)))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 1.6e-168) {
tmp = 1.0;
} else if ((y <= 9e-124) || !(y <= 3.6e-116)) {
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 <= 1.6d-168) then
tmp = 1.0d0
else if ((y <= 9d-124) .or. (.not. (y <= 3.6d-116))) 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 <= 1.6e-168) {
tmp = 1.0;
} else if ((y <= 9e-124) || !(y <= 3.6e-116)) {
tmp = (x - y) / y;
} else {
tmp = 1.0;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 1.6e-168: tmp = 1.0 elif (y <= 9e-124) or not (y <= 3.6e-116): tmp = (x - y) / y else: tmp = 1.0 return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 1.6e-168) tmp = 1.0; elseif ((y <= 9e-124) || !(y <= 3.6e-116)) 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 <= 1.6e-168) tmp = 1.0; elseif ((y <= 9e-124) || ~((y <= 3.6e-116))) 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, 1.6e-168], 1.0, If[Or[LessEqual[y, 9e-124], N[Not[LessEqual[y, 3.6e-116]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], 1.0]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.6 \cdot 10^{-168}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 9 \cdot 10^{-124} \lor \neg \left(y \leq 3.6 \cdot 10^{-116}\right):\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < 1.60000000000000003e-168 or 8.9999999999999992e-124 < y < 3.59999999999999975e-116Initial program 64.4%
Taylor expanded in x around inf 35.6%
if 1.60000000000000003e-168 < y < 8.9999999999999992e-124 or 3.59999999999999975e-116 < y Initial program 94.9%
associate-/l*94.2%
+-commutative94.2%
remove-double-neg94.2%
sub-neg94.2%
+-commutative94.2%
fma-def94.2%
sub-neg94.2%
remove-double-neg94.2%
Simplified94.2%
Taylor expanded in x around 0 91.7%
Final simplification44.1%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 2.8e-168) 1.0 (if (<= y 8e-134) -1.0 (if (<= y 4.8e-115) 1.0 -1.0))))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 2.8e-168) {
tmp = 1.0;
} else if (y <= 8e-134) {
tmp = -1.0;
} else if (y <= 4.8e-115) {
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 <= 2.8d-168) then
tmp = 1.0d0
else if (y <= 8d-134) then
tmp = -1.0d0
else if (y <= 4.8d-115) 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 <= 2.8e-168) {
tmp = 1.0;
} else if (y <= 8e-134) {
tmp = -1.0;
} else if (y <= 4.8e-115) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 2.8e-168: tmp = 1.0 elif y <= 8e-134: tmp = -1.0 elif y <= 4.8e-115: tmp = 1.0 else: tmp = -1.0 return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 2.8e-168) tmp = 1.0; elseif (y <= 8e-134) tmp = -1.0; elseif (y <= 4.8e-115) 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 <= 2.8e-168) tmp = 1.0; elseif (y <= 8e-134) tmp = -1.0; elseif (y <= 4.8e-115) 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, 2.8e-168], 1.0, If[LessEqual[y, 8e-134], -1.0, If[LessEqual[y, 4.8e-115], 1.0, -1.0]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.8 \cdot 10^{-168}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-134}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{-115}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 2.8000000000000002e-168 or 8.00000000000000032e-134 < y < 4.80000000000000042e-115Initial program 64.5%
Taylor expanded in x around inf 35.4%
if 2.8000000000000002e-168 < y < 8.00000000000000032e-134 or 4.80000000000000042e-115 < y Initial program 94.7%
Taylor expanded in x around 0 92.2%
Final simplification43.9%
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 69.0%
Taylor expanded in x around 0 68.8%
Final simplification68.8%
(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 2023275
(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))))