FastMath dist3

Percentage Accurate: 98.0% → 100.0%
Time: 4.6s
Alternatives: 6
Speedup: 1.9×

Specification

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

\\
\left(d1 \cdot d2 + \left(d3 + 5\right) \cdot d1\right) + d1 \cdot 32
\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 6 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: 98.0% accurate, 1.0× speedup?

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

\\
\left(d1 \cdot d2 + \left(d3 + 5\right) \cdot d1\right) + d1 \cdot 32
\end{array}

Alternative 1: 100.0% accurate, 1.9× speedup?

\[\begin{array}{l} [d1, d2, d3] = \mathsf{sort}([d1, d2, d3])\\ \\ d1 \cdot \left(d2 + \left(d3 + 37\right)\right) \end{array} \]
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3) :precision binary64 (* d1 (+ d2 (+ d3 37.0))))
assert(d1 < d2 && d2 < d3);
double code(double d1, double d2, double d3) {
	return d1 * (d2 + (d3 + 37.0));
}
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
real(8) function code(d1, d2, d3)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    code = d1 * (d2 + (d3 + 37.0d0))
end function
assert d1 < d2 && d2 < d3;
public static double code(double d1, double d2, double d3) {
	return d1 * (d2 + (d3 + 37.0));
}
[d1, d2, d3] = sort([d1, d2, d3])
def code(d1, d2, d3):
	return d1 * (d2 + (d3 + 37.0))
d1, d2, d3 = sort([d1, d2, d3])
function code(d1, d2, d3)
	return Float64(d1 * Float64(d2 + Float64(d3 + 37.0)))
end
d1, d2, d3 = num2cell(sort([d1, d2, d3])){:}
function tmp = code(d1, d2, d3)
	tmp = d1 * (d2 + (d3 + 37.0));
end
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_] := N[(d1 * N[(d2 + N[(d3 + 37.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[d1, d2, d3] = \mathsf{sort}([d1, d2, d3])\\
\\
d1 \cdot \left(d2 + \left(d3 + 37\right)\right)
\end{array}
Derivation
  1. Initial program 98.4%

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

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

      \[\leadsto d1 \cdot d2 + \left(\left(d3 + 5\right) \cdot d1 + \color{blue}{32 \cdot d1}\right) \]
    3. distribute-rgt-out98.4%

      \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot \left(\left(d3 + 5\right) + 32\right)} \]
    4. remove-double-neg98.4%

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

      \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right) \cdot \left(\left(d3 + 5\right) + 32\right)\right)} \]
    6. distribute-rgt-neg-in98.4%

      \[\leadsto d1 \cdot d2 + \color{blue}{\left(-d1\right) \cdot \left(-\left(\left(d3 + 5\right) + 32\right)\right)} \]
    7. cancel-sign-sub-inv98.4%

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

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

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

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

      \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d3 + \left(5 + 32\right)\right)}\right) \]
    12. metadata-eval100.0%

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

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

Alternative 2: 73.7% accurate, 0.7× speedup?

\[\begin{array}{l} [d1, d2, d3] = \mathsf{sort}([d1, d2, d3])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -132000000000:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -7 \cdot 10^{-23} \lor \neg \left(d2 \leq 1.25 \cdot 10^{-265}\right):\\ \;\;\;\;d1 \cdot d3\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot 37\\ \end{array} \end{array} \]
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3)
 :precision binary64
 (if (<= d2 -132000000000.0)
   (* d1 d2)
   (if (or (<= d2 -7e-23) (not (<= d2 1.25e-265))) (* d1 d3) (* d1 37.0))))
assert(d1 < d2 && d2 < d3);
double code(double d1, double d2, double d3) {
	double tmp;
	if (d2 <= -132000000000.0) {
		tmp = d1 * d2;
	} else if ((d2 <= -7e-23) || !(d2 <= 1.25e-265)) {
		tmp = d1 * d3;
	} else {
		tmp = d1 * 37.0;
	}
	return tmp;
}
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
real(8) function code(d1, d2, d3)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8) :: tmp
    if (d2 <= (-132000000000.0d0)) then
        tmp = d1 * d2
    else if ((d2 <= (-7d-23)) .or. (.not. (d2 <= 1.25d-265))) then
        tmp = d1 * d3
    else
        tmp = d1 * 37.0d0
    end if
    code = tmp
