FastMath dist4

Percentage Accurate: 87.4% → 100.0%
Time: 10.8s
Alternatives: 12
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

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

\\
d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) + d2\right)
\end{array}
Derivation
  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. sub-neg82.8%

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

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

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

      \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
    6. associate--r-82.8%

      \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
    7. associate-+r-82.8%

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

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

      \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    10. sub-neg82.8%

      \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    11. distribute-lft-out--83.6%

      \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    12. distribute-lft-out--92.6%

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
    13. neg-sub092.6%

      \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
    14. distribute-rgt-neg-out92.6%

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
    16. sub-neg100.0%

      \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
    17. remove-double-neg100.0%

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

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

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

Alternative 2: 65.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ t_1 := d1 \cdot \left(-d1\right)\\ t_2 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d1 \leq -1.25 \cdot 10^{+122}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d1 \leq -9.2 \cdot 10^{-137}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d1 \leq -1.45 \cdot 10^{-281}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d1 \leq 4 \cdot 10^{-103}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d1 \leq 1.4 \cdot 10^{+96}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d2 d3))) (t_1 (* d1 (- d1))) (t_2 (* d1 (+ d4 d2))))
   (if (<= d1 -1.25e+122)
     t_1
     (if (<= d1 -9.2e-137)
       t_2
       (if (<= d1 -1.45e-281)
         t_0
         (if (<= d1 4e-103) t_2 (if (<= d1 1.4e+96) t_0 t_1)))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double t_1 = d1 * -d1;
	double t_2 = d1 * (d4 + d2);
	double tmp;
	if (d1 <= -1.25e+122) {
		tmp = t_1;
	} else if (d1 <= -9.2e-137) {
		tmp = t_2;
	} else if (d1 <= -1.45e-281) {
		tmp = t_0;
	} else if (d1 <= 4e-103) {
		tmp = t_2;
	} else if (d1 <= 1.4e+96) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = d1 * (d2 - d3)
    t_1 = d1 * -d1
    t_2 = d1 * (d4 + d2)
    if (d1 <= (-1.25d+122)) then
        tmp = t_1
    else if (d1 <= (-9.2d-137)) then
        tmp = t_2
    else if (d1 <= (-1.45d-281)) then
        tmp = t_0
    else if (d1 <= 4d-103) then
        tmp = t_2
    else if (d1 <= 1.4d+96) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double t_1 = d1 * -d1;
	double t_2 = d1 * (d4 + d2);
	double tmp;
	if (d1 <= -1.25e+122) {
		tmp = t_1;
	} else if (d1 <= -9.2e-137) {
		tmp = t_2;
	} else if (d1 <= -1.45e-281) {
		tmp = t_0;
	} else if (d1 <= 4e-103) {
		tmp = t_2;
	} else if (d1 <= 1.4e+96) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d3)
	t_1 = d1 * -d1
	t_2 = d1 * (d4 + d2)
	tmp = 0
	if d1 <= -1.25e+122:
		tmp = t_1
	elif d1 <= -9.2e-137:
		tmp = t_2
	elif d1 <= -1.45e-281:
		tmp = t_0
	elif d1 <= 4e-103:
		tmp = t_2
	elif d1 <= 1.4e+96:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d3))
	t_1 = Float64(d1 * Float64(-d1))
	t_2 = Float64(d1 * Float64(d4 + d2))
	tmp = 0.0
	if (d1 <= -1.25e+122)
		tmp = t_1;
	elseif (d1 <= -9.2e-137)
		tmp = t_2;
	elseif (d1 <= -1.45e-281)
		tmp = t_0;
	elseif (d1 <= 4e-103)
		tmp = t_2;
	elseif (d1 <= 1.4e+96)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d2 - d3);
	t_1 = d1 * -d1;
	t_2 = d1 * (d4 + d2);
	tmp = 0.0;
	if (d1 <= -1.25e+122)
		tmp = t_1;
	elseif (d1 <= -9.2e-137)
		tmp = t_2;
	elseif (d1 <= -1.45e-281)
		tmp = t_0;
	elseif (d1 <= 4e-103)
		tmp = t_2;
	elseif (d1 <= 1.4e+96)
		tmp = t_0;
	else
		tmp = t_1;
	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 * (-d1)), $MachinePrecision]}, Block[{t$95$2 = N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d1, -1.25e+122], t$95$1, If[LessEqual[d1, -9.2e-137], t$95$2, If[LessEqual[d1, -1.45e-281], t$95$0, If[LessEqual[d1, 4e-103], t$95$2, If[LessEqual[d1, 1.4e+96], t$95$0, t$95$1]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d1 \leq -9.2 \cdot 10^{-137}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;d1 \leq -1.45 \cdot 10^{-281}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d1 \leq 4 \cdot 10^{-103}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;d1 \leq 1.4 \cdot 10^{+96}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d1 < -1.24999999999999997e122 or 1.4e96 < d1

    1. Initial program 57.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+57.1%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-57.1%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-57.1%

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

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

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg57.1%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--58.2%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--81.6%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub081.6%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out81.6%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

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

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

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

    if -1.24999999999999997e122 < d1 < -9.20000000000000032e-137 or -1.44999999999999995e-281 < d1 < 3.99999999999999983e-103

    1. Initial program 97.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+97.9%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-97.9%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-97.9%

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

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

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg97.9%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--98.9%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--98.9%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub098.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out98.9%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

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

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

    if -9.20000000000000032e-137 < d1 < -1.44999999999999995e-281 or 3.99999999999999983e-103 < d1 < 1.4e96

    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. sub-neg100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub0100.0%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out100.0%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -1.25 \cdot 10^{+122}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d1 \leq -9.2 \cdot 10^{-137}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d1 \leq -1.45 \cdot 10^{-281}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d1 \leq 4 \cdot 10^{-103}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d1 \leq 1.4 \cdot 10^{+96}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \end{array} \]

Alternative 3: 63.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{if}\;d2 \leq -4.5 \cdot 10^{+68}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -2.15 \cdot 10^{-275}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq 8.5 \cdot 10^{-223}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{elif}\;d2 \leq 10^{-158}:\\ \;\;\;\;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 (- (- d1) d3))))
   (if (<= d2 -4.5e+68)
     (* d1 (- d2 d3))
     (if (<= d2 -2.15e-275)
       t_0
       (if (<= d2 8.5e-223)
         (* d1 (- d4 d3))
         (if (<= d2 1e-158) t_0 (* d1 (- d4 d1))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (-d1 - d3);
	double tmp;
	if (d2 <= -4.5e+68) {
		tmp = d1 * (d2 - d3);
	} else if (d2 <= -2.15e-275) {
		tmp = t_0;
	} else if (d2 <= 8.5e-223) {
		tmp = d1 * (d4 - d3);
	} else if (d2 <= 1e-158) {
		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 * (-d1 - d3)
    if (d2 <= (-4.5d+68)) then
        tmp = d1 * (d2 - d3)
    else if (d2 <= (-2.15d-275)) then
        tmp = t_0
    else if (d2 <= 8.5d-223) then
        tmp = d1 * (d4 - d3)
    else if (d2 <= 1d-158) 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 * (-d1 - d3);
	double tmp;
	if (d2 <= -4.5e+68) {
		tmp = d1 * (d2 - d3);
	} else if (d2 <= -2.15e-275) {
		tmp = t_0;
	} else if (d2 <= 8.5e-223) {
		tmp = d1 * (d4 - d3);
	} else if (d2 <= 1e-158) {
		tmp = t_0;
	} else {
		tmp = d1 * (d4 - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (-d1 - d3)
	tmp = 0
	if d2 <= -4.5e+68:
		tmp = d1 * (d2 - d3)
	elif d2 <= -2.15e-275:
		tmp = t_0
	elif d2 <= 8.5e-223:
		tmp = d1 * (d4 - d3)
	elif d2 <= 1e-158:
		tmp = t_0
	else:
		tmp = d1 * (d4 - d1)
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(Float64(-d1) - d3))
	tmp = 0.0
	if (d2 <= -4.5e+68)
		tmp = Float64(d1 * Float64(d2 - d3));
	elseif (d2 <= -2.15e-275)
		tmp = t_0;
	elseif (d2 <= 8.5e-223)
		tmp = Float64(d1 * Float64(d4 - d3));
	elseif (d2 <= 1e-158)
		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 * (-d1 - d3);
	tmp = 0.0;
	if (d2 <= -4.5e+68)
		tmp = d1 * (d2 - d3);
	elseif (d2 <= -2.15e-275)
		tmp = t_0;
	elseif (d2 <= 8.5e-223)
		tmp = d1 * (d4 - d3);
	elseif (d2 <= 1e-158)
		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[((-d1) - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d2, -4.5e+68], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d2, -2.15e-275], t$95$0, If[LessEqual[d2, 8.5e-223], N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d2, 1e-158], t$95$0, N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d2 \leq -2.15 \cdot 10^{-275}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d2 \leq 10^{-158}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 78.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+78.3%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-78.3%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-78.3%

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--78.3%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--78.3%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out78.3%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if -4.5000000000000003e68 < d2 < -2.14999999999999988e-275 or 8.5000000000000003e-223 < d2 < 1.00000000000000006e-158

    1. Initial program 85.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-d1 \cdot d3\right)} + d1 \cdot \left(d4 - d1\right) \]
      2. distribute-rgt-neg-in88.9%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(-d3\right) + \left(d4 - d1\right)\right)} \]
      4. associate-+r-96.8%

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

        \[\leadsto d1 \cdot \left(\color{blue}{\left(d4 + \left(-d3\right)\right)} - d1\right) \]
      6. sub-neg96.8%

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

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

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

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

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

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

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

    if -2.14999999999999988e-275 < d2 < 8.5000000000000003e-223

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-84.0%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-84.0%

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--84.0%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub0100.0%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out100.0%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if 1.00000000000000006e-158 < d2

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(-d3\right) + \left(d4 - d1\right)\right)} \]
      4. associate-+r-72.8%

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

        \[\leadsto d1 \cdot \left(\color{blue}{\left(d4 + \left(-d3\right)\right)} - d1\right) \]
      6. sub-neg72.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -4.5 \cdot 10^{+68}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -2.15 \cdot 10^{-275}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{elif}\;d2 \leq 8.5 \cdot 10^{-223}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{elif}\;d2 \leq 10^{-158}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 4: 61.2% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;d4 \leq 2.6 \cdot 10^{+31} \lor \neg \left(d4 \leq 7 \cdot 10^{+79}\right) \land d4 \leq 8 \cdot 10^{+122}:\\
