Average Error: 26.3 → 13.2
Time: 18.6s
Precision: 64
Internal Precision: 128
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le -8.346460948837449 \cdot 10^{+220}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;d \le 1.0043357683224773 \cdot 10^{+119}:\\ \;\;\;\;\frac{\frac{(c \cdot a + \left(b \cdot d\right))_*}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{d^2 + c^2}^*}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original26.3
Target0.4
Herbie13.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 3 regimes
  2. if d < -8.346460948837449e+220

    1. Initial program 42.5

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified42.5

      \[\leadsto \color{blue}{\frac{(a \cdot c + \left(b \cdot d\right))_*}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt42.5

      \[\leadsto \frac{(a \cdot c + \left(b \cdot d\right))_*}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    5. Applied *-un-lft-identity42.5

      \[\leadsto \frac{\color{blue}{1 \cdot (a \cdot c + \left(b \cdot d\right))_*}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    6. Applied times-frac42.5

      \[\leadsto \color{blue}{\frac{1}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} \cdot \frac{(a \cdot c + \left(b \cdot d\right))_*}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    7. Simplified42.5

      \[\leadsto \color{blue}{\frac{1}{\sqrt{d^2 + c^2}^*}} \cdot \frac{(a \cdot c + \left(b \cdot d\right))_*}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    8. Simplified32.6

      \[\leadsto \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \color{blue}{\frac{(d \cdot b + \left(a \cdot c\right))_*}{\sqrt{d^2 + c^2}^*}}\]
    9. Using strategy rm
    10. Applied associate-*l/32.6

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{(d \cdot b + \left(a \cdot c\right))_*}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}}\]
    11. Simplified32.6

      \[\leadsto \frac{\color{blue}{\frac{(c \cdot a + \left(b \cdot d\right))_*}{\sqrt{d^2 + c^2}^*}}}{\sqrt{d^2 + c^2}^*}\]
    12. Using strategy rm
    13. Applied *-un-lft-identity32.6

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot (c \cdot a + \left(b \cdot d\right))_*}}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\]
    14. Applied associate-/l*32.6

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\sqrt{d^2 + c^2}^*}{(c \cdot a + \left(b \cdot d\right))_*}}}}{\sqrt{d^2 + c^2}^*}\]
    15. Taylor expanded around -inf 11.2

      \[\leadsto \frac{\color{blue}{-1 \cdot b}}{\sqrt{d^2 + c^2}^*}\]
    16. Simplified11.2

      \[\leadsto \frac{\color{blue}{-b}}{\sqrt{d^2 + c^2}^*}\]

    if -8.346460948837449e+220 < d < 1.0043357683224773e+119

    1. Initial program 21.3

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified21.3

      \[\leadsto \color{blue}{\frac{(a \cdot c + \left(b \cdot d\right))_*}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt21.3

      \[\leadsto \frac{(a \cdot c + \left(b \cdot d\right))_*}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    5. Applied *-un-lft-identity21.3

      \[\leadsto \frac{\color{blue}{1 \cdot (a \cdot c + \left(b \cdot d\right))_*}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    6. Applied times-frac21.3

      \[\leadsto \color{blue}{\frac{1}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} \cdot \frac{(a \cdot c + \left(b \cdot d\right))_*}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    7. Simplified21.3

      \[\leadsto \color{blue}{\frac{1}{\sqrt{d^2 + c^2}^*}} \cdot \frac{(a \cdot c + \left(b \cdot d\right))_*}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    8. Simplified12.9

      \[\leadsto \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \color{blue}{\frac{(d \cdot b + \left(a \cdot c\right))_*}{\sqrt{d^2 + c^2}^*}}\]
    9. Using strategy rm
    10. Applied associate-*l/12.8

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{(d \cdot b + \left(a \cdot c\right))_*}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}}\]
    11. Simplified12.8

      \[\leadsto \frac{\color{blue}{\frac{(c \cdot a + \left(b \cdot d\right))_*}{\sqrt{d^2 + c^2}^*}}}{\sqrt{d^2 + c^2}^*}\]

    if 1.0043357683224773e+119 < d

    1. Initial program 40.6

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified40.6

      \[\leadsto \color{blue}{\frac{(a \cdot c + \left(b \cdot d\right))_*}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt40.6

      \[\leadsto \frac{(a \cdot c + \left(b \cdot d\right))_*}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    5. Applied *-un-lft-identity40.6

      \[\leadsto \frac{\color{blue}{1 \cdot (a \cdot c + \left(b \cdot d\right))_*}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    6. Applied times-frac40.6

      \[\leadsto \color{blue}{\frac{1}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} \cdot \frac{(a \cdot c + \left(b \cdot d\right))_*}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    7. Simplified40.6

      \[\leadsto \color{blue}{\frac{1}{\sqrt{d^2 + c^2}^*}} \cdot \frac{(a \cdot c + \left(b \cdot d\right))_*}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    8. Simplified26.2

      \[\leadsto \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \color{blue}{\frac{(d \cdot b + \left(a \cdot c\right))_*}{\sqrt{d^2 + c^2}^*}}\]
    9. Using strategy rm
    10. Applied associate-*l/26.2

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{(d \cdot b + \left(a \cdot c\right))_*}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}}\]
    11. Simplified26.2

      \[\leadsto \frac{\color{blue}{\frac{(c \cdot a + \left(b \cdot d\right))_*}{\sqrt{d^2 + c^2}^*}}}{\sqrt{d^2 + c^2}^*}\]
    12. Using strategy rm
    13. Applied *-un-lft-identity26.2

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot (c \cdot a + \left(b \cdot d\right))_*}}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\]
    14. Applied associate-/l*26.2

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\sqrt{d^2 + c^2}^*}{(c \cdot a + \left(b \cdot d\right))_*}}}}{\sqrt{d^2 + c^2}^*}\]
    15. Taylor expanded around inf 15.8

      \[\leadsto \frac{\color{blue}{b}}{\sqrt{d^2 + c^2}^*}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le -8.346460948837449 \cdot 10^{+220}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;d \le 1.0043357683224773 \cdot 10^{+119}:\\ \;\;\;\;\frac{\frac{(c \cdot a + \left(b \cdot d\right))_*}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{d^2 + c^2}^*}\\ \end{array}\]

