FastMath dist4

Percentage Accurate: 87.9% → 100.0%
Time: 10.6s
Alternatives: 13
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 13 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.9% 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(d2 + \left(d4 - \left(d1 + d3\right)\right)\right) \end{array} \]
(FPCore (d1 d2 d3 d4) :precision binary64 (* d1 (+ d2 (- d4 (+ d1 d3)))))
double code(double d1, double d2, double d3, double d4) {
	return d1 * (d2 + (d4 - (d1 + d3)));
}
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 + (d4 - (d1 + d3)))
end function
public static double code(double d1, double d2, double d3, double d4) {
	return d1 * (d2 + (d4 - (d1 + d3)));
}
def code(d1, d2, d3, d4):
	return d1 * (d2 + (d4 - (d1 + d3)))
function code(d1, d2, d3, d4)
	return Float64(d1 * Float64(d2 + Float64(d4 - Float64(d1 + d3))))
end
function tmp = code(d1, d2, d3, d4)
	tmp = d1 * (d2 + (d4 - (d1 + d3)));
end
code[d1_, d2_, d3_, d4_] := N[(d1 * N[(d2 + N[(d4 - N[(d1 + d3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
d1 \cdot \left(d2 + \left(d4 - \left(d1 + d3\right)\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. distribute-lft-out--N/A

      \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. *-commutativeN/A

      \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
    3. distribute-lft-outN/A

      \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
    4. distribute-lft-out--N/A

      \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
    6. associate-+r-N/A

      \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
    7. sub-negN/A

      \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
    8. associate-+l+N/A

      \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
    9. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
    10. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
    11. unsub-negN/A

      \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
    12. associate--l-N/A

      \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
    13. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
    14. --lowering--.f64N/A

      \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
    15. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
    16. +-lowering-+.f64100.0%

      \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
  3. Simplified100.0%

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

Alternative 2: 84.3% accurate, 0.9× speedup?

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

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

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

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


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

    1. Initial program 83.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. distribute-lft-out--N/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. *-commutativeN/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
      3. distribute-lft-outN/A

        \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
      4. distribute-lft-out--N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
      6. associate-+r-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
      8. associate-+l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
      12. associate--l-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
      14. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
      15. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
      16. +-lowering-+.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(d2 + d4\right) - d3\right)}\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d4 + d2\right) - d3\right)\right) \]
      3. associate--l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d4 + \color{blue}{\left(d2 - d3\right)}\right)\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \color{blue}{\left(d2 - d3\right)}\right)\right) \]
      5. --lowering--.f6495.3%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \mathsf{\_.f64}\left(d2, \color{blue}{d3}\right)\right)\right) \]
    7. Simplified95.3%

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

    if -4.19999999999999978e71 < d2 < -5.9000000000000003e-21

    1. Initial program 90.5%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. distribute-lft-out--N/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. *-commutativeN/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
      3. distribute-lft-outN/A

        \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
      4. distribute-lft-out--N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
      6. associate-+r-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
      8. associate-+l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
      12. associate--l-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
      14. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
      15. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
      16. +-lowering-+.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d1\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(d2 + d4\right) - d1\right)}\right) \]
      2. associate--l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \left(d4 + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right)\right)\right) \]
      4. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \left(d4 + -1 \cdot \color{blue}{d1}\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(d4 + -1 \cdot d1\right)}\right)\right) \]
      6. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 + \left(\mathsf{neg}\left(d1\right)\right)\right)\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{d1}\right)\right)\right) \]
      8. --lowering--.f6492.2%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{d1}\right)\right)\right) \]
    7. Simplified92.2%

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

    if -5.9000000000000003e-21 < d2

    1. Initial program 90.1%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. distribute-lft-out--N/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. *-commutativeN/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
      3. distribute-lft-outN/A

        \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
      4. distribute-lft-out--N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
      6. associate-+r-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
      8. associate-+l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
      12. associate--l-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
      14. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
      15. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
      16. +-lowering-+.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - \left(d1 + d3\right)\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(d4 - \left(d1 + d3\right)\right)}\right) \]
      2. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d1 + d3\right)}\right)\right) \]
      3. +-lowering-+.f6485.9%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right) \]
    7. Simplified85.9%

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

Alternative 3: 93.5% accurate, 0.9× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -1.89999999999999999e80 or 8e18 < d3

    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. distribute-lft-out--N/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. *-commutativeN/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
      3. distribute-lft-outN/A

        \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
      4. distribute-lft-out--N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
      6. associate-+r-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
      8. associate-+l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
      12. associate--l-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
      14. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
      15. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
      16. +-lowering-+.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(d2 + d4\right) - d3\right)}\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d4 + d2\right) - d3\right)\right) \]
      3. associate--l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d4 + \color{blue}{\left(d2 - d3\right)}\right)\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \color{blue}{\left(d2 - d3\right)}\right)\right) \]
      5. --lowering--.f6495.4%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \mathsf{\_.f64}\left(d2, \color{blue}{d3}\right)\right)\right) \]
    7. Simplified95.4%

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

    if -1.89999999999999999e80 < d3 < 8e18

    1. Initial program 88.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. distribute-lft-out--N/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. *-commutativeN/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
      3. distribute-lft-outN/A

        \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
      4. distribute-lft-out--N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
      6. associate-+r-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
      8. associate-+l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
      12. associate--l-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
      14. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
      15. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
      16. +-lowering-+.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d1\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(d2 + d4\right) - d1\right)}\right) \]
      2. associate--l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \left(d4 + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right)\right)\right) \]
      4. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \left(d4 + -1 \cdot \color{blue}{d1}\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(d4 + -1 \cdot d1\right)}\right)\right) \]
      6. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 + \left(\mathsf{neg}\left(d1\right)\right)\right)\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{d1}\right)\right)\right) \]
      8. --lowering--.f6496.3%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{d1}\right)\right)\right) \]
    7. Simplified96.3%

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

