Complex division, imag part

Percentage Accurate: 62.0% → 97.1%
Time: 12.8s
Alternatives: 14
Speedup: 1.8×

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 14 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: 62.0% 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: 97.1% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{\frac{-a}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right) \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (fma
  (/ c (hypot c d))
  (/ b (hypot c d))
  (/ (/ (- a) (hypot c d)) (/ (hypot c d) d))))
double code(double a, double b, double c, double d) {
	return fma((c / hypot(c, d)), (b / hypot(c, d)), ((-a / hypot(c, d)) / (hypot(c, d) / d)));
}
function code(a, b, c, d)
	return fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(Float64(-a) / hypot(c, d)) / Float64(hypot(c, d) / d)))
end
code[a_, b_, c_, d_] := N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(N[((-a) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{\frac{-a}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)
\end{array}
Derivation
  1. Initial program 63.1%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Step-by-step derivation
    1. div-sub62.3%

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}} \]
    2. sub-neg62.3%

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right)} \]
    3. *-commutative62.3%

      \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    4. add-sqr-sqrt62.3%

      \[\leadsto \frac{c \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    5. times-frac63.4%

      \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    6. fma-def63.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\sqrt{c \cdot c + d \cdot d}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)} \]
    7. hypot-def63.5%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    8. hypot-def76.5%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    9. associate-/l*79.2%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{a}{\frac{c \cdot c + d \cdot d}{d}}}\right) \]
    10. add-sqr-sqrt79.2%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}{d}}\right) \]
    11. pow279.2%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{\color{blue}{{\left(\sqrt{c \cdot c + d \cdot d}\right)}^{2}}}{d}}\right) \]
    12. hypot-def79.2%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}{d}}\right) \]
  3. Applied egg-rr79.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{d}}\right)} \]
  4. Step-by-step derivation
    1. div-inv79.1%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\color{blue}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2} \cdot \frac{1}{d}}}\right) \]
    2. unpow279.1%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\color{blue}{\left(\mathsf{hypot}\left(c, d\right) \cdot \mathsf{hypot}\left(c, d\right)\right)} \cdot \frac{1}{d}}\right) \]
    3. associate-*l*95.3%

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

    \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\color{blue}{\mathsf{hypot}\left(c, d\right) \cdot \left(\mathsf{hypot}\left(c, d\right) \cdot \frac{1}{d}\right)}}\right) \]
  6. Step-by-step derivation
    1. *-un-lft-identity95.3%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{\color{blue}{1 \cdot a}}{\mathsf{hypot}\left(c, d\right) \cdot \left(\mathsf{hypot}\left(c, d\right) \cdot \frac{1}{d}\right)}\right) \]
    2. times-frac98.4%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right) \cdot \frac{1}{d}}}\right) \]
    3. un-div-inv98.4%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\color{blue}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}}\right) \]
    4. associate-/l*83.7%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}\right) \]
    5. *-commutative83.7%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{d \cdot a}}{\mathsf{hypot}\left(c, d\right)}\right) \]
    6. *-un-lft-identity83.7%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d \cdot a}{\color{blue}{1 \cdot \mathsf{hypot}\left(c, d\right)}}\right) \]
    7. times-frac98.1%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(\frac{d}{1} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\right)}\right) \]
    8. /-rgt-identity98.1%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\color{blue}{d} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\right)\right) \]
  7. Applied egg-rr98.1%

    \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\right)}\right) \]
  8. Step-by-step derivation
    1. associate-*r*98.2%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot d\right) \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}}\right) \]
    2. associate-/r/98.2%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\right) \]
    3. associate-*l/98.2%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{1 \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}}\right) \]
    4. *-lft-identity98.2%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{\color{blue}{\frac{a}{\mathsf{hypot}\left(c, d\right)}}}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right) \]
  9. Simplified98.2%

    \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{\frac{\frac{a}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}}\right) \]
  10. Final simplification98.2%

    \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{\frac{-a}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right) \]

Alternative 2: 97.3% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{c}{\frac{\mathsf{hypot}\left(c, d\right)}{b}} - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\right) \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (* (/ 1.0 (hypot c d)) (- (/ c (/ (hypot c d) b)) (* d (/ a (hypot c d))))))
double code(double a, double b, double c, double d) {
	return (1.0 / hypot(c, d)) * ((c / (hypot(c, d) / b)) - (d * (a / hypot(c, d))));
}
public static double code(double a, double b, double c, double d) {
	return (1.0 / Math.hypot(c, d)) * ((c / (Math.hypot(c, d) / b)) - (d * (a / Math.hypot(c, d))));
}
def code(a, b, c, d):
	return (1.0 / math.hypot(c, d)) * ((c / (math.hypot(c, d) / b)) - (d * (a / math.hypot(c, d))))
function code(a, b, c, d)
	return Float64(Float64(1.0 / hypot(c, d)) * Float64(Float64(c / Float64(hypot(c, d) / b)) - Float64(d * Float64(a / hypot(c, d)))))
end
function tmp = code(a, b, c, d)
	tmp = (1.0 / hypot(c, d)) * ((c / (hypot(c, d) / b)) - (d * (a / hypot(c, d))));
