Complex division, imag part

Percentage Accurate: 62.1% → 83.0%
Time: 3.8s
Alternatives: 10
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}

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 alternatives:

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

Initial Program: 62.1% 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: 83.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{-a}{c}\\ \mathbf{if}\;c \leq -1.25 \cdot 10^{+116}:\\ \;\;\;\;\mathsf{fma}\left(t\_1, \frac{d}{c}, \frac{b}{c}\right)\\ \mathbf{elif}\;c \leq -5.5 \cdot 10^{-154}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.65 \cdot 10^{-143}:\\ \;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\ \mathbf{elif}\;c \leq 6.2 \cdot 10^{+51}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t\_1, d, b\right)}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))) (t_1 (/ (- a) c)))
   (if (<= c -1.25e+116)
     (fma t_1 (/ d c) (/ b c))
     (if (<= c -5.5e-154)
       t_0
       (if (<= c 1.65e-143)
         (/ (- (/ (* c b) d) a) d)
         (if (<= c 6.2e+51) t_0 (/ (fma t_1 d b) c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	double t_1 = -a / c;
	double tmp;
	if (c <= -1.25e+116) {
		tmp = fma(t_1, (d / c), (b / c));
	} else if (c <= -5.5e-154) {
		tmp = t_0;
	} else if (c <= 1.65e-143) {
		tmp = (((c * b) / d) - a) / d;
	} else if (c <= 6.2e+51) {
		tmp = t_0;
	} else {
		tmp = fma(t_1, d, b) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(-a) / c)
	tmp = 0.0
	if (c <= -1.25e+116)
		tmp = fma(t_1, Float64(d / c), Float64(b / c));
	elseif (c <= -5.5e-154)
		tmp = t_0;
	elseif (c <= 1.65e-143)
		tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d);
	elseif (c <= 6.2e+51)
		tmp = t_0;
	else
		tmp = Float64(fma(t_1, d, b) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-a) / c), $MachinePrecision]}, If[LessEqual[c, -1.25e+116], N[(t$95$1 * N[(d / c), $MachinePrecision] + N[(b / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -5.5e-154], t$95$0, If[LessEqual[c, 1.65e-143], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6.2e+51], t$95$0, N[(N[(t$95$1 * d + b), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -5.5 \cdot 10^{-154}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 6.2 \cdot 10^{+51}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -1.25000000000000006e116

    1. Initial program 38.5%

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

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

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

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

        \[\leadsto \frac{\left(-1 \cdot a\right) \cdot d}{c \cdot c} + \frac{b}{c} \]
      4. times-fracN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{-a}{c}, \frac{d}{\color{blue}{c}}, \frac{b}{c}\right) \]
      10. lower-/.f6484.7

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

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

    if -1.25000000000000006e116 < c < -5.50000000000000002e-154 or 1.65e-143 < c < 6.20000000000000022e51

    1. Initial program 77.0%

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

    if -5.50000000000000002e-154 < c < 1.65e-143

    1. Initial program 68.5%

      \[\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.f6492.5

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

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

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

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

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

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

        \[\leadsto \frac{\frac{c}{d} \cdot b - a}{d} \]
      5. lift-/.f6492.5

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

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

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

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

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

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

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

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

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

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

    if 6.20000000000000022e51 < c

    1. Initial program 43.3%

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

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

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

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

        \[\leadsto \frac{\left(-1 \cdot a\right) \cdot d}{c \cdot c} + \frac{b}{c} \]
      4. times-fracN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{-a}{c}, \frac{d}{\color{blue}{c}}, \frac{b}{c}\right) \]
      10. lower-/.f6479.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-a}{c}, \frac{d}{c}, \frac{b}{c}\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(-1 \cdot \frac{a}{c}\right) \cdot d}{c} + \frac{\color{blue}{b}}{c} \]
      9. div-add-revN/A

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{neg}\left(\frac{a}{c}\right), d, b\right)}{c} \]
      13. distribute-frac-negN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{\mathsf{neg}\left(a\right)}{c}, d, b\right)}{c} \]
      15. lift-neg.f6479.9

        \[\leadsto \frac{\mathsf{fma}\left(\frac{-a}{c}, d, b\right)}{c} \]
    7. Applied rewrites79.9%

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

