Complex division, real part

?

Percentage Accurate: 61.6% → 86.0%
Time: 13.2s
Precision: binary64
Cost: 20560

?

\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
\[\begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \frac{c}{\frac{d}{a}}\\ \mathbf{if}\;d \leq -5.6 \cdot 10^{+141}:\\ \;\;\;\;\frac{b}{d} + \frac{t_1}{d}\\ \mathbf{elif}\;d \leq -9.5 \cdot 10^{-134}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.3 \cdot 10^{-76}:\\ \;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{+71}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + t_1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
(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 (* (/ 1.0 (hypot c d)) (/ (fma a c (* d b)) (hypot c d))))
        (t_1 (/ c (/ d a))))
   (if (<= d -5.6e+141)
     (+ (/ b d) (/ t_1 d))
     (if (<= d -9.5e-134)
       t_0
       (if (<= d 1.3e-76)
         (+ (/ a c) (/ (* b (/ d c)) c))
         (if (<= d 2.9e+71) t_0 (/ (+ b t_1) (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 = (1.0 / hypot(c, d)) * (fma(a, c, (d * b)) / hypot(c, d));
	double t_1 = c / (d / a);
	double tmp;
	if (d <= -5.6e+141) {
		tmp = (b / d) + (t_1 / d);
	} else if (d <= -9.5e-134) {
		tmp = t_0;
	} else if (d <= 1.3e-76) {
		tmp = (a / c) + ((b * (d / c)) / c);
	} else if (d <= 2.9e+71) {
		tmp = t_0;
	} else {
		tmp = (b + t_1) / 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 = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(d * b)) / hypot(c, d)))
	t_1 = Float64(c / Float64(d / a))
	tmp = 0.0
	if (d <= -5.6e+141)
		tmp = Float64(Float64(b / d) + Float64(t_1 / d));
	elseif (d <= -9.5e-134)
		tmp = t_0;
	elseif (d <= 1.3e-76)
		tmp = Float64(Float64(a / c) + Float64(Float64(b * Float64(d / c)) / c));
	elseif (d <= 2.9e+71)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + t_1) / 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[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.6e+141], N[(N[(b / d), $MachinePrecision] + N[(t$95$1 / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -9.5e-134], t$95$0, If[LessEqual[d, 1.3e-76], N[(N[(a / c), $MachinePrecision] + N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.9e+71], t$95$0, N[(N[(b + t$95$1), $MachinePrecision] / 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 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \frac{c}{\frac{d}{a}}\\
\mathbf{if}\;d \leq -5.6 \cdot 10^{+141}:\\
\;\;\;\;\frac{b}{d} + \frac{t_1}{d}\\

\mathbf{elif}\;d \leq -9.5 \cdot 10^{-134}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 1.3 \cdot 10^{-76}:\\
\;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\

\mathbf{elif}\;d \leq 2.9 \cdot 10^{+71}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{b + t_1}{\mathsf{hypot}\left(c, d\right)}\\


\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 15 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Target

Original61.6%
Target99.4%
Herbie86.0%
\[\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} \]

Derivation?

  1. Split input into 4 regimes
  2. if d < -5.59999999999999982e141

    1. Initial program 24.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Applied egg-rr54.0%

      \[\leadsto \color{blue}{\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)}} \]
      Step-by-step derivation

      [Start]24.0%

      \[ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]

      *-un-lft-identity [=>]24.0%

      \[ \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]

      add-sqr-sqrt [=>]24.0%

      \[ \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]

      times-frac [=>]24.0%

      \[ \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]

      hypot-def [=>]24.0%

      \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]

      fma-def [=>]24.0%

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]

      hypot-def [=>]54.0%

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Taylor expanded in c around 0 80.9%

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}} \]
    4. Simplified89.2%

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}} \]
      Step-by-step derivation

      [Start]80.9%

      \[ \frac{b}{d} + \frac{c \cdot a}{{d}^{2}} \]

      unpow2 [=>]80.9%

      \[ \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]

      times-frac [=>]89.2%

      \[ \frac{b}{d} + \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
    5. Applied egg-rr89.3%

      \[\leadsto \frac{b}{d} + \color{blue}{\frac{\frac{c}{d} \cdot a}{d}} \]
      Step-by-step derivation

      [Start]89.2%

      \[ \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d} \]

      associate-*r/ [=>]89.3%

      \[ \frac{b}{d} + \color{blue}{\frac{\frac{c}{d} \cdot a}{d}} \]
    6. Applied egg-rr89.3%

      \[\leadsto \frac{b}{d} + \frac{\color{blue}{\frac{c}{\frac{d}{a}}}}{d} \]
      Step-by-step derivation

      [Start]89.3%

      \[ \frac{b}{d} + \frac{\frac{c}{d} \cdot a}{d} \]

      associate-/r/ [<=]89.3%

      \[ \frac{b}{d} + \frac{\color{blue}{\frac{c}{\frac{d}{a}}}}{d} \]

    if -5.59999999999999982e141 < d < -9.5000000000000008e-134 or 1.3e-76 < d < 2.90000000000000007e71

    1. Initial program 80.2%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Applied egg-rr85.3%

      \[\leadsto \color{blue}{\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)}} \]
      Step-by-step derivation

      [Start]80.2%

      \[ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]

      *-un-lft-identity [=>]80.2%

      \[ \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]

      add-sqr-sqrt [=>]80.2%

      \[ \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]

      times-frac [=>]80.1%

      \[ \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]

      hypot-def [=>]80.1%

      \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]

      fma-def [=>]80.1%

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]

      hypot-def [=>]85.3%

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]

    if -9.5000000000000008e-134 < d < 1.3e-76

    1. Initial program 68.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Applied egg-rr82.6%

      \[\leadsto \color{blue}{\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)}} \]
      Step-by-step derivation

      [Start]68.7%

      \[ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]

      *-un-lft-identity [=>]68.7%

      \[ \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]

      add-sqr-sqrt [=>]68.7%

      \[ \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]

      times-frac [=>]68.6%

      \[ \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]

      hypot-def [=>]68.6%

      \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]

      fma-def [=>]68.6%

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]

      hypot-def [=>]82.6%

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Taylor expanded in c around inf 88.8%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    4. Simplified95.7%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}} \]
      Step-by-step derivation

      [Start]88.8%

      \[ \frac{a}{c} + \frac{d \cdot b}{{c}^{2}} \]

      unpow2 [=>]88.8%

      \[ \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]

      times-frac [=>]95.7%

      \[ \frac{a}{c} + \color{blue}{\frac{d}{c} \cdot \frac{b}{c}} \]
    5. Applied egg-rr97.8%

      \[\leadsto \frac{a}{c} + \color{blue}{\frac{\frac{d}{c} \cdot b}{c}} \]
      Step-by-step derivation

      [Start]95.7%

      \[ \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c} \]

      associate-*r/ [=>]97.8%

      \[ \frac{a}{c} + \color{blue}{\frac{\frac{d}{c} \cdot b}{c}} \]

    if 2.90000000000000007e71 < d

    1. Initial program 50.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Applied egg-rr64.6%

      \[\leadsto \color{blue}{\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)}} \]
      Step-by-step derivation

      [Start]50.7%

      \[ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]

      *-un-lft-identity [=>]50.7%

      \[ \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]

      add-sqr-sqrt [=>]50.7%

      \[ \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]

      times-frac [=>]50.5%

      \[ \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]

      hypot-def [=>]50.5%

      \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]

      fma-def [=>]50.5%

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]

      hypot-def [=>]64.6%

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Taylor expanded in c around 0 94.2%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b + \frac{c \cdot a}{d}\right)} \]
    4. Applied egg-rr94.9%

      \[\leadsto \color{blue}{\frac{b + \frac{c}{\frac{d}{a}}}{\mathsf{hypot}\left(c, d\right)}} \]
      Step-by-step derivation

      [Start]94.2%

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \frac{c \cdot a}{d}\right) \]

      associate-*l/ [=>]94.6%

      \[ \color{blue}{\frac{1 \cdot \left(b + \frac{c \cdot a}{d}\right)}{\mathsf{hypot}\left(c, d\right)}} \]

      *-un-lft-identity [<=]94.6%

      \[ \frac{\color{blue}{b + \frac{c \cdot a}{d}}}{\mathsf{hypot}\left(c, d\right)} \]

      associate-/l* [=>]94.9%

      \[ \frac{b + \color{blue}{\frac{c}{\frac{d}{a}}}}{\mathsf{hypot}\left(c, d\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification92.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.6 \cdot 10^{+141}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c}{\frac{d}{a}}}{d}\\ \mathbf{elif}\;d \leq -9.5 \cdot 10^{-134}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 1.3 \cdot 10^{-76}:\\ \;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{+71}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy86.0%
Cost20560
\[\begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \frac{c}{\frac{d}{a}}\\ \mathbf{if}\;d \leq -5.6 \cdot 10^{+141}:\\ \;\;\;\;\frac{b}{d} + \frac{t_1}{d}\\ \mathbf{elif}\;d \leq -9.5 \cdot 10^{-134}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.3 \cdot 10^{-76}:\\ \;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{+71}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + t_1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 2
Accuracy83.3%
Cost7568
\[\begin{array}{l} t_0 := \frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\ t_1 := \frac{c}{\frac{d}{a}}\\ \mathbf{if}\;d \leq -4.4 \cdot 10^{+142}:\\ \;\;\;\;\frac{b}{d} + \frac{t_1}{d}\\ \mathbf{elif}\;d \leq -7.6 \cdot 10^{-130}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{-79}:\\ \;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 9 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + t_1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 3
Accuracy83.3%
Cost7568
\[\begin{array}{l} t_0 := d \cdot d + c \cdot c\\ t_1 := b + \frac{c}{\frac{d}{a}}\\ \mathbf{if}\;d \leq -1.9 \cdot 10^{+93}:\\ \;\;\;\;t_1 \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -3.3 \cdot 10^{-128}:\\ \;\;\;\;\frac{d}{\frac{t_0}{b}} + \frac{c}{\frac{t_0}{a}}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{-79}:\\ \;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{+71}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 4
Accuracy83.1%
Cost1488
\[\begin{array}{l} t_0 := \frac{d \cdot b + c \cdot a}{d \cdot d + c \cdot c}\\ t_1 := \frac{b}{d} + \frac{\frac{c}{\frac{d}{a}}}{d}\\ \mathbf{if}\;d \leq -5.5 \cdot 10^{+141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-129}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 4 \cdot 10^{-79}:\\ \;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.32 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Accuracy69.1%
Cost1241
\[\begin{array}{l} t_0 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{if}\;d \leq -5.5 \cdot 10^{+60}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -520000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -3.1 \cdot 10^{-65}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 3.5 \cdot 10^{-59}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 7.6 \cdot 10^{+91} \lor \neg \left(d \leq 3.5 \cdot 10^{+99}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{a}{d \cdot d}\\ \end{array} \]
Alternative 6
Accuracy69.1%
Cost1240
\[\begin{array}{l} \mathbf{if}\;d \leq -1 \cdot 10^{+61}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -55000000:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -3.1 \cdot 10^{-65}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 7.2 \cdot 10^{-66}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq 5.1 \cdot 10^{+92}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 2.2 \cdot 10^{+99}:\\ \;\;\;\;c \cdot \frac{a}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
Alternative 7
Accuracy70.0%
Cost1240
\[\begin{array}{l} \mathbf{if}\;d \leq -2.05 \cdot 10^{+64}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -9500000:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -3 \cdot 10^{-65}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.1 \cdot 10^{-61}:\\ \;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 5.1 \cdot 10^{+92}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.6 \cdot 10^{+99}:\\ \;\;\;\;c \cdot \frac{a}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
Alternative 8
Accuracy63.3%
Cost976
\[\begin{array}{l} \mathbf{if}\;d \leq -1.45 \cdot 10^{-74}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.95 \cdot 10^{-44}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 5.1 \cdot 10^{+92}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{+99}:\\ \;\;\;\;c \cdot \frac{a}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
Alternative 9
Accuracy76.8%
Cost969
\[\begin{array}{l} \mathbf{if}\;d \leq -2.1 \cdot 10^{-69} \lor \neg \left(d \leq 1.15 \cdot 10^{-57}\right):\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\ \end{array} \]
Alternative 10
Accuracy75.2%
Cost968
\[\begin{array}{l} \mathbf{if}\;d \leq -2.1 \cdot 10^{-69}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq 3.5 \cdot 10^{-66}:\\ \;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + a \cdot \frac{c}{d \cdot d}\\ \end{array} \]
Alternative 11
Accuracy75.2%
Cost968
\[\begin{array}{l} \mathbf{if}\;d \leq -3.1 \cdot 10^{-65}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq 7 \cdot 10^{-66}:\\ \;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{\frac{d \cdot d}{c}}\\ \end{array} \]
Alternative 12
Accuracy75.1%
Cost968
\[\begin{array}{l} \mathbf{if}\;d \leq -3.1 \cdot 10^{-65}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{-67}:\\ \;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c \cdot a}{d \cdot d}\\ \end{array} \]
Alternative 13
Accuracy75.1%
Cost968
\[\begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{-70}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c}{\frac{d}{a}}}{d}\\ \mathbf{elif}\;d \leq 1.65 \cdot 10^{-66}:\\ \;\;\;\;\frac{a}{c} + \frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c \cdot a}{d \cdot d}\\ \end{array} \]
Alternative 14
Accuracy63.4%
Cost456
\[\begin{array}{l} \mathbf{if}\;d \leq -1.3 \cdot 10^{-74}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 5.2 \cdot 10^{-48}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
Alternative 15
Accuracy42.6%
Cost192
\[\frac{a}{c} \]

Reproduce?

herbie shell --seed 2023272 
(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))))