
(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}
(FPCore (x y) :precision binary64 (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y))))
double code(double x, double y) {
return ((x - y) / hypot(x, y)) * ((x + y) / hypot(x, y));
}
public static double code(double x, double y) {
return ((x - y) / Math.hypot(x, y)) * ((x + y) / Math.hypot(x, y));
}
def code(x, y): return ((x - y) / math.hypot(x, y)) * ((x + y) / math.hypot(x, y))
function code(x, y) return Float64(Float64(Float64(x - y) / hypot(x, y)) * Float64(Float64(x + y) / hypot(x, y))) end
function tmp = code(x, y) tmp = ((x - y) / hypot(x, y)) * ((x + y) / hypot(x, y)); end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}
\end{array}
Initial program 67.2%
add-sqr-sqrt67.2%
times-frac67.0%
hypot-define67.1%
hypot-define100.0%
Applied egg-rr100.0%
Final simplification100.0%
(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) (/ x y))) -1.0))))
double code(double x, double y) {
double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = (2.0 * ((x / y) * (x / y))) + -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) * (x / y))) + (-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) * (x / y))) + -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) * (x / y))) + -1.0 return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y))) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(Float64(2.0 * Float64(Float64(x / y) * Float64(x / y))) + -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) * (x / y))) + -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[(x / y), $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 \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -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%
associate-/l*3.1%
+-commutative3.1%
fma-define3.1%
Simplified3.1%
Taylor expanded in x around 0 52.4%
unpow252.4%
unpow252.4%
frac-times78.8%
Applied egg-rr78.8%
Final simplification93.0%
(FPCore (x y)
:precision binary64
(if (<= y 9.8e-178)
1.0
(if (or (<= y 1.05e-148) (not (<= y 1.1e-116)))
(* (- x y) (/ (+ (/ x y) 1.0) y))
1.0)))
double code(double x, double y) {
double tmp;
if (y <= 9.8e-178) {
tmp = 1.0;
} else if ((y <= 1.05e-148) || !(y <= 1.1e-116)) {
tmp = (x - y) * (((x / y) + 1.0) / 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 <= 9.8d-178) then
tmp = 1.0d0
else if ((y <= 1.05d-148) .or. (.not. (y <= 1.1d-116))) then
tmp = (x - y) * (((x / y) + 1.0d0) / y)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 9.8e-178) {
tmp = 1.0;
} else if ((y <= 1.05e-148) || !(y <= 1.1e-116)) {
tmp = (x - y) * (((x / y) + 1.0) / y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 9.8e-178: tmp = 1.0 elif (y <= 1.05e-148) or not (y <= 1.1e-116): tmp = (x - y) * (((x / y) + 1.0) / y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 9.8e-178) tmp = 1.0; elseif ((y <= 1.05e-148) || !(y <= 1.1e-116)) tmp = Float64(Float64(x - y) * Float64(Float64(Float64(x / y) + 1.0) / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 9.8e-178) tmp = 1.0; elseif ((y <= 1.05e-148) || ~((y <= 1.1e-116))) tmp = (x - y) * (((x / y) + 1.0) / y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 9.8e-178], 1.0, If[Or[LessEqual[y, 1.05e-148], N[Not[LessEqual[y, 1.1e-116]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.8 \cdot 10^{-178}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-148} \lor \neg \left(y \leq 1.1 \cdot 10^{-116}\right):\\
\;\;\;\;\left(x - y\right) \cdot \frac{\frac{x}{y} + 1}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < 9.80000000000000041e-178 or 1.05e-148 < y < 1.10000000000000005e-116Initial program 63.9%
associate-/l*63.7%
+-commutative63.7%
fma-define63.7%
Simplified63.7%
Taylor expanded in x around inf 41.6%
if 9.80000000000000041e-178 < y < 1.05e-148 or 1.10000000000000005e-116 < y Initial program 88.2%
associate-/l*86.9%
+-commutative86.9%
fma-define86.9%
Simplified86.9%
Taylor expanded in y around inf 86.3%
Final simplification47.5%
(FPCore (x y) :precision binary64 (if (or (<= y 1.05e-177) (and (not (<= y 6.5e-152)) (<= y 1.2e-118))) (* (- x y) (/ (+ 1.0 (/ y x)) x)) (* (- x y) (/ (+ (/ x y) 1.0) y))))
double code(double x, double y) {
double tmp;
if ((y <= 1.05e-177) || (!(y <= 6.5e-152) && (y <= 1.2e-118))) {
tmp = (x - y) * ((1.0 + (y / x)) / x);
} else {
tmp = (x - y) * (((x / y) + 1.0) / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= 1.05d-177) .or. (.not. (y <= 6.5d-152)) .and. (y <= 1.2d-118)) then
tmp = (x - y) * ((1.0d0 + (y / x)) / x)
else
tmp = (x - y) * (((x / y) + 1.0d0) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 1.05e-177) || (!(y <= 6.5e-152) && (y <= 1.2e-118))) {
tmp = (x - y) * ((1.0 + (y / x)) / x);
} else {
tmp = (x - y) * (((x / y) + 1.0) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 1.05e-177) or (not (y <= 6.5e-152) and (y <= 1.2e-118)): tmp = (x - y) * ((1.0 + (y / x)) / x) else: tmp = (x - y) * (((x / y) + 1.0) / y) return tmp
function code(x, y) tmp = 0.0 if ((y <= 1.05e-177) || (!(y <= 6.5e-152) && (y <= 1.2e-118))) tmp = Float64(Float64(x - y) * Float64(Float64(1.0 + Float64(y / x)) / x)); else tmp = Float64(Float64(x - y) * Float64(Float64(Float64(x / y) + 1.0) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 1.05e-177) || (~((y <= 6.5e-152)) && (y <= 1.2e-118))) tmp = (x - y) * ((1.0 + (y / x)) / x); else tmp = (x - y) * (((x / y) + 1.0) / y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 1.05e-177], And[N[Not[LessEqual[y, 6.5e-152]], $MachinePrecision], LessEqual[y, 1.2e-118]]], N[(N[(x - y), $MachinePrecision] * N[(N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.05 \cdot 10^{-177} \lor \neg \left(y \leq 6.5 \cdot 10^{-152}\right) \land y \leq 1.2 \cdot 10^{-118}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{1 + \frac{y}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{\frac{x}{y} + 1}{y}\\
\end{array}
\end{array}
if y < 1.05e-177 or 6.5000000000000001e-152 < y < 1.2000000000000001e-118Initial program 64.1%
associate-/l*63.8%
+-commutative63.8%
fma-define63.8%
Simplified63.8%
Taylor expanded in x around inf 42.8%
if 1.05e-177 < y < 6.5000000000000001e-152 or 1.2000000000000001e-118 < y Initial program 87.9%
associate-/l*86.5%
+-commutative86.5%
fma-define86.5%
Simplified86.5%
Taylor expanded in y around inf 85.9%
Final simplification48.3%
(FPCore (x y) :precision binary64 (if (or (<= y 8.5e-178) (and (not (<= y 1.55e-154)) (<= y 3.4e-119))) (* (/ (- x y) x) (+ 1.0 (/ y x))) (* (- x y) (/ (+ (/ x y) 1.0) y))))
double code(double x, double y) {
double tmp;
if ((y <= 8.5e-178) || (!(y <= 1.55e-154) && (y <= 3.4e-119))) {
tmp = ((x - y) / x) * (1.0 + (y / x));
} else {
tmp = (x - y) * (((x / y) + 1.0) / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= 8.5d-178) .or. (.not. (y <= 1.55d-154)) .and. (y <= 3.4d-119)) then
tmp = ((x - y) / x) * (1.0d0 + (y / x))
else
tmp = (x - y) * (((x / y) + 1.0d0) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 8.5e-178) || (!(y <= 1.55e-154) && (y <= 3.4e-119))) {
tmp = ((x - y) / x) * (1.0 + (y / x));
} else {
tmp = (x - y) * (((x / y) + 1.0) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 8.5e-178) or (not (y <= 1.55e-154) and (y <= 3.4e-119)): tmp = ((x - y) / x) * (1.0 + (y / x)) else: tmp = (x - y) * (((x / y) + 1.0) / y) return tmp
function code(x, y) tmp = 0.0 if ((y <= 8.5e-178) || (!(y <= 1.55e-154) && (y <= 3.4e-119))) tmp = Float64(Float64(Float64(x - y) / x) * Float64(1.0 + Float64(y / x))); else tmp = Float64(Float64(x - y) * Float64(Float64(Float64(x / y) + 1.0) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 8.5e-178) || (~((y <= 1.55e-154)) && (y <= 3.4e-119))) tmp = ((x - y) / x) * (1.0 + (y / x)); else tmp = (x - y) * (((x / y) + 1.0) / y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 8.5e-178], And[N[Not[LessEqual[y, 1.55e-154]], $MachinePrecision], LessEqual[y, 3.4e-119]]], N[(N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision] * N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.5 \cdot 10^{-178} \lor \neg \left(y \leq 1.55 \cdot 10^{-154}\right) \land y \leq 3.4 \cdot 10^{-119}:\\
\;\;\;\;\frac{x - y}{x} \cdot \left(1 + \frac{y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{\frac{x}{y} + 1}{y}\\
\end{array}
\end{array}
if y < 8.5000000000000001e-178 or 1.54999999999999991e-154 < y < 3.40000000000000024e-119Initial program 64.1%
associate-/l*63.8%
+-commutative63.8%
fma-define63.8%
Simplified63.8%
Taylor expanded in x around inf 42.8%
*-commutative42.8%
sub-neg42.8%
distribute-lft-in42.7%
Applied egg-rr42.7%
distribute-lft-out42.8%
sub-neg42.8%
/-rgt-identity42.8%
times-frac42.9%
*-commutative42.9%
times-frac42.9%
/-rgt-identity42.9%
Simplified42.9%
if 8.5000000000000001e-178 < y < 1.54999999999999991e-154 or 3.40000000000000024e-119 < y Initial program 87.9%
associate-/l*86.5%
+-commutative86.5%
fma-define86.5%
Simplified86.5%
Taylor expanded in y around inf 85.9%
Final simplification48.5%
(FPCore (x y) :precision binary64 (if (or (<= y 9.5e-178) (and (not (<= y 1.36e-148)) (<= y 3.8e-119))) (* (/ (- x y) x) (+ 1.0 (/ y x))) (+ (* 2.0 (* (/ x y) (/ x y))) -1.0)))
double code(double x, double y) {
double tmp;
if ((y <= 9.5e-178) || (!(y <= 1.36e-148) && (y <= 3.8e-119))) {
tmp = ((x - y) / x) * (1.0 + (y / x));
} else {
tmp = (2.0 * ((x / y) * (x / y))) + -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 <= 9.5d-178) .or. (.not. (y <= 1.36d-148)) .and. (y <= 3.8d-119)) then
tmp = ((x - y) / x) * (1.0d0 + (y / x))
else
tmp = (2.0d0 * ((x / y) * (x / y))) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 9.5e-178) || (!(y <= 1.36e-148) && (y <= 3.8e-119))) {
tmp = ((x - y) / x) * (1.0 + (y / x));
} else {
tmp = (2.0 * ((x / y) * (x / y))) + -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 9.5e-178) or (not (y <= 1.36e-148) and (y <= 3.8e-119)): tmp = ((x - y) / x) * (1.0 + (y / x)) else: tmp = (2.0 * ((x / y) * (x / y))) + -1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= 9.5e-178) || (!(y <= 1.36e-148) && (y <= 3.8e-119))) tmp = Float64(Float64(Float64(x - y) / x) * Float64(1.0 + Float64(y / x))); else tmp = Float64(Float64(2.0 * Float64(Float64(x / y) * Float64(x / y))) + -1.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 9.5e-178) || (~((y <= 1.36e-148)) && (y <= 3.8e-119))) tmp = ((x - y) / x) * (1.0 + (y / x)); else tmp = (2.0 * ((x / y) * (x / y))) + -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 9.5e-178], And[N[Not[LessEqual[y, 1.36e-148]], $MachinePrecision], LessEqual[y, 3.8e-119]]], N[(N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision] * N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.5 \cdot 10^{-178} \lor \neg \left(y \leq 1.36 \cdot 10^{-148}\right) \land y \leq 3.8 \cdot 10^{-119}:\\
\;\;\;\;\frac{x - y}{x} \cdot \left(1 + \frac{y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\
\end{array}
\end{array}
if y < 9.50000000000000009e-178 or 1.36e-148 < y < 3.79999999999999975e-119Initial program 63.9%
associate-/l*63.7%
+-commutative63.7%
fma-define63.7%
Simplified63.7%
Taylor expanded in x around inf 42.9%
*-commutative42.9%
sub-neg42.9%
distribute-lft-in42.8%
Applied egg-rr42.8%
distribute-lft-out42.9%
sub-neg42.9%
/-rgt-identity42.9%
times-frac43.1%
*-commutative43.1%
times-frac43.1%
/-rgt-identity43.1%
Simplified43.1%
if 9.50000000000000009e-178 < y < 1.36e-148 or 3.79999999999999975e-119 < y Initial program 88.2%
associate-/l*86.9%
+-commutative86.9%
fma-define86.9%
Simplified86.9%
Taylor expanded in x around 0 77.3%
unpow277.3%
unpow277.3%
frac-times86.5%
Applied egg-rr86.5%
Final simplification48.8%
(FPCore (x y) :precision binary64 (if (or (<= y 9.8e-178) (and (not (<= y 1.52e-148)) (<= y 3.6e-118))) (- 1.0 (/ (* (/ y x) (+ y y)) x)) (+ (* 2.0 (* (/ x y) (/ x y))) -1.0)))
double code(double x, double y) {
double tmp;
if ((y <= 9.8e-178) || (!(y <= 1.52e-148) && (y <= 3.6e-118))) {
tmp = 1.0 - (((y / x) * (y + y)) / x);
} else {
tmp = (2.0 * ((x / y) * (x / y))) + -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 <= 9.8d-178) .or. (.not. (y <= 1.52d-148)) .and. (y <= 3.6d-118)) then
tmp = 1.0d0 - (((y / x) * (y + y)) / x)
else
tmp = (2.0d0 * ((x / y) * (x / y))) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 9.8e-178) || (!(y <= 1.52e-148) && (y <= 3.6e-118))) {
tmp = 1.0 - (((y / x) * (y + y)) / x);
} else {
tmp = (2.0 * ((x / y) * (x / y))) + -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 9.8e-178) or (not (y <= 1.52e-148) and (y <= 3.6e-118)): tmp = 1.0 - (((y / x) * (y + y)) / x) else: tmp = (2.0 * ((x / y) * (x / y))) + -1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= 9.8e-178) || (!(y <= 1.52e-148) && (y <= 3.6e-118))) tmp = Float64(1.0 - Float64(Float64(Float64(y / x) * Float64(y + y)) / x)); else tmp = Float64(Float64(2.0 * Float64(Float64(x / y) * Float64(x / y))) + -1.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 9.8e-178) || (~((y <= 1.52e-148)) && (y <= 3.6e-118))) tmp = 1.0 - (((y / x) * (y + y)) / x); else tmp = (2.0 * ((x / y) * (x / y))) + -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 9.8e-178], And[N[Not[LessEqual[y, 1.52e-148]], $MachinePrecision], LessEqual[y, 3.6e-118]]], N[(1.0 - N[(N[(N[(y / x), $MachinePrecision] * N[(y + y), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.8 \cdot 10^{-178} \lor \neg \left(y \leq 1.52 \cdot 10^{-148}\right) \land y \leq 3.6 \cdot 10^{-118}:\\
\;\;\;\;1 - \frac{\frac{y}{x} \cdot \left(y + y\right)}{x}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right) + -1\\
\end{array}
\end{array}
if y < 9.80000000000000041e-178 or 1.52000000000000002e-148 < y < 3.6000000000000002e-118Initial program 63.9%
associate-/l*63.7%
+-commutative63.7%
fma-define63.7%
Simplified63.7%
*-commutative63.7%
sub-neg63.7%
distribute-lft-in63.4%
fma-undefine63.4%
+-commutative63.4%
add-sqr-sqrt63.4%
pow263.4%
hypot-define63.4%
Applied egg-rr63.4%
distribute-lft-out63.6%
sub-neg63.6%
associate-*l/63.9%
+-commutative63.9%
Simplified63.9%
Taylor expanded in x around -inf 43.0%
mul-1-neg43.0%
unsub-neg43.0%
Simplified43.5%
if 9.80000000000000041e-178 < y < 1.52000000000000002e-148 or 3.6000000000000002e-118 < y Initial program 88.2%
associate-/l*86.9%
+-commutative86.9%
fma-define86.9%
Simplified86.9%
Taylor expanded in x around 0 77.3%
unpow277.3%
unpow277.3%
frac-times86.5%
Applied egg-rr86.5%
Final simplification49.2%
(FPCore (x y) :precision binary64 (if (<= y 1e-177) 1.0 (if (<= y 2e-151) -1.0 (if (<= y 3.3e-103) 1.0 -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 1e-177) {
tmp = 1.0;
} else if (y <= 2e-151) {
tmp = -1.0;
} else if (y <= 3.3e-103) {
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 <= 1d-177) then
tmp = 1.0d0
else if (y <= 2d-151) then
tmp = -1.0d0
else if (y <= 3.3d-103) 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 <= 1e-177) {
tmp = 1.0;
} else if (y <= 2e-151) {
tmp = -1.0;
} else if (y <= 3.3e-103) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1e-177: tmp = 1.0 elif y <= 2e-151: tmp = -1.0 elif y <= 3.3e-103: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 1e-177) tmp = 1.0; elseif (y <= 2e-151) tmp = -1.0; elseif (y <= 3.3e-103) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1e-177) tmp = 1.0; elseif (y <= 2e-151) tmp = -1.0; elseif (y <= 3.3e-103) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1e-177], 1.0, If[LessEqual[y, 2e-151], -1.0, If[LessEqual[y, 3.3e-103], 1.0, -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 10^{-177}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-151}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{-103}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 9.99999999999999952e-178 or 1.9999999999999999e-151 < y < 3.2999999999999999e-103Initial program 64.4%
associate-/l*64.1%
+-commutative64.1%
fma-define64.1%
Simplified64.1%
Taylor expanded in x around inf 41.5%
if 9.99999999999999952e-178 < y < 1.9999999999999999e-151 or 3.2999999999999999e-103 < y Initial program 87.1%
associate-/l*85.7%
+-commutative85.7%
fma-define85.7%
Simplified85.7%
Taylor expanded in x around 0 87.3%
Final simplification47.0%
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
return -1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
public static double code(double x, double y) {
return -1.0;
}
def code(x, y): return -1.0
function code(x, y) return -1.0 end
function tmp = code(x, y) tmp = -1.0; end
code[x_, y_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 67.2%
associate-/l*66.8%
+-commutative66.8%
fma-define66.8%
Simplified66.8%
Taylor expanded in x around 0 62.3%
Final simplification62.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 2024079
(FPCore (x y)
:name "Kahan p9 Example"
:precision binary64
:pre (and (and (< 0.0 x) (< x 1.0)) (< y 1.0))
:alt
(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))))