end function
assert d1 < d2 && d2 < d3;
public static double code(double d1, double d2, double d3) {
	double tmp;
	if (d2 <= -132000000000.0) {
		tmp = d1 * d2;
	} else if ((d2 <= -7e-23) || !(d2 <= 1.25e-265)) {
		tmp = d1 * d3;
	} else {
		tmp = d1 * 37.0;
	}
	return tmp;
}
[d1, d2, d3] = sort([d1, d2, d3])
def code(d1, d2, d3):
	tmp = 0
	if d2 <= -132000000000.0:
		tmp = d1 * d2
	elif (d2 <= -7e-23) or not (d2 <= 1.25e-265):
		tmp = d1 * d3
	else:
		tmp = d1 * 37.0
	return tmp
d1, d2, d3 = sort([d1, d2, d3])
function code(d1, d2, d3)
	tmp = 0.0
	if (d2 <= -132000000000.0)
		tmp = Float64(d1 * d2);
	elseif ((d2 <= -7e-23) || !(d2 <= 1.25e-265))
		tmp = Float64(d1 * d3);
	else
		tmp = Float64(d1 * 37.0);
	end
	return tmp
end
d1, d2, d3 = num2cell(sort([d1, d2, d3])){:}
function tmp_2 = code(d1, d2, d3)
	tmp = 0.0;
	if (d2 <= -132000000000.0)
		tmp = d1 * d2;
	elseif ((d2 <= -7e-23) || ~((d2 <= 1.25e-265)))
		tmp = d1 * d3;
	else
		tmp = d1 * 37.0;
	end
	tmp_2 = tmp;
end
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_] := If[LessEqual[d2, -132000000000.0], N[(d1 * d2), $MachinePrecision], If[Or[LessEqual[d2, -7e-23], N[Not[LessEqual[d2, 1.25e-265]], $MachinePrecision]], N[(d1 * d3), $MachinePrecision], N[(d1 * 37.0), $MachinePrecision]]]
\begin{array}{l}
[d1, d2, d3] = \mathsf{sort}([d1, d2, d3])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -132000000000:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d2 \leq -7 \cdot 10^{-23} \lor \neg \left(d2 \leq 1.25 \cdot 10^{-265}\right):\\
\;\;\;\;d1 \cdot d3\\

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


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

    1. Initial program 96.7%

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

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

        \[\leadsto d1 \cdot d2 + \left(\left(d3 + 5\right) \cdot d1 + \color{blue}{32 \cdot d1}\right) \]
      3. distribute-rgt-out96.7%

        \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot \left(\left(d3 + 5\right) + 32\right)} \]
      4. remove-double-neg96.7%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right)\right)} \cdot \left(\left(d3 + 5\right) + 32\right) \]
      5. distribute-lft-neg-in96.7%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right) \cdot \left(\left(d3 + 5\right) + 32\right)\right)} \]
      6. distribute-rgt-neg-in96.7%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-d1\right) \cdot \left(-\left(\left(d3 + 5\right) + 32\right)\right)} \]
      7. cancel-sign-sub-inv96.7%

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d3 + \left(5 + 32\right)\right)}\right) \]
      12. metadata-eval100.0%

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

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

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

    if -1.32e11 < d2 < -6.99999999999999987e-23 or 1.25e-265 < d2

    1. Initial program 98.4%

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

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

        \[\leadsto d1 \cdot d2 + \left(\left(d3 + 5\right) \cdot d1 + \color{blue}{32 \cdot d1}\right) \]
      3. distribute-rgt-out98.4%

        \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot \left(\left(d3 + 5\right) + 32\right)} \]
      4. remove-double-neg98.4%

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

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right) \cdot \left(\left(d3 + 5\right) + 32\right)\right)} \]
      6. distribute-rgt-neg-in98.4%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-d1\right) \cdot \left(-\left(\left(d3 + 5\right) + 32\right)\right)} \]
      7. cancel-sign-sub-inv98.4%

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d3 + \left(5 + 32\right)\right)}\right) \]
      12. metadata-eval100.0%

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

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

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

    if -6.99999999999999987e-23 < d2 < 1.25e-265

    1. Initial program 100.0%

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

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

        \[\leadsto d1 \cdot d2 + \left(\left(d3 + 5\right) \cdot d1 + \color{blue}{32 \cdot d1}\right) \]
      3. distribute-rgt-out100.0%

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

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right)\right)} \cdot \left(\left(d3 + 5\right) + 32\right) \]
      5. distribute-lft-neg-in100.0%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right) \cdot \left(\left(d3 + 5\right) + 32\right)\right)} \]
      6. distribute-rgt-neg-in100.0%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-d1\right) \cdot \left(-\left(\left(d3 + 5\right) + 32\right)\right)} \]
      7. cancel-sign-sub-inv100.0%

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d3 + \left(5 + 32\right)\right)}\right) \]
      12. metadata-eval100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -132000000000:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -7 \cdot 10^{-23} \lor \neg \left(d2 \leq 1.25 \cdot 10^{-265}\right):\\ \;\;\;\;d1 \cdot d3\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot 37\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 93.0% accurate, 1.3× speedup?

