Average Error: 25.8 → 12.7
Time: 36.5s
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.28107214851456 \cdot 10^{+205}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 2.1659330210719858 \cdot 10^{+133}:\\ \;\;\;\;\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.8
Target0.5
Herbie12.7
\[\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.28107214851456e+205

    1. Initial program 41.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified41.6

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

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

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

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

      \[\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. Simplified30.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/30.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. Simplified30.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 11.0

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

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

    if -1.28107214851456e+205 < c < 2.1659330210719858e+133

    1. Initial program 20.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified20.6

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

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

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

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

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

      \[\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/12.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. Simplified12.7

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

    if 2.1659330210719858e+133 < c

    1. Initial program 42.3

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified42.3

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -1.28107214851456 \cdot 10^{+205}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 2.1659330210719858 \cdot 10^{+133}:\\ \;\;\;\;\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 2019010 +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: 35.3s)Debug log

sample69.0ms

Algorithm
intervals

simplify45.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
45.0ms
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))

prune20.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 24.4b

localize45.0ms

Local error

Found 3 expressions with local error:

24.4b
(/ (- (* b c) (* a d)) (fma d d (* c c)))
0.0b
(- (* b c) (* a d))
0.0b
(fma d d (* c c))

rewrite18.0ms

Algorithm
rewrite-expression-head
Rules
11×add-cube-cbrt
11×*-un-lft-identity
11×add-sqr-sqrt
times-frac
add-log-exp
add-exp-log
add-cbrt-cube
associate-/l*
log1p-expm1-u
associate-/r*
pow1
expm1-log1p-u
associate-/l/
flip--
flip3--
div-inv
fma-udef
prod-diff
div-exp
div-sub
diff-log
fma-neg
frac-2neg
sub-neg
clear-num
cbrt-undiv
Counts
3 → 58
Calls
3 calls:
Slowest
12.0ms
(/ (- (* b c) (* a d)) (fma d d (* c c)))
4.0ms
(- (* b c) (* a d))
0.0ms
(fma d d (* c c))

series159.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
96.0ms
(/ (- (* b c) (* a d)) (fma d d (* c c)))
40.0ms
(- (* b c) (* a d))
23.0ms
(fma d d (* c c))

simplify1.9s

Counts
40 → 67
Calls
40 calls:
Slowest
616.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
293.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))))
209.0ms
(- (pow (* b c) 3) (pow (* a d) 3))
75.0ms
(/ (- (* b c) (* a d)) (sqrt (fma d d (* c c))))
75.0ms
(/ (- (* b c) (* a d)) (cbrt (fma d d (* c c))))

prune881.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 14.7b

localize23.0ms

Local error

Found 4 expressions with local error:

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

rewrite33.0ms

Algorithm
rewrite-expression-head
Rules
21×add-cube-cbrt
21×*-un-lft-identity
21×add-sqr-sqrt
18×times-frac
17×add-exp-log
13×associate-*r*
11×add-cbrt-cube
pow1
add-log-exp
associate-/r*
div-inv
log1p-expm1-u
prod-exp
associate-*l*
expm1-log1p-u
associate-/l*
div-exp
rec-exp
associate-/l/
flip--
cbrt-unprod
flip3--
frac-2neg
clear-num
cbrt-undiv
inv-pow
pow-flip
*-commutative
associate-*r/
associate-*l/
pow-prod-down
prod-diff
div-sub
diff-log
fma-neg
sub-neg
frac-times
Counts
4 → 103
Calls
4 calls:
Slowest
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))
2.0ms
(/ 1 (hypot d c))

series356.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
141.0ms
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
128.0ms
(/ (- (* b c) (* a d)) (hypot d c))
45.0ms
(- (* b c) (* a d))
42.0ms
(/ 1 (hypot d c))

simplify3.4s

Counts
73 → 115
Calls
73 calls:
Slowest
612.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
323.0ms
(* 1 (/ (- (* b c) (* a d)) (hypot d c)))
272.0ms
(- (pow (* b c) 3) (pow (* a d) 3))
222.0ms
(/ (* (* (- (* b c) (* a d)) (- (* b c) (* a d))) (- (* b c) (* a d))) (* (* (hypot d c) (hypot d c)) (hypot d c)))
178.0ms
(+ (log (/ 1 (hypot d c))) (log (/ (- (* b c) (* a d)) (hypot d c))))

prune1.4s

Pruning

12 alts after pruning (12 fresh and 0 done)

Merged error: 5.5b

localize11.0ms

Local error

Found 4 expressions with local error:

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

rewrite19.0ms

