(FPCore (a b c d)
:precision binary64
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
↓
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (/ b c) (* (/ a c) (/ d c)))))
(if (<= c -1.25e+113)
t_0
(if (<= c 1.7e+115)
(*
(/ 1.0 (hypot c d))
(- (/ (pow (cbrt (* c b)) 3.0) (hypot c d)) (* d (/ a (hypot c d)))))
t_0))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
(-.f64 (/.f64 b c) (*.f64 (/.f64 a c) (/.f64 d c))): 0 points increase in error, 0 points decrease in error
(-.f64 (/.f64 b c) (Rewrite<= times-frac_binary64 (/.f64 (*.f64 a d) (*.f64 c c)))): 31 points increase in error, 16 points decrease in error
(-.f64 (/.f64 b c) (/.f64 (*.f64 a d) (Rewrite<= unpow2_binary64 (pow.f64 c 2)))): 0 points increase in error, 0 points decrease in error
(Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 b c) (neg.f64 (/.f64 (*.f64 a d) (pow.f64 c 2))))): 0 points increase in error, 0 points decrease in error
(+.f64 (/.f64 b c) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 a d) (pow.f64 c 2))))): 0 points increase in error, 0 points decrease in error
(Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 a d) (pow.f64 c 2))) (/.f64 b c))): 0 points increase in error, 0 points decrease in error
if -1.25e113 < c < 1.7e115
Initial program 18.6
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\]
Applied egg-rr11.6
\[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}
\]
(-.f64 (/.f64 (pow.f64 (cbrt.f64 (*.f64 c b)) 3) (hypot.f64 c d)) (*.f64 (/.f64 a (hypot.f64 c d)) d)): 0 points increase in error, 0 points decrease in error
(-.f64 (/.f64 (pow.f64 (cbrt.f64 (Rewrite<= *-commutative_binary64 (*.f64 b c))) 3) (hypot.f64 c d)) (*.f64 (/.f64 a (hypot.f64 c d)) d)): 0 points increase in error, 0 points decrease in error
(-.f64 (/.f64 (pow.f64 (cbrt.f64 (*.f64 b c)) (Rewrite<= metadata-eval (+.f64 2 1))) (hypot.f64 c d)) (*.f64 (/.f64 a (hypot.f64 c d)) d)): 0 points increase in error, 0 points decrease in error
(-.f64 (/.f64 (Rewrite<= pow-plus_binary64 (*.f64 (pow.f64 (cbrt.f64 (*.f64 b c)) 2) (cbrt.f64 (*.f64 b c)))) (hypot.f64 c d)) (*.f64 (/.f64 a (hypot.f64 c d)) d)): 11 points increase in error, 11 points decrease in error
(-.f64 (/.f64 (*.f64 (Rewrite<= /-rgt-identity_binary64 (/.f64 (pow.f64 (cbrt.f64 (*.f64 b c)) 2) 1)) (cbrt.f64 (*.f64 b c))) (hypot.f64 c d)) (*.f64 (/.f64 a (hypot.f64 c d)) d)): 0 points increase in error, 0 points decrease in error
(-.f64 (Rewrite<= associate-*r/_binary64 (*.f64 (/.f64 (pow.f64 (cbrt.f64 (*.f64 b c)) 2) 1) (/.f64 (cbrt.f64 (*.f64 b c)) (hypot.f64 c d)))) (*.f64 (/.f64 a (hypot.f64 c d)) d)): 18 points increase in error, 13 points decrease in error
(-.f64 (*.f64 (/.f64 (pow.f64 (cbrt.f64 (*.f64 b c)) 2) 1) (/.f64 (cbrt.f64 (*.f64 b c)) (hypot.f64 c d))) (Rewrite<= associate-/r/_binary64 (/.f64 a (/.f64 (hypot.f64 c d) d)))): 24 points increase in error, 19 points decrease in error
(-.f64 (*.f64 (/.f64 (pow.f64 (cbrt.f64 (*.f64 b c)) 2) 1) (/.f64 (cbrt.f64 (*.f64 b c)) (hypot.f64 c d))) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 a d) (hypot.f64 c d)))): 40 points increase in error, 8 points decrease in error
(Rewrite=> fma-neg_binary64 (fma.f64 (/.f64 (pow.f64 (cbrt.f64 (*.f64 b c)) 2) 1) (/.f64 (cbrt.f64 (*.f64 b c)) (hypot.f64 c d)) (neg.f64 (/.f64 (*.f64 a d) (hypot.f64 c d))))): 1 points increase in error, 1 points decrease in error
herbie shell --seed 2022330
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
: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))))