Average Error: 26.1 → 13.0
Time: 20.8s
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 -3.8940386072016875 \cdot 10^{+153}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 1.092948697378428 \cdot 10^{+205}:\\ \;\;\;\;\frac{\left(b \cdot c - d \cdot a\right) \cdot \frac{1}{\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

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original26.1
Target0.4
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 < -3.8940386072016875e+153

    1. Initial program 44.3

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.8940386072016875e+153 < c < 1.092948697378428e+205

    1. Initial program 21.2

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified21.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-sqrt21.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-identity21.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-frac21.2

      \[\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. Simplified21.2

      \[\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. Simplified13.2

      \[\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/13.1

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

      \[\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 div-inv13.2

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

    if 1.092948697378428e+205 < c

    1. Initial program 43.0

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

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

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

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

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

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

      \[\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/31.3

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

      \[\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 10.7

      \[\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 -3.8940386072016875 \cdot 10^{+153}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 1.092948697378428 \cdot 10^{+205}:\\ \;\;\;\;\frac{\left(b \cdot c - d \cdot a\right) \cdot \frac{1}{\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 2019007 +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: 19.9s)Debug log

sample42.0ms

Algorithm
intervals

simplify39.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 27.6b

localize27.0ms

Local error

Found 2 expressions with local error:

27.6b
(/ (- (* b c) (* a d)) (fma d d (* c c)))
1.2b
(- (* b c) (* a d))

rewrite18.0ms

Algorithm
rewrite-expression-head
Counts
2 → 48
Calls

2 calls. Slowest were:

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

series139.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

95.0ms
(/ (- (* b c) (* a d)) (fma d d (* c c)))
44.0ms
(- (* b c) (* a d))

simplify1.5s

Counts
37 → 54
Calls

37 calls. Slowest were:

470.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
244.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))))
203.0ms
(- (pow (* b c) 3) (pow (* a d) 3))

prune661.0ms

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 17.3b

localize11.0ms

Local error

Found 4 expressions with local error:

17.0b
(/ (- (* b c) (* a d)) (hypot d c))
1.2b
(- (* b c) (* a d))
0.2b
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
0.0b
(/ 1 (hypot d c))

rewrite17.0ms

Algorithm
rewrite-expression-head
Counts
4 → 103
Calls

4 calls. Slowest were:

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

series357.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

143.0ms
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
133.0ms
(/ (- (* b c) (* a d)) (hypot d c))
47.0ms
(- (* b c) (* a d))
34.0ms
(/ 1 (hypot d c))

simplify2.8s

Counts
73 → 115
Calls

73 calls. Slowest were:

486.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
266.0ms
(* 1 (/ (- (* b c) (* a d)) (hypot d c)))
252.0ms
(- (pow (* b c) 3) (pow (* a d) 3))

prune1.4s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 6.4b

localize18.0ms

Local error

Found 3 expressions with local error:

17.0b
(/ (- (* c b) (* a d)) (hypot d c))
1.2b
(- (* c b) (* a d))
0.0b
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))

rewrite35.0ms

Algorithm
rewrite-expression-head
Counts
3 → 121
Calls

3 calls. Slowest were:

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

series239.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

111.0ms
(/ (- (* c b) (* a d)) (hypot d c))
95.0ms
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))
32.0ms
(- (* c b) (* a d))

simplify6.0s

Counts
139 → 130
Calls

139 calls. Slowest were:

466.0ms
(- (* (* c b) (* c b)) (* (* a d) (* a d)))
408.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)))
367.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.3s

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 6.4b

localize6.0ms

Local error

Found 4 expressions with local error:

17.1b
(* (- (* c b) (* a d)) (/ 1 (hypot d c)))
1.2b
(- (* c b) (* a d))
0.0b
(/ (* (- (* c b) (* a d)) (/ 1 (hypot d c))) (hypot d c))
0.0b
(/ 1 (hypot d c))

rewrite21.0ms

Algorithm
rewrite-expression-head
Counts
4 → 91
Calls

4 calls. Slowest were:

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

series184.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

67.0ms
(/ (* (- (* c b) (* a d)) (/ 1 (hypot d c))) (hypot d c))
63.0ms
(* (- (* c b) (* a d)) (/ 1 (hypot d c)))
27.0ms
(- (* c b) (* a d))
27.0ms
(/ 1 (hypot d c))

simplify2.6s

Counts
58 → 103
Calls

58 calls. Slowest were:

261.0ms
(* (* (* (- (* c b) (* a d)) (- (* c b) (* a d))) (- (* c b) (* a d))) (* (* (/ 1 (hypot d c)) (/ 1 (hypot d c))) (/ 1 (hypot d c))))
207.0ms
(* (- (* (* c b) (* c b)) (* (* a d) (* a d))) 1)
191.0ms
(* (- (* (* c b) (* c b)) (* (* a d) (* a d))) 1)

prune768.0ms

Pruning

12 alts after pruning (10 fresh and 2 done)

Merged error: 6.4b

regimes293.0ms

Accuracy

36.5% (6.7b remaining)

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

bsearch92.0ms

end0.0ms

sample1.3s

Algorithm
intervals