FastMath dist4

Percentage Accurate: 88.1% → 100.0%
Time: 7.7s
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: 88.1% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 2: 62.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d1\right)\\ t_1 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d4 \leq -1.55 \cdot 10^{-195}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d4 \leq 8.4 \cdot 10^{-303}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d4 \leq 1.7 \cdot 10^{-147}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d4 \leq 3.9 \cdot 10^{+68} \lor \neg \left(d4 \leq 4.2 \cdot 10^{+90}\right) \land d4 \leq 1.45 \cdot 10^{+108}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d2 d1))) (t_1 (* d1 (- d2 d3))))
   (if (<= d4 -1.55e-195)
     t_0
     (if (<= d4 8.4e-303)
       t_1
       (if (<= d4 1.7e-147)
         t_0
         (if (or (<= d4 3.9e+68) (and (not (<= d4 4.2e+90)) (<= d4 1.45e+108)))
           t_1
           (* d1 (- d4 d1))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d1);
	double t_1 = d1 * (d2 - d3);
	double tmp;
	if (d4 <= -1.55e-195) {
		tmp = t_0;
	} else if (d4 <= 8.4e-303) {
		tmp = t_1;
	} else if (d4 <= 1.7e-147) {
		tmp = t_0;
	} else if ((d4 <= 3.9e+68) || (!(d4 <= 4.2e+90) && (d4 <= 1.45e+108))) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = d1 * (d2 - d1)
    t_1 = d1 * (d2 - d3)
    if (d4 <= (-1.55d-195)) then
        tmp = t_0
    else if (d4 <= 8.4d-303) then
        tmp = t_1
    else if (d4 <= 1.7d-147) then
        tmp = t_0
    else if ((d4 <= 3.9d+68) .or. (.not. (d4 <= 4.2d+90)) .and. (d4 <= 1.45d+108)) then
        tmp = t_1
    else
        tmp = d1 * (d4 - d1)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d1);
	double t_1 = d1 * (d2 - d3);
	double tmp;
	if (d4 <= -1.55e-195) {
		tmp = t_0;
	} else if (d4 <= 8.4e-303) {
		tmp = t_1;
	} else if (d4 <= 1.7e-147) {
		tmp = t_0;
	} else if ((d4 <= 3.9e+68) || (!(d4 <= 4.2e+90) && (d4 <= 1.45e+108))) {
		tmp = t_1;
	} else {
		tmp = d1 * (d4 - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d1)
	t_1 = d1 * (d2 - d3)
	tmp = 0
	if d4 <= -1.55e-195:
		tmp = t_0
	elif d4 <= 8.4e-303:
		tmp = t_1
	elif d4 <= 1.7e-147:
		tmp = t_0
	elif (d4 <= 3.9e+68) or (not (d4 <= 4.2e+90) and (d4 <= 1.45e+108)):
		tmp = t_1
	else:
		tmp = d1 * (d4 - d1)
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d1))
	t_1 = Float64(d1 * Float64(d2 - d3))
	tmp = 0.0
	if (d4 <= -1.55e-195)
		tmp = t_0;
	elseif (d4 <= 8.4e-303)
		tmp = t_1;
	elseif (d4 <= 1.7e-147)
		tmp = t_0;
	elseif ((d4 <= 3.9e+68) || (!(d4 <= 4.2e+90) && (d4 <= 1.45e+108)))
		tmp = t_1;
	else
		tmp = Float64(d1 * Float64(d4 - d1));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d2 - d1);
	t_1 = d1 * (d2 - d3);
	tmp = 0.0;
	if (d4 <= -1.55e-195)
		tmp = t_0;
	elseif (d4 <= 8.4e-303)
		tmp = t_1;
	elseif (d4 <= 1.7e-147)
		tmp = t_0;
	elseif ((d4 <= 3.9e+68) || (~((d4 <= 4.2e+90)) && (d4 <= 1.45e+108)))
		tmp = t_1;
	else
		tmp = d1 * (d4 - d1);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d4, -1.55e-195], t$95$0, If[LessEqual[d4, 8.4e-303], t$95$1, If[LessEqual[d4, 1.7e-147], t$95$0, If[Or[LessEqual[d4, 3.9e+68], And[N[Not[LessEqual[d4, 4.2e+90]], $MachinePrecision], LessEqual[d4, 1.45e+108]]], t$95$1, N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d4 \leq 8.4 \cdot 10^{-303}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d4 \leq 1.7 \cdot 10^{-147}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d4 \leq 3.9 \cdot 10^{+68} \lor \neg \left(d4 \leq 4.2 \cdot 10^{+90}\right) \land d4 \leq 1.45 \cdot 10^{+108}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < -1.55000000000000001e-195 or 8.4e-303 < d4 < 1.69999999999999998e-147

    1. Initial program 85.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Add Preprocessing
    3. Taylor expanded in d3 around 0 66.5%

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

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

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

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

        \[\leadsto d1 \cdot d2 - \color{blue}{d1 \cdot d1} \]
      2. distribute-lft-out--57.0%

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

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

    if -1.55000000000000001e-195 < d4 < 8.4e-303 or 1.69999999999999998e-147 < d4 < 3.90000000000000019e68 or 4.19999999999999961e90 < d4 < 1.45000000000000004e108

    1. Initial program 93.2%

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

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

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

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

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

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

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

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

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

    if 3.90000000000000019e68 < d4 < 4.19999999999999961e90 or 1.45000000000000004e108 < d4

    1. Initial program 79.6%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -1.55 \cdot 10^{-195}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 8.4 \cdot 10^{-303}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 1.7 \cdot 10^{-147}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 3.9 \cdot 10^{+68} \lor \neg \left(d4 \leq 4.2 \cdot 10^{+90}\right) \land d4 \leq 1.45 \cdot 10^{+108}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 63.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d1\right)\\ t_1 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d4 \leq -1.3 \cdot 10^{-194}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d4 \leq 2.6 \cdot 10^{-299}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d4 \leq 2.5 \cdot 10^{-147}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d4 \leq 4.15 \cdot 10^{+65}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d4 \leq 7 \cdot 10^{+90}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d4 \leq 1.5 \cdot 10^{+108}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d2 d1))) (t_1 (* d1 (- d2 d3))))
   (if (<= d4 -1.3e-194)
     t_0
     (if (<= d4 2.6e-299)
       t_1
       (if (<= d4 2.5e-147)
         t_0
         (if (<= d4 4.15e+65)
           t_1
           (if (<= d4 7e+90)
             t_0
             (if (<= d4 1.5e+108) t_1 (* d1 (+ d4 d2))))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d1);
	double t_1 = d1 * (d2 - d3);
	double tmp;
	if (d4 <= -1.3e-194) {
		tmp = t_0;
	} else if (d4 <= 2.6e-299) {
		tmp = t_1;
	} else if (d4 <= 2.5e-147) {
		tmp = t_0;
	} else if (d4 <= 4.15e+65) {
		tmp = t_1;
	} else if (d4 <= 7e+90) {
		tmp = t_0;
	} else if (d4 <= 1.5e+108) {
		tmp = t_1;
	} else {
		tmp = d1 * (d4 + d2);
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = d1 * (d2 - d1)
    t_1 = d1 * (d2 - d3)
    if (d4 <= (-1.3d-194)) then
        tmp = t_0
    else if (d4 <= 2.6d-299) then
        tmp = t_1
    else if (d4 <= 2.5d-147) then
        tmp = t_0
    else if (d4 <= 4.15d+65) then
        tmp = t_1
    else if (d4 <= 7d+90) then
        tmp = t_0
    else if (d4 <= 1.5d+108) then
        tmp = t_1
    else
        tmp = d1 * (d4 + d2)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d1);
	double t_1 = d1 * (d2 - d3);
	double tmp;
	if (d4 <= -1.3e-194) {
		tmp = t_0;
	} else if (d4 <= 2.6e-299) {
		tmp = t_1;
	} else if (d4 <= 2.5e-147) {
		tmp = t_0;
	} else if (d4 <= 4.15e+65) {
		tmp = t_1;
	} else if (d4 <= 7e+90) {
		tmp = t_0;
	} else if (d4 <= 1.5e+108) {
		tmp = t_1;
	} else {
		tmp = d1 * (d4 + d2);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d1)
	t_1 = d1 * (d2 - d3)
	tmp = 0
	if d4 <= -1.3e-194:
		tmp = t_0
	elif d4 <= 2.6e-299:
		tmp = t_1
	elif d4 <= 2.5e-147:
		tmp = t_0
	elif d4 <= 4.15e+65:
		tmp = t_1
	elif d4 <= 7e+90:
		tmp = t_0
	elif d4 <= 1.5e+108:
		tmp = t_1
	else:
		tmp = d1 * (d4 + d2)
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d1))
	t_1 = Float64(d1 * Float64(d2 - d3))
	tmp = 0.0
	if (d4 <= -1.3e-194)
		tmp = t_0;
	elseif (d4 <= 2.6e-299)
		tmp = t_1;
	elseif (d4 <= 2.5e-147)
		tmp = t_0;
	elseif (d4 <= 4.15e+65)
		tmp = t_1;
	elseif (d4 <= 7e+90)
		tmp = t_0;
	elseif (d4 <= 1.5e+108)
		tmp = t_1;
	else
		tmp = Float64(d1 * Float64(d4 + d2));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d2 - d1);
	t_1 = d1 * (d2 - d3);
	tmp = 0.0;
	if (d4 <= -1.3e-194)
		tmp = t_0;
	elseif (d4 <= 2.6e-299)
		tmp = t_1;
	elseif (d4 <= 2.5e-147)
		tmp = t_0;
	elseif (d4 <= 4.15e+65)
		tmp = t_1;
	elseif (d4 <= 7e+90)
		tmp = t_0;
	elseif (d4 <= 1.5e+108)
		tmp = t_1;
	else
		tmp = d1 * (d4 + d2);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d4, -1.3e-194], t$95$0, If[LessEqual[d4, 2.6e-299], t$95$1, If[LessEqual[d4, 2.5e-147], t$95$0, If[LessEqual[d4, 4.15e+65], t$95$1, If[LessEqual[d4, 7e+90], t$95$0, If[LessEqual[d4, 1.5e+108], t$95$1, N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d4 \leq 2.6 \cdot 10^{-299}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d4 \leq 2.5 \cdot 10^{-147}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d4 \leq 4.15 \cdot 10^{+65}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d4 \leq 7 \cdot 10^{+90}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d4 \leq 1.5 \cdot 10^{+108}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < -1.30000000000000001e-194 or 2.5999999999999999e-299 < d4 < 2.50000000000000007e-147 or 4.1500000000000002e65 < d4 < 6.9999999999999997e90

    1. Initial program 85.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Add Preprocessing
    3. Taylor expanded in d3 around 0 68.2%

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

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

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

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

        \[\leadsto d1 \cdot d2 - \color{blue}{d1 \cdot d1} \]
      2. distribute-lft-out--59.0%

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

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

    if -1.30000000000000001e-194 < d4 < 2.5999999999999999e-299 or 2.50000000000000007e-147 < d4 < 4.1500000000000002e65 or 6.9999999999999997e90 < d4 < 1.49999999999999992e108

    1. Initial program 93.3%

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

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

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

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

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

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

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

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

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

    if 1.49999999999999992e108 < d4

    1. Initial program 79.5%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -1.3 \cdot 10^{-194}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 2.6 \cdot 10^{-299}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 2.5 \cdot 10^{-147}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 4.15 \cdot 10^{+65}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 7 \cdot 10^{+90}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 1.5 \cdot 10^{+108}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 63.5% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d4 \leq 1.4 \cdot 10^{-305}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d4 \leq 2.2 \cdot 10^{-147}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d4 \leq 2 \cdot 10^{+26}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < -7.4999999999999998e-194 or 1.40000000000000007e-305 < d4 < 2.2000000000000001e-147

    1. Initial program 85.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Add Preprocessing
    3. Taylor expanded in d3 around 0 66.5%

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

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

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

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

        \[\leadsto d1 \cdot d2 - \color{blue}{d1 \cdot d1} \]
      2. distribute-lft-out--57.0%

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

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

    if -7.4999999999999998e-194 < d4 < 1.40000000000000007e-305 or 2.2000000000000001e-147 < d4 < 2.0000000000000001e26

    1. Initial program 91.9%

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

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

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

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

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

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

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

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

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

    if 2.0000000000000001e26 < d4

    1. Initial program 83.6%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot d4 - d1 \cdot d3} \]
      4. distribute-lft-out--79.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -7.5 \cdot 10^{-194}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 1.4 \cdot 10^{-305}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 2.2 \cdot 10^{-147}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 2 \cdot 10^{+26}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 62.9% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d4 \leq -3.8 \cdot 10^{-293}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d4 \leq 4.4 \cdot 10^{+24}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d4 < -1.40000000000000006e-194

    1. Initial program 83.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Add Preprocessing
    3. Taylor expanded in d3 around 0 68.5%

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

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

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

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

        \[\leadsto d1 \cdot d2 - \color{blue}{d1 \cdot d1} \]
      2. distribute-lft-out--56.2%

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

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

    if -1.40000000000000006e-194 < d4 < -3.8e-293 or 1.7000000000000001e-35 < d4 < 4.40000000000000003e24

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

    if -3.8e-293 < d4 < 1.7000000000000001e-35

    1. Initial program 91.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.40000000000000003e24 < d4

    1. Initial program 83.6%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot d4 - d1 \cdot d3} \]
      4. distribute-lft-out--79.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -1.4 \cdot 10^{-194}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq -3.8 \cdot 10^{-293}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 1.7 \cdot 10^{-35}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{elif}\;d4 \leq 4.4 \cdot 10^{+24}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 39.1% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d3 \cdot \left(-d1\right)\\ \mathbf{if}\;d4 \leq -5.2 \cdot 10^{-212}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 9 \cdot 10^{-14}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d4 \leq 2.65 \cdot 10^{+23}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 8.5 \cdot 10^{+107}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d3 (- d1))))
   (if (<= d4 -5.2e-212)
     (* d1 d2)
     (if (<= d4 9e-14)
       t_0
       (if (<= d4 2.65e+23) (* d1 d2) (if (<= d4 8.5e+107) t_0 (* d1 d4)))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d3 * -d1;
	double tmp;
	if (d4 <= -5.2e-212) {
		tmp = d1 * d2;
	} else if (d4 <= 9e-14) {
		tmp = t_0;
	} else if (d4 <= 2.65e+23) {
		tmp = d1 * d2;
	} else if (d4 <= 8.5e+107) {
		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 = d3 * -d1
    if (d4 <= (-5.2d-212)) then
        tmp = d1 * d2
    else if (d4 <= 9d-14) then
        tmp = t_0
    else if (d4 <= 2.65d+23) then
        tmp = d1 * d2
    else if (d4 <= 8.5d+107) 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 = d3 * -d1;
	double tmp;
	if (d4 <= -5.2e-212) {
		tmp = d1 * d2;
	} else if (d4 <= 9e-14) {
		tmp = t_0;
	} else if (d4 <= 2.65e+23) {
		tmp = d1 * d2;
	} else if (d4 <= 8.5e+107) {
		tmp = t_0;
	} else {
		tmp = d1 * d4;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d3 * -d1
	tmp = 0
	if d4 <= -5.2e-212:
		tmp = d1 * d2
	elif d4 <= 9e-14:
		tmp = t_0
	elif d4 <= 2.65e+23:
		tmp = d1 * d2
	elif d4 <= 8.5e+107:
		tmp = t_0
	else:
		tmp = d1 * d4
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d3 * Float64(-d1))
	tmp = 0.0
	if (d4 <= -5.2e-212)
		tmp = Float64(d1 * d2);
	elseif (d4 <= 9e-14)
		tmp = t_0;
	elseif (d4 <= 2.65e+23)
		tmp = Float64(d1 * d2);
	elseif (d4 <= 8.5e+107)
		tmp = t_0;
	else
		tmp = Float64(d1 * d4);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d3 * -d1;
	tmp = 0.0;
	if (d4 <= -5.2e-212)
		tmp = d1 * d2;
	elseif (d4 <= 9e-14)
		tmp = t_0;
	elseif (d4 <= 2.65e+23)
		tmp = d1 * d2;
	elseif (d4 <= 8.5e+107)
		tmp = t_0;
	else
		tmp = d1 * d4;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d3 * (-d1)), $MachinePrecision]}, If[LessEqual[d4, -5.2e-212], N[(d1 * d2), $MachinePrecision], If[LessEqual[d4, 9e-14], t$95$0, If[LessEqual[d4, 2.65e+23], N[(d1 * d2), $MachinePrecision], If[LessEqual[d4, 8.5e+107], t$95$0, N[(d1 * d4), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d4 \leq 9 \cdot 10^{-14}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d4 \leq 2.65 \cdot 10^{+23}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d4 \leq 8.5 \cdot 10^{+107}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < -5.2e-212 or 8.9999999999999995e-14 < d4 < 2.6500000000000001e23

    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. +-commutative84.2%

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

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

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

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

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

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

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

    if -5.2e-212 < d4 < 8.9999999999999995e-14 or 2.6500000000000001e23 < d4 < 8.4999999999999999e107

    1. Initial program 92.9%

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

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

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

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

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

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

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

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

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

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

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

    if 8.4999999999999999e107 < d4

    1. Initial program 79.5%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -5.2 \cdot 10^{-212}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 9 \cdot 10^{-14}:\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 2.65 \cdot 10^{+23}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 8.5 \cdot 10^{+107}:\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 62.8% accurate, 0.7× speedup?

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

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

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

\mathbf{elif}\;d4 \leq 5.6 \cdot 10^{+104}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 1.3e-73 or 4.39999999999999987e-45 < d4 < 5.6e104

    1. Initial program 87.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Add Preprocessing
    3. Taylor expanded in d3 around 0 67.5%

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

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

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

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

        \[\leadsto d1 \cdot d2 - \color{blue}{d1 \cdot d1} \]
      2. distribute-lft-out--60.8%

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

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

    if 1.3e-73 < d4 < 4.39999999999999987e-45

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

    if 5.6e104 < d4

    1. Initial program 80.4%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 1.3 \cdot 10^{-73}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 4.4 \cdot 10^{-45}:\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 5.6 \cdot 10^{+104}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 87.4% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -2 \cdot 10^{+188} \lor \neg \left(d3 \leq 9 \cdot 10^{+74}\right):\\
\;\;\;\;d1 \cdot \left(d4 - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -2e188 or 8.9999999999999999e74 < d3

    1. Initial program 91.5%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot d4 - d1 \cdot d3} \]
      4. distribute-lft-out--81.3%

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

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

    if -2e188 < d3 < 8.9999999999999999e74

    1. Initial program 84.9%

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

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

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

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

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

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

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

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

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

Alternative 9: 92.2% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -1.15 \cdot 10^{+71} \lor \neg \left(d1 \leq 1.7 \cdot 10^{+23}\right):\\
\;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -1.1500000000000001e71 or 1.69999999999999996e23 < d1

    1. Initial program 68.5%

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

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

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

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

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

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

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

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

    if -1.1500000000000001e71 < d1 < 1.69999999999999996e23

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

Alternative 10: 66.7% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -1.85 \cdot 10^{+188} \lor \neg \left(d3 \leq 8 \cdot 10^{+98}\right):\\
\;\;\;\;d3 \cdot \left(-d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -1.85e188 or 7.99999999999999998e98 < d3

    1. Initial program 89.6%

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

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

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

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

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

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

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

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

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

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

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

    if -1.85e188 < d3 < 7.99999999999999998e98

    1. Initial program 85.7%

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

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

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

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

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

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

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

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

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

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

Alternative 11: 39.8% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 87.7%

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

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

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

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

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

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

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

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

    if 4.8e37 < d4

    1. Initial program 83.3%

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

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

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

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

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

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

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

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

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

Alternative 12: 31.6% 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 86.7%

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

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

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

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

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

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

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

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

    \[\leadsto d1 \cdot d2 \]
  7. Add Preprocessing

Developer target: 100.0% accurate, 1.7× speedup?

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

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

Reproduce

?
herbie shell --seed 2024079 
(FPCore (d1 d2 d3 d4)
  :name "FastMath dist4"
  :precision binary64

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

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