FastMath dist4

Percentage Accurate: 87.1% → 95.7%
Time: 2.8s
Alternatives: 11
Speedup: 1.3×

Specification

?
\[\begin{array}{l} \\ \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
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(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    code = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
def code(d1, d2, d3, d4):
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
function code(d1, d2, d3, d4)
	return Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1))
end
function tmp = code(d1, d2, d3, d4)
	tmp = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\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 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: 87.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
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(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    code = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
def code(d1, d2, d3, d4):
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
function code(d1, d2, d3, d4)
	return Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1))
end
function tmp = code(d1, d2, d3, d4)
	tmp = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\end{array}

Alternative 1: 95.7% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(d1, d4 - d3, \left(-d1\right) \cdot d1\right)\right) \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (fma d2 d1 (fma d1 (- d4 d3) (* (- d1) d1))))
double code(double d1, double d2, double d3, double d4) {
	return fma(d2, d1, fma(d1, (d4 - d3), (-d1 * d1)));
}
function code(d1, d2, d3, d4)
	return fma(d2, d1, fma(d1, Float64(d4 - d3), Float64(Float64(-d1) * d1)))
end
code[d1_, d2_, d3_, d4_] := N[(d2 * d1 + N[(d1 * N[(d4 - d3), $MachinePrecision] + N[((-d1) * d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(d2, d1, \mathsf{fma}\left(d1, d4 - d3, \left(-d1\right) \cdot d1\right)\right)
\end{array}
Derivation
  1. Initial program 87.1%

    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
  2. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1} \]
    2. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} - d1 \cdot d1 \]
    3. lift--.f64N/A

      \[\leadsto \left(\color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right)} + d4 \cdot d1\right) - d1 \cdot d1 \]
    4. lift-*.f64N/A

      \[\leadsto \left(\left(\color{blue}{d1 \cdot d2} - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    5. lift-*.f64N/A

      \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    6. fp-cancel-sub-sign-invN/A

      \[\leadsto \left(\color{blue}{\left(d1 \cdot d2 + \left(\mathsf{neg}\left(d1\right)\right) \cdot d3\right)} + d4 \cdot d1\right) - d1 \cdot d1 \]
    7. mul-1-negN/A

      \[\leadsto \left(\left(d1 \cdot d2 + \color{blue}{\left(-1 \cdot d1\right)} \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    8. associate-*r*N/A

      \[\leadsto \left(\left(d1 \cdot d2 + \color{blue}{-1 \cdot \left(d1 \cdot d3\right)}\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    9. +-commutativeN/A

      \[\leadsto \left(\color{blue}{\left(-1 \cdot \left(d1 \cdot d3\right) + d1 \cdot d2\right)} + d4 \cdot d1\right) - d1 \cdot d1 \]
    10. lift-*.f64N/A

      \[\leadsto \left(\left(-1 \cdot \left(d1 \cdot d3\right) + d1 \cdot d2\right) + \color{blue}{d4 \cdot d1}\right) - d1 \cdot d1 \]
    11. *-commutativeN/A

      \[\leadsto \left(\left(-1 \cdot \left(d1 \cdot d3\right) + d1 \cdot d2\right) + \color{blue}{d1 \cdot d4}\right) - d1 \cdot d1 \]
    12. associate-+r+N/A

      \[\leadsto \color{blue}{\left(-1 \cdot \left(d1 \cdot d3\right) + \left(d1 \cdot d2 + d1 \cdot d4\right)\right)} - d1 \cdot d1 \]
    13. lift-*.f64N/A

      \[\leadsto \left(-1 \cdot \left(d1 \cdot d3\right) + \left(d1 \cdot d2 + d1 \cdot d4\right)\right) - \color{blue}{d1 \cdot d1} \]
    14. pow2N/A

      \[\leadsto \left(-1 \cdot \left(d1 \cdot d3\right) + \left(d1 \cdot d2 + d1 \cdot d4\right)\right) - \color{blue}{{d1}^{2}} \]
    15. +-commutativeN/A

      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 + d1 \cdot d4\right) + -1 \cdot \left(d1 \cdot d3\right)\right)} - {d1}^{2} \]
    16. associate-*r*N/A

      \[\leadsto \left(\left(d1 \cdot d2 + d1 \cdot d4\right) + \color{blue}{\left(-1 \cdot d1\right) \cdot d3}\right) - {d1}^{2} \]
    17. mul-1-negN/A

      \[\leadsto \left(\left(d1 \cdot d2 + d1 \cdot d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)} \cdot d3\right) - {d1}^{2} \]
    18. fp-cancel-sub-sign-invN/A

      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 + d1 \cdot d4\right) - d1 \cdot d3\right)} - {d1}^{2} \]
    19. associate--r+N/A

      \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
    20. associate--l+N/A

      \[\leadsto \color{blue}{d1 \cdot d2 + \left(d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)\right)} \]
  3. Applied rewrites95.7%

    \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, \mathsf{fma}\left(d1, d4 - d3, \left(-d1\right) \cdot d1\right)\right)} \]
  4. Add Preprocessing