\;\;\;\;d1 \cdot \left(d4 - d1\right)\\

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


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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-82.0%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-82.0%

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--82.0%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--92.7%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out92.7%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if 2.69999999999999994e-118 < d4 < 2.6e31 or 6.99999999999999961e79 < d4 < 8.00000000000000012e122

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(-d3\right) + \left(d4 - d1\right)\right)} \]
      4. associate-+r-84.3%

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

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

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

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

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

    if 2.6e31 < d4 < 6.99999999999999961e79 or 8.00000000000000012e122 < d4

    1. Initial program 78.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+78.3%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-78.3%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-78.3%

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--82.6%

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

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out91.3%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 2.7 \cdot 10^{-118}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 2.6 \cdot 10^{+31} \lor \neg \left(d4 \leq 7 \cdot 10^{+79}\right) \land d4 \leq 8 \cdot 10^{+122}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]

Alternative 5: 64.4% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;d1 \leq 1.45 \cdot 10^{-8}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d1 \leq 6.2 \cdot 10^{+93}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d1 < -1.3499999999999999e122 or 6.20000000000000038e93 < d1

    1. Initial program 57.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+57.1%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-57.1%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-57.1%

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

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

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg57.1%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--58.2%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--81.6%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub081.6%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out81.6%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

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

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

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

    if -1.3499999999999999e122 < d1 < 1.4500000000000001e-8 or 4.2000000000000001e55 < d1 < 6.20000000000000038e93

    1. Initial program 98.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+98.6%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-98.6%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-98.6%

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

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

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg98.6%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--99.3%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--99.3%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out99.3%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

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

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

    if 1.4500000000000001e-8 < d1 < 4.2000000000000001e55

    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. sub-neg100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub0100.0%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out100.0%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -1.35 \cdot 10^{+122}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d1 \leq 1.45 \cdot 10^{-8}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d1 \leq 4.2 \cdot 10^{+55}:\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \mathbf{elif}\;d1 \leq 6.2 \cdot 10^{+93}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \end{array} \]

