Complex division, imag part

Percentage Accurate: 60.9% → 80.2%
Time: 3.3s
Alternatives: 11
Speedup: 1.5×

Specification

?
\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 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{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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

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

Alternative 1: 80.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{if}\;c \leq -8.8 \cdot 10^{-13}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{-110}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\ \mathbf{elif}\;c \leq 31000000000:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- b (* d (/ a c))) c)))
   (if (<= c -8.8e-13)
     t_0
     (if (<= c 1.5e-110)
       (/ (fma b (/ c d) (- a)) d)
       (if (<= c 31000000000.0)
         (/ (- (* b c) (* a d)) (fma c c (* d d)))
         t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (b - (d * (a / c))) / c;
	double tmp;
	if (c <= -8.8e-13) {
		tmp = t_0;
	} else if (c <= 1.5e-110) {
		tmp = fma(b, (c / d), -a) / d;
	} else if (c <= 31000000000.0) {
		tmp = ((b * c) - (a * d)) / fma(c, c, (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(b - Float64(d * Float64(a / c))) / c)
	tmp = 0.0
	if (c <= -8.8e-13)
		tmp = t_0;
	elseif (c <= 1.5e-110)
		tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d);
	elseif (c <= 31000000000.0)
		tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / fma(c, c, Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -8.8e-13], t$95$0, If[LessEqual[c, 1.5e-110], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 31000000000.0], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq 1.5 \cdot 10^{-110}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\

\mathbf{elif}\;c \leq 31000000000:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -8.79999999999999986e-13 or 3.1e10 < c

    1. Initial program 48.4%

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

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

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

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

        \[\leadsto \frac{b - 1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. metadata-evalN/A

        \[\leadsto \frac{b - \frac{-1}{-1} \cdot \frac{a \cdot d}{c}}{c} \]
      5. times-fracN/A

        \[\leadsto \frac{b - \frac{-1 \cdot \left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      6. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      7. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{\mathsf{neg}\left(c\right)}}{c} \]
      8. frac-2negN/A

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

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

        \[\leadsto \frac{b - \frac{a \cdot d}{c}}{c} \]
      11. *-commutativeN/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      12. lower-*.f6476.5

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
    5. Applied rewrites76.5%

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

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      3. associate-/l*N/A

        \[\leadsto \frac{b - d \cdot \frac{a}{c}}{c} \]
      4. lower-*.f64N/A

        \[\leadsto \frac{b - d \cdot \frac{a}{c}}{c} \]
      5. lower-/.f6483.2

        \[\leadsto \frac{b - d \cdot \frac{a}{c}}{c} \]
    7. Applied rewrites83.2%

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

    if -8.79999999999999986e-13 < c < 1.49999999999999993e-110

    1. Initial program 77.9%

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

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

        \[\leadsto \frac{-1 \cdot a + \frac{b \cdot c}{d}}{\color{blue}{d}} \]
      2. +-commutativeN/A

        \[\leadsto \frac{\frac{b \cdot c}{d} + -1 \cdot a}{d} \]
      3. associate-/l*N/A

        \[\leadsto \frac{b \cdot \frac{c}{d} + -1 \cdot a}{d} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{c}{d}, -1 \cdot a\right)}{d} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{c}{d}, -1 \cdot a\right)}{d} \]
      6. mul-1-negN/A

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{c}{d}, \mathsf{neg}\left(a\right)\right)}{d} \]
      7. lower-neg.f6487.8

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d} \]
    5. Applied rewrites87.8%

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

    if 1.49999999999999993e-110 < c < 3.1e10

    1. Initial program 81.6%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c} + d \cdot d} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{b \cdot c - a \cdot d}{c \cdot c + \color{blue}{d \cdot d}} \]
      4. pow2N/A

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

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

        \[\leadsto \frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, \color{blue}{d \cdot d}\right)} \]
      7. lift-*.f6481.6

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

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 2: 62.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := b \cdot c - a \cdot d\\ \mathbf{if}\;c \leq -1.26 \cdot 10^{+107}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -6 \cdot 10^{-134}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c}\\ \mathbf{elif}\;c \leq 7.8 \cdot 10^{-177}:\\ \;\;\;\;\frac{t\_0}{d \cdot d}\\ \mathbf{elif}\;c \leq 4 \cdot 10^{-86}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{+101}:\\ \;\;\;\;\frac{t\_0}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (- (* b c) (* a d))))
   (if (<= c -1.26e+107)
     (/ b c)
     (if (<= c -6e-134)
       (/ (fma (- a) d (* c b)) (* c c))
       (if (<= c 7.8e-177)
         (/ t_0 (* d d))
         (if (<= c 4e-86)
           (/ (- a) d)
           (if (<= c 1.25e+101) (/ t_0 (* c c)) (/ b c))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (b * c) - (a * d);
	double tmp;
	if (c <= -1.26e+107) {
		tmp = b / c;
	} else if (c <= -6e-134) {
		tmp = fma(-a, d, (c * b)) / (c * c);
	} else if (c <= 7.8e-177) {
		tmp = t_0 / (d * d);
	} else if (c <= 4e-86) {
		tmp = -a / d;
	} else if (c <= 1.25e+101) {
		tmp = t_0 / (c * c);
	} else {
		tmp = b / c;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(b * c) - Float64(a * d))
	tmp = 0.0
	if (c <= -1.26e+107)
		tmp = Float64(b / c);
	elseif (c <= -6e-134)
		tmp = Float64(fma(Float64(-a), d, Float64(c * b)) / Float64(c * c));
	elseif (c <= 7.8e-177)
		tmp = Float64(t_0 / Float64(d * d));
	elseif (c <= 4e-86)
		tmp = Float64(Float64(-a) / d);
	elseif (c <= 1.25e+101)
		tmp = Float64(t_0 / Float64(c * c));
	else
		tmp = Float64(b / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.26e+107], N[(b / c), $MachinePrecision], If[LessEqual[c, -6e-134], N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.8e-177], N[(t$95$0 / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4e-86], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 1.25e+101], N[(t$95$0 / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -6 \cdot 10^{-134}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c}\\

\mathbf{elif}\;c \leq 7.8 \cdot 10^{-177}:\\
\;\;\;\;\frac{t\_0}{d \cdot d}\\

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

\mathbf{elif}\;c \leq 1.25 \cdot 10^{+101}:\\
\;\;\;\;\frac{t\_0}{c \cdot c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if c < -1.25999999999999995e107 or 1.24999999999999997e101 < c

    1. Initial program 34.1%

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

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

        \[\leadsto \frac{b}{\color{blue}{c}} \]
    5. Applied rewrites76.0%

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

    if -1.25999999999999995e107 < c < -6e-134

    1. Initial program 76.9%

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

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

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

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

        \[\leadsto \frac{b - 1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. metadata-evalN/A

        \[\leadsto \frac{b - \frac{-1}{-1} \cdot \frac{a \cdot d}{c}}{c} \]
      5. times-fracN/A

        \[\leadsto \frac{b - \frac{-1 \cdot \left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      6. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      7. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{\mathsf{neg}\left(c\right)}}{c} \]
      8. frac-2negN/A

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

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

        \[\leadsto \frac{b - \frac{a \cdot d}{c}}{c} \]
      11. *-commutativeN/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      12. lower-*.f6462.1

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
    5. Applied rewrites62.1%

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

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

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

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a \cdot d\right)\right)}{{c}^{2}} \]
      3. distribute-lft-neg-outN/A

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a\right)\right) \cdot d}{{c}^{2}} \]
      4. cancel-sign-sub-invN/A

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

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

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a\right)\right) \cdot d}{{c}^{2}} \]
      7. distribute-lft-neg-outN/A

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a \cdot d\right)\right)}{{c}^{2}} \]
      8. mul-1-negN/A

        \[\leadsto \frac{b \cdot c + -1 \cdot \left(a \cdot d\right)}{{c}^{2}} \]
      9. +-commutativeN/A

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

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

        \[\leadsto \frac{\mathsf{fma}\left(-1 \cdot a, d, b \cdot c\right)}{{c}^{2}} \]
      12. mul-1-negN/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{neg}\left(a\right), d, b \cdot c\right)}{{c}^{2}} \]
      13. lift-neg.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, b \cdot c\right)}{{c}^{2}} \]
      14. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{{c}^{2}} \]
      15. lift-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{{c}^{2}} \]
      16. pow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c} \]
      17. lift-*.f6460.0

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c} \]
    8. Applied rewrites60.0%

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

    if -6e-134 < c < 7.80000000000000028e-177

    1. Initial program 82.5%

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

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

        \[\leadsto \frac{b \cdot c - a \cdot d}{d \cdot \color{blue}{d}} \]
      2. lift-*.f6480.7

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

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

    if 7.80000000000000028e-177 < c < 4.00000000000000034e-86

    1. Initial program 72.2%

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

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

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

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

        \[\leadsto \frac{\mathsf{neg}\left(a\right)}{d} \]
      4. lower-neg.f6479.5

        \[\leadsto \frac{-a}{d} \]
    5. Applied rewrites79.5%

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

    if 4.00000000000000034e-86 < c < 1.24999999999999997e101

    1. Initial program 76.1%

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

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

        \[\leadsto \frac{b \cdot c - a \cdot d}{c \cdot \color{blue}{c}} \]
      2. lift-*.f6464.9

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

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

