FastMath dist4

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

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 88.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.7× speedup?

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

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

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

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

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

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

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

    \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + \left(d4 - d1\right)\right) \]
  6. Add Preprocessing

Alternative 2: 38.2% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;d4 \leq 7800000000000:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\

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

\mathbf{elif}\;d4 \leq 4.6 \cdot 10^{+163}:\\
\;\;\;\;d1 \cdot d2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d4 < 2.1e-185 or 1.15000000000000002e44 < d4 < 4.60000000000000003e163

    1. Initial program 86.7%

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

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

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

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

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

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

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

    if 2.1e-185 < d4 < 7.8e12

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 \cdot \left(1 + \color{blue}{\left(-\frac{d1 + d3}{d2}\right)}\right)\right) \]
      2. unsub-neg86.4%

        \[\leadsto d1 \cdot \left(d2 \cdot \color{blue}{\left(1 - \frac{d1 + d3}{d2}\right)}\right) \]
    10. Simplified86.4%

      \[\leadsto d1 \cdot \color{blue}{\left(d2 \cdot \left(1 - \frac{d1 + d3}{d2}\right)\right)} \]
    11. Taylor expanded in d1 around inf 50.9%

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

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

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

    if 7.8e12 < d4 < 1.15000000000000002e44

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

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

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

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

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

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

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

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

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

    if 4.60000000000000003e163 < d4

    1. Initial program 86.2%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 2.1 \cdot 10^{-185}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 7800000000000:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 1.15 \cdot 10^{+44}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d4 \leq 4.6 \cdot 10^{+163}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 64.0% accurate, 0.7× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d4 < 2.3500000000000001e-267

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \]
    7. Simplified76.0%

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

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

    if 2.3500000000000001e-267 < d4 < 2.3500000000000001e-132

    1. Initial program 94.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+94.1%

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

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

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

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

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

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

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

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

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

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

    if 2.3500000000000001e-132 < d4 < 2.5999999999999999e44

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.5999999999999999e44 < d4

    1. Initial program 86.8%

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

      \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right)} - d1 \cdot d1 \]
    4. Step-by-step derivation
      1. distribute-lft-out76.2%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 2.35 \cdot 10^{-267}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 2.35 \cdot 10^{-132}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 2.6 \cdot 10^{+44}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 62.0% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_0 := d1 \cdot \left(d2 - d1\right)\\
\mathbf{if}\;d4 \leq 7800000000000:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d4 \leq 5.2 \cdot 10^{+43}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 7.8e12 or 1.22e39 < d4 < 5.20000000000000042e43

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

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

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

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

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

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

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

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

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

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

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

    if 7.8e12 < d4 < 1.22e39

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

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

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

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

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

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

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

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

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

    if 5.20000000000000042e43 < d4

    1. Initial program 85.2%

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

      \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right)} - d1 \cdot d1 \]
    4. Step-by-step derivation
      1. distribute-lft-out74.8%

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(d4 + d2\right)} \]
    10. Simplified74.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 7800000000000:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 1.22 \cdot 10^{+39}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d4 \leq 5.2 \cdot 10^{+43}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 63.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d4 \leq 2.35 \cdot 10^{-269}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d4 \leq 7800000000000:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 3.1 \cdot 10^{+44}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d2 d3))))
   (if (<= d4 2.35e-269)
     t_0
     (if (<= d4 7800000000000.0)
       (* d1 (- d2 d1))
       (if (<= d4 3.1e+44) t_0 (* d1 (+ d2 d4)))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double tmp;
	if (d4 <= 2.35e-269) {
		tmp = t_0;
	} else if (d4 <= 7800000000000.0) {
		tmp = d1 * (d2 - d1);
	} else if (d4 <= 3.1e+44) {
		tmp = t_0;
	} else {
		tmp = d1 * (d2 + d4);
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: tmp
    t_0 = d1 * (d2 - d3)
    if (d4 <= 2.35d-269) then
        tmp = t_0
    else if (d4 <= 7800000000000.0d0) then
        tmp = d1 * (d2 - d1)
    else if (d4 <= 3.1d+44) then
        tmp = t_0
    else
        tmp = d1 * (d2 + d4)
    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 <= 2.35e-269) {
		tmp = t_0;
	} else if (d4 <= 7800000000000.0) {
		tmp = d1 * (d2 - d1);
	} else if (d4 <= 3.1e+44) {
		tmp = t_0;
	} else {
		tmp = d1 * (d2 + d4);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d3)
	tmp = 0
	if d4 <= 2.35e-269:
		tmp = t_0
	elif d4 <= 7800000000000.0:
		tmp = d1 * (d2 - d1)
	elif d4 <= 3.1e+44:
		tmp = t_0
	else:
		tmp = d1 * (d2 + d4)
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d3))
	tmp = 0.0
	if (d4 <= 2.35e-269)
		tmp = t_0;
	elseif (d4 <= 7800000000000.0)
		tmp = Float64(d1 * Float64(d2 - d1));
	elseif (d4 <= 3.1e+44)
		tmp = t_0;
	else
		tmp = Float64(d1 * Float64(d2 + d4));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d2 - d3);
	tmp = 0.0;
	if (d4 <= 2.35e-269)
		tmp = t_0;
	elseif (d4 <= 7800000000000.0)
		tmp = d1 * (d2 - d1);
	elseif (d4 <= 3.1e+44)
		tmp = t_0;
	else
		tmp = d1 * (d2 + d4);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d4, 2.35e-269], t$95$0, If[LessEqual[d4, 7800000000000.0], N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d4, 3.1e+44], t$95$0, N[(d1 * N[(d2 + d4), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d4 \leq 7800000000000:\\
\;\;\;\;d1 \cdot \left(d2 - d1\right)\\

\mathbf{elif}\;d4 \leq 3.1 \cdot 10^{+44}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 2.3499999999999999e-269 or 7.8e12 < d4 < 3.09999999999999996e44

    1. Initial program 83.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+83.4%

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \]
    7. Simplified78.0%

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

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

    if 2.3499999999999999e-269 < d4 < 7.8e12

    1. Initial program 92.2%

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

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

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

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

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

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

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

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

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

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

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

    if 3.09999999999999996e44 < d4

    1. Initial program 86.8%

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

      \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right)} - d1 \cdot d1 \]
    4. Step-by-step derivation
      1. distribute-lft-out76.2%

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(d4 + d2\right)} \]
    10. Simplified75.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 2.35 \cdot 10^{-269}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 7800000000000:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 3.1 \cdot 10^{+44}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 38.1% accurate, 0.8× speedup?

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

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

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

