Complex division, real part

Percentage Accurate: 61.6% → 84.1%
Time: 7.0s
Alternatives: 10
Speedup: 2.1×

Specification

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

\\
\frac{a \cdot c + b \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 10 alternatives:

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

Initial Program: 61.6% accurate, 1.0× speedup?

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

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

Alternative 1: 84.1% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 10^{+231}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 1e+231)
   (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
   (+ (/ b d) (* (/ c d) (/ a d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 1e+231) {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else {
		tmp = (b / d) + ((c / d) * (a / d));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 1e+231)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	else
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+231], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 82.7%

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

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

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

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

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

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

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

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

    if 1.0000000000000001e231 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 16.4%

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

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}} \]
    3. Step-by-step derivation
      1. unpow248.1%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac59.9%

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
    4. Simplified59.9%

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

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

Alternative 2: 77.3% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{+42}:\\
\;\;\;\;\frac{a \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -9.00000000000000025e42

    1. Initial program 44.5%

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

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

        \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2} + {c}^{2}}{a}}} \]
      2. associate-/r/50.0%

        \[\leadsto \color{blue}{\frac{c}{{d}^{2} + {c}^{2}} \cdot a} \]
      3. unpow250.0%

        \[\leadsto \frac{c}{\color{blue}{d \cdot d} + {c}^{2}} \cdot a \]
      4. unpow250.0%

        \[\leadsto \frac{c}{d \cdot d + \color{blue}{c \cdot c}} \cdot a \]
      5. +-commutative50.0%

        \[\leadsto \frac{c}{\color{blue}{c \cdot c + d \cdot d}} \cdot a \]
      6. fma-def50.0%

        \[\leadsto \frac{c}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \cdot a \]
    4. Simplified50.0%

      \[\leadsto \color{blue}{\frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot a} \]
    5. Step-by-step derivation
      1. *-un-lft-identity50.0%

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

        \[\leadsto \frac{1 \cdot c}{\color{blue}{c \cdot c + d \cdot d}} \cdot a \]
      3. add-sqr-sqrt50.0%

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\right)} \cdot a \]
    7. Step-by-step derivation
      1. associate-*l*93.0%

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

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

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

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

    if -9.00000000000000025e42 < c < 1.85000000000000007e-33

    1. Initial program 76.6%

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

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}} \]
    3. Step-by-step derivation
      1. unpow283.1%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac83.2%

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
    4. Simplified83.2%

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}} \]
    5. Step-by-step derivation
      1. associate-*r/85.4%

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{\frac{c}{d} \cdot a}{d}} \]
    6. Applied egg-rr85.4%

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

    if 1.85000000000000007e-33 < c

    1. Initial program 56.7%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 77.8% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1 \cdot 10^{+43}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.00000000000000001e43

    1. Initial program 44.5%

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

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

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac86.5%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{d}{c} \cdot \frac{b}{c}} \]
    4. Simplified86.5%

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

    if -1.00000000000000001e43 < c < 2.3500000000000001e-33

    1. Initial program 76.6%

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

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}} \]
    3. Step-by-step derivation
      1. unpow283.1%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac83.2%

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
    4. Simplified83.2%

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}} \]
    5. Step-by-step derivation
      1. associate-*r/85.4%

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{\frac{c}{d} \cdot a}{d}} \]
    6. Applied egg-rr85.4%

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

    if 2.3500000000000001e-33 < c

    1. Initial program 56.7%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 76.3% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.5 \cdot 10^{+43} \lor \neg \left(c \leq 1.7 \cdot 10^{-33}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.5000000000000002e43 or 1.7e-33 < c

    1. Initial program 52.7%

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

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

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac83.2%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{d}{c} \cdot \frac{b}{c}} \]
    4. Simplified83.2%

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

    if -2.5000000000000002e43 < c < 1.7e-33

    1. Initial program 76.6%

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

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}} \]
    3. Step-by-step derivation
      1. unpow283.1%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac83.2%

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
    4. Simplified83.2%

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

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