end
code[a_, b_, c_, d_] := N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(c / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] - N[(d * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{c}{\frac{\mathsf{hypot}\left(c, d\right)}{b}} - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\right)
\end{array}
Derivation
  1. Initial program 63.1%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Step-by-step derivation
    1. *-un-lft-identity63.1%

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
    2. add-sqr-sqrt63.1%

      \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
    3. times-frac63.1%

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
    4. hypot-def63.1%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
    5. hypot-def76.1%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
  3. Applied egg-rr76.1%

    \[\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)}} \]
  4. Step-by-step derivation
    1. div-sub76.1%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)} - \frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}\right)} \]
    2. *-commutative76.1%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{\color{blue}{c \cdot b}}{\mathsf{hypot}\left(c, d\right)} - \frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}\right) \]
    3. associate-/l*83.3%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\color{blue}{\frac{c}{\frac{\mathsf{hypot}\left(c, d\right)}{b}}} - \frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}\right) \]
    4. *-commutative83.3%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{c}{\frac{\mathsf{hypot}\left(c, d\right)}{b}} - \frac{\color{blue}{d \cdot a}}{\mathsf{hypot}\left(c, d\right)}\right) \]
    5. *-un-lft-identity83.3%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{c}{\frac{\mathsf{hypot}\left(c, d\right)}{b}} - \frac{d \cdot a}{\color{blue}{1 \cdot \mathsf{hypot}\left(c, d\right)}}\right) \]
    6. times-frac97.7%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{c}{\frac{\mathsf{hypot}\left(c, d\right)}{b}} - \color{blue}{\frac{d}{1} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}}\right) \]
    7. /-rgt-identity97.7%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{c}{\frac{\mathsf{hypot}\left(c, d\right)}{b}} - \color{blue}{d} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\right) \]
  5. Applied egg-rr97.7%

    \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(\frac{c}{\frac{\mathsf{hypot}\left(c, d\right)}{b}} - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\right)} \]
  6. Final simplification97.7%

    \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{c}{\frac{\mathsf{hypot}\left(c, d\right)}{b}} - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\right) \]

Alternative 3: 85.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot b - d \cdot a\\ \mathbf{if}\;\frac{t_0}{c \cdot c + d \cdot d} \leq 10^{+277}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (- (* c b) (* d a))))
   (if (<= (/ t_0 (+ (* c c) (* d d))) 1e+277)
     (* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
     (* (/ 1.0 c) (- b (/ a (/ c d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * b) - (d * a);
	double tmp;
	if ((t_0 / ((c * c) + (d * d))) <= 1e+277) {
		tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
	} else {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = (c * b) - (d * a);
	double tmp;
	if ((t_0 / ((c * c) + (d * d))) <= 1e+277) {
		tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
	} else {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (c * b) - (d * a)
	tmp = 0
	if (t_0 / ((c * c) + (d * d))) <= 1e+277:
		tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d))
	else:
		tmp = (1.0 / c) * (b - (a / (c / d)))
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(c * b) - Float64(d * a))
	tmp = 0.0
	if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= 1e+277)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d)));
	else
		tmp = Float64(Float64(1.0 / c) * Float64(b - Float64(a / Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (c * b) - (d * a);
	tmp = 0.0;
	if ((t_0 / ((c * c) + (d * d))) <= 1e+277)
		tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
	else
		tmp = (1.0 / c) * (b - (a / (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+277], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / c), $MachinePrecision] * N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := c \cdot b - d \cdot a\\
\mathbf{if}\;\frac{t_0}{c \cdot c + d \cdot d} \leq 10^{+277}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1e277

    1. Initial program 81.9%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity81.9%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt81.9%

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def81.8%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def97.5%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr97.5%

      \[\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)}} \]

    if 1e277 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 13.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity13.3%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt13.3%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac13.3%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def13.3%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def19.3%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr19.3%

      \[\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)}} \]
    4. Taylor expanded in c around inf 21.5%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b + -1 \cdot \frac{a \cdot d}{c}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg21.5%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \color{blue}{\left(-\frac{a \cdot d}{c}\right)}\right) \]
      2. unsub-neg21.5%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a \cdot d}{c}\right)} \]
      3. associate-/l*27.3%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \color{blue}{\frac{a}{\frac{c}{d}}}\right) \]
    6. Simplified27.3%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a}{\frac{c}{d}}\right)} \]
    7. Taylor expanded in c around inf 58.6%

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(b - \frac{a}{\frac{c}{d}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification86.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d} \leq 10^{+277}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \end{array} \]

Alternative 4: 79.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \frac{b}{\frac{d}{c}}\\ \mathbf{if}\;d \leq -4.8 \cdot 10^{-39}:\\ \;\;\;\;t_0 \cdot \left(a - t_1\right)\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{-153}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 2.45 \cdot 10^{+135}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \left(t_1 - a\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ 1.0 (hypot c d))) (t_1 (/ b (/ d c))))
   (if (<= d -4.8e-39)
     (* t_0 (- a t_1))
     (if (<= d 3.3e-153)
       (* (/ 1.0 c) (- b (/ a (/ c d))))
       (if (<= d 2.45e+135)
         (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
         (* t_0 (- t_1 a)))))))