Alternative 3: 72.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c}\\ \mathbf{if}\;c \leq -1.26 \cdot 10^{+107}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -8.8 \cdot 10^{-13}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.9 \cdot 10^{-78}:\\ \;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\ \mathbf{elif}\;c \leq 1.02 \cdot 10^{+104}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (fma (- a) d (* c b)) (* c c))))
   (if (<= c -1.26e+107)
     (/ b c)
     (if (<= c -8.8e-13)
       t_0
       (if (<= c 1.9e-78)
         (/ (- (/ (* c b) d) a) d)
         (if (<= c 1.02e+104) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(-a, d, (c * b)) / (c * c);
	double tmp;
	if (c <= -1.26e+107) {
		tmp = b / c;
	} else if (c <= -8.8e-13) {
		tmp = t_0;
	} else if (c <= 1.9e-78) {
		tmp = (((c * b) / d) - a) / d;
	} else if (c <= 1.02e+104) {
		tmp = t_0;
	} else {
		tmp = b / c;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(fma(Float64(-a), d, Float64(c * b)) / Float64(c * c))
	tmp = 0.0
	if (c <= -1.26e+107)
		tmp = Float64(b / c);
	elseif (c <= -8.8e-13)
		tmp = t_0;
	elseif (c <= 1.9e-78)
		tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d);
	elseif (c <= 1.02e+104)
		tmp = t_0;
	else
		tmp = Float64(b / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.26e+107], N[(b / c), $MachinePrecision], If[LessEqual[c, -8.8e-13], t$95$0, If[LessEqual[c, 1.9e-78], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.02e+104], t$95$0, N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -8.8 \cdot 10^{-13}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.02 \cdot 10^{+104}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.25999999999999995e107 or 1.02e104 < c

    1. Initial program 34.4%

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

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

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

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

    if -1.25999999999999995e107 < c < -8.79999999999999986e-13 or 1.8999999999999999e-78 < c < 1.02e104

    1. Initial program 74.5%

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

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

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

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

        \[\leadsto \frac{b - 1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. metadata-evalN/A

        \[\leadsto \frac{b - \frac{-1}{-1} \cdot \frac{a \cdot d}{c}}{c} \]
      5. times-fracN/A

        \[\leadsto \frac{b - \frac{-1 \cdot \left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      6. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      7. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{\mathsf{neg}\left(c\right)}}{c} \]
      8. frac-2negN/A

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

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

        \[\leadsto \frac{b - \frac{a \cdot d}{c}}{c} \]
      11. *-commutativeN/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      12. lower-*.f6471.7

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

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

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

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

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a \cdot d\right)\right)}{{c}^{2}} \]
      3. distribute-lft-neg-outN/A

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a\right)\right) \cdot d}{{c}^{2}} \]
      4. cancel-sign-sub-invN/A

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

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

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a\right)\right) \cdot d}{{c}^{2}} \]
      7. distribute-lft-neg-outN/A

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a \cdot d\right)\right)}{{c}^{2}} \]
      8. mul-1-negN/A

        \[\leadsto \frac{b \cdot c + -1 \cdot \left(a \cdot d\right)}{{c}^{2}} \]
      9. +-commutativeN/A

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

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

        \[\leadsto \frac{\mathsf{fma}\left(-1 \cdot a, d, b \cdot c\right)}{{c}^{2}} \]
      12. mul-1-negN/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{neg}\left(a\right), d, b \cdot c\right)}{{c}^{2}} \]
      13. lift-neg.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, b \cdot c\right)}{{c}^{2}} \]
      14. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{{c}^{2}} \]
      15. lift-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{{c}^{2}} \]
      16. pow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c} \]
      17. lift-*.f6467.2

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c} \]
    8. Applied rewrites67.2%

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

    if -8.79999999999999986e-13 < c < 1.8999999999999999e-78

    1. Initial program 79.1%

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

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

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

        \[\leadsto -\frac{a + -1 \cdot \frac{b \cdot c}{d}}{d} \]
      3. lower-/.f64N/A

        \[\leadsto -\frac{a + -1 \cdot \frac{b \cdot c}{d}}{d} \]
      4. +-commutativeN/A

        \[\leadsto -\frac{-1 \cdot \frac{b \cdot c}{d} + a}{d} \]
      5. *-commutativeN/A

        \[\leadsto -\frac{\frac{b \cdot c}{d} \cdot -1 + a}{d} \]
      6. lower-fma.f64N/A

        \[\leadsto -\frac{\mathsf{fma}\left(\frac{b \cdot c}{d}, -1, a\right)}{d} \]
      7. lower-/.f64N/A

        \[\leadsto -\frac{\mathsf{fma}\left(\frac{b \cdot c}{d}, -1, a\right)}{d} \]
      8. *-commutativeN/A

        \[\leadsto -\frac{\mathsf{fma}\left(\frac{c \cdot b}{d}, -1, a\right)}{d} \]
      9. lower-*.f6485.8

        \[\leadsto -\frac{\mathsf{fma}\left(\frac{c \cdot b}{d}, -1, a\right)}{d} \]
    5. Applied rewrites85.8%

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

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

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

        \[\leadsto \frac{\frac{b \cdot c}{d} - a}{d} \]
      3. *-commutativeN/A

        \[\leadsto \frac{\frac{c \cdot b}{d} - a}{d} \]
      4. lift-/.f64N/A

        \[\leadsto \frac{\frac{c \cdot b}{d} - a}{d} \]
      5. lift-*.f6485.8

        \[\leadsto \frac{\frac{c \cdot b}{d} - a}{d} \]
    8. Applied rewrites85.8%

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