Alternative 5: 77.4% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{+42} \lor \neg \left(c \leq 1.9 \cdot 10^{-33}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -9.00000000000000025e42 or 1.89999999999999997e-33 < c

    1. Initial program 52.7%

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

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

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac83.2%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{d}{c} \cdot \frac{b}{c}} \]
    4. Simplified83.2%

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

    if -9.00000000000000025e42 < c < 1.89999999999999997e-33

    1. Initial program 76.6%

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

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}} \]
    3. Step-by-step derivation
      1. unpow283.1%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac83.2%

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
    4. Simplified83.2%

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}} \]
    5. Step-by-step derivation
      1. associate-*r/85.4%

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{\frac{c}{d} \cdot a}{d}} \]
    6. Applied egg-rr85.4%

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

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

Alternative 6: 70.5% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.7 \cdot 10^{+91}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;d \leq 8.2 \cdot 10^{+22}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.7e91 or 8.19999999999999958e22 < d

    1. Initial program 48.8%

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

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

    if -1.7e91 < d < 8.19999999999999958e22

    1. Initial program 75.5%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Step-by-step derivation
      1. unpow274.2%

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac77.6%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{d}{c} \cdot \frac{b}{c}} \]
    4. Simplified77.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.7 \cdot 10^{+91}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 8.2 \cdot 10^{+22}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]

Alternative 7: 62.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.9 \cdot 10^{+43}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 1.05 \cdot 10^{-136}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 8 \cdot 10^{-76}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq 2.05 \cdot 10^{-33}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -1.9e+43)
   (/ a c)
   (if (<= c 1.05e-136)
     (/ b d)
     (if (<= c 8e-76)
       (* (/ c d) (/ a d))
       (if (<= c 2.05e-33) (/ b d) (/ a c))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -1.9e+43) {
		tmp = a / c;
	} else if (c <= 1.05e-136) {
		tmp = b / d;
	} else if (c <= 8e-76) {
		tmp = (c / d) * (a / d);
	} else if (c <= 2.05e-33) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (c <= (-1.9d+43)) then
        tmp = a / c
    else if (c <= 1.05d-136) then
        tmp = b / d
    else if (c <= 8d-76) then
        tmp = (c / d) * (a / d)
    else if (c <= 2.05d-33) then
        tmp = b / d
    else
        tmp = a / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -1.9e+43) {
		tmp = a / c;
	} else if (c <= 1.05e-136) {
		tmp = b / d;
	} else if (c <= 8e-76) {
		tmp = (c / d) * (a / d);
	} else if (c <= 2.05e-33) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -1.9e+43:
		tmp = a / c
	elif c <= 1.05e-136:
		tmp = b / d
	elif c <= 8e-76:
		tmp = (c / d) * (a / d)
	elif c <= 2.05e-33:
		tmp = b / d
	else:
		tmp = a / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -1.9e+43)
		tmp = Float64(a / c);
	elseif (c <= 1.05e-136)
		tmp = Float64(b / d);
	elseif (c <= 8e-76)
		tmp = Float64(Float64(c / d) * Float64(a / d));
	elseif (c <= 2.05e-33)
		tmp = Float64(b / d);
	else
		tmp = Float64(a / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -1.9e+43)
		tmp = a / c;
	elseif (c <= 1.05e-136)
		tmp = b / d;
	elseif (c <= 8e-76)
		tmp = (c / d) * (a / d);
	elseif (c <= 2.05e-33)
		tmp = b / d;
	else
		tmp = a / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.9e+43], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.05e-136], N[(b / d), $MachinePrecision], If[LessEqual[c, 8e-76], N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.05e-33], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.9 \cdot 10^{+43}:\\
\;\;\;\;\frac{a}{c}\\

\mathbf{elif}\;c \leq 1.05 \cdot 10^{-136}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;c \leq 8 \cdot 10^{-76}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{a}{d}\\

