FastMath dist4

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

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 87.6% 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 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--90.2%

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

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

Alternative 2: 38.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -4.25 \cdot 10^{+18}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -5.6 \cdot 10^{-171} \lor \neg \left(d2 \leq -1.14 \cdot 10^{-240}\right) \land d2 \leq 1.02 \cdot 10^{-251}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -4.25e+18)
   (* d1 d2)
   (if (or (<= d2 -5.6e-171) (and (not (<= d2 -1.14e-240)) (<= d2 1.02e-251)))
     (* d1 (- d3))
     (* d1 d4))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -4.25e+18) {
		tmp = d1 * d2;
	} else if ((d2 <= -5.6e-171) || (!(d2 <= -1.14e-240) && (d2 <= 1.02e-251))) {
		tmp = d1 * -d3;
	} 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.25d+18)) then
        tmp = d1 * d2
    else if ((d2 <= (-5.6d-171)) .or. (.not. (d2 <= (-1.14d-240))) .and. (d2 <= 1.02d-251)) then
        tmp = d1 * -d3
    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.25e+18) {
		tmp = d1 * d2;
	} else if ((d2 <= -5.6e-171) || (!(d2 <= -1.14e-240) && (d2 <= 1.02e-251))) {
		tmp = d1 * -d3;
	} else {
		tmp = d1 * d4;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -4.25e+18:
		tmp = d1 * d2
	elif (d2 <= -5.6e-171) or (not (d2 <= -1.14e-240) and (d2 <= 1.02e-251)):
		tmp = d1 * -d3
	else:
		tmp = d1 * d4
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -4.25e+18)
		tmp = Float64(d1 * d2);
	elseif ((d2 <= -5.6e-171) || (!(d2 <= -1.14e-240) && (d2 <= 1.02e-251)))
		tmp = Float64(d1 * Float64(-d3));
	else
		tmp = Float64(d1 * d4);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -4.25e+18)
		tmp = d1 * d2;
	elseif ((d2 <= -5.6e-171) || (~((d2 <= -1.14e-240)) && (d2 <= 1.02e-251)))
		tmp = d1 * -d3;
	else
		tmp = d1 * d4;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -4.25e+18], N[(d1 * d2), $MachinePrecision], If[Or[LessEqual[d2, -5.6e-171], And[N[Not[LessEqual[d2, -1.14e-240]], $MachinePrecision], LessEqual[d2, 1.02e-251]]], N[(d1 * (-d3)), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;d2 \leq -5.6 \cdot 10^{-171} \lor \neg \left(d2 \leq -1.14 \cdot 10^{-240}\right) \land d2 \leq 1.02 \cdot 10^{-251}:\\
\;\;\;\;d1 \cdot \left(-d3\right)\\

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


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

    1. Initial program 78.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+78.7%

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

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

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

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

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

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

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

    if -4.25e18 < d2 < -5.60000000000000046e-171 or -1.14e-240 < d2 < 1.0200000000000001e-251

    1. Initial program 95.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+95.0%

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + \left(d1 \cdot d2 - d1 \cdot d3\right) \]
      4. distribute-lft-out--96.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 inf 56.2%

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

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

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

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

    if -5.60000000000000046e-171 < d2 < -1.14e-240 or 1.0200000000000001e-251 < d2

    1. Initial program 91.1%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -4.25 \cdot 10^{+18}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -5.6 \cdot 10^{-171} \lor \neg \left(d2 \leq -1.14 \cdot 10^{-240}\right) \land d2 \leq 1.02 \cdot 10^{-251}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 3: 60.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d1\right)\\ \mathbf{if}\;d4 \leq 1.25 \cdot 10^{-232}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 2.4 \cdot 10^{-182}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d4 \leq 4 \cdot 10^{+80}:\\ \;\;\;\;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))))
   (if (<= d4 1.25e-232)
     t_0
     (if (<= d4 2.4e-182)
       (* d1 (- d3))
       (if (<= d4 4e+80) t_0 (* d1 (+ d4 d2)))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d1);
	double tmp;
	if (d4 <= 1.25e-232) {
		tmp = t_0;
	} else if (d4 <= 2.4e-182) {
		tmp = d1 * -d3;
	} else if (d4 <= 4e+80) {
		tmp = t_0;
	} else {
		tmp = d1 * (d4 + d2);
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: tmp
    t_0 = d1 * (d2 - d1)
    if (d4 <= 1.25d-232) then
        tmp = t_0
    else if (d4 <= 2.4d-182) then
        tmp = d1 * -d3
    else if (d4 <= 4d+80) 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 tmp;
	if (d4 <= 1.25e-232) {
		tmp = t_0;
	} else if (d4 <= 2.4e-182) {
		tmp = d1 * -d3;
	} else if (d4 <= 4e+80) {
		tmp = t_0;
	} else {
		tmp = d1 * (d4 + d2);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d1)
	tmp = 0
	if d4 <= 1.25e-232:
		tmp = t_0
	elif d4 <= 2.4e-182:
		tmp = d1 * -d3
	elif d4 <= 4e+80:
		tmp = t_0
	else:
		tmp = d1 * (d4 + d2)
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d1))
	tmp = 0.0
	if (d4 <= 1.25e-232)
		tmp = t_0;
	elseif (d4 <= 2.4e-182)
		tmp = Float64(d1 * Float64(-d3));
	elseif (d4 <= 4e+80)
		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);
	tmp = 0.0;
	if (d4 <= 1.25e-232)
		tmp = t_0;
	elseif (d4 <= 2.4e-182)
		tmp = d1 * -d3;
	elseif (d4 <= 4e+80)
		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]}, If[LessEqual[d4, 1.25e-232], t$95$0, If[LessEqual[d4, 2.4e-182], N[(d1 * (-d3)), $MachinePrecision], If[LessEqual[d4, 4e+80], t$95$0, N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d4 \leq 4 \cdot 10^{+80}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 1.25e-232 or 2.3999999999999998e-182 < d4 < 4e80

    1. Initial program 90.6%

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + \left(d1 \cdot d2 - d1 \cdot d3\right) \]
      4. distribute-lft-out--93.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 76.2%

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

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

    if 1.25e-232 < d4 < 2.3999999999999998e-182

    1. Initial program 75.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+75.0%

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + \left(d1 \cdot d2 - d1 \cdot d3\right) \]
      4. distribute-lft-out--75.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 39.9%

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

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

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

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

    if 4e80 < d4

    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--87.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 1.25 \cdot 10^{-232}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 2.4 \cdot 10^{-182}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d4 \leq 4 \cdot 10^{+80}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]

