FastMath dist4

Percentage Accurate: 88.0% → 100.0%
Time: 10.1s
Alternatives: 12
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 88.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.7× speedup?

\[\begin{array}{l} \\ d1 \cdot \left(\left(d2 - d3\right) + \left(d4 - d1\right)\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(d2 - d3) + Float64(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[(d2 - d3), $MachinePrecision] + N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
d1 \cdot \left(\left(d2 - d3\right) + \left(d4 - d1\right)\right)
\end{array}
Derivation
  1. Initial program 87.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+87.9%

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

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

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

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

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

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

Alternative 2: 39.3% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(-d3\right)\\ t_1 := d1 \cdot \left(-d1\right)\\ \mathbf{if}\;d2 \leq -9.4 \cdot 10^{+111}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -48000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq -1.05 \cdot 10^{-30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -9.2 \cdot 10^{-212}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq 8.5 \cdot 10^{-301}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq 1.95 \cdot 10^{-283}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d3))) (t_1 (* d1 (- d1))))
   (if (<= d2 -9.4e+111)
     (* d1 d2)
     (if (<= d2 -48000000.0)
       t_1
       (if (<= d2 -1.05e-30)
         t_0
         (if (<= d2 -9.2e-212)
           t_1
           (if (<= d2 8.5e-301) t_0 (if (<= d2 1.95e-283) t_1 (* d1 d4)))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * -d3;
	double t_1 = d1 * -d1;
	double tmp;
	if (d2 <= -9.4e+111) {
		tmp = d1 * d2;
	} else if (d2 <= -48000000.0) {
		tmp = t_1;
	} else if (d2 <= -1.05e-30) {
		tmp = t_0;
	} else if (d2 <= -9.2e-212) {
		tmp = t_1;
	} else if (d2 <= 8.5e-301) {
		tmp = t_0;
	} else if (d2 <= 1.95e-283) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = d1 * -d3
    t_1 = d1 * -d1
    if (d2 <= (-9.4d+111)) then
        tmp = d1 * d2
    else if (d2 <= (-48000000.0d0)) then
        tmp = t_1
    else if (d2 <= (-1.05d-30)) then
        tmp = t_0
    else if (d2 <= (-9.2d-212)) then
        tmp = t_1
    else if (d2 <= 8.5d-301) then
        tmp = t_0
    else if (d2 <= 1.95d-283) then
        tmp = t_1
    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 t_1 = d1 * -d1;
	double tmp;
	if (d2 <= -9.4e+111) {
		tmp = d1 * d2;
	} else if (d2 <= -48000000.0) {
		tmp = t_1;
	} else if (d2 <= -1.05e-30) {
		tmp = t_0;
	} else if (d2 <= -9.2e-212) {
		tmp = t_1;
	} else if (d2 <= 8.5e-301) {
		tmp = t_0;
	} else if (d2 <= 1.95e-283) {
		tmp = t_1;
	} else {
		tmp = d1 * d4;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * -d3
	t_1 = d1 * -d1
	tmp = 0
	if d2 <= -9.4e+111:
		tmp = d1 * d2
	elif d2 <= -48000000.0:
		tmp = t_1
	elif d2 <= -1.05e-30:
		tmp = t_0
	elif d2 <= -9.2e-212:
		tmp = t_1
	elif d2 <= 8.5e-301:
		tmp = t_0
	elif d2 <= 1.95e-283:
		tmp = t_1
	else:
		tmp = d1 * d4
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(-d3))
	t_1 = Float64(d1 * Float64(-d1))
	tmp = 0.0
	if (d2 <= -9.4e+111)
		tmp = Float64(d1 * d2);
	elseif (d2 <= -48000000.0)
		tmp = t_1;
	elseif (d2 <= -1.05e-30)
		tmp = t_0;
	elseif (d2 <= -9.2e-212)
		tmp = t_1;
	elseif (d2 <= 8.5e-301)
		tmp = t_0;
	elseif (d2 <= 1.95e-283)
		tmp = t_1;
	else
		tmp = Float64(d1 * d4);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * -d3;
	t_1 = d1 * -d1;
	tmp = 0.0;
	if (d2 <= -9.4e+111)
		tmp = d1 * d2;
	elseif (d2 <= -48000000.0)
		tmp = t_1;
	elseif (d2 <= -1.05e-30)
		tmp = t_0;
	elseif (d2 <= -9.2e-212)
		tmp = t_1;
	elseif (d2 <= 8.5e-301)
		tmp = t_0;
	elseif (d2 <= 1.95e-283)
		tmp = t_1;
	else
		tmp = d1 * d4;
	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[d2, -9.4e+111], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -48000000.0], t$95$1, If[LessEqual[d2, -1.05e-30], t$95$0, If[LessEqual[d2, -9.2e-212], t$95$1, If[LessEqual[d2, 8.5e-301], t$95$0, If[LessEqual[d2, 1.95e-283], t$95$1, N[(d1 * d4), $MachinePrecision]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d2 \leq -48000000:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d2 \leq -1.05 \cdot 10^{-30}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d2 \leq -9.2 \cdot 10^{-212}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d2 \leq 8.5 \cdot 10^{-301}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d2 \leq 1.95 \cdot 10^{-283}:\\
\;\;\;\;t_1\\

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


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

    1. Initial program 89.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+89.7%

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

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

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

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

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

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

    if -9.40000000000000015e111 < d2 < -4.8e7 or -1.0500000000000001e-30 < d2 < -9.2000000000000004e-212 or 8.50000000000000046e-301 < d2 < 1.9500000000000001e-283

    1. Initial program 88.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+88.2%

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

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

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

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

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

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

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

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

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

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

    if -4.8e7 < d2 < -1.0500000000000001e-30 or -9.2000000000000004e-212 < d2 < 8.50000000000000046e-301

    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. distribute-lft-out--87.0%

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

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

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

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

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

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

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

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

    if 1.9500000000000001e-283 < d2

    1. Initial program 87.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+87.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -9.4 \cdot 10^{+111}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -48000000:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d2 \leq -1.05 \cdot 10^{-30}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d2 \leq -9.2 \cdot 10^{-212}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d2 \leq 8.5 \cdot 10^{-301}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d2 \leq 1.95 \cdot 10^{-283}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 3: 62.5% 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}\;d4 \leq 5.8 \cdot 10^{-155}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq 1.95 \cdot 10^{-115}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.55 \cdot 10^{-46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq 5.4 \cdot 10^{+62}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d4 d1))) (t_1 (* d1 (- d2 d3))))
   (if (<= d4 5.8e-155)
     t_1
     (if (<= d4 1.95e-115)
       t_0
       (if (<= d4 1.55e-46) t_1 (if (<= d4 5.4e+62) t_0 (* 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 <= 5.8e-155) {
		tmp = t_1;
	} else if (d4 <= 1.95e-115) {
		tmp = t_0;
	} else if (d4 <= 1.55e-46) {
		tmp = t_1;
	} else if (d4 <= 5.4e+62) {
		tmp = t_0;
	} else {
		tmp = d1 * (d4 - d3);
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = d1 * (d4 - d1)
    t_1 = d1 * (d2 - d3)
    if (d4 <= 5.8d-155) then
        tmp = t_1
    else if (d4 <= 1.95d-115) then
        tmp = t_0
    else if (d4 <= 1.55d-46) then
        tmp = t_1
    else if (d4 <= 5.4d+62) then
        tmp = t_0
    else
        tmp = d1 * (d4 - d3)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d4 - d1);
	double t_1 = d1 * (d2 - d3);
	double tmp;
	if (d4 <= 5.8e-155) {
		tmp = t_1;
	} else if (d4 <= 1.95e-115) {
		tmp = t_0;
	} else if (d4 <= 1.55e-46) {
		tmp = t_1;
	} else if (d4 <= 5.4e+62) {
		tmp = t_0;
	} 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 <= 5.8e-155:
		tmp = t_1
	elif d4 <= 1.95e-115:
		tmp = t_0
	elif d4 <= 1.55e-46:
		tmp = t_1
	elif d4 <= 5.4e+62:
		tmp = t_0
	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 <= 5.8e-155)
		tmp = t_1;
	elseif (d4 <= 1.95e-115)
		tmp = t_0;
	elseif (d4 <= 1.55e-46)
		tmp = t_1;
	elseif (d4 <= 5.4e+62)
		tmp = t_0;
	else
		tmp = Float64(d1 * Float64(d4 - d3));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d4 - d1);
	t_1 = d1 * (d2 - d3);
	tmp = 0.0;
	if (d4 <= 5.8e-155)
		tmp = t_1;
	elseif (d4 <= 1.95e-115)
		tmp = t_0;
	elseif (d4 <= 1.55e-46)
		tmp = t_1;
	elseif (d4 <= 5.4e+62)
		tmp = t_0;
	else
		tmp = d1 * (d4 - d3);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d4, 5.8e-155], t$95$1, If[LessEqual[d4, 1.95e-115], t$95$0, If[LessEqual[d4, 1.55e-46], t$95$1, If[LessEqual[d4, 5.4e+62], t$95$0, 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 5.8 \cdot 10^{-155}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d4 \leq 1.95 \cdot 10^{-115}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 1.55 \cdot 10^{-46}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d4 \leq 5.4 \cdot 10^{+62}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 5.80000000000000021e-155 or 1.9499999999999999e-115 < d4 < 1.55e-46

    1. Initial program 88.5%

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

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

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

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

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

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

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

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

    if 5.80000000000000021e-155 < d4 < 1.9499999999999999e-115 or 1.55e-46 < d4 < 5.4e62

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

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

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

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

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

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

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

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

    if 5.4e62 < d4

    1. Initial program 85.4%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 5.8 \cdot 10^{-155}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 1.95 \cdot 10^{-115}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d4 \leq 1.55 \cdot 10^{-46}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 5.4 \cdot 10^{+62}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]

Alternative 4: 59.3% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;d2 \leq -1050000 \lor \neg \left(d2 \leq -6 \cdot 10^{-27}\right):\\
\;\;\;\;d1 \cdot \left(d4 - d1\right)\\

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


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

    1. Initial program 89.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+89.7%

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

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

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

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

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

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

    if -7.79999999999999958e111 < d2 < -1.05e6 or -6.0000000000000002e-27 < d2

    1. Initial program 87.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+87.2%

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

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

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

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

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

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

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

    if -1.05e6 < d2 < -6.0000000000000002e-27

    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. distribute-lft-out--100.0%

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

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

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

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

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

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

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

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

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

Alternative 5: 60.9% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;d2 \leq -1050000 \lor \neg \left(d2 \leq -1.05 \cdot 10^{-30}\right):\\
\;\;\;\;d1 \cdot \left(d4 - d1\right)\\

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


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

    1. Initial program 89.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+89.7%

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

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

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

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

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

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

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

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

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

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

    if -5.4999999999999998e111 < d2 < -1.05e6 or -1.0500000000000001e-30 < d2

    1. Initial program 87.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+87.2%

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

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

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

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

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

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

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

    if -1.05e6 < d2 < -1.0500000000000001e-30

    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. distribute-lft-out--100.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -5.5 \cdot 10^{+111}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{elif}\;d2 \leq -1050000 \lor \neg \left(d2 \leq -1.05 \cdot 10^{-30}\right):\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \end{array} \]

Alternative 6: 61.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -2.9 \cdot 10^{+39} \lor \neg \left(d2 \leq -4200000\right) \land d2 \leq -6 \cdot 10^{-27}:\\ \;\;\;\;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 (<= d2 -2.9e+39) (and (not (<= d2 -4200000.0)) (<= d2 -6e-27)))
   (* d1 (- d2 d3))
   (* d1 (- d4 d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d2 <= -2.9e+39) || (!(d2 <= -4200000.0) && (d2 <= -6e-27))) {
		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 ((d2 <= (-2.9d+39)) .or. (.not. (d2 <= (-4200000.0d0))) .and. (d2 <= (-6d-27))) 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 ((d2 <= -2.9e+39) || (!(d2 <= -4200000.0) && (d2 <= -6e-27))) {
		tmp = d1 * (d2 - d3);
	} else {
		tmp = d1 * (d4 - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if (d2 <= -2.9e+39) or (not (d2 <= -4200000.0) and (d2 <= -6e-27)):
		tmp = d1 * (d2 - d3)
	else:
		tmp = d1 * (d4 - d1)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d2 <= -2.9e+39) || (!(d2 <= -4200000.0) && (d2 <= -6e-27)))
		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 ((d2 <= -2.9e+39) || (~((d2 <= -4200000.0)) && (d2 <= -6e-27)))
		tmp = d1 * (d2 - d3);
	else
		tmp = d1 * (d4 - d1);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d2, -2.9e+39], And[N[Not[LessEqual[d2, -4200000.0]], $MachinePrecision], LessEqual[d2, -6e-27]]], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -2.9 \cdot 10^{+39} \lor \neg \left(d2 \leq -4200000\right) \land d2 \leq -6 \cdot 10^{-27}:\\
\;\;\;\;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 d2 < -2.90000000000000029e39 or -4.2e6 < d2 < -6.0000000000000002e-27

    1. Initial program 88.5%

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d3\right) + \left(d4 - d1\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 74.0%

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

    if -2.90000000000000029e39 < d2 < -4.2e6 or -6.0000000000000002e-27 < d2

    1. Initial program 87.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+87.7%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -2.9 \cdot 10^{+39} \lor \neg \left(d2 \leq -4200000\right) \land d2 \leq -6 \cdot 10^{-27}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 7: 63.4% accurate, 1.5× speedup?

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

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

\mathbf{elif}\;d2 \leq 1.2 \cdot 10^{-283}:\\
\;\;\;\;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 < -8.3999999999999998e111

    1. Initial program 89.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+89.7%

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

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

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

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

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

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

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

    if -8.3999999999999998e111 < d2 < 1.2e-283

    1. Initial program 87.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+87.7%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-1 \cdot \left(d1 + d3\right)\right) \cdot d1} \]
      2. neg-mul-170.4%

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

        \[\leadsto \color{blue}{d1 \cdot \left(-\left(d1 + d3\right)\right)} \]
      4. distribute-neg-in70.4%

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

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

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

    if 1.2e-283 < d2

    1. Initial program 87.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+87.4%

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

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

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

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

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

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

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

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