Alternative 4: 64.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.26 \cdot 10^{+107}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -4.6 \cdot 10^{-134}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c}\\ \mathbf{elif}\;c \leq 4 \cdot 10^{-86}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{+101}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -1.26e+107)
   (/ b c)
   (if (<= c -4.6e-134)
     (/ (fma (- a) d (* c b)) (* c c))
     (if (<= c 4e-86)
       (/ (- a) d)
       (if (<= c 1.25e+101) (/ (- (* b c) (* a d)) (* c c)) (/ b c))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -1.26e+107) {
		tmp = b / c;
	} else if (c <= -4.6e-134) {
		tmp = fma(-a, d, (c * b)) / (c * c);
	} else if (c <= 4e-86) {
		tmp = -a / d;
	} else if (c <= 1.25e+101) {
		tmp = ((b * c) - (a * d)) / (c * c);
	} else {
		tmp = b / c;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -1.26e+107)
		tmp = Float64(b / c);
	elseif (c <= -4.6e-134)
		tmp = Float64(fma(Float64(-a), d, Float64(c * b)) / Float64(c * c));
	elseif (c <= 4e-86)
		tmp = Float64(Float64(-a) / d);
	elseif (c <= 1.25e+101)
		tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(c * c));
	else
		tmp = Float64(b / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.26e+107], N[(b / c), $MachinePrecision], If[LessEqual[c, -4.6e-134], N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4e-86], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 1.25e+101], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.26 \cdot 10^{+107}:\\
