(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma (/ d c) b a)))
(if (<= c -9.581051578847133e+165)
(/
(fma
(* (/ a c) (* d (/ d c)))
0.5
(- (* (pow (/ d c) 3.0) (* 0.5 b)) t_0))
(hypot c d))
(if (<= c 2.2976467137315726e+100)
(/
(fma
(* c a)
(/ 1.0 (hypot c d))
(pow (cbrt (/ d (/ (hypot d c) b))) 3.0))
(hypot c d))
(/ t_0 (hypot c d))))))double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
double t_0 = fma((d / c), b, a);
double tmp;
if (c <= -9.581051578847133e+165) {
tmp = fma(((a / c) * (d * (d / c))), 0.5, ((pow((d / c), 3.0) * (0.5 * b)) - t_0)) / hypot(c, d);
} else if (c <= 2.2976467137315726e+100) {
tmp = fma((c * a), (1.0 / hypot(c, d)), pow(cbrt((d / (hypot(d, c) / b))), 3.0)) / hypot(c, d);
} else {
tmp = t_0 / hypot(c, d);
}
return tmp;
}
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function code(a, b, c, d) t_0 = fma(Float64(d / c), b, a) tmp = 0.0 if (c <= -9.581051578847133e+165) tmp = Float64(fma(Float64(Float64(a / c) * Float64(d * Float64(d / c))), 0.5, Float64(Float64((Float64(d / c) ^ 3.0) * Float64(0.5 * b)) - t_0)) / hypot(c, d)); elseif (c <= 2.2976467137315726e+100) tmp = Float64(fma(Float64(c * a), Float64(1.0 / hypot(c, d)), (cbrt(Float64(d / Float64(hypot(d, c) / b))) ^ 3.0)) / hypot(c, d)); else tmp = Float64(t_0 / hypot(c, d)); end return tmp 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]
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision]}, If[LessEqual[c, -9.581051578847133e+165], N[(N[(N[(N[(a / c), $MachinePrecision] * N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[(N[Power[N[(d / c), $MachinePrecision], 3.0], $MachinePrecision] * N[(0.5 * b), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.2976467137315726e+100], N[(N[(N[(c * a), $MachinePrecision] * N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[Power[N[Power[N[(d / N[(N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{d}{c}, b, a\right)\\
\mathbf{if}\;c \leq -9.581051578847133 \cdot 10^{+165}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{c} \cdot \left(d \cdot \frac{d}{c}\right), 0.5, {\left(\frac{d}{c}\right)}^{3} \cdot \left(0.5 \cdot b\right) - t_0\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq 2.2976467137315726 \cdot 10^{+100}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c \cdot a, \frac{1}{\mathsf{hypot}\left(c, d\right)}, {\left(\sqrt[3]{\frac{d}{\frac{\mathsf{hypot}\left(d, c\right)}{b}}}\right)}^{3}\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}
| Original | 26.1 |
|---|---|
| Target | 0.5 |
| Herbie | 6.0 |
if c < -9.58105157884713253e165Initial program 45.1
Simplified45.1
Applied egg-rr31.5
Applied egg-rr31.5
Taylor expanded in c around -inf 25.0
Simplified6.5
if -9.58105157884713253e165 < c < 2.2976467137315726e100Initial program 19.5
Simplified19.5
Applied egg-rr12.5
Applied egg-rr12.4
Applied egg-rr12.5
Applied egg-rr4.8
if 2.2976467137315726e100 < c Initial program 38.5
Simplified38.5
Applied egg-rr25.7
Applied egg-rr25.6
Taylor expanded in c around inf 12.7
Simplified10.0
Final simplification6.0
herbie shell --seed 2022210
(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))))