double code(double a, double b, double c, double d) {
	double t_0 = 1.0 / hypot(c, d);
	double t_1 = b / (d / c);
	double tmp;
	if (d <= -4.8e-39) {
		tmp = t_0 * (a - t_1);
	} else if (d <= 3.3e-153) {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	} else if (d <= 2.45e+135) {
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	} else {
		tmp = t_0 * (t_1 - a);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = 1.0 / Math.hypot(c, d);
	double t_1 = b / (d / c);
	double tmp;
	if (d <= -4.8e-39) {
		tmp = t_0 * (a - t_1);
	} else if (d <= 3.3e-153) {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	} else if (d <= 2.45e+135) {
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	} else {
		tmp = t_0 * (t_1 - a);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = 1.0 / math.hypot(c, d)
	t_1 = b / (d / c)
	tmp = 0
	if d <= -4.8e-39:
		tmp = t_0 * (a - t_1)
	elif d <= 3.3e-153:
		tmp = (1.0 / c) * (b - (a / (c / d)))
	elif d <= 2.45e+135:
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d))
	else:
		tmp = t_0 * (t_1 - a)
	return tmp
function code(a, b, c, d)
	t_0 = Float64(1.0 / hypot(c, d))
	t_1 = Float64(b / Float64(d / c))
	tmp = 0.0
	if (d <= -4.8e-39)
		tmp = Float64(t_0 * Float64(a - t_1));
	elseif (d <= 3.3e-153)
		tmp = Float64(Float64(1.0 / c) * Float64(b - Float64(a / Float64(c / d))));
	elseif (d <= 2.45e+135)
		tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = Float64(t_0 * Float64(t_1 - a));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = 1.0 / hypot(c, d);
	t_1 = b / (d / c);
	tmp = 0.0;
	if (d <= -4.8e-39)
		tmp = t_0 * (a - t_1);
	elseif (d <= 3.3e-153)
		tmp = (1.0 / c) * (b - (a / (c / d)));
	elseif (d <= 2.45e+135)
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	else
		tmp = t_0 * (t_1 - a);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b / N[(d / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -4.8e-39], N[(t$95$0 * N[(a - t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.3e-153], N[(N[(1.0 / c), $MachinePrecision] * N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.45e+135], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(t$95$1 - a), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \frac{b}{\frac{d}{c}}\\
\mathbf{if}\;d \leq -4.8 \cdot 10^{-39}:\\
\;\;\;\;t_0 \cdot \left(a - t_1\right)\\

\mathbf{elif}\;d \leq 3.3 \cdot 10^{-153}:\\
\;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\

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

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(t_1 - a\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -4.80000000000000031e-39

    1. Initial program 50.2%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity50.2%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt50.2%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac50.1%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def50.1%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def70.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr70.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)}} \]
    4. Taylor expanded in d around -inf 72.7%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(a + -1 \cdot \frac{b \cdot c}{d}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg72.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \color{blue}{\left(-\frac{b \cdot c}{d}\right)}\right) \]
      2. unsub-neg72.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(a - \frac{b \cdot c}{d}\right)} \]
      3. associate-/l*75.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a - \color{blue}{\frac{b}{\frac{d}{c}}}\right) \]
    6. Simplified75.7%

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

    if -4.80000000000000031e-39 < d < 3.29999999999999988e-153

    1. Initial program 69.4%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity69.4%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt69.4%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac69.4%

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def81.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr81.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)}} \]
    4. Taylor expanded in c around inf 51.2%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b + -1 \cdot \frac{a \cdot d}{c}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg51.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \color{blue}{\left(-\frac{a \cdot d}{c}\right)}\right) \]
      2. unsub-neg51.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a \cdot d}{c}\right)} \]
      3. associate-/l*51.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \color{blue}{\frac{a}{\frac{c}{d}}}\right) \]
    6. Simplified51.2%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a}{\frac{c}{d}}\right)} \]
    7. Taylor expanded in c around inf 92.2%

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(b - \frac{a}{\frac{c}{d}}\right) \]

    if 3.29999999999999988e-153 < d < 2.4500000000000001e135

    1. Initial program 87.3%

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

    if 2.4500000000000001e135 < d

    1. Initial program 40.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity40.3%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt40.3%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac40.3%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def40.3%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def51.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr51.2%

      \[\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)}} \]
    4. Taylor expanded in c around 0 81.4%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-1 \cdot a + \frac{b \cdot c}{d}\right)} \]
    5. Step-by-step derivation
      1. +-commutative81.4%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(\frac{b \cdot c}{d} + -1 \cdot a\right)} \]
      2. neg-mul-181.4%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{b \cdot c}{d} + \color{blue}{\left(-a\right)}\right) \]
      3. unsub-neg81.4%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(\frac{b \cdot c}{d} - a\right)} \]
      4. associate-/l*87.0%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\color{blue}{\frac{b}{\frac{d}{c}}} - a\right) \]
    6. Simplified87.0%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(\frac{b}{\frac{d}{c}} - a\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification85.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.8 \cdot 10^{-39}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a - \frac{b}{\frac{d}{c}}\right)\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{-153}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 2.45 \cdot 10^{+135}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{b}{\frac{d}{c}} - a\right)\\ \end{array} \]

