Average Error: 25.3 → 13.6
Time: 24.7s
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 -1.8330085165230746 \cdot 10^{+75}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 1.2160163022410464 \cdot 10^{+91}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{d^2 + c^2}^*} \cdot \left(b \cdot c - d \cdot a\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

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original25.3
Target0.4
Herbie13.6
\[\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 < -1.8330085165230746e+75

    1. Initial program 35.7

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified35.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-sqrt35.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-identity35.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-frac35.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. Simplified35.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. Simplified23.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/23.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. Simplified23.6

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

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

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

    if -1.8330085165230746e+75 < c < 1.2160163022410464e+91

    1. Initial program 18.4

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

      \[\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.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-identity18.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-frac18.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. Simplified18.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. Simplified11.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-*r/11.3

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

    if 1.2160163022410464e+91 < c

    1. Initial program 37.0

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified37.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-sqrt37.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-identity37.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-frac37.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. Simplified37.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. Simplified24.1

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\sqrt{d^2 + c^2}^*}{c \cdot b - a \cdot d}}}}{\sqrt{d^2 + c^2}^*}\]
    14. Taylor expanded around 0 17.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -1.8330085165230746 \cdot 10^{+75}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 1.2160163022410464 \cdot 10^{+91}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{d^2 + c^2}^*} \cdot \left(b \cdot c - d \cdot a\right)}{\sqrt{d^2 + c^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{d^2 + c^2}^*}\\ \end{array}\]

Reproduce

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

sample49.0ms

Algorithm
intervals

simplify62.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune17.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 27.7b

localize27.0ms

Local error

Found 3 expressions with local error:

27.7b
(/ (- (* b c) (* a d)) (fma d d (* c c)))
0.8b
(- (* b c) (* a d))
0.0b
(fma d d (* c c))

rewrite13.0ms

Algorithm
rewrite-expression-head
Counts
3 → 58
Calls

3 calls. Slowest were:

10.0ms
(/ (- (* b c) (* a d)) (fma d d (* c c)))
2.0ms
(- (* b c) (* a d))
0.0ms
(fma d d (* c c))

series121.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

67.0ms
(/ (- (* b c) (* a d)) (fma d d (* c c)))
32.0ms
(- (* b c) (* a d))
21.0ms
(fma d d (* c c))

simplify1.8s

Counts
40 → 67
Calls

40 calls. Slowest were:

564.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
307.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))))
280.0ms
(- (pow (* b c) 3) (pow (* a d) 3))

prune753.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 18.2b

localize22.0ms

Local error

Found 4 expressions with local error:

17.9b
(/ (- (* b c) (* a d)) (hypot d c))
0.8b
(- (* b c) (* a d))
0.2b
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
0.0b
(/ 1 (hypot d c))

rewrite34.0ms

Algorithm
rewrite-expression-head
Counts
4 → 103
Calls

4 calls. Slowest were:

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

series280.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

120.0ms
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
83.0ms
(/ (- (* b c) (* a d)) (hypot d c))
39.0ms
(- (* b c) (* a d))
37.0ms
(/ 1 (hypot d c))

simplify3.1s

Counts
73 → 115
Calls

73 calls. Slowest were:

500.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
339.0ms
(* 1 (/ (- (* b c) (* a d)) (hypot d c)))
266.0ms
(- (pow (* b c) 3) (pow (* a d) 3))

prune1.3s

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 7.3b

localize22.0ms

Local error

Found 3 expressions with local error:

17.9b
(/ (- (* c b) (* a d)) (hypot d c))
0.8b
(- (* c b) (* a d))
0.1b
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))

rewrite22.0ms

Algorithm
rewrite-expression-head
Counts
3 → 121
Calls

3 calls. Slowest were:

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

series216.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

96.0ms
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))
80.0ms
(/ (- (* c b) (* a d)) (hypot d c))
39.0ms
(- (* c b) (* a d))

simplify6.7s

Counts
139 → 130
Calls

139 calls. Slowest were:

616.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)))
574.0ms
(- (* (* c b) (* c b)) (* (* a d) (* a d)))
444.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.0s

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 7.3b

localize8.0ms

Local error

Found 4 expressions with local error:

18.0b
(/ (hypot d c) (- (* c b) (* a d)))
0.8b
(- (* c b) (* a d))
0.2b
(/ 1 (/ (hypot d c) (- (* c b) (* a d))))
0.1b
(/ (/ 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))
3.0ms
(/ 1 (/ (hypot d c) (- (* c b) (* a d))))

series337.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

120.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
102.0ms
(/ 1 (/ (hypot d c) (- (* c b) (* a d))))
76.0ms
(/ (hypot d c) (- (* c b) (* a d)))
39.0ms
(- (* c b) (* a d))

simplify5.3s

Counts
99 → 131
Calls

99 calls. Slowest were:

326.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
323.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
251.0ms
(- (log (/ 1 (/ (hypot d c) (- (* c b) (* a d))))) (log (hypot d c)))

prune1.0s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 3.5b

regimes239.0ms

Accuracy

18% (11.3b remaining)

Error of 13.6b against oracle of 2.3b and baseline of 16.1b

bsearch95.0ms

end0.0ms

sample1.3s

Algorithm
intervals