FastMath dist4

Percentage Accurate: 87.5% → 100.0%
Time: 8.8s
Alternatives: 12
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 87.5% accurate, 1.0× speedup?

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

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

Alternative 1: 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 89.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 40.1% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(-d1\right)\\ t_1 := d1 \cdot \left(-d3\right)\\ \mathbf{if}\;d2 \leq -5.8 \cdot 10^{+54}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -2.9 \cdot 10^{+27}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d2 \leq -5.7 \cdot 10^{-99}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d2 \leq -2.9 \cdot 10^{-119}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d2 \leq -1.55 \cdot 10^{-246}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d2 \leq 2.3 \cdot 10^{-266} \lor \neg \left(d2 \leq 1.25 \cdot 10^{-183}\right):\\ \;\;\;\;d1 \cdot d4\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d1))) (t_1 (* d1 (- d3))))
   (if (<= d2 -5.8e+54)
     (* d1 d2)
     (if (<= d2 -2.9e+27)
       t_1
       (if (<= d2 -5.7e-99)
         t_0
         (if (<= d2 -2.9e-119)
           t_1
           (if (<= d2 -1.55e-246)
             t_0
             (if (or (<= d2 2.3e-266) (not (<= d2 1.25e-183)))
               (* d1 d4)
               t_1))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * -d1;
	double t_1 = d1 * -d3;
	double tmp;
	if (d2 <= -5.8e+54) {
		tmp = d1 * d2;
	} else if (d2 <= -2.9e+27) {
		tmp = t_1;
	} else if (d2 <= -5.7e-99) {
		tmp = t_0;
	} else if (d2 <= -2.9e-119) {
		tmp = t_1;
	} else if (d2 <= -1.55e-246) {
		tmp = t_0;
	} else if ((d2 <= 2.3e-266) || !(d2 <= 1.25e-183)) {
		tmp = d1 * d4;
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_0 = d1 * -d1
    t_1 = d1 * -d3
    if (d2 <= (-5.8d+54)) then
        tmp = d1 * d2
    else if (d2 <= (-2.9d+27)) then
        tmp = t_1
    else if (d2 <= (-5.7d-99)) then
        tmp = t_0
    else if (d2 <= (-2.9d-119)) then
        tmp = t_1
    else if (d2 <= (-1.55d-246)) then
        tmp = t_0
    else if ((d2 <= 2.3d-266) .or. (.not. (d2 <= 1.25d-183))) then
        tmp = d1 * d4
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * -d1;
	double t_1 = d1 * -d3;
	double tmp;
	if (d2 <= -5.8e+54) {
		tmp = d1 * d2;
	} else if (d2 <= -2.9e+27) {
		tmp = t_1;
	} else if (d2 <= -5.7e-99) {
		tmp = t_0;
	} else if (d2 <= -2.9e-119) {
		tmp = t_1;
	} else if (d2 <= -1.55e-246) {
		tmp = t_0;
	} else if ((d2 <= 2.3e-266) || !(d2 <= 1.25e-183)) {
		tmp = d1 * d4;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * -d1
	t_1 = d1 * -d3
	tmp = 0
	if d2 <= -5.8e+54:
		tmp = d1 * d2
	elif d2 <= -2.9e+27:
		tmp = t_1
	elif d2 <= -5.7e-99:
		tmp = t_0
	elif d2 <= -2.9e-119:
		tmp = t_1
	elif d2 <= -1.55e-246:
		tmp = t_0
	elif (d2 <= 2.3e-266) or not (d2 <= 1.25e-183):
		tmp = d1 * d4
	else:
		tmp = t_1
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(-d1))
	t_1 = Float64(d1 * Float64(-d3))
	tmp = 0.0
	if (d2 <= -5.8e+54)
		tmp = Float64(d1 * d2);
	elseif (d2 <= -2.9e+27)
		tmp = t_1;
	elseif (d2 <= -5.7e-99)
		tmp = t_0;
	elseif (d2 <= -2.9e-119)
		tmp = t_1;
	elseif (d2 <= -1.55e-246)
		tmp = t_0;
	elseif ((d2 <= 2.3e-266) || !(d2 <= 1.25e-183))
		tmp = Float64(d1 * d4);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * -d1;
	t_1 = d1 * -d3;
	tmp = 0.0;
	if (d2 <= -5.8e+54)
		tmp = d1 * d2;
	elseif (d2 <= -2.9e+27)
		tmp = t_1;
	elseif (d2 <= -5.7e-99)
		tmp = t_0;
	elseif (d2 <= -2.9e-119)
		tmp = t_1;
	elseif (d2 <= -1.55e-246)
		tmp = t_0;
	elseif ((d2 <= 2.3e-266) || ~((d2 <= 1.25e-183)))
		tmp = d1 * d4;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * (-d1)), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * (-d3)), $MachinePrecision]}, If[LessEqual[d2, -5.8e+54], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -2.9e+27], t$95$1, If[LessEqual[d2, -5.7e-99], t$95$0, If[LessEqual[d2, -2.9e-119], t$95$1, If[LessEqual[d2, -1.55e-246], t$95$0, If[Or[LessEqual[d2, 2.3e-266], N[Not[LessEqual[d2, 1.25e-183]], $MachinePrecision]], N[(d1 * d4), $MachinePrecision], t$95$1]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := d1 \cdot \left(-d1\right)\\
t_1 := d1 \cdot \left(-d3\right)\\
\mathbf{if}\;d2 \leq -5.8 \cdot 10^{+54}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d2 \leq -2.9 \cdot 10^{+27}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d2 \leq -5.7 \cdot 10^{-99}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d2 \leq -2.9 \cdot 10^{-119}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d2 \leq -1.55 \cdot 10^{-246}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d2 \leq 2.3 \cdot 10^{-266} \lor \neg \left(d2 \leq 1.25 \cdot 10^{-183}\right):\\
\;\;\;\;d1 \cdot d4\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d2 < -5.7999999999999997e54

    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. sub-neg85.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.7999999999999997e54 < d2 < -2.9000000000000001e27 or -5.70000000000000032e-99 < d2 < -2.9e-119 or 2.29999999999999996e-266 < d2 < 1.2500000000000001e-183

    1. Initial program 91.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.9000000000000001e27 < d2 < -5.70000000000000032e-99 or -2.9e-119 < d2 < -1.55e-246

    1. Initial program 91.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    6. Step-by-step derivation
      1. unpow248.9%

        \[\leadsto -1 \cdot \color{blue}{\left(d1 \cdot d1\right)} \]
      2. mul-1-neg48.9%

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

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

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

    if -1.55e-246 < d2 < 2.29999999999999996e-266 or 1.2500000000000001e-183 < d2

    1. Initial program 89.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -5.8 \cdot 10^{+54}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -2.9 \cdot 10^{+27}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d2 \leq -5.7 \cdot 10^{-99}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d2 \leq -2.9 \cdot 10^{-119}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d2 \leq -1.55 \cdot 10^{-246}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d2 \leq 2.3 \cdot 10^{-266} \lor \neg \left(d2 \leq 1.25 \cdot 10^{-183}\right):\\ \;\;\;\;d1 \cdot d4\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 65.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(-d3\right)\\ t_1 := d1 \cdot \left(d2 + d4\right)\\ \mathbf{if}\;d3 \leq -3.2 \cdot 10^{+203}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq -2 \cdot 10^{-204}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d3 \leq -5.6 \cdot 10^{-253}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d3 \leq 3.9 \cdot 10^{+111}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d3))) (t_1 (* d1 (+ d2 d4))))
   (if (<= d3 -3.2e+203)
     t_0
     (if (<= d3 -2e-204)
       t_1
       (if (<= d3 -5.6e-253) (* d1 (- d1)) (if (<= d3 3.9e+111) t_1 t_0))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * -d3;
	double t_1 = d1 * (d2 + d4);
	double tmp;
	if (d3 <= -3.2e+203) {
		tmp = t_0;
	} else if (d3 <= -2e-204) {
		tmp = t_1;
	} else if (d3 <= -5.6e-253) {
		tmp = d1 * -d1;
	} else if (d3 <= 3.9e+111) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = d1 * -d3
    t_1 = d1 * (d2 + d4)
    if (d3 <= (-3.2d+203)) then
        tmp = t_0
    else if (d3 <= (-2d-204)) then
        tmp = t_1
    else if (d3 <= (-5.6d-253)) then
        tmp = d1 * -d1
    else if (d3 <= 3.9d+111) then
        tmp = t_1
    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 * -d3;
	double t_1 = d1 * (d2 + d4);
	double tmp;
	if (d3 <= -3.2e+203) {
		tmp = t_0;
	} else if (d3 <= -2e-204) {
		tmp = t_1;
	} else if (d3 <= -5.6e-253) {
		tmp = d1 * -d1;
	} else if (d3 <= 3.9e+111) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * -d3
	t_1 = d1 * (d2 + d4)
	tmp = 0
	if d3 <= -3.2e+203:
		tmp = t_0
	elif d3 <= -2e-204:
		tmp = t_1
	elif d3 <= -5.6e-253:
		tmp = d1 * -d1
	elif d3 <= 3.9e+111:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(-d3))
	t_1 = Float64(d1 * Float64(d2 + d4))
	tmp = 0.0
	if (d3 <= -3.2e+203)
		tmp = t_0;
	elseif (d3 <= -2e-204)
		tmp = t_1;
	elseif (d3 <= -5.6e-253)
		tmp = Float64(d1 * Float64(-d1));
	elseif (d3 <= 3.9e+111)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * -d3;
	t_1 = d1 * (d2 + d4);
	tmp = 0.0;
	if (d3 <= -3.2e+203)
		tmp = t_0;
	elseif (d3 <= -2e-204)
		tmp = t_1;
	elseif (d3 <= -5.6e-253)
		tmp = d1 * -d1;
	elseif (d3 <= 3.9e+111)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * (-d3)), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d2 + d4), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -3.2e+203], t$95$0, If[LessEqual[d3, -2e-204], t$95$1, If[LessEqual[d3, -5.6e-253], N[(d1 * (-d1)), $MachinePrecision], If[LessEqual[d3, 3.9e+111], t$95$1, t$95$0]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d3 \leq -2 \cdot 10^{-204}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d3 \leq -5.6 \cdot 10^{-253}:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\

\mathbf{elif}\;d3 \leq 3.9 \cdot 10^{+111}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -3.1999999999999997e203 or 3.89999999999999979e111 < d3

    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 \left(\color{blue}{\left(d1 \cdot d2 + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. associate-+l+87.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-d1 \cdot d3} \]
      2. distribute-rgt-neg-in89.6%

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

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

    if -3.1999999999999997e203 < d3 < -2e-204 or -5.60000000000000011e-253 < d3 < 3.89999999999999979e111

    1. Initial program 90.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2e-204 < d3 < -5.60000000000000011e-253

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    6. Step-by-step derivation
      1. unpow275.3%

        \[\leadsto -1 \cdot \color{blue}{\left(d1 \cdot d1\right)} \]
      2. mul-1-neg75.3%

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

        \[\leadsto \color{blue}{d1 \cdot \left(-d1\right)} \]
    7. Simplified75.3%

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

Alternative 4: 40.1% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.35 \cdot 10^{+103}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d2 \leq -1.5 \cdot 10^{-246} \lor \neg \left(d2 \leq 5.8 \cdot 10^{-266}\right) \land d2 \leq 1.55 \cdot 10^{-183}:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d2 < -1.34999999999999996e103

    1. Initial program 81.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.34999999999999996e103 < d2 < -1.5e-246 or 5.79999999999999991e-266 < d2 < 1.55e-183

    1. Initial program 92.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    6. Step-by-step derivation
      1. unpow242.3%

        \[\leadsto -1 \cdot \color{blue}{\left(d1 \cdot d1\right)} \]
      2. mul-1-neg42.3%

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

        \[\leadsto \color{blue}{d1 \cdot \left(-d1\right)} \]
    7. Simplified42.3%

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

    if -1.5e-246 < d2 < 5.79999999999999991e-266 or 1.55e-183 < d2

    1. Initial program 89.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.35 \cdot 10^{+103}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -1.5 \cdot 10^{-246} \lor \neg \left(d2 \leq 5.8 \cdot 10^{-266}\right) \land d2 \leq 1.55 \cdot 10^{-183}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 68.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d3 \leq -3.2 \cdot 10^{+177}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq 8.6 \cdot 10^{-198}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d3 \leq 3.95 \cdot 10^{+74}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d2 d3))))
   (if (<= d3 -3.2e+177)
     t_0
     (if (<= d3 8.6e-198)
       (* d1 (- d4 d1))
       (if (<= d3 3.95e+74) (* d1 (+ d2 d4)) t_0)))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double tmp;
	if (d3 <= -3.2e+177) {
		tmp = t_0;
	} else if (d3 <= 8.6e-198) {
		tmp = d1 * (d4 - d1);
	} else if (d3 <= 3.95e+74) {
		tmp = d1 * (d2 + d4);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: tmp
    t_0 = d1 * (d2 - d3)
    if (d3 <= (-3.2d+177)) then
        tmp = t_0
    else if (d3 <= 8.6d-198) then
        tmp = d1 * (d4 - d1)
    else if (d3 <= 3.95d+74) then
        tmp = d1 * (d2 + d4)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double tmp;
	if (d3 <= -3.2e+177) {
		tmp = t_0;
	} else if (d3 <= 8.6e-198) {
		tmp = d1 * (d4 - d1);
	} else if (d3 <= 3.95e+74) {
		tmp = d1 * (d2 + d4);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d3)
	tmp = 0
	if d3 <= -3.2e+177:
		tmp = t_0
	elif d3 <= 8.6e-198:
		tmp = d1 * (d4 - d1)
	elif d3 <= 3.95e+74:
		tmp = d1 * (d2 + d4)
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d3))
	tmp = 0.0
	if (d3 <= -3.2e+177)
		tmp = t_0;
	elseif (d3 <= 8.6e-198)
		tmp = Float64(d1 * Float64(d4 - d1));
	elseif (d3 <= 3.95e+74)
		tmp = Float64(d1 * Float64(d2 + d4));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d2 - d3);
	tmp = 0.0;
	if (d3 <= -3.2e+177)
		tmp = t_0;
	elseif (d3 <= 8.6e-198)
		tmp = d1 * (d4 - d1);
	elseif (d3 <= 3.95e+74)
		tmp = d1 * (d2 + d4);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -3.2e+177], t$95$0, If[LessEqual[d3, 8.6e-198], N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 3.95e+74], N[(d1 * N[(d2 + d4), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -3.2e177 or 3.94999999999999994e74 < d3

    1. Initial program 83.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.2e177 < d3 < 8.6000000000000007e-198

    1. Initial program 91.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.6000000000000007e-198 < d3 < 3.94999999999999994e74

    1. Initial program 92.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 88.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -3.2 \cdot 10^{+177} \lor \neg \left(d3 \leq 9.2 \cdot 10^{+108}\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 -3.2e+177) (not (<= d3 9.2e+108)))
   (* d1 (- d2 d3))
   (* d1 (- (+ d2 d4) d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -3.2e+177) || !(d3 <= 9.2e+108)) {
		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 <= (-3.2d+177)) .or. (.not. (d3 <= 9.2d+108))) 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 <= -3.2e+177) || !(d3 <= 9.2e+108)) {
		tmp = d1 * (d2 - d3);
	} else {
		tmp = d1 * ((d2 + d4) - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if (d3 <= -3.2e+177) or not (d3 <= 9.2e+108):
		tmp = d1 * (d2 - d3)
	else:
		tmp = d1 * ((d2 + d4) - d1)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d3 <= -3.2e+177) || !(d3 <= 9.2e+108))
		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 <= -3.2e+177) || ~((d3 <= 9.2e+108)))
		tmp = d1 * (d2 - d3);
	else
		tmp = d1 * ((d2 + d4) - d1);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -3.2e+177], N[Not[LessEqual[d3, 9.2e+108]], $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 -3.2 \cdot 10^{+177} \lor \neg \left(d3 \leq 9.2 \cdot 10^{+108}\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 < -3.2e177 or 9.1999999999999996e108 < d3

    1. Initial program 84.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.2e177 < d3 < 9.1999999999999996e108

    1. Initial program 91.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 62.5% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < -5.89999999999999978e-65

    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 \left(\color{blue}{\left(d1 \cdot d2 + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. associate-+l+86.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.89999999999999978e-65 < d4 < 5.5999999999999997e76

    1. Initial program 89.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(d3 + d1\right)}\right) \]
      5. associate--r+72.5%

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

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

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

    if 5.5999999999999997e76 < d4

    1. Initial program 94.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 84.1% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 1.4 \cdot 10^{+67}:\\
\;\;\;\;d1 \cdot \left(\left(d2 - d1\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 d4 < 1.3999999999999999e67

    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 \left(\color{blue}{\left(d1 \cdot d2 + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. associate-+l+88.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.3999999999999999e67 < d4

    1. Initial program 94.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 61.7% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 88.3%

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

      \[\leadsto \color{blue}{d1 \cdot d2} - d1 \cdot d1 \]
    4. Step-by-step derivation
      1. distribute-lft-out--63.0%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      2. *-commutative63.0%

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

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

    if 6.99999999999999954e83 < d4

    1. Initial program 94.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 63.5% accurate, 1.5× speedup?

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

    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 \left(\color{blue}{\left(d1 \cdot d2 + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. associate-+l+88.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.40000000000000003e68 < d4

    1. Initial program 94.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 39.2% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 2.8 \cdot 10^{+85}:\\
\;\;\;\;d1 \cdot d2\\

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


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

    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 \left(\color{blue}{\left(d1 \cdot d2 + \left(-d1 \cdot d3\right)\right)} + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. associate-+l+88.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.7999999999999999e85 < d4

    1. Initial program 94.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 31.4% accurate, 5.0× speedup?

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

\\
d1 \cdot d2
\end{array}
Derivation
  1. Initial program 89.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 2024097 
(FPCore (d1 d2 d3 d4)
  :name "FastMath dist4"
  :precision binary64

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

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