FastMath dist4

Percentage Accurate: 87.9% → 100.0%
Time: 7.1s
Alternatives: 12
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 87.9% 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 86.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 62.8% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d4 \leq 2.5 \cdot 10^{+22} \lor \neg \left(d4 \leq 1.75 \cdot 10^{+69}\right) \land d4 \leq 1.65 \cdot 10^{+98}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

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


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

    1. Initial program 88.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.79999999999999998e-161 < d4 < 2.4999999999999998e22 or 1.74999999999999994e69 < d4 < 1.65000000000000014e98

    1. Initial program 90.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.4999999999999998e22 < d4 < 1.74999999999999994e69 or 1.65000000000000014e98 < d4

    1. Initial program 76.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 4.8 \cdot 10^{-161}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 2.5 \cdot 10^{+22} \lor \neg \left(d4 \leq 1.75 \cdot 10^{+69}\right) \land d4 \leq 1.65 \cdot 10^{+98}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 60.5% accurate, 0.7× speedup?

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

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

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

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

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


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

    1. Initial program 88.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.90000000000000035e-161 < d4 < 1.6999999999999999e-81

    1. Initial program 93.8%

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

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

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

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

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

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

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

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

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

        \[\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-out99.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.6999999999999999e-81 < d4 < 1.1200000000000001e-44

    1. Initial program 81.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-d1 \cdot d1} \]
      3. sub0-neg55.6%

        \[\leadsto \color{blue}{0 - d1 \cdot d1} \]
    7. Simplified55.6%

      \[\leadsto \color{blue}{0 - d1 \cdot d1} \]

    if 1.1200000000000001e-44 < d4

    1. Initial program 80.5%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--83.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)} \]
    3. Simplified100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 4.9 \cdot 10^{-161}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 1.7 \cdot 10^{-81}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 1.12 \cdot 10^{-44}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 61.3% accurate, 0.7× speedup?

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

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

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

\mathbf{elif}\;d4 \leq 3 \cdot 10^{-44}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 1.6499999999999999e-161 or 3.9999999999999998e-81 < d4 < 3.0000000000000002e-44

    1. Initial program 88.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.6499999999999999e-161 < d4 < 3.9999999999999998e-81

    1. Initial program 93.8%

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

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

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

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

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

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

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

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

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

        \[\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-out99.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.0000000000000002e-44 < d4

    1. Initial program 80.5%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--83.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)} \]
    3. Simplified100.0%

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

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

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

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

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

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

Alternative 5: 71.7% accurate, 0.7× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -1.8e66 or 1.15999999999999998e36 < d3

    1. Initial program 81.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(d4 - \left(d3 - d2\right)\right)} \cdot d1 \]
    9. Applied egg-rr89.0%

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

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

    if -1.8e66 < d3 < 1.1200000000000001e-213

    1. Initial program 91.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.1200000000000001e-213 < d3 < 1.15999999999999998e36

    1. Initial program 88.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 93.9% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -7.5 \cdot 10^{+68} \lor \neg \left(d3 \leq 3.5 \cdot 10^{+32}\right):\\
\;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -7.49999999999999959e68 or 3.5000000000000001e32 < 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--83.4%

        \[\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-out99.9%

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

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

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

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

    if -7.49999999999999959e68 < d3 < 3.5000000000000001e32

    1. Initial program 90.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 89.1% accurate, 0.9× speedup?

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

    1. Initial program 81.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.49999999999999979e84 < d3 < 7.6000000000000003e96

    1. Initial program 88.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 85.0% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -5.2 \cdot 10^{+98}:\\
\;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\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 < -5.1999999999999999e98

    1. Initial program 73.3%

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

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

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

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

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

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

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

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

        \[\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-out99.9%

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

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

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

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

    if -5.1999999999999999e98 < d2

    1. Initial program 89.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 61.7% accurate, 1.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d4 < 1.84999999999999994e-34

    1. Initial program 88.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.84999999999999994e-34 < d4

    1. Initial program 79.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 39.6% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 88.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.9999999999999996e22 < d4

    1. Initial program 79.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 56.6% accurate, 3.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 31.3% 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 86.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Developer target: 100.0% accurate, 1.7× speedup?

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

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

Reproduce

?
herbie shell --seed 2024107 
(FPCore (d1 d2 d3 d4)
  :name "FastMath dist4"
  :precision binary64

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

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