FastMath dist4

Percentage Accurate: 88.2% → 98.4%
Time: 9.0s
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: 88.2% 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.4% accurate, 1.7× speedup?

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

\\
\mathsf{fma}\left(d4, d1, d1 \cdot \left(\left(d2 - d3\right) - d1\right)\right)
\end{array}
Derivation
  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--.f6499.2

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

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

Alternative 2: 38.9% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq -7.5 \cdot 10^{-256}:\\
\;\;\;\;d1 \cdot d2\\

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

\mathbf{elif}\;d4 \leq 0.55:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\

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


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

    1. Initial program 92.1%

      \[\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. lower-*.f6431.1

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

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

    if -7.50000000000000005e-256 < d4 < -1.59999999999999999e-298

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

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

        \[\leadsto \color{blue}{\mathsf{neg}\left(d1 \cdot d3\right)} \]
      2. distribute-rgt-neg-inN/A

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)} \]
      6. lower-neg.f6459.4

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

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

    if -1.59999999999999999e-298 < d4 < 0.55000000000000004

    1. Initial program 90.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. *-commutativeN/A

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

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

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

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

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

    if 0.55000000000000004 < d4

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -7.5 \cdot 10^{-256}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq -1.6 \cdot 10^{-298}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d4 \leq 0.55:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 87.5% accurate, 1.2× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -9.5e104 or 3.4999999999999999e26 < d1

    1. Initial program 70.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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -9.5e104 < d1 < 3.4999999999999999e26

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

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

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

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

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

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

    Alternative 4: 61.6% accurate, 1.3× speedup?

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

      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 d4 around 0

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto d1 \cdot \left(\color{blue}{\left(d2 - d1\right)} - d3\right) \]
        12. lower--.f6475.5

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

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

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

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

        if -2.2999999999999998e-246 < d4 < 0.450000000000000011

        1. Initial program 91.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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if 0.450000000000000011 < d4

          1. Initial program 83.1%

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

              \[\leadsto \color{blue}{d1 \cdot d2} \]
          5. Applied rewrites20.2%

            \[\leadsto \color{blue}{d1 \cdot d2} \]
          6. Taylor expanded in d2 around 0

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

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

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

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

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

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

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

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

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

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

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

          Alternative 5: 62.9% accurate, 1.4× speedup?

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

            1. Initial program 92.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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto d1 \cdot \left(d2 - \color{blue}{d3}\right) \]
            7. Step-by-step derivation
              1. Applied rewrites56.3%

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

              if -1.59999999999999999e-298 < d4 < 0.440000000000000002

              1. Initial program 90.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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if 0.440000000000000002 < d4

                1. Initial program 83.1%

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

                    \[\leadsto \color{blue}{d1 \cdot d2} \]
                5. Applied rewrites20.2%

                  \[\leadsto \color{blue}{d1 \cdot d2} \]
                6. Taylor expanded in d2 around 0

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

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

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

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

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

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

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

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

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

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

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

                Alternative 6: 38.9% accurate, 1.5× speedup?

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

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

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

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

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

                  if -1.3499999999999999e-246 < d4 < 0.55000000000000004

                  1. Initial program 91.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 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. *-commutativeN/A

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

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

                      \[\leadsto d1 \cdot \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)} \]
                    6. lower-neg.f6445.1

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

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

                  if 0.55000000000000004 < d4

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

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

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

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

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

                Alternative 7: 84.7% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  if 0.28000000000000003 < d4

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

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

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

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

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

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

                Alternative 8: 85.0% accurate, 1.7× speedup?

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

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

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

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

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

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

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

                  if -1.49999999999999989e93 < d2

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

                    \[\leadsto \color{blue}{d1 \cdot d2} \]
                  4. Step-by-step derivation
                    1. lower-*.f6423.0

                      \[\leadsto \color{blue}{d1 \cdot d2} \]
                  5. Applied rewrites23.0%

                    \[\leadsto \color{blue}{d1 \cdot d2} \]
                  6. Taylor expanded in d2 around 0

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

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

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

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

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

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

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

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

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

                Alternative 9: 62.1% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    if 0.440000000000000002 < d4

                    1. Initial program 83.1%

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

                        \[\leadsto \color{blue}{d1 \cdot d2} \]
                    5. Applied rewrites20.2%

                      \[\leadsto \color{blue}{d1 \cdot d2} \]
                    6. Taylor expanded in d2 around 0

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

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

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

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

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

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

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

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

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

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

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

                    Alternative 10: 61.9% accurate, 2.0× speedup?

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

                      1. Initial program 69.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. lower-*.f6469.7

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

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

                      if -9.0000000000000003e128 < d2

                      1. Initial program 92.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. lower-*.f6423.9

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

                        \[\leadsto \color{blue}{d1 \cdot d2} \]
                      6. Taylor expanded in d2 around 0

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

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

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

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

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

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

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

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

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

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

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

                      Alternative 11: 39.7% accurate, 2.5× speedup?

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

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

                          \[\leadsto \color{blue}{d1 \cdot d2} \]
                        4. Step-by-step derivation
                          1. lower-*.f6463.0

                            \[\leadsto \color{blue}{d1 \cdot d2} \]
                        5. Applied rewrites63.0%

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

                        if -2.2999999999999999e75 < d2

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

                          \[\leadsto \color{blue}{d1 \cdot d4} \]
                        4. Step-by-step derivation
                          1. lower-*.f6434.2

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

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

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

                      Alternative 12: 31.2% 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 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 d2 around inf

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

                          \[\leadsto \color{blue}{d1 \cdot d2} \]
                      5. Applied rewrites29.1%

                        \[\leadsto \color{blue}{d1 \cdot d2} \]
                      6. 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 2024237 
                      (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)))