\mathbf{elif}\;c \leq 2.05 \cdot 10^{-33}:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.90000000000000004e43 or 2.05e-33 < c

    1. Initial program 52.7%

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

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

    if -1.90000000000000004e43 < c < 1.0499999999999999e-136 or 7.99999999999999942e-76 < c < 2.05e-33

    1. Initial program 75.2%

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

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

    if 1.0499999999999999e-136 < c < 7.99999999999999942e-76

    1. Initial program 90.8%

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

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

        \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2} + {c}^{2}}{a}}} \]
      2. associate-/r/82.3%

        \[\leadsto \color{blue}{\frac{c}{{d}^{2} + {c}^{2}} \cdot a} \]
      3. unpow282.3%

        \[\leadsto \frac{c}{\color{blue}{d \cdot d} + {c}^{2}} \cdot a \]
      4. unpow282.3%

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

        \[\leadsto \frac{c}{\color{blue}{c \cdot c + d \cdot d}} \cdot a \]
      6. fma-def82.3%

        \[\leadsto \frac{c}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \cdot a \]
    4. Simplified82.3%

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

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

        \[\leadsto \frac{1 \cdot c}{\color{blue}{c \cdot c + d \cdot d}} \cdot a \]
      3. add-sqr-sqrt82.3%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{c \cdot a}{{d}^{2}}} \]
    8. Step-by-step derivation
      1. unpow282.3%

        \[\leadsto \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac89.4%

        \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
    9. Simplified89.4%

      \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification71.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.9 \cdot 10^{+43}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 1.05 \cdot 10^{-136}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 8 \cdot 10^{-76}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq 2.05 \cdot 10^{-33}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 8: 62.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -9 \cdot 10^{+42}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{-136}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 9.2 \cdot 10^{-76}:\\ \;\;\;\;c \cdot \frac{\frac{a}{d}}{d}\\ \mathbf{elif}\;c \leq 1.6 \cdot 10^{-33}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -9e+42)
   (/ a c)
   (if (<= c 1.2e-136)
     (/ b d)
     (if (<= c 9.2e-76)
       (* c (/ (/ a d) d))
       (if (<= c 1.6e-33) (/ b d) (/ a c))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -9e+42) {
		tmp = a / c;
	} else if (c <= 1.2e-136) {
		tmp = b / d;
	} else if (c <= 9.2e-76) {
		tmp = c * ((a / d) / d);
	} else if (c <= 1.6e-33) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (c <= (-9d+42)) then
        tmp = a / c
    else if (c <= 1.2d-136) then
        tmp = b / d
    else if (c <= 9.2d-76) then
        tmp = c * ((a / d) / d)
    else if (c <= 1.6d-33) then
        tmp = b / d
    else
        tmp = a / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -9e+42) {
		tmp = a / c;
	} else if (c <= 1.2e-136) {
		tmp = b / d;
	} else if (c <= 9.2e-76) {
		tmp = c * ((a / d) / d);
	} else if (c <= 1.6e-33) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -9e+42:
		tmp = a / c
	elif c <= 1.2e-136:
		tmp = b / d
	elif c <= 9.2e-76:
		tmp = c * ((a / d) / d)
	elif c <= 1.6e-33:
		tmp = b / d
	else:
		tmp = a / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -9e+42)
		tmp = Float64(a / c);
	elseif (c <= 1.2e-136)
		tmp = Float64(b / d);
	elseif (c <= 9.2e-76)
		tmp = Float64(c * Float64(Float64(a / d) / d));
	elseif (c <= 1.6e-33)
		tmp = Float64(b / d);
	else
		tmp = Float64(a / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -9e+42)
		tmp = a / c;
	elseif (c <= 1.2e-136)
		tmp = b / d;
	elseif (c <= 9.2e-76)
		tmp = c * ((a / d) / d);
	elseif (c <= 1.6e-33)
		tmp = b / d;
	else
		tmp = a / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -9e+42], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.2e-136], N[(b / d), $MachinePrecision], If[LessEqual[c, 9.2e-76], N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.6e-33], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{+42}:\\
\;\;\;\;\frac{a}{c}\\

\mathbf{elif}\;c \leq 1.2 \cdot 10^{-136}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;c \leq 9.2 \cdot 10^{-76}:\\
\;\;\;\;c \cdot \frac{\frac{a}{d}}{d}\\

