Average Error: 26.9 → 15.5
Time: 9.0s
Precision: binary64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \leq -1.0880969741880458 \cdot 10^{+46}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}\\ \mathbf{elif}\;c \leq -2.5124826680120464 \cdot 10^{-157}:\\ \;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;c \leq 1.4117694234224077 \cdot 10^{-177}:\\ \;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 3.948083792625873 \cdot 10^{+21}:\\ \;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;c \leq 8.313098602456845 \cdot 10^{+41}:\\ \;\;\;\;-\frac{a}{d}\\ \mathbf{elif}\;c \leq 1.324093728718764 \cdot 10^{+134}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \leq -1.0880969741880458 \cdot 10^{+46}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}\\

\mathbf{elif}\;c \leq -2.5124826680120464 \cdot 10^{-157}:\\
\;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{elif}\;c \leq 1.4117694234224077 \cdot 10^{-177}:\\
\;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\

\mathbf{elif}\;c \leq 3.948083792625873 \cdot 10^{+21}:\\
\;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{elif}\;c \leq 8.313098602456845 \cdot 10^{+41}:\\
\;\;\;\;-\frac{a}{d}\\

\mathbf{elif}\;c \leq 1.324093728718764 \cdot 10^{+134}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{\frac{c \cdot c}{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 (<= c -1.0880969741880458e+46)
   (- (/ b c) (/ a (/ (* c c) d)))
   (if (<= c -2.5124826680120464e-157)
     (/
      (/ (- (* c b) (* a d)) (sqrt (+ (* c c) (* d d))))
      (sqrt (+ (* c c) (* d d))))
     (if (<= c 1.4117694234224077e-177)
       (- (/ (* c b) (* d d)) (/ a d))
       (if (<= c 3.948083792625873e+21)
         (/
          (/ (- (* c b) (* a d)) (sqrt (+ (* c c) (* d d))))
          (sqrt (+ (* c c) (* d d))))
         (if (<= c 8.313098602456845e+41)
           (- (/ a d))
           (if (<= c 1.324093728718764e+134)
             (/ (- b (/ (* a d) c)) (sqrt (+ (* c c) (* d d))))
             (- (/ b c) (/ a (/ (* c c) d))))))))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -1.0880969741880458e+46) {
		tmp = (b / c) - (a / ((c * c) / d));
	} else if (c <= -2.5124826680120464e-157) {
		tmp = (((c * b) - (a * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
	} else if (c <= 1.4117694234224077e-177) {
		tmp = ((c * b) / (d * d)) - (a / d);
	} else if (c <= 3.948083792625873e+21) {
		tmp = (((c * b) - (a * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
	} else if (c <= 8.313098602456845e+41) {
		tmp = -(a / d);
	} else if (c <= 1.324093728718764e+134) {
		tmp = (b - ((a * d) / c)) / sqrt((c * c) + (d * d));
	} else {
		tmp = (b / c) - (a / ((c * c) / d));
	}
	return tmp;
}

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.9
Target0.4
Herbie15.5
\[\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 5 regimes
  2. if c < -1.08809697418804577e46 or 1.324093728718764e134 < c

    1. Initial program 39.0

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary6439.0

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied associate-/r*_binary6439.0

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

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    6. Taylor expanded around inf 17.4

      \[\leadsto \color{blue}{\frac{b}{c} - \frac{d \cdot a}{{c}^{2}}}\]
    7. Simplified16.5

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

    if -1.08809697418804577e46 < c < -2.51248266801204636e-157 or 1.4117694234224077e-177 < c < 3948083792625873190000

    1. Initial program 15.1

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary6415.1

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied associate-/r*_binary6415.1

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

    if -2.51248266801204636e-157 < c < 1.4117694234224077e-177

    1. Initial program 26.2

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

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied associate-/r*_binary6426.1

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

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    6. Taylor expanded around 0 26.2

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

      \[\leadsto \color{blue}{\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}}\]
    8. Taylor expanded around 0 10.2

      \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} - \frac{a}{d}}\]
    9. Simplified10.2

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

    if 3948083792625873190000 < c < 8.3130986024568448e41

    1. Initial program 16.1

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Taylor expanded around 0 44.1

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}}\]
    3. Simplified44.1

      \[\leadsto \color{blue}{-\frac{a}{d}}\]

    if 8.3130986024568448e41 < c < 1.324093728718764e134

    1. Initial program 22.4

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary6422.4

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied associate-/r*_binary6422.4

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

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    6. Taylor expanded around inf 20.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.0880969741880458 \cdot 10^{+46}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}\\ \mathbf{elif}\;c \leq -2.5124826680120464 \cdot 10^{-157}:\\ \;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;c \leq 1.4117694234224077 \cdot 10^{-177}:\\ \;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 3.948083792625873 \cdot 10^{+21}:\\ \;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;c \leq 8.313098602456845 \cdot 10^{+41}:\\ \;\;\;\;-\frac{a}{d}\\ \mathbf{elif}\;c \leq 1.324093728718764 \cdot 10^{+134}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}\\ \end{array}\]

Reproduce

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