Alternative 2: 86.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq -1 \cdot 10^{+112}:\\ \;\;\;\;\left(d2 \cdot d1 + d4 \cdot d1\right) - d1 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)) -1e+112)
   (- (+ (* d2 d1) (* d4 d1)) (* d1 d1))
   (* (- (+ d4 d2) d3) d1)))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= -1e+112) {
		tmp = ((d2 * d1) + (d4 * d1)) - (d1 * d1);
	} else {
		tmp = ((d4 + d2) - d3) * d1;
	}
	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(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= (-1d+112)) then
        tmp = ((d2 * d1) + (d4 * d1)) - (d1 * d1)
    else
        tmp = ((d4 + d2) - d3) * d1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= -1e+112) {
		tmp = ((d2 * d1) + (d4 * d1)) - (d1 * d1);
	} else {
		tmp = ((d4 + d2) - d3) * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if ((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= -1e+112:
		tmp = ((d2 * d1) + (d4 * d1)) - (d1 * d1)
	else:
		tmp = ((d4 + d2) - d3) * d1
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1)) <= -1e+112)
		tmp = Float64(Float64(Float64(d2 * d1) + Float64(d4 * d1)) - Float64(d1 * d1));
	else
		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= -1e+112)
		tmp = ((d2 * d1) + (d4 * d1)) - (d1 * d1);
	else
		tmp = ((d4 + d2) - d3) * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision], -1e+112], N[(N[(N[(d2 * d1), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq -1 \cdot 10^{+112}:\\
\;\;\;\;\left(d2 \cdot d1 + d4 \cdot d1\right) - d1 \cdot d1\\

\mathbf{else}:\\
\;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) < -9.9999999999999993e111

    1. Initial program 100.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d2 around inf

      \[\leadsto \left(\color{blue}{d1 \cdot d2} + d4 \cdot d1\right) - d1 \cdot d1 \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(d2 \cdot \color{blue}{d1} + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. lower-*.f6486.0

        \[\leadsto \left(d2 \cdot \color{blue}{d1} + d4 \cdot d1\right) - d1 \cdot d1 \]
    4. Applied rewrites86.0%

      \[\leadsto \left(\color{blue}{d2 \cdot d1} + d4 \cdot d1\right) - d1 \cdot d1 \]

    if -9.9999999999999993e111 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1))

    1. Initial program 80.8%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d1 around 0

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      2. lower-*.f64N/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      3. lower--.f64N/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot d1 \]
      4. +-commutativeN/A

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. lower-+.f6487.0

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
    4. Applied rewrites87.0%

      \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d3\right) \cdot d1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 83.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq -1 \cdot 10^{+161}:\\ \;\;\;\;d2 \cdot d1 - d1 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)) -1e+161)
   (- (* d2 d1) (* d1 d1))
   (* (- (+ d4 d2) d3) d1)))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= -1e+161) {
		tmp = (d2 * d1) - (d1 * d1);
	} else {
		tmp = ((d4 + d2) - d3) * d1;
	}
	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(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= (-1d+161)) then
        tmp = (d2 * d1) - (d1 * d1)
    else
        tmp = ((d4 + d2) - d3) * d1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= -1e+161) {
		tmp = (d2 * d1) - (d1 * d1);
	} else {
		tmp = ((d4 + d2) - d3) * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if ((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= -1e+161:
		tmp = (d2 * d1) - (d1 * d1)
	else:
		tmp = ((d4 + d2) - d3) * d1
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1)) <= -1e+161)
		tmp = Float64(Float64(d2 * d1) - Float64(d1 * d1));
	else
		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= -1e+161)
		tmp = (d2 * d1) - (d1 * d1);
	else
		tmp = ((d4 + d2) - d3) * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision], -1e+161], N[(N[(d2 * d1), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq -1 \cdot 10^{+161}:\\
\;\;\;\;d2 \cdot d1 - d1 \cdot d1\\

\mathbf{else}:\\
\;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) < -1e161

    1. Initial program 100.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d2 around inf

      \[\leadsto \color{blue}{d1 \cdot d2} - d1 \cdot d1 \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto d2 \cdot \color{blue}{d1} - d1 \cdot d1 \]
      2. lower-*.f6474.7

        \[\leadsto d2 \cdot \color{blue}{d1} - d1 \cdot d1 \]
    4. Applied rewrites74.7%

      \[\leadsto \color{blue}{d2 \cdot d1} - d1 \cdot d1 \]

    if -1e161 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1))

    1. Initial program 81.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d1 around 0

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      2. lower-*.f64N/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      3. lower--.f64N/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot d1 \]
      4. +-commutativeN/A

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. lower-+.f6486.4

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
    4. Applied rewrites86.4%

      \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d3\right) \cdot d1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 65.0% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(-d3\right) \cdot d1\\ t_1 := \left(d4 + d2\right) \cdot d1\\ \mathbf{if}\;d3 \leq -1.05 \cdot 10^{+166}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq -9 \cdot 10^{-221}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d3 \leq -1.9 \cdot 10^{-304}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{elif}\;d3 \leq 8.8 \cdot 10^{+82}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* (- d3) d1)) (t_1 (* (+ d4 d2) d1)))
   (if (<= d3 -1.05e+166)
     t_0
     (if (<= d3 -9e-221)
       t_1
       (if (<= d3 -1.9e-304) (* (- d1) d1) (if (<= d3 8.8e+82) t_1 t_0))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = -d3 * d1;
	double t_1 = (d4 + d2) * d1;
	double tmp;
	if (d3 <= -1.05e+166) {
		tmp = t_0;
	} else if (d3 <= -9e-221) {
		tmp = t_1;
	} else if (d3 <= -1.9e-304) {
		tmp = -d1 * d1;
	} else if (d3 <= 8.8e+82) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	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(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = -d3 * d1
    t_1 = (d4 + d2) * d1
    if (d3 <= (-1.05d+166)) then
        tmp = t_0
    else if (d3 <= (-9d-221)) then
        tmp = t_1
    else if (d3 <= (-1.9d-304)) then
        tmp = -d1 * d1
    else if (d3 <= 8.8d+82) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = -d3 * d1;
	double t_1 = (d4 + d2) * d1;
	double tmp;
	if (d3 <= -1.05e+166) {
		tmp = t_0;
	} else if (d3 <= -9e-221) {
		tmp = t_1;
	} else if (d3 <= -1.9e-304) {
		tmp = -d1 * d1;
	} else if (d3 <= 8.8e+82) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = -d3 * d1
	t_1 = (d4 + d2) * d1
	tmp = 0
	if d3 <= -1.05e+166:
		tmp = t_0
	elif d3 <= -9e-221:
		tmp = t_1
	elif d3 <= -1.9e-304:
		tmp = -d1 * d1
	elif d3 <= 8.8e+82:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(Float64(-d3) * d1)
	t_1 = Float64(Float64(d4 + d2) * d1)
	tmp = 0.0
	if (d3 <= -1.05e+166)
		tmp = t_0;
	elseif (d3 <= -9e-221)
		tmp = t_1;
	elseif (d3 <= -1.9e-304)
		tmp = Float64(Float64(-d1) * d1);
	elseif (d3 <= 8.8e+82)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = -d3 * d1;
	t_1 = (d4 + d2) * d1;
	tmp = 0.0;
	if (d3 <= -1.05e+166)
		tmp = t_0;
	elseif (d3 <= -9e-221)
		tmp = t_1;
	elseif (d3 <= -1.9e-304)
		tmp = -d1 * d1;
	elseif (d3 <= 8.8e+82)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[((-d3) * d1), $MachinePrecision]}, Block[{t$95$1 = N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d3, -1.05e+166], t$95$0, If[LessEqual[d3, -9e-221], t$95$1, If[LessEqual[d3, -1.9e-304], N[((-d1) * d1), $MachinePrecision], If[LessEqual[d3, 8.8e+82], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(-d3\right) \cdot d1\\
t_1 := \left(d4 + d2\right) \cdot d1\\
\mathbf{if}\;d3 \leq -1.05 \cdot 10^{+166}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d3 \leq -9 \cdot 10^{-221}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d3 \leq -1.9 \cdot 10^{-304}:\\
\;\;\;\;\left(-d1\right) \cdot d1\\

\mathbf{elif}\;d3 \leq 8.8 \cdot 10^{+82}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -1.05e166 or 8.8000000000000005e82 < d3

    1. Initial program 80.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d3 around inf

      \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
    3. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(d1 \cdot d3\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(d3 \cdot d1\right) \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(d3\right)\right) \cdot \color{blue}{d1} \]
      4. mul-1-negN/A

        \[\leadsto \left(-1 \cdot d3\right) \cdot d1 \]
      5. lower-*.f64N/A

        \[\leadsto \left(-1 \cdot d3\right) \cdot \color{blue}{d1} \]
      6. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(d3\right)\right) \cdot d1 \]
      7. lower-neg.f6470.0

        \[\leadsto \left(-d3\right) \cdot d1 \]
    4. Applied rewrites70.0%

      \[\leadsto \color{blue}{\left(-d3\right) \cdot d1} \]

    if -1.05e166 < d3 < -9.00000000000000052e-221 or -1.8999999999999998e-304 < d3 < 8.8000000000000005e82

    1. Initial program 89.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d1 around 0

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      2. lower-*.f64N/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      3. lower--.f64N/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot d1 \]
      4. +-commutativeN/A

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. lower-+.f6475.2

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
    4. Applied rewrites75.2%

      \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d3\right) \cdot d1} \]
    5. Taylor expanded in d3 around 0

      \[\leadsto \left(d2 + d4\right) \cdot d1 \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \left(d4 + d2\right) \cdot d1 \]
      2. lift-+.f6465.4

        \[\leadsto \left(d4 + d2\right) \cdot d1 \]
    7. Applied rewrites65.4%

      \[\leadsto \left(d4 + d2\right) \cdot d1 \]

    if -9.00000000000000052e-221 < d3 < -1.8999999999999998e-304

    1. Initial program 92.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d1 around inf

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    3. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
      2. pow2N/A

        \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot \color{blue}{d1} \]
      4. mul-1-negN/A

        \[\leadsto \left(-1 \cdot d1\right) \cdot d1 \]
      5. lower-*.f64N/A

        \[\leadsto \left(-1 \cdot d1\right) \cdot \color{blue}{d1} \]
      6. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot d1 \]
      7. lower-neg.f6441.7

        \[\leadsto \left(-d1\right) \cdot d1 \]
    4. Applied rewrites41.7%

      \[\leadsto \color{blue}{\left(-d1\right) \cdot d1} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 38.4% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -6.5 \cdot 10^{+142}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -3.35 \cdot 10^{-32}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{elif}\;d2 \leq 6.7 \cdot 10^{-140}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -6.5e+142)
   (* d2 d1)
   (if (<= d2 -3.35e-32)
     (* (- d3) d1)
     (if (<= d2 6.7e-140) (* (- d1) d1) (* d4 d1)))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -6.5e+142) {
		tmp = d2 * d1;
	} else if (d2 <= -3.35e-32) {
		tmp = -d3 * d1;
	} else if (d2 <= 6.7e-140) {
		tmp = -d1 * d1;
	} else {
		tmp = d4 * d1;
	}
	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(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if (d2 <= (-6.5d+142)) then
        tmp = d2 * d1
    else if (d2 <= (-3.35d-32)) then
        tmp = -d3 * d1
    else if (d2 <= 6.7d-140) then
        tmp = -d1 * d1
    else
        tmp = d4 * d1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -6.5e+142) {
		tmp = d2 * d1;
	} else if (d2 <= -3.35e-32) {
		tmp = -d3 * d1;
	} else if (d2 <= 6.7e-140) {
		tmp = -d1 * d1;
	} else {
		tmp = d4 * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -6.5e+142:
		tmp = d2 * d1
	elif d2 <= -3.35e-32:
		tmp = -d3 * d1
	elif d2 <= 6.7e-140:
		tmp = -d1 * d1
	else:
		tmp = d4 * d1
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -6.5e+142)
		tmp = Float64(d2 * d1);
	elseif (d2 <= -3.35e-32)
		tmp = Float64(Float64(-d3) * d1);
	elseif (d2 <= 6.7e-140)
		tmp = Float64(Float64(-d1) * d1);
	else
		tmp = Float64(d4 * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -6.5e+142)
		tmp = d2 * d1;
	elseif (d2 <= -3.35e-32)
		tmp = -d3 * d1;
	elseif (d2 <= 6.7e-140)
		tmp = -d1 * d1;
	else
		tmp = d4 * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -6.5e+142], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, -3.35e-32], N[((-d3) * d1), $MachinePrecision], If[LessEqual[d2, 6.7e-140], N[((-d1) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -6.5 \cdot 10^{+142}:\\
\;\;\;\;d2 \cdot d1\\

\mathbf{elif}\;d2 \leq -3.35 \cdot 10^{-32}:\\
\;\;\;\;\left(-d3\right) \cdot d1\\

\mathbf{elif}\;d2 \leq 6.7 \cdot 10^{-140}:\\
\;\;\;\;\left(-d1\right) \cdot d1\\

\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d2 < -6.4999999999999997e142

    1. Initial program 82.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d2 around inf

      \[\leadsto \color{blue}{d1 \cdot d2} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto d2 \cdot \color{blue}{d1} \]
      2. lower-*.f6473.0

        \[\leadsto d2 \cdot \color{blue}{d1} \]
    4. Applied rewrites73.0%

      \[\leadsto \color{blue}{d2 \cdot d1} \]

    if -6.4999999999999997e142 < d2 < -3.35e-32

    1. Initial program 88.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d3 around inf

      \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
    3. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(d1 \cdot d3\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(d3 \cdot d1\right) \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(d3\right)\right) \cdot \color{blue}{d1} \]
      4. mul-1-negN/A

        \[\leadsto \left(-1 \cdot d3\right) \cdot d1 \]
      5. lower-*.f64N/A

        \[\leadsto \left(-1 \cdot d3\right) \cdot \color{blue}{d1} \]
      6. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(d3\right)\right) \cdot d1 \]
      7. lower-neg.f6430.5

        \[\leadsto \left(-d3\right) \cdot d1 \]
    4. Applied rewrites30.5%

      \[\leadsto \color{blue}{\left(-d3\right) \cdot d1} \]

    if -3.35e-32 < d2 < 6.7e-140

    1. Initial program 89.8%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d1 around inf

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    3. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
      2. pow2N/A

        \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot \color{blue}{d1} \]
      4. mul-1-negN/A

        \[\leadsto \left(-1 \cdot d1\right) \cdot d1 \]
      5. lower-*.f64N/A

        \[\leadsto \left(-1 \cdot d1\right) \cdot \color{blue}{d1} \]
      6. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot d1 \]
      7. lower-neg.f6440.2

        \[\leadsto \left(-d1\right) \cdot d1 \]
    4. Applied rewrites40.2%

      \[\leadsto \color{blue}{\left(-d1\right) \cdot d1} \]

    if 6.7e-140 < d2

    1. Initial program 85.6%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d4 around inf

      \[\leadsto \color{blue}{d1 \cdot d4} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto d4 \cdot \color{blue}{d1} \]
      2. lift-*.f6427.3

        \[\leadsto d4 \cdot \color{blue}{d1} \]
    4. Applied rewrites27.3%

      \[\leadsto \color{blue}{d4 \cdot d1} \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 6: 85.4% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(-d1\right) \cdot d1\\ \mathbf{if}\;d1 \leq -1.46 \cdot 10^{+91}:\\ \;\;\;\;\mathsf{fma}\left(d2, d1, t\_0\right)\\ \mathbf{elif}\;d1 \leq 4.4 \cdot 10^{+264}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* (- d1) d1)))
   (if (<= d1 -1.46e+91)
     (fma d2 d1 t_0)
     (if (<= d1 4.4e+264) (* (- (+ d4 d2) d3) d1) t_0))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = -d1 * d1;
	double tmp;
	if (d1 <= -1.46e+91) {
		tmp = fma(d2, d1, t_0);
	} else if (d1 <= 4.4e+264) {
		tmp = ((d4 + d2) - d3) * d1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(d1, d2, d3, d4)
	t_0 = Float64(Float64(-d1) * d1)
	tmp = 0.0
	if (d1 <= -1.46e+91)
		tmp = fma(d2, d1, t_0);
	elseif (d1 <= 4.4e+264)
		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
	else
		tmp = t_0;
	end
	return tmp
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[((-d1) * d1), $MachinePrecision]}, If[LessEqual[d1, -1.46e+91], N[(d2 * d1 + t$95$0), $MachinePrecision], If[LessEqual[d1, 4.4e+264], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(-d1\right) \cdot d1\\
\mathbf{if}\;d1 \leq -1.46 \cdot 10^{+91}:\\
\;\;\;\;\mathsf{fma}\left(d2, d1, t\_0\right)\\

\mathbf{elif}\;d1 \leq 4.4 \cdot 10^{+264}:\\
\;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d1 < -1.45999999999999999e91

    1. Initial program 64.5%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1} \]
      2. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} - d1 \cdot d1 \]
      3. lift--.f64N/A

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right)} + d4 \cdot d1\right) - d1 \cdot d1 \]
      4. lift-*.f64N/A

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d2} - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      5. lift-*.f64N/A

        \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      6. fp-cancel-sub-sign-invN/A

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d2 + \left(\mathsf{neg}\left(d1\right)\right) \cdot d3\right)} + d4 \cdot d1\right) - d1 \cdot d1 \]
      7. mul-1-negN/A

        \[\leadsto \left(\left(d1 \cdot d2 + \color{blue}{\left(-1 \cdot d1\right)} \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      8. associate-*r*N/A

        \[\leadsto \left(\left(d1 \cdot d2 + \color{blue}{-1 \cdot \left(d1 \cdot d3\right)}\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      9. +-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(-1 \cdot \left(d1 \cdot d3\right) + d1 \cdot d2\right)} + d4 \cdot d1\right) - d1 \cdot d1 \]
      10. lift-*.f64N/A

        \[\leadsto \left(\left(-1 \cdot \left(d1 \cdot d3\right) + d1 \cdot d2\right) + \color{blue}{d4 \cdot d1}\right) - d1 \cdot d1 \]
      11. *-commutativeN/A

        \[\leadsto \left(\left(-1 \cdot \left(d1 \cdot d3\right) + d1 \cdot d2\right) + \color{blue}{d1 \cdot d4}\right) - d1 \cdot d1 \]
      12. associate-+r+N/A

        \[\leadsto \color{blue}{\left(-1 \cdot \left(d1 \cdot d3\right) + \left(d1 \cdot d2 + d1 \cdot d4\right)\right)} - d1 \cdot d1 \]
      13. lift-*.f64N/A

        \[\leadsto \left(-1 \cdot \left(d1 \cdot d3\right) + \left(d1 \cdot d2 + d1 \cdot d4\right)\right) - \color{blue}{d1 \cdot d1} \]
      14. pow2N/A

        \[\leadsto \left(-1 \cdot \left(d1 \cdot d3\right) + \left(d1 \cdot d2 + d1 \cdot d4\right)\right) - \color{blue}{{d1}^{2}} \]
      15. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 + d1 \cdot d4\right) + -1 \cdot \left(d1 \cdot d3\right)\right)} - {d1}^{2} \]
      16. associate-*r*N/A

        \[\leadsto \left(\left(d1 \cdot d2 + d1 \cdot d4\right) + \color{blue}{\left(-1 \cdot d1\right) \cdot d3}\right) - {d1}^{2} \]
      17. mul-1-negN/A

        \[\leadsto \left(\left(d1 \cdot d2 + d1 \cdot d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)} \cdot d3\right) - {d1}^{2} \]
      18. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 + d1 \cdot d4\right) - d1 \cdot d3\right)} - {d1}^{2} \]
      19. associate--r+N/A

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
      20. associate--l+N/A

        \[\leadsto \color{blue}{d1 \cdot d2 + \left(d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)\right)} \]
    3. Applied rewrites87.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, \mathsf{fma}\left(d1, d4 - d3, \left(-d1\right) \cdot d1\right)\right)} \]
    4. Taylor expanded in d1 around inf

      \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{-1 \cdot {d1}^{2}}\right) \]
    5. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{neg}\left({d1}^{2}\right)\right) \]
      2. pow2N/A

        \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{neg}\left(d1 \cdot d1\right)\right) \]
      3. distribute-lft-neg-outN/A

        \[\leadsto \mathsf{fma}\left(d2, d1, \left(\mathsf{neg}\left(d1\right)\right) \cdot \color{blue}{d1}\right) \]
      4. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(d2, d1, \left(\mathsf{neg}\left(d1\right)\right) \cdot \color{blue}{d1}\right) \]
      5. lift-neg.f6477.3

        \[\leadsto \mathsf{fma}\left(d2, d1, \left(-d1\right) \cdot d1\right) \]
    6. Applied rewrites77.3%

      \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{\left(-d1\right) \cdot d1}\right) \]

    if -1.45999999999999999e91 < d1 < 4.4e264

    1. Initial program 94.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d1 around 0

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      2. lower-*.f64N/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      3. lower--.f64N/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot d1 \]
      4. +-commutativeN/A

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. lower-+.f6486.9

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
    4. Applied rewrites86.9%

      \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d3\right) \cdot d1} \]

    if 4.4e264 < d1

    1. Initial program 39.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d1 around inf

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    3. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
      2. pow2N/A

        \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot \color{blue}{d1} \]
      4. mul-1-negN/A

        \[\leadsto \left(-1 \cdot d1\right) \cdot d1 \]
      5. lower-*.f64N/A

        \[\leadsto \left(-1 \cdot d1\right) \cdot \color{blue}{d1} \]
      6. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot d1 \]
      7. lower-neg.f6492.4

        \[\leadsto \left(-d1\right) \cdot d1 \]
    4. Applied rewrites92.4%

      \[\leadsto \color{blue}{\left(-d1\right) \cdot d1} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 7: 84.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(-d1\right) \cdot d1\\ \mathbf{if}\;d1 \leq -2.05 \cdot 10^{+195}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d1 \leq 4.4 \cdot 10^{+264}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* (- d1) d1)))
   (if (<= d1 -2.05e+195)
     t_0
     (if (<= d1 4.4e+264) (* (- (+ d4 d2) d3) d1) t_0))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = -d1 * d1;
	double tmp;
	if (d1 <= -2.05e+195) {
		tmp = t_0;
	} else if (d1 <= 4.4e+264) {
		tmp = ((d4 + d2) - d3) * d1;
	} else {
		tmp = t_0;
	}
	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(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: tmp
    t_0 = -d1 * d1
    if (d1 <= (-2.05d+195)) then
        tmp = t_0
    else if (d1 <= 4.4d+264) then
        tmp = ((d4 + d2) - d3) * d1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = -d1 * d1;
	double tmp;
	if (d1 <= -2.05e+195) {
		tmp = t_0;
	} else if (d1 <= 4.4e+264) {
		tmp = ((d4 + d2) - d3) * d1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = -d1 * d1
	tmp = 0
	if d1 <= -2.05e+195:
		tmp = t_0
	elif d1 <= 4.4e+264:
		tmp = ((d4 + d2) - d3) * d1
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(Float64(-d1) * d1)
	tmp = 0.0
	if (d1 <= -2.05e+195)
		tmp = t_0;
	elseif (d1 <= 4.4e+264)
		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = -d1 * d1;
	tmp = 0.0;
	if (d1 <= -2.05e+195)
		tmp = t_0;
	elseif (d1 <= 4.4e+264)
		tmp = ((d4 + d2) - d3) * d1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[((-d1) * d1), $MachinePrecision]}, If[LessEqual[d1, -2.05e+195], t$95$0, If[LessEqual[d1, 4.4e+264], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(-d1\right) \cdot d1\\
\mathbf{if}\;d1 \leq -2.05 \cdot 10^{+195}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d1 \leq 4.4 \cdot 10^{+264}:\\
\;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -2.05e195 or 4.4e264 < d1

    1. Initial program 46.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d1 around inf

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    3. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
      2. pow2N/A

        \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot \color{blue}{d1} \]
      4. mul-1-negN/A

        \[\leadsto \left(-1 \cdot d1\right) \cdot d1 \]
      5. lower-*.f64N/A

        \[\leadsto \left(-1 \cdot d1\right) \cdot \color{blue}{d1} \]
      6. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot d1 \]
      7. lower-neg.f6489.0

        \[\leadsto \left(-d1\right) \cdot d1 \]
    4. Applied rewrites89.0%

      \[\leadsto \color{blue}{\left(-d1\right) \cdot d1} \]

    if -2.05e195 < d1 < 4.4e264

    1. Initial program 92.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d1 around 0

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      2. lower-*.f64N/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      3. lower--.f64N/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot d1 \]
      4. +-commutativeN/A

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. lower-+.f6484.3

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
    4. Applied rewrites84.3%

      \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d3\right) \cdot d1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 38.6% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.8 \cdot 10^{+139}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq 6.7 \cdot 10^{-140}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -1.8e+139)
   (* d2 d1)
   (if (<= d2 6.7e-140) (* (- d1) d1) (* d4 d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -1.8e+139) {
		tmp = d2 * d1;
	} else if (d2 <= 6.7e-140) {
		tmp = -d1 * d1;
	} else {
		tmp = d4 * d1;
	}
	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(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if (d2 <= (-1.8d+139)) then
        tmp = d2 * d1
    else if (d2 <= 6.7d-140) then
        tmp = -d1 * d1
    else
        tmp = d4 * d1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -1.8e+139) {
		tmp = d2 * d1;
	} else if (d2 <= 6.7e-140) {
		tmp = -d1 * d1;
	} else {
		tmp = d4 * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -1.8e+139:
		tmp = d2 * d1
	elif d2 <= 6.7e-140:
		tmp = -d1 * d1
	else:
		tmp = d4 * d1
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -1.8e+139)
		tmp = Float64(d2 * d1);
	elseif (d2 <= 6.7e-140)
		tmp = Float64(Float64(-d1) * d1);
	else
		tmp = Float64(d4 * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -1.8e+139)
		tmp = d2 * d1;
	elseif (d2 <= 6.7e-140)
		tmp = -d1 * d1;
	else
		tmp = d4 * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.8e+139], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, 6.7e-140], N[((-d1) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.8 \cdot 10^{+139}:\\
\;\;\;\;d2 \cdot d1\\

\mathbf{elif}\;d2 \leq 6.7 \cdot 10^{-140}:\\
\;\;\;\;\left(-d1\right) \cdot d1\\

\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d2 < -1.79999999999999993e139

    1. Initial program 82.6%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d2 around inf

      \[\leadsto \color{blue}{d1 \cdot d2} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto d2 \cdot \color{blue}{d1} \]
      2. lower-*.f6472.1

        \[\leadsto d2 \cdot \color{blue}{d1} \]
    4. Applied rewrites72.1%

      \[\leadsto \color{blue}{d2 \cdot d1} \]

    if -1.79999999999999993e139 < d2 < 6.7e-140

    1. Initial program 89.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d1 around inf

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    3. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
      2. pow2N/A

        \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot \color{blue}{d1} \]
      4. mul-1-negN/A

        \[\leadsto \left(-1 \cdot d1\right) \cdot d1 \]
      5. lower-*.f64N/A

        \[\leadsto \left(-1 \cdot d1\right) \cdot \color{blue}{d1} \]
      6. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot d1 \]
      7. lower-neg.f6437.9

        \[\leadsto \left(-d1\right) \cdot d1 \]
    4. Applied rewrites37.9%

      \[\leadsto \color{blue}{\left(-d1\right) \cdot d1} \]

    if 6.7e-140 < d2

    1. Initial program 85.6%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d4 around inf

      \[\leadsto \color{blue}{d1 \cdot d4} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto d4 \cdot \color{blue}{d1} \]
      2. lift-*.f6427.3

        \[\leadsto d4 \cdot \color{blue}{d1} \]
    4. Applied rewrites27.3%

      \[\leadsto \color{blue}{d4 \cdot d1} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 9: 63.9% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 2.1 \cdot 10^{+124}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 + d2\right) \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d4 2.1e+124) (* (- d2 d3) d1) (* (+ d4 d2) d1)))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d4 <= 2.1e+124) {
		tmp = (d2 - d3) * d1;
	} else {
		tmp = (d4 + d2) * d1;
	}
	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(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if (d4 <= 2.1d+124) then
        tmp = (d2 - d3) * d1
    else
        tmp = (d4 + d2) * d1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d4 <= 2.1e+124) {
		tmp = (d2 - d3) * d1;
	} else {
		tmp = (d4 + d2) * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d4 <= 2.1e+124:
		tmp = (d2 - d3) * d1
	else:
		tmp = (d4 + d2) * d1
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d4 <= 2.1e+124)
		tmp = Float64(Float64(d2 - d3) * d1);
	else
		tmp = Float64(Float64(d4 + d2) * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d4 <= 2.1e+124)
		tmp = (d2 - d3) * d1;
	else
		tmp = (d4 + d2) * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 2.1e+124], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 2.1 \cdot 10^{+124}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\

