
(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
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= t_0 (- INFINITY))
(+ (/ a c) (/ (/ (* b d) c) c))
(if (<= t_0 INFINITY)
(/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d))
(+ (/ a c) (* d (* (/ 1.0 c) (/ b c))))))))
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 <= -((double) INFINITY)) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (t_0 <= ((double) INFINITY)) {
tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (a / c) + (d * ((1.0 / c) * (b / c)));
}
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 <= Float64(-Inf)) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); elseif (t_0 <= Inf) tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(a / c) + Float64(d * Float64(Float64(1.0 / c) * Float64(b / c)))); end return 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, (-Infinity)], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(d * N[(N[(1.0 / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $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 -\infty:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;t_0 \leq \infty:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -inf.0Initial program 67.0%
Taylor expanded in c around inf 69.9%
associate-/l*74.3%
associate-/r/74.3%
Simplified74.3%
pow274.3%
associate-*l/69.9%
associate-/r*87.3%
Applied egg-rr87.3%
if -inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 78.1%
*-un-lft-identity78.1%
+-commutative78.1%
fma-udef78.1%
add-sqr-sqrt78.1%
times-frac78.1%
fma-udef78.1%
+-commutative78.1%
hypot-def78.1%
fma-def78.1%
fma-udef78.1%
+-commutative78.1%
hypot-def94.3%
Applied egg-rr94.3%
associate-*l/94.6%
*-un-lft-identity94.6%
Applied egg-rr94.6%
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 c around inf 43.5%
associate-/l*50.0%
associate-/r/50.0%
Simplified50.0%
*-un-lft-identity50.0%
pow250.0%
times-frac55.8%
Applied egg-rr55.8%
Final simplification86.4%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.65e+31)
(/ (- (/ (- a) (/ d c)) b) (hypot c d))
(if (<= d 3e-121)
(+ (/ a c) (/ (/ (* b d) c) c))
(if (<= d 3.3e+28)
(/ (fma a c (* b d)) (fma d d (* c c)))
(/ (+ b (/ a (/ d c))) (hypot c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.65e+31) {
tmp = ((-a / (d / c)) - b) / hypot(c, d);
} else if (d <= 3e-121) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 3.3e+28) {
tmp = fma(a, c, (b * d)) / fma(d, d, (c * c));
} else {
tmp = (b + (a / (d / c))) / hypot(c, d);
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1.65e+31) tmp = Float64(Float64(Float64(Float64(-a) / Float64(d / c)) - b) / hypot(c, d)); elseif (d <= 3e-121) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); elseif (d <= 3.3e+28) tmp = Float64(fma(a, c, Float64(b * d)) / fma(d, d, Float64(c * c))); else tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / hypot(c, d)); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.65e+31], N[(N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3e-121], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.3e+28], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.65 \cdot 10^{+31}:\\
\;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq 3 \cdot 10^{-121}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 3.3 \cdot 10^{+28}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -1.64999999999999996e31Initial program 44.9%
*-un-lft-identity44.9%
+-commutative44.9%
fma-udef44.9%
add-sqr-sqrt44.9%
times-frac44.8%
fma-udef44.8%
+-commutative44.8%
hypot-def44.8%
fma-def44.8%
fma-udef44.8%
+-commutative44.8%
hypot-def56.6%
Applied egg-rr56.6%
associate-*l/56.7%
*-un-lft-identity56.7%
Applied egg-rr56.7%
Taylor expanded in d around -inf 70.1%
mul-1-neg70.1%
unsub-neg70.1%
neg-mul-170.1%
associate-/l*75.8%
Simplified75.8%
if -1.64999999999999996e31 < d < 2.9999999999999999e-121Initial program 73.0%
Taylor expanded in c around inf 82.3%
associate-/l*82.3%
associate-/r/80.0%
Simplified80.0%
pow280.0%
associate-*l/82.3%
associate-/r*92.1%
Applied egg-rr92.1%
if 2.9999999999999999e-121 < d < 3.3e28Initial program 84.8%
fma-def84.9%
+-commutative84.9%
fma-def84.9%
Simplified84.9%
if 3.3e28 < d Initial program 41.2%
*-un-lft-identity41.2%
+-commutative41.2%
fma-udef41.2%
add-sqr-sqrt41.2%
times-frac41.3%
fma-udef41.3%
+-commutative41.3%
hypot-def41.3%
fma-def41.3%
fma-udef41.3%
+-commutative41.3%
hypot-def61.6%
Applied egg-rr61.6%
associate-*l/61.7%
*-un-lft-identity61.7%
Applied egg-rr61.7%
Taylor expanded in c around 0 70.0%
associate-/l*79.8%
Simplified79.8%
Final simplification85.5%
(FPCore (a b c d)
:precision binary64
(if (<= d -5.5e+29)
(+ (/ b d) (* (/ c d) (/ a d)))
(if (<= d 3.6e-121)
(+ (/ a c) (/ (/ (* b d) c) c))
(if (<= d 2.75e+28)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(/ (+ b (/ a (/ d c))) (hypot c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5.5e+29) {
tmp = (b / d) + ((c / d) * (a / d));
} else if (d <= 3.6e-121) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 2.75e+28) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (b + (a / (d / c))) / hypot(c, d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -5.5e+29) {
tmp = (b / d) + ((c / d) * (a / d));
} else if (d <= 3.6e-121) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 2.75e+28) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (b + (a / (d / c))) / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -5.5e+29: tmp = (b / d) + ((c / d) * (a / d)) elif d <= 3.6e-121: tmp = (a / c) + (((b * d) / c) / c) elif d <= 2.75e+28: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = (b + (a / (d / c))) / math.hypot(c, d) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -5.5e+29) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); elseif (d <= 3.6e-121) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); elseif (d <= 2.75e+28) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / hypot(c, d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -5.5e+29) tmp = (b / d) + ((c / d) * (a / d)); elseif (d <= 3.6e-121) tmp = (a / c) + (((b * d) / c) / c); elseif (d <= 2.75e+28) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = (b + (a / (d / c))) / hypot(c, d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -5.5e+29], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.6e-121], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.75e+28], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.5 \cdot 10^{+29}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{elif}\;d \leq 3.6 \cdot 10^{-121}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 2.75 \cdot 10^{+28}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -5.5e29Initial program 44.9%
Taylor expanded in c around 0 67.4%
associate-/l*68.7%
Simplified68.7%
unpow268.7%
*-un-lft-identity68.7%
times-frac73.2%
Applied egg-rr73.2%
/-rgt-identity73.2%
*-un-lft-identity73.2%
*-commutative73.2%
times-frac75.3%
clear-num75.3%
Applied egg-rr75.3%
if -5.5e29 < d < 3.59999999999999984e-121Initial program 73.0%
Taylor expanded in c around inf 82.3%
associate-/l*82.3%
associate-/r/80.0%
Simplified80.0%
pow280.0%
associate-*l/82.3%
associate-/r*92.1%
Applied egg-rr92.1%
if 3.59999999999999984e-121 < d < 2.7500000000000002e28Initial program 84.8%
if 2.7500000000000002e28 < d Initial program 41.2%
*-un-lft-identity41.2%
+-commutative41.2%
fma-udef41.2%
add-sqr-sqrt41.2%
times-frac41.3%
fma-udef41.3%
+-commutative41.3%
hypot-def41.3%
fma-def41.3%
fma-udef41.3%
+-commutative41.3%
hypot-def61.6%
Applied egg-rr61.6%
associate-*l/61.7%
*-un-lft-identity61.7%
Applied egg-rr61.7%
Taylor expanded in c around 0 70.0%
associate-/l*79.8%
Simplified79.8%
Final simplification85.4%
(FPCore (a b c d)
:precision binary64
(if (<= d -3e+30)
(/ (- (/ (- a) (/ d c)) b) (hypot c d))
(if (<= d 2.1e-121)
(+ (/ a c) (/ (/ (* b d) c) c))
(if (<= d 3.3e+28)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(/ (+ b (/ a (/ d c))) (hypot c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3e+30) {
tmp = ((-a / (d / c)) - b) / hypot(c, d);
} else if (d <= 2.1e-121) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 3.3e+28) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (b + (a / (d / c))) / hypot(c, d);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3e+30) {
tmp = ((-a / (d / c)) - b) / Math.hypot(c, d);
} else if (d <= 2.1e-121) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 3.3e+28) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = (b + (a / (d / c))) / Math.hypot(c, d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -3e+30: tmp = ((-a / (d / c)) - b) / math.hypot(c, d) elif d <= 2.1e-121: tmp = (a / c) + (((b * d) / c) / c) elif d <= 3.3e+28: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = (b + (a / (d / c))) / math.hypot(c, d) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -3e+30) tmp = Float64(Float64(Float64(Float64(-a) / Float64(d / c)) - b) / hypot(c, d)); elseif (d <= 2.1e-121) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); elseif (d <= 3.3e+28) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / hypot(c, d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -3e+30) tmp = ((-a / (d / c)) - b) / hypot(c, d); elseif (d <= 2.1e-121) tmp = (a / c) + (((b * d) / c) / c); elseif (d <= 3.3e+28) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = (b + (a / (d / c))) / hypot(c, d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -3e+30], N[(N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.1e-121], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.3e+28], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3 \cdot 10^{+30}:\\
\;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-121}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 3.3 \cdot 10^{+28}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
\end{array}
if d < -2.99999999999999978e30Initial program 44.9%
*-un-lft-identity44.9%
+-commutative44.9%
fma-udef44.9%
add-sqr-sqrt44.9%
times-frac44.8%
fma-udef44.8%
+-commutative44.8%
hypot-def44.8%
fma-def44.8%
fma-udef44.8%
+-commutative44.8%
hypot-def56.6%
Applied egg-rr56.6%
associate-*l/56.7%
*-un-lft-identity56.7%
Applied egg-rr56.7%
Taylor expanded in d around -inf 70.1%
mul-1-neg70.1%
unsub-neg70.1%
neg-mul-170.1%
associate-/l*75.8%
Simplified75.8%
if -2.99999999999999978e30 < d < 2.0999999999999999e-121Initial program 73.0%
Taylor expanded in c around inf 82.3%
associate-/l*82.3%
associate-/r/80.0%
Simplified80.0%
pow280.0%
associate-*l/82.3%
associate-/r*92.1%
Applied egg-rr92.1%
if 2.0999999999999999e-121 < d < 3.3e28Initial program 84.8%
if 3.3e28 < d Initial program 41.2%
*-un-lft-identity41.2%
+-commutative41.2%
fma-udef41.2%
add-sqr-sqrt41.2%
times-frac41.3%
fma-udef41.3%
+-commutative41.3%
hypot-def41.3%
fma-def41.3%
fma-udef41.3%
+-commutative41.3%
hypot-def61.6%
Applied egg-rr61.6%
associate-*l/61.7%
*-un-lft-identity61.7%
Applied egg-rr61.7%
Taylor expanded in c around 0 70.0%
associate-/l*79.8%
Simplified79.8%
Final simplification85.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ b d) (* (/ c d) (/ a d)))))
(if (<= d -5.6e+29)
t_0
(if (<= d 2.45e-121)
(+ (/ a c) (/ (/ (* b d) c) c))
(if (<= d 3.3e+28) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = (b / d) + ((c / d) * (a / d));
double tmp;
if (d <= -5.6e+29) {
tmp = t_0;
} else if (d <= 2.45e-121) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 3.3e+28) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
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 = (b / d) + ((c / d) * (a / d))
if (d <= (-5.6d+29)) then
tmp = t_0
else if (d <= 2.45d-121) then
tmp = (a / c) + (((b * d) / c) / c)
else if (d <= 3.3d+28) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b / d) + ((c / d) * (a / d));
double tmp;
if (d <= -5.6e+29) {
tmp = t_0;
} else if (d <= 2.45e-121) {
tmp = (a / c) + (((b * d) / c) / c);
} else if (d <= 3.3e+28) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b / d) + ((c / d) * (a / d)) tmp = 0 if d <= -5.6e+29: tmp = t_0 elif d <= 2.45e-121: tmp = (a / c) + (((b * d) / c) / c) elif d <= 3.3e+28: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))) tmp = 0.0 if (d <= -5.6e+29) tmp = t_0; elseif (d <= 2.45e-121) tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); elseif (d <= 3.3e+28) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b / d) + ((c / d) * (a / d)); tmp = 0.0; if (d <= -5.6e+29) tmp = t_0; elseif (d <= 2.45e-121) tmp = (a / c) + (((b * d) / c) / c); elseif (d <= 3.3e+28) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.6e+29], t$95$0, If[LessEqual[d, 2.45e-121], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.3e+28], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{if}\;d \leq -5.6 \cdot 10^{+29}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 2.45 \cdot 10^{-121}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{elif}\;d \leq 3.3 \cdot 10^{+28}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if d < -5.5999999999999999e29 or 3.3e28 < d Initial program 42.8%
Taylor expanded in c around 0 64.2%
associate-/l*66.8%
Simplified66.8%
unpow266.8%
*-un-lft-identity66.8%
times-frac72.4%
Applied egg-rr72.4%
/-rgt-identity72.4%
*-un-lft-identity72.4%
*-commutative72.4%
times-frac77.7%
clear-num77.7%
Applied egg-rr77.7%
if -5.5999999999999999e29 < d < 2.45e-121Initial program 73.0%
Taylor expanded in c around inf 82.3%
associate-/l*82.3%
associate-/r/80.0%
Simplified80.0%
pow280.0%
associate-*l/82.3%
associate-/r*92.1%
Applied egg-rr92.1%
if 2.45e-121 < d < 3.3e28Initial program 84.8%
Final simplification85.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.6e+111) (not (<= d 9.5e-30))) (/ b d) (+ (/ a c) (/ (/ (* b d) c) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.6e+111) || !(d <= 9.5e-30)) {
tmp = b / d;
} else {
tmp = (a / c) + (((b * d) / 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 ((d <= (-3.6d+111)) .or. (.not. (d <= 9.5d-30))) then
tmp = b / d
else
tmp = (a / c) + (((b * d) / c) / c)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.6e+111) || !(d <= 9.5e-30)) {
tmp = b / d;
} else {
tmp = (a / c) + (((b * d) / c) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.6e+111) or not (d <= 9.5e-30): tmp = b / d else: tmp = (a / c) + (((b * d) / c) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.6e+111) || !(d <= 9.5e-30)) tmp = Float64(b / d); else tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -3.6e+111) || ~((d <= 9.5e-30))) tmp = b / d; else tmp = (a / c) + (((b * d) / c) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.6e+111], N[Not[LessEqual[d, 9.5e-30]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.6 \cdot 10^{+111} \lor \neg \left(d \leq 9.5 \cdot 10^{-30}\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -3.6000000000000002e111 or 9.49999999999999939e-30 < d Initial program 44.1%
Taylor expanded in c around 0 61.0%
if -3.6000000000000002e111 < d < 9.49999999999999939e-30Initial program 74.2%
Taylor expanded in c around inf 75.7%
associate-/l*75.7%
associate-/r/73.3%
Simplified73.3%
pow273.3%
associate-*l/75.7%
associate-/r*84.8%
Applied egg-rr84.8%
Final simplification75.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -7.4e+30) (not (<= d 5.4e-32))) (+ (/ b d) (* (/ c d) (/ a d))) (+ (/ a c) (/ (/ (* b d) c) c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.4e+30) || !(d <= 5.4e-32)) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + (((b * d) / 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 ((d <= (-7.4d+30)) .or. (.not. (d <= 5.4d-32))) then
tmp = (b / d) + ((c / d) * (a / d))
else
tmp = (a / c) + (((b * d) / c) / c)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -7.4e+30) || !(d <= 5.4e-32)) {
tmp = (b / d) + ((c / d) * (a / d));
} else {
tmp = (a / c) + (((b * d) / c) / c);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -7.4e+30) or not (d <= 5.4e-32): tmp = (b / d) + ((c / d) * (a / d)) else: tmp = (a / c) + (((b * d) / c) / c) return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -7.4e+30) || !(d <= 5.4e-32)) tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d))); else tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -7.4e+30) || ~((d <= 5.4e-32))) tmp = (b / d) + ((c / d) * (a / d)); else tmp = (a / c) + (((b * d) / c) / c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.4e+30], N[Not[LessEqual[d, 5.4e-32]], $MachinePrecision]], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.4 \cdot 10^{+30} \lor \neg \left(d \leq 5.4 \cdot 10^{-32}\right):\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if d < -7.40000000000000032e30 or 5.39999999999999962e-32 < d Initial program 46.4%
Taylor expanded in c around 0 65.3%
associate-/l*67.8%
Simplified67.8%
unpow267.8%
*-un-lft-identity67.8%
times-frac72.9%
Applied egg-rr72.9%
/-rgt-identity72.9%
*-un-lft-identity72.9%
*-commutative72.9%
times-frac77.8%
clear-num77.8%
Applied egg-rr77.8%
if -7.40000000000000032e30 < d < 5.39999999999999962e-32Initial program 74.4%
Taylor expanded in c around inf 78.7%
associate-/l*78.8%
associate-/r/76.8%
Simplified76.8%
pow276.8%
associate-*l/78.7%
associate-/r*87.8%
Applied egg-rr87.8%
Final simplification83.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.05e-85) (not (<= c 3.5e-25))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.05e-85) || !(c <= 3.5e-25)) {
tmp = a / 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.05d-85)) .or. (.not. (c <= 3.5d-25))) then
tmp = a / 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.05e-85) || !(c <= 3.5e-25)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.05e-85) or not (c <= 3.5e-25): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.05e-85) || !(c <= 3.5e-25)) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.05e-85) || ~((c <= 3.5e-25))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.05e-85], N[Not[LessEqual[c, 3.5e-25]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.05 \cdot 10^{-85} \lor \neg \left(c \leq 3.5 \cdot 10^{-25}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -2.04999999999999997e-85 or 3.5000000000000002e-25 < c Initial program 50.3%
Taylor expanded in c around inf 64.5%
if -2.04999999999999997e-85 < c < 3.5000000000000002e-25Initial program 76.7%
Taylor expanded in c around 0 67.4%
Final simplification65.8%
(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 61.8%
Taylor expanded in c around inf 47.3%
Final simplification47.3%
(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 2023322
(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))))