FastMath dist4

Percentage Accurate: 88.3% → 100.0%
Time: 6.0s
Alternatives: 13
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 13 alternatives:

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

Initial Program: 88.3% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

Alternative 2: 63.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d1\right)\\ \mathbf{if}\;d4 \leq 2.1 \cdot 10^{-267}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.4 \cdot 10^{-147}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 2.7 \cdot 10^{-128}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 4.5 \cdot 10^{+93}:\\ \;\;\;\;\left(d1 + d3\right) \cdot \left(-d1\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 d1))))
   (if (<= d4 2.1e-267)
     t_0
     (if (<= d4 1.4e-147)
       (* d1 (- d2 d3))
       (if (<= d4 2.7e-128)
         t_0
         (if (<= d4 4.5e+93) (* (+ d1 d3) (- d1)) (* d1 (- d4 d3))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d1);
	double tmp;
	if (d4 <= 2.1e-267) {
		tmp = t_0;
	} else if (d4 <= 1.4e-147) {
		tmp = d1 * (d2 - d3);
	} else if (d4 <= 2.7e-128) {
		tmp = t_0;
	} else if (d4 <= 4.5e+93) {
		tmp = (d1 + d3) * -d1;
	} else {
		tmp = d1 * (d4 - d3);
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: tmp
    t_0 = d1 * (d2 - d1)
    if (d4 <= 2.1d-267) then
        tmp = t_0
    else if (d4 <= 1.4d-147) then
        tmp = d1 * (d2 - d3)
    else if (d4 <= 2.7d-128) then
        tmp = t_0
    else if (d4 <= 4.5d+93) then
        tmp = (d1 + d3) * -d1
    else
        tmp = d1 * (d4 - d3)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d1);
	double tmp;
	if (d4 <= 2.1e-267) {
		tmp = t_0;
	} else if (d4 <= 1.4e-147) {
		tmp = d1 * (d2 - d3);
	} else if (d4 <= 2.7e-128) {
		tmp = t_0;
	} else if (d4 <= 4.5e+93) {
		tmp = (d1 + d3) * -d1;
	} else {
		tmp = d1 * (d4 - d3);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d1)
	tmp = 0
	if d4 <= 2.1e-267:
		tmp = t_0
	elif d4 <= 1.4e-147:
		tmp = d1 * (d2 - d3)
	elif d4 <= 2.7e-128:
		tmp = t_0
	elif d4 <= 4.5e+93:
		tmp = (d1 + d3) * -d1
	else:
		tmp = d1 * (d4 - d3)
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d1))
	tmp = 0.0
	if (d4 <= 2.1e-267)
		tmp = t_0;
	elseif (d4 <= 1.4e-147)
		tmp = Float64(d1 * Float64(d2 - d3));
	elseif (d4 <= 2.7e-128)
		tmp = t_0;
	elseif (d4 <= 4.5e+93)
		tmp = Float64(Float64(d1 + d3) * Float64(-d1));
	else
		tmp = Float64(d1 * Float64(d4 - d3));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d2 - d1);
	tmp = 0.0;
	if (d4 <= 2.1e-267)
		tmp = t_0;
	elseif (d4 <= 1.4e-147)
		tmp = d1 * (d2 - d3);
	elseif (d4 <= 2.7e-128)
		tmp = t_0;
	elseif (d4 <= 4.5e+93)
		tmp = (d1 + d3) * -d1;
	else
		tmp = d1 * (d4 - d3);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d4, 2.1e-267], t$95$0, If[LessEqual[d4, 1.4e-147], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d4, 2.7e-128], t$95$0, If[LessEqual[d4, 4.5e+93], N[(N[(d1 + d3), $MachinePrecision] * (-d1)), $MachinePrecision], N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d4 \leq 2.7 \cdot 10^{-128}:\\
\;\;\;\;t_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d4 < 2.1000000000000001e-267 or 1.4e-147 < d4 < 2.70000000000000006e-128

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

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

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

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

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

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

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

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

    if 2.1000000000000001e-267 < d4 < 1.4e-147

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

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

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

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

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

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

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

    if 2.70000000000000006e-128 < d4 < 4.49999999999999991e93

    1. Initial program 88.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.49999999999999991e93 < d4

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 2.1 \cdot 10^{-267}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 1.4 \cdot 10^{-147}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 2.7 \cdot 10^{-128}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 4.5 \cdot 10^{+93}:\\ \;\;\;\;\left(d1 + d3\right) \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]

