FastMath dist4

Percentage Accurate: 87.1% → 97.1%
Time: 12.2s
Alternatives: 12
Speedup: 1.7×

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 12 alternatives:

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

Initial Program: 87.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
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: 97.1% accurate, 1.7× speedup?

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

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

    \[\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. associate--l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)} \]
  5. Final simplification99.2%

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

Alternative 2: 63.0% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;d4 \leq 7 \cdot 10^{-53}:\\
\;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\

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

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


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

    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 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--.f6476.3

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

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

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

      if -1.9500000000000001e-283 < d4 < 6.99999999999999987e-53

      1. Initial program 98.2%

        \[\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--.f6498.3

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

        \[\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 rewrites73.6%

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

        if 6.99999999999999987e-53 < d4 < 6.50000000000000001e100

        1. Initial program 99.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--.f6480.5

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

          \[\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 rewrites77.0%

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

          if 6.50000000000000001e100 < d4

          1. Initial program 84.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-+.f6487.4

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

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

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

          Alternative 3: 89.1% accurate, 1.2× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(d2 - d1\right) \cdot d1\\ \mathbf{if}\;d1 \leq -1.6 \cdot 10^{+124}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d1 \leq 3.2 \cdot 10^{+142}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
          (FPCore (d1 d2 d3 d4)
           :precision binary64
           (let* ((t_0 (* (- d2 d1) d1)))
             (if (<= d1 -1.6e+124)
               t_0
               (if (<= d1 3.2e+142) (* (- (+ d4 d2) d3) d1) t_0))))
          double code(double d1, double d2, double d3, double d4) {
          	double t_0 = (d2 - d1) * d1;
          	double tmp;
          	if (d1 <= -1.6e+124) {
          		tmp = t_0;
          	} else if (d1 <= 3.2e+142) {
          		tmp = ((d4 + d2) - d3) * d1;
          	} else {
          		tmp = t_0;
          	}
          	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) :: t_0
              real(8) :: tmp
              t_0 = (d2 - d1) * d1
              if (d1 <= (-1.6d+124)) then
                  tmp = t_0
              else if (d1 <= 3.2d+142) then
                  tmp = ((d4 + d2) - d3) * d1
              else
                  tmp = t_0
              end if
              code = tmp
          end function
          
          public static double code(double d1, double d2, double d3, double d4) {
          	double t_0 = (d2 - d1) * d1;
          	double tmp;
          	if (d1 <= -1.6e+124) {
          		tmp = t_0;
          	} else if (d1 <= 3.2e+142) {
          		tmp = ((d4 + d2) - d3) * d1;
          	} else {
          		tmp = t_0;
          	}
          	return tmp;
          }
          
          def code(d1, d2, d3, d4):
          	t_0 = (d2 - d1) * d1
          	tmp = 0
          	if d1 <= -1.6e+124:
          		tmp = t_0
          	elif d1 <= 3.2e+142:
          		tmp = ((d4 + d2) - d3) * d1
          	else:
          		tmp = t_0
          	return tmp
          
          function code(d1, d2, d3, d4)
          	t_0 = Float64(Float64(d2 - d1) * d1)
          	tmp = 0.0
          	if (d1 <= -1.6e+124)
          		tmp = t_0;
          	elseif (d1 <= 3.2e+142)
          		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
          	else
          		tmp = t_0;
          	end
          	return tmp
          end
          
          function tmp_2 = code(d1, d2, d3, d4)
          	t_0 = (d2 - d1) * d1;
          	tmp = 0.0;
          	if (d1 <= -1.6e+124)
          		tmp = t_0;
          	elseif (d1 <= 3.2e+142)
          		tmp = ((d4 + d2) - d3) * d1;
          	else
          		tmp = t_0;
          	end
          	tmp_2 = tmp;
          end
          
          code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d1, -1.6e+124], t$95$0, If[LessEqual[d1, 3.2e+142], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_0 := \left(d2 - d1\right) \cdot d1\\
          \mathbf{if}\;d1 \leq -1.6 \cdot 10^{+124}:\\
          \;\;\;\;t\_0\\
          
          \mathbf{elif}\;d1 \leq 3.2 \cdot 10^{+142}:\\
          \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
          
          \mathbf{else}:\\
          \;\;\;\;t\_0\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if d1 < -1.59999999999999996e124 or 3.20000000000000005e142 < d1

            1. Initial program 64.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 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--.f6492.8

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

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

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

              if -1.59999999999999996e124 < d1 < 3.20000000000000005e142

              1. Initial program 99.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-+.f6494.4

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

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

            Alternative 4: 66.1% accurate, 1.4× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(-d3\right) \cdot d1\\ \mathbf{if}\;d3 \leq -1.02 \cdot 10^{+113}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq 4.1 \cdot 10^{+52}:\\ \;\;\;\;\left(d4 + d2\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
            (FPCore (d1 d2 d3 d4)
             :precision binary64
             (let* ((t_0 (* (- d3) d1)))
               (if (<= d3 -1.02e+113) t_0 (if (<= d3 4.1e+52) (* (+ d4 d2) d1) t_0))))
            double code(double d1, double d2, double d3, double d4) {
            	double t_0 = -d3 * d1;
            	double tmp;
            	if (d3 <= -1.02e+113) {
            		tmp = t_0;
            	} else if (d3 <= 4.1e+52) {
            		tmp = (d4 + d2) * d1;
            	} else {
            		tmp = t_0;
            	}
            	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) :: t_0
                real(8) :: tmp
                t_0 = -d3 * d1
                if (d3 <= (-1.02d+113)) then
                    tmp = t_0
                else if (d3 <= 4.1d+52) then
                    tmp = (d4 + d2) * d1
                else
                    tmp = t_0
                end if
                code = tmp
            end function
            
            public static double code(double d1, double d2, double d3, double d4) {
            	double t_0 = -d3 * d1;
            	double tmp;
            	if (d3 <= -1.02e+113) {
            		tmp = t_0;
            	} else if (d3 <= 4.1e+52) {
            		tmp = (d4 + d2) * d1;
            	} else {
            		tmp = t_0;
            	}
            	return tmp;
            }
            
            def code(d1, d2, d3, d4):
            	t_0 = -d3 * d1
            	tmp = 0
            	if d3 <= -1.02e+113:
            		tmp = t_0
            	elif d3 <= 4.1e+52:
            		tmp = (d4 + d2) * d1
            	else:
            		tmp = t_0
            	return tmp
            
            function code(d1, d2, d3, d4)
            	t_0 = Float64(Float64(-d3) * d1)
            	tmp = 0.0
            	if (d3 <= -1.02e+113)
            		tmp = t_0;
            	elseif (d3 <= 4.1e+52)
            		tmp = Float64(Float64(d4 + d2) * d1);
            	else
            		tmp = t_0;
            	end
            	return tmp
            end
            
            function tmp_2 = code(d1, d2, d3, d4)
            	t_0 = -d3 * d1;
            	tmp = 0.0;
            	if (d3 <= -1.02e+113)
            		tmp = t_0;
            	elseif (d3 <= 4.1e+52)
            		tmp = (d4 + d2) * d1;
            	else
            		tmp = t_0;
            	end
            	tmp_2 = tmp;
            end
            
            code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[((-d3) * d1), $MachinePrecision]}, If[LessEqual[d3, -1.02e+113], t$95$0, If[LessEqual[d3, 4.1e+52], N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_0 := \left(-d3\right) \cdot d1\\
            \mathbf{if}\;d3 \leq -1.02 \cdot 10^{+113}:\\
            \;\;\;\;t\_0\\
            
            \mathbf{elif}\;d3 \leq 4.1 \cdot 10^{+52}:\\
            \;\;\;\;\left(d4 + d2\right) \cdot d1\\
            
            \mathbf{else}:\\
            \;\;\;\;t\_0\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if d3 < -1.02000000000000002e113 or 4.1e52 < d3

              1. Initial program 86.8%

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

                \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
              4. 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.8

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

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

              if -1.02000000000000002e113 < d3 < 4.1e52

              1. Initial program 93.0%

                \[\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-+.f6478.0

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

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

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

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

              Alternative 5: 39.4% accurate, 1.5× speedup?

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

                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 d2 around inf

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

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

                    \[\leadsto \color{blue}{d2 \cdot d1} \]
                5. Applied rewrites30.8%

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

                if -1.9500000000000001e-283 < d4 < 9.49999999999999927e28

                1. Initial program 98.5%

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

                  \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
                4. 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.f6455.7

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

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

                if 9.49999999999999927e28 < d4

                1. Initial program 88.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 inf

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

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

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

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

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

              Alternative 6: 39.0% accurate, 1.5× speedup?

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

                1. Initial program 85.0%

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

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

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

                    \[\leadsto \color{blue}{d2 \cdot d1} \]
                5. Applied rewrites69.3%

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

                if -5.50000000000000036e77 < d2 < -7.49999999999999971e-277

                1. Initial program 91.7%

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

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

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

                if -7.49999999999999971e-277 < d2

                1. Initial program 91.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 inf

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

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

                    \[\leadsto \color{blue}{d4 \cdot d1} \]
                5. Applied rewrites33.0%

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

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

              Alternative 7: 85.3% accurate, 1.7× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 5.2 \cdot 10^{+26}:\\ \;\;\;\;\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 5.2e+26) (* (- (- d2 d3) d1) d1) (* (- (+ d4 d2) d3) d1)))
              double code(double d1, double d2, double d3, double d4) {
              	double tmp;
              	if (d4 <= 5.2e+26) {
              		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 <= 5.2d+26) 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 <= 5.2e+26) {
              		tmp = ((d2 - d3) - d1) * d1;
              	} else {
              		tmp = ((d4 + d2) - d3) * d1;
              	}
              	return tmp;
              }
              
              def code(d1, d2, d3, d4):
              	tmp = 0
              	if d4 <= 5.2e+26:
              		tmp = ((d2 - d3) - d1) * d1
              	else:
              		tmp = ((d4 + d2) - d3) * d1
              	return tmp
              
              function code(d1, d2, d3, d4)
              	tmp = 0.0
              	if (d4 <= 5.2e+26)
              		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 <= 5.2e+26)
              		tmp = ((d2 - d3) - d1) * d1;
              	else
              		tmp = ((d4 + d2) - d3) * d1;
              	end
              	tmp_2 = tmp;
              end
              
              code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 5.2e+26], 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 5.2 \cdot 10^{+26}:\\
              \;\;\;\;\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 < 5.20000000000000004e26

                1. Initial program 91.0%

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

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

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

                if 5.20000000000000004e26 < d4

                1. Initial program 89.1%

                  \[\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-+.f6491.0

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

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

              Alternative 8: 62.8% accurate, 2.0× speedup?

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

                1. Initial program 89.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--.f6489.4

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

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

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

                  if -5.59999999999999975e-6 < d2

                  1. Initial program 91.0%

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

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

                    \[\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.0%

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

                  Alternative 9: 62.6% accurate, 2.0× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.1 \cdot 10^{-7}:\\ \;\;\;\;\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 -1.1e-7) (* (- d2 d1) d1) (* (- d4 d3) d1)))
                  double code(double d1, double d2, double d3, double d4) {
                  	double tmp;
                  	if (d2 <= -1.1e-7) {
                  		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 <= (-1.1d-7)) 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 <= -1.1e-7) {
                  		tmp = (d2 - d1) * d1;
                  	} else {
                  		tmp = (d4 - d3) * d1;
                  	}
                  	return tmp;
                  }
                  
                  def code(d1, d2, d3, d4):
                  	tmp = 0
                  	if d2 <= -1.1e-7:
                  		tmp = (d2 - d1) * d1
                  	else:
                  		tmp = (d4 - d3) * d1
                  	return tmp
                  
                  function code(d1, d2, d3, d4)
                  	tmp = 0.0
                  	if (d2 <= -1.1e-7)
                  		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 <= -1.1e-7)
                  		tmp = (d2 - d1) * d1;
                  	else
                  		tmp = (d4 - d3) * d1;
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.1e-7], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;d2 \leq -1.1 \cdot 10^{-7}:\\
                  \;\;\;\;\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 < -1.1000000000000001e-7

                    1. Initial program 89.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--.f6489.4

                        \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
                    5. Applied rewrites89.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 rewrites69.3%

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

                      if -1.1000000000000001e-7 < d2

                      1. Initial program 91.0%

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

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

                        \[\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.0%

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

                      Alternative 10: 64.0% accurate, 2.0× speedup?

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

                        1. Initial program 85.0%

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

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

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

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

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

                          if -5.80000000000000034e78 < d2

                          1. Initial program 91.8%

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

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

                            \[\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 rewrites64.6%

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

                          Alternative 11: 38.1% accurate, 2.5× speedup?

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

                            1. Initial program 88.5%

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

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

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

                                \[\leadsto \color{blue}{d2 \cdot d1} \]
                            5. Applied rewrites52.9%

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

                            if -8.2000000000000004e-13 < d2

                            1. Initial program 91.4%

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

                                \[\leadsto \color{blue}{d4 \cdot d1} \]
                            5. Applied rewrites36.2%

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

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

                          Alternative 12: 30.3% accurate, 5.0× speedup?

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

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

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

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

                              \[\leadsto \color{blue}{d2 \cdot d1} \]
                          5. Applied rewrites31.3%

                            \[\leadsto \color{blue}{d2 \cdot d1} \]
                          6. Final simplification31.3%

                            \[\leadsto d1 \cdot d2 \]
                          7. 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 2024288 
                          (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)))