Alternative 4: 87.2% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -8.00000000000000025e83

    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. distribute-lft-out--N/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. *-commutativeN/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
      3. distribute-lft-outN/A

        \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
      4. distribute-lft-out--N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
      6. associate-+r-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
      8. associate-+l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
      12. associate--l-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
      14. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
      15. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
      16. +-lowering-+.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(d2 + d4\right) - d3\right)}\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d4 + d2\right) - d3\right)\right) \]
      3. associate--l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d4 + \color{blue}{\left(d2 - d3\right)}\right)\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \color{blue}{\left(d2 - d3\right)}\right)\right) \]
      5. --lowering--.f6494.2%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \mathsf{\_.f64}\left(d2, \color{blue}{d3}\right)\right)\right) \]
    7. Simplified94.2%

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

      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(d2 - d3\right)}\right) \]
      2. --lowering--.f6477.9%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d2, \color{blue}{d3}\right)\right) \]
    10. Simplified77.9%

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

    if -8.00000000000000025e83 < d3 < 1.45e19

    1. Initial program 88.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. distribute-lft-out--N/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. *-commutativeN/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
      3. distribute-lft-outN/A

        \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
      4. distribute-lft-out--N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
      6. associate-+r-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
      8. associate-+l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
      12. associate--l-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
      14. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
      15. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
      16. +-lowering-+.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d1\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(d2 + d4\right) - d1\right)}\right) \]
      2. associate--l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \left(d4 + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right)\right)\right) \]
      4. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \left(d4 + -1 \cdot \color{blue}{d1}\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(d4 + -1 \cdot d1\right)}\right)\right) \]
      6. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 + \left(\mathsf{neg}\left(d1\right)\right)\right)\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{d1}\right)\right)\right) \]
      8. --lowering--.f6496.3%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{d1}\right)\right)\right) \]
    7. Simplified96.3%

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

    if 1.45e19 < d3

    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. distribute-lft-out--N/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. *-commutativeN/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
      3. distribute-lft-outN/A

        \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
      4. distribute-lft-out--N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
      6. associate-+r-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
      8. associate-+l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
      12. associate--l-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
      14. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
      15. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
      16. +-lowering-+.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(d2 + d4\right) - d3\right)}\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d4 + d2\right) - d3\right)\right) \]
      3. associate--l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d4 + \color{blue}{\left(d2 - d3\right)}\right)\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \color{blue}{\left(d2 - d3\right)}\right)\right) \]
      5. --lowering--.f6496.4%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \mathsf{\_.f64}\left(d2, \color{blue}{d3}\right)\right)\right) \]
    7. Simplified96.4%

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(d4 - d3\right)}\right) \]
      2. --lowering--.f6485.7%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d4, \color{blue}{d3}\right)\right) \]
    10. Simplified85.7%

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

