Average Error: 25.7 → 18.2
Time: 1.3m
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} \lor \neg \left(c \le 1.6654143669342526 \cdot 10^{+98}\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{d \cdot b + a \cdot c}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{\sqrt{d \cdot d + c \cdot c}}}}{\sqrt{\sqrt{\sqrt{d \cdot d + c \cdot c}}}} \cdot \frac{1}{\sqrt{\sqrt{\sqrt{d \cdot d + c \cdot 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.2
\[\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 div-inv39.4

      \[\leadsto \frac{\color{blue}{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt39.4

      \[\leadsto \frac{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\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}}}}\]
    9. Applied associate-/r*39.4

      \[\leadsto \color{blue}{\frac{\frac{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}\]
    10. 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 div-inv18.5

      \[\leadsto \frac{\color{blue}{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt18.6

      \[\leadsto \frac{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\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}}}}\]
    9. Applied associate-/r*18.7

      \[\leadsto \color{blue}{\frac{\frac{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}\]
    10. Using strategy rm
    11. Applied add-sqr-sqrt18.7

      \[\leadsto \frac{\frac{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\color{blue}{\sqrt{\sqrt{\sqrt{c \cdot c + d \cdot d}}} \cdot \sqrt{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}}\]
    12. Applied *-un-lft-identity18.7

      \[\leadsto \frac{\color{blue}{1 \cdot \frac{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}}{\sqrt{\sqrt{\sqrt{c \cdot c + d \cdot d}}} \cdot \sqrt{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}\]
    13. Applied times-frac18.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -1.7035520925716615 \cdot 10^{+115} \lor \neg \left(c \le 1.6654143669342526 \cdot 10^{+98}\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{d \cdot b + a \cdot c}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{\sqrt{d \cdot d + c \cdot c}}}}{\sqrt{\sqrt{\sqrt{d \cdot d + c \cdot c}}}} \cdot \frac{1}{\sqrt{\sqrt{\sqrt{d \cdot d + c \cdot c}}}}\\ \end{array}\]

Runtime

Time bar (total: 1.3m)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))))