FastMath dist4

Percentage Accurate: 87.1% → 100.0%
Time: 5.4s
Alternatives: 13
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 13 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.1% 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(d4 - d1\right) + \left(d2 - d3\right)\right) \end{array} \]
(FPCore (d1 d2 d3 d4) :precision binary64 (* d1 (+ (- d4 d1) (- d2 d3))))
double code(double d1, double d2, double d3, double d4) {
	return d1 * ((d4 - d1) + (d2 - 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 * ((d4 - d1) + (d2 - d3))
end function
public static double code(double d1, double d2, double d3, double d4) {
	return d1 * ((d4 - d1) + (d2 - d3));
}
def code(d1, d2, d3, d4):
	return d1 * ((d4 - d1) + (d2 - d3))
function code(d1, d2, d3, d4)
	return Float64(d1 * Float64(Float64(d4 - d1) + Float64(d2 - d3)))
end
function tmp = code(d1, d2, d3, d4)
	tmp = d1 * ((d4 - d1) + (d2 - d3));
end
code[d1_, d2_, d3_, d4_] := N[(d1 * N[(N[(d4 - d1), $MachinePrecision] + N[(d2 - d3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
d1 \cdot \left(\left(d4 - d1\right) + \left(d2 - d3\right)\right)
\end{array}
Derivation
  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. associate--l+91.0%

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

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

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

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

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

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

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

Alternative 2: 62.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 3.75 \cdot 10^{-79} \lor \neg \left(d4 \leq 4.6 \cdot 10^{-49}\right) \land \left(d4 \leq 2.2 \cdot 10^{-29} \lor \neg \left(d4 \leq 5.8 \cdot 10^{+25}\right) \land d4 \leq 3.2 \cdot 10^{+73}\right):\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d4 < 3.74999999999999985e-79 or 4.5999999999999998e-49 < d4 < 2.1999999999999999e-29 or 5.7999999999999998e25 < d4 < 3.19999999999999982e73

    1. Initial program 90.6%

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

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

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

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

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

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

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

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

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

    if 3.74999999999999985e-79 < d4 < 4.5999999999999998e-49 or 2.1999999999999999e-29 < d4 < 5.7999999999999998e25 or 3.19999999999999982e73 < d4

    1. Initial program 92.5%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 3.75 \cdot 10^{-79} \lor \neg \left(d4 \leq 4.6 \cdot 10^{-49}\right) \land \left(d4 \leq 2.2 \cdot 10^{-29} \lor \neg \left(d4 \leq 5.8 \cdot 10^{+25}\right) \land d4 \leq 3.2 \cdot 10^{+73}\right):\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 3: 62.9% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;d4 \leq 5 \cdot 10^{-49}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 2.2 \cdot 10^{-29}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d4 \leq 1.18 \cdot 10^{+24}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 3.9 \cdot 10^{+71}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 3.74999999999999985e-79 or 4.9999999999999999e-49 < d4 < 2.1999999999999999e-29 or 1.17999999999999997e24 < d4 < 3.9000000000000001e71

    1. Initial program 90.6%

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

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

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

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

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

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

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

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

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

    if 3.74999999999999985e-79 < d4 < 4.9999999999999999e-49 or 2.1999999999999999e-29 < d4 < 1.17999999999999997e24

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    if 3.9000000000000001e71 < d4

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 3.75 \cdot 10^{-79}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 5 \cdot 10^{-49}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d4 \leq 2.2 \cdot 10^{-29}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 1.18 \cdot 10^{+24}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d4 \leq 3.9 \cdot 10^{+71}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]

Alternative 4: 67.1% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;d3 \leq 1.75 \cdot 10^{-214}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d3 \leq 1.8 \cdot 10^{+94}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -4.6e136 or 1.79999999999999996e94 < d3

    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. associate--l+88.7%

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

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

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

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

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

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

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

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

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

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

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

    if -4.6e136 < d3 < 1.75e-214 or 2.35000000000000007e-166 < d3 < 1.79999999999999996e94

    1. Initial program 92.1%

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

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

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

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

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

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

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

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

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

    if 1.75e-214 < d3 < 2.35000000000000007e-166

    1. Initial program 93.3%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -4.6 \cdot 10^{+136}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d3 \leq 1.75 \cdot 10^{-214}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d3 \leq 2.35 \cdot 10^{-166}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 1.8 \cdot 10^{+94}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \end{array} \]

Alternative 5: 39.4% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;d2 \leq -3.2 \cdot 10^{+74}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d2 \leq -4.1 \cdot 10^{+43}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d2 \leq 2.3 \cdot 10^{-242}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d2 < -8.5000000000000001e101 or -3.19999999999999995e74 < d2 < -4.1e43

    1. Initial program 80.4%

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

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

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

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

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

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

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

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

    if -8.5000000000000001e101 < d2 < -3.19999999999999995e74 or -4.1e43 < d2 < 2.29999999999999985e-242

    1. Initial program 95.8%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-d1 \cdot d3} \]
      2. distribute-lft-neg-in43.9%

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

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

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

    if 2.29999999999999985e-242 < d2

    1. Initial program 91.2%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -8.5 \cdot 10^{+101}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -3.2 \cdot 10^{+74}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d2 \leq -4.1 \cdot 10^{+43}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq 2.3 \cdot 10^{-242}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 6: 64.0% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;d4 \leq 1.22 \cdot 10^{-48}:\\
\;\;\;\;d1 \cdot \left(d2 - d1\right)\\

\mathbf{elif}\;d4 \leq 3.3 \cdot 10^{+73}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 3.8e-87 or 1.21999999999999993e-48 < d4 < 3.3000000000000003e73

    1. Initial program 90.9%

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

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

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

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

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

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

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

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

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

    if 3.8e-87 < d4 < 1.21999999999999993e-48

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    if 3.3000000000000003e73 < d4

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 3.8 \cdot 10^{-87}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 1.22 \cdot 10^{-48}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 3.3 \cdot 10^{+73}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]

Alternative 7: 90.1% accurate, 1.3× speedup?

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

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

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

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


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

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

    if -3.09999999999999983e136 < d3 < 5.4999999999999997e62

    1. Initial program 92.5%

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

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

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

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

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

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

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

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

    if 5.4999999999999997e62 < d3

    1. Initial program 87.0%

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

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

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

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

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

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

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

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

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

Alternative 8: 62.8% accurate, 1.5× speedup?

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

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

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

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


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

    1. Initial program 82.9%

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

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

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

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

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

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

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

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

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

    if -6.39999999999999989e78 < d2 < -1.5200000000000001e-261

    1. Initial program 92.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -\color{blue}{\left(d1 + d3\right) \cdot d1} \]
      3. distribute-rgt-neg-in71.9%

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

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

    if -1.5200000000000001e-261 < d2

    1. Initial program 92.9%

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

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

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

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

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

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

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

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

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

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

Alternative 9: 67.2% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -2.4 \cdot 10^{+136} \lor \neg \left(d3 \leq 7.8 \cdot 10^{+96}\right):\\
\;\;\;\;d1 \cdot \left(-d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -2.4e136 or 7.8e96 < d3

    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. associate--l+88.7%

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

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

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

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

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

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

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

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

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

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

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

    if -2.4e136 < d3 < 7.8e96

    1. Initial program 92.2%

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

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

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

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

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

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

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

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

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

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

Alternative 10: 82.4% accurate, 1.7× speedup?

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

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

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


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

    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. associate--l+81.8%

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

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

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

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

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

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

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

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

    if -1.55e87 < d2

    1. Initial program 92.9%

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

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

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

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

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

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

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

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

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

Alternative 11: 85.2% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 82.7%

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

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

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

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

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

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

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

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

    if -3.10000000000000005e56 < d2

    1. Initial program 93.4%

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

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

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

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

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

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

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

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

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

Alternative 12: 38.8% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -4.6 \cdot 10^{-26}:\\
\;\;\;\;d1 \cdot d2\\

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


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

    1. Initial program 85.3%

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

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

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

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

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

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

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

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

    if -4.60000000000000018e-26 < d2

    1. Initial program 93.1%

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

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

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

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

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

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

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

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

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

Alternative 13: 31.4% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{d1 \cdot d2} \]
  5. Final simplification30.7%

    \[\leadsto d1 \cdot d2 \]

Developer target: 100.0% accurate, 1.7× speedup?

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

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

Reproduce

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

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

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