Average Error: 26.0 → 14.5
Time: 25.1s
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 4.4205857620523035 \cdot 10^{+121}:\\ \;\;\;\;\frac{\frac{c \cdot b - d \cdot a}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\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

Original26.0
Target0.4
Herbie14.5
\[\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 d < 4.4205857620523035e+121

    1. Initial program 23.1

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt23.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-identity23.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-frac23.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. Simplified23.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. Simplified14.5

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

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

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

    if 4.4205857620523035e+121 < d

    1. Initial program 41.1

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt41.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-identity41.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-frac41.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. Simplified41.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. Simplified26.3

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

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

      \[\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 *-un-lft-identity26.2

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le 4.4205857620523035 \cdot 10^{+121}:\\ \;\;\;\;\frac{\frac{c \cdot b - d \cdot a}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\sqrt{c^2 + d^2}^*}\\ \end{array}\]

Reproduce

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

sample68.0ms

Algorithm
intervals

simplify73.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 26.9b

localize34.0ms

Local error

Found 3 expressions with local error:

26.9b
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
0.7b
(- (* b c) (* a d))
0.0b
(+ (* c c) (* d d))

rewrite16.0ms

Algorithm
rewrite-expression-head
Counts
3 → 64
Calls

3 calls. Slowest were:

11.0ms
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
2.0ms
(+ (* c c) (* d d))
2.0ms
(- (* b c) (* a d))

series108.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

59.0ms
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
28.0ms
(- (* b c) (* a d))
21.0ms
(+ (* c c) (* d d))

simplify1.8s

Counts
43 → 73
Calls

43 calls. Slowest were:

553.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
278.0ms
(- (pow (* b c) 3) (pow (* a d) 3))
268.0ms
(+ (* (* c c) (* c c)) (- (* (* d d) (* d d)) (* (* c c) (* d d))))

prune721.0ms

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 16.7b

localize12.0ms

Local error

Found 4 expressions with local error:

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

rewrite30.0ms

Algorithm
rewrite-expression-head
Counts
4 → 103
Calls

4 calls. Slowest were:

13.0ms
(* (/ 1 (hypot c d)) (/ (- (* b c) (* a d)) (hypot c d)))
11.0ms
(/ (- (* b c) (* a d)) (hypot c d))
4.0ms
(- (* b c) (* a d))

series255.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

110.0ms
(* (/ 1 (hypot c d)) (/ (- (* b c) (* a d)) (hypot c d)))
90.0ms
(/ (- (* b c) (* a d)) (hypot c d))
28.0ms
(- (* b c) (* a d))
26.0ms
(/ 1 (hypot c d))

simplify3.0s

Counts
73 → 115
Calls

73 calls. Slowest were:

470.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
294.0ms
(* 1 (/ (- (* b c) (* a d)) (hypot c d)))
260.0ms
(/ (* (* (- (* b c) (* a d)) (- (* b c) (* a d))) (- (* b c) (* a d))) (* (* (hypot c d) (hypot c d)) (hypot c d)))

prune1.2s

Pruning

12 alts after pruning (12 fresh and 0 done)

Merged error: 5.7b

localize26.0ms

Local error

Found 4 expressions with local error:

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

rewrite32.0ms

Algorithm
rewrite-expression-head
Counts
4 → 131
Calls

4 calls. Slowest were:

13.0ms
(/ (/ (- (* c b) (* a d)) (hypot c d)) (hypot c d))
11.0ms
(/ (- (* c b) (* a d)) (hypot c d))
4.0ms
(- (* c b) (* a d))

series228.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

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

simplify7.4s

Counts
142 → 143
Calls

142 calls. Slowest were:

580.0ms
(- (* (* c b) (* c b)) (* (* a d) (* a d)))
406.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)))
383.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.4s

Pruning

14 alts after pruning (13 fresh and 1 done)

Merged error: 5.6b

localize13.0ms

Local error

Found 4 expressions with local error:

16.5b
(/ (hypot c d) (- (* c b) (* a d)))
0.7b
(- (* c b) (* a d))
0.2b
(/ 1 (/ (hypot c d) (- (* c b) (* a d))))
0.1b
(/ (/ 1 (/ (hypot c d) (- (* c b) (* a d)))) (hypot c d))

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
4 → 119
Calls

4 calls. Slowest were:

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

series250.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

91.0ms
(/ (/ 1 (/ (hypot c d) (- (* c b) (* a d)))) (hypot c d))
66.0ms
(/ (hypot c d) (- (* c b) (* a d)))
65.0ms
(/ 1 (/ (hypot c d) (- (* c b) (* a d))))
27.0ms
(- (* c b) (* a d))

simplify4.9s

Counts
99 → 131
Calls

99 calls. Slowest were:

289.0ms
(/ (/ 1 (/ (hypot c d) (- (* c b) (* a d)))) (hypot c d))
284.0ms
(/ (/ 1 (/ (hypot c d) (- (* c b) (* a d)))) (hypot c d))
219.0ms
(- (log (/ 1 (/ (hypot c d) (- (* c b) (* a d))))) (log (hypot c d)))

prune952.0ms

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 5.6b

regimes273.0ms

Accuracy

16.7% (9.0b remaining)

Error of 14.5b against oracle of 5.6b and baseline of 16.3b

bsearch29.0ms

end0.0ms

sample1.3s

Algorithm
intervals