Alternative 4: 63.6% accurate, 1.3× speedup?

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

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

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

\mathbf{elif}\;d4 \leq 3.75 \cdot 10^{+81}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 5.5000000000000001e-70 or 2.1e17 < d4 < 3.74999999999999986e81

    1. Initial program 92.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+92.0%

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

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

        \[\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 0 83.9%

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

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

    if 5.5000000000000001e-70 < d4 < 2.1e17

    1. Initial program 61.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+61.5%

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + \left(d1 \cdot d2 - d1 \cdot d3\right) \]
      4. distribute-lft-out--69.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 78.6%

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

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

    if 3.74999999999999986e81 < d4

    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--87.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 5.5 \cdot 10^{-70}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 2.1 \cdot 10^{+17}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 3.75 \cdot 10^{+81}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]

Alternative 5: 90.7% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -1.25 \cdot 10^{+48} \lor \neg \left(d1 \leq 5 \cdot 10^{-18}\right):\\
\;\;\;\;d1 \cdot \left(\left(d4 + d2\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 d1 < -1.24999999999999993e48 or 5.00000000000000036e-18 < d1

    1. Initial program 70.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+70.8%

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

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

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

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

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

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

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

    if -1.24999999999999993e48 < d1 < 5.00000000000000036e-18

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

Alternative 6: 87.7% accurate, 1.3× speedup?

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

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

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

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


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

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

    if -1.89999999999999989e102 < d3 < 1.8499999999999999e176

    1. Initial program 91.1%

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + \left(d1 \cdot d2 - d1 \cdot d3\right) \]
      4. distribute-lft-out--93.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 91.6%

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

    if 1.8499999999999999e176 < d3

    1. Initial program 74.1%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d2 around 0 70.8%

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

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

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

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d3\right)} - {d1}^{2} \]
      2. distribute-rgt-neg-out63.3%

        \[\leadsto \color{blue}{d1 \cdot \left(-d3\right)} - {d1}^{2} \]
      3. unpow263.3%

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

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

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

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

Alternative 7: 63.9% accurate, 1.5× speedup?

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

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

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

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


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

    1. Initial program 78.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+78.7%

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + \left(d1 \cdot d2 - d1 \cdot d3\right) \]
      4. distribute-lft-out--81.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 88.7%

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

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

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

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

    if -3.6e18 < d2 < -1.86e-180

    1. Initial program 97.5%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Taylor expanded in d2 around 0 95.2%

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

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

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

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d3\right)} - {d1}^{2} \]
      2. distribute-rgt-neg-out71.1%

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

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

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

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

    if -1.86e-180 < d2

    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--92.2%

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

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

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

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

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

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

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

Alternative 8: 68.3% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -6.2 \cdot 10^{+151} \lor \neg \left(d3 \leq 2.3 \cdot 10^{+121}\right):\\
\;\;\;\;d1 \cdot \left(-d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -6.2000000000000004e151 or 2.2999999999999999e121 < d3

    1. Initial program 79.7%

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + \left(d1 \cdot d2 - d1 \cdot d3\right) \]
      4. distribute-lft-out--85.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 71.9%

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

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

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

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

    if -6.2000000000000004e151 < d3 < 2.2999999999999999e121

    1. Initial program 92.5%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 84.4% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 78.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+78.7%

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

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

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

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

    if -4.7e18 < d2

    1. Initial program 92.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+92.3%

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 64.4% accurate, 2.1× speedup?

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

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

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


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

    1. Initial program 78.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+78.7%

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + \left(d1 \cdot d2 - d1 \cdot d3\right) \]
      4. distribute-lft-out--81.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 88.7%

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

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

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

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

    if -4e18 < d2

    1. Initial program 92.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+92.3%

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + \left(d1 \cdot d2 - d1 \cdot d3\right) \]
      4. distribute-lft-out--94.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 83.2%

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

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

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

Alternative 11: 38.3% accurate, 3.0× speedup?

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

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

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


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

    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. +-commutative89.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.8%

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

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

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

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

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

    if 3.0500000000000001e66 < d4

    1. Initial program 86.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+86.8%

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} + \left(d1 \cdot d2 - d1 \cdot d3\right) \]
      4. distribute-lft-out--88.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 d4 around inf 59.1%

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

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

Alternative 12: 29.9% 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 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--90.2%

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

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

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

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

    \[\leadsto \color{blue}{d1 \cdot d2} \]
  5. Final simplification34.4%

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