Complex division, real part

Percentage Accurate: 62.1% → 83.7%
Time: 6.1s
Alternatives: 10
Speedup: 5.0×

Specification

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

Your Program's Arguments

Results

Enter valid numbers for all inputs

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.

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
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.

Alternative 1: 83.7% accurate, 0.6× speedup?

\[\begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b}}\\ \mathbf{if}\;c \leq -1.15 \cdot 10^{+81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -2.2 \cdot 10^{-97}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{-80}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\\ \mathbf{elif}\;c \leq 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Derivation
  1. Split input into 3 regimes
  2. if c < -1.1499999999999999e81 or 1.00000000000000007e70 < c

    1. Initial program 35.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around inf 72.3%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Step-by-step derivation
      1. unpow272.3%

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac82.7%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}} \]
    5. Step-by-step derivation
      1. clear-num83.6%

        \[\leadsto \frac{a}{c} + \frac{d}{c} \cdot \color{blue}{\frac{1}{\frac{c}{b}}} \]
      2. un-div-inv83.6%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{\frac{d}{c}}{\frac{c}{b}}} \]
    6. Applied egg-rr83.6%

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

    if -1.1499999999999999e81 < c < -2.1999999999999999e-97 or 2.2000000000000001e-80 < c < 1.00000000000000007e70

    1. Initial program 87.9%

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

    if -2.1999999999999999e-97 < c < 2.2000000000000001e-80

    1. Initial program 67.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity67.7%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt67.7%

        \[\leadsto \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}}} \]
      3. times-frac67.7%

        \[\leadsto \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}}} \]
      4. hypot-def67.7%

        \[\leadsto \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}} \]
      5. fma-def67.7%

        \[\leadsto \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}} \]
      6. hypot-def83.5%

        \[\leadsto \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. Applied egg-rr83.5%

      \[\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)}} \]
    4. Taylor expanded in c around 0 58.5%

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

      \[\leadsto \color{blue}{\frac{1}{d}} \cdot \left(b + \frac{c \cdot a}{d}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification88.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.15 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b}}\\ \mathbf{elif}\;c \leq -2.2 \cdot 10^{-97}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{-80}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\\ \mathbf{elif}\;c \leq 10^{+70}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b}}\\ \end{array} \]

Alternative 2: 86.0% accurate, 0.0× speedup?