Alternative 2: 82.9% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;c \leq -5.5 \cdot 10^{-154}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 6.2 \cdot 10^{+51}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -1.25000000000000006e116

    1. Initial program 38.5%

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

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

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

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

        \[\leadsto \frac{\left(-1 \cdot a\right) \cdot d}{c \cdot c} + \frac{b}{c} \]
      4. times-fracN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{-a}{c}, \frac{d}{\color{blue}{c}}, \frac{b}{c}\right) \]
      10. lower-/.f6484.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-a}{c}, \frac{d}{c}, \frac{b}{c}\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

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

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

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

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

        \[\leadsto \frac{\mathsf{neg}\left(a\right)}{c} \cdot \frac{d}{c} + \frac{b}{c} \]
      6. associate-*l/N/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(a\right)\right) \cdot \frac{d}{c}}{c} + \frac{\color{blue}{b}}{c} \]
      7. div-add-revN/A

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c} \]
      11. lift-/.f6484.6

        \[\leadsto \frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c} \]
    7. Applied rewrites84.6%

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

    if -1.25000000000000006e116 < c < -5.50000000000000002e-154 or 1.65e-143 < c < 6.20000000000000022e51

    1. Initial program 77.0%

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

    if -5.50000000000000002e-154 < c < 1.65e-143

    1. Initial program 68.5%

      \[\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.f6492.5

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

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

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

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

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

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

        \[\leadsto \frac{\frac{c}{d} \cdot b - a}{d} \]
      5. lift-/.f6492.5

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

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

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

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

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

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

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

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

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

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

    if 6.20000000000000022e51 < c

    1. Initial program 43.3%

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

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

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

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

        \[\leadsto \frac{\left(-1 \cdot a\right) \cdot d}{c \cdot c} + \frac{b}{c} \]
      4. times-fracN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{-a}{c}, \frac{d}{\color{blue}{c}}, \frac{b}{c}\right) \]
      10. lower-/.f6479.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-a}{c}, \frac{d}{c}, \frac{b}{c}\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(-1 \cdot \frac{a}{c}\right) \cdot d}{c} + \frac{\color{blue}{b}}{c} \]
      9. div-add-revN/A

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{neg}\left(\frac{a}{c}\right), d, b\right)}{c} \]
      13. distribute-frac-negN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{\mathsf{neg}\left(a\right)}{c}, d, b\right)}{c} \]
      15. lift-neg.f6479.9

        \[\leadsto \frac{\mathsf{fma}\left(\frac{-a}{c}, d, b\right)}{c} \]
    7. Applied rewrites79.9%

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

Alternative 3: 77.3% accurate, 0.9× speedup?

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

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

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

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


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

    1. Initial program 41.2%

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

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

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

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

        \[\leadsto \frac{\left(-1 \cdot a\right) \cdot d}{c \cdot c} + \frac{b}{c} \]
      4. times-fracN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{-a}{c}, \frac{d}{\color{blue}{c}}, \frac{b}{c}\right) \]
      10. lower-/.f6483.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-a}{c}, \frac{d}{c}, \frac{b}{c}\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

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

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

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

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

        \[\leadsto \frac{\mathsf{neg}\left(a\right)}{c} \cdot \frac{d}{c} + \frac{b}{c} \]
      6. associate-*l/N/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(a\right)\right) \cdot \frac{d}{c}}{c} + \frac{\color{blue}{b}}{c} \]
      7. div-add-revN/A

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c} \]
      11. lift-/.f6483.5

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

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

    if -1.95e98 < c < 7.99999999999999977e-28

    1. Initial program 73.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.f6477.3

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

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

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

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

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

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

        \[\leadsto \frac{\frac{c}{d} \cdot b - a}{d} \]
      5. lift-/.f6477.3

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

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

    if 7.99999999999999977e-28 < c

    1. Initial program 51.3%

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

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

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

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

        \[\leadsto \frac{\left(-1 \cdot a\right) \cdot d}{c \cdot c} + \frac{b}{c} \]
      4. times-fracN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{-a}{c}, \frac{d}{\color{blue}{c}}, \frac{b}{c}\right) \]
      10. lower-/.f6473.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-a}{c}, \frac{d}{c}, \frac{b}{c}\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(-1 \cdot \frac{a}{c}\right) \cdot d}{c} + \frac{\color{blue}{b}}{c} \]
      9. div-add-revN/A

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\mathsf{neg}\left(\frac{a}{c}\right), d, b\right)}{c} \]
      13. distribute-frac-negN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{\mathsf{neg}\left(a\right)}{c}, d, b\right)}{c} \]
      15. lift-neg.f6473.5

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

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

