FastMath dist4

Percentage Accurate: 87.5% → 98.8%
Time: 10.8s
Alternatives: 11
Speedup: 1.2×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 alternatives:

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

Initial Program: 87.5% accurate, 1.0× speedup?

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

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

Alternative 1: 98.8% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 1.3 \cdot 10^{+179}:\\ \;\;\;\;\mathsf{fma}\left(d4, d1, d1 \cdot \left(\left(d2 - d3\right) - d1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d4 1.3e+179)
   (fma d4 d1 (* d1 (- (- d2 d3) d1)))
   (* (- (+ d4 d2) d3) d1)))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d4 <= 1.3e+179) {
		tmp = fma(d4, d1, (d1 * ((d2 - d3) - d1)));
	} else {
		tmp = ((d4 + d2) - d3) * d1;
	}
	return tmp;
}
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d4 <= 1.3e+179)
		tmp = fma(d4, d1, Float64(d1 * Float64(Float64(d2 - d3) - d1)));
	else
		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
	end
	return tmp
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 1.3e+179], N[(d4 * d1 + N[(d1 * N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 1.3 \cdot 10^{+179}:\\
\;\;\;\;\mathsf{fma}\left(d4, d1, d1 \cdot \left(\left(d2 - d3\right) - d1\right)\right)\\

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


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

    1. Initial program 87.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.3000000000000001e179 < d4

    1. Initial program 78.3%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 1.3 \cdot 10^{+179}:\\ \;\;\;\;\mathsf{fma}\left(d4, d1, d1 \cdot \left(\left(d2 - d3\right) - d1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 63.9% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq -1.7 \cdot 10^{-265}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d4 \leq 1.5 \cdot 10^{+68}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d4 \leq 2.9 \cdot 10^{+143}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d4 -1.7e-265)
   (* (- d2 d1) d1)
   (if (<= d4 1.5e+68)
     (* (- d2 d3) d1)
     (if (<= d4 2.9e+143) (* (- d4 d3) d1) (* (+ d2 d4) d1)))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d4 <= -1.7e-265) {
		tmp = (d2 - d1) * d1;
	} else if (d4 <= 1.5e+68) {
		tmp = (d2 - d3) * d1;
	} else if (d4 <= 2.9e+143) {
		tmp = (d4 - d3) * d1;
	} else {
		tmp = (d2 + d4) * d1;
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if (d4 <= (-1.7d-265)) then
        tmp = (d2 - d1) * d1
    else if (d4 <= 1.5d+68) then
        tmp = (d2 - d3) * d1
    else if (d4 <= 2.9d+143) then
        tmp = (d4 - d3) * d1
    else
        tmp = (d2 + d4) * d1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d4 <= -1.7e-265) {
		tmp = (d2 - d1) * d1;
	} else if (d4 <= 1.5e+68) {
		tmp = (d2 - d3) * d1;
	} else if (d4 <= 2.9e+143) {
		tmp = (d4 - d3) * d1;
	} else {
		tmp = (d2 + d4) * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d4 <= -1.7e-265:
		tmp = (d2 - d1) * d1
	elif d4 <= 1.5e+68:
		tmp = (d2 - d3) * d1
	elif d4 <= 2.9e+143:
		tmp = (d4 - d3) * d1
	else:
		tmp = (d2 + d4) * d1
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d4 <= -1.7e-265)
		tmp = Float64(Float64(d2 - d1) * d1);
	elseif (d4 <= 1.5e+68)
		tmp = Float64(Float64(d2 - d3) * d1);
	elseif (d4 <= 2.9e+143)
		tmp = Float64(Float64(d4 - d3) * d1);
	else
		tmp = Float64(Float64(d2 + d4) * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d4 <= -1.7e-265)
		tmp = (d2 - d1) * d1;
	elseif (d4 <= 1.5e+68)
		tmp = (d2 - d3) * d1;
	elseif (d4 <= 2.9e+143)
		tmp = (d4 - d3) * d1;
	else
		tmp = (d2 + d4) * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, -1.7e-265], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d4, 1.5e+68], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d4, 2.9e+143], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq -1.7 \cdot 10^{-265}:\\
\;\;\;\;\left(d2 - d1\right) \cdot d1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d4 < -1.7e-265

    1. Initial program 84.9%

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

      \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
    4. Step-by-step derivation
      1. associate--r+N/A

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

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
      3. unpow2N/A

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
      8. lower--.f6472.4

        \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
    5. Applied rewrites72.4%

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

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

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

      if -1.7e-265 < d4 < 1.5000000000000001e68

      1. Initial program 91.6%

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

        \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
      4. Step-by-step derivation
        1. associate--r+N/A

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

          \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
        3. unpow2N/A

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

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

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

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

          \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
        8. lower--.f6497.7

          \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
      5. Applied rewrites97.7%

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

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

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

        if 1.5000000000000001e68 < d4 < 2.8999999999999998e143

        1. Initial program 85.6%

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

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

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

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

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

            \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
          5. lower-+.f6492.7

            \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
        5. Applied rewrites92.7%

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

          \[\leadsto \left(d4 - d3\right) \cdot d1 \]
        7. Step-by-step derivation
          1. Applied rewrites58.4%

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

          if 2.8999999999999998e143 < d4

          1. Initial program 76.9%

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

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

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

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

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

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

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

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

            \[\leadsto d1 \cdot \color{blue}{\left(d2 + d4\right)} \]
          7. Step-by-step derivation
            1. Applied rewrites97.8%

              \[\leadsto \left(d2 + d4\right) \cdot \color{blue}{d1} \]
          8. Recombined 4 regimes into one program.
          9. Final simplification63.3%

            \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -1.7 \cdot 10^{-265}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d4 \leq 1.5 \cdot 10^{+68}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d4 \leq 2.9 \cdot 10^{+143}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \end{array} \]
          10. Add Preprocessing

          Alternative 3: 40.0% accurate, 1.2× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -7.4 \cdot 10^{+61}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -70000000000:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{elif}\;d2 \leq 4 \cdot 10^{-128}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
          (FPCore (d1 d2 d3 d4)
           :precision binary64
           (if (<= d2 -7.4e+61)
             (* d2 d1)
             (if (<= d2 -70000000000.0)
               (* (- d1) d1)
               (if (<= d2 4e-128) (* (- d3) d1) (* d4 d1)))))
          double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if (d2 <= -7.4e+61) {
          		tmp = d2 * d1;
          	} else if (d2 <= -70000000000.0) {
          		tmp = -d1 * d1;
          	} else if (d2 <= 4e-128) {
          		tmp = -d3 * d1;
          	} else {
          		tmp = d4 * d1;
          	}
          	return tmp;
          }
          
          real(8) function code(d1, d2, d3, d4)
              real(8), intent (in) :: d1
              real(8), intent (in) :: d2
              real(8), intent (in) :: d3
              real(8), intent (in) :: d4
              real(8) :: tmp
              if (d2 <= (-7.4d+61)) then
                  tmp = d2 * d1
              else if (d2 <= (-70000000000.0d0)) then
                  tmp = -d1 * d1
              else if (d2 <= 4d-128) then
                  tmp = -d3 * d1
              else
                  tmp = d4 * d1
              end if
              code = tmp
          end function
          
          public static double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if (d2 <= -7.4e+61) {
          		tmp = d2 * d1;
          	} else if (d2 <= -70000000000.0) {
          		tmp = -d1 * d1;
          	} else if (d2 <= 4e-128) {
          		tmp = -d3 * d1;
          	} else {
          		tmp = d4 * d1;
          	}
          	return tmp;
          }
          
          def code(d1, d2, d3, d4):
          	tmp = 0
          	if d2 <= -7.4e+61:
          		tmp = d2 * d1
          	elif d2 <= -70000000000.0:
          		tmp = -d1 * d1
          	elif d2 <= 4e-128:
          		tmp = -d3 * d1
          	else:
          		tmp = d4 * d1
          	return tmp
          
          function code(d1, d2, d3, d4)
          	tmp = 0.0
          	if (d2 <= -7.4e+61)
          		tmp = Float64(d2 * d1);
          	elseif (d2 <= -70000000000.0)
          		tmp = Float64(Float64(-d1) * d1);
          	elseif (d2 <= 4e-128)
          		tmp = Float64(Float64(-d3) * d1);
          	else
          		tmp = Float64(d4 * d1);
          	end
          	return tmp
          end
          
          function tmp_2 = code(d1, d2, d3, d4)
          	tmp = 0.0;
          	if (d2 <= -7.4e+61)
          		tmp = d2 * d1;
          	elseif (d2 <= -70000000000.0)
          		tmp = -d1 * d1;
          	elseif (d2 <= 4e-128)
          		tmp = -d3 * d1;
          	else
          		tmp = d4 * d1;
          	end
          	tmp_2 = tmp;
          end
          
          code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -7.4e+61], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, -70000000000.0], N[((-d1) * d1), $MachinePrecision], If[LessEqual[d2, 4e-128], N[((-d3) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;d2 \leq -7.4 \cdot 10^{+61}:\\
          \;\;\;\;d2 \cdot d1\\
          
          \mathbf{elif}\;d2 \leq -70000000000:\\
          \;\;\;\;\left(-d1\right) \cdot d1\\
          
          \mathbf{elif}\;d2 \leq 4 \cdot 10^{-128}:\\
          \;\;\;\;\left(-d3\right) \cdot d1\\
          
          \mathbf{else}:\\
          \;\;\;\;d4 \cdot d1\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 4 regimes
          2. if d2 < -7.40000000000000005e61

            1. Initial program 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \color{blue}{d2 \cdot d1} \]
            7. Applied rewrites56.8%

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

            if -7.40000000000000005e61 < d2 < -7e10

            1. Initial program 93.3%

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

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

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

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

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

                \[\leadsto \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)} \cdot d1 \]
              5. lower-neg.f6442.7

                \[\leadsto \color{blue}{\left(-d1\right)} \cdot d1 \]
            5. Applied rewrites42.7%

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

            if -7e10 < d2 < 4.00000000000000022e-128

            1. Initial program 90.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)} \cdot d1 \]
              5. lower-neg.f6453.9

                \[\leadsto \color{blue}{\left(-d3\right)} \cdot d1 \]
            7. Applied rewrites53.9%

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

            if 4.00000000000000022e-128 < d2

            1. Initial program 89.5%

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

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

                \[\leadsto \color{blue}{d4 \cdot d1} \]
              2. lower-*.f6435.4

                \[\leadsto \color{blue}{d4 \cdot d1} \]
            5. Applied rewrites35.4%

              \[\leadsto \color{blue}{d4 \cdot d1} \]
          3. Recombined 4 regimes into one program.
          4. Final simplification46.9%

            \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -7.4 \cdot 10^{+61}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -70000000000:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{elif}\;d2 \leq 4 \cdot 10^{-128}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
          5. Add Preprocessing

          Alternative 4: 89.4% accurate, 1.2× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d1 \leq -2.6 \cdot 10^{+159}:\\ \;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\ \mathbf{elif}\;d1 \leq 5.5 \cdot 10^{+118}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \end{array} \end{array} \]
          (FPCore (d1 d2 d3 d4)
           :precision binary64
           (if (<= d1 -2.6e+159)
             (* (- (- d3) d1) d1)
             (if (<= d1 5.5e+118) (* (- (+ d4 d2) d3) d1) (* (- d2 d1) d1))))
          double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if (d1 <= -2.6e+159) {
          		tmp = (-d3 - d1) * d1;
          	} else if (d1 <= 5.5e+118) {
          		tmp = ((d4 + d2) - d3) * d1;
          	} else {
          		tmp = (d2 - d1) * d1;
          	}
          	return tmp;
          }
          
          real(8) function code(d1, d2, d3, d4)
              real(8), intent (in) :: d1
              real(8), intent (in) :: d2
              real(8), intent (in) :: d3
              real(8), intent (in) :: d4
              real(8) :: tmp
              if (d1 <= (-2.6d+159)) then
                  tmp = (-d3 - d1) * d1
              else if (d1 <= 5.5d+118) then
                  tmp = ((d4 + d2) - d3) * d1
              else
                  tmp = (d2 - d1) * d1
              end if
              code = tmp
          end function
          
          public static double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if (d1 <= -2.6e+159) {
          		tmp = (-d3 - d1) * d1;
          	} else if (d1 <= 5.5e+118) {
          		tmp = ((d4 + d2) - d3) * d1;
          	} else {
          		tmp = (d2 - d1) * d1;
          	}
          	return tmp;
          }
          
          def code(d1, d2, d3, d4):
          	tmp = 0
          	if d1 <= -2.6e+159:
          		tmp = (-d3 - d1) * d1
          	elif d1 <= 5.5e+118:
          		tmp = ((d4 + d2) - d3) * d1
          	else:
          		tmp = (d2 - d1) * d1
          	return tmp
          
          function code(d1, d2, d3, d4)
          	tmp = 0.0
          	if (d1 <= -2.6e+159)
          		tmp = Float64(Float64(Float64(-d3) - d1) * d1);
          	elseif (d1 <= 5.5e+118)
          		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
          	else
          		tmp = Float64(Float64(d2 - d1) * d1);
          	end
          	return tmp
          end
          
          function tmp_2 = code(d1, d2, d3, d4)
          	tmp = 0.0;
          	if (d1 <= -2.6e+159)
          		tmp = (-d3 - d1) * d1;
          	elseif (d1 <= 5.5e+118)
          		tmp = ((d4 + d2) - d3) * d1;
          	else
          		tmp = (d2 - d1) * d1;
          	end
          	tmp_2 = tmp;
          end
          
          code[d1_, d2_, d3_, d4_] := If[LessEqual[d1, -2.6e+159], N[(N[((-d3) - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d1, 5.5e+118], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;d1 \leq -2.6 \cdot 10^{+159}:\\
          \;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\
          
          \mathbf{elif}\;d1 \leq 5.5 \cdot 10^{+118}:\\
          \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
          
          \mathbf{else}:\\
          \;\;\;\;\left(d2 - d1\right) \cdot d1\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if d1 < -2.6e159

            1. Initial program 42.9%

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

              \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
            4. Step-by-step derivation
              1. associate--r+N/A

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

                \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
              3. unpow2N/A

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

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

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

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

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

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

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

              \[\leadsto \left(-1 \cdot d3 - d1\right) \cdot d1 \]
            7. Step-by-step derivation
              1. Applied rewrites100.0%

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

              if -2.6e159 < d1 < 5.5000000000000003e118

              1. Initial program 98.4%

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

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

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

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

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

                  \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
                5. lower-+.f6494.7

                  \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
              5. Applied rewrites94.7%

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

              if 5.5000000000000003e118 < d1

              1. Initial program 57.1%

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

                \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
              4. Step-by-step derivation
                1. associate--r+N/A

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

                  \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
                3. unpow2N/A

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

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

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

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

                  \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
                8. lower--.f6496.4

                  \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
              5. Applied rewrites96.4%

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

                \[\leadsto \left(d2 - d1\right) \cdot d1 \]
              7. Step-by-step derivation
                1. Applied rewrites89.3%

                  \[\leadsto \left(d2 - d1\right) \cdot d1 \]
              8. Recombined 3 regimes into one program.
              9. Final simplification94.8%

                \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -2.6 \cdot 10^{+159}:\\ \;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\ \mathbf{elif}\;d1 \leq 5.5 \cdot 10^{+118}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \end{array} \]
              10. Add Preprocessing

              Alternative 5: 67.9% accurate, 1.4× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -2.05 \cdot 10^{+100} \lor \neg \left(d3 \leq 2.4 \cdot 10^{+115}\right):\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \end{array} \end{array} \]
              (FPCore (d1 d2 d3 d4)
               :precision binary64
               (if (or (<= d3 -2.05e+100) (not (<= d3 2.4e+115)))
                 (* (- d3) d1)
                 (* (+ d2 d4) d1)))
              double code(double d1, double d2, double d3, double d4) {
              	double tmp;
              	if ((d3 <= -2.05e+100) || !(d3 <= 2.4e+115)) {
              		tmp = -d3 * d1;
              	} else {
              		tmp = (d2 + d4) * d1;
              	}
              	return tmp;
              }
              
              real(8) function code(d1, d2, d3, d4)
                  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 <= (-2.05d+100)) .or. (.not. (d3 <= 2.4d+115))) then
                      tmp = -d3 * d1
                  else
                      tmp = (d2 + d4) * d1
                  end if
                  code = tmp
              end function
              
              public static double code(double d1, double d2, double d3, double d4) {
              	double tmp;
              	if ((d3 <= -2.05e+100) || !(d3 <= 2.4e+115)) {
              		tmp = -d3 * d1;
              	} else {
              		tmp = (d2 + d4) * d1;
              	}
              	return tmp;
              }
              
              def code(d1, d2, d3, d4):
              	tmp = 0
              	if (d3 <= -2.05e+100) or not (d3 <= 2.4e+115):
              		tmp = -d3 * d1
              	else:
              		tmp = (d2 + d4) * d1
              	return tmp
              
              function code(d1, d2, d3, d4)
              	tmp = 0.0
              	if ((d3 <= -2.05e+100) || !(d3 <= 2.4e+115))
              		tmp = Float64(Float64(-d3) * d1);
              	else
              		tmp = Float64(Float64(d2 + d4) * d1);
              	end
              	return tmp
              end
              
              function tmp_2 = code(d1, d2, d3, d4)
              	tmp = 0.0;
              	if ((d3 <= -2.05e+100) || ~((d3 <= 2.4e+115)))
              		tmp = -d3 * d1;
              	else
              		tmp = (d2 + d4) * d1;
              	end
              	tmp_2 = tmp;
              end
              
              code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -2.05e+100], N[Not[LessEqual[d3, 2.4e+115]], $MachinePrecision]], N[((-d3) * d1), $MachinePrecision], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              \mathbf{if}\;d3 \leq -2.05 \cdot 10^{+100} \lor \neg \left(d3 \leq 2.4 \cdot 10^{+115}\right):\\
              \;\;\;\;\left(-d3\right) \cdot d1\\
              
              \mathbf{else}:\\
              \;\;\;\;\left(d2 + d4\right) \cdot d1\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if d3 < -2.0500000000000001e100 or 2.4e115 < d3

                1. Initial program 84.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \mathsf{fma}\left(d4, d1, d1 \cdot \color{blue}{\left(\left(d2 - d3\right) - d1\right)}\right) \]
                  15. lower--.f6499.0

                    \[\leadsto \mathsf{fma}\left(d4, d1, d1 \cdot \left(\color{blue}{\left(d2 - d3\right)} - d1\right)\right) \]
                4. Applied rewrites99.0%

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

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

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

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

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

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

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

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

                if -2.0500000000000001e100 < d3 < 2.4e115

                1. Initial program 87.2%

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

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

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

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

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

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

                    \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
                5. Applied rewrites77.2%

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

                  \[\leadsto d1 \cdot \color{blue}{\left(d2 + d4\right)} \]
                7. Step-by-step derivation
                  1. Applied rewrites70.5%

                    \[\leadsto \left(d2 + d4\right) \cdot \color{blue}{d1} \]
                8. Recombined 2 regimes into one program.
                9. Final simplification70.3%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -2.05 \cdot 10^{+100} \lor \neg \left(d3 \leq 2.4 \cdot 10^{+115}\right):\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \end{array} \]
                10. Add Preprocessing

                Alternative 6: 39.7% accurate, 1.5× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -3.25 \cdot 10^{+32}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq 4 \cdot 10^{-128}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
                (FPCore (d1 d2 d3 d4)
                 :precision binary64
                 (if (<= d2 -3.25e+32) (* d2 d1) (if (<= d2 4e-128) (* (- d3) d1) (* d4 d1))))
                double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if (d2 <= -3.25e+32) {
                		tmp = d2 * d1;
                	} else if (d2 <= 4e-128) {
                		tmp = -d3 * d1;
                	} else {
                		tmp = d4 * d1;
                	}
                	return tmp;
                }
                
                real(8) function code(d1, d2, d3, d4)
                    real(8), intent (in) :: d1
                    real(8), intent (in) :: d2
                    real(8), intent (in) :: d3
                    real(8), intent (in) :: d4
                    real(8) :: tmp
                    if (d2 <= (-3.25d+32)) then
                        tmp = d2 * d1
                    else if (d2 <= 4d-128) then
                        tmp = -d3 * d1
                    else
                        tmp = d4 * d1
                    end if
                    code = tmp
                end function
                
                public static double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if (d2 <= -3.25e+32) {
                		tmp = d2 * d1;
                	} else if (d2 <= 4e-128) {
                		tmp = -d3 * d1;
                	} else {
                		tmp = d4 * d1;
                	}
                	return tmp;
                }
                
                def code(d1, d2, d3, d4):
                	tmp = 0
                	if d2 <= -3.25e+32:
                		tmp = d2 * d1
                	elif d2 <= 4e-128:
                		tmp = -d3 * d1
                	else:
                		tmp = d4 * d1
                	return tmp
                
                function code(d1, d2, d3, d4)
                	tmp = 0.0
                	if (d2 <= -3.25e+32)
                		tmp = Float64(d2 * d1);
                	elseif (d2 <= 4e-128)
                		tmp = Float64(Float64(-d3) * d1);
                	else
                		tmp = Float64(d4 * d1);
                	end
                	return tmp
                end
                
                function tmp_2 = code(d1, d2, d3, d4)
                	tmp = 0.0;
                	if (d2 <= -3.25e+32)
                		tmp = d2 * d1;
                	elseif (d2 <= 4e-128)
                		tmp = -d3 * d1;
                	else
                		tmp = d4 * d1;
                	end
                	tmp_2 = tmp;
                end
                
                code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -3.25e+32], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, 4e-128], N[((-d3) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;d2 \leq -3.25 \cdot 10^{+32}:\\
                \;\;\;\;d2 \cdot d1\\
                
                \mathbf{elif}\;d2 \leq 4 \cdot 10^{-128}:\\
                \;\;\;\;\left(-d3\right) \cdot d1\\
                
                \mathbf{else}:\\
                \;\;\;\;d4 \cdot d1\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 3 regimes
                2. if d2 < -3.2499999999999997e32

                  1. Initial program 77.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(d4, d1, d1 \cdot \color{blue}{\left(\left(d2 - d3\right) - d1\right)}\right) \]
                    15. lower--.f6497.0

                      \[\leadsto \mathsf{fma}\left(d4, d1, d1 \cdot \left(\color{blue}{\left(d2 - d3\right)} - d1\right)\right) \]
                  4. Applied rewrites97.0%

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

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

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

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

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

                  if -3.2499999999999997e32 < d2 < 4.00000000000000022e-128

                  1. Initial program 89.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(d4, d1, d1 \cdot \color{blue}{\left(\left(d2 - d3\right) - d1\right)}\right) \]
                    15. lower--.f6498.9

                      \[\leadsto \mathsf{fma}\left(d4, d1, d1 \cdot \left(\color{blue}{\left(d2 - d3\right)} - d1\right)\right) \]
                  4. Applied rewrites98.9%

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

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

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

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

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

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

                      \[\leadsto \color{blue}{\left(-d3\right)} \cdot d1 \]
                  7. Applied rewrites51.7%

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

                  if 4.00000000000000022e-128 < d2

                  1. Initial program 89.5%

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

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

                      \[\leadsto \color{blue}{d4 \cdot d1} \]
                    2. lower-*.f6435.4

                      \[\leadsto \color{blue}{d4 \cdot d1} \]
                  5. Applied rewrites35.4%

                    \[\leadsto \color{blue}{d4 \cdot d1} \]
                3. Recombined 3 regimes into one program.
                4. Final simplification45.8%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -3.25 \cdot 10^{+32}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq 4 \cdot 10^{-128}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
                5. Add Preprocessing

                Alternative 7: 85.5% accurate, 1.7× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 3.1 \cdot 10^{+34}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
                (FPCore (d1 d2 d3 d4)
                 :precision binary64
                 (if (<= d4 3.1e+34) (* (- (- d2 d3) d1) d1) (* (- (+ d4 d2) d3) d1)))
                double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if (d4 <= 3.1e+34) {
                		tmp = ((d2 - d3) - d1) * d1;
                	} else {
                		tmp = ((d4 + d2) - d3) * d1;
                	}
                	return tmp;
                }
                
                real(8) function code(d1, d2, d3, d4)
                    real(8), intent (in) :: d1
                    real(8), intent (in) :: d2
                    real(8), intent (in) :: d3
                    real(8), intent (in) :: d4
                    real(8) :: tmp
                    if (d4 <= 3.1d+34) then
                        tmp = ((d2 - d3) - d1) * d1
                    else
                        tmp = ((d4 + d2) - d3) * d1
                    end if
                    code = tmp
                end function
                
                public static double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if (d4 <= 3.1e+34) {
                		tmp = ((d2 - d3) - d1) * d1;
                	} else {
                		tmp = ((d4 + d2) - d3) * d1;
                	}
                	return tmp;
                }
                
                def code(d1, d2, d3, d4):
                	tmp = 0
                	if d4 <= 3.1e+34:
                		tmp = ((d2 - d3) - d1) * d1
                	else:
                		tmp = ((d4 + d2) - d3) * d1
                	return tmp
                
                function code(d1, d2, d3, d4)
                	tmp = 0.0
                	if (d4 <= 3.1e+34)
                		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
                	else
                		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
                	end
                	return tmp
                end
                
                function tmp_2 = code(d1, d2, d3, d4)
                	tmp = 0.0;
                	if (d4 <= 3.1e+34)
                		tmp = ((d2 - d3) - d1) * d1;
                	else
                		tmp = ((d4 + d2) - d3) * d1;
                	end
                	tmp_2 = tmp;
                end
                
                code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 3.1e+34], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;d4 \leq 3.1 \cdot 10^{+34}:\\
                \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
                
                \mathbf{else}:\\
                \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if d4 < 3.09999999999999977e34

                  1. Initial program 86.9%

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

                    \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                  4. Step-by-step derivation
                    1. associate--r+N/A

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

                      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
                    3. unpow2N/A

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

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

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

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

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

                      \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
                  5. Applied rewrites81.8%

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

                  if 3.09999999999999977e34 < d4

                  1. Initial program 83.6%

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

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

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

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

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

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

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

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

                  \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 3.1 \cdot 10^{+34}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \end{array} \]
                5. Add Preprocessing

                Alternative 8: 63.0% accurate, 2.0× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -3.25 \cdot 10^{+32}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \end{array} \]
                (FPCore (d1 d2 d3 d4)
                 :precision binary64
                 (if (<= d2 -3.25e+32) (* (- d2 d1) d1) (* (- d4 d3) d1)))
                double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if (d2 <= -3.25e+32) {
                		tmp = (d2 - d1) * d1;
                	} else {
                		tmp = (d4 - d3) * d1;
                	}
                	return tmp;
                }
                
                real(8) function code(d1, d2, d3, d4)
                    real(8), intent (in) :: d1
                    real(8), intent (in) :: d2
                    real(8), intent (in) :: d3
                    real(8), intent (in) :: d4
                    real(8) :: tmp
                    if (d2 <= (-3.25d+32)) then
                        tmp = (d2 - d1) * d1
                    else
                        tmp = (d4 - d3) * d1
                    end if
                    code = tmp
                end function
                
                public static double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if (d2 <= -3.25e+32) {
                		tmp = (d2 - d1) * d1;
                	} else {
                		tmp = (d4 - d3) * d1;
                	}
                	return tmp;
                }
                
                def code(d1, d2, d3, d4):
                	tmp = 0
                	if d2 <= -3.25e+32:
                		tmp = (d2 - d1) * d1
                	else:
                		tmp = (d4 - d3) * d1
                	return tmp
                
                function code(d1, d2, d3, d4)
                	tmp = 0.0
                	if (d2 <= -3.25e+32)
                		tmp = Float64(Float64(d2 - d1) * d1);
                	else
                		tmp = Float64(Float64(d4 - d3) * d1);
                	end
                	return tmp
                end
                
                function tmp_2 = code(d1, d2, d3, d4)
                	tmp = 0.0;
                	if (d2 <= -3.25e+32)
                		tmp = (d2 - d1) * d1;
                	else
                		tmp = (d4 - d3) * d1;
                	end
                	tmp_2 = tmp;
                end
                
                code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -3.25e+32], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;d2 \leq -3.25 \cdot 10^{+32}:\\
                \;\;\;\;\left(d2 - d1\right) \cdot d1\\
                
                \mathbf{else}:\\
                \;\;\;\;\left(d4 - d3\right) \cdot d1\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if d2 < -3.2499999999999997e32

                  1. Initial program 77.3%

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

                    \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                  4. Step-by-step derivation
                    1. associate--r+N/A

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

                      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
                    3. unpow2N/A

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

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

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

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

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

                      \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
                  5. Applied rewrites80.7%

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

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

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

                    if -3.2499999999999997e32 < d2

                    1. Initial program 89.4%

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

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

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

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

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

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

                        \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
                    5. Applied rewrites83.2%

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

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

                        \[\leadsto \left(d4 - d3\right) \cdot d1 \]
                    8. Recombined 2 regimes into one program.
                    9. Final simplification67.8%

                      \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -3.25 \cdot 10^{+32}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \]
                    10. Add Preprocessing

                    Alternative 9: 63.8% accurate, 2.0× speedup?

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

                      1. Initial program 77.3%

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

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

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

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

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

                          \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
                        5. lower-+.f6483.4

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

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

                        \[\leadsto d1 \cdot \color{blue}{\left(d2 + d4\right)} \]
                      7. Step-by-step derivation
                        1. Applied rewrites72.9%

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

                        if -3e32 < d2

                        1. Initial program 89.4%

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

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

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

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

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

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

                            \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
                        5. Applied rewrites83.2%

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

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

                            \[\leadsto \left(d4 - d3\right) \cdot d1 \]
                        8. Recombined 2 regimes into one program.
                        9. Final simplification68.4%

                          \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -3 \cdot 10^{+32}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \]
                        10. Add Preprocessing

                        Alternative 10: 39.6% accurate, 2.5× speedup?

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

                          1. Initial program 75.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              \[\leadsto \mathsf{fma}\left(d4, d1, d1 \cdot \color{blue}{\left(\left(d2 - d3\right) - d1\right)}\right) \]
                            15. lower--.f6496.7

                              \[\leadsto \mathsf{fma}\left(d4, d1, d1 \cdot \left(\color{blue}{\left(d2 - d3\right)} - d1\right)\right) \]
                          4. Applied rewrites96.7%

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

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

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

                              \[\leadsto \color{blue}{d2 \cdot d1} \]
                          7. Applied rewrites54.8%

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

                          if -5.7000000000000002e51 < d2

                          1. Initial program 89.7%

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

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

                              \[\leadsto \color{blue}{d4 \cdot d1} \]
                            2. lower-*.f6434.6

                              \[\leadsto \color{blue}{d4 \cdot d1} \]
                          5. Applied rewrites34.6%

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

                          \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -5.7 \cdot 10^{+51}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
                        5. Add Preprocessing

                        Alternative 11: 31.3% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto \mathsf{fma}\left(d4, d1, d1 \cdot \color{blue}{\left(\left(d2 - d3\right) - d1\right)}\right) \]
                          15. lower--.f6498.8

                            \[\leadsto \mathsf{fma}\left(d4, d1, d1 \cdot \left(\color{blue}{\left(d2 - d3\right)} - d1\right)\right) \]
                        4. Applied rewrites98.8%

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

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

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

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

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

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

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

                        Reproduce

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