FastMath dist4

Percentage Accurate: 87.6% → 100.0%
Time: 4.3s
Alternatives: 11
Speedup: 2.0×

Specification

?
\[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
(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]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 alternatives:

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

Initial Program: 87.6% accurate, 1.0× speedup?

\[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
(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]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1

Alternative 1: 100.0% accurate, 2.0× speedup?

\[d1 \cdot \left(\left(d4 - \left(d3 - d2\right)\right) - d1\right) \]
(FPCore (d1 d2 d3 d4)
  :precision binary64
  (* d1 (- (- d4 (- d3 d2)) d1)))
double code(double d1, double d2, double d3, double d4) {
	return d1 * ((d4 - (d3 - d2)) - d1);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    code = d1 * ((d4 - (d3 - d2)) - d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
	return d1 * ((d4 - (d3 - d2)) - d1);
}
def code(d1, d2, d3, d4):
	return d1 * ((d4 - (d3 - d2)) - d1)
function code(d1, d2, d3, d4)
	return Float64(d1 * Float64(Float64(d4 - Float64(d3 - d2)) - d1))
end
function tmp = code(d1, d2, d3, d4)
	tmp = d1 * ((d4 - (d3 - d2)) - d1);
end
code[d1_, d2_, d3_, d4_] := N[(d1 * N[(N[(d4 - N[(d3 - d2), $MachinePrecision]), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]
d1 \cdot \left(\left(d4 - \left(d3 - d2\right)\right) - d1\right)
Derivation
  1. Initial program 87.6%

    \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
    3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 92.8% accurate, 0.1× speedup?

\[\begin{array}{l} \mathbf{if}\;\mathsf{max}\left(d2, d4\right) \leq 3.9 \cdot 10^{-56}:\\ \;\;\;\;d1 \cdot \left(\left(\mathsf{min}\left(d2, d4\right) - d3\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(\mathsf{min}\left(d2, d4\right) + \mathsf{max}\left(d2, d4\right)\right) - d3\right)\\ \end{array} \]
(FPCore (d1 d2 d3 d4)
  :precision binary64
  (if (<= (fmax d2 d4) 3.9e-56)
  (* d1 (- (- (fmin d2 d4) d3) d1))
  (* d1 (- (+ (fmin d2 d4) (fmax d2 d4)) d3))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (fmax(d2, d4) <= 3.9e-56) {
		tmp = d1 * ((fmin(d2, d4) - d3) - d1);
	} else {
		tmp = d1 * ((fmin(d2, d4) + fmax(d2, 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 (fmax(d2, d4) <= 3.9d-56) then
        tmp = d1 * ((fmin(d2, d4) - d3) - d1)
    else
        tmp = d1 * ((fmin(d2, d4) + fmax(d2, d4)) - d3)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (fmax(d2, d4) <= 3.9e-56) {
		tmp = d1 * ((fmin(d2, d4) - d3) - d1);
	} else {
		tmp = d1 * ((fmin(d2, d4) + fmax(d2, d4)) - d3);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if fmax(d2, d4) <= 3.9e-56:
		tmp = d1 * ((fmin(d2, d4) - d3) - d1)
	else:
		tmp = d1 * ((fmin(d2, d4) + fmax(d2, d4)) - d3)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (fmax(d2, d4) <= 3.9e-56)
		tmp = Float64(d1 * Float64(Float64(fmin(d2, d4) - d3) - d1));
	else
		tmp = Float64(d1 * Float64(Float64(fmin(d2, d4) + fmax(d2, d4)) - d3));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (max(d2, d4) <= 3.9e-56)
		tmp = d1 * ((min(d2, d4) - d3) - d1);
	else
		tmp = d1 * ((min(d2, d4) + max(d2, d4)) - d3);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[N[Max[d2, d4], $MachinePrecision], 3.9e-56], N[(d1 * N[(N[(N[Min[d2, d4], $MachinePrecision] - d3), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(N[(N[Min[d2, d4], $MachinePrecision] + N[Max[d2, d4], $MachinePrecision]), $MachinePrecision] - d3), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\mathsf{max}\left(d2, d4\right) \leq 3.9 \cdot 10^{-56}:\\
\;\;\;\;d1 \cdot \left(\left(\mathsf{min}\left(d2, d4\right) - d3\right) - d1\right)\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d4 < 3.9000000000000002e-56

    1. Initial program 87.6%

      \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
      3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.9000000000000002e-56 < d4

    1. Initial program 87.6%

      \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
      3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 92.8% accurate, 1.2× speedup?

\[\begin{array}{l} t_0 := d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\ \mathbf{if}\;d3 \leq -1.8 \cdot 10^{-13}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq 9 \cdot 10^{-27}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
(FPCore (d1 d2 d3 d4)
  :precision binary64
  (let* ((t_0 (* d1 (- (+ d2 d4) d3))))
  (if (<= d3 -1.8e-13)
    t_0
    (if (<= d3 9e-27) (* d1 (- (+ d2 d4) 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.8e-13) {
		tmp = t_0;
	} else if (d3 <= 9e-27) {
		tmp = d1 * ((d2 + d4) - 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.8d-13)) then
        tmp = t_0
    else if (d3 <= 9d-27) then
        tmp = d1 * ((d2 + d4) - 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.8e-13) {
		tmp = t_0;
	} else if (d3 <= 9e-27) {
		tmp = d1 * ((d2 + d4) - d1);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * ((d2 + d4) - d3)
	tmp = 0
	if d3 <= -1.8e-13:
		tmp = t_0
	elif d3 <= 9e-27:
		tmp = d1 * ((d2 + d4) - 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.8e-13)
		tmp = t_0;
	elseif (d3 <= 9e-27)
		tmp = Float64(d1 * Float64(Float64(d2 + d4) - 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.8e-13)
		tmp = t_0;
	elseif (d3 <= 9e-27)
		tmp = d1 * ((d2 + d4) - 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.8e-13], t$95$0, If[LessEqual[d3, 9e-27], N[(d1 * N[(N[(d2 + d4), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\
\mathbf{if}\;d3 \leq -1.8 \cdot 10^{-13}:\\
\;\;\;\;t\_0\\

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

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -1.7999999999999999e-13 or 9.0000000000000003e-27 < d3

    1. Initial program 87.6%

      \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
      3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.7999999999999999e-13 < d3 < 9.0000000000000003e-27

    1. Initial program 87.6%

      \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
      3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 87.8% accurate, 0.1× speedup?

\[\begin{array}{l} \mathbf{if}\;d3 \leq -1.75 \cdot 10^{+116}:\\ \;\;\;\;d1 \cdot \left(\mathsf{max}\left(d2, d4\right) - d3\right)\\ \mathbf{elif}\;d3 \leq 3.3 \cdot 10^{+54}:\\ \;\;\;\;d1 \cdot \left(\left(\mathsf{min}\left(d2, d4\right) + \mathsf{max}\left(d2, d4\right)\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\mathsf{min}\left(d2, d4\right) - d3\right)\\ \end{array} \]
(FPCore (d1 d2 d3 d4)
  :precision binary64
  (if (<= d3 -1.75e+116)
  (* d1 (- (fmax d2 d4) d3))
  (if (<= d3 3.3e+54)
    (* d1 (- (+ (fmin d2 d4) (fmax d2 d4)) d1))
    (* d1 (- (fmin d2 d4) d3)))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d3 <= -1.75e+116) {
		tmp = d1 * (fmax(d2, d4) - d3);
	} else if (d3 <= 3.3e+54) {
		tmp = d1 * ((fmin(d2, d4) + fmax(d2, d4)) - d1);
	} else {
		tmp = d1 * (fmin(d2, 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 (d3 <= (-1.75d+116)) then
        tmp = d1 * (fmax(d2, d4) - d3)
    else if (d3 <= 3.3d+54) then
        tmp = d1 * ((fmin(d2, d4) + fmax(d2, d4)) - d1)
    else
        tmp = d1 * (fmin(d2, d4) - d3)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d3 <= -1.75e+116) {
		tmp = d1 * (fmax(d2, d4) - d3);
	} else if (d3 <= 3.3e+54) {
		tmp = d1 * ((fmin(d2, d4) + fmax(d2, d4)) - d1);
	} else {
		tmp = d1 * (fmin(d2, d4) - d3);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d3 <= -1.75e+116:
		tmp = d1 * (fmax(d2, d4) - d3)
	elif d3 <= 3.3e+54:
		tmp = d1 * ((fmin(d2, d4) + fmax(d2, d4)) - d1)
	else:
		tmp = d1 * (fmin(d2, d4) - d3)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d3 <= -1.75e+116)
		tmp = Float64(d1 * Float64(fmax(d2, d4) - d3));
	elseif (d3 <= 3.3e+54)
		tmp = Float64(d1 * Float64(Float64(fmin(d2, d4) + fmax(d2, d4)) - d1));
	else
		tmp = Float64(d1 * Float64(fmin(d2, d4) - d3));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d3 <= -1.75e+116)
		tmp = d1 * (max(d2, d4) - d3);
	elseif (d3 <= 3.3e+54)
		tmp = d1 * ((min(d2, d4) + max(d2, d4)) - d1);
	else
		tmp = d1 * (min(d2, d4) - d3);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d3, -1.75e+116], N[(d1 * N[(N[Max[d2, d4], $MachinePrecision] - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 3.3e+54], N[(d1 * N[(N[(N[Min[d2, d4], $MachinePrecision] + N[Max[d2, d4], $MachinePrecision]), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(N[Min[d2, d4], $MachinePrecision] - d3), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;d3 \leq -1.75 \cdot 10^{+116}:\\
\;\;\;\;d1 \cdot \left(\mathsf{max}\left(d2, d4\right) - d3\right)\\

\mathbf{elif}\;d3 \leq 3.3 \cdot 10^{+54}:\\
\;\;\;\;d1 \cdot \left(\left(\mathsf{min}\left(d2, d4\right) + \mathsf{max}\left(d2, d4\right)\right) - d1\right)\\

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


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -1.75e116

    1. Initial program 87.6%

      \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
      3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto d1 \cdot \left(d4 - d3\right) \]
    8. Step-by-step derivation
      1. Applied rewrites56.3%

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

      if -1.75e116 < d3 < 3.3e54

      1. Initial program 87.6%

        \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
        3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 3.3e54 < d3

      1. Initial program 87.6%

        \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
        3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 5: 74.2% accurate, 0.1× speedup?

    \[\begin{array}{l} t_0 := d1 \cdot \left(\mathsf{max}\left(d2, d4\right) - d3\right)\\ \mathbf{if}\;\mathsf{min}\left(d2, d4\right) \leq -3.25 \cdot 10^{+94}:\\ \;\;\;\;d1 \cdot \left(\mathsf{min}\left(d2, d4\right) - d3\right)\\ \mathbf{elif}\;\mathsf{min}\left(d2, d4\right) \leq -4200000000:\\ \;\;\;\;d1 \cdot \left(\mathsf{min}\left(d2, d4\right) - d1\right)\\ \mathbf{elif}\;\mathsf{min}\left(d2, d4\right) \leq -1.4 \cdot 10^{-129}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\mathsf{min}\left(d2, d4\right) \leq -9.2 \cdot 10^{-177}:\\ \;\;\;\;d1 \cdot \left(\mathsf{max}\left(d2, d4\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
    (FPCore (d1 d2 d3 d4)
      :precision binary64
      (let* ((t_0 (* d1 (- (fmax d2 d4) d3))))
      (if (<= (fmin d2 d4) -3.25e+94)
        (* d1 (- (fmin d2 d4) d3))
        (if (<= (fmin d2 d4) -4200000000.0)
          (* d1 (- (fmin d2 d4) d1))
          (if (<= (fmin d2 d4) -1.4e-129)
            t_0
            (if (<= (fmin d2 d4) -9.2e-177)
              (* d1 (- (fmax d2 d4) d1))
              t_0))))))
    double code(double d1, double d2, double d3, double d4) {
    	double t_0 = d1 * (fmax(d2, d4) - d3);
    	double tmp;
    	if (fmin(d2, d4) <= -3.25e+94) {
    		tmp = d1 * (fmin(d2, d4) - d3);
    	} else if (fmin(d2, d4) <= -4200000000.0) {
    		tmp = d1 * (fmin(d2, d4) - d1);
    	} else if (fmin(d2, d4) <= -1.4e-129) {
    		tmp = t_0;
    	} else if (fmin(d2, d4) <= -9.2e-177) {
    		tmp = d1 * (fmax(d2, d4) - 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 * (fmax(d2, d4) - d3)
        if (fmin(d2, d4) <= (-3.25d+94)) then
            tmp = d1 * (fmin(d2, d4) - d3)
        else if (fmin(d2, d4) <= (-4200000000.0d0)) then
            tmp = d1 * (fmin(d2, d4) - d1)
        else if (fmin(d2, d4) <= (-1.4d-129)) then
            tmp = t_0
        else if (fmin(d2, d4) <= (-9.2d-177)) then
            tmp = d1 * (fmax(d2, d4) - 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 * (fmax(d2, d4) - d3);
    	double tmp;
    	if (fmin(d2, d4) <= -3.25e+94) {
    		tmp = d1 * (fmin(d2, d4) - d3);
    	} else if (fmin(d2, d4) <= -4200000000.0) {
    		tmp = d1 * (fmin(d2, d4) - d1);
    	} else if (fmin(d2, d4) <= -1.4e-129) {
    		tmp = t_0;
    	} else if (fmin(d2, d4) <= -9.2e-177) {
    		tmp = d1 * (fmax(d2, d4) - d1);
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    def code(d1, d2, d3, d4):
    	t_0 = d1 * (fmax(d2, d4) - d3)
    	tmp = 0
    	if fmin(d2, d4) <= -3.25e+94:
    		tmp = d1 * (fmin(d2, d4) - d3)
    	elif fmin(d2, d4) <= -4200000000.0:
    		tmp = d1 * (fmin(d2, d4) - d1)
    	elif fmin(d2, d4) <= -1.4e-129:
    		tmp = t_0
    	elif fmin(d2, d4) <= -9.2e-177:
    		tmp = d1 * (fmax(d2, d4) - d1)
    	else:
    		tmp = t_0
    	return tmp
    
    function code(d1, d2, d3, d4)
    	t_0 = Float64(d1 * Float64(fmax(d2, d4) - d3))
    	tmp = 0.0
    	if (fmin(d2, d4) <= -3.25e+94)
    		tmp = Float64(d1 * Float64(fmin(d2, d4) - d3));
    	elseif (fmin(d2, d4) <= -4200000000.0)
    		tmp = Float64(d1 * Float64(fmin(d2, d4) - d1));
    	elseif (fmin(d2, d4) <= -1.4e-129)
    		tmp = t_0;
    	elseif (fmin(d2, d4) <= -9.2e-177)
    		tmp = Float64(d1 * Float64(fmax(d2, d4) - d1));
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(d1, d2, d3, d4)
    	t_0 = d1 * (max(d2, d4) - d3);
    	tmp = 0.0;
    	if (min(d2, d4) <= -3.25e+94)
    		tmp = d1 * (min(d2, d4) - d3);
    	elseif (min(d2, d4) <= -4200000000.0)
    		tmp = d1 * (min(d2, d4) - d1);
    	elseif (min(d2, d4) <= -1.4e-129)
    		tmp = t_0;
    	elseif (min(d2, d4) <= -9.2e-177)
    		tmp = d1 * (max(d2, d4) - d1);
    	else
    		tmp = t_0;
    	end
    	tmp_2 = tmp;
    end
    
    code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(N[Max[d2, d4], $MachinePrecision] - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Min[d2, d4], $MachinePrecision], -3.25e+94], N[(d1 * N[(N[Min[d2, d4], $MachinePrecision] - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Min[d2, d4], $MachinePrecision], -4200000000.0], N[(d1 * N[(N[Min[d2, d4], $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Min[d2, d4], $MachinePrecision], -1.4e-129], t$95$0, If[LessEqual[N[Min[d2, d4], $MachinePrecision], -9.2e-177], N[(d1 * N[(N[Max[d2, d4], $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
    
    \begin{array}{l}
    t_0 := d1 \cdot \left(\mathsf{max}\left(d2, d4\right) - d3\right)\\
    \mathbf{if}\;\mathsf{min}\left(d2, d4\right) \leq -3.25 \cdot 10^{+94}:\\
    \;\;\;\;d1 \cdot \left(\mathsf{min}\left(d2, d4\right) - d3\right)\\
    
    \mathbf{elif}\;\mathsf{min}\left(d2, d4\right) \leq -4200000000:\\
    \;\;\;\;d1 \cdot \left(\mathsf{min}\left(d2, d4\right) - d1\right)\\
    
    \mathbf{elif}\;\mathsf{min}\left(d2, d4\right) \leq -1.4 \cdot 10^{-129}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;\mathsf{min}\left(d2, d4\right) \leq -9.2 \cdot 10^{-177}:\\
    \;\;\;\;d1 \cdot \left(\mathsf{max}\left(d2, d4\right) - d1\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 4 regimes
    2. if d2 < -3.2499999999999999e94

      1. Initial program 87.6%

        \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
        3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -3.2499999999999999e94 < d2 < -4.2e9

      1. Initial program 87.6%

        \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
        3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -4.2e9 < d2 < -1.4e-129 or -9.2000000000000009e-177 < d2

      1. Initial program 87.6%

        \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
        3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \left(d4 - d3\right) \]
      8. Step-by-step derivation
        1. Applied rewrites56.3%

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

        if -1.4e-129 < d2 < -9.2000000000000009e-177

        1. Initial program 87.6%

          \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
          3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto d1 \cdot \left(d4 - d1\right) \]
        12. Recombined 4 regimes into one program.
        13. Add Preprocessing

        Alternative 6: 72.4% accurate, 0.1× speedup?

        \[\begin{array}{l} t_0 := d1 \cdot \left(\mathsf{max}\left(d2, d4\right) - d1\right)\\ t_1 := d1 \cdot \left(\mathsf{min}\left(d2, d4\right) - d3\right)\\ \mathbf{if}\;d3 \leq -1.7 \cdot 10^{+58}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d3 \leq -1.45 \cdot 10^{-227}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq 3.8 \cdot 10^{-237}:\\ \;\;\;\;d1 \cdot \left(\mathsf{min}\left(d2, d4\right) + \mathsf{max}\left(d2, d4\right)\right)\\ \mathbf{elif}\;d3 \leq 3.7 \cdot 10^{-83}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \]
        (FPCore (d1 d2 d3 d4)
          :precision binary64
          (let* ((t_0 (* d1 (- (fmax d2 d4) d1)))
               (t_1 (* d1 (- (fmin d2 d4) d3))))
          (if (<= d3 -1.7e+58)
            t_1
            (if (<= d3 -1.45e-227)
              t_0
              (if (<= d3 3.8e-237)
                (* d1 (+ (fmin d2 d4) (fmax d2 d4)))
                (if (<= d3 3.7e-83) t_0 t_1))))))
        double code(double d1, double d2, double d3, double d4) {
        	double t_0 = d1 * (fmax(d2, d4) - d1);
        	double t_1 = d1 * (fmin(d2, d4) - d3);
        	double tmp;
        	if (d3 <= -1.7e+58) {
        		tmp = t_1;
        	} else if (d3 <= -1.45e-227) {
        		tmp = t_0;
        	} else if (d3 <= 3.8e-237) {
        		tmp = d1 * (fmin(d2, d4) + fmax(d2, d4));
        	} else if (d3 <= 3.7e-83) {
        		tmp = t_0;
        	} else {
        		tmp = t_1;
        	}
        	return tmp;
        }
        
        module fmin_fmax_functions
            implicit none
            private
            public fmax
            public fmin
        
            interface fmax
                module procedure fmax88
                module procedure fmax44
                module procedure fmax84
                module procedure fmax48
            end interface
            interface fmin
                module procedure fmin88
                module procedure fmin44
                module procedure fmin84
                module procedure fmin48
            end interface
        contains
            real(8) function fmax88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(4) function fmax44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(8) function fmax84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmax48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
            end function
            real(8) function fmin88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(4) function fmin44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(8) function fmin84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmin48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
            end function
        end module
        
        real(8) function code(d1, d2, d3, d4)
        use fmin_fmax_functions
            real(8), intent (in) :: d1
            real(8), intent (in) :: d2
            real(8), intent (in) :: d3
            real(8), intent (in) :: d4
            real(8) :: t_0
            real(8) :: t_1
            real(8) :: tmp
            t_0 = d1 * (fmax(d2, d4) - d1)
            t_1 = d1 * (fmin(d2, d4) - d3)
            if (d3 <= (-1.7d+58)) then
                tmp = t_1
            else if (d3 <= (-1.45d-227)) then
                tmp = t_0
            else if (d3 <= 3.8d-237) then
                tmp = d1 * (fmin(d2, d4) + fmax(d2, d4))
            else if (d3 <= 3.7d-83) then
                tmp = t_0
            else
                tmp = t_1
            end if
            code = tmp
        end function
        
        public static double code(double d1, double d2, double d3, double d4) {
        	double t_0 = d1 * (fmax(d2, d4) - d1);
        	double t_1 = d1 * (fmin(d2, d4) - d3);
        	double tmp;
        	if (d3 <= -1.7e+58) {
        		tmp = t_1;
        	} else if (d3 <= -1.45e-227) {
        		tmp = t_0;
        	} else if (d3 <= 3.8e-237) {
        		tmp = d1 * (fmin(d2, d4) + fmax(d2, d4));
        	} else if (d3 <= 3.7e-83) {
        		tmp = t_0;
        	} else {
        		tmp = t_1;
        	}
        	return tmp;
        }
        
        def code(d1, d2, d3, d4):
        	t_0 = d1 * (fmax(d2, d4) - d1)
        	t_1 = d1 * (fmin(d2, d4) - d3)
        	tmp = 0
        	if d3 <= -1.7e+58:
        		tmp = t_1
        	elif d3 <= -1.45e-227:
        		tmp = t_0
        	elif d3 <= 3.8e-237:
        		tmp = d1 * (fmin(d2, d4) + fmax(d2, d4))
        	elif d3 <= 3.7e-83:
        		tmp = t_0
        	else:
        		tmp = t_1
        	return tmp
        
        function code(d1, d2, d3, d4)
        	t_0 = Float64(d1 * Float64(fmax(d2, d4) - d1))
        	t_1 = Float64(d1 * Float64(fmin(d2, d4) - d3))
        	tmp = 0.0
        	if (d3 <= -1.7e+58)
        		tmp = t_1;
        	elseif (d3 <= -1.45e-227)
        		tmp = t_0;
        	elseif (d3 <= 3.8e-237)
        		tmp = Float64(d1 * Float64(fmin(d2, d4) + fmax(d2, d4)));
        	elseif (d3 <= 3.7e-83)
        		tmp = t_0;
        	else
        		tmp = t_1;
        	end
        	return tmp
        end
        
        function tmp_2 = code(d1, d2, d3, d4)
        	t_0 = d1 * (max(d2, d4) - d1);
        	t_1 = d1 * (min(d2, d4) - d3);
        	tmp = 0.0;
        	if (d3 <= -1.7e+58)
        		tmp = t_1;
        	elseif (d3 <= -1.45e-227)
        		tmp = t_0;
        	elseif (d3 <= 3.8e-237)
        		tmp = d1 * (min(d2, d4) + max(d2, d4));
        	elseif (d3 <= 3.7e-83)
        		tmp = t_0;
        	else
        		tmp = t_1;
        	end
        	tmp_2 = tmp;
        end
        
        code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(N[Max[d2, d4], $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(N[Min[d2, d4], $MachinePrecision] - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -1.7e+58], t$95$1, If[LessEqual[d3, -1.45e-227], t$95$0, If[LessEqual[d3, 3.8e-237], N[(d1 * N[(N[Min[d2, d4], $MachinePrecision] + N[Max[d2, d4], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 3.7e-83], t$95$0, t$95$1]]]]]]
        
        \begin{array}{l}
        t_0 := d1 \cdot \left(\mathsf{max}\left(d2, d4\right) - d1\right)\\
        t_1 := d1 \cdot \left(\mathsf{min}\left(d2, d4\right) - d3\right)\\
        \mathbf{if}\;d3 \leq -1.7 \cdot 10^{+58}:\\
        \;\;\;\;t\_1\\
        
        \mathbf{elif}\;d3 \leq -1.45 \cdot 10^{-227}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;d3 \leq 3.8 \cdot 10^{-237}:\\
        \;\;\;\;d1 \cdot \left(\mathsf{min}\left(d2, d4\right) + \mathsf{max}\left(d2, d4\right)\right)\\
        
        \mathbf{elif}\;d3 \leq 3.7 \cdot 10^{-83}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_1\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if d3 < -1.7e58 or 3.6999999999999999e-83 < d3

          1. Initial program 87.6%

            \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
            3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if -1.7e58 < d3 < -1.4500000000000001e-227 or 3.8000000000000002e-237 < d3 < 3.6999999999999999e-83

          1. Initial program 87.6%

            \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
            3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if -1.4500000000000001e-227 < d3 < 3.8000000000000002e-237

            1. Initial program 87.6%

              \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
              3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto d1 \cdot \left(d2 + \color{blue}{d4}\right) \]
            11. Step-by-step derivation
              1. lower-+.f6456.2%

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

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

          Alternative 7: 69.6% accurate, 0.1× speedup?

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

            1. Initial program 87.6%

              \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
              3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if -1.3e-235 < d4 < 1.6000000000000001e48

            1. Initial program 87.6%

              \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
              3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 1.6000000000000001e48 < d4

            1. Initial program 87.6%

              \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
              3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto d1 \cdot \left(d2 + \color{blue}{d4}\right) \]
            11. Step-by-step derivation
              1. lower-+.f6456.2%

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

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

          Alternative 8: 69.3% accurate, 0.1× speedup?

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

            1. Initial program 87.6%

              \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
              3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 3.9000000000000002e-56 < d4

            1. Initial program 87.6%

              \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
              3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto d1 \cdot \left(d2 + \color{blue}{d4}\right) \]
            11. Step-by-step derivation
              1. lower-+.f6456.2%

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

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

          Alternative 9: 65.8% accurate, 1.4× speedup?

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

            1. Initial program 87.6%

              \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
              3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \color{blue}{\left(-1 \cdot d1\right) \cdot d1} \]
              3. lower-*.f6432.3%

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

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

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

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

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

            if -4.4999999999999997e132 < d1 < 1.7000000000000001e64

            1. Initial program 87.6%

              \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
              3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto d1 \cdot \left(d2 + \color{blue}{d4}\right) \]
            11. Step-by-step derivation
              1. lower-+.f6456.2%

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

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

          Alternative 10: 47.6% accurate, 0.1× speedup?

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

            1. Initial program 87.6%

              \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
              3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto d2 \cdot \left(d1 + \frac{d1 \cdot \left(d4 - \left(d1 + d3\right)\right)}{d2}\right) \]
              6. lower-+.f6489.5%

                \[\leadsto d2 \cdot \left(d1 + \frac{d1 \cdot \left(d4 - \left(d1 + d3\right)\right)}{d2}\right) \]
            6. Applied rewrites89.5%

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

              \[\leadsto d1 \cdot \color{blue}{d2} \]
            8. Step-by-step derivation
              1. lower-*.f6431.1%

                \[\leadsto d1 \cdot d2 \]
            9. Applied rewrites31.1%

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

            if -1.45e92 < d2

            1. Initial program 87.6%

              \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
              3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \color{blue}{\left(-1 \cdot d1\right) \cdot d1} \]
              3. lower-*.f6432.3%

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

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

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

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

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

          Alternative 11: 31.0% accurate, 0.3× speedup?

          \[d1 \cdot \mathsf{min}\left(d2, d4\right) \]
          (FPCore (d1 d2 d3 d4)
            :precision binary64
            (* d1 (fmin d2 d4)))
          double code(double d1, double d2, double d3, double d4) {
          	return d1 * fmin(d2, 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 * fmin(d2, d4)
          end function
          
          public static double code(double d1, double d2, double d3, double d4) {
          	return d1 * fmin(d2, d4);
          }
          
          def code(d1, d2, d3, d4):
          	return d1 * fmin(d2, d4)
          
          function code(d1, d2, d3, d4)
          	return Float64(d1 * fmin(d2, d4))
          end
          
          function tmp = code(d1, d2, d3, d4)
          	tmp = d1 * min(d2, d4);
          end
          
          code[d1_, d2_, d3_, d4_] := N[(d1 * N[Min[d2, d4], $MachinePrecision]), $MachinePrecision]
          
          d1 \cdot \mathsf{min}\left(d2, d4\right)
          
          Derivation
          1. Initial program 87.6%

            \[\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 \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - \color{blue}{d1 \cdot d1} \]
            3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto d2 \cdot \left(d1 + \frac{d1 \cdot \left(d4 - \left(d1 + d3\right)\right)}{d2}\right) \]
            6. lower-+.f6489.5%

              \[\leadsto d2 \cdot \left(d1 + \frac{d1 \cdot \left(d4 - \left(d1 + d3\right)\right)}{d2}\right) \]
          6. Applied rewrites89.5%

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

            \[\leadsto d1 \cdot \color{blue}{d2} \]
          8. Step-by-step derivation
            1. lower-*.f6431.1%

              \[\leadsto d1 \cdot d2 \]
          9. Applied rewrites31.1%

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

          Reproduce

          ?
          herbie shell --seed 2025258 
          (FPCore (d1 d2 d3 d4)
            :name "FastMath dist4"
            :precision binary64
            (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))