
(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 10 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))) 1e+231) (* (/ 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))) <= 1e+231) {
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))) <= 1e+231) 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], 1e+231], 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 10^{+231}:\\
\;\;\;\;\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))) < 1.0000000000000001e231Initial program 82.7%
*-un-lft-identity82.7%
add-sqr-sqrt82.7%
times-frac82.7%
hypot-def82.7%
fma-def82.7%
hypot-def97.0%
Applied egg-rr97.0%
if 1.0000000000000001e231 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 16.4%
Taylor expanded in c around 0 48.1%
unpow248.1%
times-frac59.9%
Simplified59.9%
Final simplification86.9%
(FPCore (a b c d)
:precision binary64
(if (<= c -9e+42)
(/ (* a (/ c (hypot c d))) (hypot c d))
(if (<= c 1.85e-33)
(+ (/ b d) (/ (* a (/ c d)) d))
(* (/ 1.0 (hypot c d)) (+ a (/ d (/ c b)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9e+42) {
tmp = (a * (c / hypot(c, d))) / hypot(c, d);
} else if (c <= 1.85e-33) {
tmp = (b / d) + ((a * (c / d)) / d);
} else {
tmp = (1.0 / hypot(c, d)) * (a + (d / (c / b)));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9e+42) {
tmp = (a * (c / Math.hypot(c, d))) / Math.hypot(c, d);
} else if (c <= 1.85e-33) {
tmp = (b / d) + ((a * (c / d)) / d);
} else {
tmp = (1.0 / Math.hypot(c, d)) * (a + (d / (c / b)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -9e+42: tmp = (a * (c / math.hypot(c, d))) / math.hypot(c, d) elif c <= 1.85e-33: tmp = (b / d) + ((a * (c / d)) / d) else: tmp = (1.0 / math.hypot(c, d)) * (a + (d / (c / b))) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -9e+42) tmp = Float64(Float64(a * Float64(c / hypot(c, d))) / hypot(c, d)); elseif (c <= 1.85e-33) tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / d)); else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a + Float64(d / Float64(c / b)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -9e+42) tmp = (a * (c / hypot(c, d))) / hypot(c, d); elseif (c <= 1.85e-33) tmp = (b / d) + ((a * (c / d)) / d); else tmp = (1.0 / hypot(c, d)) * (a + (d / (c / b))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -9e+42], N[(N[(a * N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.85e-33], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a + N[(d / N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{+42}:\\
\;\;\;\;\frac{a \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq 1.85 \cdot 10^{-33}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\
\end{array}
\end{array}
if c < -9.00000000000000025e42Initial program 44.5%
Taylor expanded in a around inf 44.6%
associate-/l*43.6%
associate-/r/50.0%
unpow250.0%
unpow250.0%
+-commutative50.0%
fma-def50.0%
Simplified50.0%
*-un-lft-identity50.0%
fma-def50.0%
add-sqr-sqrt50.0%
hypot-udef50.0%
hypot-udef50.0%
times-frac86.5%
Applied egg-rr86.5%
associate-*l*93.0%
associate-*l/93.3%
*-un-lft-identity93.3%
Applied egg-rr93.3%
if -9.00000000000000025e42 < c < 1.85000000000000007e-33Initial program 76.6%
Taylor expanded in c around 0 83.1%
unpow283.1%
times-frac83.2%
Simplified83.2%
associate-*r/85.4%
Applied egg-rr85.4%
if 1.85000000000000007e-33 < c Initial program 56.7%
*-un-lft-identity56.7%
add-sqr-sqrt56.7%
times-frac56.7%
hypot-def56.7%
fma-def56.7%
hypot-def66.3%
Applied egg-rr66.3%
Taylor expanded in c around inf 78.2%
associate-/l*81.8%
Simplified81.8%
Final simplification85.4%
(FPCore (a b c d)
:precision binary64
(if (<= c -1e+43)
(+ (/ a c) (* (/ d c) (/ b c)))
(if (<= c 2.35e-33)
(+ (/ b d) (/ (* a (/ c d)) d))
(* (/ 1.0 (hypot c d)) (+ a (/ d (/ c b)))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1e+43) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= 2.35e-33) {
tmp = (b / d) + ((a * (c / d)) / d);
} else {
tmp = (1.0 / hypot(c, d)) * (a + (d / (c / b)));
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1e+43) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= 2.35e-33) {
tmp = (b / d) + ((a * (c / d)) / d);
} else {
tmp = (1.0 / Math.hypot(c, d)) * (a + (d / (c / b)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1e+43: tmp = (a / c) + ((d / c) * (b / c)) elif c <= 2.35e-33: tmp = (b / d) + ((a * (c / d)) / d) else: tmp = (1.0 / math.hypot(c, d)) * (a + (d / (c / b))) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1e+43) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); elseif (c <= 2.35e-33) tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / d)); else tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a + Float64(d / Float64(c / b)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1e+43) tmp = (a / c) + ((d / c) * (b / c)); elseif (c <= 2.35e-33) tmp = (b / d) + ((a * (c / d)) / d); else tmp = (1.0 / hypot(c, d)) * (a + (d / (c / b))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1e+43], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.35e-33], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a + N[(d / N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1 \cdot 10^{+43}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{elif}\;c \leq 2.35 \cdot 10^{-33}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\
\end{array}
\end{array}
if c < -1.00000000000000001e43Initial program 44.5%
Taylor expanded in c around inf 79.4%
unpow279.4%
times-frac86.5%
Simplified86.5%
if -1.00000000000000001e43 < c < 2.3500000000000001e-33Initial program 76.6%
Taylor expanded in c around 0 83.1%
unpow283.1%
times-frac83.2%
Simplified83.2%
associate-*r/85.4%
Applied egg-rr85.4%
if 2.3500000000000001e-33 < c Initial program 56.7%
*-un-lft-identity56.7%
add-sqr-sqrt56.7%
times-frac56.7%
hypot-def56.7%
fma-def56.7%
hypot-def66.3%
Applied egg-rr66.3%
Taylor expanded in c around inf 78.2%
associate-/l*81.8%
Simplified81.8%
Final simplification84.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.5e+43) (not (<= c 1.7e-33))) (+ (/ a c) (* (/ d c) (/ b c))) (+ (/ b d) (* (/ c d) (/ a d)))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.5e+43) || !(c <= 1.7e-33)) {
tmp = (a / c) + ((d / c) * (b / c));
} 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) :: tmp
if ((c <= (-2.5d+43)) .or. (.not. (c <= 1.7d-33))) then
tmp = (a / c) + ((d / c) * (b / c))
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 tmp;
if ((c <= -2.5e+43) || !(c <= 1.7e-33)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (b / d) + ((c / d) * (a / d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.5e+43) or not (c <= 1.7e-33): tmp = (a / c) + ((d / c) * (b / c)) else: tmp = (b / d) + ((c / d) * (a / d)) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.5e+43) || !(c <= 1.7e-33)) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); 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) tmp = 0.0; if ((c <= -2.5e+43) || ~((c <= 1.7e-33))) tmp = (a / c) + ((d / c) * (b / c)); else tmp = (b / d) + ((c / d) * (a / d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.5e+43], N[Not[LessEqual[c, 1.7e-33]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $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}\;c \leq -2.5 \cdot 10^{+43} \lor \neg \left(c \leq 1.7 \cdot 10^{-33}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\end{array}
if c < -2.5000000000000002e43 or 1.7e-33 < c Initial program 52.7%
Taylor expanded in c around inf 78.4%
unpow278.4%
times-frac83.2%
Simplified83.2%
if -2.5000000000000002e43 < c < 1.7e-33Initial program 76.6%
Taylor expanded in c around 0 83.1%
unpow283.1%
times-frac83.2%
Simplified83.2%
Final simplification83.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -9e+42) (not (<= c 1.9e-33))) (+ (/ a c) (* (/ d c) (/ b c))) (+ (/ b d) (/ (* a (/ c d)) d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -9e+42) || !(c <= 1.9e-33)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (b / d) + ((a * (c / d)) / 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 <= (-9d+42)) .or. (.not. (c <= 1.9d-33))) then
tmp = (a / c) + ((d / c) * (b / c))
else
tmp = (b / d) + ((a * (c / d)) / d)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -9e+42) || !(c <= 1.9e-33)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (b / d) + ((a * (c / d)) / d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -9e+42) or not (c <= 1.9e-33): tmp = (a / c) + ((d / c) * (b / c)) else: tmp = (b / d) + ((a * (c / d)) / d) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -9e+42) || !(c <= 1.9e-33)) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); else tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -9e+42) || ~((c <= 1.9e-33))) tmp = (a / c) + ((d / c) * (b / c)); else tmp = (b / d) + ((a * (c / d)) / d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -9e+42], N[Not[LessEqual[c, 1.9e-33]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{+42} \lor \neg \left(c \leq 1.9 \cdot 10^{-33}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\
\end{array}
\end{array}
if c < -9.00000000000000025e42 or 1.89999999999999997e-33 < c Initial program 52.7%
Taylor expanded in c around inf 78.4%
unpow278.4%
times-frac83.2%
Simplified83.2%
if -9.00000000000000025e42 < c < 1.89999999999999997e-33Initial program 76.6%
Taylor expanded in c around 0 83.1%
unpow283.1%
times-frac83.2%
Simplified83.2%
associate-*r/85.4%
Applied egg-rr85.4%
Final simplification84.3%
(FPCore (a b c d) :precision binary64 (if (<= d -1.7e+91) (/ b d) (if (<= d 8.2e+22) (+ (/ a c) (* (/ d c) (/ b c))) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.7e+91) {
tmp = b / d;
} else if (d <= 8.2e+22) {
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 (d <= (-1.7d+91)) then
tmp = b / d
else if (d <= 8.2d+22) 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 (d <= -1.7e+91) {
tmp = b / d;
} else if (d <= 8.2e+22) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.7e+91: tmp = b / d elif d <= 8.2e+22: tmp = (a / c) + ((d / c) * (b / c)) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.7e+91) tmp = Float64(b / d); elseif (d <= 8.2e+22) 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 (d <= -1.7e+91) tmp = b / d; elseif (d <= 8.2e+22) tmp = (a / c) + ((d / c) * (b / c)); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.7e+91], N[(b / d), $MachinePrecision], If[LessEqual[d, 8.2e+22], 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}\;d \leq -1.7 \cdot 10^{+91}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 8.2 \cdot 10^{+22}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.7e91 or 8.19999999999999958e22 < d Initial program 48.8%
Taylor expanded in c around 0 66.6%
if -1.7e91 < d < 8.19999999999999958e22Initial program 75.5%
Taylor expanded in c around inf 74.2%
unpow274.2%
times-frac77.6%
Simplified77.6%
Final simplification73.1%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.9e+43)
(/ a c)
(if (<= c 1.05e-136)
(/ b d)
(if (<= c 8e-76)
(* (/ c d) (/ a d))
(if (<= c 2.05e-33) (/ b d) (/ a c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.9e+43) {
tmp = a / c;
} else if (c <= 1.05e-136) {
tmp = b / d;
} else if (c <= 8e-76) {
tmp = (c / d) * (a / d);
} else if (c <= 2.05e-33) {
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 <= (-1.9d+43)) then
tmp = a / c
else if (c <= 1.05d-136) then
tmp = b / d
else if (c <= 8d-76) then
tmp = (c / d) * (a / d)
else if (c <= 2.05d-33) 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 <= -1.9e+43) {
tmp = a / c;
} else if (c <= 1.05e-136) {
tmp = b / d;
} else if (c <= 8e-76) {
tmp = (c / d) * (a / d);
} else if (c <= 2.05e-33) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.9e+43: tmp = a / c elif c <= 1.05e-136: tmp = b / d elif c <= 8e-76: tmp = (c / d) * (a / d) elif c <= 2.05e-33: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.9e+43) tmp = Float64(a / c); elseif (c <= 1.05e-136) tmp = Float64(b / d); elseif (c <= 8e-76) tmp = Float64(Float64(c / d) * Float64(a / d)); elseif (c <= 2.05e-33) 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 <= -1.9e+43) tmp = a / c; elseif (c <= 1.05e-136) tmp = b / d; elseif (c <= 8e-76) tmp = (c / d) * (a / d); elseif (c <= 2.05e-33) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.9e+43], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.05e-136], N[(b / d), $MachinePrecision], If[LessEqual[c, 8e-76], N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.05e-33], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.9 \cdot 10^{+43}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 1.05 \cdot 10^{-136}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{-76}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{elif}\;c \leq 2.05 \cdot 10^{-33}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.90000000000000004e43 or 2.05e-33 < c Initial program 52.7%
Taylor expanded in c around inf 74.4%
if -1.90000000000000004e43 < c < 1.0499999999999999e-136 or 7.99999999999999942e-76 < c < 2.05e-33Initial program 75.2%
Taylor expanded in c around 0 66.9%
if 1.0499999999999999e-136 < c < 7.99999999999999942e-76Initial program 90.8%
Taylor expanded in a around inf 82.3%
associate-/l*82.5%
associate-/r/82.3%
unpow282.3%
unpow282.3%
+-commutative82.3%
fma-def82.3%
Simplified82.3%
*-un-lft-identity82.3%
fma-def82.3%
add-sqr-sqrt82.3%
hypot-udef82.3%
hypot-udef82.3%
times-frac82.3%
Applied egg-rr82.3%
Taylor expanded in c around 0 82.3%
unpow282.3%
times-frac89.4%
Simplified89.4%
Final simplification71.6%
(FPCore (a b c d)
:precision binary64
(if (<= c -9e+42)
(/ a c)
(if (<= c 1.2e-136)
(/ b d)
(if (<= c 9.2e-76)
(* c (/ (/ a d) d))
(if (<= c 1.6e-33) (/ b d) (/ a c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9e+42) {
tmp = a / c;
} else if (c <= 1.2e-136) {
tmp = b / d;
} else if (c <= 9.2e-76) {
tmp = c * ((a / d) / d);
} else if (c <= 1.6e-33) {
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 <= (-9d+42)) then
tmp = a / c
else if (c <= 1.2d-136) then
tmp = b / d
else if (c <= 9.2d-76) then
tmp = c * ((a / d) / d)
else if (c <= 1.6d-33) 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 <= -9e+42) {
tmp = a / c;
} else if (c <= 1.2e-136) {
tmp = b / d;
} else if (c <= 9.2e-76) {
tmp = c * ((a / d) / d);
} else if (c <= 1.6e-33) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -9e+42: tmp = a / c elif c <= 1.2e-136: tmp = b / d elif c <= 9.2e-76: tmp = c * ((a / d) / d) elif c <= 1.6e-33: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -9e+42) tmp = Float64(a / c); elseif (c <= 1.2e-136) tmp = Float64(b / d); elseif (c <= 9.2e-76) tmp = Float64(c * Float64(Float64(a / d) / d)); elseif (c <= 1.6e-33) 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 <= -9e+42) tmp = a / c; elseif (c <= 1.2e-136) tmp = b / d; elseif (c <= 9.2e-76) tmp = c * ((a / d) / d); elseif (c <= 1.6e-33) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -9e+42], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.2e-136], N[(b / d), $MachinePrecision], If[LessEqual[c, 9.2e-76], N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.6e-33], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{+42}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 1.2 \cdot 10^{-136}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 9.2 \cdot 10^{-76}:\\
\;\;\;\;c \cdot \frac{\frac{a}{d}}{d}\\
\mathbf{elif}\;c \leq 1.6 \cdot 10^{-33}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -9.00000000000000025e42 or 1.59999999999999988e-33 < c Initial program 52.7%
Taylor expanded in c around inf 74.4%
if -9.00000000000000025e42 < c < 1.1999999999999999e-136 or 9.20000000000000025e-76 < c < 1.59999999999999988e-33Initial program 75.2%
Taylor expanded in c around 0 66.9%
if 1.1999999999999999e-136 < c < 9.20000000000000025e-76Initial program 90.8%
Taylor expanded in a around inf 82.3%
associate-/l*82.5%
associate-/r/82.3%
unpow282.3%
unpow282.3%
+-commutative82.3%
fma-def82.3%
Simplified82.3%
*-un-lft-identity82.3%
fma-def82.3%
add-sqr-sqrt82.3%
hypot-udef82.3%
hypot-udef82.3%
times-frac82.3%
Applied egg-rr82.3%
Taylor expanded in c around 0 82.3%
unpow282.3%
times-frac89.4%
Simplified89.4%
Taylor expanded in c around 0 82.3%
*-commutative82.3%
unpow282.3%
times-frac89.4%
associate-*r/91.1%
associate-*l/91.0%
Simplified91.0%
Final simplification71.7%
(FPCore (a b c d) :precision binary64 (if (<= c -9e+42) (/ a c) (if (<= c 1.8e-33) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9e+42) {
tmp = a / c;
} else if (c <= 1.8e-33) {
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 <= (-9d+42)) then
tmp = a / c
else if (c <= 1.8d-33) 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 <= -9e+42) {
tmp = a / c;
} else if (c <= 1.8e-33) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -9e+42: tmp = a / c elif c <= 1.8e-33: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -9e+42) tmp = Float64(a / c); elseif (c <= 1.8e-33) 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 <= -9e+42) tmp = a / c; elseif (c <= 1.8e-33) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -9e+42], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.8e-33], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{+42}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 1.8 \cdot 10^{-33}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -9.00000000000000025e42 or 1.80000000000000017e-33 < c Initial program 52.7%
Taylor expanded in c around inf 74.4%
if -9.00000000000000025e42 < c < 1.80000000000000017e-33Initial program 76.6%
Taylor expanded in c around 0 64.4%
Final simplification69.4%
(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 64.6%
Taylor expanded in c around inf 46.5%
Final simplification46.5%
(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 2023224
(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))))