Reproduce

herbie shell --seed 2019005 +o rules:numerics
(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))))

Details

Time bar (total: 17.8s)Debug log

sample61.0ms

Algorithm
intervals

simplify13.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

12.0ms
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))

prune23.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 23.6b

localize17.0ms

Local error

Found 2 expressions with local error:

23.6b
(/ (fma a c (* b d)) (fma d d (* c c)))
0.0b
(fma a c (* b d))

rewrite4.0ms

Algorithm
rewrite-expression-head
Counts
2 → 39
Calls

2 calls. Slowest were:

3.0ms
(/ (fma a c (* b d)) (fma d d (* c c)))
0.0ms
(fma a c (* b d))

series119.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

72.0ms
(/ (fma a c (* b d)) (fma d d (* c c)))
47.0ms
(fma a c (* b d))

simplify603.0ms

Counts
31 → 45
Calls

31 calls. Slowest were:

241.0ms
(/ (* (* (fma a c (* b d)) (fma a c (* b d))) (fma a c (* b d))) (* (* (fma d d (* c c)) (fma d d (* c c))) (fma d d (* c c))))
28.0ms
(/ (* (cbrt (fma a c (* b d))) (cbrt (fma a c (* b d)))) (* (cbrt (fma d d (* c c))) (cbrt (fma d d (* c c)))))
27.0ms
(/ (* (cbrt (fma a c (* b d))) (cbrt (fma a c (* b d)))) 1)

prune529.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 14.7b

localize34.0ms

Local error

Found 4 expressions with local error:

14.4b
(/ (fma d b (* a c)) (hypot d c))
0.2b
(* (/ 1 (hypot d c)) (/ (fma d b (* a c)) (hypot d c)))
0.2b
(fma d b (* a c))
0.0b
(hypot d c)

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
4 → 86
Calls

4 calls. Slowest were:

7.0ms
(* (/ 1 (hypot d c)) (/ (fma d b (* a c)) (hypot d c)))
3.0ms
(/ (fma d b (* a c)) (hypot d c))
0.0ms
(fma d b (* a c))

series271.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

125.0ms
(* (/ 1 (hypot d c)) (/ (fma d b (* a c)) (hypot d c)))
79.0ms
(/ (fma d b (* a c)) (hypot d c))
40.0ms
(fma d b (* a c))
26.0ms
(hypot d c)

