Average Error: 26.1 → 7.1
Time: 19.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.8988337831022309 \cdot 10^{+177}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 2.599647374459235 \cdot 10^{+114}:\\ \;\;\;\;\frac{\frac{-a}{\sqrt{d^2 + c^2}^*} \cdot d + \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \left(b \cdot c\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

Original26.1
Target0.3
Herbie7.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 c < -1.8988337831022309e+177

    1. Initial program 43.4

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified43.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-sqrt43.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-identity43.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-frac43.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. Simplified43.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. Simplified29.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/29.8

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

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

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

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

    if -1.8988337831022309e+177 < c < 2.599647374459235e+114

    1. Initial program 19.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified19.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-sqrt19.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-identity19.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-frac19.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. Simplified19.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.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-*r/12.1

      \[\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}^*}}\]
    11. Using strategy rm
    12. Applied sub-neg12.1

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

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

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

    if 2.599647374459235e+114 < c

    1. Initial program 41.9

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

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

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

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

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

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

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

      \[\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}^*}}\]
    11. Taylor expanded around 0 16.4

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

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

Reproduce

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

sample37.0ms

Algorithm
intervals
Results
25.0ms267×body80valid

simplify60.0ms

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

prune23.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 28.1b

localize27.0ms

Local error

Found 3 expressions with local error:

28.1b
(/ (- (* b c) (* a d)) (fma d d (* c c)))
0.2b
(- (* b c) (* a d))
0.0b
(fma d d (* c c))

rewrite10.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
7.0ms
(/ (- (* b c) (* a d)) (fma d d (* c c)))
2.0ms
(- (* b c) (* a d))
0.0ms
(fma d d (* c c))

series108.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
63.0ms
(/ (- (* b c) (* a d)) (fma d d (* c c)))
29.0ms
(- (* b c) (* a d))
17.0ms
(fma d d (* c c))

simplify1.4s

Counts
40 → 67
Calls
40 calls:
Slowest
478.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
250.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))))
194.0ms
(- (pow (* b c) 3) (pow (* a d) 3))
44.0ms
(/ (* (cbrt (- (* b c) (* a d))) (cbrt (- (* b c) (* a d)))) (* (cbrt (fma d d (* c c))) (cbrt (fma d d (* c c)))))
38.0ms
(/ (- (* b c) (* a d)) (fma d d (* c c)))

prune620.0ms

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 16.8b

localize11.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.2b
(- (* b c) (* a d))
0.0b
(hypot d c)

rewrite19.0ms

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

series238.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
98.0ms
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
89.0ms
(/ (- (* b c) (* a d)) (hypot d c))
28.0ms
(- (* b c) (* a d))
23.0ms
(hypot d c)

simplify2.3s

Counts
69 → 107
Calls
69 calls:
Slowest
430.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
264.0ms
(- (pow (* b c) 3) (pow (* a d) 3))
219.0ms
(* 1 (/ (- (* b c) (* a d)) (hypot d c)))
186.0ms
(/ (* (* (- (* b c) (* a d)) (- (* b c) (* a d))) (- (* b c) (* a d))) (* (* (hypot d c) (hypot d c)) (hypot d c)))
98.0ms
(* (* (* (/ 1 (hypot d c)) (/ 1 (hypot d c))) (/ 1 (hypot d c))) (/ (* (* (- (* b c) (* a d)) (- (* b c) (* a d))) (- (* b c) (* a d))) (* (* (hypot d c) (hypot d c)) (hypot d c))))

prune812.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 4.5b

localize10.0ms

Local error

Found 4 expressions with local error:

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

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

series174.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
63.0ms
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))
62.0ms
(/ (- (* c b) (* a d)) (hypot d c))
27.0ms
(- (* c b) (* a d))
22.0ms
(hypot d c)

simplify4.9s

Counts
142 → 143
Calls
142 calls:
Slowest
351.0ms
(- (* (* c b) (* c b)) (* (* a d) (* a d)))
337.0ms
(/ (/ (- (* c b) (* a d)) (sqrt (hypot d c))) (hypot d c))
332.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)))
263.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)))
176.0ms
(- (pow (* c b) 3) (pow (* a d) 3))

prune999.0ms

Pruning

12 alts after pruning (12 fresh and 0 done)

Merged error: 4.5b

localize6.0ms

Local error

Found 4 expressions with local error:

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

rewrite21.0ms

Algorithm
rewrite-expression-head
Rules
16×add-exp-log
11×add-cbrt-cube
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-log-exp
pow1
associate-/l/
flip--
flip3--
log1p-expm1-u
associate-*r/
prod-exp
associate-*l*
frac-times
expm1-log1p-u
prod-diff
associate-*r*
div-exp
times-frac
distribute-lft-in
sub-neg
associate-/r*
distribute-rgt-in
div-inv
cbrt-unprod
associate-*l/
rec-exp
cbrt-undiv
associate-/l*
*-commutative
pow-prod-down
diff-log
fma-neg
frac-2neg
clear-num
hypot-udef
Counts
4 → 87
Calls
4 calls:
Slowest
10.0ms
(/ (* (/ 1 (hypot d c)) (- (* b c) (* a d))) (hypot d c))
7.0ms
(* (/ 1 (hypot d c)) (- (* b c) (* a d)))
2.0ms
(- (* b c) (* a d))
0.0ms
(hypot d c)

series229.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
90.0ms
(/ (* (/ 1 (hypot d c)) (- (* b c) (* a d))) (hypot d c))
83.0ms
(* (/ 1 (hypot d c)) (- (* b c) (* a d)))
31.0ms
(hypot d c)
26.0ms
(- (* b c) (* a d))

simplify3.9s

Counts
57 → 99
Calls
57 calls:
Slowest
312.0ms
(* (- (* a d)) (/ 1 (hypot d c)))
287.0ms
(* 1 (- (* (* b c) (* b c)) (* (* a d) (* a d))))
263.0ms
(* (/ 1 (hypot d c)) (- (pow (* b c) 3) (pow (* a d) 3)))
236.0ms
(* (- (* a d)) (/ 1 (hypot d c)))
207.0ms
(- (log (* (/ 1 (hypot d c)) (- (* b c) (* a d)))) (log (hypot d c)))

prune939.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 0.9b

regimes230.0ms

Accuracy

32.1% (5.4b remaining)

Error of 7.1b against oracle of 1.7b and baseline of 9.6b

bsearch88.0ms

end0.0ms

sample1.3s

Algorithm
intervals
Results
1.1s8441×body80valid