
(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)) (/ (hypot x y) (- x y))))
double code(double x, double y) {
return ((x + y) / hypot(x, y)) / (hypot(x, y) / (x - y));
}
public static double code(double x, double y) {
return ((x + y) / Math.hypot(x, y)) / (Math.hypot(x, y) / (x - y));
}
def code(x, y): return ((x + y) / math.hypot(x, y)) / (math.hypot(x, y) / (x - y))
function code(x, y) return Float64(Float64(Float64(x + y) / hypot(x, y)) / Float64(hypot(x, y) / Float64(x - y))) end
function tmp = code(x, y) tmp = ((x + y) / hypot(x, y)) / (hypot(x, y) / (x - y)); end
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}
\\
\frac{\frac{x + y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x - y}}
\end{array}
Initial program 66.4%
add-sqr-sqrt66.4%
times-frac66.9%
hypot-def67.0%
hypot-def100.0%
Applied egg-rr100.0%
*-commutative100.0%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
Final simplification100.0%
(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 66.4%
add-sqr-sqrt66.4%
times-frac66.9%
hypot-def67.0%
hypot-def100.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 (* (/ (- x y) (hypot 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 = ((x - y) / hypot(x, y)) * ((x / y) + 1.0);
}
return tmp;
}
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) / Math.hypot(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 = ((x - y) / math.hypot(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(Float64(x - y) / hypot(x, y)) * Float64(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 = ((x - y) / hypot(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[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $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}:\\
\;\;\;\;\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(\frac{x}{y} + 1\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%
add-sqr-sqrt0.0%
times-frac3.1%
hypot-def3.1%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 6.7%
+-commutative6.7%
Simplified6.7%
Final simplification68.7%
(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) 1.0) (+ (/ 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 = ((x / y) + 1.0) * ((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 = ((x / y) + 1.0d0) * ((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 = ((x / y) + 1.0) * ((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 = ((x / y) + 1.0) * ((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(Float64(x / y) + 1.0) * Float64(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 = ((x / y) + 1.0) * ((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[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $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}:\\
\;\;\;\;\left(\frac{x}{y} + 1\right) \cdot \left(\frac{x}{y} + -1\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%
add-sqr-sqrt0.0%
times-frac3.1%
hypot-def3.1%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 6.7%
+-commutative6.7%
Simplified6.7%
Taylor expanded in x around 0 85.6%
Final simplification95.2%
(FPCore (x y)
:precision binary64
(if (<= y 3.7e-206)
(* (- 1.0 (/ y x)) (+ 1.0 (/ y x)))
(if (or (<= y 6.5e-151) (not (<= y 1.7e-146)))
(* (+ (/ x y) 1.0) (+ (/ x y) -1.0))
1.0)))
double code(double x, double y) {
double tmp;
if (y <= 3.7e-206) {
tmp = (1.0 - (y / x)) * (1.0 + (y / x));
} else if ((y <= 6.5e-151) || !(y <= 1.7e-146)) {
tmp = ((x / y) + 1.0) * ((x / y) + -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 <= 3.7d-206) then
tmp = (1.0d0 - (y / x)) * (1.0d0 + (y / x))
else if ((y <= 6.5d-151) .or. (.not. (y <= 1.7d-146))) then
tmp = ((x / y) + 1.0d0) * ((x / y) + (-1.0d0))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.7e-206) {
tmp = (1.0 - (y / x)) * (1.0 + (y / x));
} else if ((y <= 6.5e-151) || !(y <= 1.7e-146)) {
tmp = ((x / y) + 1.0) * ((x / y) + -1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.7e-206: tmp = (1.0 - (y / x)) * (1.0 + (y / x)) elif (y <= 6.5e-151) or not (y <= 1.7e-146): tmp = ((x / y) + 1.0) * ((x / y) + -1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 3.7e-206) tmp = Float64(Float64(1.0 - Float64(y / x)) * Float64(1.0 + Float64(y / x))); elseif ((y <= 6.5e-151) || !(y <= 1.7e-146)) tmp = Float64(Float64(Float64(x / y) + 1.0) * Float64(Float64(x / y) + -1.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.7e-206) tmp = (1.0 - (y / x)) * (1.0 + (y / x)); elseif ((y <= 6.5e-151) || ~((y <= 1.7e-146))) tmp = ((x / y) + 1.0) * ((x / y) + -1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.7e-206], N[(N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 6.5e-151], N[Not[LessEqual[y, 1.7e-146]], $MachinePrecision]], N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.7 \cdot 10^{-206}:\\
\;\;\;\;\left(1 - \frac{y}{x}\right) \cdot \left(1 + \frac{y}{x}\right)\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-151} \lor \neg \left(y \leq 1.7 \cdot 10^{-146}\right):\\
\;\;\;\;\left(\frac{x}{y} + 1\right) \cdot \left(\frac{x}{y} + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < 3.69999999999999998e-206Initial program 61.0%
add-sqr-sqrt61.0%
times-frac61.7%
hypot-def61.7%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 25.8%
mul-1-neg25.8%
unsub-neg25.8%
Simplified25.8%
Taylor expanded in x around inf 25.2%
if 3.69999999999999998e-206 < y < 6.4999999999999994e-151 or 1.7e-146 < y Initial program 92.3%
add-sqr-sqrt92.2%
times-frac92.3%
hypot-def92.3%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 91.5%
+-commutative91.5%
Simplified91.5%
Taylor expanded in x around 0 91.4%
if 6.4999999999999994e-151 < y < 1.7e-146Initial program 100.0%
Taylor expanded in x around inf 100.0%
Final simplification36.4%
(FPCore (x y)
:precision binary64
(if (<= y 3.5e-205)
(+ 1.0 (- (* (/ y x) (- 1.0 (/ y x))) (/ y x)))
(if (or (<= y 7.8e-151) (not (<= y 1.14e-147)))
(* (+ (/ x y) 1.0) (+ (/ x y) -1.0))
1.0)))
double code(double x, double y) {
double tmp;
if (y <= 3.5e-205) {
tmp = 1.0 + (((y / x) * (1.0 - (y / x))) - (y / x));
} else if ((y <= 7.8e-151) || !(y <= 1.14e-147)) {
tmp = ((x / y) + 1.0) * ((x / y) + -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 <= 3.5d-205) then
tmp = 1.0d0 + (((y / x) * (1.0d0 - (y / x))) - (y / x))
else if ((y <= 7.8d-151) .or. (.not. (y <= 1.14d-147))) then
tmp = ((x / y) + 1.0d0) * ((x / y) + (-1.0d0))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.5e-205) {
tmp = 1.0 + (((y / x) * (1.0 - (y / x))) - (y / x));
} else if ((y <= 7.8e-151) || !(y <= 1.14e-147)) {
tmp = ((x / y) + 1.0) * ((x / y) + -1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.5e-205: tmp = 1.0 + (((y / x) * (1.0 - (y / x))) - (y / x)) elif (y <= 7.8e-151) or not (y <= 1.14e-147): tmp = ((x / y) + 1.0) * ((x / y) + -1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 3.5e-205) tmp = Float64(1.0 + Float64(Float64(Float64(y / x) * Float64(1.0 - Float64(y / x))) - Float64(y / x))); elseif ((y <= 7.8e-151) || !(y <= 1.14e-147)) tmp = Float64(Float64(Float64(x / y) + 1.0) * Float64(Float64(x / y) + -1.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.5e-205) tmp = 1.0 + (((y / x) * (1.0 - (y / x))) - (y / x)); elseif ((y <= 7.8e-151) || ~((y <= 1.14e-147))) tmp = ((x / y) + 1.0) * ((x / y) + -1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.5e-205], N[(1.0 + N[(N[(N[(y / x), $MachinePrecision] * N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 7.8e-151], N[Not[LessEqual[y, 1.14e-147]], $MachinePrecision]], N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.5 \cdot 10^{-205}:\\
\;\;\;\;1 + \left(\frac{y}{x} \cdot \left(1 - \frac{y}{x}\right) - \frac{y}{x}\right)\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{-151} \lor \neg \left(y \leq 1.14 \cdot 10^{-147}\right):\\
\;\;\;\;\left(\frac{x}{y} + 1\right) \cdot \left(\frac{x}{y} + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < 3.5e-205Initial program 61.0%
add-sqr-sqrt61.0%
times-frac61.7%
hypot-def61.7%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 25.8%
mul-1-neg25.8%
unsub-neg25.8%
Simplified25.8%
Taylor expanded in x around inf 25.2%
distribute-rgt-in24.5%
*-un-lft-identity24.5%
associate-+l-24.5%
Applied egg-rr24.5%
if 3.5e-205 < y < 7.80000000000000013e-151 or 1.14e-147 < y Initial program 92.3%
add-sqr-sqrt92.2%
times-frac92.3%
hypot-def92.3%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 91.5%
+-commutative91.5%
Simplified91.5%
Taylor expanded in x around 0 91.4%
if 7.80000000000000013e-151 < y < 1.14e-147Initial program 100.0%
Taylor expanded in x around inf 100.0%
Final simplification35.9%
(FPCore (x y) :precision binary64 (if (<= y 3.3e-205) (* (- 1.0 (/ y x)) (+ 1.0 (/ y x))) (if (<= y 7.1e-152) -1.0 (if (<= y 1e-147) 1.0 -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 3.3e-205) {
tmp = (1.0 - (y / x)) * (1.0 + (y / x));
} else if (y <= 7.1e-152) {
tmp = -1.0;
} else if (y <= 1e-147) {
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 <= 3.3d-205) then
tmp = (1.0d0 - (y / x)) * (1.0d0 + (y / x))
else if (y <= 7.1d-152) then
tmp = -1.0d0
else if (y <= 1d-147) 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 <= 3.3e-205) {
tmp = (1.0 - (y / x)) * (1.0 + (y / x));
} else if (y <= 7.1e-152) {
tmp = -1.0;
} else if (y <= 1e-147) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.3e-205: tmp = (1.0 - (y / x)) * (1.0 + (y / x)) elif y <= 7.1e-152: tmp = -1.0 elif y <= 1e-147: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 3.3e-205) tmp = Float64(Float64(1.0 - Float64(y / x)) * Float64(1.0 + Float64(y / x))); elseif (y <= 7.1e-152) tmp = -1.0; elseif (y <= 1e-147) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.3e-205) tmp = (1.0 - (y / x)) * (1.0 + (y / x)); elseif (y <= 7.1e-152) tmp = -1.0; elseif (y <= 1e-147) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.3e-205], N[(N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.1e-152], -1.0, If[LessEqual[y, 1e-147], 1.0, -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.3 \cdot 10^{-205}:\\
\;\;\;\;\left(1 - \frac{y}{x}\right) \cdot \left(1 + \frac{y}{x}\right)\\
\mathbf{elif}\;y \leq 7.1 \cdot 10^{-152}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 10^{-147}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 3.2999999999999999e-205Initial program 61.0%
add-sqr-sqrt61.0%
times-frac61.7%
hypot-def61.7%
hypot-def100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 25.8%
mul-1-neg25.8%
unsub-neg25.8%
Simplified25.8%
Taylor expanded in x around inf 25.2%
if 3.2999999999999999e-205 < y < 7.10000000000000011e-152 or 9.9999999999999997e-148 < y Initial program 92.3%
Taylor expanded in x around 0 91.0%
if 7.10000000000000011e-152 < y < 9.9999999999999997e-148Initial program 100.0%
Taylor expanded in x around inf 100.0%
Final simplification36.4%
(FPCore (x y) :precision binary64 (if (<= y 3.3e-205) 1.0 (if (<= y 2.2e-151) -1.0 (if (<= y 1.2e-146) 1.0 -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 3.3e-205) {
tmp = 1.0;
} else if (y <= 2.2e-151) {
tmp = -1.0;
} else if (y <= 1.2e-146) {
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 <= 3.3d-205) then
tmp = 1.0d0
else if (y <= 2.2d-151) then
tmp = -1.0d0
else if (y <= 1.2d-146) 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 <= 3.3e-205) {
tmp = 1.0;
} else if (y <= 2.2e-151) {
tmp = -1.0;
} else if (y <= 1.2e-146) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.3e-205: tmp = 1.0 elif y <= 2.2e-151: tmp = -1.0 elif y <= 1.2e-146: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 3.3e-205) tmp = 1.0; elseif (y <= 2.2e-151) tmp = -1.0; elseif (y <= 1.2e-146) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.3e-205) tmp = 1.0; elseif (y <= 2.2e-151) tmp = -1.0; elseif (y <= 1.2e-146) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.3e-205], 1.0, If[LessEqual[y, 2.2e-151], -1.0, If[LessEqual[y, 1.2e-146], 1.0, -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.3 \cdot 10^{-205}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-151}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{-146}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 3.2999999999999999e-205 or 2.1999999999999999e-151 < y < 1.2000000000000001e-146Initial program 61.8%
Taylor expanded in x around inf 24.7%
if 3.2999999999999999e-205 < y < 2.1999999999999999e-151 or 1.2000000000000001e-146 < y Initial program 92.3%
Taylor expanded in x around 0 91.0%
Final simplification34.8%
(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 66.4%
Taylor expanded in x around 0 78.6%
Final simplification78.6%
(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 2023322
(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))))