FastMath dist4

Percentage Accurate: 87.8% → 100.0%
Time: 3.8s
Alternatives: 13
Speedup: 1.8×

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 13 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.8% 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: 100.0% accurate, 1.8× speedup?

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

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

    \[\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. sub-flipN/A

      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
    3. add-flipN/A

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

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

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

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

      \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
    8. distribute-lft-out--N/A

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

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

      \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
    11. distribute-lft-outN/A

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

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

      \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
    14. distribute-lft-out--N/A

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

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

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

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

      \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
    19. sub-negate-revN/A

      \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
    20. sub-flip-reverseN/A

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

      \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
    22. lower--.f64100.0

      \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
  3. Applied rewrites100.0%

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

Alternative 2: 92.5% accurate, 1.2× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -1.26000000000000005e69 or 3.9000000000000001e114 < d3

    1. Initial program 87.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. lower-*.f64N/A

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

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

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

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

    if -1.26000000000000005e69 < d3 < 3.9000000000000001e114

    1. Initial program 87.8%

      \[\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. sub-flipN/A

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
      3. add-flipN/A

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

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

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

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

        \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
      8. distribute-lft-out--N/A

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

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

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
      11. distribute-lft-outN/A

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
      14. distribute-lft-out--N/A

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

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

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

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

        \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
      19. sub-negate-revN/A

        \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
      20. sub-flip-reverseN/A

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

        \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
      22. lower--.f64100.0

        \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
    3. Applied rewrites100.0%

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

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

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

        \[\leadsto \left(\left(d2 + d4\right) - d1\right) \cdot d1 \]
    6. Applied rewrites76.8%

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

Alternative 3: 92.2% accurate, 1.2× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -1.1e52 or 4.4999999999999999e27 < d1

    1. Initial program 87.8%

      \[\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. sub-flipN/A

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
      3. add-flipN/A

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

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

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

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

        \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
      8. distribute-lft-out--N/A

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

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

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
      11. distribute-lft-outN/A

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
      14. distribute-lft-out--N/A

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

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

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

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

        \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
      19. sub-negate-revN/A

        \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
      20. sub-flip-reverseN/A

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

        \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
      22. lower--.f64100.0

        \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
    3. Applied rewrites100.0%

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

      \[\leadsto \left(\left(d4 - \color{blue}{d3}\right) - d1\right) \cdot d1 \]
    5. Step-by-step derivation
      1. Applied rewrites76.9%

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

      if -1.1e52 < d1 < 4.4999999999999999e27

      1. Initial program 87.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. lower-*.f64N/A

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

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

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

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

    Alternative 4: 82.5% accurate, 1.6× speedup?

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

      1. Initial program 87.8%

        \[\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. sub-flipN/A

          \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
        3. add-flipN/A

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

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

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

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

          \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
        8. distribute-lft-out--N/A

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

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

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
        11. distribute-lft-outN/A

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

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

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
        14. distribute-lft-out--N/A

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

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

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

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

          \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
        19. sub-negate-revN/A

          \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
        20. sub-flip-reverseN/A

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

          \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
        22. lower--.f64100.0

          \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
      3. Applied rewrites100.0%

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

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

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

          \[\leadsto \left(\left(d2 + d4\right) - d1\right) \cdot d1 \]
      6. Applied rewrites76.8%

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

        \[\leadsto \left(d2 - \color{blue}{d1}\right) \cdot d1 \]
      8. Step-by-step derivation
        1. lower--.f6454.6

          \[\leadsto \left(d2 - d1\right) \cdot d1 \]
      9. Applied rewrites54.6%

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

      if -1.1499999999999999e156 < d2

      1. Initial program 87.8%

        \[\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. sub-flipN/A

          \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
        3. add-flipN/A

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

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

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

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

          \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
        8. distribute-lft-out--N/A

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

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

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
        11. distribute-lft-outN/A

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

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

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
        14. distribute-lft-out--N/A

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

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

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

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

          \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
        19. sub-negate-revN/A

          \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
        20. sub-flip-reverseN/A

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

          \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
        22. lower--.f64100.0

          \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
      3. Applied rewrites100.0%

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

        \[\leadsto \left(\left(d4 - \color{blue}{d3}\right) - d1\right) \cdot d1 \]
      5. Step-by-step derivation
        1. Applied rewrites76.9%

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

      Alternative 5: 67.6% accurate, 0.3× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\\ \mathbf{if}\;t\_0 \leq -4 \cdot 10^{+47}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \mathbf{elif}\;t\_0 \leq -1 \cdot 10^{-152}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;t\_0 \leq \infty:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{else}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \end{array} \end{array} \]
      (FPCore (d1 d2 d3 d4)
       :precision binary64
       (let* ((t_0 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1))))
         (if (<= t_0 -4e+47)
           (* (- d4 d1) d1)
           (if (<= t_0 -1e-152)
             (* d1 (- d2 d3))
             (if (<= t_0 INFINITY) (* d1 (+ d2 d4)) (* (- d2 d1) d1))))))
      double code(double d1, double d2, double d3, double d4) {
      	double t_0 = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
      	double tmp;
      	if (t_0 <= -4e+47) {
      		tmp = (d4 - d1) * d1;
      	} else if (t_0 <= -1e-152) {
      		tmp = d1 * (d2 - d3);
      	} else if (t_0 <= ((double) INFINITY)) {
      		tmp = d1 * (d2 + d4);
      	} else {
      		tmp = (d2 - d1) * d1;
      	}
      	return tmp;
      }
      
      public static double code(double d1, double d2, double d3, double d4) {
      	double t_0 = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
      	double tmp;
      	if (t_0 <= -4e+47) {
      		tmp = (d4 - d1) * d1;
      	} else if (t_0 <= -1e-152) {
      		tmp = d1 * (d2 - d3);
      	} else if (t_0 <= Double.POSITIVE_INFINITY) {
      		tmp = d1 * (d2 + d4);
      	} else {
      		tmp = (d2 - d1) * d1;
      	}
      	return tmp;
      }
      
      def code(d1, d2, d3, d4):
      	t_0 = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
      	tmp = 0
      	if t_0 <= -4e+47:
      		tmp = (d4 - d1) * d1
      	elif t_0 <= -1e-152:
      		tmp = d1 * (d2 - d3)
      	elif t_0 <= math.inf:
      		tmp = d1 * (d2 + d4)
      	else:
      		tmp = (d2 - d1) * d1
      	return tmp
      
      function code(d1, d2, d3, d4)
      	t_0 = Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1))
      	tmp = 0.0
      	if (t_0 <= -4e+47)
      		tmp = Float64(Float64(d4 - d1) * d1);
      	elseif (t_0 <= -1e-152)
      		tmp = Float64(d1 * Float64(d2 - d3));
      	elseif (t_0 <= Inf)
      		tmp = Float64(d1 * Float64(d2 + d4));
      	else
      		tmp = Float64(Float64(d2 - d1) * d1);
      	end
      	return tmp
      end
      
      function tmp_2 = code(d1, d2, d3, d4)
      	t_0 = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
      	tmp = 0.0;
      	if (t_0 <= -4e+47)
      		tmp = (d4 - d1) * d1;
      	elseif (t_0 <= -1e-152)
      		tmp = d1 * (d2 - d3);
      	elseif (t_0 <= Inf)
      		tmp = d1 * (d2 + d4);
      	else
      		tmp = (d2 - d1) * d1;
      	end
      	tmp_2 = tmp;
      end
      
      code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -4e+47], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[t$95$0, -1e-152], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(d1 * N[(d2 + d4), $MachinePrecision]), $MachinePrecision], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision]]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\\
      \mathbf{if}\;t\_0 \leq -4 \cdot 10^{+47}:\\
      \;\;\;\;\left(d4 - d1\right) \cdot d1\\
      
      \mathbf{elif}\;t\_0 \leq -1 \cdot 10^{-152}:\\
      \;\;\;\;d1 \cdot \left(d2 - d3\right)\\
      
      \mathbf{elif}\;t\_0 \leq \infty:\\
      \;\;\;\;d1 \cdot \left(d2 + d4\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\left(d2 - d1\right) \cdot d1\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 4 regimes
      2. if (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) < -4.0000000000000002e47

        1. Initial program 87.8%

          \[\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. sub-flipN/A

            \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
          3. add-flipN/A

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

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

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

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

            \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
          8. distribute-lft-out--N/A

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

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

            \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
          11. distribute-lft-outN/A

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

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

            \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
          14. distribute-lft-out--N/A

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

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

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

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

            \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
          19. sub-negate-revN/A

            \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
          20. sub-flip-reverseN/A

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

            \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
          22. lower--.f64100.0

            \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
        3. Applied rewrites100.0%

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

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

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

            \[\leadsto \left(\left(d2 + d4\right) - d1\right) \cdot d1 \]
        6. Applied rewrites76.8%

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

          \[\leadsto \left(d4 - \color{blue}{d1}\right) \cdot d1 \]
        8. Step-by-step derivation
          1. lower--.f6453.9

            \[\leadsto \left(d4 - d1\right) \cdot d1 \]
        9. Applied rewrites53.9%

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

        if -4.0000000000000002e47 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) < -1.00000000000000007e-152

        1. Initial program 87.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. lower-*.f64N/A

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

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

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

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

          \[\leadsto d1 \cdot \left(d2 - \color{blue}{d3}\right) \]
        6. Step-by-step derivation
          1. lower--.f6456.4

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

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

        if -1.00000000000000007e-152 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) < +inf.0

        1. Initial program 87.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. lower-*.f64N/A

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

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

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

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

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

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

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

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

        if +inf.0 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1))

        1. Initial program 87.8%

          \[\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. sub-flipN/A

            \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
          3. add-flipN/A

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

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

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

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

            \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
          8. distribute-lft-out--N/A

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

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

            \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
          11. distribute-lft-outN/A

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

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

            \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
          14. distribute-lft-out--N/A

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

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

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

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

            \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
          19. sub-negate-revN/A

            \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
          20. sub-flip-reverseN/A

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

            \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
          22. lower--.f64100.0

            \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
        3. Applied rewrites100.0%

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

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

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

            \[\leadsto \left(\left(d2 + d4\right) - d1\right) \cdot d1 \]
        6. Applied rewrites76.8%

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

          \[\leadsto \left(d2 - \color{blue}{d1}\right) \cdot d1 \]
        8. Step-by-step derivation
          1. lower--.f6454.6

            \[\leadsto \left(d2 - d1\right) \cdot d1 \]
        9. Applied rewrites54.6%

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

      Alternative 6: 64.3% accurate, 1.3× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 1.7 \cdot 10^{+16}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d4 \leq 1.25 \cdot 10^{+149}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(d4, d1, d2 \cdot d1\right)\\ \end{array} \end{array} \]
      (FPCore (d1 d2 d3 d4)
       :precision binary64
       (if (<= d4 1.7e+16)
         (* (- d2 d1) d1)
         (if (<= d4 1.25e+149) (* (- d4 d1) d1) (fma d4 d1 (* d2 d1)))))
      double code(double d1, double d2, double d3, double d4) {
      	double tmp;
      	if (d4 <= 1.7e+16) {
      		tmp = (d2 - d1) * d1;
      	} else if (d4 <= 1.25e+149) {
      		tmp = (d4 - d1) * d1;
      	} else {
      		tmp = fma(d4, d1, (d2 * d1));
      	}
      	return tmp;
      }
      
      function code(d1, d2, d3, d4)
      	tmp = 0.0
      	if (d4 <= 1.7e+16)
      		tmp = Float64(Float64(d2 - d1) * d1);
      	elseif (d4 <= 1.25e+149)
      		tmp = Float64(Float64(d4 - d1) * d1);
      	else
      		tmp = fma(d4, d1, Float64(d2 * d1));
      	end
      	return tmp
      end
      
      code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 1.7e+16], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d4, 1.25e+149], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(d4 * d1 + N[(d2 * d1), $MachinePrecision]), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;d4 \leq 1.7 \cdot 10^{+16}:\\
      \;\;\;\;\left(d2 - d1\right) \cdot d1\\
      
      \mathbf{elif}\;d4 \leq 1.25 \cdot 10^{+149}:\\
      \;\;\;\;\left(d4 - d1\right) \cdot d1\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(d4, d1, d2 \cdot d1\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if d4 < 1.7e16

        1. Initial program 87.8%

          \[\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. sub-flipN/A

            \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
          3. add-flipN/A

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

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

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

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

            \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
          8. distribute-lft-out--N/A

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

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

            \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
          11. distribute-lft-outN/A

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

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

            \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
          14. distribute-lft-out--N/A

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

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

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

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

            \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
          19. sub-negate-revN/A

            \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
          20. sub-flip-reverseN/A

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

            \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
          22. lower--.f64100.0

            \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
        3. Applied rewrites100.0%

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

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

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

            \[\leadsto \left(\left(d2 + d4\right) - d1\right) \cdot d1 \]
        6. Applied rewrites76.8%

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

          \[\leadsto \left(d2 - \color{blue}{d1}\right) \cdot d1 \]
        8. Step-by-step derivation
          1. lower--.f6454.6

            \[\leadsto \left(d2 - d1\right) \cdot d1 \]
        9. Applied rewrites54.6%

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

        if 1.7e16 < d4 < 1.24999999999999998e149

        1. Initial program 87.8%

          \[\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. sub-flipN/A

            \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
          3. add-flipN/A

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

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

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

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

            \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
          8. distribute-lft-out--N/A

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

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

            \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
          11. distribute-lft-outN/A

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

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

            \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
          14. distribute-lft-out--N/A

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

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

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

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

            \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
          19. sub-negate-revN/A

            \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
          20. sub-flip-reverseN/A

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

            \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
          22. lower--.f64100.0

            \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
        3. Applied rewrites100.0%

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

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

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

            \[\leadsto \left(\left(d2 + d4\right) - d1\right) \cdot d1 \]
        6. Applied rewrites76.8%

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

          \[\leadsto \left(d4 - \color{blue}{d1}\right) \cdot d1 \]
        8. Step-by-step derivation
          1. lower--.f6453.9

            \[\leadsto \left(d4 - d1\right) \cdot d1 \]
        9. Applied rewrites53.9%

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

        if 1.24999999999999998e149 < d4

        1. Initial program 87.8%

          \[\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. +-commutativeN/A

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

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

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

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

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

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

            \[\leadsto d4 \cdot d1 - \left(\mathsf{neg}\left(\color{blue}{\left(d1 \cdot d2 - \left(d1 \cdot d3 - \left(\mathsf{neg}\left(d1\right)\right) \cdot d1\right)\right)}\right)\right) \]
          10. sub-negateN/A

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

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

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{d4 - d1}, d1, d2 \cdot d1\right) \]
        5. Step-by-step derivation
          1. lower--.f6473.5

            \[\leadsto \mathsf{fma}\left(d4 - \color{blue}{d1}, d1, d2 \cdot d1\right) \]
        6. Applied rewrites73.5%

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

          \[\leadsto \mathsf{fma}\left(d4, d1, d2 \cdot d1\right) \]
        8. Step-by-step derivation
          1. Applied rewrites55.5%

            \[\leadsto \mathsf{fma}\left(d4, d1, d2 \cdot d1\right) \]
        9. Recombined 3 regimes into one program.
        10. Add Preprocessing

        Alternative 7: 62.3% accurate, 1.5× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -7.5 \cdot 10^{+204}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -9.6 \cdot 10^{-39}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \end{array} \end{array} \]
        (FPCore (d1 d2 d3 d4)
         :precision binary64
         (if (<= d2 -7.5e+204)
           (* (- d2 d1) d1)
           (if (<= d2 -9.6e-39) (* d1 (- d2 d3)) (* (- d4 d1) d1))))
        double code(double d1, double d2, double d3, double d4) {
        	double tmp;
        	if (d2 <= -7.5e+204) {
        		tmp = (d2 - d1) * d1;
        	} else if (d2 <= -9.6e-39) {
        		tmp = d1 * (d2 - d3);
        	} else {
        		tmp = (d4 - d1) * 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 <= (-7.5d+204)) then
                tmp = (d2 - d1) * d1
            else if (d2 <= (-9.6d-39)) then
                tmp = d1 * (d2 - d3)
            else
                tmp = (d4 - d1) * d1
            end if
            code = tmp
        end function
        
        public static double code(double d1, double d2, double d3, double d4) {
        	double tmp;
        	if (d2 <= -7.5e+204) {
        		tmp = (d2 - d1) * d1;
        	} else if (d2 <= -9.6e-39) {
        		tmp = d1 * (d2 - d3);
        	} else {
        		tmp = (d4 - d1) * d1;
        	}
        	return tmp;
        }
        
        def code(d1, d2, d3, d4):
        	tmp = 0
        	if d2 <= -7.5e+204:
        		tmp = (d2 - d1) * d1
        	elif d2 <= -9.6e-39:
        		tmp = d1 * (d2 - d3)
        	else:
        		tmp = (d4 - d1) * d1
        	return tmp
        
        function code(d1, d2, d3, d4)
        	tmp = 0.0
        	if (d2 <= -7.5e+204)
        		tmp = Float64(Float64(d2 - d1) * d1);
        	elseif (d2 <= -9.6e-39)
        		tmp = Float64(d1 * Float64(d2 - d3));
        	else
        		tmp = Float64(Float64(d4 - d1) * d1);
        	end
        	return tmp
        end
        
        function tmp_2 = code(d1, d2, d3, d4)
        	tmp = 0.0;
        	if (d2 <= -7.5e+204)
        		tmp = (d2 - d1) * d1;
        	elseif (d2 <= -9.6e-39)
        		tmp = d1 * (d2 - d3);
        	else
        		tmp = (d4 - d1) * d1;
        	end
        	tmp_2 = tmp;
        end
        
        code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -7.5e+204], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -9.6e-39], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;d2 \leq -7.5 \cdot 10^{+204}:\\
        \;\;\;\;\left(d2 - d1\right) \cdot d1\\
        
        \mathbf{elif}\;d2 \leq -9.6 \cdot 10^{-39}:\\
        \;\;\;\;d1 \cdot \left(d2 - d3\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\left(d4 - d1\right) \cdot d1\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if d2 < -7.4999999999999998e204

          1. Initial program 87.8%

            \[\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. sub-flipN/A

              \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
            3. add-flipN/A

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

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

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

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

              \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
            8. distribute-lft-out--N/A

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

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

              \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
            11. distribute-lft-outN/A

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

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

              \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
            14. distribute-lft-out--N/A

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

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

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

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

              \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
            19. sub-negate-revN/A

              \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
            20. sub-flip-reverseN/A

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

              \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
            22. lower--.f64100.0

              \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
          3. Applied rewrites100.0%

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

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

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

              \[\leadsto \left(\left(d2 + d4\right) - d1\right) \cdot d1 \]
          6. Applied rewrites76.8%

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

            \[\leadsto \left(d2 - \color{blue}{d1}\right) \cdot d1 \]
          8. Step-by-step derivation
            1. lower--.f6454.6

              \[\leadsto \left(d2 - d1\right) \cdot d1 \]
          9. Applied rewrites54.6%

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

          if -7.4999999999999998e204 < d2 < -9.60000000000000063e-39

          1. Initial program 87.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. lower-*.f64N/A

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

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

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

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

            \[\leadsto d1 \cdot \left(d2 - \color{blue}{d3}\right) \]
          6. Step-by-step derivation
            1. lower--.f6456.4

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

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

          if -9.60000000000000063e-39 < d2

          1. Initial program 87.8%

            \[\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. sub-flipN/A

              \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
            3. add-flipN/A

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

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

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

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

              \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
            8. distribute-lft-out--N/A

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

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

              \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
            11. distribute-lft-outN/A

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

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

              \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
            14. distribute-lft-out--N/A

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

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

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

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

              \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
            19. sub-negate-revN/A

              \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
            20. sub-flip-reverseN/A

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

              \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
            22. lower--.f64100.0

              \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
          3. Applied rewrites100.0%

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

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

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

              \[\leadsto \left(\left(d2 + d4\right) - d1\right) \cdot d1 \]
          6. Applied rewrites76.8%

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

            \[\leadsto \left(d4 - \color{blue}{d1}\right) \cdot d1 \]
          8. Step-by-step derivation
            1. lower--.f6453.9

              \[\leadsto \left(d4 - d1\right) \cdot d1 \]
          9. Applied rewrites53.9%

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

        Alternative 8: 61.8% accurate, 2.0× speedup?

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

          1. Initial program 87.8%

            \[\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. sub-flipN/A

              \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
            3. add-flipN/A

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

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

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

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

              \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
            8. distribute-lft-out--N/A

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

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

              \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
            11. distribute-lft-outN/A

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

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

              \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
            14. distribute-lft-out--N/A

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

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

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

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

              \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
            19. sub-negate-revN/A

              \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
            20. sub-flip-reverseN/A

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

              \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
            22. lower--.f64100.0

              \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
          3. Applied rewrites100.0%

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

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

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

              \[\leadsto \left(\left(d2 + d4\right) - d1\right) \cdot d1 \]
          6. Applied rewrites76.8%

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

            \[\leadsto \left(d2 - \color{blue}{d1}\right) \cdot d1 \]
          8. Step-by-step derivation
            1. lower--.f6454.6

              \[\leadsto \left(d2 - d1\right) \cdot d1 \]
          9. Applied rewrites54.6%

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

          if 5.9000000000000003e26 < d4

          1. Initial program 87.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. lower-*.f64N/A

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

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

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

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

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

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

          Alternative 9: 61.0% accurate, 1.2× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d4 - d3\right)\\ \mathbf{if}\;d2 \leq -350000:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -7.2 \cdot 10^{-107}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d2 \leq -2 \cdot 10^{-232}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
          (FPCore (d1 d2 d3 d4)
           :precision binary64
           (let* ((t_0 (* d1 (- d4 d3))))
             (if (<= d2 -350000.0)
               (* d1 (- d2 d3))
               (if (<= d2 -7.2e-107) t_0 (if (<= d2 -2e-232) (* (- d1) d1) t_0)))))
          double code(double d1, double d2, double d3, double d4) {
          	double t_0 = d1 * (d4 - d3);
          	double tmp;
          	if (d2 <= -350000.0) {
          		tmp = d1 * (d2 - d3);
          	} else if (d2 <= -7.2e-107) {
          		tmp = t_0;
          	} else if (d2 <= -2e-232) {
          		tmp = -d1 * 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 * (d4 - d3)
              if (d2 <= (-350000.0d0)) then
                  tmp = d1 * (d2 - d3)
              else if (d2 <= (-7.2d-107)) then
                  tmp = t_0
              else if (d2 <= (-2d-232)) then
                  tmp = -d1 * 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 * (d4 - d3);
          	double tmp;
          	if (d2 <= -350000.0) {
          		tmp = d1 * (d2 - d3);
          	} else if (d2 <= -7.2e-107) {
          		tmp = t_0;
          	} else if (d2 <= -2e-232) {
          		tmp = -d1 * d1;
          	} else {
          		tmp = t_0;
          	}
          	return tmp;
          }
          
          def code(d1, d2, d3, d4):
          	t_0 = d1 * (d4 - d3)
          	tmp = 0
          	if d2 <= -350000.0:
          		tmp = d1 * (d2 - d3)
          	elif d2 <= -7.2e-107:
          		tmp = t_0
          	elif d2 <= -2e-232:
          		tmp = -d1 * d1
          	else:
          		tmp = t_0
          	return tmp
          
          function code(d1, d2, d3, d4)
          	t_0 = Float64(d1 * Float64(d4 - d3))
          	tmp = 0.0
          	if (d2 <= -350000.0)
          		tmp = Float64(d1 * Float64(d2 - d3));
          	elseif (d2 <= -7.2e-107)
          		tmp = t_0;
          	elseif (d2 <= -2e-232)
          		tmp = Float64(Float64(-d1) * d1);
          	else
          		tmp = t_0;
          	end
          	return tmp
          end
          
          function tmp_2 = code(d1, d2, d3, d4)
          	t_0 = d1 * (d4 - d3);
          	tmp = 0.0;
          	if (d2 <= -350000.0)
          		tmp = d1 * (d2 - d3);
          	elseif (d2 <= -7.2e-107)
          		tmp = t_0;
          	elseif (d2 <= -2e-232)
          		tmp = -d1 * d1;
          	else
          		tmp = t_0;
          	end
          	tmp_2 = tmp;
          end
          
          code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d2, -350000.0], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d2, -7.2e-107], t$95$0, If[LessEqual[d2, -2e-232], N[((-d1) * d1), $MachinePrecision], t$95$0]]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_0 := d1 \cdot \left(d4 - d3\right)\\
          \mathbf{if}\;d2 \leq -350000:\\
          \;\;\;\;d1 \cdot \left(d2 - d3\right)\\
          
          \mathbf{elif}\;d2 \leq -7.2 \cdot 10^{-107}:\\
          \;\;\;\;t\_0\\
          
          \mathbf{elif}\;d2 \leq -2 \cdot 10^{-232}:\\
          \;\;\;\;\left(-d1\right) \cdot d1\\
          
          \mathbf{else}:\\
          \;\;\;\;t\_0\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if d2 < -3.5e5

            1. Initial program 87.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. lower-*.f64N/A

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

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

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

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

              \[\leadsto d1 \cdot \left(d2 - \color{blue}{d3}\right) \]
            6. Step-by-step derivation
              1. lower--.f6456.4

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

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

            if -3.5e5 < d2 < -7.19999999999999953e-107 or -2.00000000000000005e-232 < d2

            1. Initial program 87.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. lower-*.f64N/A

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

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

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

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

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

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

              if -7.19999999999999953e-107 < d2 < -2.00000000000000005e-232

              1. Initial program 87.8%

                \[\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. sub-flipN/A

                  \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
                3. add-flipN/A

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

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

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

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

                  \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
                8. distribute-lft-out--N/A

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

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

                  \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
                11. distribute-lft-outN/A

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

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

                  \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
                14. distribute-lft-out--N/A

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

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

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

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

                  \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
                19. sub-negate-revN/A

                  \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
                20. sub-flip-reverseN/A

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

                  \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
                22. lower--.f64100.0

                  \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
              3. Applied rewrites100.0%

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

                \[\leadsto \color{blue}{\left(-1 \cdot d1\right)} \cdot d1 \]
              5. Step-by-step derivation
                1. lower-*.f6432.0

                  \[\leadsto \left(-1 \cdot \color{blue}{d1}\right) \cdot d1 \]
              6. Applied rewrites32.0%

                \[\leadsto \color{blue}{\left(-1 \cdot d1\right)} \cdot d1 \]
              7. Step-by-step derivation
                1. lift-*.f64N/A

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

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

                  \[\leadsto \left(-d1\right) \cdot d1 \]
              8. Applied rewrites32.0%

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

            Alternative 10: 60.4% accurate, 1.5× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(-d1\right) \cdot d1\\ \mathbf{if}\;d1 \leq -1.4 \cdot 10^{+61}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d1 \leq 1.08 \cdot 10^{+38}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
            (FPCore (d1 d2 d3 d4)
             :precision binary64
             (let* ((t_0 (* (- d1) d1)))
               (if (<= d1 -1.4e+61) t_0 (if (<= d1 1.08e+38) (* d1 (- d2 d3)) t_0))))
            double code(double d1, double d2, double d3, double d4) {
            	double t_0 = -d1 * d1;
            	double tmp;
            	if (d1 <= -1.4e+61) {
            		tmp = t_0;
            	} else if (d1 <= 1.08e+38) {
            		tmp = d1 * (d2 - d3);
            	} 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 <= (-1.4d+61)) then
                    tmp = t_0
                else if (d1 <= 1.08d+38) then
                    tmp = d1 * (d2 - d3)
                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 <= -1.4e+61) {
            		tmp = t_0;
            	} else if (d1 <= 1.08e+38) {
            		tmp = d1 * (d2 - d3);
            	} else {
            		tmp = t_0;
            	}
            	return tmp;
            }
            
            def code(d1, d2, d3, d4):
            	t_0 = -d1 * d1
            	tmp = 0
            	if d1 <= -1.4e+61:
            		tmp = t_0
            	elif d1 <= 1.08e+38:
            		tmp = d1 * (d2 - d3)
            	else:
            		tmp = t_0
            	return tmp
            
            function code(d1, d2, d3, d4)
            	t_0 = Float64(Float64(-d1) * d1)
            	tmp = 0.0
            	if (d1 <= -1.4e+61)
            		tmp = t_0;
            	elseif (d1 <= 1.08e+38)
            		tmp = Float64(d1 * Float64(d2 - d3));
            	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 <= -1.4e+61)
            		tmp = t_0;
            	elseif (d1 <= 1.08e+38)
            		tmp = d1 * (d2 - d3);
            	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, -1.4e+61], t$95$0, If[LessEqual[d1, 1.08e+38], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], t$95$0]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_0 := \left(-d1\right) \cdot d1\\
            \mathbf{if}\;d1 \leq -1.4 \cdot 10^{+61}:\\
            \;\;\;\;t\_0\\
            
            \mathbf{elif}\;d1 \leq 1.08 \cdot 10^{+38}:\\
            \;\;\;\;d1 \cdot \left(d2 - d3\right)\\
            
            \mathbf{else}:\\
            \;\;\;\;t\_0\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if d1 < -1.4000000000000001e61 or 1.07999999999999995e38 < d1

              1. Initial program 87.8%

                \[\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. sub-flipN/A

                  \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
                3. add-flipN/A

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

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

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

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

                  \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
                8. distribute-lft-out--N/A

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

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

                  \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
                11. distribute-lft-outN/A

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

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

                  \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
                14. distribute-lft-out--N/A

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

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

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

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

                  \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
                19. sub-negate-revN/A

                  \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
                20. sub-flip-reverseN/A

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

                  \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
                22. lower--.f64100.0

                  \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
              3. Applied rewrites100.0%

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

                \[\leadsto \color{blue}{\left(-1 \cdot d1\right)} \cdot d1 \]
              5. Step-by-step derivation
                1. lower-*.f6432.0

                  \[\leadsto \left(-1 \cdot \color{blue}{d1}\right) \cdot d1 \]
              6. Applied rewrites32.0%

                \[\leadsto \color{blue}{\left(-1 \cdot d1\right)} \cdot d1 \]
              7. Step-by-step derivation
                1. lift-*.f64N/A

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

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

                  \[\leadsto \left(-d1\right) \cdot d1 \]
              8. Applied rewrites32.0%

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

              if -1.4000000000000001e61 < d1 < 1.07999999999999995e38

              1. Initial program 87.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. lower-*.f64N/A

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

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

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

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

                \[\leadsto d1 \cdot \left(d2 - \color{blue}{d3}\right) \]
              6. Step-by-step derivation
                1. lower--.f6456.4

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

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

            Alternative 11: 39.4% accurate, 1.0× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(-d1\right) \cdot d1\\ \mathbf{if}\;d4 \leq -1.45 \cdot 10^{-112}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d4 \leq 1.8 \cdot 10^{-160}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d4 \leq 8.2 \cdot 10^{-96}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d4 \leq 3.9 \cdot 10^{+119}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \end{array} \]
            (FPCore (d1 d2 d3 d4)
             :precision binary64
             (let* ((t_0 (* (- d1) d1)))
               (if (<= d4 -1.45e-112)
                 (* d2 d1)
                 (if (<= d4 1.8e-160)
                   t_0
                   (if (<= d4 8.2e-96) (* d2 d1) (if (<= d4 3.9e+119) t_0 (* d1 d4)))))))
            double code(double d1, double d2, double d3, double d4) {
            	double t_0 = -d1 * d1;
            	double tmp;
            	if (d4 <= -1.45e-112) {
            		tmp = d2 * d1;
            	} else if (d4 <= 1.8e-160) {
            		tmp = t_0;
            	} else if (d4 <= 8.2e-96) {
            		tmp = d2 * d1;
            	} else if (d4 <= 3.9e+119) {
            		tmp = t_0;
            	} else {
            		tmp = d1 * d4;
            	}
            	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 (d4 <= (-1.45d-112)) then
                    tmp = d2 * d1
                else if (d4 <= 1.8d-160) then
                    tmp = t_0
                else if (d4 <= 8.2d-96) then
                    tmp = d2 * d1
                else if (d4 <= 3.9d+119) then
                    tmp = t_0
                else
                    tmp = d1 * d4
                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 (d4 <= -1.45e-112) {
            		tmp = d2 * d1;
            	} else if (d4 <= 1.8e-160) {
            		tmp = t_0;
            	} else if (d4 <= 8.2e-96) {
            		tmp = d2 * d1;
            	} else if (d4 <= 3.9e+119) {
            		tmp = t_0;
            	} else {
            		tmp = d1 * d4;
            	}
            	return tmp;
            }
            
            def code(d1, d2, d3, d4):
            	t_0 = -d1 * d1
            	tmp = 0
            	if d4 <= -1.45e-112:
            		tmp = d2 * d1
            	elif d4 <= 1.8e-160:
            		tmp = t_0
            	elif d4 <= 8.2e-96:
            		tmp = d2 * d1
            	elif d4 <= 3.9e+119:
            		tmp = t_0
            	else:
            		tmp = d1 * d4
            	return tmp
            
            function code(d1, d2, d3, d4)
            	t_0 = Float64(Float64(-d1) * d1)
            	tmp = 0.0
            	if (d4 <= -1.45e-112)
            		tmp = Float64(d2 * d1);
            	elseif (d4 <= 1.8e-160)
            		tmp = t_0;
            	elseif (d4 <= 8.2e-96)
            		tmp = Float64(d2 * d1);
            	elseif (d4 <= 3.9e+119)
            		tmp = t_0;
            	else
            		tmp = Float64(d1 * d4);
            	end
            	return tmp
            end
            
            function tmp_2 = code(d1, d2, d3, d4)
            	t_0 = -d1 * d1;
            	tmp = 0.0;
            	if (d4 <= -1.45e-112)
            		tmp = d2 * d1;
            	elseif (d4 <= 1.8e-160)
            		tmp = t_0;
            	elseif (d4 <= 8.2e-96)
            		tmp = d2 * d1;
            	elseif (d4 <= 3.9e+119)
            		tmp = t_0;
            	else
            		tmp = d1 * d4;
            	end
            	tmp_2 = tmp;
            end
            
            code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[((-d1) * d1), $MachinePrecision]}, If[LessEqual[d4, -1.45e-112], N[(d2 * d1), $MachinePrecision], If[LessEqual[d4, 1.8e-160], t$95$0, If[LessEqual[d4, 8.2e-96], N[(d2 * d1), $MachinePrecision], If[LessEqual[d4, 3.9e+119], t$95$0, N[(d1 * d4), $MachinePrecision]]]]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_0 := \left(-d1\right) \cdot d1\\
            \mathbf{if}\;d4 \leq -1.45 \cdot 10^{-112}:\\
            \;\;\;\;d2 \cdot d1\\
            
            \mathbf{elif}\;d4 \leq 1.8 \cdot 10^{-160}:\\
            \;\;\;\;t\_0\\
            
            \mathbf{elif}\;d4 \leq 8.2 \cdot 10^{-96}:\\
            \;\;\;\;d2 \cdot d1\\
            
            \mathbf{elif}\;d4 \leq 3.9 \cdot 10^{+119}:\\
            \;\;\;\;t\_0\\
            
            \mathbf{else}:\\
            \;\;\;\;d1 \cdot d4\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 3 regimes
            2. if d4 < -1.44999999999999996e-112 or 1.7999999999999999e-160 < d4 < 8.20000000000000048e-96

              1. Initial program 87.8%

                \[\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. sub-flipN/A

                  \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
                3. add-flipN/A

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

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

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

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

                  \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
                8. distribute-lft-out--N/A

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

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

                  \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
                11. distribute-lft-outN/A

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

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

                  \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
                14. distribute-lft-out--N/A

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

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

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

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

                  \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
                19. sub-negate-revN/A

                  \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
                20. sub-flip-reverseN/A

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

                  \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
                22. lower--.f64100.0

                  \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
              3. Applied rewrites100.0%

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

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

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

                  \[\leadsto \left(\left(d2 + d4\right) - d1\right) \cdot d1 \]
              6. Applied rewrites76.8%

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

                \[\leadsto \left(d2 - \color{blue}{d1}\right) \cdot d1 \]
              8. Step-by-step derivation
                1. lower--.f6454.6

                  \[\leadsto \left(d2 - d1\right) \cdot d1 \]
              9. Applied rewrites54.6%

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

                \[\leadsto d2 \cdot d1 \]
              11. Step-by-step derivation
                1. Applied rewrites31.0%

                  \[\leadsto d2 \cdot d1 \]

                if -1.44999999999999996e-112 < d4 < 1.7999999999999999e-160 or 8.20000000000000048e-96 < d4 < 3.8999999999999998e119

                1. Initial program 87.8%

                  \[\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. sub-flipN/A

                    \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
                  3. add-flipN/A

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

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

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

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

                    \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
                  8. distribute-lft-out--N/A

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

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

                    \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
                  11. distribute-lft-outN/A

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

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

                    \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
                  14. distribute-lft-out--N/A

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

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

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

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

                    \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
                  19. sub-negate-revN/A

                    \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
                  20. sub-flip-reverseN/A

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

                    \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
                  22. lower--.f64100.0

                    \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
                3. Applied rewrites100.0%

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

                  \[\leadsto \color{blue}{\left(-1 \cdot d1\right)} \cdot d1 \]
                5. Step-by-step derivation
                  1. lower-*.f6432.0

                    \[\leadsto \left(-1 \cdot \color{blue}{d1}\right) \cdot d1 \]
                6. Applied rewrites32.0%

                  \[\leadsto \color{blue}{\left(-1 \cdot d1\right)} \cdot d1 \]
                7. Step-by-step derivation
                  1. lift-*.f64N/A

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

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

                    \[\leadsto \left(-d1\right) \cdot d1 \]
                8. Applied rewrites32.0%

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

                if 3.8999999999999998e119 < d4

                1. Initial program 87.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. lower-*.f64N/A

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

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

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

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

                  \[\leadsto \color{blue}{d1 \cdot d4} \]
                6. Step-by-step derivation
                  1. lower-*.f6430.7

                    \[\leadsto d1 \cdot \color{blue}{d4} \]
                7. Applied rewrites30.7%

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

              Alternative 12: 39.1% accurate, 2.7× speedup?

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

                1. Initial program 87.8%

                  \[\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. sub-flipN/A

                    \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) + \left(\mathsf{neg}\left(d1 \cdot d1\right)\right)} \]
                  3. add-flipN/A

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

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

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

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

                    \[\leadsto \left(\left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + d4 \cdot d1\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
                  8. distribute-lft-out--N/A

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

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

                    \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + \color{blue}{d1 \cdot d4}\right) - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(d1 \cdot d1\right)\right)\right)\right) \]
                  11. distribute-lft-outN/A

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

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

                    \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1 \cdot d1} \]
                  14. distribute-lft-out--N/A

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

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

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

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

                    \[\leadsto \left(\color{blue}{\left(d4 + \left(d2 - d3\right)\right)} - d1\right) \cdot d1 \]
                  19. sub-negate-revN/A

                    \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(\left(d3 - d2\right)\right)\right)}\right) - d1\right) \cdot d1 \]
                  20. sub-flip-reverseN/A

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

                    \[\leadsto \left(\color{blue}{\left(d4 - \left(d3 - d2\right)\right)} - d1\right) \cdot d1 \]
                  22. lower--.f64100.0

                    \[\leadsto \left(\left(d4 - \color{blue}{\left(d3 - d2\right)}\right) - d1\right) \cdot d1 \]
                3. Applied rewrites100.0%

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

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

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

                    \[\leadsto \left(\left(d2 + d4\right) - d1\right) \cdot d1 \]
                6. Applied rewrites76.8%

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

                  \[\leadsto \left(d2 - \color{blue}{d1}\right) \cdot d1 \]
                8. Step-by-step derivation
                  1. lower--.f6454.6

                    \[\leadsto \left(d2 - d1\right) \cdot d1 \]
                9. Applied rewrites54.6%

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

                  \[\leadsto d2 \cdot d1 \]
                11. Step-by-step derivation
                  1. Applied rewrites31.0%

                    \[\leadsto d2 \cdot d1 \]

                  if 1.7e16 < d4

                  1. Initial program 87.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. lower-*.f64N/A

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

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

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

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

                    \[\leadsto \color{blue}{d1 \cdot d4} \]
                  6. Step-by-step derivation
                    1. lower-*.f6430.7

                      \[\leadsto d1 \cdot \color{blue}{d4} \]
                  7. Applied rewrites30.7%

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

                Alternative 13: 30.7% accurate, 5.3× speedup?

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

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

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

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

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

                  \[\leadsto \color{blue}{d1 \cdot d4} \]
                6. Step-by-step derivation
                  1. lower-*.f6430.7

                    \[\leadsto d1 \cdot \color{blue}{d4} \]
                7. Applied rewrites30.7%

                  \[\leadsto \color{blue}{d1 \cdot d4} \]
                8. Add Preprocessing

                Developer Target 1: 100.0% accurate, 1.7× 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 2025150 
                (FPCore (d1 d2 d3 d4)
                  :name "FastMath dist4"
                  :precision binary64
                
                  :alt
                  (! :herbie-platform c (* d1 (- (+ (- d2 d3) d4) d1)))
                
                  (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))