Average Error: 25.8 → 13.0
Time: 23.1s
Precision: 64
Internal Precision: 128
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -2.0358380435950273 \cdot 10^{+138}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 6.412199599525631 \cdot 10^{+120}:\\ \;\;\;\;\frac{\frac{1}{\frac{\sqrt{d^2 + c^2}^*}{(c \cdot b + \left(a \cdot \left(-d\right)\right))_*}}}{\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

Original25.8
Target0.5
Herbie13.0
\[\begin{array}{l} \mathbf{if}\;\left|d\right| \lt \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if c < -2.0358380435950273e+138

    1. Initial program 43.2

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

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

      \[\leadsto \frac{b \cdot c - a \cdot d}{\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.2

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \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.1

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

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

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

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}}\]
    11. Simplified29.5

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{d^2 + c^2}^*}}}{\sqrt{d^2 + c^2}^*}\]
    12. Taylor expanded around -inf 15.4

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

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

    if -2.0358380435950273e+138 < c < 6.412199599525631e+120

    1. Initial program 18.7

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified18.7

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

      \[\leadsto \frac{b \cdot c - a \cdot d}{\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-identity18.7

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \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-frac18.8

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{d^2 + c^2}^*}}}{\sqrt{d^2 + c^2}^*}\]
    12. Using strategy rm
    13. Applied fma-neg11.8

      \[\leadsto \frac{\frac{\color{blue}{(c \cdot b + \left(-a \cdot d\right))_*}}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\]
    14. Using strategy rm
    15. Applied clear-num11.9

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

    if 6.412199599525631e+120 < c

    1. Initial program 40.9

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

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

      \[\leadsto \frac{b \cdot c - a \cdot d}{\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.9

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \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.9

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

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

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

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}}\]
    11. Simplified26.6

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{d^2 + c^2}^*}}}{\sqrt{d^2 + c^2}^*}\]
    12. Using strategy rm
    13. Applied fma-neg26.6

      \[\leadsto \frac{\frac{\color{blue}{(c \cdot b + \left(-a \cdot d\right))_*}}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\]
    14. 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.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -2.0358380435950273 \cdot 10^{+138}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 6.412199599525631 \cdot 10^{+120}:\\ \;\;\;\;\frac{\frac{1}{\frac{\sqrt{d^2 + c^2}^*}{(c \cdot b + \left(a \cdot \left(-d\right)\right))_*}}}{\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, imag part"

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))

  (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))

Details

Time bar (total: 22.0s)Debug log

sample72.0ms

Algorithm
intervals

simplify76.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

76.0ms
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))

prune16.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 23.9b

localize23.0ms

Local error

Found 2 expressions with local error:

23.9b
(/ (- (* b c) (* a d)) (fma d d (* c c)))
0.0b
(- (* b c) (* a d))

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
2 → 48
Calls

2 calls. Slowest were:

7.0ms
(/ (- (* b c) (* a d)) (fma d d (* c c)))
4.0ms
(- (* b c) (* a d))

series128.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

87.0ms
(/ (- (* b c) (* a d)) (fma d d (* c c)))
41.0ms
(- (* b c) (* a d))

simplify1.8s

Counts
37 → 54
Calls

37 calls. Slowest were:

595.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
311.0ms
(/ (* (* (- (* b c) (* a d)) (- (* b c) (* a d))) (- (* b c) (* a d))) (* (* (fma d d (* c c)) (fma d d (* c c))) (fma d d (* c c))))
237.0ms
(- (pow (* b c) 3) (pow (* a d) 3))

prune606.0ms

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 16.3b

localize20.0ms

Local error

Found 4 expressions with local error:

16.1b
(/ (- (* b c) (* a d)) (hypot d c))
0.3b
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
0.0b
(- (* b c) (* a d))
0.0b
(hypot d c)

rewrite29.0ms

Algorithm
rewrite-expression-head
Counts
4 → 95
Calls