Alternative 5: 78.5% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -1.25 \cdot 10^{+52}:\\ \;\;\;\;a \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -5 \cdot 10^{-128}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.6 \cdot 10^{-148}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{+151}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;a \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
   (if (<= d -1.25e+52)
     (* a (/ 1.0 (hypot c d)))
     (if (<= d -5e-128)
       t_0
       (if (<= d 1.6e-148)
         (* (/ 1.0 c) (- b (/ a (/ c d))))
         (if (<= d 5.8e+151) t_0 (* a (/ -1.0 (hypot c d)))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -1.25e+52) {
		tmp = a * (1.0 / hypot(c, d));
	} else if (d <= -5e-128) {
		tmp = t_0;
	} else if (d <= 1.6e-148) {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	} else if (d <= 5.8e+151) {
		tmp = t_0;
	} else {
		tmp = a * (-1.0 / hypot(c, d));
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -1.25e+52) {
		tmp = a * (1.0 / Math.hypot(c, d));
	} else if (d <= -5e-128) {
		tmp = t_0;
	} else if (d <= 1.6e-148) {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	} else if (d <= 5.8e+151) {
		tmp = t_0;
	} else {
		tmp = a * (-1.0 / Math.hypot(c, d));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -1.25e+52:
		tmp = a * (1.0 / math.hypot(c, d))
	elif d <= -5e-128:
		tmp = t_0
	elif d <= 1.6e-148:
		tmp = (1.0 / c) * (b - (a / (c / d)))
	elif d <= 5.8e+151:
		tmp = t_0
	else:
		tmp = a * (-1.0 / math.hypot(c, d))
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (d <= -1.25e+52)
		tmp = Float64(a * Float64(1.0 / hypot(c, d)));
	elseif (d <= -5e-128)
		tmp = t_0;
	elseif (d <= 1.6e-148)
		tmp = Float64(Float64(1.0 / c) * Float64(b - Float64(a / Float64(c / d))));
	elseif (d <= 5.8e+151)
		tmp = t_0;
	else
		tmp = Float64(a * Float64(-1.0 / hypot(c, d)));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (d <= -1.25e+52)
		tmp = a * (1.0 / hypot(c, d));
	elseif (d <= -5e-128)
		tmp = t_0;
	elseif (d <= 1.6e-148)
		tmp = (1.0 / c) * (b - (a / (c / d)));
	elseif (d <= 5.8e+151)
		tmp = t_0;
	else
		tmp = a * (-1.0 / hypot(c, d));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.25e+52], N[(a * N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5e-128], t$95$0, If[LessEqual[d, 1.6e-148], N[(N[(1.0 / c), $MachinePrecision] * N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.8e+151], t$95$0, N[(a * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.25 \cdot 10^{+52}:\\
\;\;\;\;a \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;d \leq -5 \cdot 10^{-128}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 1.6 \cdot 10^{-148}:\\
\;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\

\mathbf{elif}\;d \leq 5.8 \cdot 10^{+151}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;a \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.25e52

    1. Initial program 39.4%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity39.4%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt39.4%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac39.3%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def39.3%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def62.5%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr62.5%

      \[\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)}} \]
    4. Taylor expanded in d around -inf 73.2%

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

    if -1.25e52 < d < -5.0000000000000001e-128 or 1.59999999999999997e-148 < d < 5.80000000000000036e151

    1. Initial program 86.1%

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

    if -5.0000000000000001e-128 < d < 1.59999999999999997e-148

    1. Initial program 65.6%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity65.6%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt65.6%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac65.6%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def65.7%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def78.3%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr78.3%

      \[\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)}} \]
    4. Taylor expanded in c around inf 52.7%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b + -1 \cdot \frac{a \cdot d}{c}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg52.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \color{blue}{\left(-\frac{a \cdot d}{c}\right)}\right) \]
      2. unsub-neg52.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a \cdot d}{c}\right)} \]
      3. associate-/l*52.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \color{blue}{\frac{a}{\frac{c}{d}}}\right) \]
    6. Simplified52.6%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a}{\frac{c}{d}}\right)} \]
    7. Taylor expanded in c around inf 95.5%

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(b - \frac{a}{\frac{c}{d}}\right) \]

    if 5.80000000000000036e151 < d

    1. Initial program 38.0%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity38.0%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt38.0%

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def38.0%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def49.9%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr49.9%

      \[\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)}} \]
    4. Taylor expanded in c around 0 83.5%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-1 \cdot a\right)} \]
    5. Step-by-step derivation
      1. neg-mul-183.5%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-a\right)} \]
    6. Simplified83.5%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-a\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification85.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.25 \cdot 10^{+52}:\\ \;\;\;\;a \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -5 \cdot 10^{-128}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.6 \cdot 10^{-148}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{+151}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;a \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 6: 78.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2.2 \cdot 10^{-36}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a - \frac{b}{\frac{d}{c}}\right)\\ \mathbf{elif}\;d \leq 6.2 \cdot 10^{-153}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 1.8 \cdot 10^{+152}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;a \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -2.2e-36)
   (* (/ 1.0 (hypot c d)) (- a (/ b (/ d c))))
   (if (<= d 6.2e-153)
     (* (/ 1.0 c) (- b (/ a (/ c d))))
     (if (<= d 1.8e+152)
       (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
       (* a (/ -1.0 (hypot c d)))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -2.2e-36) {
		tmp = (1.0 / hypot(c, d)) * (a - (b / (d / c)));
	} else if (d <= 6.2e-153) {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	} else if (d <= 1.8e+152) {
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	} else {
		tmp = a * (-1.0 / hypot(c, d));
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -2.2e-36) {
		tmp = (1.0 / Math.hypot(c, d)) * (a - (b / (d / c)));
	} else if (d <= 6.2e-153) {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	} else if (d <= 1.8e+152) {
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	} else {
		tmp = a * (-1.0 / Math.hypot(c, d));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -2.2e-36:
		tmp = (1.0 / math.hypot(c, d)) * (a - (b / (d / c)))
	elif d <= 6.2e-153:
		tmp = (1.0 / c) * (b - (a / (c / d)))
	elif d <= 1.8e+152:
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d))
	else:
		tmp = a * (-1.0 / math.hypot(c, d))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -2.2e-36)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a - Float64(b / Float64(d / c))));
	elseif (d <= 6.2e-153)
		tmp = Float64(Float64(1.0 / c) * Float64(b - Float64(a / Float64(c / d))));
	elseif (d <= 1.8e+152)
		tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = Float64(a * Float64(-1.0 / hypot(c, d)));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -2.2e-36)
		tmp = (1.0 / hypot(c, d)) * (a - (b / (d / c)));
	elseif (d <= 6.2e-153)
		tmp = (1.0 / c) * (b - (a / (c / d)));
	elseif (d <= 1.8e+152)
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	else
		tmp = a * (-1.0 / hypot(c, d));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.2e-36], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a - N[(b / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.2e-153], N[(N[(1.0 / c), $MachinePrecision] * N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.8e+152], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.2 \cdot 10^{-36}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a - \frac{b}{\frac{d}{c}}\right)\\

\mathbf{elif}\;d \leq 6.2 \cdot 10^{-153}:\\
\;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\

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

\mathbf{else}:\\
\;\;\;\;a \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -2.1999999999999999e-36

    1. Initial program 50.2%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity50.2%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt50.2%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac50.1%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def50.1%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def70.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr70.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)}} \]
    4. Taylor expanded in d around -inf 72.7%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(a + -1 \cdot \frac{b \cdot c}{d}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg72.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \color{blue}{\left(-\frac{b \cdot c}{d}\right)}\right) \]
      2. unsub-neg72.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(a - \frac{b \cdot c}{d}\right)} \]
      3. associate-/l*75.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a - \color{blue}{\frac{b}{\frac{d}{c}}}\right) \]
    6. Simplified75.7%

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

    if -2.1999999999999999e-36 < d < 6.1999999999999999e-153

    1. Initial program 69.4%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity69.4%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt69.4%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac69.4%

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def81.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr81.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)}} \]
    4. Taylor expanded in c around inf 51.2%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b + -1 \cdot \frac{a \cdot d}{c}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg51.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \color{blue}{\left(-\frac{a \cdot d}{c}\right)}\right) \]
      2. unsub-neg51.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a \cdot d}{c}\right)} \]
      3. associate-/l*51.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \color{blue}{\frac{a}{\frac{c}{d}}}\right) \]
    6. Simplified51.2%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a}{\frac{c}{d}}\right)} \]
    7. Taylor expanded in c around inf 92.2%

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(b - \frac{a}{\frac{c}{d}}\right) \]

    if 6.1999999999999999e-153 < d < 1.7999999999999999e152

    1. Initial program 86.2%

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

    if 1.7999999999999999e152 < d

    1. Initial program 38.0%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity38.0%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt38.0%

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def38.0%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def49.9%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr49.9%

      \[\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)}} \]
    4. Taylor expanded in c around 0 83.5%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-1 \cdot a\right)} \]
    5. Step-by-step derivation
      1. neg-mul-183.5%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-a\right)} \]
    6. Simplified83.5%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-a\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification84.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.2 \cdot 10^{-36}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a - \frac{b}{\frac{d}{c}}\right)\\ \mathbf{elif}\;d \leq 6.2 \cdot 10^{-153}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 1.8 \cdot 10^{+152}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;a \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 7: 78.5% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -1.25 \cdot 10^{+52}:\\ \;\;\;\;a \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -4.2 \cdot 10^{-128}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{-150}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{+152}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
   (if (<= d -1.25e+52)
     (* a (/ 1.0 (hypot c d)))
     (if (<= d -4.2e-128)
       t_0
       (if (<= d 6.5e-150)
         (* (/ 1.0 c) (- b (/ a (/ c d))))
         (if (<= d 2.1e+152) t_0 (/ (- a) d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -1.25e+52) {
		tmp = a * (1.0 / hypot(c, d));
	} else if (d <= -4.2e-128) {
		tmp = t_0;
	} else if (d <= 6.5e-150) {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	} else if (d <= 2.1e+152) {
		tmp = t_0;
	} else {
		tmp = -a / d;
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -1.25e+52) {
		tmp = a * (1.0 / Math.hypot(c, d));
	} else if (d <= -4.2e-128) {
		tmp = t_0;
	} else if (d <= 6.5e-150) {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	} else if (d <= 2.1e+152) {
		tmp = t_0;
	} else {
		tmp = -a / d;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -1.25e+52:
		tmp = a * (1.0 / math.hypot(c, d))
	elif d <= -4.2e-128:
		tmp = t_0
	elif d <= 6.5e-150:
		tmp = (1.0 / c) * (b - (a / (c / d)))
	elif d <= 2.1e+152:
		tmp = t_0
	else:
		tmp = -a / d
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (d <= -1.25e+52)
		tmp = Float64(a * Float64(1.0 / hypot(c, d)));
	elseif (d <= -4.2e-128)
		tmp = t_0;
	elseif (d <= 6.5e-150)
		tmp = Float64(Float64(1.0 / c) * Float64(b - Float64(a / Float64(c / d))));
	elseif (d <= 2.1e+152)
		tmp = t_0;
	else
		tmp = Float64(Float64(-a) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (d <= -1.25e+52)
		tmp = a * (1.0 / hypot(c, d));
	elseif (d <= -4.2e-128)
		tmp = t_0;
	elseif (d <= 6.5e-150)
		tmp = (1.0 / c) * (b - (a / (c / d)));
	elseif (d <= 2.1e+152)
		tmp = t_0;
	else
		tmp = -a / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.25e+52], N[(a * N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -4.2e-128], t$95$0, If[LessEqual[d, 6.5e-150], N[(N[(1.0 / c), $MachinePrecision] * N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.1e+152], t$95$0, N[((-a) / d), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.25 \cdot 10^{+52}:\\
\;\;\;\;a \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;d \leq -4.2 \cdot 10^{-128}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 6.5 \cdot 10^{-150}:\\
\;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\

\mathbf{elif}\;d \leq 2.1 \cdot 10^{+152}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.25e52

    1. Initial program 39.4%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity39.4%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt39.4%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac39.3%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def39.3%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def62.5%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr62.5%

      \[\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)}} \]
    4. Taylor expanded in d around -inf 73.2%

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

    if -1.25e52 < d < -4.2000000000000002e-128 or 6.49999999999999997e-150 < d < 2.1000000000000002e152

    1. Initial program 86.1%

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

    if -4.2000000000000002e-128 < d < 6.49999999999999997e-150

    1. Initial program 65.6%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity65.6%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt65.6%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac65.6%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def65.7%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def78.3%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr78.3%

      \[\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)}} \]
    4. Taylor expanded in c around inf 52.7%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b + -1 \cdot \frac{a \cdot d}{c}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg52.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \color{blue}{\left(-\frac{a \cdot d}{c}\right)}\right) \]
      2. unsub-neg52.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a \cdot d}{c}\right)} \]
      3. associate-/l*52.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \color{blue}{\frac{a}{\frac{c}{d}}}\right) \]
    6. Simplified52.6%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a}{\frac{c}{d}}\right)} \]
    7. Taylor expanded in c around inf 95.5%

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(b - \frac{a}{\frac{c}{d}}\right) \]

    if 2.1000000000000002e152 < d

    1. Initial program 38.0%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    3. Step-by-step derivation
      1. associate-*r/83.4%

        \[\leadsto \color{blue}{\frac{-1 \cdot a}{d}} \]
      2. neg-mul-183.4%

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    4. Simplified83.4%

      \[\leadsto \color{blue}{\frac{-a}{d}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification85.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.25 \cdot 10^{+52}:\\ \;\;\;\;a \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -4.2 \cdot 10^{-128}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{-150}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{+152}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]

Alternative 8: 78.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-a}{d}\\ t_1 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -1.2 \cdot 10^{+52}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -9.5 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 4.4 \cdot 10^{-149}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 8 \cdot 10^{+151}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- a) d)) (t_1 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
   (if (<= d -1.2e+52)
     t_0
     (if (<= d -9.5e-131)
       t_1
       (if (<= d 4.4e-149)
         (* (/ 1.0 c) (- b (/ a (/ c d))))
         (if (<= d 8e+151) t_1 t_0))))))
