Average Error: 25.7 → 12.7
Time: 28.4s
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 -2.5161194196285015 \cdot 10^{+141}:\\ \;\;\;\;\frac{a}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;d \le 1.679685344068761 \cdot 10^{+113}:\\ \;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\\ \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.7
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 d < -2.5161194196285015e+141

    1. Initial program 43.3

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified43.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-sqrt43.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-identity43.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-frac43.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. Simplified43.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. Simplified26.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/26.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. Simplified26.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-identity26.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*26.7

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

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

    if -2.5161194196285015e+141 < d < 1.679685344068761e+113

    1. Initial program 18.4

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified18.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-sqrt18.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-identity18.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-frac18.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. Simplified18.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. 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}^*}\]

    if 1.679685344068761e+113 < d

    1. Initial program 40.5

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified40.5

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

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

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

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

      \[\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. Simplified25.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/25.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. Simplified25.6

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

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

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

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

Reproduce

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

sample41.0ms

Algorithm
intervals
Results
274×(pre true 80)
274×(body real 80)

simplify52.0ms

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

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 26.5b

localize36.0ms

Local error

Found 3 expressions with local error:

26.5b
(/ (- (* b c) (* a d)) (fma d d (* c c)))
1.2b
(- (* b c) (* a d))
0.0b
(fma d d (* c c))

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

series141.0ms

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

simplify1.8s

Counts
40 → 67
Calls
40 calls:
Slowest
555.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
298.0ms
(- (pow (* b c) 3) (pow (* a d) 3))
296.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))))
73.0ms
(/ (- (* b c) (* a d)) (cbrt (fma d d (* c c))))
50.0ms
(/ (- (* b c) (* a d)) (sqrt (fma d d (* c c))))

prune730.0ms

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 16.8b

localize12.0ms

Local error

Found 4 expressions with local error:

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

rewrite18.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
7.0ms
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
7.0ms
(/ (- (* b c) (* a d)) (hypot d c))
2.0ms
(- (* b c) (* a d))
1.0ms
(/ 1 (hypot d c))

series306.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
125.0ms
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))
105.0ms
(/ (- (* b c) (* a d)) (hypot d c))
41.0ms
(/ 1 (hypot d c))
36.0ms
(- (* b c) (* a d))

simplify2.9s

Counts
73 → 115
Calls
73 calls:
Slowest
426.0ms
(- (* (* b c) (* b c)) (* (* a d) (* a d)))
309.0ms
(* 1 (/ (- (* b c) (* a d)) (hypot d c)))
283.0ms
(- (pow (* b c) 3) (pow (* a d) 3))
216.0ms
(/ (* (* (- (* b c) (* a d)) (- (* b c) (* a d))) (- (* b c) (* a d))) (* (* (hypot d c) (hypot d c)) (hypot d c)))
131.0ms
(* (/ 1 (hypot d c)) (/ (- (* b c) (* a d)) (hypot d c)))

prune1.4s

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 6.0b

localize21.0ms

Local error

Found 3 expressions with local error:

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

rewrite35.0ms

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

series261.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
110.0ms
(/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))
108.0ms
(/ (- (* c b) (* a d)) (hypot d c))
44.0ms
(- (* c b) (* a d))

simplify7.1s

Counts
139 → 130
Calls
139 calls:
Slowest
531.0ms
(- (* (* c b) (* c b)) (* (* a d) (* a d)))
426.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)))
398.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)))
302.0ms
(- (pow (* c b) 3) (pow (* a d) 3))
267.0ms
(/ (/ (* (cbrt (- (* c b) (* a d))) (cbrt (- (* c b) (* a d)))) 1) (* (cbrt (hypot d c)) (cbrt (hypot d c))))

prune1.6s

Pruning

13 alts after pruning (12 fresh and 1 done)

Merged error: 5.9b

localize8.0ms

Local error

Found 4 expressions with local error:

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

rewrite16.0ms

Algorithm
rewrite-expression-head
Rules
33×times-frac
29×add-cube-cbrt
29×*-un-lft-identity
29×add-sqr-sqrt
21×associate-/r*
16×add-exp-log
associate-/r/
associate-/l*
div-inv
add-cbrt-cube
add-log-exp
div-exp
pow1
log1p-expm1-u
rec-exp
expm1-log1p-u
flip--
flip3--
frac-2neg
clear-num
cbrt-undiv
associate-/l/
inv-pow
pow-flip
prod-diff
diff-log
fma-neg
sub-neg
Counts
4 → 119
Calls
4 calls:
Slowest
5.0ms
(/ (hypot d c) (- (* c b) (* a d)))
4.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
3.0ms
(/ 1 (/ (hypot d c) (- (* c b) (* a d))))
2.0ms
(- (* c b) (* a d))

series357.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
139.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
125.0ms
(/ 1 (/ (hypot d c) (- (* c b) (* a d))))
66.0ms
(/ (hypot d c) (- (* c b) (* a d)))
27.0ms
(- (* c b) (* a d))

simplify6.9s

Counts
99 → 131
Calls
99 calls:
Slowest
455.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
387.0ms
(/ (/ 1 (/ (hypot d c) (- (* c b) (* a d)))) (hypot d c))
298.0ms
(- (log (/ 1 (/ (hypot d c) (- (* c b) (* a d))))) (log (hypot d c)))
294.0ms
(/ (* (cbrt (/ 1 (/ (hypot d c) (- (* c b) (* a d))))) (cbrt (/ 1 (/ (hypot d c) (- (* c b) (* a d)))))) (* (cbrt (hypot d c)) (cbrt (hypot d c))))
290.0ms
(/ (sqrt (/ 1 (/ (hypot d c) (- (* c b) (* a d))))) (sqrt (hypot d c)))

prune1.4s

Pruning

13 alts after pruning (11 fresh and 2 done)

Merged error: 2.3b

regimes341.0ms

Accuracy

24.3% (10.5b remaining)

Error of 12.7b against oracle of 2.2b and baseline of 16.0b

bsearch111.0ms

end0.0ms

sample1.5s

Algorithm
intervals
Results
8500×(pre true 80)
8500×(body real 80)