Alternative 3: 62.2% accurate, 1.3× speedup?

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

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

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

\mathbf{elif}\;d4 \leq 2.05 \cdot 10^{+93}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 6.9999999999999997e-82 or 4.9999999999999999e-48 < d4 < 2.0500000000000001e93

    1. Initial program 89.7%

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

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

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

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

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

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

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

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

    if 6.9999999999999997e-82 < d4 < 4.9999999999999999e-48

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

    if 2.0500000000000001e93 < d4

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 7 \cdot 10^{-82}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 5 \cdot 10^{-48}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d4 \leq 2.05 \cdot 10^{+93}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]

Alternative 4: 71.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d3 \leq -6.8 \cdot 10^{+103}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 7 \cdot 10^{-27}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 1.62 \cdot 10^{+74}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d2 d3))))
   (if (<= d3 -6.8e+103)
     t_0
     (if (<= d3 7e-27)
       (* d1 (- d2 d1))
       (if (<= d3 1.62e+74) (* d1 (+ d2 d4)) t_0)))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double tmp;
	if (d3 <= -6.8e+103) {
		tmp = t_0;
	} else if (d3 <= 7e-27) {
		tmp = d1 * (d2 - d1);
	} else if (d3 <= 1.62e+74) {
		tmp = d1 * (d2 + d4);
	} 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) :: tmp
    t_0 = d1 * (d2 - d3)
    if (d3 <= (-6.8d+103)) then
        tmp = t_0
    else if (d3 <= 7d-27) then
        tmp = d1 * (d2 - d1)
    else if (d3 <= 1.62d+74) then
        tmp = d1 * (d2 + d4)
    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 tmp;
	if (d3 <= -6.8e+103) {
		tmp = t_0;
	} else if (d3 <= 7e-27) {
		tmp = d1 * (d2 - d1);
	} else if (d3 <= 1.62e+74) {
		tmp = d1 * (d2 + d4);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d3)
	tmp = 0
	if d3 <= -6.8e+103:
		tmp = t_0
	elif d3 <= 7e-27:
		tmp = d1 * (d2 - d1)
	elif d3 <= 1.62e+74:
		tmp = d1 * (d2 + d4)
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d3))
	tmp = 0.0
	if (d3 <= -6.8e+103)
		tmp = t_0;
	elseif (d3 <= 7e-27)
		tmp = Float64(d1 * Float64(d2 - d1));
	elseif (d3 <= 1.62e+74)
		tmp = Float64(d1 * Float64(d2 + d4));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d2 - d3);
	tmp = 0.0;
	if (d3 <= -6.8e+103)
		tmp = t_0;
	elseif (d3 <= 7e-27)
		tmp = d1 * (d2 - d1);
	elseif (d3 <= 1.62e+74)
		tmp = d1 * (d2 + d4);
	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]}, If[LessEqual[d3, -6.8e+103], t$95$0, If[LessEqual[d3, 7e-27], N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 1.62e+74], N[(d1 * N[(d2 + d4), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -6.7999999999999997e103 or 1.62e74 < d3

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

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

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

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

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

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

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

    if -6.7999999999999997e103 < d3 < 7.0000000000000003e-27

    1. Initial program 90.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+90.8%

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

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

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

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

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

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

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

    if 7.0000000000000003e-27 < d3 < 1.62e74

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -6.8 \cdot 10^{+103}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq 7 \cdot 10^{-27}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 1.62 \cdot 10^{+74}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \end{array} \]

Alternative 5: 70.8% accurate, 1.3× speedup?

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

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

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

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

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


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

    1. Initial program 79.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+79.6%

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

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

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

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

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

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

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

    if -1.0499999999999999e39 < d3 < 3.0000000000000001e-27

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

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

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

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

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

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

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

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

    if 3.0000000000000001e-27 < d3 < 1.35e72

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

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

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

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

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

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

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

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

    if 1.35e72 < d3

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -1.05 \cdot 10^{+39}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{elif}\;d3 \leq 3 \cdot 10^{-27}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 1.35 \cdot 10^{+72}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \end{array} \]

Alternative 6: 92.5% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -1.2 \cdot 10^{-33} \lor \neg \left(d3 \leq 1.4 \cdot 10^{-13}\right):\\
\;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -1.2e-33 or 1.4000000000000001e-13 < d3

    1. Initial program 84.4%

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

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

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

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

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

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

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

    if -1.2e-33 < d3 < 1.4000000000000001e-13

    1. Initial program 92.1%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -1.2 \cdot 10^{-33} \lor \neg \left(d3 \leq 1.4 \cdot 10^{-13}\right):\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d1\right)\\ \end{array} \]

