FastMath dist4

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

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 87.8% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.7× speedup?

\[\begin{array}{l} \\ d1 \cdot \left(\left(d4 + \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 84.4%

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

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

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

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

Alternative 2: 61.9% accurate, 0.6× speedup?

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

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

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

\mathbf{elif}\;d2 \leq -2.4 \cdot 10^{-97} \lor \neg \left(d2 \leq 1.2 \cdot 10^{-284}\right):\\
\;\;\;\;d1 \cdot \left(d4 - d1\right)\\

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


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

    1. Initial program 74.1%

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

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

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

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

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

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

    if -8.2000000000000003e198 < d2 < -4.1000000000000001e-11

    1. Initial program 75.5%

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

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

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

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

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

    if -4.1000000000000001e-11 < d2 < -2.4e-97 or 1.20000000000000001e-284 < d2

    1. Initial program 86.5%

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

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

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

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

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

    if -2.4e-97 < d2 < 1.20000000000000001e-284

    1. Initial program 95.3%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -8.2 \cdot 10^{+198}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d2 \leq -4.1 \cdot 10^{-11}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d2 \leq -2.4 \cdot 10^{-97} \lor \neg \left(d2 \leq 1.2 \cdot 10^{-284}\right):\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 62.0% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;d4 \leq 51000000000000:\\
\;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\

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

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


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

    1. Initial program 88.0%

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

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

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

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

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

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

    if 4.80000000000000041e-214 < d4 < 5.1e13

    1. Initial program 86.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.1e13 < d4 < 1.5000000000000001e131

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

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

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

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

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

    if 1.5000000000000001e131 < d4

    1. Initial program 68.2%

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

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

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

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

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

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

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

Alternative 4: 40.2% accurate, 0.8× speedup?

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

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

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

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

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


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

    1. Initial program 88.0%

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

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

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

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

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

    if 2.8999999999999999e-213 < d4 < 1.4499999999999999e-64

    1. Initial program 81.0%

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

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

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

        \[\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 d1 around inf 75.9%

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

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

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

    if 1.4499999999999999e-64 < d4 < 1.2500000000000001e75

    1. Initial program 88.6%

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

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

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

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

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

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

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

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

    if 1.2500000000000001e75 < d4

    1. Initial program 72.0%

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

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

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

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

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

Alternative 5: 86.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -2.3 \cdot 10^{+231} \lor \neg \left(d3 \leq 6.5 \cdot 10^{+189}\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 -2.3e+231) (not (<= d3 6.5e+189)))
   (* d1 (- d4 d3))
   (* d1 (- (+ d4 d2) d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -2.3e+231) || !(d3 <= 6.5e+189)) {
		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 <= (-2.3d+231)) .or. (.not. (d3 <= 6.5d+189))) 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 <= -2.3e+231) || !(d3 <= 6.5e+189)) {
		tmp = d1 * (d4 - d3);
	} else {
		tmp = d1 * ((d4 + d2) - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if (d3 <= -2.3e+231) or not (d3 <= 6.5e+189):
		tmp = d1 * (d4 - d3)
	else:
		tmp = d1 * ((d4 + d2) - d1)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d3 <= -2.3e+231) || !(d3 <= 6.5e+189))
		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 <= -2.3e+231) || ~((d3 <= 6.5e+189)))
		tmp = d1 * (d4 - d3);
	else
		tmp = d1 * ((d4 + d2) - d1);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -2.3e+231], N[Not[LessEqual[d3, 6.5e+189]], $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.3 \cdot 10^{+231} \lor \neg \left(d3 \leq 6.5 \cdot 10^{+189}\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 < -2.29999999999999999e231 or 6.50000000000000027e189 < d3

    1. Initial program 88.6%

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

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

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

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

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

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

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

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

    if -2.29999999999999999e231 < d3 < 6.50000000000000027e189

    1. Initial program 83.7%

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

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

        \[\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-out86.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 89.4%

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

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

Alternative 6: 67.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -5.1 \cdot 10^{+127} \lor \neg \left(d1 \leq 1.4 \cdot 10^{+161}\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 < -5.10000000000000038e127 or 1.4000000000000001e161 < d1

    1. Initial program 54.3%

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

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

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

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

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

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

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

    if -5.10000000000000038e127 < d1 < 1.4000000000000001e161

    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-out99.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 74.7%

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

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

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

Alternative 7: 61.9% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 74.1%

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

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

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

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

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

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

    if -3.90000000000000016e194 < d2 < -4.6000000000000002e-8

    1. Initial program 76.9%

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

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

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

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

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

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

    if -4.6000000000000002e-8 < d2

    1. Initial program 88.1%

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

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

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

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

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

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

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

Alternative 8: 40.0% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 88.0%

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

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

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

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

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

    if 2.4000000000000002e-214 < d4 < 8.0000000000000001e86

    1. Initial program 86.0%

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

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

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

        \[\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 d1 around inf 45.5%

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

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

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

    if 8.0000000000000001e86 < d4

    1. Initial program 71.4%

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

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

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

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

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

Alternative 9: 83.6% accurate, 1.2× speedup?

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

    1. Initial program 75.9%

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

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

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

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

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

    if -4.10000000000000032e-8 < d2

    1. Initial program 88.1%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -4.1 \cdot 10^{-8}:\\ \;\;\;\;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 10: 62.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 2100000000:\\ \;\;\;\;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 2100000000.0) (* d1 (- d2 d1)) (* d1 (+ d4 d2))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d4 <= 2100000000.0) {
		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 <= 2100000000.0d0) 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 <= 2100000000.0) {
		tmp = d1 * (d2 - d1);
	} else {
		tmp = d1 * (d4 + d2);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d4 <= 2100000000.0:
		tmp = d1 * (d2 - d1)
	else:
		tmp = d1 * (d4 + d2)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d4 <= 2100000000.0)
		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 <= 2100000000.0)
		tmp = d1 * (d2 - d1);
	else
		tmp = d1 * (d4 + d2);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 2100000000.0], N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 2100000000:\\
