FastMath dist4

Percentage Accurate: 87.4% → 100.0%
Time: 6.2s
Alternatives: 14
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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: 87.4% 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, 1.7× speedup?

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

\\
d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)
\end{array}
Derivation
  1. Initial program 87.5%

    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
  2. Step-by-step derivation
    1. sub-neg87.5%

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

      \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
    3. associate-+r+87.5%

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

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

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

      \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
    7. associate-+r+87.5%

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
    12. associate--r-87.5%

      \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
    13. distribute-rgt-out--91.0%

      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
    14. *-commutative91.0%

      \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
    15. distribute-lft-out--92.6%

      \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
    16. distribute-lft-out--100.0%

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

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

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

Alternative 2: 61.6% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
t_0 := d1 \cdot \left(d4 - d1\right)\\
\mathbf{if}\;d2 \leq -5.4 \cdot 10^{-73}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

\mathbf{elif}\;d2 \leq -7.5 \cdot 10^{-178}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d2 \leq -4.8 \cdot 10^{-294}:\\
\;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d2 < -5.39999999999999989e-73

    1. Initial program 86.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg86.0%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+86.0%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+86.0%

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

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative86.0%

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg86.0%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-86.0%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--91.1%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative91.1%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--93.6%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

        \[\leadsto d1 \cdot \left(d2 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+80.4%

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

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

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

    if -5.39999999999999989e-73 < d2 < -7.50000000000000019e-178 or 1.04e-75 < d2

    1. Initial program 83.6%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.6%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+83.6%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+83.6%

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

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative83.6%

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg83.6%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-83.6%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--88.4%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative88.4%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--90.4%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - \left(d1 + d3\right)\right)} \]
    5. Step-by-step derivation
      1. associate--r+78.2%

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

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

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

    if -7.50000000000000019e-178 < d2 < -4.79999999999999994e-294

    1. Initial program 96.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg96.3%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+96.3%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+96.3%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d1 \cdot d2 + \left(-d1 \cdot d1\right)\right)\right)} + d4 \cdot d1 \]
      8. sub-neg96.3%

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative96.3%

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \left(\color{blue}{d2 \cdot d1} - d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      10. +-commutative96.3%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg96.3%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-96.3%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--96.3%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative96.3%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--96.3%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--99.9%

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

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

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

        \[\leadsto d1 \cdot \left(d2 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+81.1%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot \left(d1 + d3\right)\right)} \]
    8. Step-by-step derivation
      1. mul-1-neg81.1%

        \[\leadsto \color{blue}{-d1 \cdot \left(d1 + d3\right)} \]
      2. distribute-rgt-neg-in81.1%

        \[\leadsto \color{blue}{d1 \cdot \left(-\left(d1 + d3\right)\right)} \]
    9. Simplified81.1%

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

    if -4.79999999999999994e-294 < d2 < 1.04e-75

    1. Initial program 93.5%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+93.5%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. distribute-lft-out--93.5%

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

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

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

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d1\right) + d1 \cdot \left(d2 - d3\right)} \]
      2. distribute-lft-out--93.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -5.4 \cdot 10^{-73}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -7.5 \cdot 10^{-178}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d2 \leq -4.8 \cdot 10^{-294}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{elif}\;d2 \leq 1.04 \cdot 10^{-75}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 3: 39.8% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
