FastMath dist4

Percentage Accurate: 88.4% → 100.0%
Time: 6.9s
Alternatives: 14
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 14 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.4% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

Alternative 2: 39.4% accurate, 0.9× speedup?

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

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

\mathbf{elif}\;d4 \leq -1.8 \cdot 10^{-230}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d4 \leq 3.6 \cdot 10^{-255}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d4 \leq 4 \cdot 10^{-151}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 9.6 \cdot 10^{-16}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d4 \leq 4.1 \cdot 10^{+68}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d4 < -3.90000000000000021e-170 or -1.7999999999999999e-230 < d4 < 3.6000000000000002e-255

    1. Initial program 88.8%

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

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

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

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

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

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

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

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

    if -3.90000000000000021e-170 < d4 < -1.7999999999999999e-230 or 3.9999999999999998e-151 < d4 < 9.60000000000000019e-16

    1. Initial program 85.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+85.7%

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

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

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

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

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

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

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

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

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

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

    if 3.6000000000000002e-255 < d4 < 3.9999999999999998e-151 or 9.60000000000000019e-16 < d4 < 4.0999999999999999e68

    1. Initial program 90.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+90.0%

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

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

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

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

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

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

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

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

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

    if 4.0999999999999999e68 < d4

    1. Initial program 87.8%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -3.9 \cdot 10^{-170}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq -1.8 \cdot 10^{-230}:\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 3.6 \cdot 10^{-255}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 4 \cdot 10^{-151}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 9.6 \cdot 10^{-16}:\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 4.1 \cdot 10^{+68}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 3: 60.0% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;d4 \leq -4.5 \cdot 10^{-219}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d4 \leq 4.5 \cdot 10^{-151}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 2.6 \cdot 10^{-119}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d4 \leq 1.25 \cdot 10^{+67}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < -2.29999999999999988e-173 or -4.50000000000000014e-219 < d4 < 4.5000000000000002e-151 or 2.60000000000000012e-119 < d4 < 1.24999999999999994e67

    1. Initial program 88.7%

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

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

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

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

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

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

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

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

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

    if -2.29999999999999988e-173 < d4 < -4.50000000000000014e-219 or 4.5000000000000002e-151 < d4 < 2.60000000000000012e-119

    1. Initial program 84.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+84.2%

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

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

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

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

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

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

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

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

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

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

    if 1.24999999999999994e67 < d4

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -2.3 \cdot 10^{-173}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq -4.5 \cdot 10^{-219}:\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 4.5 \cdot 10^{-151}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 2.6 \cdot 10^{-119}:\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 1.25 \cdot 10^{+67}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]

Alternative 4: 63.2% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;d4 \leq 1.3 \cdot 10^{-151}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 1.3 \cdot 10^{-16}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d4 \leq 2.9 \cdot 10^{+66}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 5.2 \cdot 10^{+74}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < -7.2000000000000002e-267 or 1.3e-151 < d4 < 1.2999999999999999e-16 or 2.89999999999999986e66 < d4 < 5.2000000000000001e74

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

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

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

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

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

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

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

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

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

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

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

    if -7.2000000000000002e-267 < d4 < 1.3e-151 or 1.2999999999999999e-16 < d4 < 2.89999999999999986e66

    1. Initial program 90.7%

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

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

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

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

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

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

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

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

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

    if 5.2000000000000001e74 < d4

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -7.2 \cdot 10^{-267}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 1.3 \cdot 10^{-151}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 1.3 \cdot 10^{-16}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 2.9 \cdot 10^{+66}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 5.2 \cdot 10^{+74}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]

Alternative 5: 62.1% accurate, 1.1× speedup?

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

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

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