Alternative 6: 39.4% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;d4 \leq 2.4 \cdot 10^{-223}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 5.2 \cdot 10^{-148}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d4 \leq 5.2 \cdot 10^{+84}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < -1.79999999999999985e-275 or 2.39999999999999985e-223 < d4 < 5.20000000000000015e-148

    1. Initial program 81.6%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-81.6%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-81.6%

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

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

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg81.6%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--81.6%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub092.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out92.9%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    if -1.79999999999999985e-275 < d4 < 2.39999999999999985e-223 or 5.20000000000000015e-148 < d4 < 5.2000000000000002e84

    1. Initial program 87.1%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-87.1%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-87.1%

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

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

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg87.1%

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub092.8%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out92.8%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

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

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

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

    if 5.2000000000000002e84 < d4

    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. sub-neg80.0%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-80.0%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-80.0%

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--84.4%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub091.1%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out91.1%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -1.8 \cdot 10^{-275}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 2.4 \cdot 10^{-223}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 5.2 \cdot 10^{-148}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 5.2 \cdot 10^{+84}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 7: 39.5% accurate, 1.2× speedup?

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

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

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

\mathbf{elif}\;d4 \leq 5.2 \cdot 10^{-148}:\\
\;\;\;\;d1 \cdot d2\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d4 < -3.89999999999999985e-274 or 8.00000000000000014e-221 < d4 < 5.20000000000000015e-148

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-81.2%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-81.2%

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--81.2%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub092.8%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out92.8%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    if -3.89999999999999985e-274 < d4 < 8.00000000000000014e-221

    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. sub-neg88.2%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-88.2%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-88.2%

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub094.1%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out94.1%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

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

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

    if 5.20000000000000015e-148 < d4 < 1.0999999999999999e84

    1. Initial program 87.2%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-87.2%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-87.2%

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

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

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

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

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--92.3%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out92.3%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

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

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

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

    if 1.0999999999999999e84 < d4

    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. sub-neg80.0%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-80.0%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-80.0%

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--84.4%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub091.1%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out91.1%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -3.9 \cdot 10^{-274}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 8 \cdot 10^{-221}:\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 5.2 \cdot 10^{-148}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 1.1 \cdot 10^{+84}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 8: 62.5% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;d2 \leq 6.4 \cdot 10^{-270} \lor \neg \left(d2 \leq 4 \cdot 10^{-238}\right):\\
\;\;\;\;d1 \cdot \left(d4 - d1\right)\\

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


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

    1. Initial program 77.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+77.8%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-77.8%

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

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

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg77.8%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--77.7%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub079.6%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out79.6%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if -6.00000000000000047e46 < d2 < 6.39999999999999976e-270 or 4e-238 < d2

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(-d3\right) + \left(d4 - d1\right)\right)} \]
      4. associate-+r-85.5%

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

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

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

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

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

    if 6.39999999999999976e-270 < d2 < 4e-238

    1. Initial program 62.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+62.5%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-62.5%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-62.5%

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

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

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg62.5%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--62.5%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub0100.0%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out100.0%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -6 \cdot 10^{+46}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq 6.4 \cdot 10^{-270} \lor \neg \left(d2 \leq 4 \cdot 10^{-238}\right):\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \end{array} \]

