FastMath dist4

Percentage Accurate: 88.2% → 100.0%
Time: 17.2s
Alternatives: 14
Speedup: 2.0×

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 14 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: 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}
Derivation
  1. Initial program 87.9%

    \[\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. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 39.9% accurate, 1.2× speedup?

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

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

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

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

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


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

    1. Initial program 86.3%

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

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

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

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

    if 5.1999999999999998e-298 < d4 < 7.0000000000000001e-52

    1. Initial program 94.5%

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

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

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

    if 7.0000000000000001e-52 < d4 < 3.99999999999999971e75

    1. Initial program 95.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. 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.f6443.1

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

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

    if 3.99999999999999971e75 < d4

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

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

        \[\leadsto \color{blue}{d1 \cdot d4} \]
    5. Applied rewrites72.9%

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

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

Alternative 3: 91.8% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 + \left(d4 - d1\right)\right)\\ \mathbf{if}\;d1 \leq -8 \cdot 10^{+79}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d1 \leq 1.95 \cdot 10^{+43}:\\ \;\;\;\;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 (+ d2 (- d4 d1)))))
   (if (<= d1 -8e+79) t_0 (if (<= d1 1.95e+43) (* d1 (+ d2 (- d4 d3))) t_0))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 + (d4 - d1));
	double tmp;
	if (d1 <= -8e+79) {
		tmp = t_0;
	} else if (d1 <= 1.95e+43) {
		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 * (d2 + (d4 - d1))
    if (d1 <= (-8d+79)) then
        tmp = t_0
    else if (d1 <= 1.95d+43) 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 * (d2 + (d4 - d1));
	double tmp;
	if (d1 <= -8e+79) {
		tmp = t_0;
	} else if (d1 <= 1.95e+43) {
		tmp = d1 * (d2 + (d4 - d3));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 + (d4 - d1))
	tmp = 0
	if d1 <= -8e+79:
		tmp = t_0
	elif d1 <= 1.95e+43:
		tmp = d1 * (d2 + (d4 - d3))
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 + Float64(d4 - d1)))
	tmp = 0.0
	if (d1 <= -8e+79)
		tmp = t_0;
	elseif (d1 <= 1.95e+43)
		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 * (d2 + (d4 - d1));
	tmp = 0.0;
	if (d1 <= -8e+79)
		tmp = t_0;
	elseif (d1 <= 1.95e+43)
		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[(d2 + N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d1, -8e+79], t$95$0, If[LessEqual[d1, 1.95e+43], N[(d1 * N[(d2 + N[(d4 - d3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

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

\mathbf{elif}\;d1 \leq 1.95 \cdot 10^{+43}:\\
\;\;\;\;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 < -7.99999999999999974e79 or 1.95e43 < d1

    1. Initial program 72.4%

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

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

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

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

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

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

        \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
      6. associate-+r+N/A

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

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

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

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

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

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

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

    if -7.99999999999999974e79 < d1 < 1.95e43

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

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

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

Alternative 4: 86.5% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -4.8 \cdot 10^{+143}:\\
\;\;\;\;d1 \cdot \left(\left(-d3\right) - d1\right)\\

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

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


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

    1. Initial program 75.9%

      \[\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. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.79999999999999959e143 < d3 < 9.7999999999999994e218

    1. Initial program 90.2%

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

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

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

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

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

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

        \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
      6. associate-+r+N/A

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

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

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

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

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

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

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

    if 9.7999999999999994e218 < d3

    1. Initial program 81.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 0

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

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

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

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

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

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

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

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

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

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

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

    Alternative 5: 62.1% accurate, 1.3× speedup?

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

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

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

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

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

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

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

          \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
        6. associate-+r+N/A

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

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

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

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

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

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

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

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

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

        if 7.79999999999999956e-47 < d4 < 2e104

        1. Initial program 96.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. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if 2e104 < d4

        1. Initial program 78.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 0

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

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

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

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

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

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

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

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

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

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

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

        Alternative 6: 61.0% accurate, 1.4× speedup?

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

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

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

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

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

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

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

              \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
            6. associate-+r+N/A

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

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

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

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

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

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

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

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

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

            if 9.4999999999999998e-51 < d4 < 2.80000000000000008e73

            1. Initial program 95.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 0

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

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

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

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

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

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

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

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

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

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

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

              if 2.80000000000000008e73 < d4

              1. Initial program 81.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 0

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

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

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

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

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

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

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

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

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

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

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

              Alternative 7: 66.0% accurate, 1.4× speedup?

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

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

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

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

                if -2.39999999999999989e123 < d1 < 5.5000000000000001e113

                1. Initial program 98.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 0

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

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

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

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

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

                    \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
                  6. associate-+r+N/A

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

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

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

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

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

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

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

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

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

                Alternative 8: 39.7% accurate, 1.5× speedup?

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

                  1. Initial program 86.3%

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

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

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

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

                  if 5.1999999999999998e-298 < d4 < 2.19999999999999999e111

                  1. Initial program 95.4%

                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                  2. Add Preprocessing
                  3. Taylor expanded in d1 around 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.f6441.2

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

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

                  if 2.19999999999999999e111 < d4

                  1. Initial program 77.3%

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

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

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

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

                Alternative 9: 83.6% accurate, 1.7× speedup?

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

                  1. Initial program 88.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  if 9.4999999999999998e-51 < d4

                  1. Initial program 85.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 0

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

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

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

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

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

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

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

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

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

                Alternative 10: 85.4% accurate, 1.7× speedup?

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

                  1. Initial program 79.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. 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--.f6490.7

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

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

                  if -1.8999999999999999e58 < d2

                  1. Initial program 90.3%

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

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

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

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

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

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

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

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

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

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

                Alternative 11: 62.0% accurate, 2.0× speedup?

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

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

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

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

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

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

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

                      \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
                    6. associate-+r+N/A

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

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

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

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

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

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

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

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

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

                    if 8.4e47 < d4

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

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

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

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

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

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

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

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

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

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

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

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

                    Alternative 12: 63.1% accurate, 2.0× speedup?

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

                      1. Initial program 90.1%

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

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

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

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

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

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

                          \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
                        6. associate-+r+N/A

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

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

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

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

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

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

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

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

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

                        if 2.19999999999999999e111 < d4

                        1. Initial program 77.3%

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

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

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

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

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

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

                            \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
                          6. associate-+r+N/A

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

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

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

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

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

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

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

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

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

                        Alternative 13: 39.2% accurate, 2.5× speedup?

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

                          1. Initial program 89.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. lower-*.f6433.9

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

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

                          if 1.4e33 < d4

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

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

                              \[\leadsto \color{blue}{d1 \cdot d4} \]
                          5. Applied rewrites65.8%

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

                        Alternative 14: 30.9% 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 87.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-*.f6430.7

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

                          \[\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 2024233 
                        (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)))