4 calls. Slowest were:

12.0ms
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
10.0ms
(/ (- (* b c) (* a d)) (hypot d c))
4.0ms
(- (* b c) (* a d))

series264.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

107.0ms
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
97.0ms
(/ (- (* b c) (* a d)) (hypot d c))
32.0ms
(hypot d c)
28.0ms
(- (* b c) (* a d))

simplify3.3s

Counts
69 → 107
Calls

69 calls. Slowest were:

473.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
342.0ms
(* 1 (/ (- (* b c) (* a d)) (hypot d c)))
324.0ms
(- (pow (* b c) 3) (pow (* a d) 3))

prune1.4s

Pruning

12 alts after pruning (12 fresh and 0 done)

Merged error: 8.1b

localize12.0ms

Local error

Found 4 expressions with local error:

16.1b
(/ (- (* c b) (* a d)) (hypot d c))
0.1b
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))
0.0b
(- (* c b) (* a d))
0.0b
(hypot d c)

rewrite18.0ms

Algorithm
rewrite-expression-head
Counts
4 → 131
Calls

4 calls. Slowest were:

8.0ms
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))
6.0ms
(/ (- (* c b) (* a d)) (hypot d c))
2.0ms
(- (* c b) (* a d))

series266.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

108.0ms
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))
76.0ms
(/ (- (* c b) (* a d)) (hypot d c))
47.0ms
(- (* c b) (* a d))
35.0ms
(hypot d c)

simplify6.4s

Counts
142 → 143
Calls

142 calls. Slowest were:

516.0ms
(- (* (* c b) (* c b)) (* (* a d) (* a d)))
496.0ms
(/ (* (* (/ (- (* c b) (* a d)) (hypot d c)) (/ (- (* c b) (* a d)) (hypot d c))) (/ (- (* c b) (* a d)) (hypot d c))) (* (* (hypot d c) (hypot d c)) (hypot d c)))
350.0ms
(/ (/ (* (* (- (* c b) (* a d)) (- (* c b) (* a d))) (- (* c b) (* a d))) (* (* (hypot d c) (hypot d c)) (hypot d c))) (* (* (hypot d c) (hypot d c)) (hypot d c)))

prune1.2s

Pruning

14 alts after pruning (14 fresh and 0 done)

Merged error: 8.1b

localize11.0ms

Local error

Found 4 expressions with local error:

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

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
4 → 121
Calls

4 calls. Slowest were:

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

series448.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

332.0ms
(/ (/ (fma c b (- (* a d))) (hypot d c)) (hypot d c))
69.0ms
(/ (fma c b (- (* a d))) (hypot d c))
24.0ms
(hypot d c)
24.0ms
(hypot d c)

simplify3.4s

Counts
135 → 133
Calls

135 calls. Slowest were:

276.0ms
(/ (/ (* (* (fma c b (- (* a d))) (fma c b (- (* a d)))) (fma c b (- (* a d)))) (* (* (hypot d c) (hypot d c)) (hypot d c))) (* (* (hypot d c) (hypot d c)) (hypot d c)))
201.0ms
(/ (/ (* (cbrt (fma c b (- (* a d)))) (cbrt (fma c b (- (* a d))))) (* (cbrt (hypot d c)) (cbrt (hypot d c)))) 1)
190.0ms
(/ (* (* (/ (fma c b (- (* a d))) (hypot d c)) (/ (fma c b (- (* a d))) (hypot d c))) (/ (fma c b (- (* a d))) (hypot d c))) (* (* (hypot d c) (hypot d c)) (hypot d c)))

prune1.1s

Pruning

13 alts after pruning (13 fresh and 0 done)

Merged error: 8.1b

regimes294.0ms

Accuracy

34.7% (7.1b remaining)

Error of 13.0b against oracle of 5.9b and baseline of 16.8b

bsearch101.0ms

end0.0ms

sample1.1s

Algorithm
intervals