\mathbf{else}:\\
\;\;\;\;\left(d4 + d2\right) \cdot d1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d4 < 2.10000000000000011e124

    1. Initial program 88.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d1 around 0

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      2. lower-*.f64N/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      3. lower--.f64N/A

        \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot d1 \]
      4. +-commutativeN/A

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. lower-+.f6477.6

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
    4. Applied rewrites77.6%

      \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d3\right) \cdot d1} \]
    5. Taylor expanded in d2 around inf

      \[\leadsto \left(d2 - d3\right) \cdot d1 \]
    6. Step-by-step derivation
      1. Applied rewrites60.6%

        \[\leadsto \left(d2 - d3\right) \cdot d1 \]

      if 2.10000000000000011e124 < d4

      1. Initial program 81.1%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Taylor expanded in d1 around 0

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
      3. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
        2. lower-*.f64N/A

          \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
        3. lower--.f64N/A

          \[\leadsto \left(\left(d2 + d4\right) - d3\right) \cdot d1 \]
        4. +-commutativeN/A

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        5. lower-+.f6492.8

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      4. Applied rewrites92.8%

        \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d3\right) \cdot d1} \]
      5. Taylor expanded in d3 around 0

        \[\leadsto \left(d2 + d4\right) \cdot d1 \]
      6. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \left(d4 + d2\right) \cdot d1 \]
        2. lift-+.f6482.1

          \[\leadsto \left(d4 + d2\right) \cdot d1 \]
      7. Applied rewrites82.1%

        \[\leadsto \left(d4 + d2\right) \cdot d1 \]
    7. Recombined 2 regimes into one program.
    8. Add Preprocessing

    Alternative 10: 38.1% accurate, 2.5× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -9.5 \cdot 10^{-15}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
    (FPCore (d1 d2 d3 d4)
     :precision binary64
     (if (<= d2 -9.5e-15) (* d2 d1) (* d4 d1)))
    double code(double d1, double d2, double d3, double d4) {
    	double tmp;
    	if (d2 <= -9.5e-15) {
    		tmp = d2 * d1;
    	} else {
    		tmp = d4 * d1;
    	}
    	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(d1, d2, d3, d4)
    use fmin_fmax_functions
        real(8), intent (in) :: d1
        real(8), intent (in) :: d2
        real(8), intent (in) :: d3
        real(8), intent (in) :: d4
        real(8) :: tmp
        if (d2 <= (-9.5d-15)) then
            tmp = d2 * d1
        else
            tmp = d4 * d1
        end if
        code = tmp
    end function
    
    public static double code(double d1, double d2, double d3, double d4) {
    	double tmp;
    	if (d2 <= -9.5e-15) {
    		tmp = d2 * d1;
    	} else {
    		tmp = d4 * d1;
    	}
    	return tmp;
    }
    
    def code(d1, d2, d3, d4):
    	tmp = 0
    	if d2 <= -9.5e-15:
    		tmp = d2 * d1
    	else:
    		tmp = d4 * d1
    	return tmp
    
    function code(d1, d2, d3, d4)
    	tmp = 0.0
    	if (d2 <= -9.5e-15)
    		tmp = Float64(d2 * d1);
    	else
    		tmp = Float64(d4 * d1);
    	end
    	return tmp
    end
    
    function tmp_2 = code(d1, d2, d3, d4)
    	tmp = 0.0;
    	if (d2 <= -9.5e-15)
    		tmp = d2 * d1;
    	else
    		tmp = d4 * d1;
    	end
    	tmp_2 = tmp;
    end
    
    code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -9.5e-15], N[(d2 * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;d2 \leq -9.5 \cdot 10^{-15}:\\
    \;\;\;\;d2 \cdot d1\\
    
    \mathbf{else}:\\
    \;\;\;\;d4 \cdot d1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if d2 < -9.5000000000000005e-15

      1. Initial program 85.4%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Taylor expanded in d2 around inf

        \[\leadsto \color{blue}{d1 \cdot d2} \]
      3. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto d2 \cdot \color{blue}{d1} \]
        2. lower-*.f6451.9

          \[\leadsto d2 \cdot \color{blue}{d1} \]
      4. Applied rewrites51.9%

        \[\leadsto \color{blue}{d2 \cdot d1} \]

      if -9.5000000000000005e-15 < d2

      1. Initial program 87.7%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Taylor expanded in d4 around inf

        \[\leadsto \color{blue}{d1 \cdot d4} \]
      3. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto d4 \cdot \color{blue}{d1} \]
        2. lift-*.f6433.3

          \[\leadsto d4 \cdot \color{blue}{d1} \]
      4. Applied rewrites33.3%

        \[\leadsto \color{blue}{d4 \cdot d1} \]
    3. Recombined 2 regimes into one program.
    4. Add Preprocessing

    Alternative 11: 31.2% accurate, 5.0× speedup?

    \[\begin{array}{l} \\ d2 \cdot d1 \end{array} \]
    (FPCore (d1 d2 d3 d4) :precision binary64 (* d2 d1))
    double code(double d1, double d2, double d3, double d4) {
    	return d2 * d1;
    }
    
    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(d1, d2, d3, d4)
    use fmin_fmax_functions
        real(8), intent (in) :: d1
        real(8), intent (in) :: d2
        real(8), intent (in) :: d3
        real(8), intent (in) :: d4
        code = d2 * d1
    end function
    
    public static double code(double d1, double d2, double d3, double d4) {
    	return d2 * d1;
    }
    
    def code(d1, d2, d3, d4):
    	return d2 * d1
    
    function code(d1, d2, d3, d4)
    	return Float64(d2 * d1)
    end
    
    function tmp = code(d1, d2, d3, d4)
    	tmp = d2 * d1;
    end
    
    code[d1_, d2_, d3_, d4_] := N[(d2 * d1), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    d2 \cdot d1
    \end{array}
    
    Derivation
    1. Initial program 87.1%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d2 around inf

      \[\leadsto \color{blue}{d1 \cdot d2} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto d2 \cdot \color{blue}{d1} \]
      2. lower-*.f6431.2

        \[\leadsto d2 \cdot \color{blue}{d1} \]
    4. Applied rewrites31.2%

      \[\leadsto \color{blue}{d2 \cdot d1} \]
    5. Add Preprocessing

    Developer Target 1: 100.0% accurate, 2.0× speedup?

    \[\begin{array}{l} \\ d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right) \end{array} \]
    (FPCore (d1 d2 d3 d4) :precision binary64 (* d1 (- (+ (- d2 d3) d4) d1)))
    double code(double d1, double d2, double d3, double d4) {
    	return d1 * (((d2 - d3) + d4) - d1);
    }
    
    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(d1, d2, d3, d4)
    use fmin_fmax_functions
        real(8), intent (in) :: d1
        real(8), intent (in) :: d2
        real(8), intent (in) :: d3
        real(8), intent (in) :: d4
        code = d1 * (((d2 - d3) + d4) - d1)
    end function
    
    public static double code(double d1, double d2, double d3, double d4) {
    	return d1 * (((d2 - d3) + d4) - d1);
    }
    
    def code(d1, d2, d3, d4):
    	return d1 * (((d2 - d3) + d4) - d1)
    
    function code(d1, d2, d3, d4)
    	return Float64(d1 * Float64(Float64(Float64(d2 - d3) + d4) - d1))
    end
    
    function tmp = code(d1, d2, d3, d4)
    	tmp = d1 * (((d2 - d3) + d4) - d1);
    end
    
    code[d1_, d2_, d3_, d4_] := N[(d1 * N[(N[(N[(d2 - d3), $MachinePrecision] + d4), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right)
    \end{array}
    

    Reproduce

    ?
    herbie shell --seed 2025095 
    (FPCore (d1 d2 d3 d4)
      :name "FastMath dist4"
      :precision binary64
    
      :alt
      (! :herbie-platform default (* d1 (- (+ (- d2 d3) d4) d1)))
    
      (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))