Algorithm
rewrite-expression-head
Rules
84×times-frac
54×add-cube-cbrt
54×*-un-lft-identity
54×add-sqr-sqrt
16×associate-/l*
11×add-exp-log
11×add-cbrt-cube
add-log-exp
div-inv
associate-/r*
log1p-expm1-u
div-exp
cbrt-undiv
pow1
expm1-log1p-u
associate-/l/
div-sub
flip--
flip3--
frac-2neg
clear-num
prod-diff
diff-log
fma-neg
sub-neg
hypot-udef
Counts
4 → 131
Calls
4 calls:
Slowest
9.0ms
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))
6.0ms
(/ (- (* c b) (* a d)) (hypot d c))
2.0ms
(- (* c b) (* a d))
0.0ms
(hypot d c)

series233.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
79.0ms
(/ (- (* c b) (* a d)) (hypot d c))
77.0ms
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))
39.0ms
(hypot d c)
39.0ms
(- (* c b) (* a d))

simplify6.7s

Counts
142 → 143
Calls
142 calls:
Slowest
540.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)))
471.0ms
(- (* (* c b) (* c b)) (* (* a d) (* a d)))
366.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)))
300.0ms
(- (pow (* c b) 3) (pow (* a d) 3))
229.0ms
(/ (/ (* (cbrt (- (* c b) (* a d))) (cbrt (- (* c b) (* a d)))) (* (cbrt (hypot d c)) (cbrt (hypot d c)))) 1)

prune1.3s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 5.5b

localize14.0ms

Local error

Found 4 expressions with local error:

8.1b
(/ (- (* c b) (* a d)) (sqrt (hypot d c)))
6.6b
(/ (/ (- (* c b) (* a d)) (sqrt (hypot d c))) (hypot d c))
0.3b
(/ 1 (sqrt (hypot d c)))
0.3b
(* (/ 1 (sqrt (hypot d c))) (/ (/ (- (* c b) (* a d)) (sqrt (hypot d c))) (hypot d c)))

rewrite33.0ms

Algorithm
rewrite-expression-head
Rules
276×times-frac
159×add-cube-cbrt
159×*-un-lft-identity
159×add-sqr-sqrt
78×sqrt-prod
70×associate-*r*
30×add-exp-log
25×associate-/l*
20×add-cbrt-cube
15×associate-/r*
12×div-inv
10×div-exp
cbrt-undiv
pow1
prod-exp
add-log-exp
log1p-expm1-u
associate-*l*
rec-exp
expm1-log1p-u
associate-/l/
cbrt-unprod
div-sub
frac-2neg
clear-num
pow-flip
inv-pow
flip--
*-commutative
associate-*r/
associate-*l/
pow-prod-down
pow1/2
flip3--
frac-times
Counts
4 → 272
Calls
4 calls:
Slowest
10.0ms
(* (/ 1 (sqrt (hypot d c))) (/ (/ (- (* c b) (* a d)) (sqrt (hypot d c))) (hypot d c)))
8.0ms
(/ (- (* c b) (* a d)) (sqrt (hypot d c)))
8.0ms
(/ (/ (- (* c b) (* a d)) (sqrt (hypot d c))) (hypot d c))
1.0ms
(/ 1 (sqrt (hypot d c)))

series316.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
94.0ms
(/ (- (* c b) (* a d)) (sqrt (hypot d c)))
93.0ms
(* (/ 1 (sqrt (hypot d c))) (/ (/ (- (* c b) (* a d)) (sqrt (hypot d c))) (hypot d c)))
92.0ms
(/ (/ (- (* c b) (* a d)) (sqrt (hypot d c))) (hypot d c))
37.0ms
(/ 1 (sqrt (hypot d c)))

simplify14.5s

Counts
317 → 284
Calls
317 calls:
Slowest
483.0ms
(- (* (* c b) (* c b)) (* (* a d) (* a d)))
306.0ms
(+ (log (/ 1 (sqrt (hypot d c)))) (- (log (/ (- (* c b) (* a d)) (sqrt (hypot d c)))) (log (hypot d c))))
264.0ms
(* 1 (/ (- (* c b) (* a d)) (sqrt (hypot d c))))
256.0ms
(/ (/ 1 (sqrt 1)) (* (cbrt (hypot d c)) (cbrt (hypot d c))))
207.0ms
(* 1 (/ (/ (- (* c b) (* a d)) (sqrt (hypot d c))) (hypot d c)))

prune2.5s

Pruning

11 alts after pruning (9 fresh and 2 done)

Merged error: 5.5b

regimes261.0ms

Accuracy

34.7% (7.0b remaining)

Error of 12.7b against oracle of 5.7b and baseline of 16.4b

bsearch90.0ms

end0.0ms

sample1.0s

Algorithm
intervals