FastMath dist4

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

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 87.4% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.7× speedup?

\[\begin{array}{l} \\ d1 \cdot \left(\left(d2 - d3\right) + \left(d4 - d1\right)\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(d2 - d3) + Float64(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[(d2 - d3), $MachinePrecision] + N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

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

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

Alternative 2: 71.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d1\right)\\ t_1 := d1 \cdot \left(d2 - d3\right)\\ t_2 := d1 \cdot \left(d2 + d4\right)\\ \mathbf{if}\;d3 \leq -1.55 \cdot 10^{+100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq -6.2 \cdot 10^{+23}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d3 \leq -5.4 \cdot 10^{-89}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq -1.1 \cdot 10^{-214}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d3 \leq 5.4 \cdot 10^{-34}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 2500:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d3 \leq 10^{+73}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d2 d1))) (t_1 (* d1 (- d2 d3))) (t_2 (* d1 (+ d2 d4))))
   (if (<= d3 -1.55e+100)
     t_1
     (if (<= d3 -6.2e+23)
       t_2
       (if (<= d3 -5.4e-89)
         t_0
         (if (<= d3 -1.1e-214)
           t_2
           (if (<= d3 5.4e-34)
             t_0
             (if (<= d3 2500.0) t_2 (if (<= d3 1e+73) t_0 t_1)))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d1);
	double t_1 = d1 * (d2 - d3);
	double t_2 = d1 * (d2 + d4);
	double tmp;
	if (d3 <= -1.55e+100) {
		tmp = t_1;
	} else if (d3 <= -6.2e+23) {
		tmp = t_2;
	} else if (d3 <= -5.4e-89) {
		tmp = t_0;
	} else if (d3 <= -1.1e-214) {
		tmp = t_2;
	} else if (d3 <= 5.4e-34) {
		tmp = t_0;
	} else if (d3 <= 2500.0) {
		tmp = t_2;
	} else if (d3 <= 1e+73) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = d1 * (d2 - d1)
    t_1 = d1 * (d2 - d3)
    t_2 = d1 * (d2 + d4)
    if (d3 <= (-1.55d+100)) then
        tmp = t_1
    else if (d3 <= (-6.2d+23)) then
        tmp = t_2
    else if (d3 <= (-5.4d-89)) then
        tmp = t_0
    else if (d3 <= (-1.1d-214)) then
        tmp = t_2
    else if (d3 <= 5.4d-34) then
        tmp = t_0
    else if (d3 <= 2500.0d0) then
        tmp = t_2
    else if (d3 <= 1d+73) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d1);
	double t_1 = d1 * (d2 - d3);
	double t_2 = d1 * (d2 + d4);
	double tmp;
	if (d3 <= -1.55e+100) {
		tmp = t_1;
	} else if (d3 <= -6.2e+23) {
		tmp = t_2;
	} else if (d3 <= -5.4e-89) {
		tmp = t_0;
	} else if (d3 <= -1.1e-214) {
		tmp = t_2;
	} else if (d3 <= 5.4e-34) {
		tmp = t_0;
	} else if (d3 <= 2500.0) {
		tmp = t_2;
	} else if (d3 <= 1e+73) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d1)
	t_1 = d1 * (d2 - d3)
	t_2 = d1 * (d2 + d4)
	tmp = 0
	if d3 <= -1.55e+100:
		tmp = t_1
	elif d3 <= -6.2e+23:
		tmp = t_2
	elif d3 <= -5.4e-89:
		tmp = t_0
	elif d3 <= -1.1e-214:
		tmp = t_2
	elif d3 <= 5.4e-34:
		tmp = t_0
	elif d3 <= 2500.0:
		tmp = t_2
	elif d3 <= 1e+73:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d1))
	t_1 = Float64(d1 * Float64(d2 - d3))
	t_2 = Float64(d1 * Float64(d2 + d4))
	tmp = 0.0
	if (d3 <= -1.55e+100)
		tmp = t_1;
	elseif (d3 <= -6.2e+23)
		tmp = t_2;
	elseif (d3 <= -5.4e-89)
		tmp = t_0;
	elseif (d3 <= -1.1e-214)
		tmp = t_2;
	elseif (d3 <= 5.4e-34)
		tmp = t_0;
	elseif (d3 <= 2500.0)
		tmp = t_2;
	elseif (d3 <= 1e+73)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d2 - d1);
	t_1 = d1 * (d2 - d3);
	t_2 = d1 * (d2 + d4);
	tmp = 0.0;
	if (d3 <= -1.55e+100)
		tmp = t_1;
	elseif (d3 <= -6.2e+23)
		tmp = t_2;
	elseif (d3 <= -5.4e-89)
		tmp = t_0;
	elseif (d3 <= -1.1e-214)
		tmp = t_2;
	elseif (d3 <= 5.4e-34)
		tmp = t_0;
	elseif (d3 <= 2500.0)
		tmp = t_2;
	elseif (d3 <= 1e+73)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(d1 * N[(d2 + d4), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -1.55e+100], t$95$1, If[LessEqual[d3, -6.2e+23], t$95$2, If[LessEqual[d3, -5.4e-89], t$95$0, If[LessEqual[d3, -1.1e-214], t$95$2, If[LessEqual[d3, 5.4e-34], t$95$0, If[LessEqual[d3, 2500.0], t$95$2, If[LessEqual[d3, 1e+73], t$95$0, t$95$1]]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d3 \leq -6.2 \cdot 10^{+23}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;d3 \leq -5.4 \cdot 10^{-89}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d3 \leq -1.1 \cdot 10^{-214}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;d3 \leq 5.4 \cdot 10^{-34}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d3 \leq 2500:\\
\;\;\;\;t_2\\

\mathbf{elif}\;d3 \leq 10^{+73}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -1.55000000000000003e100 or 9.99999999999999983e72 < d3

    1. Initial program 87.2%

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

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

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

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

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

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

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

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

    if -1.55000000000000003e100 < d3 < -6.19999999999999941e23 or -5.39999999999999975e-89 < d3 < -1.10000000000000001e-214 or 5.40000000000000034e-34 < d3 < 2500

    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. associate--l+87.5%

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

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

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

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

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

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

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

    if -6.19999999999999941e23 < d3 < -5.39999999999999975e-89 or -1.10000000000000001e-214 < d3 < 5.40000000000000034e-34 or 2500 < d3 < 9.99999999999999983e72

    1. Initial program 91.5%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -1.55 \cdot 10^{+100}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq -6.2 \cdot 10^{+23}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{elif}\;d3 \leq -5.4 \cdot 10^{-89}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq -1.1 \cdot 10^{-214}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{elif}\;d3 \leq 5.4 \cdot 10^{-34}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 2500:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{elif}\;d3 \leq 10^{+73}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \end{array} \]

Alternative 3: 39.0% accurate, 0.9× speedup?

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

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

\mathbf{elif}\;d2 \leq -2.4 \cdot 10^{+70}:\\
\;\;\;\;d1 \cdot d4\\

\mathbf{elif}\;d2 \leq -1.14 \cdot 10^{+45}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d2 \leq -2.4 \cdot 10^{-25}:\\
\;\;\;\;d1 \cdot d4\\

\mathbf{elif}\;d2 \leq -4.2 \cdot 10^{-183}:\\
\;\;\;\;-d1 \cdot d1\\

\mathbf{elif}\;d2 \leq 7 \cdot 10^{-83}:\\
\;\;\;\;d1 \cdot \left(-d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d2 < -1.3e98 or -2.39999999999999987e70 < d2 < -1.1400000000000001e45

    1. Initial program 82.4%

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

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

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

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

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

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

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

    if -1.3e98 < d2 < -2.39999999999999987e70 or -1.1400000000000001e45 < d2 < -2.40000000000000009e-25 or 7.00000000000000061e-83 < d2

    1. Initial program 89.3%

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

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

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

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

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

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

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

    if -2.40000000000000009e-25 < d2 < -4.2000000000000004e-183

    1. Initial program 93.1%

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

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

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

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

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

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

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

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

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

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

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

    if -4.2000000000000004e-183 < d2 < 7.00000000000000061e-83

    1. Initial program 92.1%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.3 \cdot 10^{+98}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -2.4 \cdot 10^{+70}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{elif}\;d2 \leq -1.14 \cdot 10^{+45}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -2.4 \cdot 10^{-25}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{elif}\;d2 \leq -4.2 \cdot 10^{-183}:\\ \;\;\;\;-d1 \cdot d1\\ \mathbf{elif}\;d2 \leq 7 \cdot 10^{-83}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 4: 39.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.3 \cdot 10^{+98}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -1.25 \cdot 10^{+70}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{elif}\;d2 \leq -2.7 \cdot 10^{+45}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -2.5 \cdot 10^{-27}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{elif}\;d2 \leq 4.2 \cdot 10^{-51}:\\ \;\;\;\;-d1 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -1.3e+98)
   (* d1 d2)
   (if (<= d2 -1.25e+70)
     (* d1 d4)
     (if (<= d2 -2.7e+45)
       (* d1 d2)
       (if (<= d2 -2.5e-27)
         (* d1 d4)
         (if (<= d2 4.2e-51) (- (* d1 d1)) (* d1 d4)))))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -1.3e+98) {
		tmp = d1 * d2;
	} else if (d2 <= -1.25e+70) {
		tmp = d1 * d4;
	} else if (d2 <= -2.7e+45) {
		tmp = d1 * d2;
	} else if (d2 <= -2.5e-27) {
		tmp = d1 * d4;
	} else if (d2 <= 4.2e-51) {
		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 (d2 <= (-1.3d+98)) then
        tmp = d1 * d2
    else if (d2 <= (-1.25d+70)) then
        tmp = d1 * d4
    else if (d2 <= (-2.7d+45)) then
        tmp = d1 * d2
    else if (d2 <= (-2.5d-27)) then
        tmp = d1 * d4
    else if (d2 <= 4.2d-51) 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 (d2 <= -1.3e+98) {
		tmp = d1 * d2;
	} else if (d2 <= -1.25e+70) {
		tmp = d1 * d4;
	} else if (d2 <= -2.7e+45) {
		tmp = d1 * d2;
	} else if (d2 <= -2.5e-27) {
		tmp = d1 * d4;
	} else if (d2 <= 4.2e-51) {
		tmp = -(d1 * d1);
	} else {
		tmp = d1 * d4;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -1.3e+98:
		tmp = d1 * d2
	elif d2 <= -1.25e+70:
		tmp = d1 * d4
	elif d2 <= -2.7e+45:
		tmp = d1 * d2
	elif d2 <= -2.5e-27:
		tmp = d1 * d4
	elif d2 <= 4.2e-51:
		tmp = -(d1 * d1)
	else:
		tmp = d1 * d4
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -1.3e+98)
		tmp = Float64(d1 * d2);
	elseif (d2 <= -1.25e+70)
		tmp = Float64(d1 * d4);
	elseif (d2 <= -2.7e+45)
		tmp = Float64(d1 * d2);
	elseif (d2 <= -2.5e-27)
		tmp = Float64(d1 * d4);
	elseif (d2 <= 4.2e-51)
		tmp = Float64(-Float64(d1 * d1));
	else
		tmp = Float64(d1 * d4);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -1.3e+98)
		tmp = d1 * d2;
	elseif (d2 <= -1.25e+70)
		tmp = d1 * d4;
	elseif (d2 <= -2.7e+45)
		tmp = d1 * d2;
	elseif (d2 <= -2.5e-27)
		tmp = d1 * d4;
	elseif (d2 <= 4.2e-51)
		tmp = -(d1 * d1);
	else
		tmp = d1 * d4;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.3e+98], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -1.25e+70], N[(d1 * d4), $MachinePrecision], If[LessEqual[d2, -2.7e+45], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -2.5e-27], N[(d1 * d4), $MachinePrecision], If[LessEqual[d2, 4.2e-51], (-N[(d1 * d1), $MachinePrecision]), N[(d1 * d4), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d2 \leq -1.25 \cdot 10^{+70}:\\
\;\;\;\;d1 \cdot d4\\

\mathbf{elif}\;d2 \leq -2.7 \cdot 10^{+45}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d2 \leq -2.5 \cdot 10^{-27}:\\
\;\;\;\;d1 \cdot d4\\

\mathbf{elif}\;d2 \leq 4.2 \cdot 10^{-51}:\\
\;\;\;\;-d1 \cdot d1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d2 < -1.3e98 or -1.2500000000000001e70 < d2 < -2.69999999999999984e45

    1. Initial program 82.4%

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

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

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

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

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

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

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

    if -1.3e98 < d2 < -1.2500000000000001e70 or -2.69999999999999984e45 < d2 < -2.5000000000000001e-27 or 4.20000000000000003e-51 < d2

    1. Initial program 89.7%

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

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

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

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

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

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

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

    if -2.5000000000000001e-27 < d2 < 4.20000000000000003e-51

    1. Initial program 91.9%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.3 \cdot 10^{+98}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -1.25 \cdot 10^{+70}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{elif}\;d2 \leq -2.7 \cdot 10^{+45}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -2.5 \cdot 10^{-27}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{elif}\;d2 \leq 4.2 \cdot 10^{-51}:\\ \;\;\;\;-d1 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 5: 62.9% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;d2 \leq -5.1 \cdot 10^{-20}:\\
\;\;\;\;d1 \cdot \left(d2 + d4\right)\\

\mathbf{elif}\;d2 \leq 2.6 \cdot 10^{-151}:\\
\;\;\;\;d1 \cdot \left(-\left(d1 + d3\right)\right)\\

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


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

    1. Initial program 81.2%

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

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

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

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

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

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

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

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

    if -1.35e98 < d2 < -5.10000000000000019e-20

    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. associate--l+87.5%

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

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

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

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

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

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

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

    if -5.10000000000000019e-20 < d2 < 2.6e-151

    1. Initial program 92.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.6e-151 < d2

    1. Initial program 90.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.35 \cdot 10^{+98}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -5.1 \cdot 10^{-20}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{elif}\;d2 \leq 2.6 \cdot 10^{-151}:\\ \;\;\;\;d1 \cdot \left(-\left(d1 + d3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]

Alternative 6: 59.4% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;d2 \leq -3.8 \cdot 10^{-27}:\\
\;\;\;\;d1 \cdot \left(d2 + d4\right)\\

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

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


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

    1. Initial program 81.2%

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

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

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

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

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

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

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

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

    if -1.5000000000000001e98 < d2 < -3.8e-27

    1. Initial program 87.8%

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

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

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

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

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

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

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

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

    if -3.8e-27 < d2 < -2.4000000000000001e-181

    1. Initial program 93.1%

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

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

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

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

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

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

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

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

    if -2.4000000000000001e-181 < d2

    1. Initial program 91.1%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.5 \cdot 10^{+98}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -3.8 \cdot 10^{-27}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{elif}\;d2 \leq -2.4 \cdot 10^{-181}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]

Alternative 7: 89.2% accurate, 1.3× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -5.09999999999999972e123 or 7.9999999999999998e107 < d1

    1. Initial program 65.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.09999999999999972e123 < d1 < 7.9999999999999998e107

    1. Initial program 99.4%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -5.1 \cdot 10^{+123} \lor \neg \left(d1 \leq 8 \cdot 10^{+107}\right):\\ \;\;\;\;d1 \cdot \left(-\left(d1 + d3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\ \end{array} \]

Alternative 8: 92.2% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -5.2 \cdot 10^{+98} \lor \neg \left(d1 \leq 7.5 \cdot 10^{+93}\right):\\
\;\;\;\;d1 \cdot \left(d2 - \left(d1 + d3\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -5.1999999999999999e98 or 7.5000000000000002e93 < d1

    1. Initial program 69.2%

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

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

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

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

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

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

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

    if -5.1999999999999999e98 < d1 < 7.5000000000000002e93

    1. Initial program 100.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -5.2 \cdot 10^{+98} \lor \neg \left(d1 \leq 7.5 \cdot 10^{+93}\right):\\ \;\;\;\;d1 \cdot \left(d2 - \left(d1 + d3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\ \end{array} \]

Alternative 9: 38.2% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.2 \cdot 10^{+98} \lor \neg \left(d2 \leq -9.5 \cdot 10^{+69}\right) \land d2 \leq -2.5 \cdot 10^{+45}:\\
\;\;\;\;d1 \cdot d2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d2 < -1.1999999999999999e98 or -9.4999999999999995e69 < d2 < -2.5e45

    1. Initial program 82.4%

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

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

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

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

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

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

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

    if -1.1999999999999999e98 < d2 < -9.4999999999999995e69 or -2.5e45 < d2

    1. Initial program 90.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.2 \cdot 10^{+98} \lor \neg \left(d2 \leq -9.5 \cdot 10^{+69}\right) \land d2 \leq -2.5 \cdot 10^{+45}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 10: 66.5% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -5 \cdot 10^{+144} \lor \neg \left(d1 \leq 7.8 \cdot 10^{+110}\right):\\
\;\;\;\;-d1 \cdot d1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -4.9999999999999999e144 or 7.8000000000000007e110 < d1

    1. Initial program 62.5%

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

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

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

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

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

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

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

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

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

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

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

    if -4.9999999999999999e144 < d1 < 7.8000000000000007e110

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -5 \cdot 10^{+144} \lor \neg \left(d1 \leq 7.8 \cdot 10^{+110}\right):\\ \;\;\;\;-d1 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]

Alternative 11: 69.7% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -5 \cdot 10^{+98} \lor \neg \left(d1 \leq 6.5 \cdot 10^{+95}\right):\\
\;\;\;\;d1 \cdot \left(d2 - d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -4.9999999999999998e98 or 6.5e95 < d1

    1. Initial program 69.2%

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

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

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

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

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

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

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

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

    if -4.9999999999999998e98 < d1 < 6.5e95

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -5 \cdot 10^{+98} \lor \neg \left(d1 \leq 6.5 \cdot 10^{+95}\right):\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]

Alternative 12: 30.4% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{d1 \cdot d4} \]
  5. Final simplification30.6%

    \[\leadsto d1 \cdot d4 \]

Developer target: 100.0% accurate, 1.7× speedup?

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

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

Reproduce

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

  :herbie-target
  (* d1 (- (+ (- d2 d3) d4) d1))

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