\[\begin{array}{l} [d1, d2, d3] = \mathsf{sort}([d1, d2, d3])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -0.000135:\\ \;\;\;\;d1 \cdot \left(d2 + 37\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d3 + 37\right)\\ \end{array} \end{array} \]
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3)
 :precision binary64
 (if (<= d2 -0.000135) (* d1 (+ d2 37.0)) (* d1 (+ d3 37.0))))
assert(d1 < d2 && d2 < d3);
double code(double d1, double d2, double d3) {
	double tmp;
	if (d2 <= -0.000135) {
		tmp = d1 * (d2 + 37.0);
	} else {
		tmp = d1 * (d3 + 37.0);
	}
	return tmp;
}
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
real(8) function code(d1, d2, d3)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8) :: tmp
    if (d2 <= (-0.000135d0)) then
        tmp = d1 * (d2 + 37.0d0)
    else
        tmp = d1 * (d3 + 37.0d0)
    end if
    code = tmp
end function
assert d1 < d2 && d2 < d3;
public static double code(double d1, double d2, double d3) {
	double tmp;
	if (d2 <= -0.000135) {
		tmp = d1 * (d2 + 37.0);
	} else {
		tmp = d1 * (d3 + 37.0);
	}
	return tmp;
}
[d1, d2, d3] = sort([d1, d2, d3])
def code(d1, d2, d3):
	tmp = 0
	if d2 <= -0.000135:
		tmp = d1 * (d2 + 37.0)
	else:
		tmp = d1 * (d3 + 37.0)
	return tmp
d1, d2, d3 = sort([d1, d2, d3])
function code(d1, d2, d3)
	tmp = 0.0
	if (d2 <= -0.000135)
		tmp = Float64(d1 * Float64(d2 + 37.0));
	else
		tmp = Float64(d1 * Float64(d3 + 37.0));
	end
	return tmp
end
d1, d2, d3 = num2cell(sort([d1, d2, d3])){:}
function tmp_2 = code(d1, d2, d3)
	tmp = 0.0;
	if (d2 <= -0.000135)
		tmp = d1 * (d2 + 37.0);
	else
		tmp = d1 * (d3 + 37.0);
	end
	tmp_2 = tmp;