\;\;\;\;\frac{b}{c}\\

\mathbf{elif}\;c \leq -4.6 \cdot 10^{-134}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -1.25999999999999995e107 or 1.24999999999999997e101 < c

    1. Initial program 34.1%

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

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

        \[\leadsto \frac{b}{\color{blue}{c}} \]
    5. Applied rewrites76.0%

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

    if -1.25999999999999995e107 < c < -4.6000000000000001e-134

    1. Initial program 76.9%

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

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

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

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

        \[\leadsto \frac{b - 1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. metadata-evalN/A

        \[\leadsto \frac{b - \frac{-1}{-1} \cdot \frac{a \cdot d}{c}}{c} \]
      5. times-fracN/A

        \[\leadsto \frac{b - \frac{-1 \cdot \left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      6. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      7. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{\mathsf{neg}\left(c\right)}}{c} \]
      8. frac-2negN/A

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

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

        \[\leadsto \frac{b - \frac{a \cdot d}{c}}{c} \]
      11. *-commutativeN/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      12. lower-*.f6462.1

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
    5. Applied rewrites62.1%

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

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

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

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a \cdot d\right)\right)}{{c}^{2}} \]
      3. distribute-lft-neg-outN/A

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a\right)\right) \cdot d}{{c}^{2}} \]
      4. cancel-sign-sub-invN/A

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

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

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a\right)\right) \cdot d}{{c}^{2}} \]
      7. distribute-lft-neg-outN/A

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a \cdot d\right)\right)}{{c}^{2}} \]
      8. mul-1-negN/A

        \[\leadsto \frac{b \cdot c + -1 \cdot \left(a \cdot d\right)}{{c}^{2}} \]
      9. +-commutativeN/A

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

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

        \[\leadsto \frac{\mathsf{fma}\left(-1 \cdot a, d, b \cdot c\right)}{{c}^{2}} \]
      12. mul-1-negN/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{neg}\left(a\right), d, b \cdot c\right)}{{c}^{2}} \]
      13. lift-neg.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, b \cdot c\right)}{{c}^{2}} \]
      14. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{{c}^{2}} \]
      15. lift-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{{c}^{2}} \]
      16. pow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c} \]
      17. lift-*.f6460.0

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c} \]
    8. Applied rewrites60.0%

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

    if -4.6000000000000001e-134 < c < 4.00000000000000034e-86

    1. Initial program 79.1%

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

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

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

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

        \[\leadsto \frac{\mathsf{neg}\left(a\right)}{d} \]
      4. lower-neg.f6474.5

        \[\leadsto \frac{-a}{d} \]
    5. Applied rewrites74.5%

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

    if 4.00000000000000034e-86 < c < 1.24999999999999997e101

    1. Initial program 76.1%

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

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

        \[\leadsto \frac{b \cdot c - a \cdot d}{c \cdot \color{blue}{c}} \]
      2. lift-*.f6464.9

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

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

