Average Error: 25.0 → 4.8
Time: 26.7s
Precision: 64
Internal Precision: 128
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;b \le -3.7549061336177695 \cdot 10^{+50} \lor \neg \left(b \le 3.160825419620763 \cdot 10^{+142}\right):\\ \;\;\;\;\frac{c \cdot \frac{b}{\sqrt{c^2 + d^2}^*} - \frac{d \cdot a}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c \cdot b}{\sqrt{c^2 + d^2}^*} - a \cdot \frac{d}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^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.0
Target0.5
Herbie4.8
\[\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 2 regimes
  2. if b < -3.7549061336177695e+50 or 3.160825419620763e+142 < b

    1. Initial program 33.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt33.6

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied *-un-lft-identity33.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac33.6

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Simplified33.6

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}}}{\sqrt{c^2 + d^2}^*}\]
    11. Using strategy rm
    12. Applied div-sub28.0

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b}{\sqrt{c^2 + d^2}^*} - \frac{a \cdot d}{\sqrt{c^2 + d^2}^*}}}{\sqrt{c^2 + d^2}^*}\]
    13. Using strategy rm
    14. Applied *-un-lft-identity28.0

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

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

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

    if -3.7549061336177695e+50 < b < 3.160825419620763e+142

    1. Initial program 21.1

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt21.1

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied *-un-lft-identity21.1

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac21.1

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Simplified21.1

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}}}{\sqrt{c^2 + d^2}^*}\]
    11. Using strategy rm
    12. Applied div-sub10.5

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b}{\sqrt{c^2 + d^2}^*} - \frac{a \cdot d}{\sqrt{c^2 + d^2}^*}}}{\sqrt{c^2 + d^2}^*}\]
    13. Using strategy rm
    14. Applied *-un-lft-identity10.5

      \[\leadsto \frac{\frac{c \cdot b}{\sqrt{c^2 + d^2}^*} - \frac{a \cdot d}{\color{blue}{1 \cdot \sqrt{c^2 + d^2}^*}}}{\sqrt{c^2 + d^2}^*}\]
    15. Applied times-frac2.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.7549061336177695 \cdot 10^{+50} \lor \neg \left(b \le 3.160825419620763 \cdot 10^{+142}\right):\\ \;\;\;\;\frac{c \cdot \frac{b}{\sqrt{c^2 + d^2}^*} - \frac{d \cdot a}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c \cdot b}{\sqrt{c^2 + d^2}^*} - a \cdot \frac{d}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \end{array}\]

Reproduce

herbie shell --seed 2018362 +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: 23.4s)Debug log

start40.0ms

Algorithm
intervals

setup63.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 22.7b

localize19.0ms

Local error

Found 3 expressions with local error:

22.7b
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
0.5b
(- (* b c) (* a d))
0.0b
(+ (* c c) (* d d))

rewrite21.0ms

Algorithm
rewrite-expression-head
Counts
3 → 64
Calls

3 calls. Slowest were:

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

series121.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

79.0ms
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
27.0ms
(- (* b c) (* a d))
15.0ms
(+ (* c c) (* d d))

simplify1.9s

Counts
43 → 73
Calls

43 calls. Slowest were:

586.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
303.0ms
(- (pow (* b c) 3) (pow (* a d) 3))
249.0ms
(+ (* (* c c) (* c c)) (- (* (* d d) (* d d)) (* (* c c) (* d d))))

prune753.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 15.4b

localize11.0ms

Local error

Found 4 expressions with local error:

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

rewrite17.0ms

Algorithm
rewrite-expression-head
Counts
4 → 103
Calls

4 calls. Slowest were:

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

series291.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

118.0ms
(* (/ 1 (hypot c d)) (/ (- (* b c) (* a d)) (hypot c d)))
97.0ms
(/ (- (* b c) (* a d)) (hypot c d))
42.0ms
(/ 1 (hypot c d))
34.0ms
(- (* b c) (* a d))

simplify3.3s

Counts
73 → 115
Calls

73 calls. Slowest were:

584.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
359.0ms
(* 1 (/ (- (* b c) (* a d)) (hypot c d)))
306.0ms
(- (pow (* b c) 3) (pow (* a d) 3))

prune1.5s

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 4.5b

localize11.0ms

Local error

Found 4 expressions with local error:

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

rewrite17.0ms

Algorithm
rewrite-expression-head
Counts
4 → 131
Calls

4 calls. Slowest were:

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

series214.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

85.0ms
(/ (/ (- (* c b) (* a d)) (hypot c d)) (hypot c d))
65.0ms
(/ (- (* c b) (* a d)) (hypot c d))
35.0ms
(hypot c d)
28.0ms
(- (* c b) (* a d))

simplify7.3s

Counts
142 → 143
Calls

142 calls. Slowest were:

639.0ms
(- (* (* c b) (* c b)) (* (* a d) (* a d)))
495.0ms
(/ (* (* (/ (- (* c b) (* a d)) (hypot c d)) (/ (- (* c b) (* a d)) (hypot c d))) (/ (- (* c b) (* a d)) (hypot c d))) (* (* (hypot c d) (hypot c d)) (hypot c d)))
437.0ms
(/ (/ (* (* (- (* c b) (* a d)) (- (* c b) (* a d))) (- (* c b) (* a d))) (* (* (hypot c d) (hypot c d)) (hypot c d))) (* (* (hypot c d) (hypot c d)) (hypot c d)))

prune1.6s

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 4.5b

localize11.0ms

Local error

Found 4 expressions with local error:

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

rewrite43.0ms

Algorithm
rewrite-expression-head
Counts
4 → 98
Calls

4 calls. Slowest were:

36.0ms
(/ (- (/ (* c b) (hypot c d)) (/ (* a d) (hypot c d))) (hypot c d))
3.0ms
(/ (* c b) (hypot c d))
3.0ms
(/ (* a d) (hypot c d))

series302.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

165.0ms
(/ (- (/ (* c b) (hypot c d)) (/ (* a d) (hypot c d))) (hypot c d))
55.0ms
(/ (* c b) (hypot c d))
54.0ms
(/ (* a d) (hypot c d))
27.0ms
(hypot c d)

simplify4.0s

Counts
84 → 110
Calls

84 calls. Slowest were:

653.0ms
(/ (* (* (* a d) (* a d)) (* a d)) (* (* (hypot c d) (hypot c d)) (hypot c d)))
469.0ms
(/ (* (* (* c b) (* c b)) (* c b)) (* (* (hypot c d) (hypot c d)) (hypot c d)))
394.0ms
(- (pow (/ (* c b) (hypot c d)) 3) (pow (/ (* a d) (hypot c d)) 3))

prune1.4s

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 0.2b

regimes421.0ms

Accuracy

52% (4.1b remaining)

Error of 4.8b against oracle of 0.7b and baseline of 9.3b

bsearch136.0ms