t_0 := d1 \cdot \left(-d3\right)\\
\mathbf{if}\;d4 \leq 6.5 \cdot 10^{-278}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d4 \leq 1.7 \cdot 10^{-153}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 1.25 \cdot 10^{-63}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d4 \leq 3.4 \cdot 10^{+64}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 6.5e-278 or 1.6999999999999999e-153 < d4 < 1.25e-63

    1. Initial program 88.6%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg88.6%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+88.6%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+88.6%

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

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative88.6%

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg88.6%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-88.6%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--91.8%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative91.8%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--93.7%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

    if 6.5e-278 < d4 < 1.6999999999999999e-153 or 1.25e-63 < d4 < 3.4000000000000002e64

    1. Initial program 84.8%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg84.8%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+84.8%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+84.8%

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

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative84.8%

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg84.8%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-84.8%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--90.5%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative90.5%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--92.4%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

        \[\leadsto \color{blue}{-d1 \cdot d3} \]
      2. *-commutative43.3%

        \[\leadsto -\color{blue}{d3 \cdot d1} \]
      3. distribute-rgt-neg-in43.3%

        \[\leadsto \color{blue}{d3 \cdot \left(-d1\right)} \]
    6. Simplified43.3%

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

    if 3.4000000000000002e64 < d4

    1. Initial program 86.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg86.3%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+86.3%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+86.3%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d1 \cdot d2 + \left(-d1 \cdot d1\right)\right)\right)} + d4 \cdot d1 \]
      8. sub-neg86.3%

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative86.3%

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \left(\color{blue}{d2 \cdot d1} - d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      10. +-commutative86.3%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg86.3%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-86.3%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--88.5%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative88.5%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--88.6%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 6.5 \cdot 10^{-278}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 1.7 \cdot 10^{-153}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d4 \leq 1.25 \cdot 10^{-63}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 3.4 \cdot 10^{+64}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 4: 88.7% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -4 \cdot 10^{+97} \lor \neg \left(d3 \leq 9 \cdot 10^{+68}\right):\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d1\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (or (<= d3 -4e+97) (not (<= d3 9e+68)))
   (* d1 (- d2 d3))
   (* d1 (- (+ d2 d4) d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -4e+97) || !(d3 <= 9e+68)) {
		tmp = d1 * (d2 - d3);
	} else {
		tmp = d1 * ((d2 + d4) - d1);
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if ((d3 <= (-4d+97)) .or. (.not. (d3 <= 9d+68))) then
        tmp = d1 * (d2 - d3)
    else
        tmp = d1 * ((d2 + d4) - d1)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -4e+97) || !(d3 <= 9e+68)) {
		tmp = d1 * (d2 - d3);
	} else {
		tmp = d1 * ((d2 + d4) - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if (d3 <= -4e+97) or not (d3 <= 9e+68):
		tmp = d1 * (d2 - d3)
	else:
		tmp = d1 * ((d2 + d4) - d1)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d3 <= -4e+97) || !(d3 <= 9e+68))
		tmp = Float64(d1 * Float64(d2 - d3));
	else
		tmp = Float64(d1 * Float64(Float64(d2 + d4) - d1));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if ((d3 <= -4e+97) || ~((d3 <= 9e+68)))
		tmp = d1 * (d2 - d3);
	else
		tmp = d1 * ((d2 + d4) - d1);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -4e+97], N[Not[LessEqual[d3, 9e+68]], $MachinePrecision]], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(N[(d2 + d4), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -4 \cdot 10^{+97} \lor \neg \left(d3 \leq 9 \cdot 10^{+68}\right):\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -4.0000000000000003e97 or 9.0000000000000007e68 < d3

    1. Initial program 82.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg82.0%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+82.0%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+82.0%

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

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative82.0%

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg82.0%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-82.0%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--84.5%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative84.5%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--88.4%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

        \[\leadsto d1 \cdot \left(d2 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+88.7%

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

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

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

    if -4.0000000000000003e97 < d3 < 9.0000000000000007e68

    1. Initial program 89.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg89.9%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+89.9%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+89.9%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d1 \cdot d2 + \left(-d1 \cdot d1\right)\right)\right)} + d4 \cdot d1 \]
      8. sub-neg89.9%

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

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \left(\color{blue}{d2 \cdot d1} - d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      10. +-commutative89.9%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg89.9%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-89.9%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--93.8%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative93.8%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--94.4%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -4 \cdot 10^{+97} \lor \neg \left(d3 \leq 9 \cdot 10^{+68}\right):\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d1\right)\\ \end{array} \]