Alternative 7: 87.7% accurate, 1.3× speedup?

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

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

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

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


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

    1. Initial program 80.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+80.0%

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

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

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

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

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

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

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

    if -2.40000000000000018e211 < d3 < 6.6000000000000003e97

    1. Initial program 90.2%

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

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

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

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

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

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

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

    if 6.6000000000000003e97 < d3

    1. Initial program 82.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+82.3%

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

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

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

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

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

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

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

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

Alternative 8: 39.4% accurate, 1.5× speedup?

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

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

\mathbf{elif}\;d2 \leq 1.35 \cdot 10^{-299}:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\

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

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


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

    1. Initial program 80.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+80.7%

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

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

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

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

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

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

    if -1.19999999999999995e45 < d2 < 1.35000000000000001e-299

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    5. Step-by-step derivation
      1. unpow248.6%

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

        \[\leadsto \color{blue}{-d1 \cdot d1} \]
      3. distribute-rgt-neg-out48.6%

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

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

    if 1.35000000000000001e-299 < d2 < 1.60000000000000002e-124

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

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

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

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

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

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

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

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

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

    if 1.60000000000000002e-124 < d2

    1. Initial program 84.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+84.8%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.2 \cdot 10^{+45}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq 1.35 \cdot 10^{-299}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d2 \leq 1.6 \cdot 10^{-124}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 9: 64.1% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -7.5 \cdot 10^{+45} \lor \neg \left(d1 \leq 6.6 \cdot 10^{+77}\right):\\
\;\;\;\;d1 \cdot \left(-d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -7.50000000000000058e45 or 6.5999999999999996e77 < d1

    1. Initial program 73.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+73.9%

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    5. Step-by-step derivation
      1. unpow267.4%

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

        \[\leadsto \color{blue}{-d1 \cdot d1} \]
      3. distribute-rgt-neg-out67.4%

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

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

    if -7.50000000000000058e45 < d1 < 6.5999999999999996e77

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -7.5 \cdot 10^{+45} \lor \neg \left(d1 \leq 6.6 \cdot 10^{+77}\right):\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]

Alternative 10: 85.9% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 89.1%

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

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

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

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

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

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

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

    if 2.1e88 < d4

    1. Initial program 82.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+82.2%

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

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

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

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

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

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

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

Alternative 11: 39.9% accurate, 1.8× speedup?

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

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

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

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


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

    1. Initial program 80.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+80.7%

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

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

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

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

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

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

    if -1.19999999999999995e45 < d2 < 1.25000000000000005e-43

    1. Initial program 93.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+93.2%

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    5. Step-by-step derivation
      1. unpow246.2%

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

        \[\leadsto \color{blue}{-d1 \cdot d1} \]
      3. distribute-rgt-neg-out46.2%

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

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

    if 1.25000000000000005e-43 < d2

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.2 \cdot 10^{+45}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq 1.25 \cdot 10^{-43}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 12: 38.7% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 79.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+79.6%

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

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

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

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

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

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

    if -6.2000000000000004e37 < d2

    1. Initial program 90.1%

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

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

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

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

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

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

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

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

Alternative 13: 30.4% accurate, 5.0× speedup?

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

\\
d1 \cdot d4
\end{array}
Derivation
  1. Initial program 87.9%

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

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

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

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

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

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

    \[\leadsto \color{blue}{d1 \cdot d4} \]
  5. Final simplification27.9%

    \[\leadsto d1 \cdot d4 \]

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 2023196 
(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)))