Complex division, real part

Percentage Accurate: 60.9% → 89.5%
Time: 10.6s
Alternatives: 8
Speedup: 1.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 8 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: 60.9% 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: 89.5% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 2 \cdot 10^{+307}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\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)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 2e+307)))
     (* (/ (fma b (/ d a) c) (hypot c d)) (/ a (hypot c d)))
     (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 2e+307)) {
		tmp = (fma(b, (d / a), c) / hypot(c, d)) * (a / hypot(c, d));
	} else {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 2e+307))
		tmp = Float64(Float64(fma(b, Float64(d / a), c) / hypot(c, d)) * Float64(a / hypot(c, d)));
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 2e+307]], $MachinePrecision]], N[(N[(N[(b * N[(d / a), $MachinePrecision] + c), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 2 \cdot 10^{+307}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{else}:\\
\;\;\;\;\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)}\\


\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))) < -inf.0 or 1.99999999999999997e307 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 20.5%

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

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

        \[\leadsto \frac{a \cdot \left(c + \color{blue}{b \cdot \frac{d}{a}}\right)}{c \cdot c + d \cdot d} \]
    5. Simplified20.6%

      \[\leadsto \frac{\color{blue}{a \cdot \left(c + b \cdot \frac{d}{a}\right)}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. *-commutative20.6%

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

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

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

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

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

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

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

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

    if -inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.99999999999999997e307

    1. Initial program 83.2%

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}} \]
      2. associate-*r/83.2%

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

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

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

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

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

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

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

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

        \[\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)}} \]
    4. Applied egg-rr98.9%

      \[\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)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq -\infty \lor \neg \left(\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+307}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\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)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 86.4% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+307}:\\ \;\;\;\;\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 + c \cdot \frac{a}{d}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= t_0 (- INFINITY))
     (/ (+ b (* a (/ c d))) d)
     (if (<= t_0 2e+307)
       (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
       (/ (+ b (* c (/ a d))) d)))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = (b + (a * (c / d))) / d;
	} else if (t_0 <= 2e+307) {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else {
		tmp = (b + (c * (a / d))) / d;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (t_0 <= 2e+307)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	else
		tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[t$95$0, 2e+307], 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 + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+307}:\\
\;\;\;\;\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 + c \cdot \frac{a}{d}}{d}\\


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

    1. Initial program 44.2%

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

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

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

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

    if -inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.99999999999999997e307

    1. Initial program 83.2%

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}} \]
      2. associate-*r/83.2%

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

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

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

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

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

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

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

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

        \[\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)}} \]
    4. Applied egg-rr98.9%

      \[\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.99999999999999997e307 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 15.2%

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

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

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

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

        \[\leadsto \frac{b + a \cdot \color{blue}{\frac{1}{\frac{d}{c}}}}{d} \]
      2. un-div-inv67.3%

        \[\leadsto \frac{b + \color{blue}{\frac{a}{\frac{d}{c}}}}{d} \]
    7. Applied egg-rr67.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq -\infty:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+307}:\\ \;\;\;\;\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 + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 81.0% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;c \leq -3 \cdot 10^{-83}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 2.8 \cdot 10^{+46}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -1.4999999999999999e-7

    1. Initial program 40.6%

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

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

        \[\leadsto \frac{a \cdot \left(c + \color{blue}{b \cdot \frac{d}{a}}\right)}{c \cdot c + d \cdot d} \]
    5. Simplified34.1%

      \[\leadsto \frac{\color{blue}{a \cdot \left(c + b \cdot \frac{d}{a}\right)}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. *-commutative34.1%

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

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

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

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

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

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

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

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

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

    if -1.4999999999999999e-7 < c < -3.0000000000000001e-83 or 1.6499999999999999e-145 < c < 2.80000000000000018e46

    1. Initial program 87.3%

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

    if -3.0000000000000001e-83 < c < 1.6499999999999999e-145

    1. Initial program 65.1%

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

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

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

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

        \[\leadsto \frac{b + a \cdot \color{blue}{\frac{1}{\frac{d}{c}}}}{d} \]
      2. un-div-inv93.1%

        \[\leadsto \frac{b + \color{blue}{\frac{a}{\frac{d}{c}}}}{d} \]
    7. Applied egg-rr93.1%

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

    if 2.80000000000000018e46 < c

    1. Initial program 41.1%

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}} \]
      2. associate-*r/41.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      10. hypot-define61.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)}} \]
    4. Applied egg-rr61.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)}} \]
    5. Taylor expanded in c around inf 78.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.5 \cdot 10^{-7}:\\ \;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -3 \cdot 10^{-83}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.65 \cdot 10^{-145}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \mathbf{elif}\;c \leq 2.8 \cdot 10^{+46}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + b \cdot \frac{d}{c}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 80.7% accurate, 0.6× speedup?

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

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

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

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

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


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

    1. Initial program 37.0%

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

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

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

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

    if -9.40000000000000058e64 < d < -1.75e-105

    1. Initial program 90.7%

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

    if -1.75e-105 < d < 2.25e83

    1. Initial program 68.4%

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

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

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

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

    if 2.25e83 < d

    1. Initial program 47.5%

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

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

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

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

        \[\leadsto \frac{b + a \cdot \color{blue}{\frac{1}{\frac{d}{c}}}}{d} \]
      2. un-div-inv84.3%

        \[\leadsto \frac{b + \color{blue}{\frac{a}{\frac{d}{c}}}}{d} \]
    7. Applied egg-rr84.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9.4 \cdot 10^{+64}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq -1.75 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.25 \cdot 10^{+83}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 78.3% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.7 \cdot 10^{+37} \lor \neg \left(c \leq 0.053\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.69999999999999986e37 or 0.0529999999999999985 < c

    1. Initial program 43.8%

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

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

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

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

    if -2.69999999999999986e37 < c < 0.0529999999999999985

    1. Initial program 72.7%

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

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

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

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

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

Alternative 6: 73.5% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.45 \cdot 10^{+76} \lor \neg \left(d \leq 1.15 \cdot 10^{+84}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.4500000000000001e76 or 1.1499999999999999e84 < d

    1. Initial program 41.4%

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

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

    if -1.4500000000000001e76 < d < 1.1499999999999999e84

    1. Initial program 72.6%

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

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

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

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

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

Alternative 7: 64.2% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.2 \cdot 10^{-63} \lor \neg \left(d \leq 1.6 \cdot 10^{+86}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -9.2e-63 or 1.6e86 < d

    1. Initial program 51.4%

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

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

    if -9.2e-63 < d < 1.6e86

    1. Initial program 69.8%

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

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

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

Alternative 8: 42.5% 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 60.4%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Add Preprocessing

Developer Target 1: 99.3% 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 2024123 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :alt
  (! :herbie-platform default (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))))