FastMath dist4

Percentage Accurate: 87.0% → 100.0%
Time: 6.1s
Alternatives: 12
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 87.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(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 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.3%

      \[\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. Final simplification100.0%

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

Alternative 2: 67.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d4 + d2\right)\\ t_1 := d1 \cdot \left(-d3\right)\\ t_2 := d1 \cdot \left(d2 - d1\right)\\ \mathbf{if}\;d3 \leq -2.2 \cdot 10^{+156}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d3 \leq -7.6 \cdot 10^{-43}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;d3 \leq -5.8 \cdot 10^{-300}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq 1.8 \cdot 10^{-215}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;d3 \leq 2.8 \cdot 10^{+135}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (+ d4 d2))) (t_1 (* d1 (- d3))) (t_2 (* d1 (- d2 d1))))
   (if (<= d3 -2.2e+156)
     t_1
     (if (<= d3 -7.6e-43)
       t_2
       (if (<= d3 -5.8e-300)
         t_0
         (if (<= d3 1.8e-215) t_2 (if (<= d3 2.8e+135) t_0 t_1)))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d4 + d2);
	double t_1 = d1 * -d3;
	double t_2 = d1 * (d2 - d1);
	double tmp;
	if (d3 <= -2.2e+156) {
		tmp = t_1;
	} else if (d3 <= -7.6e-43) {
		tmp = t_2;
	} else if (d3 <= -5.8e-300) {
		tmp = t_0;
	} else if (d3 <= 1.8e-215) {
		tmp = t_2;
	} else if (d3 <= 2.8e+135) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = d1 * (d4 + d2)
    t_1 = d1 * -d3
    t_2 = d1 * (d2 - d1)
    if (d3 <= (-2.2d+156)) then
        tmp = t_1
    else if (d3 <= (-7.6d-43)) then
        tmp = t_2
    else if (d3 <= (-5.8d-300)) then
        tmp = t_0
    else if (d3 <= 1.8d-215) then
        tmp = t_2
    else if (d3 <= 2.8d+135) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d4 + d2);
	double t_1 = d1 * -d3;
	double t_2 = d1 * (d2 - d1);
	double tmp;
	if (d3 <= -2.2e+156) {
		tmp = t_1;
	} else if (d3 <= -7.6e-43) {
		tmp = t_2;
	} else if (d3 <= -5.8e-300) {
		tmp = t_0;
	} else if (d3 <= 1.8e-215) {
		tmp = t_2;
	} else if (d3 <= 2.8e+135) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d4 + d2)
	t_1 = d1 * -d3
	t_2 = d1 * (d2 - d1)
	tmp = 0
	if d3 <= -2.2e+156:
		tmp = t_1
	elif d3 <= -7.6e-43:
		tmp = t_2
	elif d3 <= -5.8e-300:
		tmp = t_0
	elif d3 <= 1.8e-215:
		tmp = t_2
	elif d3 <= 2.8e+135:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d4 + d2))
	t_1 = Float64(d1 * Float64(-d3))
	t_2 = Float64(d1 * Float64(d2 - d1))
	tmp = 0.0
	if (d3 <= -2.2e+156)
		tmp = t_1;
	elseif (d3 <= -7.6e-43)
		tmp = t_2;
	elseif (d3 <= -5.8e-300)
		tmp = t_0;
	elseif (d3 <= 1.8e-215)
		tmp = t_2;
	elseif (d3 <= 2.8e+135)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d4 + d2);
	t_1 = d1 * -d3;
	t_2 = d1 * (d2 - d1);
	tmp = 0.0;
	if (d3 <= -2.2e+156)
		tmp = t_1;
	elseif (d3 <= -7.6e-43)
		tmp = t_2;
	elseif (d3 <= -5.8e-300)
		tmp = t_0;
	elseif (d3 <= 1.8e-215)
		tmp = t_2;
	elseif (d3 <= 2.8e+135)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * (-d3)), $MachinePrecision]}, Block[{t$95$2 = N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -2.2e+156], t$95$1, If[LessEqual[d3, -7.6e-43], t$95$2, If[LessEqual[d3, -5.8e-300], t$95$0, If[LessEqual[d3, 1.8e-215], t$95$2, If[LessEqual[d3, 2.8e+135], t$95$0, t$95$1]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := d1 \cdot \left(d4 + d2\right)\\
t_1 := d1 \cdot \left(-d3\right)\\
t_2 := d1 \cdot \left(d2 - d1\right)\\
\mathbf{if}\;d3 \leq -2.2 \cdot 10^{+156}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d3 \leq -7.6 \cdot 10^{-43}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;d3 \leq -5.8 \cdot 10^{-300}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d3 \leq 1.8 \cdot 10^{-215}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;d3 \leq 2.8 \cdot 10^{+135}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -2.20000000000000004e156 or 2.80000000000000002e135 < d3

    1. Initial program 83.1%

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

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

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

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

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

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

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

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

    if -2.20000000000000004e156 < d3 < -7.59999999999999939e-43 or -5.79999999999999985e-300 < d3 < 1.7999999999999999e-215

    1. Initial program 92.9%

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

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

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

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

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

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

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

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

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

    if -7.59999999999999939e-43 < d3 < -5.79999999999999985e-300 or 1.7999999999999999e-215 < d3 < 2.80000000000000002e135

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -2.2 \cdot 10^{+156}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d3 \leq -7.6 \cdot 10^{-43}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq -5.8 \cdot 10^{-300}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d3 \leq 1.8 \cdot 10^{-215}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 2.8 \cdot 10^{+135}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 70.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ t_1 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d3 \leq -2.4 \cdot 10^{-41}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq -2.1 \cdot 10^{-302}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d3 \leq 9 \cdot 10^{-216}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 2.2 \cdot 10^{+26}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d3 \leq 6.6 \cdot 10^{+106}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d2 d3))) (t_1 (* d1 (+ d4 d2))))
   (if (<= d3 -2.4e-41)
     t_0
     (if (<= d3 -2.1e-302)
       t_1
       (if (<= d3 9e-216)
         (* d1 (- d2 d1))
         (if (<= d3 2.2e+26)
           t_1
           (if (<= d3 6.6e+106) (* d1 (- d4 d1)) t_0)))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double t_1 = d1 * (d4 + d2);
	double tmp;
	if (d3 <= -2.4e-41) {
		tmp = t_0;
	} else if (d3 <= -2.1e-302) {
		tmp = t_1;
	} else if (d3 <= 9e-216) {
		tmp = d1 * (d2 - d1);
	} else if (d3 <= 2.2e+26) {
		tmp = t_1;
	} else if (d3 <= 6.6e+106) {
		tmp = d1 * (d4 - d1);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = d1 * (d2 - d3)
    t_1 = d1 * (d4 + d2)
    if (d3 <= (-2.4d-41)) then
        tmp = t_0
    else if (d3 <= (-2.1d-302)) then
        tmp = t_1
    else if (d3 <= 9d-216) then
        tmp = d1 * (d2 - d1)
    else if (d3 <= 2.2d+26) then
        tmp = t_1
    else if (d3 <= 6.6d+106) then
        tmp = d1 * (d4 - d1)
    else
        tmp = t_0
    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 t_1 = d1 * (d4 + d2);
	double tmp;
	if (d3 <= -2.4e-41) {
		tmp = t_0;
	} else if (d3 <= -2.1e-302) {
		tmp = t_1;
	} else if (d3 <= 9e-216) {
		tmp = d1 * (d2 - d1);
	} else if (d3 <= 2.2e+26) {
		tmp = t_1;
	} else if (d3 <= 6.6e+106) {
		tmp = d1 * (d4 - d1);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d3)
	t_1 = d1 * (d4 + d2)
	tmp = 0
	if d3 <= -2.4e-41:
		tmp = t_0
	elif d3 <= -2.1e-302:
		tmp = t_1
	elif d3 <= 9e-216:
		tmp = d1 * (d2 - d1)
	elif d3 <= 2.2e+26:
		tmp = t_1
	elif d3 <= 6.6e+106:
		tmp = d1 * (d4 - d1)
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d3))
	t_1 = Float64(d1 * Float64(d4 + d2))
	tmp = 0.0
	if (d3 <= -2.4e-41)
		tmp = t_0;
	elseif (d3 <= -2.1e-302)
		tmp = t_1;
	elseif (d3 <= 9e-216)
		tmp = Float64(d1 * Float64(d2 - d1));
	elseif (d3 <= 2.2e+26)
		tmp = t_1;
	elseif (d3 <= 6.6e+106)
		tmp = Float64(d1 * Float64(d4 - d1));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d2 - d3);
	t_1 = d1 * (d4 + d2);
	tmp = 0.0;
	if (d3 <= -2.4e-41)
		tmp = t_0;
	elseif (d3 <= -2.1e-302)
		tmp = t_1;
	elseif (d3 <= 9e-216)
		tmp = d1 * (d2 - d1);
	elseif (d3 <= 2.2e+26)
		tmp = t_1;
	elseif (d3 <= 6.6e+106)
		tmp = d1 * (d4 - d1);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -2.4e-41], t$95$0, If[LessEqual[d3, -2.1e-302], t$95$1, If[LessEqual[d3, 9e-216], N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 2.2e+26], t$95$1, If[LessEqual[d3, 6.6e+106], N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d3 \leq -2.1 \cdot 10^{-302}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;d3 \leq 2.2 \cdot 10^{+26}:\\
\;\;\;\;t\_1\\

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d3 < -2.40000000000000022e-41 or 6.60000000000000015e106 < d3

    1. Initial program 85.2%

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

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

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

        \[\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 d4 around 0 86.5%

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

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

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

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

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

    if -2.40000000000000022e-41 < d3 < -2.10000000000000013e-302 or 8.9999999999999997e-216 < d3 < 2.20000000000000007e26

    1. Initial program 90.2%

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

        \[\leadsto \color{blue}{\left(d4 \cdot d1 + \left(d1 \cdot d2 - d1 \cdot d3\right)\right)} - d1 \cdot d1 \]
      2. *-commutative90.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-out91.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 0 98.5%

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

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

    if -2.10000000000000013e-302 < d3 < 8.9999999999999997e-216

    1. Initial program 87.0%

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

        \[\leadsto \color{blue}{\left(d4 \cdot d1 + \left(d1 \cdot d2 - d1 \cdot d3\right)\right)} - d1 \cdot d1 \]
      2. *-commutative87.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.0%

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

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

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

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

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

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

    if 2.20000000000000007e26 < d3 < 6.60000000000000015e106

    1. Initial program 86.9%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -2.4 \cdot 10^{-41}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq -2.1 \cdot 10^{-302}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d3 \leq 9 \cdot 10^{-216}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 2.2 \cdot 10^{+26}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d3 \leq 6.6 \cdot 10^{+106}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 62.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d4 - d1\right)\\ t_1 := d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{if}\;d2 \leq -2.15 \cdot 10^{+49}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -6 \cdot 10^{-159}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d2 \leq -1.95 \cdot 10^{-243}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d2 \leq 2.95 \cdot 10^{-254}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d2 \leq 5.5 \cdot 10^{-101}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d4 d1))) (t_1 (* d1 (- (- d1) d3))))
   (if (<= d2 -2.15e+49)
     (* d1 (- d2 d3))
     (if (<= d2 -6e-159)
       t_1
       (if (<= d2 -1.95e-243)
         t_0
         (if (<= d2 2.95e-254)
           t_1
           (if (<= d2 5.5e-101) (* d1 (- d4 d3)) t_0)))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d4 - d1);
	double t_1 = d1 * (-d1 - d3);
	double tmp;
	if (d2 <= -2.15e+49) {
		tmp = d1 * (d2 - d3);
	} else if (d2 <= -6e-159) {
		tmp = t_1;
	} else if (d2 <= -1.95e-243) {
		tmp = t_0;
	} else if (d2 <= 2.95e-254) {
		tmp = t_1;
	} else if (d2 <= 5.5e-101) {
		tmp = d1 * (d4 - d3);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = d1 * (d4 - d1)
    t_1 = d1 * (-d1 - d3)
    if (d2 <= (-2.15d+49)) then
        tmp = d1 * (d2 - d3)
    else if (d2 <= (-6d-159)) then
        tmp = t_1
    else if (d2 <= (-1.95d-243)) then
        tmp = t_0
    else if (d2 <= 2.95d-254) then
        tmp = t_1
    else if (d2 <= 5.5d-101) then
        tmp = d1 * (d4 - d3)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d4 - d1);
	double t_1 = d1 * (-d1 - d3);
	double tmp;
	if (d2 <= -2.15e+49) {
		tmp = d1 * (d2 - d3);
	} else if (d2 <= -6e-159) {
		tmp = t_1;
	} else if (d2 <= -1.95e-243) {
		tmp = t_0;
	} else if (d2 <= 2.95e-254) {
		tmp = t_1;
	} else if (d2 <= 5.5e-101) {
		tmp = d1 * (d4 - d3);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d4 - d1)
	t_1 = d1 * (-d1 - d3)
	tmp = 0
	if d2 <= -2.15e+49:
		tmp = d1 * (d2 - d3)
	elif d2 <= -6e-159:
		tmp = t_1
	elif d2 <= -1.95e-243:
		tmp = t_0
	elif d2 <= 2.95e-254:
		tmp = t_1
	elif d2 <= 5.5e-101:
		tmp = d1 * (d4 - d3)
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d4 - d1))
	t_1 = Float64(d1 * Float64(Float64(-d1) - d3))
	tmp = 0.0
	if (d2 <= -2.15e+49)
		tmp = Float64(d1 * Float64(d2 - d3));
	elseif (d2 <= -6e-159)
		tmp = t_1;
	elseif (d2 <= -1.95e-243)
		tmp = t_0;
	elseif (d2 <= 2.95e-254)
		tmp = t_1;
	elseif (d2 <= 5.5e-101)
		tmp = Float64(d1 * Float64(d4 - d3));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d4 - d1);
	t_1 = d1 * (-d1 - d3);
	tmp = 0.0;
	if (d2 <= -2.15e+49)
		tmp = d1 * (d2 - d3);
	elseif (d2 <= -6e-159)
		tmp = t_1;
	elseif (d2 <= -1.95e-243)
		tmp = t_0;
	elseif (d2 <= 2.95e-254)
		tmp = t_1;
	elseif (d2 <= 5.5e-101)
		tmp = d1 * (d4 - d3);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[((-d1) - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d2, -2.15e+49], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d2, -6e-159], t$95$1, If[LessEqual[d2, -1.95e-243], t$95$0, If[LessEqual[d2, 2.95e-254], t$95$1, If[LessEqual[d2, 5.5e-101], N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d2 \leq -6 \cdot 10^{-159}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d2 \leq -1.95 \cdot 10^{-243}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d2 \leq 2.95 \cdot 10^{-254}:\\
\;\;\;\;t\_1\\

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 86.9%

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

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

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

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

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

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

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

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

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

    if -2.15e49 < d2 < -6.00000000000000018e-159 or -1.95000000000000008e-243 < d2 < 2.9499999999999999e-254

    1. Initial program 91.3%

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.00000000000000018e-159 < d2 < -1.95000000000000008e-243 or 5.49999999999999973e-101 < d2

    1. Initial program 82.6%

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

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

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

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

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

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

    if 2.9499999999999999e-254 < d2 < 5.49999999999999973e-101

    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. +-commutative94.1%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -2.15 \cdot 10^{+49}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -6 \cdot 10^{-159}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{elif}\;d2 \leq -1.95 \cdot 10^{-243}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d2 \leq 2.95 \cdot 10^{-254}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{elif}\;d2 \leq 5.5 \cdot 10^{-101}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 66.6% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -4.25 \cdot 10^{+155} \lor \neg \left(d3 \leq -3.2 \cdot 10^{+86}\right) \land \left(d3 \leq -1.2 \cdot 10^{+35} \lor \neg \left(d3 \leq 9 \cdot 10^{+135}\right)\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 < -4.2500000000000001e155 or -3.2e86 < d3 < -1.20000000000000007e35 or 9.00000000000000014e135 < d3

    1. Initial program 84.9%

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

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

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

        \[\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 78.8%

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

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

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

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

    if -4.2500000000000001e155 < d3 < -3.2e86 or -1.20000000000000007e35 < d3 < 9.00000000000000014e135

    1. Initial program 88.5%

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

        \[\leadsto \color{blue}{\left(d4 \cdot d1 + \left(d1 \cdot d2 - d1 \cdot d3\right)\right)} - d1 \cdot d1 \]
      2. *-commutative88.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.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 0 93.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -4.25 \cdot 10^{+155} \lor \neg \left(d3 \leq -3.2 \cdot 10^{+86}\right) \land \left(d3 \leq -1.2 \cdot 10^{+35} \lor \neg \left(d3 \leq 9 \cdot 10^{+135}\right)\right):\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 70.2% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d3 \leq -8.5 \cdot 10^{-302}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;d3 \leq 4.7 \cdot 10^{+126}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -2.40000000000000022e-41 or 4.6999999999999999e126 < d3

    1. Initial program 88.0%

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

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

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

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

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

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

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

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

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

    if -2.40000000000000022e-41 < d3 < -8.5000000000000005e-302 or 1.24999999999999989e-215 < d3 < 4.6999999999999999e126

    1. Initial program 87.2%

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

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

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

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

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

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

    if -8.5000000000000005e-302 < d3 < 1.24999999999999989e-215

    1. Initial program 87.0%

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

        \[\leadsto \color{blue}{\left(d4 \cdot d1 + \left(d1 \cdot d2 - d1 \cdot d3\right)\right)} - d1 \cdot d1 \]
      2. *-commutative87.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.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -2.4 \cdot 10^{-41}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq -8.5 \cdot 10^{-302}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d3 \leq 1.25 \cdot 10^{-215}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 4.7 \cdot 10^{+126}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 39.7% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d2 \leq -6.8 \cdot 10^{-199} \lor \neg \left(d2 \leq -1.15 \cdot 10^{-248}\right) \land d2 \leq 8.8 \cdot 10^{-157}:\\
\;\;\;\;d1 \cdot \left(-d3\right)\\

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


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

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

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

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

    if -1.7000000000000001e64 < d2 < -6.80000000000000011e-199 or -1.15e-248 < d2 < 8.80000000000000041e-157

    1. Initial program 91.1%

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

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

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

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

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

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

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

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

    if -6.80000000000000011e-199 < d2 < -1.15e-248 or 8.80000000000000041e-157 < d2

    1. Initial program 83.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.7 \cdot 10^{+64}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -6.8 \cdot 10^{-199} \lor \neg \left(d2 \leq -1.15 \cdot 10^{-248}\right) \land d2 \leq 8.8 \cdot 10^{-157}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 86.3% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -1.95 \cdot 10^{-13} \lor \neg \left(d3 \leq 3.8 \cdot 10^{+126}\right):\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -1.95000000000000002e-13 or 3.80000000000000017e126 < d3

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

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

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

        \[\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 d4 around 0 85.6%

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

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

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

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

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

    if -1.95000000000000002e-13 < d3 < 3.80000000000000017e126

    1. Initial program 87.0%

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

        \[\leadsto \color{blue}{\left(d4 \cdot d1 + \left(d1 \cdot d2 - d1 \cdot d3\right)\right)} - d1 \cdot d1 \]
      2. *-commutative87.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.0%

        \[\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 d3 around 0 95.9%

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

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

Alternative 9: 90.6% accurate, 0.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -8.3999999999999996e-32 or 2.44999999999999983e100 < d3

    1. Initial program 84.4%

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

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

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

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

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

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

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

    if -8.3999999999999996e-32 < d3 < 2.44999999999999983e100

    1. Initial program 89.8%

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

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

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

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

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

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

Alternative 10: 83.1% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.4 \cdot 10^{-49}:\\ \;\;\;\;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.4e-49) (* d1 (- (- d2 d3) d1)) (* d1 (- (- d4 d1) d3))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -1.4e-49) {
		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.4d-49)) 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.4e-49) {
		tmp = d1 * ((d2 - d3) - d1);
	} else {
		tmp = d1 * ((d4 - d1) - d3);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -1.4e-49:
		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.4e-49)
		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.4e-49)
		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.4e-49], 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.4 \cdot 10^{-49}:\\
\;\;\;\;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.39999999999999999e-49

    1. Initial program 86.6%

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

        \[\leadsto \color{blue}{\left(d4 \cdot d1 + \left(d1 \cdot d2 - d1 \cdot d3\right)\right)} - d1 \cdot d1 \]
      2. *-commutative86.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.6%

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

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

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

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

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

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

    if -1.39999999999999999e-49 < d2

    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-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 0 84.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.4 \cdot 10^{-49}:\\ \;\;\;\;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: 37.7% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 86.6%

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

        \[\leadsto \color{blue}{\left(d4 \cdot d1 + \left(d1 \cdot d2 - d1 \cdot d3\right)\right)} - d1 \cdot d1 \]
      2. *-commutative86.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.6%

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

        \[\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 49.5%

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

    if -1.29999999999999997e-49 < d2

    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-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 d4 around inf 35.0%

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

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

Alternative 12: 30.9% accurate, 5.0× speedup?

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

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

      \[\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 inf 31.7%

    \[\leadsto \color{blue}{d1 \cdot d2} \]
  6. Final simplification31.7%

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

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

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