Complex division, imag part

Percentage Accurate: 61.8% → 80.4%
Time: 5.4s
Alternatives: 6
Speedup: 0.9×

Specification

?
\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 61.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}

Alternative 1: 80.4% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{if}\;d \leq -6.5 \cdot 10^{+163}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq -2.8 \cdot 10^{-156}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 4.6 \cdot 10^{+48}:\\ \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c (/ b d)) a) d)))
   (if (<= d -6.5e+163)
     t_0
     (if (<= d -2.8e-156)
       (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
       (if (<= d 4.6e+48) (/ (- b (* (/ d c) a)) c) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * (b / d)) - a) / d;
	double tmp;
	if (d <= -6.5e+163) {
		tmp = t_0;
	} else if (d <= -2.8e-156) {
		tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
	} else if (d <= 4.6e+48) {
		tmp = (b - ((d / c) * a)) / c;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((c * (b / d)) - a) / d
    if (d <= (-6.5d+163)) then
        tmp = t_0
    else if (d <= (-2.8d-156)) then
        tmp = ((b * c) - (a * d)) / ((c * c) + (d * d))
    else if (d <= 4.6d+48) then
        tmp = (b - ((d / c) * a)) / c
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((c * (b / d)) - a) / d;
	double tmp;
	if (d <= -6.5e+163) {
		tmp = t_0;
	} else if (d <= -2.8e-156) {
		tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
	} else if (d <= 4.6e+48) {
		tmp = (b - ((d / c) * a)) / c;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((c * (b / d)) - a) / d
	tmp = 0
	if d <= -6.5e+163:
		tmp = t_0
	elif d <= -2.8e-156:
		tmp = ((b * c) - (a * d)) / ((c * c) + (d * d))
	elif d <= 4.6e+48:
		tmp = (b - ((d / c) * a)) / c
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d)
	tmp = 0.0
	if (d <= -6.5e+163)
		tmp = t_0;
	elseif (d <= -2.8e-156)
		tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 4.6e+48)
		tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((c * (b / d)) - a) / d;
	tmp = 0.0;
	if (d <= -6.5e+163)
		tmp = t_0;
	elseif (d <= -2.8e-156)
		tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
	elseif (d <= 4.6e+48)
		tmp = (b - ((d / c) * a)) / c;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -6.5e+163], t$95$0, If[LessEqual[d, -2.8e-156], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.6e+48], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -6.5 \cdot 10^{+163}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq -2.8 \cdot 10^{-156}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\

\mathbf{elif}\;d \leq 4.6 \cdot 10^{+48}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -6.4999999999999998e163 or 4.6e48 < d

    1. Initial program 39.5%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around 0

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{b \cdot c}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} + -1 \cdot \frac{a}{d}} \]
      2. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} - \left(\mathsf{neg}\left(-1\right)\right) \cdot \frac{a}{d}} \]
      3. unpow2N/A

        \[\leadsto \frac{b \cdot c}{\color{blue}{d \cdot d}} - \left(\mathsf{neg}\left(-1\right)\right) \cdot \frac{a}{d} \]
      4. associate-/r*N/A

        \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d}}{d}} - \left(\mathsf{neg}\left(-1\right)\right) \cdot \frac{a}{d} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\frac{b \cdot c}{d}}{d} - \color{blue}{1} \cdot \frac{a}{d} \]
      6. *-lft-identityN/A

        \[\leadsto \frac{\frac{b \cdot c}{d}}{d} - \color{blue}{\frac{a}{d}} \]
      7. div-subN/A

        \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d} - a}{d}} \]
      8. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d} - a}{d}} \]
      9. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{b \cdot c}{d} - a}}{d} \]
      10. lower-/.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{b \cdot c}{d}} - a}{d} \]
      11. lower-*.f6478.0

        \[\leadsto \frac{\frac{\color{blue}{b \cdot c}}{d} - a}{d} \]
    5. Applied rewrites78.0%

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d} - a}{d}} \]
    6. Step-by-step derivation
      1. Applied rewrites83.2%

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

      if -6.4999999999999998e163 < d < -2.8000000000000002e-156

      1. Initial program 77.6%

        \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
      2. Add Preprocessing

      if -2.8000000000000002e-156 < d < 4.6e48

      1. Initial program 70.1%

        \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
      2. Add Preprocessing
      3. Taylor expanded in c around inf

        \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
      4. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
        2. fp-cancel-sign-sub-invN/A

          \[\leadsto \frac{\color{blue}{b - \left(\mathsf{neg}\left(-1\right)\right) \cdot \frac{a \cdot d}{c}}}{c} \]
        3. metadata-evalN/A

          \[\leadsto \frac{b - \color{blue}{1} \cdot \frac{a \cdot d}{c}}{c} \]
        4. *-lft-identityN/A

          \[\leadsto \frac{b - \color{blue}{\frac{a \cdot d}{c}}}{c} \]
        5. lower--.f64N/A

          \[\leadsto \frac{\color{blue}{b - \frac{a \cdot d}{c}}}{c} \]
        6. lower-/.f64N/A

          \[\leadsto \frac{b - \color{blue}{\frac{a \cdot d}{c}}}{c} \]
        7. lower-*.f6484.7

          \[\leadsto \frac{b - \frac{\color{blue}{a \cdot d}}{c}}{c} \]
      5. Applied rewrites84.7%

        \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
      6. Step-by-step derivation
        1. Applied rewrites86.6%

          \[\leadsto \frac{b - \frac{d}{c} \cdot a}{c} \]
      7. Recombined 3 regimes into one program.
      8. Add Preprocessing

      Alternative 2: 78.9% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -7 \cdot 10^{-29} \lor \neg \left(d \leq 4.6 \cdot 10^{+48}\right):\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (if (or (<= d -7e-29) (not (<= d 4.6e+48)))
         (/ (- (* c (/ b d)) a) d)
         (/ (- b (* (/ d c) a)) c)))
      double code(double a, double b, double c, double d) {
      	double tmp;
      	if ((d <= -7e-29) || !(d <= 4.6e+48)) {
      		tmp = ((c * (b / d)) - a) / d;
      	} else {
      		tmp = (b - ((d / c) * a)) / c;
      	}
      	return tmp;
      }
      
      real(8) function code(a, b, c, d)
          real(8), intent (in) :: a
          real(8), intent (in) :: b
          real(8), intent (in) :: c
          real(8), intent (in) :: d
          real(8) :: tmp
          if ((d <= (-7d-29)) .or. (.not. (d <= 4.6d+48))) then
              tmp = ((c * (b / d)) - a) / d
          else
              tmp = (b - ((d / c) * a)) / c
          end if
          code = tmp
      end function
      
      public static double code(double a, double b, double c, double d) {
      	double tmp;
      	if ((d <= -7e-29) || !(d <= 4.6e+48)) {
      		tmp = ((c * (b / d)) - a) / d;
      	} else {
      		tmp = (b - ((d / c) * a)) / c;
      	}
      	return tmp;
      }
      
      def code(a, b, c, d):
      	tmp = 0
      	if (d <= -7e-29) or not (d <= 4.6e+48):
      		tmp = ((c * (b / d)) - a) / d
      	else:
      		tmp = (b - ((d / c) * a)) / c
      	return tmp
      
      function code(a, b, c, d)
      	tmp = 0.0
      	if ((d <= -7e-29) || !(d <= 4.6e+48))
      		tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d);
      	else
      		tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c);
      	end
      	return tmp
      end
      
      function tmp_2 = code(a, b, c, d)
      	tmp = 0.0;
      	if ((d <= -7e-29) || ~((d <= 4.6e+48)))
      		tmp = ((c * (b / d)) - a) / d;
      	else
      		tmp = (b - ((d / c) * a)) / c;
      	end
      	tmp_2 = tmp;
      end
      
      code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7e-29], N[Not[LessEqual[d, 4.6e+48]], $MachinePrecision]], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;d \leq -7 \cdot 10^{-29} \lor \neg \left(d \leq 4.6 \cdot 10^{+48}\right):\\
      \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if d < -6.9999999999999995e-29 or 4.6e48 < d

        1. Initial program 50.9%

          \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
        2. Add Preprocessing
        3. Taylor expanded in c around 0

          \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{b \cdot c}{{d}^{2}}} \]
        4. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} + -1 \cdot \frac{a}{d}} \]
          2. fp-cancel-sign-sub-invN/A

            \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} - \left(\mathsf{neg}\left(-1\right)\right) \cdot \frac{a}{d}} \]
          3. unpow2N/A

            \[\leadsto \frac{b \cdot c}{\color{blue}{d \cdot d}} - \left(\mathsf{neg}\left(-1\right)\right) \cdot \frac{a}{d} \]
          4. associate-/r*N/A

            \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d}}{d}} - \left(\mathsf{neg}\left(-1\right)\right) \cdot \frac{a}{d} \]
          5. metadata-evalN/A

            \[\leadsto \frac{\frac{b \cdot c}{d}}{d} - \color{blue}{1} \cdot \frac{a}{d} \]
          6. *-lft-identityN/A

            \[\leadsto \frac{\frac{b \cdot c}{d}}{d} - \color{blue}{\frac{a}{d}} \]
          7. div-subN/A

            \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d} - a}{d}} \]
          8. lower-/.f64N/A

            \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d} - a}{d}} \]
          9. lower--.f64N/A

            \[\leadsto \frac{\color{blue}{\frac{b \cdot c}{d} - a}}{d} \]
          10. lower-/.f64N/A

            \[\leadsto \frac{\color{blue}{\frac{b \cdot c}{d}} - a}{d} \]
          11. lower-*.f6474.6

            \[\leadsto \frac{\frac{\color{blue}{b \cdot c}}{d} - a}{d} \]
        5. Applied rewrites74.6%

          \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d} - a}{d}} \]
        6. Step-by-step derivation
          1. Applied rewrites79.1%

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

          if -6.9999999999999995e-29 < d < 4.6e48

          1. Initial program 70.9%

            \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
          2. Add Preprocessing
          3. Taylor expanded in c around inf

            \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
          4. Step-by-step derivation
            1. lower-/.f64N/A

              \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
            2. fp-cancel-sign-sub-invN/A

              \[\leadsto \frac{\color{blue}{b - \left(\mathsf{neg}\left(-1\right)\right) \cdot \frac{a \cdot d}{c}}}{c} \]
            3. metadata-evalN/A

              \[\leadsto \frac{b - \color{blue}{1} \cdot \frac{a \cdot d}{c}}{c} \]
            4. *-lft-identityN/A

              \[\leadsto \frac{b - \color{blue}{\frac{a \cdot d}{c}}}{c} \]
            5. lower--.f64N/A

              \[\leadsto \frac{\color{blue}{b - \frac{a \cdot d}{c}}}{c} \]
            6. lower-/.f64N/A

              \[\leadsto \frac{b - \color{blue}{\frac{a \cdot d}{c}}}{c} \]
            7. lower-*.f6481.6

              \[\leadsto \frac{b - \frac{\color{blue}{a \cdot d}}{c}}{c} \]
          5. Applied rewrites81.6%

            \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
          6. Step-by-step derivation
            1. Applied rewrites83.1%

              \[\leadsto \frac{b - \frac{d}{c} \cdot a}{c} \]
          7. Recombined 2 regimes into one program.
          8. Final simplification81.0%

            \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7 \cdot 10^{-29} \lor \neg \left(d \leq 4.6 \cdot 10^{+48}\right):\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\ \end{array} \]
          9. Add Preprocessing

          Alternative 3: 70.6% accurate, 0.9× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -4.8 \cdot 10^{-25} \lor \neg \left(d \leq 1.95 \cdot 10^{+164}\right):\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\ \end{array} \end{array} \]
          (FPCore (a b c d)
           :precision binary64
           (if (or (<= d -4.8e-25) (not (<= d 1.95e+164)))
             (/ a (- d))
             (/ (- b (* (/ d c) a)) c)))
          double code(double a, double b, double c, double d) {
          	double tmp;
          	if ((d <= -4.8e-25) || !(d <= 1.95e+164)) {
          		tmp = a / -d;
          	} else {
          		tmp = (b - ((d / c) * a)) / c;
          	}
          	return tmp;
          }
          
          real(8) function code(a, b, c, d)
              real(8), intent (in) :: a
              real(8), intent (in) :: b
              real(8), intent (in) :: c
              real(8), intent (in) :: d
              real(8) :: tmp
              if ((d <= (-4.8d-25)) .or. (.not. (d <= 1.95d+164))) then
                  tmp = a / -d
              else
                  tmp = (b - ((d / c) * a)) / c
              end if
              code = tmp
          end function
          
          public static double code(double a, double b, double c, double d) {
          	double tmp;
          	if ((d <= -4.8e-25) || !(d <= 1.95e+164)) {
          		tmp = a / -d;
          	} else {
          		tmp = (b - ((d / c) * a)) / c;
          	}
          	return tmp;
          }
          
          def code(a, b, c, d):
          	tmp = 0
          	if (d <= -4.8e-25) or not (d <= 1.95e+164):
          		tmp = a / -d
          	else:
          		tmp = (b - ((d / c) * a)) / c
          	return tmp
          
          function code(a, b, c, d)
          	tmp = 0.0
          	if ((d <= -4.8e-25) || !(d <= 1.95e+164))
          		tmp = Float64(a / Float64(-d));
          	else
          		tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c);
          	end
          	return tmp
          end
          
          function tmp_2 = code(a, b, c, d)
          	tmp = 0.0;
          	if ((d <= -4.8e-25) || ~((d <= 1.95e+164)))
          		tmp = a / -d;
          	else
          		tmp = (b - ((d / c) * a)) / c;
          	end
          	tmp_2 = tmp;
          end
          
          code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.8e-25], N[Not[LessEqual[d, 1.95e+164]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;d \leq -4.8 \cdot 10^{-25} \lor \neg \left(d \leq 1.95 \cdot 10^{+164}\right):\\
          \;\;\;\;\frac{a}{-d}\\
          
          \mathbf{else}:\\
          \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if d < -4.80000000000000018e-25 or 1.94999999999999993e164 < d

            1. Initial program 52.0%

              \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
            2. Add Preprocessing
            3. Taylor expanded in c around 0

              \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
            4. Step-by-step derivation
              1. mul-1-negN/A

                \[\leadsto \color{blue}{\mathsf{neg}\left(\frac{a}{d}\right)} \]
              2. distribute-neg-frac2N/A

                \[\leadsto \color{blue}{\frac{a}{\mathsf{neg}\left(d\right)}} \]
              3. mul-1-negN/A

                \[\leadsto \frac{a}{\color{blue}{-1 \cdot d}} \]
              4. lower-/.f64N/A

                \[\leadsto \color{blue}{\frac{a}{-1 \cdot d}} \]
              5. mul-1-negN/A

                \[\leadsto \frac{a}{\color{blue}{\mathsf{neg}\left(d\right)}} \]
              6. lower-neg.f6476.7

                \[\leadsto \frac{a}{\color{blue}{-d}} \]
            5. Applied rewrites76.7%

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

            if -4.80000000000000018e-25 < d < 1.94999999999999993e164

            1. Initial program 67.2%

              \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
            2. Add Preprocessing
            3. Taylor expanded in c around inf

              \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
            4. Step-by-step derivation
              1. lower-/.f64N/A

                \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
              2. fp-cancel-sign-sub-invN/A

                \[\leadsto \frac{\color{blue}{b - \left(\mathsf{neg}\left(-1\right)\right) \cdot \frac{a \cdot d}{c}}}{c} \]
              3. metadata-evalN/A

                \[\leadsto \frac{b - \color{blue}{1} \cdot \frac{a \cdot d}{c}}{c} \]
              4. *-lft-identityN/A

                \[\leadsto \frac{b - \color{blue}{\frac{a \cdot d}{c}}}{c} \]
              5. lower--.f64N/A

                \[\leadsto \frac{\color{blue}{b - \frac{a \cdot d}{c}}}{c} \]
              6. lower-/.f64N/A

                \[\leadsto \frac{b - \color{blue}{\frac{a \cdot d}{c}}}{c} \]
              7. lower-*.f6475.0

                \[\leadsto \frac{b - \frac{\color{blue}{a \cdot d}}{c}}{c} \]
            5. Applied rewrites75.0%

              \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
            6. Step-by-step derivation
              1. Applied rewrites77.8%

                \[\leadsto \frac{b - \frac{d}{c} \cdot a}{c} \]
            7. Recombined 2 regimes into one program.
            8. Final simplification77.3%

              \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.8 \cdot 10^{-25} \lor \neg \left(d \leq 1.95 \cdot 10^{+164}\right):\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\ \end{array} \]
            9. Add Preprocessing

            Alternative 4: 62.2% accurate, 0.9× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{-d}\\ \mathbf{if}\;d \leq -6.5 \cdot 10^{+163}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq -9.5 \cdot 10^{-76}:\\ \;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;d \leq 1.95 \cdot 10^{+164}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
            (FPCore (a b c d)
             :precision binary64
             (let* ((t_0 (/ a (- d))))
               (if (<= d -6.5e+163)
                 t_0
                 (if (<= d -9.5e-76)
                   (* (- a) (/ d (fma d d (* c c))))
                   (if (<= d 1.95e+164) (/ b c) t_0)))))
            double code(double a, double b, double c, double d) {
            	double t_0 = a / -d;
            	double tmp;
            	if (d <= -6.5e+163) {
            		tmp = t_0;
            	} else if (d <= -9.5e-76) {
            		tmp = -a * (d / fma(d, d, (c * c)));
            	} else if (d <= 1.95e+164) {
            		tmp = b / c;
            	} else {
            		tmp = t_0;
            	}
            	return tmp;
            }
            
            function code(a, b, c, d)
            	t_0 = Float64(a / Float64(-d))
            	tmp = 0.0
            	if (d <= -6.5e+163)
            		tmp = t_0;
            	elseif (d <= -9.5e-76)
            		tmp = Float64(Float64(-a) * Float64(d / fma(d, d, Float64(c * c))));
            	elseif (d <= 1.95e+164)
            		tmp = Float64(b / c);
            	else
            		tmp = t_0;
            	end
            	return tmp
            end
            
            code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / (-d)), $MachinePrecision]}, If[LessEqual[d, -6.5e+163], t$95$0, If[LessEqual[d, -9.5e-76], N[((-a) * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.95e+164], N[(b / c), $MachinePrecision], t$95$0]]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_0 := \frac{a}{-d}\\
            \mathbf{if}\;d \leq -6.5 \cdot 10^{+163}:\\
            \;\;\;\;t\_0\\
            
            \mathbf{elif}\;d \leq -9.5 \cdot 10^{-76}:\\
            \;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
            
            \mathbf{elif}\;d \leq 1.95 \cdot 10^{+164}:\\
            \;\;\;\;\frac{b}{c}\\
            
            \mathbf{else}:\\
            \;\;\;\;t\_0\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 3 regimes
            2. if d < -6.4999999999999998e163 or 1.94999999999999993e164 < d

              1. Initial program 38.0%

                \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
              2. Add Preprocessing
              3. Taylor expanded in c around 0

                \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
              4. Step-by-step derivation
                1. mul-1-negN/A

                  \[\leadsto \color{blue}{\mathsf{neg}\left(\frac{a}{d}\right)} \]
                2. distribute-neg-frac2N/A

                  \[\leadsto \color{blue}{\frac{a}{\mathsf{neg}\left(d\right)}} \]
                3. mul-1-negN/A

                  \[\leadsto \frac{a}{\color{blue}{-1 \cdot d}} \]
                4. lower-/.f64N/A

                  \[\leadsto \color{blue}{\frac{a}{-1 \cdot d}} \]
                5. mul-1-negN/A

                  \[\leadsto \frac{a}{\color{blue}{\mathsf{neg}\left(d\right)}} \]
                6. lower-neg.f6484.6

                  \[\leadsto \frac{a}{\color{blue}{-d}} \]
              5. Applied rewrites84.6%

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

              if -6.4999999999999998e163 < d < -9.49999999999999984e-76

              1. Initial program 77.3%

                \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
              2. Add Preprocessing
              3. Taylor expanded in a around inf

                \[\leadsto \color{blue}{-1 \cdot \frac{a \cdot d}{{c}^{2} + {d}^{2}}} \]
              4. Step-by-step derivation
                1. associate-/l*N/A

                  \[\leadsto -1 \cdot \color{blue}{\left(a \cdot \frac{d}{{c}^{2} + {d}^{2}}\right)} \]
                2. associate-*r*N/A

                  \[\leadsto \color{blue}{\left(-1 \cdot a\right) \cdot \frac{d}{{c}^{2} + {d}^{2}}} \]
                3. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(-1 \cdot a\right) \cdot \frac{d}{{c}^{2} + {d}^{2}}} \]
                4. mul-1-negN/A

                  \[\leadsto \color{blue}{\left(\mathsf{neg}\left(a\right)\right)} \cdot \frac{d}{{c}^{2} + {d}^{2}} \]
                5. lower-neg.f64N/A

                  \[\leadsto \color{blue}{\left(-a\right)} \cdot \frac{d}{{c}^{2} + {d}^{2}} \]
                6. lower-/.f64N/A

                  \[\leadsto \left(-a\right) \cdot \color{blue}{\frac{d}{{c}^{2} + {d}^{2}}} \]
                7. +-commutativeN/A

                  \[\leadsto \left(-a\right) \cdot \frac{d}{\color{blue}{{d}^{2} + {c}^{2}}} \]
                8. unpow2N/A

                  \[\leadsto \left(-a\right) \cdot \frac{d}{\color{blue}{d \cdot d} + {c}^{2}} \]
                9. lower-fma.f64N/A

                  \[\leadsto \left(-a\right) \cdot \frac{d}{\color{blue}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
                10. unpow2N/A

                  \[\leadsto \left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)} \]
                11. lower-*.f6465.3

                  \[\leadsto \left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)} \]
              5. Applied rewrites65.3%

                \[\leadsto \color{blue}{\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]

              if -9.49999999999999984e-76 < d < 1.94999999999999993e164

              1. Initial program 67.3%

                \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
              2. Add Preprocessing
              3. Taylor expanded in c around inf

                \[\leadsto \color{blue}{\frac{b}{c}} \]
              4. Step-by-step derivation
                1. lower-/.f6461.6

                  \[\leadsto \color{blue}{\frac{b}{c}} \]
              5. Applied rewrites61.6%

                \[\leadsto \color{blue}{\frac{b}{c}} \]
            3. Recombined 3 regimes into one program.
            4. Add Preprocessing

            Alternative 5: 61.2% accurate, 1.5× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -4.8 \cdot 10^{-31} \lor \neg \left(d \leq 1.95 \cdot 10^{+164}\right):\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
            (FPCore (a b c d)
             :precision binary64
             (if (or (<= d -4.8e-31) (not (<= d 1.95e+164))) (/ a (- d)) (/ b c)))
            double code(double a, double b, double c, double d) {
            	double tmp;
            	if ((d <= -4.8e-31) || !(d <= 1.95e+164)) {
            		tmp = a / -d;
            	} else {
            		tmp = b / c;
            	}
            	return tmp;
            }
            
            real(8) function code(a, b, c, d)
                real(8), intent (in) :: a
                real(8), intent (in) :: b
                real(8), intent (in) :: c
                real(8), intent (in) :: d
                real(8) :: tmp
                if ((d <= (-4.8d-31)) .or. (.not. (d <= 1.95d+164))) then
                    tmp = a / -d
                else
                    tmp = b / c
                end if
                code = tmp
            end function
            
            public static double code(double a, double b, double c, double d) {
            	double tmp;
            	if ((d <= -4.8e-31) || !(d <= 1.95e+164)) {
            		tmp = a / -d;
            	} else {
            		tmp = b / c;
            	}
            	return tmp;
            }
            
            def code(a, b, c, d):
            	tmp = 0
            	if (d <= -4.8e-31) or not (d <= 1.95e+164):
            		tmp = a / -d
            	else:
            		tmp = b / c
            	return tmp
            
            function code(a, b, c, d)
            	tmp = 0.0
            	if ((d <= -4.8e-31) || !(d <= 1.95e+164))
            		tmp = Float64(a / Float64(-d));
            	else
            		tmp = Float64(b / c);
            	end
            	return tmp
            end
            
            function tmp_2 = code(a, b, c, d)
            	tmp = 0.0;
            	if ((d <= -4.8e-31) || ~((d <= 1.95e+164)))
            		tmp = a / -d;
            	else
            		tmp = b / c;
            	end
            	tmp_2 = tmp;
            end
            
            code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.8e-31], N[Not[LessEqual[d, 1.95e+164]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(b / c), $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;d \leq -4.8 \cdot 10^{-31} \lor \neg \left(d \leq 1.95 \cdot 10^{+164}\right):\\
            \;\;\;\;\frac{a}{-d}\\
            
            \mathbf{else}:\\
            \;\;\;\;\frac{b}{c}\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if d < -4.8e-31 or 1.94999999999999993e164 < d

              1. Initial program 52.0%

                \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
              2. Add Preprocessing
              3. Taylor expanded in c around 0

                \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
              4. Step-by-step derivation
                1. mul-1-negN/A

                  \[\leadsto \color{blue}{\mathsf{neg}\left(\frac{a}{d}\right)} \]
                2. distribute-neg-frac2N/A

                  \[\leadsto \color{blue}{\frac{a}{\mathsf{neg}\left(d\right)}} \]
                3. mul-1-negN/A

                  \[\leadsto \frac{a}{\color{blue}{-1 \cdot d}} \]
                4. lower-/.f64N/A

                  \[\leadsto \color{blue}{\frac{a}{-1 \cdot d}} \]
                5. mul-1-negN/A

                  \[\leadsto \frac{a}{\color{blue}{\mathsf{neg}\left(d\right)}} \]
                6. lower-neg.f6476.7

                  \[\leadsto \frac{a}{\color{blue}{-d}} \]
              5. Applied rewrites76.7%

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

              if -4.8e-31 < d < 1.94999999999999993e164

              1. Initial program 67.2%

                \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
              2. Add Preprocessing
              3. Taylor expanded in c around inf

                \[\leadsto \color{blue}{\frac{b}{c}} \]
              4. Step-by-step derivation
                1. lower-/.f6459.8

                  \[\leadsto \color{blue}{\frac{b}{c}} \]
              5. Applied rewrites59.8%

                \[\leadsto \color{blue}{\frac{b}{c}} \]
            3. Recombined 2 regimes into one program.
            4. Final simplification67.1%

              \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.8 \cdot 10^{-31} \lor \neg \left(d \leq 1.95 \cdot 10^{+164}\right):\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
            5. Add Preprocessing

            Alternative 6: 42.7% accurate, 3.2× speedup?

            \[\begin{array}{l} \\ \frac{b}{c} \end{array} \]
            (FPCore (a b c d) :precision binary64 (/ b c))
            double code(double a, double b, double c, double d) {
            	return b / c;
            }
            
            real(8) function code(a, b, c, d)
                real(8), intent (in) :: a
                real(8), intent (in) :: b
                real(8), intent (in) :: c
                real(8), intent (in) :: d
                code = b / c
            end function
            
            public static double code(double a, double b, double c, double d) {
            	return b / c;
            }
            
            def code(a, b, c, d):
            	return b / c
            
            function code(a, b, c, d)
            	return Float64(b / c)
            end
            
            function tmp = code(a, b, c, d)
            	tmp = b / c;
            end
            
            code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
            
            \begin{array}{l}
            
            \\
            \frac{b}{c}
            \end{array}
            
            Derivation
            1. Initial program 60.7%

              \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
            2. Add Preprocessing
            3. Taylor expanded in c around inf

              \[\leadsto \color{blue}{\frac{b}{c}} \]
            4. Step-by-step derivation
              1. lower-/.f6444.9

                \[\leadsto \color{blue}{\frac{b}{c}} \]
            5. Applied rewrites44.9%

              \[\leadsto \color{blue}{\frac{b}{c}} \]
            6. Add Preprocessing

            Developer Target 1: 99.3% accurate, 0.6× speedup?

            \[\begin{array}{l} \\ \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} \end{array} \]
            (FPCore (a b c d)
             :precision binary64
             (if (< (fabs d) (fabs c))
               (/ (- b (* a (/ d c))) (+ c (* d (/ d c))))
               (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
            double code(double a, double b, double c, double d) {
            	double tmp;
            	if (fabs(d) < fabs(c)) {
            		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
            	} else {
            		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
            	}
            	return tmp;
            }
            
            real(8) function code(a, b, c, d)
                real(8), intent (in) :: a
                real(8), intent (in) :: b
                real(8), intent (in) :: c
                real(8), intent (in) :: d
                real(8) :: tmp
                if (abs(d) < abs(c)) then
                    tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
                else
                    tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
                end if
                code = tmp
            end function
            
            public static double code(double a, double b, double c, double d) {
            	double tmp;
            	if (Math.abs(d) < Math.abs(c)) {
            		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
            	} else {
            		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
            	}
            	return tmp;
            }
            
            def code(a, b, c, d):
            	tmp = 0
            	if math.fabs(d) < math.fabs(c):
            		tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
            	else:
            		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
            	return tmp
            
            function code(a, b, c, d)
            	tmp = 0.0
            	if (abs(d) < abs(c))
            		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
            	else
            		tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d))));
            	end
            	return tmp
            end
            
            function tmp_2 = code(a, b, c, d)
            	tmp = 0.0;
            	if (abs(d) < abs(c))
            		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
            	else
            		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
            	end
            	tmp_2 = tmp;
            end
            
            code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \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}
            \end{array}
            

            Reproduce

            ?
            herbie shell --seed 2024343 
            (FPCore (a b c d)
              :name "Complex division, imag part"
              :precision binary64
            
              :alt
              (! :herbie-platform default (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))))