
(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
double code(double x, double y) {
return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x - y) * (x + y)) / ((x * x) + (y * y))
end function
public static double code(double x, double y) {
return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
def code(x, y): return ((x - y) * (x + y)) / ((x * x) + (y * y))
function code(x, y) return Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) end
function tmp = code(x, y) tmp = ((x - y) * (x + y)) / ((x * x) + (y * y)); end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
double code(double x, double y) {
return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x - y) * (x + y)) / ((x * x) + (y * y))
end function
public static double code(double x, double y) {
return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
def code(x, y): return ((x - y) * (x + y)) / ((x * x) + (y * y))
function code(x, y) return Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) end
function tmp = code(x, y) tmp = ((x - y) * (x + y)) / ((x * x) + (y * y)); end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\end{array}
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (/ (/ (- x y) (hypot x y)) (/ (hypot x y) (+ x y))))
y = abs(y);
double code(double x, double y) {
return ((x - y) / hypot(x, y)) / (hypot(x, y) / (x + y));
}
y = Math.abs(y);
public static double code(double x, double y) {
return ((x - y) / Math.hypot(x, y)) / (Math.hypot(x, y) / (x + y));
}
y = abs(y) def code(x, y): return ((x - y) / math.hypot(x, y)) / (math.hypot(x, y) / (x + y))
y = abs(y) function code(x, y) return Float64(Float64(Float64(x - y) / hypot(x, y)) / Float64(hypot(x, y) / Float64(x + y))) end
y = abs(y) function tmp = code(x, y) tmp = ((x - y) / hypot(x, y)) / (hypot(x, y) / (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[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}
\end{array}
Initial program 66.0%
fma-def66.0%
add-sqr-sqrt66.0%
times-frac66.5%
fma-def66.5%
hypot-def66.5%
fma-def66.5%
hypot-def99.9%
Applied egg-rr99.9%
clear-num99.9%
un-div-inv99.9%
Applied egg-rr99.9%
Final simplification99.9%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (* (- x y) (/ (/ (+ x y) (hypot x y)) (hypot x y))))
y = abs(y);
double code(double x, double y) {
return (x - y) * (((x + y) / hypot(x, y)) / hypot(x, y));
}
y = Math.abs(y);
public static double code(double x, double y) {
return (x - y) * (((x + y) / Math.hypot(x, y)) / Math.hypot(x, y));
}
y = abs(y) def code(x, y): return (x - y) * (((x + y) / math.hypot(x, y)) / math.hypot(x, y))
y = abs(y) function code(x, y) return Float64(Float64(x - y) * Float64(Float64(Float64(x + y) / hypot(x, y)) / hypot(x, y))) end
y = abs(y) function tmp = code(x, y) tmp = (x - y) * (((x + y) / hypot(x, y)) / hypot(x, y)); end
NOTE: y should be positive before calling this function 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}
y = |y|\\
\\
\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 66.0%
+-commutative66.0%
+-commutative66.0%
associate-*r/66.3%
+-commutative66.3%
+-commutative66.3%
fma-def66.3%
Simplified66.3%
add-sqr-sqrt66.3%
*-un-lft-identity66.3%
times-frac66.3%
fma-def66.3%
hypot-def66.3%
fma-def66.3%
hypot-def99.7%
Applied egg-rr99.7%
associate-*l/99.7%
*-lft-identity99.7%
+-commutative99.7%
Simplified99.7%
Final simplification99.7%
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 66.0%
fma-def66.0%
add-sqr-sqrt66.0%
times-frac66.5%
fma-def66.5%
hypot-def66.5%
fma-def66.5%
hypot-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
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) / Float64(hypot(x, y) / 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[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{\frac{x - y}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Initial program 66.0%
fma-def66.0%
add-sqr-sqrt66.0%
times-frac66.5%
fma-def66.5%
hypot-def66.5%
fma-def66.5%
hypot-def99.9%
Applied egg-rr99.9%
associate-*l/99.9%
clear-num99.9%
un-div-inv99.9%
Applied egg-rr99.9%
Final simplification99.9%
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 (/ y x))) x)))))
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 / (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) :: 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 / (y / x))) - x)
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 / (y / x))) - x);
}
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 / (y / x))) - x) 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 + Float64(x / Float64(y / x))) - x)); 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 / (y / x))) - x); 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 + N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $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 + \frac{x}{\frac{y}{x}}\right) - x}\\
\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-/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 3.1%
unpow23.1%
Simplified3.1%
Taylor expanded in y around inf 71.9%
+-commutative71.9%
neg-mul-171.9%
+-commutative71.9%
associate-+l+71.9%
unpow271.9%
+-commutative71.9%
sub-neg71.9%
Simplified71.9%
associate-+r-71.9%
associate-/l*73.3%
Applied egg-rr73.3%
Final simplification90.9%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 1.85e-162) (+ 1.0 (* -2.0 (/ (/ y (/ x y)) x))) (if (<= y 10000.0) (* (- x y) (/ (+ x y) (+ (* x x) (* y y)))) -1.0)))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 1.85e-162) {
tmp = 1.0 + (-2.0 * ((y / (x / y)) / x));
} else if (y <= 10000.0) {
tmp = (x - y) * ((x + y) / ((x * 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.85d-162) then
tmp = 1.0d0 + ((-2.0d0) * ((y / (x / y)) / x))
else if (y <= 10000.0d0) then
tmp = (x - y) * ((x + y) / ((x * 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.85e-162) {
tmp = 1.0 + (-2.0 * ((y / (x / y)) / x));
} else if (y <= 10000.0) {
tmp = (x - y) * ((x + y) / ((x * x) + (y * y)));
} else {
tmp = -1.0;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 1.85e-162: tmp = 1.0 + (-2.0 * ((y / (x / y)) / x)) elif y <= 10000.0: tmp = (x - y) * ((x + y) / ((x * x) + (y * y))) else: tmp = -1.0 return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 1.85e-162) tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / Float64(x / y)) / x))); elseif (y <= 10000.0) tmp = Float64(Float64(x - y) * Float64(Float64(x + y) / Float64(Float64(x * x) + Float64(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.85e-162) tmp = 1.0 + (-2.0 * ((y / (x / y)) / x)); elseif (y <= 10000.0) tmp = (x - y) * ((x + y) / ((x * 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.85e-162], N[(1.0 + N[(-2.0 * N[(N[(y / N[(x / y), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 10000.0], N[(N[(x - y), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.85 \cdot 10^{-162}:\\
\;\;\;\;1 + -2 \cdot \frac{\frac{y}{\frac{x}{y}}}{x}\\
\mathbf{elif}\;y \leq 10000:\\
\;\;\;\;\left(x - y\right) \cdot \frac{x + y}{x \cdot x + y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.8500000000000001e-162Initial program 57.1%
+-commutative57.1%
+-commutative57.1%
associate-*r/58.3%
+-commutative58.3%
+-commutative58.3%
fma-def58.3%
Simplified58.3%
Taylor expanded in y around 0 26.6%
unpow226.6%
unpow226.6%
Simplified26.6%
*-un-lft-identity26.6%
times-frac37.5%
Applied egg-rr37.5%
associate-*l/37.5%
*-lft-identity37.5%
associate-/l*38.5%
Simplified38.5%
if 1.8500000000000001e-162 < y < 1e4Initial program 99.8%
+-commutative99.8%
+-commutative99.8%
associate-*r/96.8%
+-commutative96.8%
+-commutative96.8%
fma-def96.8%
Simplified96.8%
fma-def96.8%
+-commutative96.8%
Applied egg-rr96.8%
if 1e4 < y Initial program 66.0%
+-commutative66.0%
+-commutative66.0%
associate-*r/66.3%
+-commutative66.3%
+-commutative66.3%
fma-def66.3%
Simplified66.3%
Taylor expanded in x around 0 65.0%
Final simplification50.5%
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(if (<= y 2.3e-162)
1.0
(if (or (<= y 1.1e-132) (not (<= y 3.8e-101)))
(+ -1.0 (/ (* x x) (* y y)))
(/ (- x y) x))))y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 2.3e-162) {
tmp = 1.0;
} else if ((y <= 1.1e-132) || !(y <= 3.8e-101)) {
tmp = -1.0 + ((x * x) / (y * y));
} else {
tmp = (x - y) / 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 <= 2.3d-162) then
tmp = 1.0d0
else if ((y <= 1.1d-132) .or. (.not. (y <= 3.8d-101))) then
tmp = (-1.0d0) + ((x * x) / (y * y))
else
tmp = (x - y) / x
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if (y <= 2.3e-162) {
tmp = 1.0;
} else if ((y <= 1.1e-132) || !(y <= 3.8e-101)) {
tmp = -1.0 + ((x * x) / (y * y));
} else {
tmp = (x - y) / x;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 2.3e-162: tmp = 1.0 elif (y <= 1.1e-132) or not (y <= 3.8e-101): tmp = -1.0 + ((x * x) / (y * y)) else: tmp = (x - y) / x return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 2.3e-162) tmp = 1.0; elseif ((y <= 1.1e-132) || !(y <= 3.8e-101)) tmp = Float64(-1.0 + Float64(Float64(x * x) / Float64(y * y))); else tmp = Float64(Float64(x - y) / x); end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.3e-162) tmp = 1.0; elseif ((y <= 1.1e-132) || ~((y <= 3.8e-101))) tmp = -1.0 + ((x * x) / (y * y)); else tmp = (x - y) / x; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 2.3e-162], 1.0, If[Or[LessEqual[y, 1.1e-132], N[Not[LessEqual[y, 3.8e-101]], $MachinePrecision]], N[(-1.0 + N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.3 \cdot 10^{-162}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-132} \lor \neg \left(y \leq 3.8 \cdot 10^{-101}\right):\\
\;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y}{x}\\
\end{array}
\end{array}
if y < 2.2999999999999998e-162Initial program 57.1%
+-commutative57.1%
+-commutative57.1%
associate-*r/58.3%
+-commutative58.3%
+-commutative58.3%
fma-def58.3%
Simplified58.3%
Taylor expanded in x around inf 36.3%
if 2.2999999999999998e-162 < y < 1.09999999999999995e-132 or 3.8000000000000001e-101 < y Initial program 99.9%
+-commutative99.9%
+-commutative99.9%
associate-*r/96.2%
+-commutative96.2%
+-commutative96.2%
fma-def96.2%
Simplified96.2%
Taylor expanded in x around 0 81.8%
unpow281.8%
Simplified81.8%
Taylor expanded in x around 0 85.5%
sub-neg85.5%
metadata-eval85.5%
unpow285.5%
unpow285.5%
Simplified85.5%
if 1.09999999999999995e-132 < y < 3.8000000000000001e-101Initial program 99.6%
associate-/l*99.7%
+-commutative99.7%
remove-double-neg99.7%
sub-neg99.7%
+-commutative99.7%
fma-def99.7%
sub-neg99.7%
remove-double-neg99.7%
Simplified99.7%
Taylor expanded in x around inf 58.9%
Final simplification45.4%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 1.45e-111) (+ 1.0 (* -2.0 (/ (/ y (/ x y)) x))) (/ (- x y) (+ (/ (* x x) y) (- y x)))))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 1.45e-111) {
tmp = 1.0 + (-2.0 * ((y / (x / y)) / x));
} else {
tmp = (x - y) / (((x * x) / y) + (y - 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.45d-111) then
tmp = 1.0d0 + ((-2.0d0) * ((y / (x / y)) / x))
else
tmp = (x - y) / (((x * x) / y) + (y - x))
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if (y <= 1.45e-111) {
tmp = 1.0 + (-2.0 * ((y / (x / y)) / x));
} else {
tmp = (x - y) / (((x * x) / y) + (y - x));
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 1.45e-111: tmp = 1.0 + (-2.0 * ((y / (x / y)) / x)) else: tmp = (x - y) / (((x * x) / y) + (y - x)) return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 1.45e-111) tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / Float64(x / y)) / x))); else tmp = Float64(Float64(x - y) / Float64(Float64(Float64(x * x) / y) + Float64(y - x))); end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.45e-111) tmp = 1.0 + (-2.0 * ((y / (x / y)) / x)); else tmp = (x - y) / (((x * x) / y) + (y - x)); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 1.45e-111], N[(1.0 + N[(-2.0 * N[(N[(y / N[(x / y), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] / N[(N[(N[(x * x), $MachinePrecision] / y), $MachinePrecision] + N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.45 \cdot 10^{-111}:\\
\;\;\;\;1 + -2 \cdot \frac{\frac{y}{\frac{x}{y}}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y}{\frac{x \cdot x}{y} + \left(y - x\right)}\\
\end{array}
\end{array}
if y < 1.45000000000000001e-111Initial program 60.0%
+-commutative60.0%
+-commutative60.0%
associate-*r/60.4%
+-commutative60.4%
+-commutative60.4%
fma-def60.4%
Simplified60.4%
Taylor expanded in y around 0 27.7%
unpow227.7%
unpow227.7%
Simplified27.7%
*-un-lft-identity27.7%
times-frac37.9%
Applied egg-rr37.9%
associate-*l/37.9%
*-lft-identity37.9%
associate-/l*38.8%
Simplified38.8%
if 1.45000000000000001e-111 < y Initial program 99.9%
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 83.8%
unpow283.7%
Simplified83.8%
Taylor expanded in y around inf 84.2%
+-commutative84.2%
neg-mul-184.2%
+-commutative84.2%
associate-+l+84.2%
unpow284.2%
+-commutative84.2%
sub-neg84.2%
Simplified84.2%
Final simplification45.5%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 1.45e-111) (+ 1.0 (* -2.0 (/ (/ y (/ x y)) x))) (+ -1.0 (/ (* x x) (* y y)))))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 1.45e-111) {
tmp = 1.0 + (-2.0 * ((y / (x / y)) / x));
} else {
tmp = -1.0 + ((x * 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 <= 1.45d-111) then
tmp = 1.0d0 + ((-2.0d0) * ((y / (x / y)) / x))
else
tmp = (-1.0d0) + ((x * 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 <= 1.45e-111) {
tmp = 1.0 + (-2.0 * ((y / (x / y)) / x));
} else {
tmp = -1.0 + ((x * x) / (y * y));
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 1.45e-111: tmp = 1.0 + (-2.0 * ((y / (x / y)) / x)) else: tmp = -1.0 + ((x * x) / (y * y)) return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 1.45e-111) tmp = Float64(1.0 + Float64(-2.0 * Float64(Float64(y / Float64(x / y)) / x))); else tmp = Float64(-1.0 + Float64(Float64(x * x) / Float64(y * y))); end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.45e-111) tmp = 1.0 + (-2.0 * ((y / (x / y)) / x)); else tmp = -1.0 + ((x * x) / (y * y)); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 1.45e-111], N[(1.0 + N[(-2.0 * N[(N[(y / N[(x / y), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.45 \cdot 10^{-111}:\\
\;\;\;\;1 + -2 \cdot \frac{\frac{y}{\frac{x}{y}}}{x}\\
\mathbf{else}:\\
\;\;\;\;-1 + \frac{x \cdot x}{y \cdot y}\\
\end{array}
\end{array}
if y < 1.45000000000000001e-111Initial program 60.0%
+-commutative60.0%
+-commutative60.0%
associate-*r/60.4%
+-commutative60.4%
+-commutative60.4%
fma-def60.4%
Simplified60.4%
Taylor expanded in y around 0 27.7%
unpow227.7%
unpow227.7%
Simplified27.7%
*-un-lft-identity27.7%
times-frac37.9%
Applied egg-rr37.9%
associate-*l/37.9%
*-lft-identity37.9%
associate-/l*38.8%
Simplified38.8%
if 1.45000000000000001e-111 < y Initial program 99.9%
+-commutative99.9%
+-commutative99.9%
associate-*r/99.6%
+-commutative99.6%
+-commutative99.6%
fma-def99.6%
Simplified99.6%
Taylor expanded in x around 0 83.7%
unpow283.7%
Simplified83.7%
Taylor expanded in x around 0 84.0%
sub-neg84.0%
metadata-eval84.0%
unpow284.0%
unpow284.0%
Simplified84.0%
Final simplification45.5%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 1.95e-162) 1.0 (if (<= y 1e-132) -1.0 (if (<= y 2e-111) 1.0 -1.0))))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 1.95e-162) {
tmp = 1.0;
} else if (y <= 1e-132) {
tmp = -1.0;
} else if (y <= 2e-111) {
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 <= 1.95d-162) then
tmp = 1.0d0
else if (y <= 1d-132) then
tmp = -1.0d0
else if (y <= 2d-111) 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 <= 1.95e-162) {
tmp = 1.0;
} else if (y <= 1e-132) {
tmp = -1.0;
} else if (y <= 2e-111) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 1.95e-162: tmp = 1.0 elif y <= 1e-132: tmp = -1.0 elif y <= 2e-111: tmp = 1.0 else: tmp = -1.0 return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 1.95e-162) tmp = 1.0; elseif (y <= 1e-132) tmp = -1.0; elseif (y <= 2e-111) 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 <= 1.95e-162) tmp = 1.0; elseif (y <= 1e-132) tmp = -1.0; elseif (y <= 2e-111) 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, 1.95e-162], 1.0, If[LessEqual[y, 1e-132], -1.0, If[LessEqual[y, 2e-111], 1.0, -1.0]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.95 \cdot 10^{-162}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 10^{-132}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-111}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.95e-162 or 9.9999999999999999e-133 < y < 2.00000000000000018e-111Initial program 58.3%
+-commutative58.3%
+-commutative58.3%
associate-*r/59.5%
+-commutative59.5%
+-commutative59.5%
fma-def59.5%
Simplified59.5%
Taylor expanded in x around inf 36.7%
if 1.95e-162 < y < 9.9999999999999999e-133 or 2.00000000000000018e-111 < y Initial program 99.9%
+-commutative99.9%
+-commutative99.9%
associate-*r/96.5%
+-commutative96.5%
+-commutative96.5%
fma-def96.5%
Simplified96.5%
Taylor expanded in x around 0 79.7%
Final simplification44.6%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 3.7e-101) (/ (- x y) x) -1.0))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 3.7e-101) {
tmp = (x - y) / x;
} 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 <= 3.7d-101) then
tmp = (x - y) / x
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 <= 3.7e-101) {
tmp = (x - y) / x;
} else {
tmp = -1.0;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 3.7e-101: tmp = (x - y) / x else: tmp = -1.0 return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 3.7e-101) tmp = Float64(Float64(x - y) / x); else tmp = -1.0; end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.7e-101) tmp = (x - y) / x; else tmp = -1.0; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 3.7e-101], N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision], -1.0]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.7 \cdot 10^{-101}:\\
\;\;\;\;\frac{x - y}{x}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 3.70000000000000005e-101Initial program 60.9%
associate-/l*61.5%
+-commutative61.5%
remove-double-neg61.5%
sub-neg61.5%
+-commutative61.5%
fma-def61.5%
sub-neg61.5%
remove-double-neg61.5%
Simplified61.5%
Taylor expanded in x around inf 36.0%
if 3.70000000000000005e-101 < y Initial program 99.9%
+-commutative99.9%
+-commutative99.9%
associate-*r/99.6%
+-commutative99.6%
+-commutative99.6%
fma-def99.7%
Simplified99.7%
Taylor expanded in x around 0 89.0%
Final simplification42.8%
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 66.0%
+-commutative66.0%
+-commutative66.0%
associate-*r/66.3%
+-commutative66.3%
+-commutative66.3%
fma-def66.3%
Simplified66.3%
Taylor expanded in x around 0 65.0%
Final simplification65.0%
(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 2023270
(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))))