Alternative 9: 83.1% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 78.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+78.3%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-78.3%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-78.3%

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--78.3%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--78.3%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out78.3%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if -1.4499999999999999e69 < d2

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-83.8%

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

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

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg83.8%

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

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

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out95.7%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

Alternative 10: 85.7% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 78.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+78.3%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-78.3%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-78.3%

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--78.3%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--78.3%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out78.3%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    if -1.1000000000000001e69 < d2

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-83.8%

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

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

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg83.8%

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

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

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out95.7%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

Alternative 11: 40.1% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 77.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+77.4%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-77.4%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-77.4%

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--77.4%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--79.2%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out79.2%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    if -6.5e51 < d2

    1. Initial program 84.2%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-84.2%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-84.2%

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--85.2%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--96.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub096.0%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out96.0%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

Alternative 12: 31.0% accurate, 5.0× speedup?

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
    6. associate--r-82.8%

      \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
    7. associate-+r-82.8%

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

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

      \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    10. sub-neg82.8%

      \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    11. distribute-lft-out--83.6%

      \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    12. distribute-lft-out--92.6%

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
    13. neg-sub092.6%

      \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
    14. distribute-rgt-neg-out92.6%

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
    16. sub-neg100.0%

      \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
    17. remove-double-neg100.0%

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

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

    \[\leadsto \color{blue}{d1 \cdot d2} \]
  5. Final simplification28.2%

    \[\leadsto d1 \cdot d2 \]

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