Average Error: 26.0 → 24.4
Time: 3.8s
Precision: binary64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \leq -3.4420726088017006 \cdot 10^{-112} \lor \neg \left(c \leq 2.206658626264936 \cdot 10^{-10}\right):\\ \;\;\;\;\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}} - d \cdot \frac{a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{b}{c \cdot c + d \cdot d} - \frac{d}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a}{\sqrt{c \cdot c + d \cdot d}}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \leq -3.4420726088017006 \cdot 10^{-112} \lor \neg \left(c \leq 2.206658626264936 \cdot 10^{-10}\right):\\
\;\;\;\;\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}} - d \cdot \frac{a}{c \cdot c + d \cdot d}\\

\mathbf{else}:\\
\;\;\;\;c \cdot \frac{b}{c \cdot c + d \cdot d} - \frac{d}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a}{\sqrt{c \cdot c + d \cdot d}}\\

\end{array}
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -3.4420726088017006e-112) (not (<= c 2.206658626264936e-10)))
   (-
    (* (/ c (sqrt (+ (* c c) (* d d)))) (/ b (sqrt (+ (* c c) (* d d)))))
    (* d (/ a (+ (* c c) (* d d)))))
   (-
    (* c (/ b (+ (* c c) (* d d))))
    (* (/ d (sqrt (+ (* c c) (* d d)))) (/ a (sqrt (+ (* c c) (* d d))))))))
double code(double a, double b, double c, double d) {
	return (((double) (((double) (b * c)) - ((double) (a * d)))) / ((double) (((double) (c * c)) + ((double) (d * d)))));
}
double code(double a, double b, double c, double d) {
	double VAR;
	if (((c <= -3.4420726088017006e-112) || !(c <= 2.206658626264936e-10))) {
		VAR = ((double) (((double) ((c / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))) * (b / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))))) - ((double) (d * (a / ((double) (((double) (c * c)) + ((double) (d * d)))))))));
	} else {
		VAR = ((double) (((double) (c * (b / ((double) (((double) (c * c)) + ((double) (d * d))))))) - ((double) ((d / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))) * (a / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))))))));
	}
	return VAR;
}

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.5
Herbie24.4
\[\begin{array}{l} \mathbf{if}\;\left|d\right| < \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 c < -3.44207260880170059e-112 or 2.206658626264936e-10 < c

    1. Initial program 29.3

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub29.3

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
    4. Simplified28.3

      \[\leadsto \color{blue}{c \cdot \frac{b}{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
    5. Simplified27.8

      \[\leadsto c \cdot \frac{b}{c \cdot c + d \cdot d} - \color{blue}{d \cdot \frac{a}{c \cdot c + d \cdot d}}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt27.8

      \[\leadsto c \cdot \frac{b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - d \cdot \frac{a}{c \cdot c + d \cdot d}\]
    8. Applied *-un-lft-identity27.8

      \[\leadsto c \cdot \frac{\color{blue}{1 \cdot b}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}} - d \cdot \frac{a}{c \cdot c + d \cdot d}\]
    9. Applied times-frac27.7

      \[\leadsto c \cdot \color{blue}{\left(\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}\right)} - d \cdot \frac{a}{c \cdot c + d \cdot d}\]
    10. Applied associate-*r*26.0

      \[\leadsto \color{blue}{\left(c \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}\right) \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - d \cdot \frac{a}{c \cdot c + d \cdot d}\]
    11. Simplified26.0

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

    if -3.44207260880170059e-112 < c < 2.206658626264936e-10

    1. Initial program 20.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub20.6

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
    4. Simplified24.3

      \[\leadsto \color{blue}{c \cdot \frac{b}{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
    5. Simplified25.3

      \[\leadsto c \cdot \frac{b}{c \cdot c + d \cdot d} - \color{blue}{d \cdot \frac{a}{c \cdot c + d \cdot d}}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt25.3

      \[\leadsto c \cdot \frac{b}{c \cdot c + d \cdot d} - d \cdot \frac{a}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    8. Applied *-un-lft-identity25.3

      \[\leadsto c \cdot \frac{b}{c \cdot c + d \cdot d} - d \cdot \frac{\color{blue}{1 \cdot a}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    9. Applied times-frac25.3

      \[\leadsto c \cdot \frac{b}{c \cdot c + d \cdot d} - d \cdot \color{blue}{\left(\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a}{\sqrt{c \cdot c + d \cdot d}}\right)}\]
    10. Applied associate-*r*21.9

      \[\leadsto c \cdot \frac{b}{c \cdot c + d \cdot d} - \color{blue}{\left(d \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}\right) \cdot \frac{a}{\sqrt{c \cdot c + d \cdot d}}}\]
    11. Simplified21.8

      \[\leadsto c \cdot \frac{b}{c \cdot c + d \cdot d} - \color{blue}{\frac{d}{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{a}{\sqrt{c \cdot c + d \cdot d}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification24.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.4420726088017006 \cdot 10^{-112} \lor \neg \left(c \leq 2.206658626264936 \cdot 10^{-10}\right):\\ \;\;\;\;\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}} - d \cdot \frac{a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{b}{c \cdot c + d \cdot d} - \frac{d}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a}{\sqrt{c \cdot c + d \cdot d}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020198 
(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))))