
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+305) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (+ (/ b d) (* (/ c d) (/ a d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+305) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 5e+305) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+305], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+305}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5.00000000000000009e305Initial program 82.9%
*-un-lft-identity82.9%
add-sqr-sqrt82.9%
times-frac82.8%
hypot-def82.8%
fma-def82.8%
hypot-def98.1%
Applied egg-rr98.1%
if 5.00000000000000009e305 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 15.0%
Taylor expanded in c around 0 50.4%
*-commutative50.4%
unpow250.4%
times-frac60.1%
Simplified60.1%
Final simplification88.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= t_0 -5e-281)
t_0
(if (<= t_0 0.0)
(* (/ c (hypot c d)) (/ a (hypot c d)))
(if (<= t_0 5e+305) t_0 (+ (/ b d) (* (/ c d) (/ a d))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (t_0 <= -5e-281) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (c / hypot(c, d)) * (a / hypot(c, d));
} else if (t_0 <= 5e+305) {
tmp = t_0;
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (t_0 <= -5e-281) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (c / Math.hypot(c, d)) * (a / Math.hypot(c, d));
} else if (t_0 <= 5e+305) {
tmp = t_0;
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if t_0 <= -5e-281: tmp = t_0 elif t_0 <= 0.0: tmp = (c / math.hypot(c, d)) * (a / math.hypot(c, d)) elif t_0 <= 5e+305: tmp = t_0 else: tmp = (b / d) + ((c / d) * (a / d)) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (t_0 <= -5e-281) tmp = t_0; elseif (t_0 <= 0.0) tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(c, d))); elseif (t_0 <= 5e+305) tmp = t_0; else tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (t_0 <= -5e-281) tmp = t_0; elseif (t_0 <= 0.0) tmp = (c / hypot(c, d)) * (a / hypot(c, d)); elseif (t_0 <= 5e+305) tmp = t_0; else tmp = (b / d) + ((c / d) * (a / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-281], t$95$0, If[LessEqual[t$95$0, 0.0], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+305], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{-281}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+305}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -4.9999999999999998e-281 or -0.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5.00000000000000009e305Initial program 95.2%
if -4.9999999999999998e-281 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -0.0Initial program 64.1%
Taylor expanded in a around inf 64.1%
*-commutative64.1%
Simplified64.1%
add-sqr-sqrt64.1%
hypot-udef64.1%
hypot-udef64.1%
times-frac80.6%
Applied egg-rr80.6%
if 5.00000000000000009e305 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 15.0%
Taylor expanded in c around 0 50.4%
*-commutative50.4%
unpow250.4%
times-frac60.1%
Simplified60.1%
Final simplification82.2%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))) (if (<= t_0 5e+305) t_0 (+ (/ b d) (* (/ c d) (/ a d))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (t_0 <= 5e+305) {
tmp = t_0;
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (t_0 <= 5d+305) then
tmp = t_0
else
tmp = (b / d) + ((c / d) * (a / d))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (t_0 <= 5e+305) {
tmp = t_0;
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if t_0 <= 5e+305: tmp = t_0 else: tmp = (b / d) + ((c / d) * (a / d)) return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (t_0 <= 5e+305) tmp = t_0; else tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (t_0 <= 5e+305) tmp = t_0; else tmp = (b / d) + ((c / d) * (a / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e+305], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_0 \leq 5 \cdot 10^{+305}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5.00000000000000009e305Initial program 82.9%
if 5.00000000000000009e305 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 15.0%
Taylor expanded in c around 0 50.4%
*-commutative50.4%
unpow250.4%
times-frac60.1%
Simplified60.1%
Final simplification77.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.4e+39) (not (<= c 2.15e+46))) (+ (/ a c) (* (/ d c) (/ b c))) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.4e+39) || !(c <= 2.15e+46)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = b / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-2.4d+39)) .or. (.not. (c <= 2.15d+46))) then
tmp = (a / c) + ((d / c) * (b / c))
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.4e+39) || !(c <= 2.15e+46)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.4e+39) or not (c <= 2.15e+46): tmp = (a / c) + ((d / c) * (b / c)) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.4e+39) || !(c <= 2.15e+46)) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.4e+39) || ~((c <= 2.15e+46))) tmp = (a / c) + ((d / c) * (b / c)); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.4e+39], N[Not[LessEqual[c, 2.15e+46]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.4 \cdot 10^{+39} \lor \neg \left(c \leq 2.15 \cdot 10^{+46}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -2.4000000000000001e39 or 2.15000000000000002e46 < c Initial program 54.0%
Taylor expanded in c around inf 72.1%
*-commutative72.1%
unpow272.1%
times-frac80.9%
Simplified80.9%
if -2.4000000000000001e39 < c < 2.15000000000000002e46Initial program 76.9%
Taylor expanded in c around 0 64.6%
Final simplification72.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.4e+39) (not (<= c 1.3e+46))) (+ (/ a c) (/ (* d (/ b c)) c)) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.4e+39) || !(c <= 1.3e+46)) {
tmp = (a / c) + ((d * (b / c)) / c);
} else {
tmp = b / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-2.4d+39)) .or. (.not. (c <= 1.3d+46))) then
tmp = (a / c) + ((d * (b / c)) / c)
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.4e+39) || !(c <= 1.3e+46)) {
tmp = (a / c) + ((d * (b / c)) / c);
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.4e+39) or not (c <= 1.3e+46): tmp = (a / c) + ((d * (b / c)) / c) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.4e+39) || !(c <= 1.3e+46)) tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.4e+39) || ~((c <= 1.3e+46))) tmp = (a / c) + ((d * (b / c)) / c); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.4e+39], N[Not[LessEqual[c, 1.3e+46]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.4 \cdot 10^{+39} \lor \neg \left(c \leq 1.3 \cdot 10^{+46}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -2.4000000000000001e39 or 1.30000000000000007e46 < c Initial program 54.0%
Taylor expanded in c around inf 72.1%
*-commutative72.1%
unpow272.1%
times-frac80.9%
Simplified80.9%
associate-*l/81.8%
Applied egg-rr81.8%
if -2.4000000000000001e39 < c < 1.30000000000000007e46Initial program 76.9%
Taylor expanded in c around 0 64.6%
Final simplification72.7%
(FPCore (a b c d) :precision binary64 (if (<= c -1.02e-10) (+ (/ a c) (/ (* b (/ d c)) c)) (if (<= c 3.8e+46) (/ b d) (+ (/ a c) (/ (* d (/ b c)) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.02e-10) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (c <= 3.8e+46) {
tmp = b / d;
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-1.02d-10)) then
tmp = (a / c) + ((b * (d / c)) / c)
else if (c <= 3.8d+46) then
tmp = b / d
else
tmp = (a / c) + ((d * (b / c)) / c)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.02e-10) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (c <= 3.8e+46) {
tmp = b / d;
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.02e-10: tmp = (a / c) + ((b * (d / c)) / c) elif c <= 3.8e+46: tmp = b / d else: tmp = (a / c) + ((d * (b / c)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.02e-10) tmp = Float64(Float64(a / c) + Float64(Float64(b * Float64(d / c)) / c)); elseif (c <= 3.8e+46) tmp = Float64(b / d); else tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.02e-10) tmp = (a / c) + ((b * (d / c)) / c); elseif (c <= 3.8e+46) tmp = b / d; else tmp = (a / c) + ((d * (b / c)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.02e-10], N[(N[(a / c), $MachinePrecision] + N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.8e+46], N[(b / d), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.02 \cdot 10^{-10}:\\
\;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 3.8 \cdot 10^{+46}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -1.01999999999999997e-10Initial program 59.9%
Taylor expanded in c around inf 67.7%
*-commutative67.7%
unpow267.7%
times-frac77.3%
Simplified77.3%
associate-*r/78.7%
Applied egg-rr78.7%
if -1.01999999999999997e-10 < c < 3.7999999999999999e46Initial program 77.3%
Taylor expanded in c around 0 65.5%
if 3.7999999999999999e46 < c Initial program 49.2%
Taylor expanded in c around inf 74.7%
*-commutative74.7%
unpow274.7%
times-frac79.4%
Simplified79.4%
associate-*l/81.5%
Applied egg-rr81.5%
Final simplification72.8%
(FPCore (a b c d)
:precision binary64
(if (<= c -8.6e-11)
(+ (/ a c) (/ (* b (/ d c)) c))
(if (<= c 2.2e+47)
(+ (/ b d) (* c (/ (/ a d) d)))
(+ (/ a c) (/ (* d (/ b c)) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -8.6e-11) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (c <= 2.2e+47) {
tmp = (b / d) + (c * ((a / d) / d));
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-8.6d-11)) then
tmp = (a / c) + ((b * (d / c)) / c)
else if (c <= 2.2d+47) then
tmp = (b / d) + (c * ((a / d) / d))
else
tmp = (a / c) + ((d * (b / c)) / c)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -8.6e-11) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (c <= 2.2e+47) {
tmp = (b / d) + (c * ((a / d) / d));
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -8.6e-11: tmp = (a / c) + ((b * (d / c)) / c) elif c <= 2.2e+47: tmp = (b / d) + (c * ((a / d) / d)) else: tmp = (a / c) + ((d * (b / c)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -8.6e-11) tmp = Float64(Float64(a / c) + Float64(Float64(b * Float64(d / c)) / c)); elseif (c <= 2.2e+47) tmp = Float64(Float64(b / d) + Float64(c * Float64(Float64(a / d) / d))); else tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -8.6e-11) tmp = (a / c) + ((b * (d / c)) / c); elseif (c <= 2.2e+47) tmp = (b / d) + (c * ((a / d) / d)); else tmp = (a / c) + ((d * (b / c)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -8.6e-11], N[(N[(a / c), $MachinePrecision] + N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.2e+47], N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.6 \cdot 10^{-11}:\\
\;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{+47}:\\
\;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -8.60000000000000003e-11Initial program 59.9%
Taylor expanded in c around inf 67.7%
*-commutative67.7%
unpow267.7%
times-frac77.3%
Simplified77.3%
associate-*r/78.7%
Applied egg-rr78.7%
if -8.60000000000000003e-11 < c < 2.1999999999999999e47Initial program 77.4%
Taylor expanded in c around 0 81.1%
unpow281.1%
associate-/l*78.2%
Simplified78.2%
Taylor expanded in a around 0 81.1%
unpow281.1%
associate-*l/74.5%
*-commutative74.5%
associate-/r*76.4%
Simplified76.4%
if 2.1999999999999999e47 < c Initial program 48.3%
Taylor expanded in c around inf 76.0%
*-commutative76.0%
unpow276.0%
times-frac80.8%
Simplified80.8%
associate-*l/82.9%
Applied egg-rr82.9%
Final simplification78.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -3e-10)
(+ (/ a c) (/ (* b (/ d c)) c))
(if (<= c 3.5e+48)
(+ (/ b d) (* (/ c d) (/ a d)))
(+ (/ a c) (/ (* d (/ b c)) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3e-10) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (c <= 3.5e+48) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-3d-10)) then
tmp = (a / c) + ((b * (d / c)) / c)
else if (c <= 3.5d+48) then
tmp = (b / d) + ((c / d) * (a / d))
else
tmp = (a / c) + ((d * (b / c)) / c)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3e-10) {
tmp = (a / c) + ((b * (d / c)) / c);
} else if (c <= 3.5e+48) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + ((d * (b / c)) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -3e-10: tmp = (a / c) + ((b * (d / c)) / c) elif c <= 3.5e+48: tmp = (b / d) + ((c / d) * (a / d)) else: tmp = (a / c) + ((d * (b / c)) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -3e-10) tmp = Float64(Float64(a / c) + Float64(Float64(b * Float64(d / c)) / c)); elseif (c <= 3.5e+48) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); else tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -3e-10) tmp = (a / c) + ((b * (d / c)) / c); elseif (c <= 3.5e+48) tmp = (b / d) + ((c / d) * (a / d)); else tmp = (a / c) + ((d * (b / c)) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -3e-10], N[(N[(a / c), $MachinePrecision] + N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.5e+48], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-10}:\\
\;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq 3.5 \cdot 10^{+48}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\
\end{array}
\end{array}
if c < -3e-10Initial program 59.9%
Taylor expanded in c around inf 67.7%
*-commutative67.7%
unpow267.7%
times-frac77.3%
Simplified77.3%
associate-*r/78.7%
Applied egg-rr78.7%
if -3e-10 < c < 3.4999999999999997e48Initial program 77.4%
Taylor expanded in c around 0 81.1%
*-commutative81.1%
unpow281.1%
times-frac81.4%
Simplified81.4%
if 3.4999999999999997e48 < c Initial program 48.3%
Taylor expanded in c around inf 76.0%
*-commutative76.0%
unpow276.0%
times-frac80.8%
Simplified80.8%
associate-*l/82.9%
Applied egg-rr82.9%
Final simplification81.0%
(FPCore (a b c d) :precision binary64 (if (<= c -2.75e-30) (/ a c) (if (<= c 4.2e+91) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.75e-30) {
tmp = a / c;
} else if (c <= 4.2e+91) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-2.75d-30)) then
tmp = a / c
else if (c <= 4.2d+91) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.75e-30) {
tmp = a / c;
} else if (c <= 4.2e+91) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.75e-30: tmp = a / c elif c <= 4.2e+91: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.75e-30) tmp = Float64(a / c); elseif (c <= 4.2e+91) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -2.75e-30) tmp = a / c; elseif (c <= 4.2e+91) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.75e-30], N[(a / c), $MachinePrecision], If[LessEqual[c, 4.2e+91], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.75 \cdot 10^{-30}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 4.2 \cdot 10^{+91}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -2.74999999999999988e-30 or 4.20000000000000015e91 < c Initial program 53.4%
Taylor expanded in c around inf 67.9%
if -2.74999999999999988e-30 < c < 4.20000000000000015e91Initial program 77.7%
Taylor expanded in c around 0 63.8%
Final simplification65.7%
(FPCore (a b c d) :precision binary64 (if (<= d -9.2e+196) (/ a d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -9.2e+196) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-9.2d+196)) then
tmp = a / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -9.2e+196) {
tmp = a / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -9.2e+196: tmp = a / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -9.2e+196) tmp = Float64(a / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -9.2e+196) tmp = a / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -9.2e+196], N[(a / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.2 \cdot 10^{+196}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -9.19999999999999922e196Initial program 50.3%
*-un-lft-identity50.3%
add-sqr-sqrt50.3%
times-frac50.3%
hypot-def50.3%
fma-def50.3%
hypot-def71.0%
Applied egg-rr71.0%
Taylor expanded in c around -inf 26.8%
neg-mul-126.8%
Simplified26.8%
Taylor expanded in d around -inf 26.7%
if -9.19999999999999922e196 < d Initial program 68.1%
Taylor expanded in c around inf 47.4%
Final simplification45.2%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 66.2%
Taylor expanded in c around inf 42.8%
Final simplification42.8%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2023275
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))