double code(double a, double b, double c, double d) {
	double t_0 = -a / d;
	double t_1 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -1.2e+52) {
		tmp = t_0;
	} else if (d <= -9.5e-131) {
		tmp = t_1;
	} else if (d <= 4.4e-149) {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	} else if (d <= 8e+151) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = -a / d
    t_1 = ((c * b) - (d * a)) / ((c * c) + (d * d))
    if (d <= (-1.2d+52)) then
        tmp = t_0
    else if (d <= (-9.5d-131)) then
        tmp = t_1
    else if (d <= 4.4d-149) then
        tmp = (1.0d0 / c) * (b - (a / (c / d)))
    else if (d <= 8d+151) then
        tmp = t_1
    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 = -a / d;
	double t_1 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -1.2e+52) {
		tmp = t_0;
	} else if (d <= -9.5e-131) {
		tmp = t_1;
	} else if (d <= 4.4e-149) {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	} else if (d <= 8e+151) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = -a / d
	t_1 = ((c * b) - (d * a)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -1.2e+52:
		tmp = t_0
	elif d <= -9.5e-131:
		tmp = t_1
	elif d <= 4.4e-149:
		tmp = (1.0 / c) * (b - (a / (c / d)))
	elif d <= 8e+151:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(-a) / d)
	t_1 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (d <= -1.2e+52)
		tmp = t_0;
	elseif (d <= -9.5e-131)
		tmp = t_1;
	elseif (d <= 4.4e-149)
		tmp = Float64(Float64(1.0 / c) * Float64(b - Float64(a / Float64(c / d))));
	elseif (d <= 8e+151)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = -a / d;
	t_1 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (d <= -1.2e+52)
		tmp = t_0;
	elseif (d <= -9.5e-131)
		tmp = t_1;
	elseif (d <= 4.4e-149)
		tmp = (1.0 / c) * (b - (a / (c / d)));
	elseif (d <= 8e+151)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.2e+52], t$95$0, If[LessEqual[d, -9.5e-131], t$95$1, If[LessEqual[d, 4.4e-149], N[(N[(1.0 / c), $MachinePrecision] * N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 8e+151], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
t_1 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.2 \cdot 10^{+52}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq -9.5 \cdot 10^{-131}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d \leq 4.4 \cdot 10^{-149}:\\
\;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\

\mathbf{elif}\;d \leq 8 \cdot 10^{+151}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.2e52 or 8.00000000000000014e151 < d

    1. Initial program 38.9%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    3. Step-by-step derivation
      1. associate-*r/75.9%

        \[\leadsto \color{blue}{\frac{-1 \cdot a}{d}} \]
      2. neg-mul-175.9%

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    4. Simplified75.9%

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

    if -1.2e52 < d < -9.4999999999999996e-131 or 4.3999999999999996e-149 < d < 8.00000000000000014e151

    1. Initial program 86.1%

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

    if -9.4999999999999996e-131 < d < 4.3999999999999996e-149

    1. Initial program 65.6%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity65.6%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt65.6%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac65.6%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def65.7%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def78.3%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr78.3%

      \[\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)}} \]
    4. Taylor expanded in c around inf 52.7%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b + -1 \cdot \frac{a \cdot d}{c}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg52.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \color{blue}{\left(-\frac{a \cdot d}{c}\right)}\right) \]
      2. unsub-neg52.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a \cdot d}{c}\right)} \]
      3. associate-/l*52.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \color{blue}{\frac{a}{\frac{c}{d}}}\right) \]
    6. Simplified52.6%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a}{\frac{c}{d}}\right)} \]
    7. Taylor expanded in c around inf 95.5%

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(b - \frac{a}{\frac{c}{d}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification84.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.2 \cdot 10^{+52}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -9.5 \cdot 10^{-131}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 4.4 \cdot 10^{-149}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 8 \cdot 10^{+151}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]

Alternative 9: 71.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-a}{d}\\ \mathbf{if}\;d \leq -2.4 \cdot 10^{-36}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{-19}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 1.65 \cdot 10^{+121}:\\ \;\;\;\;\frac{d \cdot \left(-a\right)}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- a) d)))
   (if (<= d -2.4e-36)
     t_0
     (if (<= d 7.5e-19)
       (* (/ 1.0 c) (- b (/ a (/ c d))))
       (if (<= d 1.65e+121) (/ (* d (- a)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = -a / d;
	double tmp;
	if (d <= -2.4e-36) {
		tmp = t_0;
	} else if (d <= 7.5e-19) {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	} else if (d <= 1.65e+121) {
		tmp = (d * -a) / ((c * c) + (d * d));
	} 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 = -a / d
    if (d <= (-2.4d-36)) then
        tmp = t_0
    else if (d <= 7.5d-19) then
        tmp = (1.0d0 / c) * (b - (a / (c / d)))
    else if (d <= 1.65d+121) then
        tmp = (d * -a) / ((c * c) + (d * d))
    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 = -a / d;
	double tmp;
	if (d <= -2.4e-36) {
		tmp = t_0;
	} else if (d <= 7.5e-19) {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	} else if (d <= 1.65e+121) {
		tmp = (d * -a) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = -a / d
	tmp = 0
	if d <= -2.4e-36:
		tmp = t_0
	elif d <= 7.5e-19:
		tmp = (1.0 / c) * (b - (a / (c / d)))
	elif d <= 1.65e+121:
		tmp = (d * -a) / ((c * c) + (d * d))
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(-a) / d)
	tmp = 0.0
	if (d <= -2.4e-36)
		tmp = t_0;
	elseif (d <= 7.5e-19)
		tmp = Float64(Float64(1.0 / c) * Float64(b - Float64(a / Float64(c / d))));
	elseif (d <= 1.65e+121)
		tmp = Float64(Float64(d * Float64(-a)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = -a / d;
	tmp = 0.0;
	if (d <= -2.4e-36)
		tmp = t_0;
	elseif (d <= 7.5e-19)
		tmp = (1.0 / c) * (b - (a / (c / d)));
	elseif (d <= 1.65e+121)
		tmp = (d * -a) / ((c * c) + (d * d));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -2.4e-36], t$95$0, If[LessEqual[d, 7.5e-19], N[(N[(1.0 / c), $MachinePrecision] * N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.65e+121], N[(N[(d * (-a)), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -2.4 \cdot 10^{-36}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 7.5 \cdot 10^{-19}:\\
\;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\

\mathbf{elif}\;d \leq 1.65 \cdot 10^{+121}:\\
\;\;\;\;\frac{d \cdot \left(-a\right)}{c \cdot c + d \cdot d}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.4e-36 or 1.6499999999999999e121 < d

    1. Initial program 48.2%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    3. Step-by-step derivation
      1. associate-*r/73.4%

        \[\leadsto \color{blue}{\frac{-1 \cdot a}{d}} \]
      2. neg-mul-173.4%

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    4. Simplified73.4%

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

    if -2.4e-36 < d < 7.49999999999999957e-19

    1. Initial program 74.4%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity74.4%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt74.4%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac74.5%

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def84.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr84.7%

      \[\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)}} \]
    4. Taylor expanded in c around inf 52.6%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b + -1 \cdot \frac{a \cdot d}{c}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg52.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \color{blue}{\left(-\frac{a \cdot d}{c}\right)}\right) \]
      2. unsub-neg52.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a \cdot d}{c}\right)} \]
      3. associate-/l*52.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \color{blue}{\frac{a}{\frac{c}{d}}}\right) \]
    6. Simplified52.6%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a}{\frac{c}{d}}\right)} \]
    7. Taylor expanded in c around inf 87.9%

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(b - \frac{a}{\frac{c}{d}}\right) \]

    if 7.49999999999999957e-19 < d < 1.6499999999999999e121

    1. Initial program 81.8%

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

      \[\leadsto \frac{\color{blue}{-1 \cdot \left(a \cdot d\right)}}{c \cdot c + d \cdot d} \]
    3. Step-by-step derivation
      1. associate-*r*70.7%

        \[\leadsto \frac{\color{blue}{\left(-1 \cdot a\right) \cdot d}}{c \cdot c + d \cdot d} \]
      2. neg-mul-170.7%

        \[\leadsto \frac{\color{blue}{\left(-a\right)} \cdot d}{c \cdot c + d \cdot d} \]
      3. *-commutative70.7%

        \[\leadsto \frac{\color{blue}{d \cdot \left(-a\right)}}{c \cdot c + d \cdot d} \]
    4. Simplified70.7%

      \[\leadsto \frac{\color{blue}{d \cdot \left(-a\right)}}{c \cdot c + d \cdot d} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification79.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.4 \cdot 10^{-36}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{-19}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 1.65 \cdot 10^{+121}:\\ \;\;\;\;\frac{d \cdot \left(-a\right)}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]

