FastMath dist4

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 63.0% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(-d1\right)\\ t_1 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d1 \leq -7 \cdot 10^{+156}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d1 \leq -4 \cdot 10^{+101}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d1 \leq -1.95 \cdot 10^{+54}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d1 \leq -6.8 \cdot 10^{-144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d1 \leq -2.4 \cdot 10^{-240}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d1 \leq 1.08 \cdot 10^{+176}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d1))) (t_1 (* d1 (+ d4 d2))))
   (if (<= d1 -7e+156)
     t_0
     (if (<= d1 -4e+101)
       t_1
       (if (<= d1 -1.95e+54)
         t_0
         (if (<= d1 -6.8e-144)
           t_1
           (if (<= d1 -2.4e-240)
             (* d1 (- d3))
             (if (<= d1 1.08e+176) t_1 t_0))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * -d1;
	double t_1 = d1 * (d4 + d2);
	double tmp;
	if (d1 <= -7e+156) {
		tmp = t_0;
	} else if (d1 <= -4e+101) {
		tmp = t_1;
	} else if (d1 <= -1.95e+54) {
		tmp = t_0;
	} else if (d1 <= -6.8e-144) {
		tmp = t_1;
	} else if (d1 <= -2.4e-240) {
		tmp = d1 * -d3;
	} else if (d1 <= 1.08e+176) {
		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 * -d1
    t_1 = d1 * (d4 + d2)
    if (d1 <= (-7d+156)) then
        tmp = t_0
    else if (d1 <= (-4d+101)) then
        tmp = t_1
    else if (d1 <= (-1.95d+54)) then
        tmp = t_0
    else if (d1 <= (-6.8d-144)) then
        tmp = t_1
    else if (d1 <= (-2.4d-240)) then
        tmp = d1 * -d3
    else if (d1 <= 1.08d+176) 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 * -d1;
	double t_1 = d1 * (d4 + d2);
	double tmp;
	if (d1 <= -7e+156) {
		tmp = t_0;
	} else if (d1 <= -4e+101) {
		tmp = t_1;
	} else if (d1 <= -1.95e+54) {
		tmp = t_0;
	} else if (d1 <= -6.8e-144) {
		tmp = t_1;
	} else if (d1 <= -2.4e-240) {
		tmp = d1 * -d3;
	} else if (d1 <= 1.08e+176) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * -d1
	t_1 = d1 * (d4 + d2)
	tmp = 0
	if d1 <= -7e+156:
		tmp = t_0
	elif d1 <= -4e+101:
		tmp = t_1
	elif d1 <= -1.95e+54:
		tmp = t_0
	elif d1 <= -6.8e-144:
		tmp = t_1
	elif d1 <= -2.4e-240:
		tmp = d1 * -d3
	elif d1 <= 1.08e+176:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(-d1))
	t_1 = Float64(d1 * Float64(d4 + d2))
	tmp = 0.0
	if (d1 <= -7e+156)
		tmp = t_0;
	elseif (d1 <= -4e+101)
		tmp = t_1;
	elseif (d1 <= -1.95e+54)
		tmp = t_0;
	elseif (d1 <= -6.8e-144)
		tmp = t_1;
	elseif (d1 <= -2.4e-240)
		tmp = Float64(d1 * Float64(-d3));
	elseif (d1 <= 1.08e+176)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * -d1;
	t_1 = d1 * (d4 + d2);
	tmp = 0.0;
	if (d1 <= -7e+156)
		tmp = t_0;
	elseif (d1 <= -4e+101)
		tmp = t_1;
	elseif (d1 <= -1.95e+54)
		tmp = t_0;
	elseif (d1 <= -6.8e-144)
		tmp = t_1;
	elseif (d1 <= -2.4e-240)
		tmp = d1 * -d3;
	elseif (d1 <= 1.08e+176)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * (-d1)), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d1, -7e+156], t$95$0, If[LessEqual[d1, -4e+101], t$95$1, If[LessEqual[d1, -1.95e+54], t$95$0, If[LessEqual[d1, -6.8e-144], t$95$1, If[LessEqual[d1, -2.4e-240], N[(d1 * (-d3)), $MachinePrecision], If[LessEqual[d1, 1.08e+176], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d1 \leq -4 \cdot 10^{+101}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d1 \leq -1.95 \cdot 10^{+54}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d1 \leq -6.8 \cdot 10^{-144}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d1 \leq 1.08 \cdot 10^{+176}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d1 < -7.0000000000000006e156 or -3.9999999999999999e101 < d1 < -1.9500000000000001e54 or 1.08e176 < d1

    1. Initial program 56.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.0000000000000006e156 < d1 < -3.9999999999999999e101 or -1.9500000000000001e54 < d1 < -6.80000000000000035e-144 or -2.3999999999999999e-240 < d1 < 1.08e176

    1. Initial program 96.8%

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

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

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

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

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

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

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

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

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

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

    if -6.80000000000000035e-144 < d1 < -2.3999999999999999e-240

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -7 \cdot 10^{+156}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d1 \leq -4 \cdot 10^{+101}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d1 \leq -1.95 \cdot 10^{+54}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d1 \leq -6.8 \cdot 10^{-144}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d1 \leq -2.4 \cdot 10^{-240}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d1 \leq 1.08 \cdot 10^{+176}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \end{array} \]

Alternative 3: 47.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(-d3\right)\\ t_1 := d1 \cdot \left(-d1\right)\\ \mathbf{if}\;d3 \leq -4.2 \cdot 10^{+88}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq -5.2 \cdot 10^{-150}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 2.1 \cdot 10^{-211}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d3 \leq 4 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 6 \cdot 10^{+92}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d3))) (t_1 (* d1 (- d1))))
   (if (<= d3 -4.2e+88)
     t_0
     (if (<= d3 -5.2e-150)
       t_1
       (if (<= d3 2.1e-211)
         (* d1 d2)
         (if (<= d3 4e-88) t_1 (if (<= d3 6e+92) (* d1 d4) t_0)))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * -d3;
	double t_1 = d1 * -d1;
	double tmp;
	if (d3 <= -4.2e+88) {
		tmp = t_0;
	} else if (d3 <= -5.2e-150) {
		tmp = t_1;
	} else if (d3 <= 2.1e-211) {
		tmp = d1 * d2;
	} else if (d3 <= 4e-88) {
		tmp = t_1;
	} else if (d3 <= 6e+92) {
		tmp = d1 * d4;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = d1 * -d3
    t_1 = d1 * -d1
    if (d3 <= (-4.2d+88)) then
        tmp = t_0
    else if (d3 <= (-5.2d-150)) then
        tmp = t_1
    else if (d3 <= 2.1d-211) then
        tmp = d1 * d2
    else if (d3 <= 4d-88) then
        tmp = t_1
    else if (d3 <= 6d+92) then
        tmp = d1 * d4
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * -d3;
	double t_1 = d1 * -d1;
	double tmp;
	if (d3 <= -4.2e+88) {
		tmp = t_0;
	} else if (d3 <= -5.2e-150) {
		tmp = t_1;
	} else if (d3 <= 2.1e-211) {
		tmp = d1 * d2;
	} else if (d3 <= 4e-88) {
		tmp = t_1;
	} else if (d3 <= 6e+92) {
		tmp = d1 * d4;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * -d3
	t_1 = d1 * -d1
	tmp = 0
	if d3 <= -4.2e+88:
		tmp = t_0
	elif d3 <= -5.2e-150:
		tmp = t_1
	elif d3 <= 2.1e-211:
		tmp = d1 * d2
	elif d3 <= 4e-88:
		tmp = t_1
	elif d3 <= 6e+92:
		tmp = d1 * d4
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(-d3))
	t_1 = Float64(d1 * Float64(-d1))
	tmp = 0.0
	if (d3 <= -4.2e+88)
		tmp = t_0;
	elseif (d3 <= -5.2e-150)
		tmp = t_1;
	elseif (d3 <= 2.1e-211)
		tmp = Float64(d1 * d2);
	elseif (d3 <= 4e-88)
		tmp = t_1;
	elseif (d3 <= 6e+92)
		tmp = Float64(d1 * d4);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * -d3;
	t_1 = d1 * -d1;
	tmp = 0.0;
	if (d3 <= -4.2e+88)
		tmp = t_0;
	elseif (d3 <= -5.2e-150)
		tmp = t_1;
	elseif (d3 <= 2.1e-211)
		tmp = d1 * d2;
	elseif (d3 <= 4e-88)
		tmp = t_1;
	elseif (d3 <= 6e+92)
		tmp = d1 * d4;
	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 * (-d1)), $MachinePrecision]}, If[LessEqual[d3, -4.2e+88], t$95$0, If[LessEqual[d3, -5.2e-150], t$95$1, If[LessEqual[d3, 2.1e-211], N[(d1 * d2), $MachinePrecision], If[LessEqual[d3, 4e-88], t$95$1, If[LessEqual[d3, 6e+92], N[(d1 * d4), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d3 \leq -5.2 \cdot 10^{-150}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d3 \leq 2.1 \cdot 10^{-211}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d3 \leq 4 \cdot 10^{-88}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d3 \leq 6 \cdot 10^{+92}:\\
\;\;\;\;d1 \cdot d4\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d3 < -4.2e88 or 6.00000000000000026e92 < d3

    1. Initial program 81.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.2e88 < d3 < -5.1999999999999995e-150 or 2.10000000000000008e-211 < d3 < 3.99999999999999974e-88

    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. +-commutative81.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.1999999999999995e-150 < d3 < 2.10000000000000008e-211

    1. Initial program 96.1%

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

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

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

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

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

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

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

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

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

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

    if 3.99999999999999974e-88 < d3 < 6.00000000000000026e92

    1. Initial program 86.7%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -4.2 \cdot 10^{+88}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d3 \leq -5.2 \cdot 10^{-150}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d3 \leq 2.1 \cdot 10^{-211}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d3 \leq 4 \cdot 10^{-88}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d3 \leq 6 \cdot 10^{+92}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \end{array} \]

Alternative 4: 67.0% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;d1 \leq -4.5 \cdot 10^{-144}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d1 \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d1 < -3.0999999999999999e54 or 5.60000000000000037e102 < d1

    1. Initial program 62.0%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2} + d1 \cdot d4} \]
    8. Step-by-step derivation
      1. +-commutative71.3%

        \[\leadsto \color{blue}{d1 \cdot d4 + -1 \cdot {d1}^{2}} \]
      2. unpow271.3%

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

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

        \[\leadsto \color{blue}{d1 \cdot d4 - d1 \cdot d1} \]
      5. distribute-lft-out--84.3%

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

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

    if -3.0999999999999999e54 < d1 < -4.4999999999999998e-144 or -4.1000000000000001e-240 < d1 < 5.60000000000000037e102

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

    if -4.4999999999999998e-144 < d1 < -4.1000000000000001e-240

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -3.1 \cdot 10^{+54}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d1 \leq -4.5 \cdot 10^{-144}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d1 \leq -4.1 \cdot 10^{-240}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d1 \leq 5.6 \cdot 10^{+102}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 5: 69.8% accurate, 1.1× 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}\;d1 \leq -1.3 \cdot 10^{+46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d1 \leq 9.5 \cdot 10^{-188}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d1 \leq 6.5 \cdot 10^{-82}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{elif}\;d1 \leq 7.5 \cdot 10^{+122}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d4 d1))) (t_1 (* d1 (- d2 d3))))
   (if (<= d1 -1.3e+46)
     t_0
     (if (<= d1 9.5e-188)
       t_1
       (if (<= d1 6.5e-82) (* d1 (- d4 d3)) (if (<= d1 7.5e+122) t_1 t_0))))))
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 (d1 <= -1.3e+46) {
		tmp = t_0;
	} else if (d1 <= 9.5e-188) {
		tmp = t_1;
	} else if (d1 <= 6.5e-82) {
		tmp = d1 * (d4 - d3);
	} else if (d1 <= 7.5e+122) {
		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 * (d4 - d1)
    t_1 = d1 * (d2 - d3)
    if (d1 <= (-1.3d+46)) then
        tmp = t_0
    else if (d1 <= 9.5d-188) then
        tmp = t_1
    else if (d1 <= 6.5d-82) then
        tmp = d1 * (d4 - d3)
    else if (d1 <= 7.5d+122) 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 * (d4 - d1);
	double t_1 = d1 * (d2 - d3);
	double tmp;
	if (d1 <= -1.3e+46) {
		tmp = t_0;
	} else if (d1 <= 9.5e-188) {
		tmp = t_1;
	} else if (d1 <= 6.5e-82) {
		tmp = d1 * (d4 - d3);
	} else if (d1 <= 7.5e+122) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d4 - d1)
	t_1 = d1 * (d2 - d3)
	tmp = 0
	if d1 <= -1.3e+46:
		tmp = t_0
	elif d1 <= 9.5e-188:
		tmp = t_1
	elif d1 <= 6.5e-82:
		tmp = d1 * (d4 - d3)
	elif d1 <= 7.5e+122:
		tmp = t_1
	else:
		tmp = t_0
	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 (d1 <= -1.3e+46)
		tmp = t_0;
	elseif (d1 <= 9.5e-188)
		tmp = t_1;
	elseif (d1 <= 6.5e-82)
		tmp = Float64(d1 * Float64(d4 - d3));
	elseif (d1 <= 7.5e+122)
		tmp = t_1;
	else
		tmp = t_0;
	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 (d1 <= -1.3e+46)
		tmp = t_0;
	elseif (d1 <= 9.5e-188)
		tmp = t_1;
	elseif (d1 <= 6.5e-82)
		tmp = d1 * (d4 - d3);
	elseif (d1 <= 7.5e+122)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d1, -1.3e+46], t$95$0, If[LessEqual[d1, 9.5e-188], t$95$1, If[LessEqual[d1, 6.5e-82], N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d1, 7.5e+122], t$95$1, t$95$0]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d1 \leq 9.5 \cdot 10^{-188}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d1 \leq 7.5 \cdot 10^{+122}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d1 < -1.30000000000000007e46 or 7.5000000000000002e122 < d1

    1. Initial program 61.6%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2} + d1 \cdot d4} \]
    8. Step-by-step derivation
      1. +-commutative71.1%

        \[\leadsto \color{blue}{d1 \cdot d4 + -1 \cdot {d1}^{2}} \]
      2. unpow271.1%

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

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

        \[\leadsto \color{blue}{d1 \cdot d4 - d1 \cdot d1} \]
      5. distribute-lft-out--84.2%

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

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

    if -1.30000000000000007e46 < d1 < 9.50000000000000063e-188 or 6.4999999999999997e-82 < d1 < 7.5000000000000002e122

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

    if 9.50000000000000063e-188 < d1 < 6.4999999999999997e-82

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -1.3 \cdot 10^{+46}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d1 \leq 9.5 \cdot 10^{-188}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d1 \leq 6.5 \cdot 10^{-82}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{elif}\;d1 \leq 7.5 \cdot 10^{+122}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 6: 69.4% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -1.25 \cdot 10^{+46} \lor \neg \left(d1 \leq 7.3 \cdot 10^{+124}\right):\\
\;\;\;\;d1 \cdot \left(d4 - d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -1.2500000000000001e46 or 7.29999999999999994e124 < d1

    1. Initial program 61.6%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2} + d1 \cdot d4} \]
    8. Step-by-step derivation
      1. +-commutative71.1%

        \[\leadsto \color{blue}{d1 \cdot d4 + -1 \cdot {d1}^{2}} \]
      2. unpow271.1%

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

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

        \[\leadsto \color{blue}{d1 \cdot d4 - d1 \cdot d1} \]
      5. distribute-lft-out--84.2%

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

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

    if -1.2500000000000001e46 < d1 < 7.29999999999999994e124

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 82.5% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 86.2%

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

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

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

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

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

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

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

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

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

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

    if 4.6e110 < d4

    1. Initial program 78.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 39.6% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 2.9 \cdot 10^{-228}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d4 \leq 6 \cdot 10^{+42}:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\

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


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

    1. Initial program 85.5%

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

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

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

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

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

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

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

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

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

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

    if 2.9000000000000001e-228 < d4 < 6.00000000000000058e42

    1. Initial program 91.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.00000000000000058e42 < d4

    1. Initial program 77.1%

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 62.5% accurate, 2.1× speedup?

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

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

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


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

    1. Initial program 74.6%

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

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

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

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

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

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

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

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

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

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

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

    if -2.79999999999999999e35 < d2

    1. Initial program 88.9%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2} + d1 \cdot d4} \]
    8. Step-by-step derivation
      1. +-commutative57.2%

        \[\leadsto \color{blue}{d1 \cdot d4 + -1 \cdot {d1}^{2}} \]
      2. unpow257.2%

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

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

        \[\leadsto \color{blue}{d1 \cdot d4 - d1 \cdot d1} \]
      5. distribute-lft-out--61.4%

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

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

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

Alternative 10: 38.8% accurate, 3.0× speedup?

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

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

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


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

    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. +-commutative87.0%

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

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

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

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

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

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

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

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

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

    if 1.12e43 < d4

    1. Initial program 77.1%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 1.12 \cdot 10^{+43}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 11: 31.5% accurate, 5.0× speedup?

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

\\
d1 \cdot d4
\end{array}
Derivation
  1. Initial program 85.1%

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{d1 \cdot d4} \]
  5. Final simplification29.4%

    \[\leadsto d1 \cdot d4 \]

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 2023238 
(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)))