Alternative 5: 68.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := 0 - d1 \cdot d3\\
\mathbf{if}\;d3 \leq -1.8 \cdot 10^{+110}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d3 \leq 7 \cdot 10^{+158}:\\
\;\;\;\;d1 \cdot \left(d2 + d4\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -1.7999999999999998e110 or 7.0000000000000003e158 < d3

    1. Initial program 86.5%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. distribute-lft-out--N/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. *-commutativeN/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
      3. distribute-lft-outN/A

        \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
      4. distribute-lft-out--N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
      6. associate-+r-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
      8. associate-+l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
      12. associate--l-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
      14. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
      15. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
      16. +-lowering-+.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
    3. Simplified100.0%

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

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

        \[\leadsto \mathsf{neg}\left(d1 \cdot d3\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{d1 \cdot d3} \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(d1 \cdot d3\right)}\right) \]
      4. *-lowering-*.f6476.2%

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(d1, \color{blue}{d3}\right)\right) \]
    7. Simplified76.2%

      \[\leadsto \color{blue}{0 - d1 \cdot d3} \]
    8. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(d1 \cdot d3\right) \]
      2. neg-lowering-neg.f64N/A

        \[\leadsto \mathsf{neg.f64}\left(\left(d1 \cdot d3\right)\right) \]
      3. *-lowering-*.f6476.2%

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(d1, d3\right)\right) \]
    9. Applied egg-rr76.2%

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

    if -1.7999999999999998e110 < d3 < 7.0000000000000003e158

    1. Initial program 89.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. distribute-lft-out--N/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. *-commutativeN/A

        \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
      3. distribute-lft-outN/A

        \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
      4. distribute-lft-out--N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
      6. associate-+r-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
      7. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
      8. associate-+l+N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
      11. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
      12. associate--l-N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
      14. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
      15. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
      16. +-lowering-+.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
    3. Simplified100.0%

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

      \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{d4}\right)\right) \]
    6. Step-by-step derivation
      1. Simplified66.8%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -1.8 \cdot 10^{+110}:\\ \;\;\;\;0 - d1 \cdot d3\\ \mathbf{elif}\;d3 \leq 7 \cdot 10^{+158}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{else}:\\ \;\;\;\;0 - d1 \cdot d3\\ \end{array} \]
    9. Add Preprocessing

    Alternative 6: 39.7% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 1.4 \cdot 10^{-155}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 1.5 \cdot 10^{+133}:\\ \;\;\;\;0 - d1 \cdot d3\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \end{array} \]
    (FPCore (d1 d2 d3 d4)
     :precision binary64
     (if (<= d4 1.4e-155)
       (* d1 d2)
       (if (<= d4 1.5e+133) (- 0.0 (* d1 d3)) (* d1 d4))))
    double code(double d1, double d2, double d3, double d4) {
    	double tmp;
    	if (d4 <= 1.4e-155) {
    		tmp = d1 * d2;
    	} else if (d4 <= 1.5e+133) {
    		tmp = 0.0 - (d1 * d3);
    	} else {
    		tmp = d1 * d4;
    	}
    	return tmp;
    }
    
    real(8) function code(d1, d2, d3, d4)
        real(8), intent (in) :: d1
        real(8), intent (in) :: d2
        real(8), intent (in) :: d3
        real(8), intent (in) :: d4
        real(8) :: tmp
        if (d4 <= 1.4d-155) then
            tmp = d1 * d2
        else if (d4 <= 1.5d+133) then
            tmp = 0.0d0 - (d1 * d3)
        else
            tmp = d1 * d4
        end if
        code = tmp
    end function
    
    public static double code(double d1, double d2, double d3, double d4) {
    	double tmp;
    	if (d4 <= 1.4e-155) {
    		tmp = d1 * d2;
    	} else if (d4 <= 1.5e+133) {
    		tmp = 0.0 - (d1 * d3);
    	} else {
    		tmp = d1 * d4;
    	}
    	return tmp;
    }
    
    def code(d1, d2, d3, d4):
    	tmp = 0
    	if d4 <= 1.4e-155:
    		tmp = d1 * d2
    	elif d4 <= 1.5e+133:
    		tmp = 0.0 - (d1 * d3)
    	else:
    		tmp = d1 * d4
    	return tmp
    
    function code(d1, d2, d3, d4)
    	tmp = 0.0
    	if (d4 <= 1.4e-155)
    		tmp = Float64(d1 * d2);
    	elseif (d4 <= 1.5e+133)
    		tmp = Float64(0.0 - Float64(d1 * d3));
    	else
    		tmp = Float64(d1 * d4);
    	end
    	return tmp
    end
    
    function tmp_2 = code(d1, d2, d3, d4)
    	tmp = 0.0;
    	if (d4 <= 1.4e-155)
    		tmp = d1 * d2;
    	elseif (d4 <= 1.5e+133)
    		tmp = 0.0 - (d1 * d3);
    	else
    		tmp = d1 * d4;
    	end
    	tmp_2 = tmp;
    end
    
    code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 1.4e-155], N[(d1 * d2), $MachinePrecision], If[LessEqual[d4, 1.5e+133], N[(0.0 - N[(d1 * d3), $MachinePrecision]), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;d4 \leq 1.4 \cdot 10^{-155}:\\
    \;\;\;\;d1 \cdot d2\\
    
    \mathbf{elif}\;d4 \leq 1.5 \cdot 10^{+133}:\\
    \;\;\;\;0 - d1 \cdot d3\\
    
    \mathbf{else}:\\
    \;\;\;\;d1 \cdot d4\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if d4 < 1.4e-155

      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. distribute-lft-out--N/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. *-commutativeN/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
        3. distribute-lft-outN/A

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
        4. distribute-lft-out--N/A

          \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
        6. associate-+r-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
        7. sub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
        8. associate-+l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        9. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
        11. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
        12. associate--l-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
        13. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
        14. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
        15. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
        16. +-lowering-+.f64100.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
      3. Simplified100.0%

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

        \[\leadsto \color{blue}{d1 \cdot d2} \]
      6. Step-by-step derivation
        1. *-lowering-*.f6432.4%

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{d2}\right) \]
      7. Simplified32.4%

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

      if 1.4e-155 < d4 < 1.50000000000000003e133

      1. Initial program 91.8%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Step-by-step derivation
        1. distribute-lft-out--N/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. *-commutativeN/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
        3. distribute-lft-outN/A

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
        4. distribute-lft-out--N/A

          \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
        6. associate-+r-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
        7. sub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
        8. associate-+l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        9. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
        11. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
        12. associate--l-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
        13. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
        14. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
        15. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
        16. +-lowering-+.f64100.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
      3. Simplified100.0%

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

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

          \[\leadsto \mathsf{neg}\left(d1 \cdot d3\right) \]
        2. neg-sub0N/A

          \[\leadsto 0 - \color{blue}{d1 \cdot d3} \]
        3. --lowering--.f64N/A

          \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(d1 \cdot d3\right)}\right) \]
        4. *-lowering-*.f6440.3%

          \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(d1, \color{blue}{d3}\right)\right) \]
      7. Simplified40.3%

        \[\leadsto \color{blue}{0 - d1 \cdot d3} \]
      8. Step-by-step derivation
        1. sub0-negN/A

          \[\leadsto \mathsf{neg}\left(d1 \cdot d3\right) \]
        2. neg-lowering-neg.f64N/A

          \[\leadsto \mathsf{neg.f64}\left(\left(d1 \cdot d3\right)\right) \]
        3. *-lowering-*.f6440.3%

          \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(d1, d3\right)\right) \]
      9. Applied egg-rr40.3%

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

      if 1.50000000000000003e133 < d4

      1. Initial program 85.4%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Step-by-step derivation
        1. distribute-lft-out--N/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. *-commutativeN/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
        3. distribute-lft-outN/A

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
        4. distribute-lft-out--N/A

          \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
        6. associate-+r-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
        7. sub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
        8. associate-+l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        9. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
        11. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
        12. associate--l-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
        13. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
        14. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
        15. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
        16. +-lowering-+.f64100.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
      3. Simplified100.0%

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

        \[\leadsto \color{blue}{d1 \cdot d4} \]
      6. Step-by-step derivation
        1. *-lowering-*.f6479.2%

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{d4}\right) \]
      7. Simplified79.2%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 1.4 \cdot 10^{-155}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 1.5 \cdot 10^{+133}:\\ \;\;\;\;0 - d1 \cdot d3\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
    5. Add Preprocessing

    Alternative 7: 39.8% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -6 \cdot 10^{+70}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -6.4 \cdot 10^{-308}:\\ \;\;\;\;d1 \cdot \left(0 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \end{array} \]
    (FPCore (d1 d2 d3 d4)
     :precision binary64
     (if (<= d2 -6e+70)
       (* d1 d2)
       (if (<= d2 -6.4e-308) (* d1 (- 0.0 d1)) (* d1 d4))))
    double code(double d1, double d2, double d3, double d4) {
    	double tmp;
    	if (d2 <= -6e+70) {
    		tmp = d1 * d2;
    	} else if (d2 <= -6.4e-308) {
    		tmp = d1 * (0.0 - 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 <= (-6d+70)) then
            tmp = d1 * d2
        else if (d2 <= (-6.4d-308)) then
            tmp = d1 * (0.0d0 - 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 <= -6e+70) {
    		tmp = d1 * d2;
    	} else if (d2 <= -6.4e-308) {
    		tmp = d1 * (0.0 - d1);
    	} else {
    		tmp = d1 * d4;
    	}
    	return tmp;
    }
    
    def code(d1, d2, d3, d4):
    	tmp = 0
    	if d2 <= -6e+70:
    		tmp = d1 * d2
    	elif d2 <= -6.4e-308:
    		tmp = d1 * (0.0 - d1)
    	else:
    		tmp = d1 * d4
    	return tmp
    
    function code(d1, d2, d3, d4)
    	tmp = 0.0
    	if (d2 <= -6e+70)
    		tmp = Float64(d1 * d2);
    	elseif (d2 <= -6.4e-308)
    		tmp = Float64(d1 * Float64(0.0 - d1));
    	else
    		tmp = Float64(d1 * d4);
    	end
    	return tmp
    end
    
    function tmp_2 = code(d1, d2, d3, d4)
    	tmp = 0.0;
    	if (d2 <= -6e+70)
    		tmp = d1 * d2;
    	elseif (d2 <= -6.4e-308)
    		tmp = d1 * (0.0 - d1);
    	else
    		tmp = d1 * d4;
    	end
    	tmp_2 = tmp;
    end
    
    code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -6e+70], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -6.4e-308], N[(d1 * N[(0.0 - d1), $MachinePrecision]), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;d2 \leq -6 \cdot 10^{+70}:\\
    \;\;\;\;d1 \cdot d2\\
    
    \mathbf{elif}\;d2 \leq -6.4 \cdot 10^{-308}:\\
    \;\;\;\;d1 \cdot \left(0 - d1\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;d1 \cdot d4\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if d2 < -5.99999999999999952e70

      1. Initial program 84.1%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Step-by-step derivation
        1. distribute-lft-out--N/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. *-commutativeN/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
        3. distribute-lft-outN/A

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
        4. distribute-lft-out--N/A

          \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
        6. associate-+r-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
        7. sub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
        8. associate-+l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        9. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
        11. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
        12. associate--l-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
        13. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
        14. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
        15. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
        16. +-lowering-+.f64100.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
      3. Simplified100.0%

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

        \[\leadsto \color{blue}{d1 \cdot d2} \]
      6. Step-by-step derivation
        1. *-lowering-*.f6469.1%

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{d2}\right) \]
      7. Simplified69.1%

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

      if -5.99999999999999952e70 < d2 < -6.4000000000000002e-308

      1. Initial program 85.2%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Step-by-step derivation
        1. distribute-lft-out--N/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. *-commutativeN/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
        3. distribute-lft-outN/A

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
        4. distribute-lft-out--N/A

          \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
        6. associate-+r-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
        7. sub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
        8. associate-+l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        9. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
        11. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
        12. associate--l-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
        13. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
        14. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
        15. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
        16. +-lowering-+.f64100.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
      3. Simplified100.0%

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

        \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
      6. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
        2. neg-sub0N/A

          \[\leadsto 0 - \color{blue}{{d1}^{2}} \]
        3. --lowering--.f64N/A

          \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left({d1}^{2}\right)}\right) \]
        4. unpow2N/A

          \[\leadsto \mathsf{\_.f64}\left(0, \left(d1 \cdot \color{blue}{d1}\right)\right) \]
        5. *-lowering-*.f6438.2%

          \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(d1, \color{blue}{d1}\right)\right) \]
      7. Simplified38.2%

        \[\leadsto \color{blue}{0 - d1 \cdot d1} \]
      8. Step-by-step derivation
        1. sub0-negN/A

          \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
        2. neg-lowering-neg.f64N/A

          \[\leadsto \mathsf{neg.f64}\left(\left(d1 \cdot d1\right)\right) \]
        3. *-lowering-*.f6438.2%

          \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(d1, d1\right)\right) \]
      9. Applied egg-rr38.2%

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

      if -6.4000000000000002e-308 < d2

      1. Initial program 92.3%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Step-by-step derivation
        1. distribute-lft-out--N/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. *-commutativeN/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
        3. distribute-lft-outN/A

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
        4. distribute-lft-out--N/A

          \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
        6. associate-+r-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
        7. sub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
        8. associate-+l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        9. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
        11. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
        12. associate--l-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
        13. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
        14. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
        15. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
        16. +-lowering-+.f64100.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
      3. Simplified100.0%

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

        \[\leadsto \color{blue}{d1 \cdot d4} \]
      6. Step-by-step derivation
        1. *-lowering-*.f6432.7%

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{d4}\right) \]
      7. Simplified32.7%

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

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

    Alternative 8: 65.1% accurate, 1.5× speedup?

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

      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. distribute-lft-out--N/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. *-commutativeN/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
        3. distribute-lft-outN/A

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
        4. distribute-lft-out--N/A

          \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
        6. associate-+r-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
        7. sub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
        8. associate-+l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        9. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
        11. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
        12. associate--l-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
        13. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
        14. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
        15. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
        16. +-lowering-+.f64100.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
      3. Simplified100.0%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
      6. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(d2 + d4\right) - d3\right)}\right) \]
        2. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d4 + d2\right) - d3\right)\right) \]
        3. associate--l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d4 + \color{blue}{\left(d2 - d3\right)}\right)\right) \]
        4. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \color{blue}{\left(d2 - d3\right)}\right)\right) \]
        5. --lowering--.f6477.9%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \mathsf{\_.f64}\left(d2, \color{blue}{d3}\right)\right)\right) \]
      7. Simplified77.9%

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

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} \]
      9. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(d2 - d3\right)}\right) \]
        2. --lowering--.f6462.9%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d2, \color{blue}{d3}\right)\right) \]
      10. Simplified62.9%

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

      if 4.1999999999999997e81 < d4

      1. Initial program 86.8%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Step-by-step derivation
        1. distribute-lft-out--N/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. *-commutativeN/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
        3. distribute-lft-outN/A

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
        4. distribute-lft-out--N/A

          \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
        6. associate-+r-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
        7. sub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
        8. associate-+l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        9. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
        11. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
        12. associate--l-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
        13. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
        14. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
        15. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
        16. +-lowering-+.f64100.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
      3. Simplified100.0%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
      6. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(d2 + d4\right) - d3\right)}\right) \]
        2. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d4 + d2\right) - d3\right)\right) \]
        3. associate--l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d4 + \color{blue}{\left(d2 - d3\right)}\right)\right) \]
        4. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \color{blue}{\left(d2 - d3\right)}\right)\right) \]
        5. --lowering--.f6492.2%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \mathsf{\_.f64}\left(d2, \color{blue}{d3}\right)\right)\right) \]
      7. Simplified92.2%

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} \]
      9. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(d4 - d3\right)}\right) \]
        2. --lowering--.f6482.7%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d4, \color{blue}{d3}\right)\right) \]
      10. Simplified82.7%

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

    Alternative 9: 63.7% accurate, 1.5× speedup?

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

      1. Initial program 89.9%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Step-by-step derivation
        1. distribute-lft-out--N/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. *-commutativeN/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
        3. distribute-lft-outN/A

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
        4. distribute-lft-out--N/A

          \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
        6. associate-+r-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
        7. sub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
        8. associate-+l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        9. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
        11. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
        12. associate--l-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
        13. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
        14. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
        15. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
        16. +-lowering-+.f64100.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
      3. Simplified100.0%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
      6. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(d2 + d4\right) - d3\right)}\right) \]
        2. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d4 + d2\right) - d3\right)\right) \]
        3. associate--l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d4 + \color{blue}{\left(d2 - d3\right)}\right)\right) \]
        4. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \color{blue}{\left(d2 - d3\right)}\right)\right) \]
        5. --lowering--.f6478.9%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \mathsf{\_.f64}\left(d2, \color{blue}{d3}\right)\right)\right) \]
      7. Simplified78.9%

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

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} \]
      9. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(d2 - d3\right)}\right) \]
        2. --lowering--.f6463.4%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d2, \color{blue}{d3}\right)\right) \]
      10. Simplified63.4%

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

      if 1.14999999999999995e133 < d4

      1. Initial program 85.4%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Step-by-step derivation
        1. distribute-lft-out--N/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. *-commutativeN/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
        3. distribute-lft-outN/A

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
        4. distribute-lft-out--N/A

          \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
        6. associate-+r-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
        7. sub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
        8. associate-+l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        9. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
        11. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
        12. associate--l-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
        13. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
        14. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
        15. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
        16. +-lowering-+.f64100.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
      3. Simplified100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 + \left(d4 - \left(d1 + d3\right)\right)\right)} \]
      4. Add Preprocessing
      5. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto d1 \cdot \left(\left(d4 - \left(d1 + d3\right)\right) + \color{blue}{d2}\right) \]
        2. distribute-lft-inN/A

          \[\leadsto d1 \cdot \left(d4 - \left(d1 + d3\right)\right) + \color{blue}{d1 \cdot d2} \]
        3. +-lowering-+.f64N/A

          \[\leadsto \mathsf{+.f64}\left(\left(d1 \cdot \left(d4 - \left(d1 + d3\right)\right)\right), \color{blue}{\left(d1 \cdot d2\right)}\right) \]
        4. *-lowering-*.f64N/A

          \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(d1, \left(d4 - \left(d1 + d3\right)\right)\right), \left(\color{blue}{d1} \cdot d2\right)\right) \]
        5. --lowering--.f64N/A

          \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d4, \left(d1 + d3\right)\right)\right), \left(d1 \cdot d2\right)\right) \]
        6. +-lowering-+.f64N/A

          \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, d3\right)\right)\right), \left(d1 \cdot d2\right)\right) \]
        7. *-lowering-*.f6495.8%

          \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, d3\right)\right)\right), \mathsf{*.f64}\left(d1, \color{blue}{d2}\right)\right) \]
      6. Applied egg-rr95.8%

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

        \[\leadsto \color{blue}{d1 \cdot d2 + d1 \cdot \left(d4 - d1\right)} \]
      8. Step-by-step derivation
        1. distribute-lft-outN/A

          \[\leadsto d1 \cdot \color{blue}{\left(d2 + \left(d4 - d1\right)\right)} \]
        2. sub-negN/A

          \[\leadsto d1 \cdot \left(d2 + \left(d4 + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right)\right) \]
        3. mul-1-negN/A

          \[\leadsto d1 \cdot \left(d2 + \left(d4 + -1 \cdot \color{blue}{d1}\right)\right) \]
        4. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(d2 + \left(d4 + -1 \cdot d1\right)\right)}\right) \]
        5. associate-+r+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right)\right) \]
        6. mul-1-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + d4\right) + \left(\mathsf{neg}\left(d1\right)\right)\right)\right) \]
        7. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + d4\right) - \color{blue}{d1}\right)\right) \]
        8. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(\left(d2 + d4\right), \color{blue}{d1}\right)\right) \]
        9. +-lowering-+.f6491.6%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(\mathsf{+.f64}\left(d2, d4\right), d1\right)\right) \]
      9. Simplified91.6%

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} \]
      11. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(d4 - d1\right)}\right) \]
        2. --lowering--.f6487.6%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d4, \color{blue}{d1}\right)\right) \]
      12. Simplified87.6%

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

    Alternative 10: 64.2% accurate, 1.5× speedup?

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

      1. Initial program 89.1%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Step-by-step derivation
        1. distribute-lft-out--N/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. *-commutativeN/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
        3. distribute-lft-outN/A

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
        4. distribute-lft-out--N/A

          \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
        6. associate-+r-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
        7. sub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
        8. associate-+l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        9. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
        11. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
        12. associate--l-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
        13. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
        14. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
        15. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
        16. +-lowering-+.f64100.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
      3. Simplified100.0%

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

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
      6. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(d2 + d4\right) - d3\right)}\right) \]
        2. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d4 + d2\right) - d3\right)\right) \]
        3. associate--l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d4 + \color{blue}{\left(d2 - d3\right)}\right)\right) \]
        4. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \color{blue}{\left(d2 - d3\right)}\right)\right) \]
        5. --lowering--.f6478.2%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d4, \mathsf{\_.f64}\left(d2, \color{blue}{d3}\right)\right)\right) \]
      7. Simplified78.2%

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

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} \]
      9. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(d2 - d3\right)}\right) \]
        2. --lowering--.f6463.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d2, \color{blue}{d3}\right)\right) \]
      10. Simplified63.0%

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

      if 8.49999999999999966e136 < d4

      1. Initial program 88.9%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Step-by-step derivation
        1. distribute-lft-out--N/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. *-commutativeN/A

          \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
        3. distribute-lft-outN/A

          \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
        4. distribute-lft-out--N/A

          \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
        6. associate-+r-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
        7. sub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
        8. associate-+l+N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        9. +-lowering-+.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
        11. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
        12. associate--l-N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
        13. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
        14. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
        15. +-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
        16. +-lowering-+.f64100.0%

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
      3. Simplified100.0%

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

        \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{d4}\right)\right) \]
      6. Step-by-step derivation
        1. Simplified86.6%

          \[\leadsto d1 \cdot \left(d2 + \color{blue}{d4}\right) \]
      7. Recombined 2 regimes into one program.
      8. Add Preprocessing

      Alternative 11: 63.0% accurate, 1.5× speedup?

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

        1. Initial program 89.9%

          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. Step-by-step derivation
          1. distribute-lft-out--N/A

            \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
          2. *-commutativeN/A

            \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
          3. distribute-lft-outN/A

            \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
          4. distribute-lft-out--N/A

            \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
          5. *-lowering-*.f64N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
          6. associate-+r-N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
          7. sub-negN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
          8. associate-+l+N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
          9. +-lowering-+.f64N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
          10. +-commutativeN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
          11. unsub-negN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
          12. associate--l-N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
          13. +-commutativeN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
          14. --lowering--.f64N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
          15. +-commutativeN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
          16. +-lowering-+.f64100.0%

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
        3. Simplified100.0%

          \[\leadsto \color{blue}{d1 \cdot \left(d2 + \left(d4 - \left(d1 + d3\right)\right)\right)} \]
        4. Add Preprocessing
        5. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto d1 \cdot \left(\left(d4 - \left(d1 + d3\right)\right) + \color{blue}{d2}\right) \]
          2. distribute-lft-inN/A

            \[\leadsto d1 \cdot \left(d4 - \left(d1 + d3\right)\right) + \color{blue}{d1 \cdot d2} \]
          3. +-lowering-+.f64N/A

            \[\leadsto \mathsf{+.f64}\left(\left(d1 \cdot \left(d4 - \left(d1 + d3\right)\right)\right), \color{blue}{\left(d1 \cdot d2\right)}\right) \]
          4. *-lowering-*.f64N/A

            \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(d1, \left(d4 - \left(d1 + d3\right)\right)\right), \left(\color{blue}{d1} \cdot d2\right)\right) \]
          5. --lowering--.f64N/A

            \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d4, \left(d1 + d3\right)\right)\right), \left(d1 \cdot d2\right)\right) \]
          6. +-lowering-+.f64N/A

            \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, d3\right)\right)\right), \left(d1 \cdot d2\right)\right) \]
          7. *-lowering-*.f6495.7%

            \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, d3\right)\right)\right), \mathsf{*.f64}\left(d1, \color{blue}{d2}\right)\right) \]
        6. Applied egg-rr95.7%

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

          \[\leadsto \color{blue}{d1 \cdot d2 + d1 \cdot \left(d4 - d1\right)} \]
        8. Step-by-step derivation
          1. distribute-lft-outN/A

            \[\leadsto d1 \cdot \color{blue}{\left(d2 + \left(d4 - d1\right)\right)} \]
          2. sub-negN/A

            \[\leadsto d1 \cdot \left(d2 + \left(d4 + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right)\right) \]
          3. mul-1-negN/A

            \[\leadsto d1 \cdot \left(d2 + \left(d4 + -1 \cdot \color{blue}{d1}\right)\right) \]
          4. *-lowering-*.f64N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(d2 + \left(d4 + -1 \cdot d1\right)\right)}\right) \]
          5. associate-+r+N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right)\right) \]
          6. mul-1-negN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + d4\right) + \left(\mathsf{neg}\left(d1\right)\right)\right)\right) \]
          7. unsub-negN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + d4\right) - \color{blue}{d1}\right)\right) \]
          8. --lowering--.f64N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(\left(d2 + d4\right), \color{blue}{d1}\right)\right) \]
          9. +-lowering-+.f6470.5%

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(\mathsf{+.f64}\left(d2, d4\right), d1\right)\right) \]
        9. Simplified70.5%

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

          \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
        11. Step-by-step derivation
          1. *-lowering-*.f64N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(d2 - d1\right)}\right) \]
          2. --lowering--.f6456.1%

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{\_.f64}\left(d2, \color{blue}{d1}\right)\right) \]
        12. Simplified56.1%

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

        if 7.4e20 < d4

        1. Initial program 86.7%

          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. Step-by-step derivation
          1. distribute-lft-out--N/A

            \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
          2. *-commutativeN/A

            \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
          3. distribute-lft-outN/A

            \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
          4. distribute-lft-out--N/A

            \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
          5. *-lowering-*.f64N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
          6. associate-+r-N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
          7. sub-negN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
          8. associate-+l+N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
          9. +-lowering-+.f64N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
          10. +-commutativeN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
          11. unsub-negN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
          12. associate--l-N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
          13. +-commutativeN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
          14. --lowering--.f64N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
          15. +-commutativeN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
          16. +-lowering-+.f64100.0%

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
        3. Simplified100.0%

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

          \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{d4}\right)\right) \]
        6. Step-by-step derivation
          1. Simplified77.2%

            \[\leadsto d1 \cdot \left(d2 + \color{blue}{d4}\right) \]
        7. Recombined 2 regimes into one program.
        8. Add Preprocessing

        Alternative 12: 40.5% accurate, 1.9× speedup?

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

          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. distribute-lft-out--N/A

              \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
            2. *-commutativeN/A

              \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
            3. distribute-lft-outN/A

              \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
            4. distribute-lft-out--N/A

              \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
            5. *-lowering-*.f64N/A

              \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
            6. associate-+r-N/A

              \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
            7. sub-negN/A

              \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
            8. associate-+l+N/A

              \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
            9. +-lowering-+.f64N/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
            10. +-commutativeN/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
            11. unsub-negN/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
            12. associate--l-N/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
            13. +-commutativeN/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
            14. --lowering--.f64N/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
            15. +-commutativeN/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
            16. +-lowering-+.f64100.0%

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
          3. Simplified100.0%

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

            \[\leadsto \color{blue}{d1 \cdot d2} \]
          6. Step-by-step derivation
            1. *-lowering-*.f6432.5%

              \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{d2}\right) \]
          7. Simplified32.5%

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

          if 6.09999999999999981e85 < d4

          1. Initial program 86.8%

            \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
          2. Step-by-step derivation
            1. distribute-lft-out--N/A

              \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
            2. *-commutativeN/A

              \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
            3. distribute-lft-outN/A

              \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
            4. distribute-lft-out--N/A

              \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
            5. *-lowering-*.f64N/A

              \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
            6. associate-+r-N/A

              \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
            7. sub-negN/A

              \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
            8. associate-+l+N/A

              \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
            9. +-lowering-+.f64N/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
            10. +-commutativeN/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
            11. unsub-negN/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
            12. associate--l-N/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
            13. +-commutativeN/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
            14. --lowering--.f64N/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
            15. +-commutativeN/A

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
            16. +-lowering-+.f64100.0%

              \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
          3. Simplified100.0%

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

            \[\leadsto \color{blue}{d1 \cdot d4} \]
          6. Step-by-step derivation
            1. *-lowering-*.f6468.2%

              \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{d4}\right) \]
          7. Simplified68.2%

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

        Alternative 13: 31.3% accurate, 5.0× speedup?

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

          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. Step-by-step derivation
          1. distribute-lft-out--N/A

            \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
          2. *-commutativeN/A

            \[\leadsto \left(d1 \cdot \left(d2 - d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
          3. distribute-lft-outN/A

            \[\leadsto d1 \cdot \left(\left(d2 - d3\right) + d4\right) - \color{blue}{d1} \cdot d1 \]
          4. distribute-lft-out--N/A

            \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)} \]
          5. *-lowering-*.f64N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{\left(\left(\left(d2 - d3\right) + d4\right) - d1\right)}\right) \]
          6. associate-+r-N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 - d3\right) + \color{blue}{\left(d4 - d1\right)}\right)\right) \]
          7. sub-negN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \left(\left(d2 + \left(\mathsf{neg}\left(d3\right)\right)\right) + \left(\color{blue}{d4} - d1\right)\right)\right) \]
          8. associate-+l+N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \left(d2 + \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
          9. +-lowering-+.f64N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \color{blue}{\left(\left(\mathsf{neg}\left(d3\right)\right) + \left(d4 - d1\right)\right)}\right)\right) \]
          10. +-commutativeN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) + \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)}\right)\right)\right) \]
          11. unsub-negN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(\left(d4 - d1\right) - \color{blue}{d3}\right)\right)\right) \]
          12. associate--l-N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \color{blue}{\left(d1 + d3\right)}\right)\right)\right) \]
          13. +-commutativeN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \left(d4 - \left(d3 + \color{blue}{d1}\right)\right)\right)\right) \]
          14. --lowering--.f64N/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \color{blue}{\left(d3 + d1\right)}\right)\right)\right) \]
          15. +-commutativeN/A

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \left(d1 + \color{blue}{d3}\right)\right)\right)\right) \]
          16. +-lowering-+.f64100.0%

            \[\leadsto \mathsf{*.f64}\left(d1, \mathsf{+.f64}\left(d2, \mathsf{\_.f64}\left(d4, \mathsf{+.f64}\left(d1, \color{blue}{d3}\right)\right)\right)\right) \]
        3. Simplified100.0%

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

          \[\leadsto \color{blue}{d1 \cdot d2} \]
        6. Step-by-step derivation
          1. *-lowering-*.f6429.0%

            \[\leadsto \mathsf{*.f64}\left(d1, \color{blue}{d2}\right) \]
        7. Simplified29.0%

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

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

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

        Reproduce

        ?
        herbie shell --seed 2024161 
        (FPCore (d1 d2 d3 d4)
          :name "FastMath dist4"
          :precision binary64
        
          :alt
          (! :herbie-platform default (* d1 (- (+ (- d2 d3) d4) d1)))
        
          (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))