Alternative 10: 71.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.1 \cdot 10^{-36} \lor \neg \left(d \leq 1.45 \cdot 10^{-16}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -1.1e-36) (not (<= d 1.45e-16)))
   (/ (- a) d)
   (* (/ 1.0 c) (- b (/ a (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -1.1e-36) || !(d <= 1.45e-16)) {
		tmp = -a / d;
	} else {
		tmp = (1.0 / c) * (b - (a / (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 ((d <= (-1.1d-36)) .or. (.not. (d <= 1.45d-16))) then
        tmp = -a / d
    else
        tmp = (1.0d0 / c) * (b - (a / (c / d)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -1.1e-36) || !(d <= 1.45e-16)) {
		tmp = -a / d;
	} else {
		tmp = (1.0 / c) * (b - (a / (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -1.1e-36) or not (d <= 1.45e-16):
		tmp = -a / d
	else:
		tmp = (1.0 / c) * (b - (a / (c / d)))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -1.1e-36) || !(d <= 1.45e-16))
		tmp = Float64(Float64(-a) / d);
	else
		tmp = Float64(Float64(1.0 / c) * Float64(b - Float64(a / Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((d <= -1.1e-36) || ~((d <= 1.45e-16)))
		tmp = -a / d;
	else
		tmp = (1.0 / c) * (b - (a / (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.1e-36], N[Not[LessEqual[d, 1.45e-16]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(1.0 / c), $MachinePrecision] * N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.1 \cdot 10^{-36} \lor \neg \left(d \leq 1.45 \cdot 10^{-16}\right):\\
\;\;\;\;\frac{-a}{d}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.1e-36 or 1.4499999999999999e-16 < d

    1. Initial program 54.5%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    3. Step-by-step derivation
      1. associate-*r/69.8%

        \[\leadsto \color{blue}{\frac{-1 \cdot a}{d}} \]
      2. neg-mul-169.8%

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    4. Simplified69.8%

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

    if -1.1e-36 < d < 1.4499999999999999e-16

    1. Initial program 74.4%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity74.4%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt74.4%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac74.5%

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def84.7%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr84.7%

      \[\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)}} \]
    4. Taylor expanded in c around inf 52.6%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b + -1 \cdot \frac{a \cdot d}{c}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg52.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \color{blue}{\left(-\frac{a \cdot d}{c}\right)}\right) \]
      2. unsub-neg52.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a \cdot d}{c}\right)} \]
      3. associate-/l*52.6%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \color{blue}{\frac{a}{\frac{c}{d}}}\right) \]
    6. Simplified52.6%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a}{\frac{c}{d}}\right)} \]
    7. Taylor expanded in c around inf 87.9%

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(b - \frac{a}{\frac{c}{d}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.1 \cdot 10^{-36} \lor \neg \left(d \leq 1.45 \cdot 10^{-16}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(b - \frac{a}{\frac{c}{d}}\right)\\ \end{array} \]

Alternative 11: 63.6% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -9.5 \cdot 10^{-39} \lor \neg \left(d \leq 3.35 \cdot 10^{-18}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -9.5e-39) (not (<= d 3.35e-18))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -9.5e-39) || !(d <= 3.35e-18)) {
		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 <= (-9.5d-39)) .or. (.not. (d <= 3.35d-18))) 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 <= -9.5e-39) || !(d <= 3.35e-18)) {
		tmp = -a / d;
	} else {
		tmp = b / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -9.5e-39) or not (d <= 3.35e-18):
		tmp = -a / d
	else:
		tmp = b / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -9.5e-39) || !(d <= 3.35e-18))
		tmp = Float64(Float64(-a) / d);
	else
		tmp = Float64(b / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((d <= -9.5e-39) || ~((d <= 3.35e-18)))
		tmp = -a / d;
	else
		tmp = b / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9.5e-39], N[Not[LessEqual[d, 3.35e-18]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.5 \cdot 10^{-39} \lor \neg \left(d \leq 3.35 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{-a}{d}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -9.4999999999999999e-39 or 3.3499999999999999e-18 < d

    1. Initial program 54.5%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    3. Step-by-step derivation
      1. associate-*r/69.8%

        \[\leadsto \color{blue}{\frac{-1 \cdot a}{d}} \]
      2. neg-mul-169.8%

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    4. Simplified69.8%

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

    if -9.4999999999999999e-39 < d < 3.3499999999999999e-18

    1. Initial program 74.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9.5 \cdot 10^{-39} \lor \neg \left(d \leq 3.35 \cdot 10^{-18}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]

Alternative 12: 43.9% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq 6.6 \cdot 10^{+136}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d) :precision binary64 (if (<= d 6.6e+136) (/ b c) (/ b d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= 6.6e+136) {
		tmp = b / c;
	} else {
		tmp = b / 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 (d <= 6.6d+136) then
        tmp = b / c
    else
        tmp = b / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= 6.6e+136) {
		tmp = b / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= 6.6e+136:
		tmp = b / c
	else:
		tmp = b / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= 6.6e+136)
		tmp = Float64(b / c);
	else
		tmp = Float64(b / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= 6.6e+136)
		tmp = b / c;
	else
		tmp = b / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, 6.6e+136], N[(b / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq 6.6 \cdot 10^{+136}:\\
\;\;\;\;\frac{b}{c}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 6.59999999999999984e136

    1. Initial program 67.1%

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

      \[\leadsto \color{blue}{\frac{b}{c}} \]

    if 6.59999999999999984e136 < d

    1. Initial program 40.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity40.3%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt40.3%

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac40.3%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def40.3%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-def51.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Applied egg-rr51.2%

      \[\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)}} \]
    4. Taylor expanded in c around -inf 27.2%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-1 \cdot b\right)} \]
    5. Step-by-step derivation
      1. neg-mul-127.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-b\right)} \]
    6. Simplified27.2%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-b\right)} \]
    7. Taylor expanded in d around -inf 25.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 6.6 \cdot 10^{+136}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]

