FastMath dist4

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

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

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

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

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

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

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

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

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

Alternative 2: 62.8% accurate, 0.7× speedup?

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

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

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

\mathbf{elif}\;d4 \leq 32000000:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < -1.01999999999999994e-135 or 7.5e-158 < d4 < 3.2e7

    1. Initial program 87.6%

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

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

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

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

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

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

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

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

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

    if -1.01999999999999994e-135 < d4 < 7.5e-158

    1. Initial program 87.6%

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.2e7 < d4

    1. Initial program 79.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot d4 + \color{blue}{\left(-d1 \cdot d3\right)} \]
      3. distribute-rgt-neg-in76.8%

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

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

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

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

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

Alternative 3: 88.4% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d1 < -6.5000000000000002e185

    1. Initial program 40.6%

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

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

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

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

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

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

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

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

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

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

    if -6.5000000000000002e185 < d1 < 5.5000000000000004e126

    1. Initial program 98.4%

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

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

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

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

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

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

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

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

    if 5.5000000000000004e126 < d1

    1. Initial program 58.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 67.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -9 \cdot 10^{+83} \lor \neg \left(d3 \leq 1.75 \cdot 10^{+150}\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 < -8.9999999999999999e83 or 1.74999999999999992e150 < d3

    1. Initial program 84.6%

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

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

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

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

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

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

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

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

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

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

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

    if -8.9999999999999999e83 < d3 < 1.74999999999999992e150

    1. Initial program 86.0%

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

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

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

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

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

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

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

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

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

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

Alternative 5: 38.6% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 87.4%

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

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

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

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

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

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

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

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

    if -1.42000000000000004e-260 < d4 < 8.59999999999999971e-12

    1. Initial program 87.9%

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

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

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

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

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

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

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

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

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

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

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

    if 8.59999999999999971e-12 < d4

    1. Initial program 79.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot d4} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 38.8% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 85.4%

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

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

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

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

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

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

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

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

    if -6.4999999999999998e-134 < d4 < 3.2e7

    1. Initial program 89.2%

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

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

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

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

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

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

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

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

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

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

    if 3.2e7 < d4

    1. Initial program 79.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot d4} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 7: 84.7% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -2.6 \cdot 10^{+20}:\\
\;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d3\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 < -2.6e20

    1. Initial program 83.0%

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

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

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

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

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

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

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

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

    if -2.6e20 < d2

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

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

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

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

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

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

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

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

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

Alternative 8: 63.0% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 87.6%

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

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

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

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

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

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

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

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

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

    if 2.8e7 < d4

    1. Initial program 79.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot d4 + \color{blue}{\left(-d1 \cdot d3\right)} \]
      3. distribute-rgt-neg-in76.8%

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

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

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

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

Alternative 9: 63.9% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 87.5%

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

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

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

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

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

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

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

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

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

    if 3.8e105 < d4

    1. Initial program 76.6%

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

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

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

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

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

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

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

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

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

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

Alternative 10: 38.3% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 10000000:\\
\;\;\;\;d1 \cdot d2\\

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


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

    1. Initial program 87.6%

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

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

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

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

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

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

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

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

    if 1e7 < d4

    1. Initial program 79.0%

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

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

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

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

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

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

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

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

Alternative 11: 30.5% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -2.75 \cdot 10^{+202}:\\
\;\;\;\;d1 \cdot d3\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -2.75000000000000006e202

    1. Initial program 37.0%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(-d1\right) \cdot d3} \]
    10. Step-by-step derivation
      1. add-sqr-sqrt16.3%

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

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

        \[\leadsto \sqrt{\color{blue}{d1 \cdot d1}} \cdot d3 \]
      4. sqrt-unprod0.0%

        \[\leadsto \color{blue}{\left(\sqrt{d1} \cdot \sqrt{d1}\right)} \cdot d3 \]
      5. add-sqr-sqrt37.9%

        \[\leadsto \color{blue}{d1} \cdot d3 \]
      6. pow137.9%

        \[\leadsto \color{blue}{{\left(d1 \cdot d3\right)}^{1}} \]
    11. Applied egg-rr37.9%

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

        \[\leadsto \color{blue}{d1 \cdot d3} \]
    13. Simplified37.9%

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

    if -2.75000000000000006e202 < d1

    1. Initial program 91.2%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot d2} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 12: 31.0% 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 85.5%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{d1 \cdot d2} \]
  6. Add Preprocessing

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

  :alt
  (! :herbie-platform default (* d1 (- (+ (- d2 d3) d4) d1)))

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