\[\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}{c} + \frac{\frac{d}{c}}{\frac{c}{b}}\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0

    1. Initial program 77.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity77.7%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt77.7%

        \[\leadsto \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}}} \]
      3. times-frac77.8%

        \[\leadsto \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}}} \]
      4. hypot-def77.8%

        \[\leadsto \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}} \]
      5. fma-def77.8%

        \[\leadsto \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}} \]
      6. hypot-def93.9%

        \[\leadsto \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. Applied egg-rr93.9%

      \[\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)}} \]

    if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 0.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around inf 45.6%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Step-by-step derivation
      1. unpow245.6%

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac56.9%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{d}{c} \cdot \frac{b}{c}} \]
    4. Simplified56.9%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}} \]
    5. Step-by-step derivation
      1. clear-num56.9%

        \[\leadsto \frac{a}{c} + \frac{d}{c} \cdot \color{blue}{\frac{1}{\frac{c}{b}}} \]
      2. un-div-inv57.0%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{\frac{d}{c}}{\frac{c}{b}}} \]
    6. Applied egg-rr57.0%

      \[\leadsto \frac{a}{c} + \color{blue}{\frac{\frac{d}{c}}{\frac{c}{b}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.8%

    \[\leadsto \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}{c} + \frac{\frac{d}{c}}{\frac{c}{b}}\\ \end{array} \]

Alternative 3: 71.6% accurate, 0.8× speedup?

\[\begin{array}{l} \mathbf{if}\;c \leq -2.2 \cdot 10^{+22} \lor \neg \left(c \leq -1.85 \cdot 10^{-71}\right) \land \left(c \leq -1.55 \cdot 10^{-94} \lor \neg \left(c \leq 5.2 \cdot 10^{+67}\right)\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if c < -2.2e22 or -1.8499999999999998e-71 < c < -1.5499999999999999e-94 or 5.2000000000000001e67 < c

    1. Initial program 45.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around inf 71.0%

      \[\leadsto \color{blue}{\frac{a}{c}} \]

    if -2.2e22 < c < -1.8499999999999998e-71 or -1.5499999999999999e-94 < c < 5.2000000000000001e67

    1. Initial program 74.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity74.0%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt74.0%

        \[\leadsto \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}}} \]
      3. times-frac74.0%

        \[\leadsto \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}}} \]
      4. hypot-def74.0%

        \[\leadsto \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}} \]
      5. fma-def74.0%

        \[\leadsto \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}} \]
      6. hypot-def85.4%

        \[\leadsto \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. Applied egg-rr85.4%

      \[\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)}} \]
    4. Taylor expanded in c around 0 50.6%

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

      \[\leadsto \color{blue}{\frac{1}{d}} \cdot \left(b + \frac{c \cdot a}{d}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.2 \cdot 10^{+22} \lor \neg \left(c \leq -1.85 \cdot 10^{-71}\right) \land \left(c \leq -1.55 \cdot 10^{-94} \lor \neg \left(c \leq 5.2 \cdot 10^{+67}\right)\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\\ \end{array} \]

Alternative 4: 77.5% accurate, 0.8× speedup?

\[\begin{array}{l} \mathbf{if}\;c \leq -1.5 \cdot 10^{-21} \lor \neg \left(c \leq -6.8 \cdot 10^{-67} \lor \neg \left(c \leq -1.5 \cdot 10^{-94}\right) \land c \leq 5 \cdot 10^{+31}\right):\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if c < -1.49999999999999996e-21 or -6.8000000000000002e-67 < c < -1.5000000000000001e-94 or 5.00000000000000027e31 < c

    1. Initial program 51.6%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around inf 71.0%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Step-by-step derivation
      1. unpow271.0%

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac77.7%

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

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

    if -1.49999999999999996e-21 < c < -6.8000000000000002e-67 or -1.5000000000000001e-94 < c < 5.00000000000000027e31

    1. Initial program 71.2%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity71.2%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt71.2%

        \[\leadsto \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}}} \]
      3. times-frac71.2%

        \[\leadsto \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}}} \]
      4. hypot-def71.2%

        \[\leadsto \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}} \]
      5. fma-def71.2%

        \[\leadsto \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}} \]
      6. hypot-def84.2%

        \[\leadsto \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. Applied egg-rr84.2%

      \[\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)}} \]
    4. Taylor expanded in c around 0 54.8%

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

      \[\leadsto \color{blue}{\frac{1}{d}} \cdot \left(b + \frac{c \cdot a}{d}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification81.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.5 \cdot 10^{-21} \lor \neg \left(c \leq -6.8 \cdot 10^{-67} \lor \neg \left(c \leq -1.5 \cdot 10^{-94}\right) \land c \leq 5 \cdot 10^{+31}\right):\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\\ \end{array} \]

Alternative 5: 77.6% accurate, 0.8× speedup?

\[\begin{array}{l} \mathbf{if}\;c \leq -1.45 \cdot 10^{-21} \lor \neg \left(c \leq -3.4 \cdot 10^{-61}\right) \land \left(c \leq -1.55 \cdot 10^{-94} \lor \neg \left(c \leq 6.4 \cdot 10^{+31}\right)\right):\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if c < -1.45e-21 or -3.3999999999999998e-61 < c < -1.5499999999999999e-94 or 6.4000000000000001e31 < c

    1. Initial program 51.6%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around inf 71.0%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Step-by-step derivation
      1. unpow271.0%

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac77.7%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}} \]
    5. Step-by-step derivation
      1. clear-num78.3%

        \[\leadsto \frac{a}{c} + \frac{d}{c} \cdot \color{blue}{\frac{1}{\frac{c}{b}}} \]
      2. un-div-inv78.4%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{\frac{d}{c}}{\frac{c}{b}}} \]
    6. Applied egg-rr78.4%

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

    if -1.45e-21 < c < -3.3999999999999998e-61 or -1.5499999999999999e-94 < c < 6.4000000000000001e31

    1. Initial program 71.2%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity71.2%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt71.2%

        \[\leadsto \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}}} \]
      3. times-frac71.2%

        \[\leadsto \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}}} \]
      4. hypot-def71.2%

        \[\leadsto \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}} \]
      5. fma-def71.2%

        \[\leadsto \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}} \]
      6. hypot-def84.2%

        \[\leadsto \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. Applied egg-rr84.2%

      \[\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)}} \]
    4. Taylor expanded in c around 0 54.8%

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

      \[\leadsto \color{blue}{\frac{1}{d}} \cdot \left(b + \frac{c \cdot a}{d}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification82.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.45 \cdot 10^{-21} \lor \neg \left(c \leq -3.4 \cdot 10^{-61}\right) \land \left(c \leq -1.55 \cdot 10^{-94} \lor \neg \left(c \leq 6.4 \cdot 10^{+31}\right)\right):\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\\ \end{array} \]

Alternative 6: 77.6% accurate, 0.8× speedup?

\[\begin{array}{l} t_0 := \frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b}}\\ \mathbf{if}\;c \leq -6.8 \cdot 10^{-22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -1.9 \cdot 10^{-60}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -1.85 \cdot 10^{-96} \lor \neg \left(c \leq 5.4 \cdot 10^{+31}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\\ \end{array} \]
Derivation
  1. Split input into 3 regimes
  2. if c < -6.7999999999999997e-22 or -1.89999999999999997e-60 < c < -1.84999999999999993e-96 or 5.39999999999999971e31 < c

    1. Initial program 51.6%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around inf 71.0%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Step-by-step derivation
      1. unpow271.0%

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac77.7%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}} \]
    5. Step-by-step derivation
      1. clear-num78.3%

        \[\leadsto \frac{a}{c} + \frac{d}{c} \cdot \color{blue}{\frac{1}{\frac{c}{b}}} \]
      2. un-div-inv78.4%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{\frac{d}{c}}{\frac{c}{b}}} \]
    6. Applied egg-rr78.4%

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

    if -6.7999999999999997e-22 < c < -1.89999999999999997e-60

    1. Initial program 69.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around 0 86.8%

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}} \]
    3. Step-by-step derivation
      1. unpow286.8%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac86.8%

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
    4. Simplified86.8%

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

    if -1.84999999999999993e-96 < c < 5.39999999999999971e31

    1. Initial program 71.3%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity71.3%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt71.3%

        \[\leadsto \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}}} \]
      3. times-frac71.3%

        \[\leadsto \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}}} \]
      4. hypot-def71.3%

        \[\leadsto \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}} \]
      5. fma-def71.3%

        \[\leadsto \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}} \]
      6. hypot-def84.1%

        \[\leadsto \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. Applied egg-rr84.1%

      \[\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)}} \]
    4. Taylor expanded in c around 0 53.7%

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

      \[\leadsto \color{blue}{\frac{1}{d}} \cdot \left(b + \frac{c \cdot a}{d}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification82.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6.8 \cdot 10^{-22}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b}}\\ \mathbf{elif}\;c \leq -1.9 \cdot 10^{-60}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -1.85 \cdot 10^{-96} \lor \neg \left(c \leq 5.4 \cdot 10^{+31}\right):\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{c}}{\frac{c}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\\ \end{array} \]

