FastMath dist4

Percentage Accurate: 87.5% → 100.0%
Time: 5.6s
Alternatives: 10
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 10 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 83.2%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
    10. distribute-rgt-out--89.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)} \]
    13. sub-neg100.0%

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

      \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
    15. remove-double-neg100.0%

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

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

      \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
    18. distribute-neg-in100.0%

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

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

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

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

    \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right) \]
  6. Add Preprocessing

Alternative 2: 62.1% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d2 \leq -2.05 \cdot 10^{-139} \lor \neg \left(d2 \leq -8.4 \cdot 10^{-294}\right) \land d2 \leq 1.85 \cdot 10^{-216}:\\
\;\;\;\;d1 \cdot \left(d4 - d3\right)\\

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


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

    1. Initial program 84.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg84.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+84.3%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--98.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

    if -3.8999999999999997e42 < d2 < -2.05000000000000007e-139 or -8.39999999999999937e-294 < d2 < 1.84999999999999998e-216

    1. Initial program 82.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg82.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+82.7%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--86.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

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

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

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

    if -2.05000000000000007e-139 < d2 < -8.39999999999999937e-294 or 1.84999999999999998e-216 < d2

    1. Initial program 83.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.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+83.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--87.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -3.9 \cdot 10^{+42}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d2 \leq -2.05 \cdot 10^{-139} \lor \neg \left(d2 \leq -8.4 \cdot 10^{-294}\right) \land d2 \leq 1.85 \cdot 10^{-216}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 68.4% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d1 \leq -2.85 \cdot 10^{-154}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;d1 \leq 7.2 \cdot 10^{+121}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d1 < -1.2500000000000001e53 or 7.19999999999999963e121 < d1

    1. Initial program 60.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg60.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+60.7%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--74.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

    if -1.2500000000000001e53 < d1 < -2.8499999999999999e-154 or -6e-195 < d1 < 7.19999999999999963e121

    1. Initial program 99.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg99.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+99.3%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--100.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

    if -2.8499999999999999e-154 < d1 < -6e-195

    1. Initial program 100.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg100.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+100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--100.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -1.25 \cdot 10^{+53}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d1 \leq -2.85 \cdot 10^{-154}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{elif}\;d1 \leq -6 \cdot 10^{-195}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d1 \leq 7.2 \cdot 10^{+121}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 88.7% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -1 \cdot 10^{+180} \lor \neg \left(d3 \leq 3.2 \cdot 10^{+167}\right):\\
\;\;\;\;d1 \cdot \left(d4 - 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 < -1e180 or 3.19999999999999981e167 < d3

    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--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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

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

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

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

    if -1e180 < d3 < 3.19999999999999981e167

    1. Initial program 83.9%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--90.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) - \left(d3 - d4\right)\right)} \]
    4. 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 -1 \cdot 10^{+180} \lor \neg \left(d3 \leq 3.2 \cdot 10^{+167}\right):\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 67.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -7 \cdot 10^{+179} \lor \neg \left(d3 \leq 1.02 \cdot 10^{+90}\right):\\
\;\;\;\;d1 \cdot \left(-d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -7.0000000000000003e179 or 1.02000000000000005e90 < d3

    1. Initial program 80.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg80.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+80.7%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--87.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

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

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

    if -7.0000000000000003e179 < d3 < 1.02000000000000005e90

    1. Initial program 84.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg84.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+84.3%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--90.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

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

Alternative 6: 58.6% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 82.5%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg82.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+82.5%

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

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

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

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

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

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

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

        \[\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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

    if -5.5 < d2 < -1.9000000000000001e-136

    1. Initial program 83.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.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+83.3%

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

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

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

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

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

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

        \[\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--87.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

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

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

    if -1.9000000000000001e-136 < d2

    1. Initial program 83.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.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+83.4%

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--88.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

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

Alternative 7: 38.8% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 83.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.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+83.7%

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

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

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

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

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

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

        \[\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--98.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

    if -5.8000000000000004e46 < d2 < 2.05000000000000001e-278

    1. Initial program 82.5%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg82.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+82.5%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--85.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

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

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

    if 2.05000000000000001e-278 < d2

    1. Initial program 83.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.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+83.4%

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--88.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

Alternative 8: 84.2% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 83.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.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+83.7%

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

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

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

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

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

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

        \[\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--98.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

    if -1e47 < d2

    1. Initial program 83.1%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.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+83.1%

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--87.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

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

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

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

Alternative 9: 39.5% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 83.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.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+83.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--96.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

    if -1.44999999999999997e35 < d2

    1. Initial program 83.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--87.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)} \]
      13. sub-neg100.0%

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
      15. remove-double-neg100.0%

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

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

        \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
      18. distribute-neg-in100.0%

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

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

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

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

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

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

Alternative 10: 30.6% 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 83.2%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
    10. distribute-rgt-out--89.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)} \]
    13. sub-neg100.0%

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

      \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + d4\right)}\right) \]
    15. remove-double-neg100.0%

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

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

      \[\leadsto d1 \cdot \left(\left(d2 - d1\right) + \color{blue}{\left(\left(-d3\right) + \left(-\left(-d4\right)\right)\right)}\right) \]
    18. distribute-neg-in100.0%

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

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

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

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

    \[\leadsto \color{blue}{d1 \cdot d2} \]
  6. Final simplification30.0%

    \[\leadsto d1 \cdot d2 \]
  7. 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 2024031 
(FPCore (d1 d2 d3 d4)
  :name "FastMath dist4"
  :precision binary64

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

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