Alternative 5: 92.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -4.2 \cdot 10^{-64} \lor \neg \left(d3 \leq 1200000000\right):\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d1\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (or (<= d3 -4.2e-64) (not (<= d3 1200000000.0)))
   (* d1 (- (+ d2 d4) d3))
   (* d1 (- (+ d2 d4) d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -4.2e-64) || !(d3 <= 1200000000.0)) {
		tmp = d1 * ((d2 + d4) - d3);
	} else {
		tmp = d1 * ((d2 + d4) - d1);
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if ((d3 <= (-4.2d-64)) .or. (.not. (d3 <= 1200000000.0d0))) then
        tmp = d1 * ((d2 + d4) - d3)
    else
        tmp = d1 * ((d2 + d4) - d1)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -4.2e-64) || !(d3 <= 1200000000.0)) {
		tmp = d1 * ((d2 + d4) - d3);
	} else {
		tmp = d1 * ((d2 + d4) - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if (d3 <= -4.2e-64) or not (d3 <= 1200000000.0):
		tmp = d1 * ((d2 + d4) - d3)
	else:
		tmp = d1 * ((d2 + d4) - d1)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d3 <= -4.2e-64) || !(d3 <= 1200000000.0))
		tmp = Float64(d1 * Float64(Float64(d2 + d4) - d3));
	else
		tmp = Float64(d1 * Float64(Float64(d2 + d4) - d1));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if ((d3 <= -4.2e-64) || ~((d3 <= 1200000000.0)))
		tmp = d1 * ((d2 + d4) - d3);
	else
		tmp = d1 * ((d2 + d4) - d1);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -4.2e-64], N[Not[LessEqual[d3, 1200000000.0]], $MachinePrecision]], N[(d1 * N[(N[(d2 + d4), $MachinePrecision] - d3), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(N[(d2 + d4), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -4.2 \cdot 10^{-64} \lor \neg \left(d3 \leq 1200000000\right):\\
\;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -4.20000000000000023e-64 or 1.2e9 < d3

    1. Initial program 86.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+86.7%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. distribute-lft-out--87.5%

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

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

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

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d1\right) + d1 \cdot \left(d2 - d3\right)} \]
      2. distribute-lft-out--89.1%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + d1 \cdot \left(d2 - d3\right) \]
      3. fma-def95.3%

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

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

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

    if -4.20000000000000023e-64 < d3 < 1.2e9

    1. Initial program 88.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg88.2%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+88.2%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+88.2%

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

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

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg88.2%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-88.2%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--93.7%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative93.7%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--93.7%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -4.2 \cdot 10^{-64} \lor \neg \left(d3 \leq 1200000000\right):\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d1\right)\\ \end{array} \]

Alternative 6: 68.3% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -1.1 \cdot 10^{+152} \lor \neg \left(d3 \leq 1.9 \cdot 10^{+168}\right):\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (or (<= d3 -1.1e+152) (not (<= d3 1.9e+168)))
   (* d1 (- d3))
   (* d1 (+ d2 d4))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -1.1e+152) || !(d3 <= 1.9e+168)) {
		tmp = d1 * -d3;
	} 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 ((d3 <= (-1.1d+152)) .or. (.not. (d3 <= 1.9d+168))) then
        tmp = d1 * -d3
    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 ((d3 <= -1.1e+152) || !(d3 <= 1.9e+168)) {
		tmp = d1 * -d3;
	} else {
		tmp = d1 * (d2 + d4);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if (d3 <= -1.1e+152) or not (d3 <= 1.9e+168):
		tmp = d1 * -d3
	else:
		tmp = d1 * (d2 + d4)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d3 <= -1.1e+152) || !(d3 <= 1.9e+168))
		tmp = Float64(d1 * Float64(-d3));
	else
		tmp = Float64(d1 * Float64(d2 + d4));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if ((d3 <= -1.1e+152) || ~((d3 <= 1.9e+168)))
		tmp = d1 * -d3;
	else
		tmp = d1 * (d2 + d4);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -1.1e+152], N[Not[LessEqual[d3, 1.9e+168]], $MachinePrecision]], N[(d1 * (-d3)), $MachinePrecision], N[(d1 * N[(d2 + d4), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -1.1 \cdot 10^{+152} \lor \neg \left(d3 \leq 1.9 \cdot 10^{+168}\right):\\
\;\;\;\;d1 \cdot \left(-d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -1.0999999999999999e152 or 1.9000000000000001e168 < d3

    1. Initial program 75.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg75.4%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+75.4%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+75.4%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d1 \cdot d2 + \left(-d1 \cdot d1\right)\right)\right)} + d4 \cdot d1 \]
      8. sub-neg75.4%

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative75.4%

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg75.4%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-75.4%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--79.2%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative79.2%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--84.9%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg84.9%

        \[\leadsto \color{blue}{-d1 \cdot d3} \]
      2. *-commutative84.9%

        \[\leadsto -\color{blue}{d3 \cdot d1} \]
      3. distribute-rgt-neg-in84.9%

        \[\leadsto \color{blue}{d3 \cdot \left(-d1\right)} \]
    6. Simplified84.9%

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

    if -1.0999999999999999e152 < d3 < 1.9000000000000001e168

    1. Initial program 90.6%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+90.6%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. distribute-lft-out--91.1%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
      3. *-commutative91.1%

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

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

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d1\right) + d1 \cdot \left(d2 - d3\right)} \]
      2. distribute-lft-out--93.1%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + d1 \cdot \left(d2 - d3\right) \]
      3. fma-def94.6%

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(d4 + d2\right)} \]
    9. Simplified72.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -1.1 \cdot 10^{+152} \lor \neg \left(d3 \leq 1.9 \cdot 10^{+168}\right):\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]

Alternative 7: 64.1% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -650000000:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