end
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_] := If[LessEqual[d2, -0.000135], N[(d1 * N[(d2 + 37.0), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d3 + 37.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3] = \mathsf{sort}([d1, d2, d3])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -0.000135:\\
\;\;\;\;d1 \cdot \left(d2 + 37\right)\\

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


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

    1. Initial program 96.9%

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

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

        \[\leadsto d1 \cdot d2 + \left(\left(d3 + 5\right) \cdot d1 + \color{blue}{32 \cdot d1}\right) \]
      3. distribute-rgt-out96.9%

        \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot \left(\left(d3 + 5\right) + 32\right)} \]
      4. remove-double-neg96.9%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right)\right)} \cdot \left(\left(d3 + 5\right) + 32\right) \]
      5. distribute-lft-neg-in96.9%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right) \cdot \left(\left(d3 + 5\right) + 32\right)\right)} \]
      6. distribute-rgt-neg-in96.9%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-d1\right) \cdot \left(-\left(\left(d3 + 5\right) + 32\right)\right)} \]
      7. cancel-sign-sub-inv96.9%

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d3 + \left(5 + 32\right)\right)}\right) \]
      12. metadata-eval100.0%

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

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

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

    if -1.35000000000000002e-4 < d2

    1. Initial program 98.9%

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

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

        \[\leadsto d1 \cdot d2 + \left(\left(d3 + 5\right) \cdot d1 + \color{blue}{32 \cdot d1}\right) \]
      3. distribute-rgt-out98.9%

        \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot \left(\left(d3 + 5\right) + 32\right)} \]
      4. remove-double-neg98.9%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right)\right)} \cdot \left(\left(d3 + 5\right) + 32\right) \]
      5. distribute-lft-neg-in98.9%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right) \cdot \left(\left(d3 + 5\right) + 32\right)\right)} \]
      6. distribute-rgt-neg-in98.9%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-d1\right) \cdot \left(-\left(\left(d3 + 5\right) + 32\right)\right)} \]
      7. cancel-sign-sub-inv98.9%

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d3 + \left(5 + 32\right)\right)}\right) \]
      12. metadata-eval100.0%

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

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

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

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

Alternative 4: 92.4% accurate, 1.3× speedup?

\[\begin{array}{l} [d1, d2, d3] = \mathsf{sort}([d1, d2, d3])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -290000000000:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d3 + 37\right)\\ \end{array} \end{array} \]
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3)
 :precision binary64
 (if (<= d2 -290000000000.0) (* d1 d2) (* d1 (+ d3 37.0))))
assert(d1 < d2 && d2 < d3);
double code(double d1, double d2, double d3) {
	double tmp;
	if (d2 <= -290000000000.0) {
		tmp = d1 * d2;
	} else {
		tmp = d1 * (d3 + 37.0);
	}
	return tmp;
}
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
real(8) function code(d1, d2, d3)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8) :: tmp
    if (d2 <= (-290000000000.0d0)) then
        tmp = d1 * d2
    else
        tmp = d1 * (d3 + 37.0d0)
    end if
    code = tmp
end function
assert d1 < d2 && d2 < d3;
public static double code(double d1, double d2, double d3) {
	double tmp;
	if (d2 <= -290000000000.0) {
		tmp = d1 * d2;
	} else {
		tmp = d1 * (d3 + 37.0);
	}
	return tmp;
}
[d1, d2, d3] = sort([d1, d2, d3])
def code(d1, d2, d3):
	tmp = 0
	if d2 <= -290000000000.0:
		tmp = d1 * d2
	else:
		tmp = d1 * (d3 + 37.0)
	return tmp
d1, d2, d3 = sort([d1, d2, d3])
function code(d1, d2, d3)
	tmp = 0.0
	if (d2 <= -290000000000.0)
		tmp = Float64(d1 * d2);
	else
		tmp = Float64(d1 * Float64(d3 + 37.0));
	end
	return tmp
end
d1, d2, d3 = num2cell(sort([d1, d2, d3])){:}
function tmp_2 = code(d1, d2, d3)
	tmp = 0.0;
	if (d2 <= -290000000000.0)
		tmp = d1 * d2;
	else
		tmp = d1 * (d3 + 37.0);
	end
	tmp_2 = tmp;
