
(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 9 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 (<= d -1.55e+27)
(+ (/ b d) (/ c (/ (* d d) a)))
(if (<= d -8e-143)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 4.5e-115)
(* (/ 1.0 c) (+ a (/ (* b d) c)))
(if (<= d 19500.0)
(/ (fma a c (* b d)) (fma c c (* d d)))
(+ (/ b d) (/ (* a c) (* d d))))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.55e+27) {
tmp = (b / d) + (c / ((d * d) / a));
} else if (d <= -8e-143) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (d <= 4.5e-115) {
tmp = (1.0 / c) * (a + ((b * d) / c));
} else if (d <= 19500.0) {
tmp = fma(a, c, (b * d)) / fma(c, c, (d * d));
} else {
tmp = (b / d) + ((a * c) / (d * d));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1.55e+27) tmp = Float64(Float64(b / d) + Float64(c / Float64(Float64(d * d) / a))); elseif (d <= -8e-143) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 4.5e-115) tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c))); elseif (d <= 19500.0) tmp = Float64(fma(a, c, Float64(b * d)) / fma(c, c, Float64(d * d))); else tmp = Float64(Float64(b / d) + Float64(Float64(a * c) / Float64(d * d))); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.55e+27], N[(N[(b / d), $MachinePrecision] + N[(c / N[(N[(d * d), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -8e-143], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.5e-115], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 19500.0], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.55 \cdot 10^{+27}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{\frac{d \cdot d}{a}}\\
\mathbf{elif}\;d \leq -8 \cdot 10^{-143}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 4.5 \cdot 10^{-115}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\mathbf{elif}\;d \leq 19500:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot c}{d \cdot d}\\
\end{array}
\end{array}
if d < -1.54999999999999998e27Initial program 72.7%
Taylor expanded in c around 0 97.1%
unpow297.1%
associate-/l*97.1%
Simplified97.1%
if -1.54999999999999998e27 < d < -7.9999999999999996e-143Initial program 87.4%
if -7.9999999999999996e-143 < d < 4.50000000000000023e-115Initial program 70.1%
*-un-lft-identity70.1%
add-sqr-sqrt70.1%
times-frac70.2%
hypot-def70.2%
fma-def70.2%
hypot-def85.5%
Applied egg-rr85.5%
Taylor expanded in c around inf 49.0%
Taylor expanded in c around inf 91.7%
if 4.50000000000000023e-115 < d < 19500Initial program 87.8%
fma-def87.9%
fma-def87.9%
Simplified87.9%
if 19500 < d Initial program 73.6%
Taylor expanded in c around 0 98.3%
unpow298.3%
times-frac98.2%
Simplified98.2%
frac-times98.3%
Applied egg-rr98.3%
Final simplification92.8%
(FPCore (a b c d) :precision binary64 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY) (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))) (/ (* a (/ c (hypot c d))) (hypot c d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
} else {
tmp = (a * (c / hypot(c, d))) / hypot(c, 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))) <= Inf) tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d))); else tmp = Float64(Float64(a * Float64(c / hypot(c, d))) / hypot(c, 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], Infinity], 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[(a * N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\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{a \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 84.5%
*-un-lft-identity84.5%
add-sqr-sqrt84.5%
times-frac84.5%
hypot-def84.5%
fma-def84.5%
hypot-def95.0%
Applied egg-rr95.0%
if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 0.0%
Taylor expanded in a around inf 1.8%
associate-/l*3.6%
associate-/r/3.6%
unpow23.6%
unpow23.6%
+-commutative3.6%
fma-def3.6%
Simplified3.6%
*-un-lft-identity3.6%
fma-def3.6%
add-sqr-sqrt3.6%
hypot-udef3.6%
hypot-udef3.6%
times-frac53.5%
Applied egg-rr53.5%
associate-*l/53.4%
*-lft-identity53.4%
Simplified53.4%
associate-*l/53.7%
Applied egg-rr53.7%
Final simplification90.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -1.55e+27)
(+ (/ b d) (/ c (/ (* d d) a)))
(if (<= d -1e-142)
t_0
(if (<= d 6.8e-115)
(* (/ 1.0 c) (+ a (/ (* b d) c)))
(if (<= d 21000.0) t_0 (+ (/ b d) (/ (* a c) (* d 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 (d <= -1.55e+27) {
tmp = (b / d) + (c / ((d * d) / a));
} else if (d <= -1e-142) {
tmp = t_0;
} else if (d <= 6.8e-115) {
tmp = (1.0 / c) * (a + ((b * d) / c));
} else if (d <= 21000.0) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (d <= (-1.55d+27)) then
tmp = (b / d) + (c / ((d * d) / a))
else if (d <= (-1d-142)) then
tmp = t_0
else if (d <= 6.8d-115) then
tmp = (1.0d0 / c) * (a + ((b * d) / c))
else if (d <= 21000.0d0) then
tmp = t_0
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 t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -1.55e+27) {
tmp = (b / d) + (c / ((d * d) / a));
} else if (d <= -1e-142) {
tmp = t_0;
} else if (d <= 6.8e-115) {
tmp = (1.0 / c) * (a + ((b * d) / c));
} else if (d <= 21000.0) {
tmp = t_0;
} else {
tmp = (b / d) + ((a * c) / (d * d));
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -1.55e+27: tmp = (b / d) + (c / ((d * d) / a)) elif d <= -1e-142: tmp = t_0 elif d <= 6.8e-115: tmp = (1.0 / c) * (a + ((b * d) / c)) elif d <= 21000.0: tmp = t_0 else: tmp = (b / d) + ((a * c) / (d * 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 (d <= -1.55e+27) tmp = Float64(Float64(b / d) + Float64(c / Float64(Float64(d * d) / a))); elseif (d <= -1e-142) tmp = t_0; elseif (d <= 6.8e-115) tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c))); elseif (d <= 21000.0) tmp = t_0; else tmp = Float64(Float64(b / d) + Float64(Float64(a * c) / Float64(d * 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 (d <= -1.55e+27) tmp = (b / d) + (c / ((d * d) / a)); elseif (d <= -1e-142) tmp = t_0; elseif (d <= 6.8e-115) tmp = (1.0 / c) * (a + ((b * d) / c)); elseif (d <= 21000.0) tmp = t_0; else tmp = (b / d) + ((a * c) / (d * 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[d, -1.55e+27], N[(N[(b / d), $MachinePrecision] + N[(c / N[(N[(d * d), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1e-142], t$95$0, If[LessEqual[d, 6.8e-115], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 21000.0], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] / N[(d * 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}\;d \leq -1.55 \cdot 10^{+27}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{\frac{d \cdot d}{a}}\\
\mathbf{elif}\;d \leq -1 \cdot 10^{-142}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 6.8 \cdot 10^{-115}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\mathbf{elif}\;d \leq 21000:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot c}{d \cdot d}\\
\end{array}
\end{array}
if d < -1.54999999999999998e27Initial program 72.7%
Taylor expanded in c around 0 97.1%
unpow297.1%
associate-/l*97.1%
Simplified97.1%
if -1.54999999999999998e27 < d < -1e-142 or 6.7999999999999996e-115 < d < 21000Initial program 87.5%
if -1e-142 < d < 6.7999999999999996e-115Initial program 70.1%
*-un-lft-identity70.1%
add-sqr-sqrt70.1%
times-frac70.2%
hypot-def70.2%
fma-def70.2%
hypot-def85.5%
Applied egg-rr85.5%
Taylor expanded in c around inf 49.0%
Taylor expanded in c around inf 91.7%
if 21000 < d Initial program 73.6%
Taylor expanded in c around 0 98.3%
unpow298.3%
times-frac98.2%
Simplified98.2%
frac-times98.3%
Applied egg-rr98.3%
Final simplification92.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.8e-8) (not (<= c 1.3))) (+ (/ 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 <= -4.8e-8) || !(c <= 1.3)) {
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 <= (-4.8d-8)) .or. (.not. (c <= 1.3d0))) 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 <= -4.8e-8) || !(c <= 1.3)) {
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 <= -4.8e-8) or not (c <= 1.3): 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 <= -4.8e-8) || !(c <= 1.3)) 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 <= -4.8e-8) || ~((c <= 1.3))) 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, -4.8e-8], N[Not[LessEqual[c, 1.3]], $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 -4.8 \cdot 10^{-8} \lor \neg \left(c \leq 1.3\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 < -4.79999999999999997e-8 or 1.30000000000000004 < c Initial program 68.9%
Taylor expanded in c around inf 94.6%
unpow294.6%
times-frac95.7%
Simplified95.7%
if -4.79999999999999997e-8 < c < 1.30000000000000004Initial program 79.0%
Taylor expanded in c around 0 75.7%
unpow275.7%
times-frac80.3%
Simplified80.3%
Final simplification85.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.3e-8) (not (<= c 0.000235))) (+ (/ a c) (* (/ d c) (/ b c))) (+ (/ b d) (/ a (* d (/ d c))))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.3e-8) || !(c <= 0.000235)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (b / d) + (a / (d * (d / 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 <= (-5.3d-8)) .or. (.not. (c <= 0.000235d0))) then
tmp = (a / c) + ((d / c) * (b / c))
else
tmp = (b / d) + (a / (d * (d / c)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.3e-8) || !(c <= 0.000235)) {
tmp = (a / c) + ((d / c) * (b / c));
} else {
tmp = (b / d) + (a / (d * (d / c)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.3e-8) or not (c <= 0.000235): tmp = (a / c) + ((d / c) * (b / c)) else: tmp = (b / d) + (a / (d * (d / c))) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.3e-8) || !(c <= 0.000235)) tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c))); else tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -5.3e-8) || ~((c <= 0.000235))) tmp = (a / c) + ((d / c) * (b / c)); else tmp = (b / d) + (a / (d * (d / c))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.3e-8], N[Not[LessEqual[c, 0.000235]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.3 \cdot 10^{-8} \lor \neg \left(c \leq 0.000235\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\
\end{array}
\end{array}
if c < -5.2999999999999998e-8 or 2.34999999999999993e-4 < c Initial program 68.9%
Taylor expanded in c around inf 94.6%
unpow294.6%
times-frac95.7%
Simplified95.7%
if -5.2999999999999998e-8 < c < 2.34999999999999993e-4Initial program 79.0%
Taylor expanded in c around 0 75.7%
unpow275.7%
times-frac80.3%
Simplified80.3%
clear-num79.8%
frac-times80.3%
*-un-lft-identity80.3%
Applied egg-rr80.3%
Final simplification85.5%
(FPCore (a b c d) :precision binary64 (if (<= d -8200000000000.0) (/ b d) (if (<= d 70000000.0) (* (/ 1.0 c) (+ a (/ (* b d) c))) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -8200000000000.0) {
tmp = b / d;
} else if (d <= 70000000.0) {
tmp = (1.0 / c) * (a + ((b * d) / 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 <= (-8200000000000.0d0)) then
tmp = b / d
else if (d <= 70000000.0d0) then
tmp = (1.0d0 / c) * (a + ((b * d) / 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 <= -8200000000000.0) {
tmp = b / d;
} else if (d <= 70000000.0) {
tmp = (1.0 / c) * (a + ((b * d) / c));
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -8200000000000.0: tmp = b / d elif d <= 70000000.0: tmp = (1.0 / c) * (a + ((b * d) / c)) else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -8200000000000.0) tmp = Float64(b / d); elseif (d <= 70000000.0) tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c))); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -8200000000000.0) tmp = b / d; elseif (d <= 70000000.0) tmp = (1.0 / c) * (a + ((b * d) / c)); else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -8200000000000.0], N[(b / d), $MachinePrecision], If[LessEqual[d, 70000000.0], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -8200000000000:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 70000000:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -8.2e12 or 7e7 < d Initial program 73.0%
Taylor expanded in c around 0 87.0%
if -8.2e12 < d < 7e7Initial program 76.9%
*-un-lft-identity76.9%
add-sqr-sqrt76.9%
times-frac76.9%
hypot-def76.9%
fma-def76.9%
hypot-def88.1%
Applied egg-rr88.1%
Taylor expanded in c around inf 44.7%
Taylor expanded in c around inf 79.1%
Final simplification81.8%
(FPCore (a b c d)
:precision binary64
(if (<= d -45.0)
(+ (/ b d) (/ c (/ (* d d) a)))
(if (<= d 1.12e-79)
(* (/ 1.0 c) (+ a (/ (* b d) c)))
(+ (/ b d) (/ (* a c) (* d d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -45.0) {
tmp = (b / d) + (c / ((d * d) / a));
} else if (d <= 1.12e-79) {
tmp = (1.0 / c) * (a + ((b * d) / 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 (d <= (-45.0d0)) then
tmp = (b / d) + (c / ((d * d) / a))
else if (d <= 1.12d-79) then
tmp = (1.0d0 / c) * (a + ((b * d) / 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 (d <= -45.0) {
tmp = (b / d) + (c / ((d * d) / a));
} else if (d <= 1.12e-79) {
tmp = (1.0 / c) * (a + ((b * d) / c));
} else {
tmp = (b / d) + ((a * c) / (d * d));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -45.0: tmp = (b / d) + (c / ((d * d) / a)) elif d <= 1.12e-79: tmp = (1.0 / c) * (a + ((b * d) / c)) else: tmp = (b / d) + ((a * c) / (d * d)) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -45.0) tmp = Float64(Float64(b / d) + Float64(c / Float64(Float64(d * d) / a))); elseif (d <= 1.12e-79) tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c))); else tmp = Float64(Float64(b / d) + Float64(Float64(a * c) / Float64(d * d))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -45.0) tmp = (b / d) + (c / ((d * d) / a)); elseif (d <= 1.12e-79) tmp = (1.0 / c) * (a + ((b * d) / c)); else tmp = (b / d) + ((a * c) / (d * d)); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -45.0], N[(N[(b / d), $MachinePrecision] + N[(c / N[(N[(d * d), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.12e-79], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -45:\\
\;\;\;\;\frac{b}{d} + \frac{c}{\frac{d \cdot d}{a}}\\
\mathbf{elif}\;d \leq 1.12 \cdot 10^{-79}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{a \cdot c}{d \cdot d}\\
\end{array}
\end{array}
if d < -45Initial program 74.5%
Taylor expanded in c around 0 90.3%
unpow290.3%
associate-/l*90.3%
Simplified90.3%
if -45 < d < 1.11999999999999996e-79Initial program 75.2%
*-un-lft-identity75.2%
add-sqr-sqrt75.1%
times-frac75.2%
hypot-def75.2%
fma-def75.2%
hypot-def86.9%
Applied egg-rr86.9%
Taylor expanded in c around inf 46.5%
Taylor expanded in c around inf 84.8%
if 1.11999999999999996e-79 < d Initial program 77.0%
Taylor expanded in c around 0 88.0%
unpow288.0%
times-frac86.7%
Simplified86.7%
frac-times88.0%
Applied egg-rr88.0%
Final simplification86.6%
(FPCore (a b c d) :precision binary64 (if (<= c -2.3e-30) (/ a c) (if (<= c 12.6) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.3e-30) {
tmp = a / c;
} else if (c <= 12.6) {
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.3d-30)) then
tmp = a / c
else if (c <= 12.6d0) 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.3e-30) {
tmp = a / c;
} else if (c <= 12.6) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.3e-30: tmp = a / c elif c <= 12.6: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.3e-30) tmp = Float64(a / c); elseif (c <= 12.6) 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.3e-30) tmp = a / c; elseif (c <= 12.6) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.3e-30], N[(a / c), $MachinePrecision], If[LessEqual[c, 12.6], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.3 \cdot 10^{-30}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 12.6:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -2.29999999999999984e-30 or 12.5999999999999996 < c Initial program 70.9%
Taylor expanded in c around inf 79.5%
if -2.29999999999999984e-30 < c < 12.5999999999999996Initial program 78.2%
Taylor expanded in c around 0 63.3%
Final simplification69.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 75.6%
Taylor expanded in c around inf 40.6%
Final simplification40.6%
(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 2023278
(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))))