\mathbf{elif}\;d2 \leq -2.4 \cdot 10^{-177} \lor \neg \left(d2 \leq -3.5 \cdot 10^{-300}\right):\\
\;\;\;\;d1 \cdot \left(d4 - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d2 < -9.9999999999999996e-39

    1. Initial program 88.1%

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

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

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

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

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

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

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

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

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

    if -9.9999999999999996e-39 < d2 < -3.10000000000000002e-84

    1. Initial program 71.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+71.4%

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

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

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

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

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

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

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

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

    if -3.10000000000000002e-84 < d2 < -2.3999999999999999e-177 or -3.5000000000000002e-300 < d2

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

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

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

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

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

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

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

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

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

    if -2.3999999999999999e-177 < d2 < -3.5000000000000002e-300

    1. Initial program 88.3%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1 \cdot 10^{-38}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d2 \leq -3.1 \cdot 10^{-84}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d2 \leq -2.4 \cdot 10^{-177} \lor \neg \left(d2 \leq -3.5 \cdot 10^{-300}\right):\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 6: 88.6% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -3.2 \cdot 10^{+109} \lor \neg \left(d3 \leq 1.05 \cdot 10^{+194}\right):\\
\;\;\;\;d1 \cdot \left(d4 - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -3.2000000000000001e109 or 1.05000000000000008e194 < d3

    1. Initial program 80.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+80.3%

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

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

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

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

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

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

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

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

    if -3.2000000000000001e109 < d3 < 1.05000000000000008e194

    1. Initial program 90.7%

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

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

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

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

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

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

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

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

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

Alternative 7: 93.1% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -2.4 \cdot 10^{+105} \lor \neg \left(d3 \leq 1.85 \cdot 10^{+18}\right):\\
\;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -2.39999999999999975e105 or 1.85e18 < d3

    1. Initial program 83.0%

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

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

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

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

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

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

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

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

    if -2.39999999999999975e105 < d3 < 1.85e18

    1. Initial program 91.6%

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

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

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

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

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

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

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

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

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

Alternative 8: 63.0% accurate, 1.5× speedup?

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

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

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

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


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

    1. Initial program 88.1%

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

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

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

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

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

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

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

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

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

    if -1.41999999999999996e-36 < d2 < 2.0500000000000001e-134

    1. Initial program 91.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+91.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.0500000000000001e-134 < d2

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

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

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

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

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

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

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

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

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

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

Alternative 9: 67.9% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -3.6 \cdot 10^{+118} \lor \neg \left(d3 \leq 5.4 \cdot 10^{+195}\right):\\
\;\;\;\;d3 \cdot \left(-d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -3.6e118 or 5.4000000000000003e195 < d3

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

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

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

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

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

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

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

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

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

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

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

    if -3.6e118 < d3 < 5.4000000000000003e195

    1. Initial program 90.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -3.6 \cdot 10^{+118} \lor \neg \left(d3 \leq 5.4 \cdot 10^{+195}\right):\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]

Alternative 10: 84.8% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 88.3%

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

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

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

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

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

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

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

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

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

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

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

    if 2.3e66 < d4

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

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

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

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

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

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

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

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

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

Alternative 11: 39.2% accurate, 1.8× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

    if -4.19999999999999982e-31 < d2 < 1.04999999999999999e-131

    1. Initial program 91.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+91.4%

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

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

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

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

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

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

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

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

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

    if 1.04999999999999999e-131 < d2

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

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

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

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

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

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

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

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

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

Alternative 12: 62.4% accurate, 2.1× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

    if -1.9000000000000002e-30 < d2

    1. Initial program 88.3%

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

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

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

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

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

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

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

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

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

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

Alternative 13: 39.0% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 88.3%

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

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

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

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

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

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

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

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

    if 1.01999999999999996e64 < d4

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

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

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

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

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

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

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

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

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

Alternative 14: 30.4% accurate, 5.0× speedup?

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

\\
d1 \cdot d2
\end{array}
Derivation
  1. Initial program 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. +-commutative88.2%

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

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

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

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

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

    \[\leadsto \color{blue}{d1 \cdot d2} \]
  5. Final simplification32.2%

    \[\leadsto d1 \cdot d2 \]

Developer target: 100.0% accurate, 1.7× speedup?

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

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

Reproduce

?
herbie shell --seed 2023333 
(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)))