end
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_] := If[LessEqual[d2, -290000000000.0], N[(d1 * d2), $MachinePrecision], N[(d1 * N[(d3 + 37.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3] = \mathsf{sort}([d1, d2, d3])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -290000000000:\\
\;\;\;\;d1 \cdot d2\\

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


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

    1. Initial program 96.7%

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

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

        \[\leadsto d1 \cdot d2 + \left(\left(d3 + 5\right) \cdot d1 + \color{blue}{32 \cdot d1}\right) \]
      3. distribute-rgt-out96.7%

        \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot \left(\left(d3 + 5\right) + 32\right)} \]
      4. remove-double-neg96.7%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right)\right)} \cdot \left(\left(d3 + 5\right) + 32\right) \]
      5. distribute-lft-neg-in96.7%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right) \cdot \left(\left(d3 + 5\right) + 32\right)\right)} \]
      6. distribute-rgt-neg-in96.7%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-d1\right) \cdot \left(-\left(\left(d3 + 5\right) + 32\right)\right)} \]
      7. cancel-sign-sub-inv96.7%

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d3 + \left(5 + 32\right)\right)}\right) \]
      12. metadata-eval100.0%

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

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

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

    if -2.9e11 < d2

    1. Initial program 98.9%

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

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

        \[\leadsto d1 \cdot d2 + \left(\left(d3 + 5\right) \cdot d1 + \color{blue}{32 \cdot d1}\right) \]
      3. distribute-rgt-out99.0%

        \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot \left(\left(d3 + 5\right) + 32\right)} \]
      4. remove-double-neg99.0%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right)\right)} \cdot \left(\left(d3 + 5\right) + 32\right) \]
      5. distribute-lft-neg-in99.0%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right) \cdot \left(\left(d3 + 5\right) + 32\right)\right)} \]
      6. distribute-rgt-neg-in99.0%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-d1\right) \cdot \left(-\left(\left(d3 + 5\right) + 32\right)\right)} \]
      7. cancel-sign-sub-inv99.0%

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d3 + \left(5 + 32\right)\right)}\right) \]
      12. metadata-eval100.0%

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

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

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

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

Alternative 5: 62.3% accurate, 1.6× speedup?

\[\begin{array}{l} [d1, d2, d3] = \mathsf{sort}([d1, d2, d3])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -37:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot 37\\ \end{array} \end{array} \]
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3)
 :precision binary64
 (if (<= d2 -37.0) (* d1 d2) (* d1 37.0)))
assert(d1 < d2 && d2 < d3);
double code(double d1, double d2, double d3) {
	double tmp;
	if (d2 <= -37.0) {
		tmp = d1 * d2;
	} else {
		tmp = d1 * 37.0;
	}
	return tmp;
}
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
real(8) function code(d1, d2, d3)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8) :: tmp
    if (d2 <= (-37.0d0)) then
        tmp = d1 * d2
    else
        tmp = d1 * 37.0d0
    end if
    code = tmp
end function
assert d1 < d2 && d2 < d3;
public static double code(double d1, double d2, double d3) {
	double tmp;
	if (d2 <= -37.0) {
		tmp = d1 * d2;
	} else {
		tmp = d1 * 37.0;
	}
	return tmp;
}
[d1, d2, d3] = sort([d1, d2, d3])
def code(d1, d2, d3):
	tmp = 0
	if d2 <= -37.0:
		tmp = d1 * d2
	else:
		tmp = d1 * 37.0
	return tmp
d1, d2, d3 = sort([d1, d2, d3])
function code(d1, d2, d3)
	tmp = 0.0
	if (d2 <= -37.0)
		tmp = Float64(d1 * d2);
	else
		tmp = Float64(d1 * 37.0);
	end
	return tmp
end
d1, d2, d3 = num2cell(sort([d1, d2, d3])){:}
function tmp_2 = code(d1, d2, d3)
	tmp = 0.0;
	if (d2 <= -37.0)
		tmp = d1 * d2;
	else
		tmp = d1 * 37.0;
	end
	tmp_2 = tmp;