\mathbf{elif}\;d2 \leq 2.8 \cdot 10^{-78}:\\
\;\;\;\;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 d2 < -6.5e8

    1. Initial program 83.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.2%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+83.2%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+83.2%

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

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

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg83.2%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-83.2%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--89.3%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative89.3%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--92.4%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

        \[\leadsto d1 \cdot \left(d2 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+85.5%

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

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

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

    if -6.5e8 < d2 < 2.80000000000000024e-78

    1. Initial program 92.6%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+92.6%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. distribute-lft-out--92.6%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
      3. *-commutative92.6%

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

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

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d1\right) + d1 \cdot \left(d2 - d3\right)} \]
      2. distribute-lft-out--93.6%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + d1 \cdot \left(d2 - d3\right) \]
      3. fma-def96.3%

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

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

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

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

    if 2.80000000000000024e-78 < d2

    1. Initial program 83.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.9%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+83.9%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+83.9%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d1 \cdot d2 + \left(-d1 \cdot d1\right)\right)\right)} + d4 \cdot d1 \]
      8. sub-neg83.9%

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

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \left(\color{blue}{d2 \cdot d1} - d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      10. +-commutative83.9%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg83.9%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-83.9%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--90.1%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative90.1%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--91.3%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - \left(d1 + d3\right)\right)} \]
    5. Step-by-step derivation
      1. associate--r+72.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification73.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -650000000:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq 2.8 \cdot 10^{-78}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 8: 84.7% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 6 \cdot 10^{+16}:\\
\;\;\;\;d1 \cdot \left(\left(d2 - d3\right) - d1\right)\\

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


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

    1. Initial program 87.6%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg87.6%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+87.6%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+87.6%

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

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative87.6%

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg87.6%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-87.6%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--91.6%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative91.6%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--93.1%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

        \[\leadsto d1 \cdot \left(d2 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+82.6%

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

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

    if 6e16 < d4

    1. Initial program 86.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+86.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. distribute-lft-out--88.8%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
      3. *-commutative88.8%

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

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

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d1\right) + d1 \cdot \left(d2 - d3\right)} \]
      2. distribute-lft-out--92.5%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + d1 \cdot \left(d2 - d3\right) \]
      3. fma-def94.4%

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

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

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

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

Alternative 9: 84.3% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -3.1 \cdot 10^{-56}:\\
\;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\

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


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

    1. Initial program 85.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+85.4%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. distribute-lft-out--85.4%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
      3. *-commutative85.4%

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

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

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d1\right) + d1 \cdot \left(d2 - d3\right)} \]
      2. distribute-lft-out--90.7%

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

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

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

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

    if -3.09999999999999987e-56 < d2

    1. Initial program 88.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg88.3%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+88.3%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+88.3%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d1 \cdot d2 + \left(-d1 \cdot d1\right)\right)\right)} + d4 \cdot d1 \]
      8. sub-neg88.3%

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative88.3%

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \left(\color{blue}{d2 \cdot d1} - d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      10. +-commutative88.3%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg88.3%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-88.3%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--91.1%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative91.1%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--92.2%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - \left(d1 + d3\right)\right)} \]
    5. Step-by-step derivation
      1. associate--r+87.1%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(d4 - d1\right) - d3\right)} \]
    6. Simplified87.1%

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

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

Alternative 10: 62.0% accurate, 2.1× speedup?

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

    1. Initial program 87.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg87.3%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+87.3%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+87.3%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d1 \cdot d2 + \left(-d1 \cdot d1\right)\right)\right)} + d4 \cdot d1 \]
      8. sub-neg87.3%

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative87.3%

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \left(\color{blue}{d2 \cdot d1} - d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      10. +-commutative87.3%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg87.3%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-87.3%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--91.6%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative91.6%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--93.4%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

        \[\leadsto d1 \cdot \left(d2 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+81.8%

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

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

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

    if 2.10000000000000008e70 < d4

    1. Initial program 88.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+88.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. distribute-lft-out--88.0%

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

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

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

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d1\right) + d1 \cdot \left(d2 - d3\right)} \]
      2. distribute-lft-out--92.8%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + d1 \cdot \left(d2 - d3\right) \]
      3. fma-def95.2%

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(d4 + d2\right)} \]
    9. Simplified80.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 2.1 \cdot 10^{+70}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]

