Average Error: 25.7 → 18.1
Time: 7.9m
Precision: 64
Internal Precision: 576
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -1.7035520925716615 \cdot 10^{+115}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \le 1.6654143669342526 \cdot 10^{+98}:\\ \;\;\;\;\frac{\frac{\frac{a \cdot c + d \cdot b}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original25.7
Target0.4
Herbie18.1
\[\begin{array}{l} \mathbf{if}\;\left|d\right| \lt \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 2 regimes
  2. if c < -1.7035520925716615e+115 or 1.6654143669342526e+98 < c

    1. Initial program 39.4

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt39.4

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied associate-/r*39.3

      \[\leadsto \color{blue}{\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt39.3

      \[\leadsto \frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}}\]
    7. Applied sqrt-prod39.4

      \[\leadsto \frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\color{blue}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}}\]
    8. Applied associate-/r*39.4

      \[\leadsto \color{blue}{\frac{\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}\]
    9. Taylor expanded around inf 17.2

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

    if -1.7035520925716615e+115 < c < 1.6654143669342526e+98

    1. Initial program 18.5

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt18.5

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied associate-/r*18.4

      \[\leadsto \color{blue}{\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt18.4

      \[\leadsto \frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}}\]
    7. Applied sqrt-prod18.6

      \[\leadsto \frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\color{blue}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}}\]
    8. Applied associate-/r*18.6

      \[\leadsto \color{blue}{\frac{\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification18.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -1.7035520925716615 \cdot 10^{+115}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \le 1.6654143669342526 \cdot 10^{+98}:\\ \;\;\;\;\frac{\frac{\frac{a \cdot c + d \cdot b}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array}\]

Runtime

Time bar (total: 7.9m)Debug logProfile

herbie shell --seed 2018234 
(FPCore (a b c d)
  :name "Complex division, real part"

  :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))))