FastMath dist4

Percentage Accurate: 87.7% → 100.0%
Time: 7.8s
Alternatives: 11
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 11 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.7% 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--88.3%

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

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

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

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

Alternative 2: 92.7% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -7 \cdot 10^{+101} \lor \neg \left(d3 \leq 5.8 \cdot 10^{+110}\right):\\
\;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - 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 < -7.00000000000000046e101 or 5.7999999999999999e110 < d3

    1. Initial program 80.5%

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

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

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

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

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

    if -7.00000000000000046e101 < d3 < 5.7999999999999999e110

    1. Initial program 89.4%

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

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

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

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

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

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

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

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

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

Alternative 3: 88.7% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -1.05 \cdot 10^{+147} \lor \neg \left(d3 \leq 8.5 \cdot 10^{+111}\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 -1.05e+147) (not (<= d3 8.5e+111)))
   (* d1 (- d4 d3))
   (* d1 (- (+ d4 d2) d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -1.05e+147) || !(d3 <= 8.5e+111)) {
		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 <= (-1.05d+147)) .or. (.not. (d3 <= 8.5d+111))) 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 <= -1.05e+147) || !(d3 <= 8.5e+111)) {
		tmp = d1 * (d4 - d3);
	} else {
		tmp = d1 * ((d4 + d2) - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if (d3 <= -1.05e+147) or not (d3 <= 8.5e+111):
		tmp = d1 * (d4 - d3)
	else:
		tmp = d1 * ((d4 + d2) - d1)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d3 <= -1.05e+147) || !(d3 <= 8.5e+111))
		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 <= -1.05e+147) || ~((d3 <= 8.5e+111)))
		tmp = d1 * (d4 - d3);
	else
		tmp = d1 * ((d4 + d2) - d1);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -1.05e+147], N[Not[LessEqual[d3, 8.5e+111]], $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 -1.05 \cdot 10^{+147} \lor \neg \left(d3 \leq 8.5 \cdot 10^{+111}\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 < -1.05000000000000003e147 or 8.49999999999999983e111 < d3

    1. Initial program 80.6%

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

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

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

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

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

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

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

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

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

    if -1.05000000000000003e147 < d3 < 8.49999999999999983e111

    1. Initial program 88.9%

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

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

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

        \[\leadsto \left(d1 \cdot d4 + \color{blue}{d1 \cdot \left(d2 - d3\right)}\right) - d1 \cdot d1 \]
      4. distribute-lft-out89.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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.8%

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

Alternative 4: 65.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -4.8 \cdot 10^{+141} \lor \neg \left(d1 \leq 1.05 \cdot 10^{+121}\right):\\
\;\;\;\;d1 \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 d1 < -4.79999999999999995e141 or 1.0500000000000001e121 < d1

    1. Initial program 60.8%

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

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

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

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

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

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

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

    if -4.79999999999999995e141 < d1 < 1.0500000000000001e121

    1. Initial program 98.3%

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

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

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

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

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

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

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

Alternative 5: 38.6% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 87.6%

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

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

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

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

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

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

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

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

    if 3.2e-275 < d4 < 1.45000000000000013e89

    1. Initial program 87.5%

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

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

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

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

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

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

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

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

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

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

    if 1.45000000000000013e89 < d4

    1. Initial program 82.9%

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

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

        \[\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 d4 around inf 73.5%

      \[\leadsto \color{blue}{d1 \cdot d4} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 84.9% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 76.3%

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

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

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

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

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

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

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

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

    if -1.50000000000000001e66 < d2

    1. Initial program 89.5%

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

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

        \[\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-out92.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 d2 around 0 82.9%

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

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

Alternative 7: 61.4% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 87.5%

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

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

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

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

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

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

    if 1.0499999999999999e86 < 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--85.4%

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

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

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

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

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

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

Alternative 8: 61.2% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 87.6%

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

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

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

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

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

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

    if 1.8e89 < d4

    1. Initial program 82.9%

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

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

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

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

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

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

Alternative 9: 38.4% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 88.5%

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

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

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

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

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

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

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

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

    if 1.5999999999999999e34 < d4

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

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

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

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

Alternative 10: 30.2% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -3.4 \cdot 10^{+230}:\\
\;\;\;\;d1 \cdot d3\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -3.39999999999999986e230

    1. Initial program 36.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{d1 \cdot d1}} \cdot d3 \]
      4. sqrt-unprod0.0%

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

        \[\leadsto \color{blue}{d1} \cdot d3 \]
      6. pow129.6%

        \[\leadsto \color{blue}{{\left(d1 \cdot d3\right)}^{1}} \]
    10. Applied egg-rr29.6%

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

        \[\leadsto \color{blue}{d1 \cdot d3} \]
    12. Simplified29.6%

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

    if -3.39999999999999986e230 < d1

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot d2} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 11: 30.5% 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--88.3%

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

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

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

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

    \[\leadsto \color{blue}{d1 \cdot d2} \]
  6. Add Preprocessing

Developer Target 1: 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 2024185 
(FPCore (d1 d2 d3 d4)
  :name "FastMath dist4"
  :precision binary64

  :alt
  (! :herbie-platform default (* d1 (- (+ (- d2 d3) d4) d1)))

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