Alternative 4: 77.0% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.95e98 or 7.99999999999999977e-28 < c

    1. Initial program 47.5%

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

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

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

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

        \[\leadsto \frac{\left(-1 \cdot a\right) \cdot d}{c \cdot c} + \frac{b}{c} \]
      4. times-fracN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{-a}{c}, \frac{d}{\color{blue}{c}}, \frac{b}{c}\right) \]
      10. lower-/.f6477.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-a}{c}, \frac{d}{c}, \frac{b}{c}\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

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

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

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

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

        \[\leadsto \frac{\mathsf{neg}\left(a\right)}{c} \cdot \frac{d}{c} + \frac{b}{c} \]
      6. associate-*l/N/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(a\right)\right) \cdot \frac{d}{c}}{c} + \frac{\color{blue}{b}}{c} \]
      7. div-add-revN/A

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(-a, \frac{d}{c}, b\right)}{c} \]
      11. lift-/.f6476.7

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

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

    if -1.95e98 < c < 7.99999999999999977e-28

    1. Initial program 73.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.f6477.3

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

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

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

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

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

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

        \[\leadsto \frac{\frac{c}{d} \cdot b - a}{d} \]
      5. lift-/.f6477.3

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

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

Alternative 5: 77.4% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.1e-5

    1. Initial program 51.6%

      \[\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.f6477.7

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

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

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

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

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

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

        \[\leadsto \frac{\frac{c}{d} \cdot b - a}{d} \]
      5. lift-/.f6477.7

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

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

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

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

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

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

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

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

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

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

    if -1.1e-5 < d < 3.6000000000000001e-15

    1. Initial program 74.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 + -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-*.f6480.5

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

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

    if 3.6000000000000001e-15 < d

    1. Initial program 49.0%

      \[\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.f6475.4

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

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

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

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

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

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

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

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

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

Alternative 6: 72.8% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -4.20000000000000024e58 or 1.38e-27 < c

    1. Initial program 49.0%

      \[\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.1

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

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

    if -4.20000000000000024e58 < c < 1.38e-27

    1. Initial program 73.3%

      \[\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.f6479.4

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 72.6% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3.10000000000000019e98 or 1.38e-27 < c

    1. Initial program 47.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-/.f6466.4

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

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

    if -3.10000000000000019e98 < c < 1.38e-27

    1. Initial program 73.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.f6477.2

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

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

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

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

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

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

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

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

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

Alternative 8: 65.5% accurate, 0.9× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -4.4999999999999997e143 or 7.99999999999999977e-28 < c

    1. Initial program 46.0%

      \[\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-/.f6466.9

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

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

    if -4.4999999999999997e143 < c < -3.19999999999999993e-119

    1. Initial program 74.6%

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

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

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

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

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

        \[\leadsto b \cdot \frac{c}{{d}^{2} + \color{blue}{{c}^{2}}} \]
      5. pow2N/A

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

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

        \[\leadsto b \cdot \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \]
      8. lift-*.f6455.1

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

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

    if -3.19999999999999993e-119 < c < 7.99999999999999977e-28

    1. Initial program 71.4%

      \[\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.f6469.8

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

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

Alternative 9: 64.1% accurate, 1.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.1e58 or 7.99999999999999977e-28 < c

    1. Initial program 49.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-/.f6465.1

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

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

    if -1.1e58 < c < 7.99999999999999977e-28

    1. Initial program 73.3%

      \[\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.f6463.2

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

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

Alternative 10: 41.7% accurate, 3.2× speedup?

\[\begin{array}{l} \\ \frac{b}{c} \end{array} \]
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
	return b / c;
}
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.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-/.f6441.7

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

    \[\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 2025087 
(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))))