Alternative 11: 63.9% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 8.5 \cdot 10^{+63}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

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


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

    1. Initial program 87.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg87.7%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+87.7%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+87.7%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d1 \cdot d2 + \left(-d1 \cdot d1\right)\right)\right)} + d4 \cdot d1 \]
      8. sub-neg87.7%

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative87.7%

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg87.7%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-87.7%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--91.5%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative91.5%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--93.4%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

        \[\leadsto d1 \cdot \left(d2 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+82.0%

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

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

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

    if 8.5000000000000004e63 < d4

    1. Initial program 86.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+86.3%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. distribute-lft-out--86.3%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
      3. *-commutative86.3%

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

      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right) + \left(d1 \cdot d4 - d1 \cdot d1\right)} \]
    4. Step-by-step derivation
      1. +-commutative86.3%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d1\right) + d1 \cdot \left(d2 - d3\right)} \]
      2. distribute-lft-out--90.8%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + d1 \cdot \left(d2 - d3\right) \]
      3. fma-def93.1%

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

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

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

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

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

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

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

Alternative 12: 60.8% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -2.7 \cdot 10^{-73}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d2 < -2.69999999999999994e-73

    1. Initial program 86.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg86.0%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+86.0%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+86.0%

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

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative86.0%

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg86.0%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-86.0%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--91.1%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative91.1%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--93.6%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

        \[\leadsto d1 \cdot \left(d2 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+80.4%

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

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

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

    if -2.69999999999999994e-73 < d2

    1. Initial program 88.1%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg88.1%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+88.1%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+88.1%

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

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \color{blue}{\left(d1 \cdot d2 - d1 \cdot d1\right)}\right) + d4 \cdot d1 \]
      9. *-commutative88.1%

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg88.1%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-88.1%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--90.9%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative90.9%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--92.1%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - \left(d1 + d3\right)\right)} \]
    5. Step-by-step derivation
      1. associate--r+87.2%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification67.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -2.7 \cdot 10^{-73}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 13: 38.8% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -105000000:\\
\;\;\;\;d1 \cdot d2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d2 < -1.05e8

    1. Initial program 83.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.2%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+83.2%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+83.2%

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

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

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

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg83.2%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-83.2%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--89.3%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative89.3%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--92.4%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

    if -1.05e8 < d2

    1. Initial program 88.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg88.9%

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
      3. associate-+r+88.9%

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

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

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

        \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      7. associate-+r+88.9%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d1 \cdot d2 + \left(-d1 \cdot d1\right)\right)\right)} + d4 \cdot d1 \]
      8. sub-neg88.9%

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

        \[\leadsto \left(\left(-d1 \cdot d3\right) + \left(\color{blue}{d2 \cdot d1} - d1 \cdot d1\right)\right) + d4 \cdot d1 \]
      10. +-commutative88.9%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1 \]
      11. unsub-neg88.9%

        \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
      12. associate--r-88.9%

        \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
      13. distribute-rgt-out--91.5%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
      14. *-commutative91.5%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
      15. distribute-lft-out--92.6%

        \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
      16. distribute-lft-out--100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -105000000:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 14: 30.8% 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.5%

    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
  2. Step-by-step derivation
    1. sub-neg87.5%

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

      \[\leadsto \color{blue}{\left(-d1 \cdot d1\right) + \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} \]
    3. associate-+r+87.5%

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

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

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

      \[\leadsto \left(\color{blue}{\left(\left(-d1 \cdot d3\right) + d1 \cdot d2\right)} + \left(-d1 \cdot d1\right)\right) + d4 \cdot d1 \]
    7. associate-+r+87.5%

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(d2 \cdot d1 - d1 \cdot d1\right) - d1 \cdot d3\right)} + d4 \cdot d1 \]
    12. associate--r-87.5%

      \[\leadsto \color{blue}{\left(d2 \cdot d1 - d1 \cdot d1\right) - \left(d1 \cdot d3 - d4 \cdot d1\right)} \]
    13. distribute-rgt-out--91.0%

      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} - \left(d1 \cdot d3 - d4 \cdot d1\right) \]
    14. *-commutative91.0%

      \[\leadsto d1 \cdot \left(d2 - d1\right) - \left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right) \]
    15. distribute-lft-out--92.6%

      \[\leadsto d1 \cdot \left(d2 - d1\right) - \color{blue}{d1 \cdot \left(d3 - d4\right)} \]
    16. distribute-lft-out--100.0%

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

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

    \[\leadsto \color{blue}{d1 \cdot d2} \]
  5. Final simplification34.1%

    \[\leadsto d1 \cdot d2 \]

Developer target: 100.0% accurate, 1.7× 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 2023320 
(FPCore (d1 d2 d3 d4)
  :name "FastMath dist4"
  :precision binary64

  :herbie-target
  (* d1 (- (+ (- d2 d3) d4) d1))

  (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))