Alternative 5: 64.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c}\\ \mathbf{if}\;c \leq -1.26 \cdot 10^{+107}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -4.6 \cdot 10^{-134}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 4 \cdot 10^{-86}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 1.02 \cdot 10^{+104}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (fma (- a) d (* c b)) (* c c))))
   (if (<= c -1.26e+107)
     (/ b c)
     (if (<= c -4.6e-134)
       t_0
       (if (<= c 4e-86) (/ (- a) d) (if (<= c 1.02e+104) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(-a, d, (c * b)) / (c * c);
	double tmp;
	if (c <= -1.26e+107) {
		tmp = b / c;
	} else if (c <= -4.6e-134) {
		tmp = t_0;
	} else if (c <= 4e-86) {
		tmp = -a / d;
	} else if (c <= 1.02e+104) {
		tmp = t_0;
	} else {
		tmp = b / c;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(fma(Float64(-a), d, Float64(c * b)) / Float64(c * c))
	tmp = 0.0
	if (c <= -1.26e+107)
		tmp = Float64(b / c);
	elseif (c <= -4.6e-134)
		tmp = t_0;
	elseif (c <= 4e-86)
		tmp = Float64(Float64(-a) / d);
	elseif (c <= 1.02e+104)
		tmp = t_0;
	else
		tmp = Float64(b / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.26e+107], N[(b / c), $MachinePrecision], If[LessEqual[c, -4.6e-134], t$95$0, If[LessEqual[c, 4e-86], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 1.02e+104], t$95$0, N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -4.6 \cdot 10^{-134}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.02 \cdot 10^{+104}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.25999999999999995e107 or 1.02e104 < c

    1. Initial program 34.4%

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

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

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

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

    if -1.25999999999999995e107 < c < -4.6000000000000001e-134 or 4.00000000000000034e-86 < c < 1.02e104

    1. Initial program 75.8%

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

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

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

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

        \[\leadsto \frac{b - 1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. metadata-evalN/A

        \[\leadsto \frac{b - \frac{-1}{-1} \cdot \frac{a \cdot d}{c}}{c} \]
      5. times-fracN/A

        \[\leadsto \frac{b - \frac{-1 \cdot \left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      6. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      7. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{\mathsf{neg}\left(c\right)}}{c} \]
      8. frac-2negN/A

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

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

        \[\leadsto \frac{b - \frac{a \cdot d}{c}}{c} \]
      11. *-commutativeN/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      12. lower-*.f6464.8

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
    5. Applied rewrites64.8%

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

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

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

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a \cdot d\right)\right)}{{c}^{2}} \]
      3. distribute-lft-neg-outN/A

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a\right)\right) \cdot d}{{c}^{2}} \]
      4. cancel-sign-sub-invN/A

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

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

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a\right)\right) \cdot d}{{c}^{2}} \]
      7. distribute-lft-neg-outN/A

        \[\leadsto \frac{b \cdot c + \left(\mathsf{neg}\left(a \cdot d\right)\right)}{{c}^{2}} \]
      8. mul-1-negN/A

        \[\leadsto \frac{b \cdot c + -1 \cdot \left(a \cdot d\right)}{{c}^{2}} \]
      9. +-commutativeN/A

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

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

        \[\leadsto \frac{\mathsf{fma}\left(-1 \cdot a, d, b \cdot c\right)}{{c}^{2}} \]
      12. mul-1-negN/A

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{neg}\left(a\right), d, b \cdot c\right)}{{c}^{2}} \]
      13. lift-neg.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, b \cdot c\right)}{{c}^{2}} \]
      14. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{{c}^{2}} \]
      15. lift-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{{c}^{2}} \]
      16. pow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c} \]
      17. lift-*.f6461.5

        \[\leadsto \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c} \]
    8. Applied rewrites61.5%

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

    if -4.6000000000000001e-134 < c < 4.00000000000000034e-86

    1. Initial program 79.1%

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

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

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

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

        \[\leadsto \frac{\mathsf{neg}\left(a\right)}{d} \]
      4. lower-neg.f6474.5

        \[\leadsto \frac{-a}{d} \]
    5. Applied rewrites74.5%

      \[\leadsto \color{blue}{\frac{-a}{d}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 77.7% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -8.8 \cdot 10^{-13} \lor \neg \left(c \leq 1.9 \cdot 10^{-78}\right):\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -8.8e-13) (not (<= c 1.9e-78)))
   (/ (- b (* d (/ a c))) c)
   (/ (fma b (/ c d) (- a)) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -8.8e-13) || !(c <= 1.9e-78)) {
		tmp = (b - (d * (a / c))) / c;
	} else {
		tmp = fma(b, (c / d), -a) / d;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -8.8e-13) || !(c <= 1.9e-78))
		tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c);
	else
		tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -8.8e-13], N[Not[LessEqual[c, 1.9e-78]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.8 \cdot 10^{-13} \lor \neg \left(c \leq 1.9 \cdot 10^{-78}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -8.79999999999999986e-13 or 1.8999999999999999e-78 < c

    1. Initial program 51.5%

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

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

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

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

        \[\leadsto \frac{b - 1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. metadata-evalN/A

        \[\leadsto \frac{b - \frac{-1}{-1} \cdot \frac{a \cdot d}{c}}{c} \]
      5. times-fracN/A

        \[\leadsto \frac{b - \frac{-1 \cdot \left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      6. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      7. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{\mathsf{neg}\left(c\right)}}{c} \]
      8. frac-2negN/A

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

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

        \[\leadsto \frac{b - \frac{a \cdot d}{c}}{c} \]
      11. *-commutativeN/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      12. lower-*.f6474.7

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

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

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      3. associate-/l*N/A

        \[\leadsto \frac{b - d \cdot \frac{a}{c}}{c} \]
      4. lower-*.f64N/A

        \[\leadsto \frac{b - d \cdot \frac{a}{c}}{c} \]
      5. lower-/.f6480.0

        \[\leadsto \frac{b - d \cdot \frac{a}{c}}{c} \]
    7. Applied rewrites80.0%

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

    if -8.79999999999999986e-13 < c < 1.8999999999999999e-78

    1. Initial program 79.1%

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

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

        \[\leadsto \frac{-1 \cdot a + \frac{b \cdot c}{d}}{\color{blue}{d}} \]
      2. +-commutativeN/A

        \[\leadsto \frac{\frac{b \cdot c}{d} + -1 \cdot a}{d} \]
      3. associate-/l*N/A

        \[\leadsto \frac{b \cdot \frac{c}{d} + -1 \cdot a}{d} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{c}{d}, -1 \cdot a\right)}{d} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{c}{d}, -1 \cdot a\right)}{d} \]
      6. mul-1-negN/A

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{c}{d}, \mathsf{neg}\left(a\right)\right)}{d} \]
      7. lower-neg.f6486.0

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d} \]
    5. Applied rewrites86.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -8.8 \cdot 10^{-13} \lor \neg \left(c \leq 1.9 \cdot 10^{-78}\right):\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 77.7% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -8.8 \cdot 10^{-13} \lor \neg \left(c \leq 1.9 \cdot 10^{-78}\right):\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -8.8e-13) (not (<= c 1.9e-78)))
   (/ (- b (* d (/ a c))) c)
   (/ (- (/ (* c b) d) a) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -8.8e-13) || !(c <= 1.9e-78)) {
		tmp = (b - (d * (a / c))) / c;
	} else {
		tmp = (((c * b) / d) - a) / d;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    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 <= (-8.8d-13)) .or. (.not. (c <= 1.9d-78))) then
        tmp = (b - (d * (a / c))) / c
    else
        tmp = (((c * b) / 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 <= -8.8e-13) || !(c <= 1.9e-78)) {
		tmp = (b - (d * (a / c))) / c;
	} else {
		tmp = (((c * b) / d) - a) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -8.8e-13) or not (c <= 1.9e-78):
		tmp = (b - (d * (a / c))) / c
	else:
		tmp = (((c * b) / d) - a) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -8.8e-13) || !(c <= 1.9e-78))
		tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c);
	else
		tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -8.8e-13) || ~((c <= 1.9e-78)))
		tmp = (b - (d * (a / c))) / c;
	else
		tmp = (((c * b) / d) - a) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -8.8e-13], N[Not[LessEqual[c, 1.9e-78]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.8 \cdot 10^{-13} \lor \neg \left(c \leq 1.9 \cdot 10^{-78}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -8.79999999999999986e-13 or 1.8999999999999999e-78 < c

    1. Initial program 51.5%

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

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

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

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

        \[\leadsto \frac{b - 1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. metadata-evalN/A

        \[\leadsto \frac{b - \frac{-1}{-1} \cdot \frac{a \cdot d}{c}}{c} \]
      5. times-fracN/A

        \[\leadsto \frac{b - \frac{-1 \cdot \left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      6. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      7. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{\mathsf{neg}\left(c\right)}}{c} \]
      8. frac-2negN/A

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

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

        \[\leadsto \frac{b - \frac{a \cdot d}{c}}{c} \]
      11. *-commutativeN/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      12. lower-*.f6474.7

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

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

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      3. associate-/l*N/A

        \[\leadsto \frac{b - d \cdot \frac{a}{c}}{c} \]
      4. lower-*.f64N/A

        \[\leadsto \frac{b - d \cdot \frac{a}{c}}{c} \]
      5. lower-/.f6480.0

        \[\leadsto \frac{b - d \cdot \frac{a}{c}}{c} \]
    7. Applied rewrites80.0%

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

    if -8.79999999999999986e-13 < c < 1.8999999999999999e-78

    1. Initial program 79.1%

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

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

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

        \[\leadsto -\frac{a + -1 \cdot \frac{b \cdot c}{d}}{d} \]
      3. lower-/.f64N/A

        \[\leadsto -\frac{a + -1 \cdot \frac{b \cdot c}{d}}{d} \]
      4. +-commutativeN/A

        \[\leadsto -\frac{-1 \cdot \frac{b \cdot c}{d} + a}{d} \]
      5. *-commutativeN/A

        \[\leadsto -\frac{\frac{b \cdot c}{d} \cdot -1 + a}{d} \]
      6. lower-fma.f64N/A

        \[\leadsto -\frac{\mathsf{fma}\left(\frac{b \cdot c}{d}, -1, a\right)}{d} \]
      7. lower-/.f64N/A

        \[\leadsto -\frac{\mathsf{fma}\left(\frac{b \cdot c}{d}, -1, a\right)}{d} \]
      8. *-commutativeN/A

        \[\leadsto -\frac{\mathsf{fma}\left(\frac{c \cdot b}{d}, -1, a\right)}{d} \]
      9. lower-*.f6485.8

        \[\leadsto -\frac{\mathsf{fma}\left(\frac{c \cdot b}{d}, -1, a\right)}{d} \]
    5. Applied rewrites85.8%

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

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

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

        \[\leadsto \frac{\frac{b \cdot c}{d} - a}{d} \]
      3. *-commutativeN/A

        \[\leadsto \frac{\frac{c \cdot b}{d} - a}{d} \]
      4. lift-/.f64N/A

        \[\leadsto \frac{\frac{c \cdot b}{d} - a}{d} \]
      5. lift-*.f6485.8

        \[\leadsto \frac{\frac{c \cdot b}{d} - a}{d} \]
    8. Applied rewrites85.8%

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

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

Alternative 8: 77.6% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -8.8 \cdot 10^{-13} \lor \neg \left(c \leq 1.9 \cdot 10^{-78}\right):\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -8.8e-13) (not (<= c 1.9e-78)))
   (/ (- b (* a (/ d c))) c)
   (/ (- (/ (* c b) d) a) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -8.8e-13) || !(c <= 1.9e-78)) {
		tmp = (b - (a * (d / c))) / c;
	} else {
		tmp = (((c * b) / d) - a) / d;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    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 <= (-8.8d-13)) .or. (.not. (c <= 1.9d-78))) then
        tmp = (b - (a * (d / c))) / c
    else
        tmp = (((c * b) / 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 <= -8.8e-13) || !(c <= 1.9e-78)) {
		tmp = (b - (a * (d / c))) / c;
	} else {
		tmp = (((c * b) / d) - a) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -8.8e-13) or not (c <= 1.9e-78):
		tmp = (b - (a * (d / c))) / c
	else:
		tmp = (((c * b) / d) - a) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -8.8e-13) || !(c <= 1.9e-78))
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	else
		tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -8.8e-13) || ~((c <= 1.9e-78)))
		tmp = (b - (a * (d / c))) / c;
	else
		tmp = (((c * b) / d) - a) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -8.8e-13], N[Not[LessEqual[c, 1.9e-78]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.8 \cdot 10^{-13} \lor \neg \left(c \leq 1.9 \cdot 10^{-78}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -8.79999999999999986e-13 or 1.8999999999999999e-78 < c

    1. Initial program 51.5%

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

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

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

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

        \[\leadsto \frac{b - 1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. metadata-evalN/A

        \[\leadsto \frac{b - \frac{-1}{-1} \cdot \frac{a \cdot d}{c}}{c} \]
      5. times-fracN/A

        \[\leadsto \frac{b - \frac{-1 \cdot \left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      6. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      7. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{\mathsf{neg}\left(c\right)}}{c} \]
      8. frac-2negN/A

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

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

        \[\leadsto \frac{b - \frac{a \cdot d}{c}}{c} \]
      11. *-commutativeN/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      12. lower-*.f6474.7

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

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

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      3. *-commutativeN/A

        \[\leadsto \frac{b - \frac{a \cdot d}{c}}{c} \]
      4. associate-/l*N/A

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

        \[\leadsto \frac{b - a \cdot \frac{d}{c}}{c} \]
      6. lower-/.f6479.3

        \[\leadsto \frac{b - a \cdot \frac{d}{c}}{c} \]
    7. Applied rewrites79.3%

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

    if -8.79999999999999986e-13 < c < 1.8999999999999999e-78

    1. Initial program 79.1%

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

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

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

        \[\leadsto -\frac{a + -1 \cdot \frac{b \cdot c}{d}}{d} \]
      3. lower-/.f64N/A

        \[\leadsto -\frac{a + -1 \cdot \frac{b \cdot c}{d}}{d} \]
      4. +-commutativeN/A

        \[\leadsto -\frac{-1 \cdot \frac{b \cdot c}{d} + a}{d} \]
      5. *-commutativeN/A

        \[\leadsto -\frac{\frac{b \cdot c}{d} \cdot -1 + a}{d} \]
      6. lower-fma.f64N/A

        \[\leadsto -\frac{\mathsf{fma}\left(\frac{b \cdot c}{d}, -1, a\right)}{d} \]
      7. lower-/.f64N/A

        \[\leadsto -\frac{\mathsf{fma}\left(\frac{b \cdot c}{d}, -1, a\right)}{d} \]
      8. *-commutativeN/A

        \[\leadsto -\frac{\mathsf{fma}\left(\frac{c \cdot b}{d}, -1, a\right)}{d} \]
      9. lower-*.f6485.8

        \[\leadsto -\frac{\mathsf{fma}\left(\frac{c \cdot b}{d}, -1, a\right)}{d} \]
    5. Applied rewrites85.8%

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

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

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

        \[\leadsto \frac{\frac{b \cdot c}{d} - a}{d} \]
      3. *-commutativeN/A

        \[\leadsto \frac{\frac{c \cdot b}{d} - a}{d} \]
      4. lift-/.f64N/A

        \[\leadsto \frac{\frac{c \cdot b}{d} - a}{d} \]
      5. lift-*.f6485.8

        \[\leadsto \frac{\frac{c \cdot b}{d} - a}{d} \]
    8. Applied rewrites85.8%

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

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

Alternative 9: 62.0% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -4.7 \cdot 10^{+35}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -4.1 \cdot 10^{-12}:\\ \;\;\;\;\frac{\left(-a\right) \cdot d}{c \cdot c}\\ \mathbf{elif}\;c \leq 4 \cdot 10^{-86}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -4.7e+35)
   (/ b c)
   (if (<= c -4.1e-12)
     (/ (* (- a) d) (* c c))
     (if (<= c 4e-86) (/ (- a) d) (/ b c)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -4.7e+35) {
		tmp = b / c;
	} else if (c <= -4.1e-12) {
		tmp = (-a * d) / (c * c);
	} else if (c <= 4e-86) {
		tmp = -a / d;
	} else {
		tmp = b / c;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    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 <= (-4.7d+35)) then
        tmp = b / c
    else if (c <= (-4.1d-12)) then
        tmp = (-a * d) / (c * c)
    else if (c <= 4d-86) then
        tmp = -a / d
    else
        tmp = b / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -4.7e+35) {
		tmp = b / c;
	} else if (c <= -4.1e-12) {
		tmp = (-a * d) / (c * c);
	} else if (c <= 4e-86) {
		tmp = -a / d;
	} else {
		tmp = b / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -4.7e+35:
		tmp = b / c
	elif c <= -4.1e-12:
		tmp = (-a * d) / (c * c)
	elif c <= 4e-86:
		tmp = -a / d
	else:
		tmp = b / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -4.7e+35)
		tmp = Float64(b / c);
	elseif (c <= -4.1e-12)
		tmp = Float64(Float64(Float64(-a) * d) / Float64(c * c));
	elseif (c <= 4e-86)
		tmp = Float64(Float64(-a) / d);
	else
		tmp = Float64(b / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -4.7e+35)
		tmp = b / c;
	elseif (c <= -4.1e-12)
		tmp = (-a * d) / (c * c);
	elseif (c <= 4e-86)
		tmp = -a / d;
	else
		tmp = b / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.7e+35], N[(b / c), $MachinePrecision], If[LessEqual[c, -4.1e-12], N[(N[((-a) * d), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4e-86], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.7 \cdot 10^{+35}:\\
\;\;\;\;\frac{b}{c}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -4.70000000000000033e35 or 4.00000000000000034e-86 < c

    1. Initial program 49.2%

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

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

        \[\leadsto \frac{b}{\color{blue}{c}} \]
    5. Applied rewrites68.0%

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

    if -4.70000000000000033e35 < c < -4.0999999999999999e-12

    1. Initial program 84.4%

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

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

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

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

        \[\leadsto \frac{b - 1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. metadata-evalN/A

        \[\leadsto \frac{b - \frac{-1}{-1} \cdot \frac{a \cdot d}{c}}{c} \]
      5. times-fracN/A

        \[\leadsto \frac{b - \frac{-1 \cdot \left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      6. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{-1 \cdot c}}{c} \]
      7. mul-1-negN/A

        \[\leadsto \frac{b - \frac{\mathsf{neg}\left(a \cdot d\right)}{\mathsf{neg}\left(c\right)}}{c} \]
      8. frac-2negN/A

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

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

        \[\leadsto \frac{b - \frac{a \cdot d}{c}}{c} \]
      11. *-commutativeN/A

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
      12. lower-*.f6476.9

        \[\leadsto \frac{b - \frac{d \cdot a}{c}}{c} \]
    5. Applied rewrites76.9%

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

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

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

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

        \[\leadsto \frac{\mathsf{neg}\left(a \cdot d\right)}{{c}^{2}} \]
      4. distribute-lft-neg-outN/A

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

        \[\leadsto \frac{\left(\mathsf{neg}\left(a\right)\right) \cdot d}{{c}^{2}} \]
      6. lift-neg.f64N/A

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

        \[\leadsto \frac{\left(-a\right) \cdot d}{c \cdot c} \]
      8. lift-*.f6460.3

        \[\leadsto \frac{\left(-a\right) \cdot d}{c \cdot c} \]
    8. Applied rewrites60.3%

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

    if -4.0999999999999999e-12 < c < 4.00000000000000034e-86

    1. Initial program 78.6%

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

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

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

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

        \[\leadsto \frac{\mathsf{neg}\left(a\right)}{d} \]
      4. lower-neg.f6467.8

        \[\leadsto \frac{-a}{d} \]
    5. Applied rewrites67.8%

      \[\leadsto \color{blue}{\frac{-a}{d}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 10: 63.1% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.45 \cdot 10^{+14} \lor \neg \left(c \leq 4 \cdot 10^{-86}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -1.45e+14) (not (<= c 4e-86))) (/ b c) (/ (- a) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -1.45e+14) || !(c <= 4e-86)) {
		tmp = b / c;
	} else {
		tmp = -a / d;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    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.45d+14)) .or. (.not. (c <= 4d-86))) then
        tmp = b / c
    else
        tmp = -a / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -1.45e+14) || !(c <= 4e-86)) {
		tmp = b / c;
	} else {
		tmp = -a / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -1.45e+14) or not (c <= 4e-86):
		tmp = b / c
	else:
		tmp = -a / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -1.45e+14) || !(c <= 4e-86))
		tmp = Float64(b / c);
	else
		tmp = Float64(Float64(-a) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -1.45e+14) || ~((c <= 4e-86)))
		tmp = b / c;
	else
		tmp = -a / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.45e+14], N[Not[LessEqual[c, 4e-86]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.45 \cdot 10^{+14} \lor \neg \left(c \leq 4 \cdot 10^{-86}\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.45e14 or 4.00000000000000034e-86 < c

    1. Initial program 51.2%

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

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

        \[\leadsto \frac{b}{\color{blue}{c}} \]
    5. Applied rewrites65.3%

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

    if -1.45e14 < c < 4.00000000000000034e-86

    1. Initial program 78.7%

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

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

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

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

        \[\leadsto \frac{\mathsf{neg}\left(a\right)}{d} \]
      4. lower-neg.f6466.5

        \[\leadsto \frac{-a}{d} \]
    5. Applied rewrites66.5%

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

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

Alternative 11: 44.1% accurate, 3.2× speedup?

\[\begin{array}{l} \\ \frac{b}{c} \end{array} \]
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
	return b / c;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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

\\
\frac{b}{c}
\end{array}
Derivation
  1. Initial program 62.7%

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

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

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

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

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

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (< (fabs d) (fabs c))
   (/ (- b (* a (/ d c))) (+ c (* d (/ d c))))
   (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (fabs(d) < fabs(c)) {
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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

\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\

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


\end{array}
\end{array}

Reproduce

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

  :alt
  (! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))

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