Alternative 8: 83.0% accurate, 1.7× speedup?

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

    1. Initial program 89.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+89.7%

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

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

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

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

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

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

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

    if -1.0499999999999999e112 < d2

    1. Initial program 87.5%

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

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

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

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

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

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

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

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

Alternative 9: 84.7% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -6.2 \cdot 10^{+111}:\\
\;\;\;\;d1 \cdot \left(\left(d2 + d4\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 < -6.2000000000000001e111

    1. Initial program 89.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+89.7%

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

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

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

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

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

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

    if -6.2000000000000001e111 < d2

    1. Initial program 87.5%

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

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

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

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

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

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

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

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

Alternative 10: 39.3% accurate, 1.8× speedup?

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

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

\mathbf{elif}\;d2 \leq 2.1 \cdot 10^{-283}:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\

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


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

    1. Initial program 89.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+89.7%

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

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

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

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

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

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

    if -9.00000000000000001e111 < d2 < 2.09999999999999997e-283

    1. Initial program 87.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+87.9%

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

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

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

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

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

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

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

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

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

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

    if 2.09999999999999997e-283 < d2

    1. Initial program 87.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+87.3%

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

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

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

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

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

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

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

Alternative 11: 39.8% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 88.5%

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

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

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

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

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

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

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

    if 3.50000000000000006e50 < d4

    1. Initial program 85.4%

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

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

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

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

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

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

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

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

Alternative 12: 31.3% 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 87.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+87.9%

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

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

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

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

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

    \[\leadsto \color{blue}{d1 \cdot d4} \]
  5. Final simplification31.9%

    \[\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 2023187 
(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)))