Average Error: 26.0 → 13.0
Time: 18.5s
Precision: 64
Internal Precision: 128
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -5.958224986118704 \cdot 10^{+172}:\\ \;\;\;\;\frac{-a}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 6.6100911784357434 \cdot 10^{+81}:\\ \;\;\;\;\frac{\frac{(c \cdot a + \left(d \cdot b\right))_*}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{\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.0
Target0.4
Herbie13.0
\[\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 c < -5.958224986118704e+172

    1. Initial program 43.4

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified43.4

      \[\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-sqrt43.4

      \[\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-identity43.4

      \[\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-frac43.4

      \[\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. Simplified43.4

      \[\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. Simplified30.3

      \[\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/30.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. Simplified30.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. Taylor expanded around -inf 11.7

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

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

    if -5.958224986118704e+172 < c < 6.6100911784357434e+81

    1. Initial program 20.0

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified20.0

      \[\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-sqrt20.0

      \[\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-identity20.0

      \[\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-frac20.0

      \[\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. Simplified20.0

      \[\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.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/12.0

      \[\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.0

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

    if 6.6100911784357434e+81 < c

    1. Initial program 37.4

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified37.4

      \[\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-sqrt37.4

      \[\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-identity37.4

      \[\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-frac37.4

      \[\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. Simplified37.4

      \[\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. Simplified24.7

      \[\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/24.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. Simplified24.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. Taylor expanded around inf 17.1

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

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

Reproduce

herbie shell --seed 2019008 +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.5s)Debug log

sample33.0ms

Algorithm
intervals

simplify7.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune17.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 28.3b

localize16.0ms

Local error

Found 3 expressions with local error:

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

rewrite4.0ms

Algorithm
rewrite-expression-head
Counts
3 → 49
Calls

3 calls. Slowest were:

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

series121.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

61.0ms
(/ (fma a c (* b d)) (fma d d (* c c)))
41.0ms
(fma a c (* b d))
18.0ms
(fma d d (* c c))

simplify555.0ms

Counts
34 → 58
Calls

34 calls. Slowest were:

216.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))))
24.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)))))
19.0ms
(- (log (fma a c (* b d))) (log (fma d d (* c c))))

prune528.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 17.5b

localize21.0ms

Local error

Found 4 expressions with local error:

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

rewrite11.0ms

Algorithm
rewrite-expression-head
Counts
4 → 94
Calls

4 calls. Slowest were:

6.0ms
(* (/ 1 (hypot d c)) (/ (fma d b (* a c)) (hypot d c)))
3.0ms
(/ (fma d b (* a c)) (hypot d c))
1.0ms
(/ 1 (hypot d c))

series289.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

120.0ms
(* (/ 1 (hypot d c)) (/ (fma d b (* a c)) (hypot d c)))
110.0ms
(/ (fma d b (* a c)) (hypot d c))
31.0ms
(/ 1 (hypot d c))
28.0ms
(hypot d c)

simplify1.6s

Counts
67 → 106
Calls

67 calls. Slowest were:

467.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))))
226.0ms
(* (/ 1 (hypot d c)) (/ (fma d b (* a c)) (hypot d c)))
115.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)))

prune981.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 7.1b

localize12.0ms

Local error

Found 4 expressions with local error:

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

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
4 → 121
Calls

4 calls. Slowest were:

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

series223.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

77.0ms
(/ (/ (fma c a (* b d)) (hypot d c)) (hypot d c))
64.0ms
(/ (fma c a (* b d)) (hypot d c))
44.0ms
(fma c a (* b d))
38.0ms
(hypot d c)

simplify2.9s

Counts
135 → 133
Calls

135 calls. Slowest were:

272.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)))
223.0ms
(/ (/ (* (cbrt (fma c a (* b d))) (cbrt (fma c a (* b d)))) (* (cbrt (hypot d c)) (cbrt (hypot d c)))) 1)
195.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)))

prune1.4s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 1.9b

localize10.0ms

Local error

Found 4 expressions with local error:

17.3b
(/ (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
(fma c a (* b d))

rewrite11.0ms

Algorithm
rewrite-expression-head
Counts
4 → 109
Calls

4 calls. Slowest were:

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

series329.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

129.0ms
(/ 1 (/ (hypot d c) (fma c a (* b d))))
104.0ms
(/ (/ 1 (/ (hypot d c) (fma c a (* b d)))) (hypot d c))
70.0ms
(/ (hypot d c) (fma c a (* b d)))
25.0ms
(fma c a (* b d))

simplify5.0s

Counts
92 → 121
Calls

92 calls. Slowest were:

461.0ms
(/ (/ 1 (/ (hypot d c) (fma c a (* b d)))) (cbrt (hypot d c)))
404.0ms
(/ (/ 1 (/ (hypot d c) (fma c a (* b d)))) (sqrt (hypot d c)))
400.0ms
(/ (/ 1 (/ (hypot d c) (fma c a (* b d)))) (cbrt (hypot d c)))

prune1.3s

Pruning

11 alts after pruning (9 fresh and 2 done)

Merged error: 1.9b

regimes406.0ms

Accuracy

25% (10.6b remaining)

Error of 13.0b against oracle of 2.4b and baseline of 16.5b

bsearch86.0ms

end0.0ms

sample1.7s

Algorithm
intervals