Average Error: 25.4 → 12.1
Time: 25.9s
Precision: 64
Internal Precision: 128
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le -3.888992367226674 \cdot 10^{+174}:\\ \;\;\;\;\frac{a}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;d \le 2.3163448447978856 \cdot 10^{+141}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{d^2 + c^2}^*}}{\frac{\sqrt{d^2 + c^2}^*}{b \cdot c - a \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\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.4
Target0.4
Herbie12.1
\[\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 d < -3.888992367226674e+174

    1. Initial program 44.7

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified44.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-sqrt44.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-identity44.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-frac44.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. Simplified44.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. Simplified29.6

      \[\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.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. Simplified29.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 *-un-lft-identity29.6

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(c \cdot b - a \cdot d\right)}}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\]
    14. Applied associate-/l*29.6

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

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

    if -3.888992367226674e+174 < d < 2.3163448447978856e+141

    1. Initial program 18.8

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

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

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

      \[\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 *-un-lft-identity11.5

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(c \cdot b - a \cdot d\right)}}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\]
    14. Applied associate-/l*11.6

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\sqrt{d^2 + c^2}^*}{c \cdot b - a \cdot d}}}}{\sqrt{d^2 + c^2}^*}\]
    15. Using strategy rm
    16. Applied associate-/r/11.6

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{d^2 + c^2}^*} \cdot \left(c \cdot b - a \cdot d\right)}}{\sqrt{d^2 + c^2}^*}\]
    17. Applied associate-/l*11.6

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

    if 2.3163448447978856e+141 < d

    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. Simplified27.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/27.7

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le -3.888992367226674 \cdot 10^{+174}:\\ \;\;\;\;\frac{a}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;d \le 2.3163448447978856 \cdot 10^{+141}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{d^2 + c^2}^*}}{\frac{\sqrt{d^2 + c^2}^*}{b \cdot c - a \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\sqrt{d^2 + c^2}^*}\\ \end{array}\]

Reproduce

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

sample66.0ms

Algorithm
intervals

simplify53.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 25.6b

localize29.0ms

Local error

Found 2 expressions with local error:

25.6b
(/ (- (* b c) (* a d)) (fma d d (* c c)))
0.3b
(- (* 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))

series130.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

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

simplify2.0s

Counts
37 → 54
Calls

37 calls. Slowest were:

683.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
367.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))))
339.0ms
(- (pow (* b c) 3) (pow (* a d) 3))

prune623.0ms

Pruning

12 alts after pruning (12 fresh and 0 done)

Merged error: 16.7b

localize17.0ms

Local error

Found 4 expressions with local error:

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

rewrite39.0ms

Algorithm
rewrite-expression-head
Counts
4 → 103
Calls

4 calls. Slowest were:

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

series273.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

113.0ms
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
104.0ms
(/ (- (* b c) (* a d)) (hypot d c))
30.0ms
(- (* b c) (* a d))
26.0ms
(/ 1 (hypot d c))

simplify3.3s

Counts
73 → 115
Calls

73 calls. Slowest were:

555.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
353.0ms
(* 1 (/ (- (* b c) (* a d)) (hypot d c)))
310.0ms
(- (pow (* b c) 3) (pow (* a d) 3))

prune1.3s

Pruning

14 alts after pruning (14 fresh and 0 done)

Merged error: 6.3b

localize22.0ms

Local error

Found 4 expressions with local error:

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

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
4 → 131
Calls

4 calls. Slowest were:

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

series204.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

76.0ms
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))
65.0ms
(/ (- (* c b) (* a d)) (hypot d c))
39.0ms
(- (* c b) (* a d))
23.0ms
(hypot d c)

simplify7.2s

Counts
142 → 143
Calls

142 calls. Slowest were:

582.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)))
575.0ms
(- (* (* c b) (* c b)) (* (* a d) (* a d)))
411.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

15 alts after pruning (15 fresh and 0 done)

Merged error: 6.3b

localize8.0ms

Local error

Found 4 expressions with local error:

16.5b
(/ (hypot d c) (- (* c b) (* a d)))
0.3b
(- (* 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))

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

series288.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

107.0ms
(/ 1 (/ (hypot d c) (- (* c b) (* a d))))
90.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
65.0ms
(/ (hypot d c) (- (* c b) (* a d)))
25.0ms
(- (* c b) (* a d))

simplify5.1s

Counts
99 → 131
Calls

99 calls. Slowest were:

315.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
302.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
232.0ms
(- (log (/ 1 (/ (hypot d c) (- (* c b) (* a d))))) (log (hypot d c)))

prune1.0s

Pruning

13 alts after pruning (13 fresh and 0 done)

Merged error: 1.5b

regimes301.0ms

Accuracy

28.9% (9.8b remaining)

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

bsearch142.0ms

end0.0ms

sample1.3s

Algorithm
intervals