\;\;\;\;d1 \cdot \left(d2 - d1\right)\\

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


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

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

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

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

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

    if 2.1e9 < d4

    1. Initial program 75.4%

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

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

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

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

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

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

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

Alternative 11: 40.4% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 87.4%

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

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

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

    if 1.4999999999999999e77 < d4

    1. Initial program 71.4%

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

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

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

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

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

Alternative 12: 20.0% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -4.1 \cdot 10^{-187}:\\
\;\;\;\;d1 \cdot d2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d2 < -4.1000000000000002e-187

    1. Initial program 81.4%

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

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

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

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

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

    if -4.1000000000000002e-187 < d2

    1. Initial program 87.0%

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

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

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

        \[\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 d3 around inf 30.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{{\left(d1 \cdot d3\right)}^{1}} \]
    9. Applied egg-rr9.7%

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

        \[\leadsto \color{blue}{d1 \cdot d3} \]
    11. Simplified9.7%

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

Alternative 13: 32.0% accurate, 5.0× speedup?

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

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

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

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

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

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

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

Alternative 14: 7.6% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto d1 \cdot \color{blue}{\left(0 - d1\right)} \]
    2. sub-neg34.7%

      \[\leadsto d1 \cdot \color{blue}{\left(0 + \left(-d1\right)\right)} \]
    3. add-sqr-sqrt17.9%

      \[\leadsto d1 \cdot \left(0 + \color{blue}{\sqrt{-d1} \cdot \sqrt{-d1}}\right) \]
    4. sqrt-unprod21.4%

      \[\leadsto d1 \cdot \left(0 + \color{blue}{\sqrt{\left(-d1\right) \cdot \left(-d1\right)}}\right) \]
    5. sqr-neg21.4%

      \[\leadsto d1 \cdot \left(0 + \sqrt{\color{blue}{d1 \cdot d1}}\right) \]
    6. sqrt-unprod3.4%

      \[\leadsto d1 \cdot \left(0 + \color{blue}{\sqrt{d1} \cdot \sqrt{d1}}\right) \]
    7. add-sqr-sqrt8.8%

      \[\leadsto d1 \cdot \left(0 + \color{blue}{d1}\right) \]
  9. Applied egg-rr8.8%

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

      \[\leadsto d1 \cdot \color{blue}{d1} \]
  11. Simplified8.8%

    \[\leadsto d1 \cdot \color{blue}{d1} \]
  12. 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 2024172 
(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)))