\mathbf{elif}\;c \leq 1.6 \cdot 10^{-33}:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -9.00000000000000025e42 or 1.59999999999999988e-33 < c

    1. Initial program 52.7%

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

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

    if -9.00000000000000025e42 < c < 1.1999999999999999e-136 or 9.20000000000000025e-76 < c < 1.59999999999999988e-33

    1. Initial program 75.2%

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

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

    if 1.1999999999999999e-136 < c < 9.20000000000000025e-76

    1. Initial program 90.8%

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

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

        \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2} + {c}^{2}}{a}}} \]
      2. associate-/r/82.3%

        \[\leadsto \color{blue}{\frac{c}{{d}^{2} + {c}^{2}} \cdot a} \]
      3. unpow282.3%

        \[\leadsto \frac{c}{\color{blue}{d \cdot d} + {c}^{2}} \cdot a \]
      4. unpow282.3%

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

        \[\leadsto \frac{c}{\color{blue}{c \cdot c + d \cdot d}} \cdot a \]
      6. fma-def82.3%

        \[\leadsto \frac{c}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \cdot a \]
    4. Simplified82.3%

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

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

        \[\leadsto \frac{1 \cdot c}{\color{blue}{c \cdot c + d \cdot d}} \cdot a \]
      3. add-sqr-sqrt82.3%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{c \cdot a}{{d}^{2}}} \]
    8. Step-by-step derivation
      1. unpow282.3%

        \[\leadsto \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac89.4%

        \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
    9. Simplified89.4%

      \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
    10. Taylor expanded in c around 0 82.3%

      \[\leadsto \color{blue}{\frac{c \cdot a}{{d}^{2}}} \]
    11. Step-by-step derivation
      1. *-commutative82.3%

        \[\leadsto \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      2. unpow282.3%

        \[\leadsto \frac{a \cdot c}{\color{blue}{d \cdot d}} \]
      3. times-frac89.4%

        \[\leadsto \color{blue}{\frac{a}{d} \cdot \frac{c}{d}} \]
      4. associate-*r/91.1%

        \[\leadsto \color{blue}{\frac{\frac{a}{d} \cdot c}{d}} \]
      5. associate-*l/91.0%

        \[\leadsto \color{blue}{\frac{\frac{a}{d}}{d} \cdot c} \]
    12. Simplified91.0%

      \[\leadsto \color{blue}{\frac{\frac{a}{d}}{d} \cdot c} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification71.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -9 \cdot 10^{+42}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{-136}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 9.2 \cdot 10^{-76}:\\ \;\;\;\;c \cdot \frac{\frac{a}{d}}{d}\\ \mathbf{elif}\;c \leq 1.6 \cdot 10^{-33}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 9: 63.6% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -9 \cdot 10^{+42}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 1.8 \cdot 10^{-33}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -9e+42) (/ a c) (if (<= c 1.8e-33) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -9e+42) {
		tmp = a / c;
	} else if (c <= 1.8e-33) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (c <= (-9d+42)) then
        tmp = a / c
    else if (c <= 1.8d-33) then
        tmp = b / d
    else
        tmp = a / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -9e+42) {
		tmp = a / c;
	} else if (c <= 1.8e-33) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -9e+42:
		tmp = a / c
	elif c <= 1.8e-33:
		tmp = b / d
	else:
		tmp = a / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -9e+42)
		tmp = Float64(a / c);
	elseif (c <= 1.8e-33)
		tmp = Float64(b / d);
	else
		tmp = Float64(a / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -9e+42)
		tmp = a / c;
	elseif (c <= 1.8e-33)
		tmp = b / d;
	else
		tmp = a / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -9e+42], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.8e-33], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{+42}:\\
\;\;\;\;\frac{a}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -9.00000000000000025e42 or 1.80000000000000017e-33 < c

    1. Initial program 52.7%

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

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

    if -9.00000000000000025e42 < c < 1.80000000000000017e-33

    1. Initial program 76.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -9 \cdot 10^{+42}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 1.8 \cdot 10^{-33}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 10: 42.1% 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 64.6%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification46.5%

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

Developer target: 99.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \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))
   (/ (+ a (* b (/ d c))) (+ c (* d (/ d c))))
   (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (fabs(d) < fabs(c)) {
		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)))
    else
        tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if math.fabs(d) < math.fabs(c):
		tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
	else:
		tmp = (b + (a * (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(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
	else
		tmp = Float64(Float64(b + Float64(a * 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 = (a + (b * (d / c))) / (c + (d * (d / c)));
	else
		tmp = (b + (a * (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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * 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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2023224 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))

  (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))