simplify2.1s

Counts
63 → 98
Calls

63 calls. Slowest were:

519.0ms
(* (* (* (/ 1 (hypot d c)) (/ 1 (hypot d c))) (/ 1 (hypot d c))) (* (* (/ (fma d b (* a c)) (hypot d c)) (/ (fma d b (* a c)) (hypot d c))) (/ (fma d b (* a c)) (hypot d c))))
331.0ms
(* (/ 1 (hypot d c)) (/ (fma d b (* a c)) (hypot d c)))
201.0ms
(/ (* (* (fma d b (* a c)) (fma d b (* a c))) (fma d b (* a c))) (* (* (hypot d c) (hypot d c)) (hypot d c)))

prune1.1s

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 5.5b

localize11.0ms

Local error

Found 4 expressions with local error:

14.4b
(/ (fma c a (* b d)) (hypot d c))
0.1b
(/ (/ (fma c a (* b d)) (hypot d c)) (hypot d c))
0.0b
(hypot d c)
0.0b
(hypot d c)

rewrite23.0ms

Algorithm
rewrite-expression-head
Counts
4 → 121
Calls

4 calls. Slowest were:

12.0ms
(/ (/ (fma c a (* b d)) (hypot d c)) (hypot d c))
7.0ms
(/ (fma c a (* b d)) (hypot d c))
0.0ms
(hypot d c)

series270.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

97.0ms
(/ (/ (fma c a (* b d)) (hypot d c)) (hypot d c))
91.0ms
(/ (fma c a (* b d)) (hypot d c))
41.0ms
(hypot d c)
40.0ms
(hypot d c)

simplify3.3s

Counts
135 → 133
Calls

135 calls. Slowest were:

304.0ms
(/ (/ (* (* (fma c a (* b d)) (fma c a (* b d))) (fma c a (* b d))) (* (* (hypot d c) (hypot d c)) (hypot d c))) (* (* (hypot d c) (hypot d c)) (hypot d c)))
258.0ms
(/ (* (* (/ (fma c a (* b d)) (hypot d c)) (/ (fma c a (* b d)) (hypot d c))) (/ (fma c a (* b d)) (hypot d c))) (* (* (hypot d c) (hypot d c)) (hypot d c)))
226.0ms
(/ (/ (* (cbrt (fma c a (* b d))) (cbrt (fma c a (* b d)))) (* (cbrt (hypot d c)) (cbrt (hypot d c)))) 1)

prune1.6s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 3.0b

localize8.0ms

Local error

Found 4 expressions with local error:

14.5b
(/ (hypot d c) (fma c a (* b d)))
0.2b
(/ 1 (/ (hypot d c) (fma c a (* b d))))
0.1b
(/ (/ 1 (/ (hypot d c) (fma c a (* b d)))) (hypot d c))
0.0b
(hypot d c)

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
4 → 109
Calls

4 calls. Slowest were:

6.0ms
(/ (hypot d c) (fma c a (* b d)))
4.0ms
(/ (/ 1 (/ (hypot d c) (fma c a (* b d)))) (hypot d c))
2.0ms
(/ 1 (/ (hypot d c) (fma c a (* b d))))

series361.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

136.0ms
(/ (/ 1 (/ (hypot d c) (fma c a (* b d)))) (hypot d c))
117.0ms
(/ 1 (/ (hypot d c) (fma c a (* b d))))
69.0ms
(/ (hypot d c) (fma c a (* b d)))
38.0ms
(hypot d c)

simplify4.7s

Counts
92 → 121
Calls

92 calls. Slowest were:

495.0ms
(- (log (/ 1 (/ (hypot d c) (fma c a (* b d))))) (log (hypot d c)))
351.0ms
(/ (/ 1 (/ (hypot d c) (fma c a (* b d)))) (cbrt (hypot d c)))
348.0ms
(/ (/ 1 (/ (hypot d c) (fma c a (* b d)))) (sqrt (hypot d c)))

prune1.2s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 3.0b

regimes251.0ms

Accuracy

24.7% (10.5b remaining)

Error of 13.2b against oracle of 2.7b and baseline of 16.6b

bsearch61.0ms

end0.0ms

sample1.1s

Algorithm
intervals