Alternative 7: 61.5% accurate, 0.9× speedup?

\[\begin{array}{l} \mathbf{if}\;c \leq -1.62 \cdot 10^{-15}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -4.7 \cdot 10^{-68}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq -1.02 \cdot 10^{-97}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{-164}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 2.7 \cdot 10^{-89}:\\ \;\;\;\;\frac{c}{d \cdot \frac{d}{a}}\\ \mathbf{elif}\;c \leq 1.02 \cdot 10^{+68}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
Derivation
  1. Split input into 3 regimes
  2. if c < -1.62000000000000009e-15 or -4.69999999999999988e-68 < c < -1.02000000000000004e-97 or 1.02e68 < c

    1. Initial program 49.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around inf 68.4%

      \[\leadsto \color{blue}{\frac{a}{c}} \]

    if -1.62000000000000009e-15 < c < -4.69999999999999988e-68 or -1.02000000000000004e-97 < c < 2.0999999999999999e-164 or 2.69999999999999988e-89 < c < 1.02e68

    1. Initial program 71.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around 0 69.9%

      \[\leadsto \color{blue}{\frac{b}{d}} \]

    if 2.0999999999999999e-164 < c < 2.69999999999999988e-89

    1. Initial program 80.2%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity80.2%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt80.2%

        \[\leadsto \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}}} \]
      3. times-frac80.6%

        \[\leadsto \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}}} \]
      4. hypot-def80.6%

        \[\leadsto \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}} \]
      5. fma-def80.6%

        \[\leadsto \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}} \]
      6. hypot-def90.1%

        \[\leadsto \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. Applied egg-rr90.1%

      \[\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)}} \]
    4. Taylor expanded in c around 0 51.2%

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

      \[\leadsto \color{blue}{\frac{1}{d}} \cdot \left(b + \frac{c \cdot a}{d}\right) \]
    6. Taylor expanded in d around 0 62.7%

      \[\leadsto \color{blue}{\frac{c \cdot a}{{d}^{2}}} \]
    7. Step-by-step derivation
      1. unpow262.7%

        \[\leadsto \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. associate-/l*62.7%

        \[\leadsto \color{blue}{\frac{c}{\frac{d \cdot d}{a}}} \]
      3. associate-*r/72.3%

        \[\leadsto \frac{c}{\color{blue}{d \cdot \frac{d}{a}}} \]
    8. Simplified72.3%

      \[\leadsto \color{blue}{\frac{c}{d \cdot \frac{d}{a}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification69.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.62 \cdot 10^{-15}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -4.7 \cdot 10^{-68}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq -1.02 \cdot 10^{-97}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{-164}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 2.7 \cdot 10^{-89}:\\ \;\;\;\;\frac{c}{d \cdot \frac{d}{a}}\\ \mathbf{elif}\;c \leq 1.02 \cdot 10^{+68}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 8: 73.0% accurate, 0.9× speedup?

\[\begin{array}{l} \mathbf{if}\;c \leq -1.95 \cdot 10^{+124}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -8.2 \cdot 10^{-98}:\\ \;\;\;\;a \cdot \frac{c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 5.5 \cdot 10^{+67}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
Derivation
  1. Split input into 3 regimes
  2. if c < -1.95e124 or 5.49999999999999968e67 < c

    1. Initial program 35.2%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around inf 75.4%

      \[\leadsto \color{blue}{\frac{a}{c}} \]

    if -1.95e124 < c < -8.1999999999999996e-98

    1. Initial program 84.1%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in a around inf 56.5%

      \[\leadsto \color{blue}{\frac{c \cdot a}{{d}^{2} + {c}^{2}}} \]
    3. Step-by-step derivation
      1. associate-/l*62.8%

        \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2} + {c}^{2}}{a}}} \]
      2. associate-/r/62.9%

        \[\leadsto \color{blue}{\frac{c}{{d}^{2} + {c}^{2}} \cdot a} \]
      3. unpow262.9%

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

        \[\leadsto \frac{c}{d \cdot d + \color{blue}{c \cdot c}} \cdot a \]
      5. fma-udef62.9%

        \[\leadsto \frac{c}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot a \]
    4. Simplified62.9%

      \[\leadsto \color{blue}{\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a} \]
    5. Step-by-step derivation
      1. fma-udef62.9%

        \[\leadsto \frac{c}{\color{blue}{d \cdot d + c \cdot c}} \cdot a \]
    6. Applied egg-rr62.9%

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

    if -8.1999999999999996e-98 < c < 5.49999999999999968e67

    1. Initial program 72.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity72.0%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt72.0%

        \[\leadsto \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}}} \]
      3. times-frac71.9%

        \[\leadsto \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}}} \]
      4. hypot-def71.9%

        \[\leadsto \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}} \]
      5. fma-def71.9%

        \[\leadsto \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}} \]
      6. hypot-def84.1%

        \[\leadsto \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. Applied egg-rr84.1%

      \[\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)}} \]
    4. Taylor expanded in c around 0 51.2%

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

      \[\leadsto \color{blue}{\frac{1}{d}} \cdot \left(b + \frac{c \cdot a}{d}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification77.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.95 \cdot 10^{+124}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -8.2 \cdot 10^{-98}:\\ \;\;\;\;a \cdot \frac{c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 5.5 \cdot 10^{+67}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 9: 62.9% accurate, 1.3× speedup?

\[\begin{array}{l} \mathbf{if}\;c \leq -1.45 \cdot 10^{-15}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -4.2 \cdot 10^{-68} \lor \neg \left(c \leq -1.35 \cdot 10^{-97}\right) \land c \leq 5.5 \cdot 10^{+67}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if c < -1.45000000000000009e-15 or -4.20000000000000016e-68 < c < -1.34999999999999993e-97 or 5.49999999999999968e67 < c

    1. Initial program 49.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around inf 68.4%

      \[\leadsto \color{blue}{\frac{a}{c}} \]

    if -1.45000000000000009e-15 < c < -4.20000000000000016e-68 or -1.34999999999999993e-97 < c < 5.49999999999999968e67

    1. Initial program 72.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Taylor expanded in c around 0 66.8%

      \[\leadsto \color{blue}{\frac{b}{d}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification67.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.45 \cdot 10^{-15}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -4.2 \cdot 10^{-68} \lor \neg \left(c \leq -1.35 \cdot 10^{-97}\right) \land c \leq 5.5 \cdot 10^{+67}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 10: 43.0% accurate, 5.0× speedup?

\[\frac{a}{c} \]
Derivation
  1. Initial program 60.7%

    \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
  2. Taylor expanded in c around inf 44.0%

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification44.0%

    \[\leadsto \frac{a}{c} \]

Developer target: 99.2% accurate, 0.1× speedup?

\[\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} \]

Reproduce

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