Average Error: 26.2 → 24.4
Time: 3.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;b \le -9.63064641952166374 \cdot 10^{-28}:\\ \;\;\;\;b \cdot \frac{c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;b \le 1.1328506141572114 \cdot 10^{123}:\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - a \cdot \frac{d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{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}\;b \le -9.63064641952166374 \cdot 10^{-28}:\\
\;\;\;\;b \cdot \frac{c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\

\mathbf{elif}\;b \le 1.1328506141572114 \cdot 10^{123}:\\
\;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - a \cdot \frac{d}{c \cdot c + d \cdot d}\\

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

\end{array}
double code(double a, double b, double c, double d) {
	return ((double) (((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 ((b <= -9.630646419521664e-28)) {
		VAR = ((double) (((double) (b * ((double) (c / ((double) (((double) (c * c)) + ((double) (d * d)))))))) - ((double) (((double) (a * d)) / ((double) (((double) (c * c)) + ((double) (d * d))))))));
	} else {
		double VAR_1;
		if ((b <= 1.1328506141572114e+123)) {
			VAR_1 = ((double) (((double) (((double) (b * c)) / ((double) (((double) (c * c)) + ((double) (d * d)))))) - ((double) (a * ((double) (d / ((double) (((double) (c * c)) + ((double) (d * d))))))))));
		} else {
			VAR_1 = ((double) (((double) (((double) (b / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))))) * ((double) (c / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))))))) - ((double) (((double) (a * d)) / ((double) (((double) (c * c)) + ((double) (d * d))))))));
		}
		VAR = VAR_1;
	}
	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.2
Target0.5
Herbie24.4
\[\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 b < -9.630646419521664e-28

    1. Initial program 31.9

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

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity31.9

      \[\leadsto \frac{b \cdot c}{\color{blue}{1 \cdot \left(c \cdot c + d \cdot d\right)}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
    6. Applied times-frac30.2

      \[\leadsto \color{blue}{\frac{b}{1} \cdot \frac{c}{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
    7. Simplified30.2

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

    if -9.630646419521664e-28 < b < 1.1328506141572114e+123

    1. Initial program 21.2

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

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity21.2

      \[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{\color{blue}{1 \cdot \left(c \cdot c + d \cdot d\right)}}\]
    6. Applied times-frac19.7

      \[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \color{blue}{\frac{a}{1} \cdot \frac{d}{c \cdot c + d \cdot d}}\]
    7. Simplified19.7

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

    if 1.1328506141572114e+123 < b

    1. Initial program 36.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub36.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. Using strategy rm
    5. Applied add-sqr-sqrt36.6

      \[\leadsto \frac{b \cdot c}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
    6. Applied times-frac33.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -9.63064641952166374 \cdot 10^{-28}:\\ \;\;\;\;b \cdot \frac{c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;b \le 1.1328506141572114 \cdot 10^{123}:\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - a \cdot \frac{d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \end{array}\]

Reproduce

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