Average Error: 25.9 → 13.3
Time: 26.6s
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.9469398602138537 \cdot 10^{+156}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 2.229079571946664 \cdot 10^{+76}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\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

Original25.9
Target0.4
Herbie13.3
\[\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.9469398602138537e+156

    1. Initial program 44.4

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Initial simplification44.4

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

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

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

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

      \[\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. Simplified28.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/28.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. Simplified28.1

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

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

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

    if -2.9469398602138537e+156 < c < 2.229079571946664e+76

    1. Initial program 18.7

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

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

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

      \[\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}^*}\]

    if 2.229079571946664e+76 < c

    1. Initial program 37.8

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Initial simplification37.8

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

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

      \[\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-frac37.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. Simplified37.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. Simplified24.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/24.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -2.9469398602138537 \cdot 10^{+156}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 2.229079571946664 \cdot 10^{+76}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\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 2018365 +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: 24.1s)Debug log

start55.0ms

Algorithm
intervals

setup72.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 27.0b

localize38.0ms

Local error

Found 2 expressions with local error:

27.0b
(/ (- (* b c) (* a d)) (fma d d (* c c)))
0.7b
(- (* b c) (* a d))

rewrite17.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))

series117.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

71.0ms
(/ (- (* b c) (* a d)) (fma d d (* c c)))
46.0ms
(- (* b c) (* a d))

simplify1.8s

Counts
37 → 54
Calls

37 calls. Slowest were:

590.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
335.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))))
284.0ms
(- (pow (* b c) 3) (pow (* a d) 3))

prune718.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 18.0b

localize11.0ms

Local error

Found 4 expressions with local error:

17.6b
(/ (- (* b c) (* a d)) (hypot d c))
0.7b
(- (* b c) (* a d))
0.2b
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
0.0b
(/ 1 (hypot d c))

rewrite19.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))

series342.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

157.0ms
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
112.0ms
(/ (- (* b c) (* a d)) (hypot d c))
47.0ms
(- (* b c) (* a d))
27.0ms
(/ 1 (hypot d c))

simplify3.5s

Counts
73 → 115
Calls

73 calls. Slowest were:

626.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
368.0ms
(* 1 (/ (- (* b c) (* a d)) (hypot d c)))
309.0ms
(- (pow (* b c) 3) (pow (* a d) 3))

prune1.3s

Pruning

12 alts after pruning (12 fresh and 0 done)

Merged error: 5.1b

localize31.0ms

Local error

Found 3 expressions with local error:

17.6b
(/ (- (* c b) (* a d)) (hypot d c))
0.7b
(- (* c b) (* a d))
0.0b
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))

rewrite34.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))
11.0ms
(/ (- (* c b) (* a d)) (hypot d c))
4.0ms
(- (* c b) (* a d))

series225.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

101.0ms
(/ (- (* c b) (* a d)) (hypot d c))
93.0ms
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))
31.0ms
(- (* c b) (* a d))

simplify6.9s

Counts
139 → 130
Calls

139 calls. Slowest were:

596.0ms
(- (* (* c b) (* c b)) (* (* a d) (* a d)))
558.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)))
372.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.5s

Pruning

13 alts after pruning (12 fresh and 1 done)

Merged error: 5.0b

localize12.0ms

Local error

Found 4 expressions with local error:

17.6b
(/ (hypot d c) (- (* c b) (* a d)))
0.7b
(- (* c b) (* a d))
0.2b
(/ 1 (/ (hypot d c) (- (* c b) (* a d))))
0.0b
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
4 → 119
Calls

4 calls. Slowest were:

5.0ms
(/ (hypot d c) (- (* c b) (* a d)))
4.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
2.0ms
(/ 1 (/ (hypot d c) (- (* c b) (* a d))))

series326.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

116.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
105.0ms
(/ 1 (/ (hypot d c) (- (* c b) (* a d))))
71.0ms
(/ (hypot d c) (- (* c b) (* a d)))
33.0ms
(- (* c b) (* a d))

simplify5.5s

Counts
99 → 131
Calls

99 calls. Slowest were:

307.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
307.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
289.0ms
(/ (* (cbrt (/ 1 (/ (hypot d c) (- (* c b) (* a d))))) (cbrt (/ 1 (/ (hypot d c) (- (* c b) (* a d)))))) (* (cbrt (hypot d c)) (cbrt (hypot d c))))

prune1.1s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 2.1b

regimes267.0ms

Accuracy

22.6% (10.7b remaining)

Error of 13.3b against oracle of 2.6b and baseline of 16.5b

bsearch102.0ms