\mathbf{elif}\;d4 \leq 3 \cdot 10^{+164}:\\
\;\;\;\;d1 \cdot d2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 2.4000000000000001e-185 or 3.9000000000000001e43 < d4 < 3.00000000000000001e164

    1. Initial program 86.2%

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

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

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

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

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

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

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

    if 2.4000000000000001e-185 < d4 < 3.9000000000000001e43

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 \cdot \left(1 + \color{blue}{\left(-\frac{d1 + d3}{d2}\right)}\right)\right) \]
      2. unsub-neg87.4%

        \[\leadsto d1 \cdot \left(d2 \cdot \color{blue}{\left(1 - \frac{d1 + d3}{d2}\right)}\right) \]
    10. Simplified87.4%

      \[\leadsto d1 \cdot \color{blue}{\left(d2 \cdot \left(1 - \frac{d1 + d3}{d2}\right)\right)} \]
    11. Taylor expanded in d1 around inf 48.4%

      \[\leadsto d1 \cdot \color{blue}{\left(-1 \cdot d1\right)} \]
    12. Step-by-step derivation
      1. mul-1-neg48.4%

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

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

    if 3.00000000000000001e164 < d4

    1. Initial program 86.2%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 2.4 \cdot 10^{-185}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 3.9 \cdot 10^{+43}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 3 \cdot 10^{+164}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 88.5% accurate, 0.9× speedup?

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

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

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

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


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

    1. Initial program 85.3%

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \]
    7. Simplified77.3%

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

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

    if -8.5000000000000004e109 < d3 < 8.00000000000000039e149

    1. Initial program 88.9%

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

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

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

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

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

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

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

    if 8.00000000000000039e149 < d3

    1. Initial program 74.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+74.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-d1\right)} \cdot \left(d1 + d3\right) \]
    10. Simplified83.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -8.5 \cdot 10^{+109}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq 8 \cdot 10^{+149}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 66.5% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -4.8 \cdot 10^{+103} \lor \neg \left(d1 \leq 7.3 \cdot 10^{+136}\right):\\
\;\;\;\;d1 \cdot \left(-d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -4.7999999999999997e103 or 7.3000000000000002e136 < d1

    1. Initial program 53.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+53.4%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 \cdot \left(1 + \color{blue}{\left(-\frac{d1 + d3}{d2}\right)}\right)\right) \]
      2. unsub-neg95.9%

        \[\leadsto d1 \cdot \left(d2 \cdot \color{blue}{\left(1 - \frac{d1 + d3}{d2}\right)}\right) \]
    10. Simplified95.9%

      \[\leadsto d1 \cdot \color{blue}{\left(d2 \cdot \left(1 - \frac{d1 + d3}{d2}\right)\right)} \]
    11. Taylor expanded in d1 around inf 77.2%

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

        \[\leadsto d1 \cdot \color{blue}{\left(-d1\right)} \]
    13. Simplified77.2%

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

    if -4.7999999999999997e103 < d1 < 7.3000000000000002e136

    1. Initial program 99.4%

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

      \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right)} - d1 \cdot d1 \]
    4. Step-by-step derivation
      1. distribute-lft-out76.5%

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

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

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

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

        \[\leadsto \color{blue}{\left(d2 + \left(d4 - d1\right)\right)} \cdot d1 \]
    7. Applied egg-rr76.5%

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(d4 + d2\right)} \]
    10. Simplified67.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -4.8 \cdot 10^{+103} \lor \neg \left(d1 \leq 7.3 \cdot 10^{+136}\right):\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 84.2% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 86.2%

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

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

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

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

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

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

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

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

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

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

    if 2.30000000000000004e44 < 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. distribute-lft-out--86.8%

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

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

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

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

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

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

Alternative 10: 82.2% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 81.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+81.6%

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

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

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

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

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

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

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

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

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

    if -1.8999999999999999e-69 < 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. distribute-lft-out--88.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.9 \cdot 10^{-69}:\\ \;\;\;\;d1 \cdot \left(\left(d2 - d3\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d4 - d1\right) - d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 36.6% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 81.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+81.6%

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

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

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

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

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

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

    if -1.8999999999999999e-69 < 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. distribute-lft-out--88.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.9 \cdot 10^{-69}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 31.1% 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 86.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+86.3%

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

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

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

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

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

    \[\leadsto \color{blue}{d1 \cdot d2} \]
  6. Final simplification33.9%

    \[\leadsto d1 \cdot d2 \]
  7. Add Preprocessing

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 2024071 
(FPCore (d1 d2 d3 d4)
  :name "FastMath dist4"
  :precision binary64

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

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