Alternative 13: 10.0% accurate, 5.0× speedup?

\[\begin{array}{l} \\ \frac{a}{c} \end{array} \]
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
	return a / 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 = a / c
end function
public static double code(double a, double b, double c, double d) {
	return a / c;
}
def code(a, b, c, d):
	return a / c
function code(a, b, c, d)
	return Float64(a / c)
end
function tmp = code(a, b, c, d)
	tmp = a / c;
end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}

\\
\frac{a}{c}
\end{array}
Derivation
  1. Initial program 63.1%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Step-by-step derivation
    1. *-un-lft-identity63.1%

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
    2. add-sqr-sqrt63.1%

      \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
    3. times-frac63.1%

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
    4. hypot-def63.1%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
    5. hypot-def76.1%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
  3. Applied egg-rr76.1%

    \[\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)}} \]
  4. Taylor expanded in c around inf 32.6%

    \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b + -1 \cdot \frac{a \cdot d}{c}\right)} \]
  5. Step-by-step derivation
    1. mul-1-neg32.6%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + \color{blue}{\left(-\frac{a \cdot d}{c}\right)}\right) \]
    2. unsub-neg32.6%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a \cdot d}{c}\right)} \]
    3. associate-/l*34.2%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b - \color{blue}{\frac{a}{\frac{c}{d}}}\right) \]
  6. Simplified34.2%

    \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(b - \frac{a}{\frac{c}{d}}\right)} \]
  7. Taylor expanded in d around -inf 9.9%

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  8. Final simplification9.9%

    \[\leadsto \frac{a}{c} \]

Alternative 14: 43.4% accurate, 5.0× 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 63.1%

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

    \[\leadsto \color{blue}{\frac{b}{c}} \]
  3. Final simplification41.6%

    \[\leadsto \frac{b}{c} \]

Developer target: 99.3% accurate, 0.1× 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 2023300 
(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))))