end
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_] := If[LessEqual[d2, -37.0], N[(d1 * d2), $MachinePrecision], N[(d1 * 37.0), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3] = \mathsf{sort}([d1, d2, d3])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -37:\\
\;\;\;\;d1 \cdot d2\\

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


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

    1. Initial program 96.8%

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

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

        \[\leadsto d1 \cdot d2 + \left(\left(d3 + 5\right) \cdot d1 + \color{blue}{32 \cdot d1}\right) \]
      3. distribute-rgt-out96.8%

        \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot \left(\left(d3 + 5\right) + 32\right)} \]
      4. remove-double-neg96.8%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right)\right)} \cdot \left(\left(d3 + 5\right) + 32\right) \]
      5. distribute-lft-neg-in96.8%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right) \cdot \left(\left(d3 + 5\right) + 32\right)\right)} \]
      6. distribute-rgt-neg-in96.8%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-d1\right) \cdot \left(-\left(\left(d3 + 5\right) + 32\right)\right)} \]
      7. cancel-sign-sub-inv96.8%

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d3 + \left(5 + 32\right)\right)}\right) \]
      12. metadata-eval100.0%

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

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

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

    if -37 < d2

    1. Initial program 98.9%

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

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

        \[\leadsto d1 \cdot d2 + \left(\left(d3 + 5\right) \cdot d1 + \color{blue}{32 \cdot d1}\right) \]
      3. distribute-rgt-out98.9%

        \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot \left(\left(d3 + 5\right) + 32\right)} \]
      4. remove-double-neg98.9%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right)\right)} \cdot \left(\left(d3 + 5\right) + 32\right) \]
      5. distribute-lft-neg-in98.9%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right) \cdot \left(\left(d3 + 5\right) + 32\right)\right)} \]
      6. distribute-rgt-neg-in98.9%

        \[\leadsto d1 \cdot d2 + \color{blue}{\left(-d1\right) \cdot \left(-\left(\left(d3 + 5\right) + 32\right)\right)} \]
      7. cancel-sign-sub-inv98.9%

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d3 + \left(5 + 32\right)\right)}\right) \]
      12. metadata-eval100.0%

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

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

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

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

Alternative 6: 26.9% accurate, 4.3× speedup?

\[\begin{array}{l} [d1, d2, d3] = \mathsf{sort}([d1, d2, d3])\\ \\ d1 \cdot 37 \end{array} \]
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3) :precision binary64 (* d1 37.0))
assert(d1 < d2 && d2 < d3);
double code(double d1, double d2, double d3) {
	return d1 * 37.0;
}
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
real(8) function code(d1, d2, d3)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    code = d1 * 37.0d0
end function
assert d1 < d2 && d2 < d3;
public static double code(double d1, double d2, double d3) {
	return d1 * 37.0;
}
[d1, d2, d3] = sort([d1, d2, d3])
def code(d1, d2, d3):
	return d1 * 37.0
d1, d2, d3 = sort([d1, d2, d3])
function code(d1, d2, d3)
	return Float64(d1 * 37.0)
end
d1, d2, d3 = num2cell(sort([d1, d2, d3])){:}
function tmp = code(d1, d2, d3)
	tmp = d1 * 37.0;
end
NOTE: d1, d2, and d3 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_] := N[(d1 * 37.0), $MachinePrecision]
\begin{array}{l}
[d1, d2, d3] = \mathsf{sort}([d1, d2, d3])\\
\\
d1 \cdot 37
\end{array}
Derivation
  1. Initial program 98.4%

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

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

      \[\leadsto d1 \cdot d2 + \left(\left(d3 + 5\right) \cdot d1 + \color{blue}{32 \cdot d1}\right) \]
    3. distribute-rgt-out98.4%

      \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot \left(\left(d3 + 5\right) + 32\right)} \]
    4. remove-double-neg98.4%

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

      \[\leadsto d1 \cdot d2 + \color{blue}{\left(-\left(-d1\right) \cdot \left(\left(d3 + 5\right) + 32\right)\right)} \]
    6. distribute-rgt-neg-in98.4%

      \[\leadsto d1 \cdot d2 + \color{blue}{\left(-d1\right) \cdot \left(-\left(\left(d3 + 5\right) + 32\right)\right)} \]
    7. cancel-sign-sub-inv98.4%

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

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

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

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

      \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d3 + \left(5 + 32\right)\right)}\right) \]
    12. metadata-eval100.0%

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

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

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

    \[\leadsto d1 \cdot \color{blue}{37} \]
  7. Add Preprocessing

Developer Target 1: 100.0% accurate, 1.9× speedup?

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

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

Reproduce

?
herbie shell --seed 2024185 
(FPCore (d1 d2 d3)
  :name "FastMath dist3"
  :precision binary64

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

  (+ (+ (* d1 d2) (* (+ d3 5.0) d1)) (* d1 32.0)))