FastMath dist4

Percentage Accurate: 87.8% → 100.0%
Time: 7.3s
Alternatives: 14
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 86.8% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ t_1 := d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \mathbf{if}\;d3 \leq -1.38 \cdot 10^{+188}:\\ \;\;\;\;-d1 \cdot d3\\ \mathbf{elif}\;d3 \leq 1.3 \cdot 10^{+70}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 6.2 \cdot 10^{+140}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 2.6 \cdot 10^{+193}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 10^{+253}:\\ \;\;\;\;d1 \cdot \left(-\left(d1 + d3\right)\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) d1))))
   (if (<= d3 -1.38e+188)
     (- (* d1 d3))
     (if (<= d3 1.3e+70)
       t_1
       (if (<= d3 6.2e+140)
         t_0
         (if (<= d3 2.6e+193)
           t_1
           (if (<= d3 1e+253) (* d1 (- (+ d1 d3))) t_0)))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double t_1 = d1 * ((d4 + d2) - d1);
	double tmp;
	if (d3 <= -1.38e+188) {
		tmp = -(d1 * d3);
	} else if (d3 <= 1.3e+70) {
		tmp = t_1;
	} else if (d3 <= 6.2e+140) {
		tmp = t_0;
	} else if (d3 <= 2.6e+193) {
		tmp = t_1;
	} else if (d3 <= 1e+253) {
		tmp = d1 * -(d1 + 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 * (d2 - d3)
    t_1 = d1 * ((d4 + d2) - d1)
    if (d3 <= (-1.38d+188)) then
        tmp = -(d1 * d3)
    else if (d3 <= 1.3d+70) then
        tmp = t_1
    else if (d3 <= 6.2d+140) then
        tmp = t_0
    else if (d3 <= 2.6d+193) then
        tmp = t_1
    else if (d3 <= 1d+253) then
        tmp = d1 * -(d1 + 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 * (d2 - d3);
	double t_1 = d1 * ((d4 + d2) - d1);
	double tmp;
	if (d3 <= -1.38e+188) {
		tmp = -(d1 * d3);
	} else if (d3 <= 1.3e+70) {
		tmp = t_1;
	} else if (d3 <= 6.2e+140) {
		tmp = t_0;
	} else if (d3 <= 2.6e+193) {
		tmp = t_1;
	} else if (d3 <= 1e+253) {
		tmp = d1 * -(d1 + d3);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d3)
	t_1 = d1 * ((d4 + d2) - d1)
	tmp = 0
	if d3 <= -1.38e+188:
		tmp = -(d1 * d3)
	elif d3 <= 1.3e+70:
		tmp = t_1
	elif d3 <= 6.2e+140:
		tmp = t_0
	elif d3 <= 2.6e+193:
		tmp = t_1
	elif d3 <= 1e+253:
		tmp = d1 * -(d1 + d3)
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d3))
	t_1 = Float64(d1 * Float64(Float64(d4 + d2) - d1))
	tmp = 0.0
	if (d3 <= -1.38e+188)
		tmp = Float64(-Float64(d1 * d3));
	elseif (d3 <= 1.3e+70)
		tmp = t_1;
	elseif (d3 <= 6.2e+140)
		tmp = t_0;
	elseif (d3 <= 2.6e+193)
		tmp = t_1;
	elseif (d3 <= 1e+253)
		tmp = Float64(d1 * Float64(-Float64(d1 + d3)));
	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) - d1);
	tmp = 0.0;
	if (d3 <= -1.38e+188)
		tmp = -(d1 * d3);
	elseif (d3 <= 1.3e+70)
		tmp = t_1;
	elseif (d3 <= 6.2e+140)
		tmp = t_0;
	elseif (d3 <= 2.6e+193)
		tmp = t_1;
	elseif (d3 <= 1e+253)
		tmp = d1 * -(d1 + d3);
	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[(N[(d4 + d2), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -1.38e+188], (-N[(d1 * d3), $MachinePrecision]), If[LessEqual[d3, 1.3e+70], t$95$1, If[LessEqual[d3, 6.2e+140], t$95$0, If[LessEqual[d3, 2.6e+193], t$95$1, If[LessEqual[d3, 1e+253], N[(d1 * (-N[(d1 + d3), $MachinePrecision])), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d3 \leq 1.3 \cdot 10^{+70}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d3 \leq 6.2 \cdot 10^{+140}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d3 \leq 2.6 \cdot 10^{+193}:\\
\;\;\;\;t_1\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d3 < -1.3799999999999999e188

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

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

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

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

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

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

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

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

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

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

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

    if -1.3799999999999999e188 < d3 < 1.3e70 or 6.2000000000000001e140 < d3 < 2.60000000000000013e193

    1. Initial program 90.3%

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

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

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

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

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

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

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

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

    if 1.3e70 < d3 < 6.2000000000000001e140 or 9.9999999999999994e252 < d3

    1. Initial program 92.5%

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

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

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

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

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

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

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

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

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

    if 2.60000000000000013e193 < d3 < 9.9999999999999994e252

    1. Initial program 69.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -1.38 \cdot 10^{+188}:\\ \;\;\;\;-d1 \cdot d3\\ \mathbf{elif}\;d3 \leq 1.3 \cdot 10^{+70}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \mathbf{elif}\;d3 \leq 6.2 \cdot 10^{+140}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq 2.6 \cdot 10^{+193}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \mathbf{elif}\;d3 \leq 10^{+253}:\\ \;\;\;\;d1 \cdot \left(-\left(d1 + d3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 39.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -d1 \cdot d3\\ \mathbf{if}\;d4 \leq -7.5 \cdot 10^{-258}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 7 \cdot 10^{-300}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 2.2 \cdot 10^{-117}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 4.5 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.6 \cdot 10^{+65} \lor \neg \left(d4 \leq 1.35 \cdot 10^{+75}\right):\\ \;\;\;\;d1 \cdot d4\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d2\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (- (* d1 d3))))
   (if (<= d4 -7.5e-258)
     (* d1 d2)
     (if (<= d4 7e-300)
       t_0
       (if (<= d4 2.2e-117)
         (* d1 d2)
         (if (<= d4 4.5e+29)
           t_0
           (if (or (<= d4 1.6e+65) (not (<= d4 1.35e+75)))
             (* d1 d4)
             (* d1 d2))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = -(d1 * d3);
	double tmp;
	if (d4 <= -7.5e-258) {
		tmp = d1 * d2;
	} else if (d4 <= 7e-300) {
		tmp = t_0;
	} else if (d4 <= 2.2e-117) {
		tmp = d1 * d2;
	} else if (d4 <= 4.5e+29) {
		tmp = t_0;
	} else if ((d4 <= 1.6e+65) || !(d4 <= 1.35e+75)) {
		tmp = d1 * d4;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = -(d1 * d3)
    if (d4 <= (-7.5d-258)) then
        tmp = d1 * d2
    else if (d4 <= 7d-300) then
        tmp = t_0
    else if (d4 <= 2.2d-117) then
        tmp = d1 * d2
    else if (d4 <= 4.5d+29) then
        tmp = t_0
    else if ((d4 <= 1.6d+65) .or. (.not. (d4 <= 1.35d+75))) then
        tmp = d1 * d4
    else
        tmp = d1 * d2
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = -(d1 * d3);
	double tmp;
	if (d4 <= -7.5e-258) {
		tmp = d1 * d2;
	} else if (d4 <= 7e-300) {
		tmp = t_0;
	} else if (d4 <= 2.2e-117) {
		tmp = d1 * d2;
	} else if (d4 <= 4.5e+29) {
		tmp = t_0;
	} else if ((d4 <= 1.6e+65) || !(d4 <= 1.35e+75)) {
		tmp = d1 * d4;
	} else {
		tmp = d1 * d2;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = -(d1 * d3)
	tmp = 0
	if d4 <= -7.5e-258:
		tmp = d1 * d2
	elif d4 <= 7e-300:
		tmp = t_0
	elif d4 <= 2.2e-117:
		tmp = d1 * d2
	elif d4 <= 4.5e+29:
		tmp = t_0
	elif (d4 <= 1.6e+65) or not (d4 <= 1.35e+75):
		tmp = d1 * d4
	else:
		tmp = d1 * d2
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(-Float64(d1 * d3))
	tmp = 0.0
	if (d4 <= -7.5e-258)
		tmp = Float64(d1 * d2);
	elseif (d4 <= 7e-300)
		tmp = t_0;
	elseif (d4 <= 2.2e-117)
		tmp = Float64(d1 * d2);
	elseif (d4 <= 4.5e+29)
		tmp = t_0;
	elseif ((d4 <= 1.6e+65) || !(d4 <= 1.35e+75))
		tmp = Float64(d1 * d4);
	else
		tmp = Float64(d1 * d2);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = -(d1 * d3);
	tmp = 0.0;
	if (d4 <= -7.5e-258)
		tmp = d1 * d2;
	elseif (d4 <= 7e-300)
		tmp = t_0;
	elseif (d4 <= 2.2e-117)
		tmp = d1 * d2;
	elseif (d4 <= 4.5e+29)
		tmp = t_0;
	elseif ((d4 <= 1.6e+65) || ~((d4 <= 1.35e+75)))
		tmp = d1 * d4;
	else
		tmp = d1 * d2;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = (-N[(d1 * d3), $MachinePrecision])}, If[LessEqual[d4, -7.5e-258], N[(d1 * d2), $MachinePrecision], If[LessEqual[d4, 7e-300], t$95$0, If[LessEqual[d4, 2.2e-117], N[(d1 * d2), $MachinePrecision], If[LessEqual[d4, 4.5e+29], t$95$0, If[Or[LessEqual[d4, 1.6e+65], N[Not[LessEqual[d4, 1.35e+75]], $MachinePrecision]], N[(d1 * d4), $MachinePrecision], N[(d1 * d2), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -d1 \cdot d3\\
\mathbf{if}\;d4 \leq -7.5 \cdot 10^{-258}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d4 \leq 7 \cdot 10^{-300}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 2.2 \cdot 10^{-117}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d4 \leq 4.5 \cdot 10^{+29}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 1.6 \cdot 10^{+65} \lor \neg \left(d4 \leq 1.35 \cdot 10^{+75}\right):\\
\;\;\;\;d1 \cdot d4\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < -7.4999999999999998e-258 or 7.0000000000000003e-300 < d4 < 2.2000000000000001e-117 or 1.60000000000000003e65 < d4 < 1.34999999999999999e75

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

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

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

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

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

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

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

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

    if -7.4999999999999998e-258 < d4 < 7.0000000000000003e-300 or 2.2000000000000001e-117 < d4 < 4.5000000000000002e29

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

    if 4.5000000000000002e29 < d4 < 1.60000000000000003e65 or 1.34999999999999999e75 < d4

    1. Initial program 81.3%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -7.5 \cdot 10^{-258}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 7 \cdot 10^{-300}:\\ \;\;\;\;-d1 \cdot d3\\ \mathbf{elif}\;d4 \leq 2.2 \cdot 10^{-117}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 4.5 \cdot 10^{+29}:\\ \;\;\;\;-d1 \cdot d3\\ \mathbf{elif}\;d4 \leq 1.6 \cdot 10^{+65} \lor \neg \left(d4 \leq 1.35 \cdot 10^{+75}\right):\\ \;\;\;\;d1 \cdot d4\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d2\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 66.9% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -d1 \cdot d3\\ t_1 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d3 \leq -1.02 \cdot 10^{+188}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq -6.2 \cdot 10^{-232}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq -1.3 \cdot 10^{-276}:\\ \;\;\;\;-d1 \cdot d1\\ \mathbf{elif}\;d3 \leq 2.3 \cdot 10^{+193}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (- (* d1 d3))) (t_1 (* d1 (+ d4 d2))))
   (if (<= d3 -1.02e+188)
     t_0
     (if (<= d3 -6.2e-232)
       t_1
       (if (<= d3 -1.3e-276) (- (* d1 d1)) (if (<= d3 2.3e+193) t_1 t_0))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = -(d1 * d3);
	double t_1 = d1 * (d4 + d2);
	double tmp;
	if (d3 <= -1.02e+188) {
		tmp = t_0;
	} else if (d3 <= -6.2e-232) {
		tmp = t_1;
	} else if (d3 <= -1.3e-276) {
		tmp = -(d1 * d1);
	} else if (d3 <= 2.3e+193) {
		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 * d3)
    t_1 = d1 * (d4 + d2)
    if (d3 <= (-1.02d+188)) then
        tmp = t_0
    else if (d3 <= (-6.2d-232)) then
        tmp = t_1
    else if (d3 <= (-1.3d-276)) then
        tmp = -(d1 * d1)
    else if (d3 <= 2.3d+193) 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 * d3);
	double t_1 = d1 * (d4 + d2);
	double tmp;
	if (d3 <= -1.02e+188) {
		tmp = t_0;
	} else if (d3 <= -6.2e-232) {
		tmp = t_1;
	} else if (d3 <= -1.3e-276) {
		tmp = -(d1 * d1);
	} else if (d3 <= 2.3e+193) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = -(d1 * d3)
	t_1 = d1 * (d4 + d2)
	tmp = 0
	if d3 <= -1.02e+188:
		tmp = t_0
	elif d3 <= -6.2e-232:
		tmp = t_1
	elif d3 <= -1.3e-276:
		tmp = -(d1 * d1)
	elif d3 <= 2.3e+193:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(-Float64(d1 * d3))
	t_1 = Float64(d1 * Float64(d4 + d2))
	tmp = 0.0
	if (d3 <= -1.02e+188)
		tmp = t_0;
	elseif (d3 <= -6.2e-232)
		tmp = t_1;
	elseif (d3 <= -1.3e-276)
		tmp = Float64(-Float64(d1 * d1));
	elseif (d3 <= 2.3e+193)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = -(d1 * d3);
	t_1 = d1 * (d4 + d2);
	tmp = 0.0;
	if (d3 <= -1.02e+188)
		tmp = t_0;
	elseif (d3 <= -6.2e-232)
		tmp = t_1;
	elseif (d3 <= -1.3e-276)
		tmp = -(d1 * d1);
	elseif (d3 <= 2.3e+193)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = (-N[(d1 * d3), $MachinePrecision])}, Block[{t$95$1 = N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -1.02e+188], t$95$0, If[LessEqual[d3, -6.2e-232], t$95$1, If[LessEqual[d3, -1.3e-276], (-N[(d1 * d1), $MachinePrecision]), If[LessEqual[d3, 2.3e+193], t$95$1, t$95$0]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d3 \leq -6.2 \cdot 10^{-232}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d3 \leq -1.3 \cdot 10^{-276}:\\
\;\;\;\;-d1 \cdot d1\\

\mathbf{elif}\;d3 \leq 2.3 \cdot 10^{+193}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -1.02e188 or 2.30000000000000013e193 < d3

    1. Initial program 85.0%

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

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

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

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

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

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

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

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

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

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

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

    if -1.02e188 < d3 < -6.1999999999999998e-232 or -1.29999999999999992e-276 < d3 < 2.30000000000000013e193

    1. Initial program 89.9%

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

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

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

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

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

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

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

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

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

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

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

    if -6.1999999999999998e-232 < d3 < -1.29999999999999992e-276

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -1.02 \cdot 10^{+188}:\\ \;\;\;\;-d1 \cdot d3\\ \mathbf{elif}\;d3 \leq -6.2 \cdot 10^{-232}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d3 \leq -1.3 \cdot 10^{-276}:\\ \;\;\;\;-d1 \cdot d1\\ \mathbf{elif}\;d3 \leq 2.3 \cdot 10^{+193}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;-d1 \cdot d3\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 64.3% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d4 \leq 1.9 \cdot 10^{-283}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.85 \cdot 10^{-122}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 2.5 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 7.5 \cdot 10^{+88}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d2 d3))))
   (if (<= d4 1.9e-283)
     t_0
     (if (<= d4 1.85e-122)
       (* d1 (- d2 d1))
       (if (<= d4 2.5e+29)
         t_0
         (if (<= d4 7.5e+88) (* d1 (+ d4 d2)) (* d1 (- d4 d3))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double tmp;
	if (d4 <= 1.9e-283) {
		tmp = t_0;
	} else if (d4 <= 1.85e-122) {
		tmp = d1 * (d2 - d1);
	} else if (d4 <= 2.5e+29) {
		tmp = t_0;
	} else if (d4 <= 7.5e+88) {
		tmp = d1 * (d4 + d2);
	} else {
		tmp = d1 * (d4 - d3);
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: tmp
    t_0 = d1 * (d2 - d3)
    if (d4 <= 1.9d-283) then
        tmp = t_0
    else if (d4 <= 1.85d-122) then
        tmp = d1 * (d2 - d1)
    else if (d4 <= 2.5d+29) then
        tmp = t_0
    else if (d4 <= 7.5d+88) then
        tmp = d1 * (d4 + d2)
    else
        tmp = d1 * (d4 - d3)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double tmp;
	if (d4 <= 1.9e-283) {
		tmp = t_0;
	} else if (d4 <= 1.85e-122) {
		tmp = d1 * (d2 - d1);
	} else if (d4 <= 2.5e+29) {
		tmp = t_0;
	} else if (d4 <= 7.5e+88) {
		tmp = d1 * (d4 + d2);
	} else {
		tmp = d1 * (d4 - d3);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d3)
	tmp = 0
	if d4 <= 1.9e-283:
		tmp = t_0
	elif d4 <= 1.85e-122:
		tmp = d1 * (d2 - d1)
	elif d4 <= 2.5e+29:
		tmp = t_0
	elif d4 <= 7.5e+88:
		tmp = d1 * (d4 + d2)
	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.9e-283)
		tmp = t_0;
	elseif (d4 <= 1.85e-122)
		tmp = Float64(d1 * Float64(d2 - d1));
	elseif (d4 <= 2.5e+29)
		tmp = t_0;
	elseif (d4 <= 7.5e+88)
		tmp = Float64(d1 * Float64(d4 + d2));
	else
		tmp = Float64(d1 * Float64(d4 - d3));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d2 - d3);
	tmp = 0.0;
	if (d4 <= 1.9e-283)
		tmp = t_0;
	elseif (d4 <= 1.85e-122)
		tmp = d1 * (d2 - d1);
	elseif (d4 <= 2.5e+29)
		tmp = t_0;
	elseif (d4 <= 7.5e+88)
		tmp = d1 * (d4 + d2);
	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.9e-283], t$95$0, If[LessEqual[d4, 1.85e-122], N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d4, 2.5e+29], t$95$0, If[LessEqual[d4, 7.5e+88], N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision], 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.9 \cdot 10^{-283}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d4 \leq 2.5 \cdot 10^{+29}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 7.5 \cdot 10^{+88}:\\
\;\;\;\;d1 \cdot \left(d4 + d2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d4 < 1.9000000000000001e-283 or 1.8499999999999999e-122 < d4 < 2.5e29

    1. Initial program 91.9%

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

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

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

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

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

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

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

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

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

    if 1.9000000000000001e-283 < d4 < 1.8499999999999999e-122

    1. Initial program 90.0%

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

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

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

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

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

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

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

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

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

    if 2.5e29 < d4 < 7.50000000000000031e88

    1. Initial program 88.2%

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

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

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

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

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

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

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

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

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

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

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

    if 7.50000000000000031e88 < d4

    1. Initial program 80.8%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 1.9 \cdot 10^{-283}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 1.85 \cdot 10^{-122}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 2.5 \cdot 10^{+29}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 7.5 \cdot 10^{+88}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 64.1% accurate, 1.1× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d4 < 2.5e-283

    1. Initial program 90.4%

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

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

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

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

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

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

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

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

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

    if 2.5e-283 < d4 < 3.8000000000000001e-121

    1. Initial program 90.6%

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

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

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

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

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

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

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

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

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

    if 3.8000000000000001e-121 < d4 < 1.15e32

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.15e32 < d4 < 2.1e88

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

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

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

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

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

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

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

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

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

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

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

    if 2.1e88 < d4

    1. Initial program 80.8%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 2.5 \cdot 10^{-283}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 3.8 \cdot 10^{-121}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 1.15 \cdot 10^{+32}:\\ \;\;\;\;d1 \cdot \left(-\left(d1 + d3\right)\right)\\ \mathbf{elif}\;d4 \leq 2.1 \cdot 10^{+88}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 40.3% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;d4 \leq 1.85 \cdot 10^{+31}:\\
\;\;\;\;-d1 \cdot d1\\

\mathbf{elif}\;d4 \leq 1.3 \cdot 10^{+65} \lor \neg \left(d4 \leq 8.8 \cdot 10^{+73}\right):\\
\;\;\;\;d1 \cdot d4\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 5.7999999999999996e-150 or 1.30000000000000001e65 < d4 < 8.8e73

    1. Initial program 91.0%

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

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

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

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

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

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

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

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

    if 5.7999999999999996e-150 < d4 < 1.8499999999999999e31

    1. Initial program 96.6%

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

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

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

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

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

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

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

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

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

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

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

    if 1.8499999999999999e31 < d4 < 1.30000000000000001e65 or 8.8e73 < d4

    1. Initial program 81.3%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 5.8 \cdot 10^{-150}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 1.85 \cdot 10^{+31}:\\ \;\;\;\;-d1 \cdot d1\\ \mathbf{elif}\;d4 \leq 1.3 \cdot 10^{+65} \lor \neg \left(d4 \leq 8.8 \cdot 10^{+73}\right):\\ \;\;\;\;d1 \cdot d4\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d2\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 64.5% accurate, 1.3× speedup?

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

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

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

\mathbf{elif}\;d4 \leq 7.8 \cdot 10^{+29}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 3.10000000000000004e-283 or 1.79999999999999997e-122 < d4 < 7.79999999999999937e29

    1. Initial program 91.9%

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

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

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

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

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

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

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

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

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

    if 3.10000000000000004e-283 < d4 < 1.79999999999999997e-122

    1. Initial program 90.0%

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

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

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

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

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

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

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

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

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

    if 7.79999999999999937e29 < d4

    1. Initial program 82.8%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 3.1 \cdot 10^{-283}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 1.8 \cdot 10^{-122}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 7.8 \cdot 10^{+29}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 62.9% accurate, 1.3× speedup?

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

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

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

\mathbf{elif}\;d4 \leq 3.3 \cdot 10^{+20}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 4.80000000000000006e-284 or 1.8499999999999999e-122 < d4 < 3.3e20

    1. Initial program 91.8%

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

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

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

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

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

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

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

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

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

    if 4.80000000000000006e-284 < d4 < 1.8499999999999999e-122

    1. Initial program 90.0%

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

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

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

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

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

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

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

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

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

    if 3.3e20 < d4

    1. Initial program 83.3%

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

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

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

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

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

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

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

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

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

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

Alternative 10: 92.4% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -1.26 \cdot 10^{+33} \lor \neg \left(d1 \leq 8.6 \cdot 10^{+48}\right):\\
\;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -1.26e33 or 8.59999999999999957e48 < d1

    1. Initial program 70.9%

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

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

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

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

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

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

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

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

    if -1.26e33 < d1 < 8.59999999999999957e48

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

Alternative 11: 92.3% accurate, 1.3× speedup?

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

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

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

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


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

    1. Initial program 63.5%

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

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

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

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

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

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

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

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

    if -6.49999999999999993e33 < d1 < 3.1000000000000002e86

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

    if 3.1000000000000002e86 < d1

    1. Initial program 74.3%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 39.9% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 3.6 \cdot 10^{+20} \lor \neg \left(d4 \leq 6.8 \cdot 10^{+65}\right) \land d4 \leq 1.05 \cdot 10^{+75}:\\
\;\;\;\;d1 \cdot d2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d4 < 3.6e20 or 6.7999999999999999e65 < d4 < 1.04999999999999999e75

    1. Initial program 91.7%

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

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

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

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

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

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

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

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

    if 3.6e20 < d4 < 6.7999999999999999e65 or 1.04999999999999999e75 < d4

    1. Initial program 81.9%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 3.6 \cdot 10^{+20} \lor \neg \left(d4 \leq 6.8 \cdot 10^{+65}\right) \land d4 \leq 1.05 \cdot 10^{+75}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 63.7% accurate, 2.1× speedup?

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

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

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


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

    1. Initial program 91.6%

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

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

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

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

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

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

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

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

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

    if 2.59999999999999988e30 < d4

    1. Initial program 82.8%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 31.9% accurate, 5.0× speedup?

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

\\
d1 \cdot d2
\end{array}
Derivation
  1. Initial program 89.4%

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

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

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

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

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

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

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

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

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

  :herbie-target
  (* d1 (- (+ (- d2 d3) d4) d1))

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