Data.Metrics.Snapshot:quantile from metrics-0.3.0.2

Percentage Accurate: 100.0% → 100.0%
Time: 9.1s
Alternatives: 10
Speedup: 1.2×

Specification

?
\[\begin{array}{l} \\ x + \left(y - z\right) \cdot \left(t - x\right) \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
	return x + ((y - z) * (t - x));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
	return x + ((y - z) * (t - x));
}
def code(x, y, z, t):
	return x + ((y - z) * (t - x))
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y - z) * Float64(t - x)))
end
function tmp = code(x, y, z, t)
	tmp = x + ((y - z) * (t - x));
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \left(y - z\right) \cdot \left(t - x\right)
\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 10 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: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \left(y - z\right) \cdot \left(t - x\right) \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
	return x + ((y - z) * (t - x));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
	return x + ((y - z) * (t - x));
}
def code(x, y, z, t):
	return x + ((y - z) * (t - x))
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y - z) * Float64(t - x)))
end
function tmp = code(x, y, z, t)
	tmp = x + ((y - z) * (t - x));
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}

Alternative 1: 100.0% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(t - x, y - z, x\right) \end{array} \]
(FPCore (x y z t) :precision binary64 (fma (- t x) (- y z) x))
double code(double x, double y, double z, double t) {
	return fma((t - x), (y - z), x);
}
function code(x, y, z, t)
	return fma(Float64(t - x), Float64(y - z), x)
end
code[x_, y_, z_, t_] := N[(N[(t - x), $MachinePrecision] * N[(y - z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(t - x, y - z, x\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[x + \left(y - z\right) \cdot \left(t - x\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{t \cdot \left(y - z\right) + x \cdot \left(1 + -1 \cdot \left(y - z\right)\right)} \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto t \cdot \left(y - z\right) + x \cdot \color{blue}{\left(-1 \cdot \left(y - z\right) + 1\right)} \]
    2. distribute-lft-inN/A

      \[\leadsto t \cdot \left(y - z\right) + \color{blue}{\left(x \cdot \left(-1 \cdot \left(y - z\right)\right) + x \cdot 1\right)} \]
    3. mul-1-negN/A

      \[\leadsto t \cdot \left(y - z\right) + \left(x \cdot \color{blue}{\left(\mathsf{neg}\left(\left(y - z\right)\right)\right)} + x \cdot 1\right) \]
    4. distribute-rgt-neg-inN/A

      \[\leadsto t \cdot \left(y - z\right) + \left(\color{blue}{\left(\mathsf{neg}\left(x \cdot \left(y - z\right)\right)\right)} + x \cdot 1\right) \]
    5. mul-1-negN/A

      \[\leadsto t \cdot \left(y - z\right) + \left(\color{blue}{-1 \cdot \left(x \cdot \left(y - z\right)\right)} + x \cdot 1\right) \]
    6. *-rgt-identityN/A

      \[\leadsto t \cdot \left(y - z\right) + \left(-1 \cdot \left(x \cdot \left(y - z\right)\right) + \color{blue}{x}\right) \]
    7. associate-+l+N/A

      \[\leadsto \color{blue}{\left(t \cdot \left(y - z\right) + -1 \cdot \left(x \cdot \left(y - z\right)\right)\right) + x} \]
    8. +-commutativeN/A

      \[\leadsto \color{blue}{\left(-1 \cdot \left(x \cdot \left(y - z\right)\right) + t \cdot \left(y - z\right)\right)} + x \]
    9. +-commutativeN/A

      \[\leadsto \color{blue}{\left(t \cdot \left(y - z\right) + -1 \cdot \left(x \cdot \left(y - z\right)\right)\right)} + x \]
    10. mul-1-negN/A

      \[\leadsto \left(t \cdot \left(y - z\right) + \color{blue}{\left(\mathsf{neg}\left(x \cdot \left(y - z\right)\right)\right)}\right) + x \]
    11. unsub-negN/A

      \[\leadsto \color{blue}{\left(t \cdot \left(y - z\right) - x \cdot \left(y - z\right)\right)} + x \]
    12. distribute-rgt-out--N/A

      \[\leadsto \color{blue}{\left(y - z\right) \cdot \left(t - x\right)} + x \]
    13. *-commutativeN/A

      \[\leadsto \color{blue}{\left(t - x\right) \cdot \left(y - z\right)} + x \]
    14. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(t - x, y - z, x\right)} \]
    15. lower--.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{t - x}, y - z, x\right) \]
    16. lower--.f64100.0

      \[\leadsto \mathsf{fma}\left(t - x, \color{blue}{y - z}, x\right) \]
  5. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(t - x, y - z, x\right)} \]
  6. Add Preprocessing

Alternative 2: 68.3% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(t - x\right) \cdot y\\ \mathbf{if}\;y \leq -3.2 \cdot 10^{-13}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 1.06 \cdot 10^{-150}:\\ \;\;\;\;\mathsf{fma}\left(x, z, x\right)\\ \mathbf{elif}\;y \leq 92000000000:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* (- t x) y)))
   (if (<= y -3.2e-13)
     t_1
     (if (<= y 1.06e-150)
       (fma x z x)
       (if (<= y 92000000000.0) (* z (- x t)) t_1)))))
double code(double x, double y, double z, double t) {
	double t_1 = (t - x) * y;
	double tmp;
	if (y <= -3.2e-13) {
		tmp = t_1;
	} else if (y <= 1.06e-150) {
		tmp = fma(x, z, x);
	} else if (y <= 92000000000.0) {
		tmp = z * (x - t);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	t_1 = Float64(Float64(t - x) * y)
	tmp = 0.0
	if (y <= -3.2e-13)
		tmp = t_1;
	elseif (y <= 1.06e-150)
		tmp = fma(x, z, x);
	elseif (y <= 92000000000.0)
		tmp = Float64(z * Float64(x - t));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -3.2e-13], t$95$1, If[LessEqual[y, 1.06e-150], N[(x * z + x), $MachinePrecision], If[LessEqual[y, 92000000000.0], N[(z * N[(x - t), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot y\\
\mathbf{if}\;y \leq -3.2 \cdot 10^{-13}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 1.06 \cdot 10^{-150}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\

\mathbf{elif}\;y \leq 92000000000:\\
\;\;\;\;z \cdot \left(x - t\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -3.2e-13 or 9.2e10 < y

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(t - x\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(t - x\right) \cdot y} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(t - x\right) \cdot y} \]
      3. lower--.f6478.7

        \[\leadsto \color{blue}{\left(t - x\right)} \cdot y \]
    5. Simplified78.7%

      \[\leadsto \color{blue}{\left(t - x\right) \cdot y} \]

    if -3.2e-13 < y < 1.05999999999999996e-150

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot \left(y - z\right)\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(-1 \cdot \left(y - z\right) + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{x \cdot \left(-1 \cdot \left(y - z\right)\right) + x \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto x \cdot \left(-1 \cdot \left(y - z\right)\right) + \color{blue}{x} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, -1 \cdot \left(y - z\right), x\right)} \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\mathsf{neg}\left(\left(y - z\right)\right)}, x\right) \]
      6. sub-negN/A

        \[\leadsto \mathsf{fma}\left(x, \mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(z\right)\right)\right)}\right), x\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x, \mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(z\right)\right) + y\right)}\right), x\right) \]
      8. distribute-neg-inN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}, x\right) \]
      9. unsub-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) - y}, x\right) \]
      10. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{z} - y, x\right) \]
      11. lower--.f6473.4

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{z - y}, x\right) \]
    5. Simplified73.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, z - y, x\right)} \]
    6. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x + x \cdot z} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{x \cdot z + x} \]
      2. lower-fma.f6473.4

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, z, x\right)} \]
    8. Simplified73.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, z, x\right)} \]

    if 1.05999999999999996e-150 < y < 9.2e10

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \left(t - x\right)\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(z \cdot \left(t - x\right)\right)} \]
      2. distribute-rgt-neg-inN/A

        \[\leadsto \color{blue}{z \cdot \left(\mathsf{neg}\left(\left(t - x\right)\right)\right)} \]
      3. mul-1-negN/A

        \[\leadsto z \cdot \color{blue}{\left(-1 \cdot \left(t - x\right)\right)} \]
      4. lower-*.f64N/A

        \[\leadsto \color{blue}{z \cdot \left(-1 \cdot \left(t - x\right)\right)} \]
      5. mul-1-negN/A

        \[\leadsto z \cdot \color{blue}{\left(\mathsf{neg}\left(\left(t - x\right)\right)\right)} \]
      6. sub-negN/A

        \[\leadsto z \cdot \left(\mathsf{neg}\left(\color{blue}{\left(t + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right) \]
      7. +-commutativeN/A

        \[\leadsto z \cdot \left(\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + t\right)}\right)\right) \]
      8. distribute-neg-inN/A

        \[\leadsto z \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(t\right)\right)\right)} \]
      9. unsub-negN/A

        \[\leadsto z \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) - t\right)} \]
      10. remove-double-negN/A

        \[\leadsto z \cdot \left(\color{blue}{x} - t\right) \]
      11. lower--.f6468.4

        \[\leadsto z \cdot \color{blue}{\left(x - t\right)} \]
    5. Simplified68.4%

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

Alternative 3: 49.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -2.2 \cdot 10^{+263}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq -1.55 \cdot 10^{+142}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 0.72:\\ \;\;\;\;\mathsf{fma}\left(x, z, x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* y (- x))))
   (if (<= y -2.2e+263)
     (* t y)
     (if (<= y -1.55e+142) t_1 (if (<= y 0.72) (fma x z x) t_1)))))
double code(double x, double y, double z, double t) {
	double t_1 = y * -x;
	double tmp;
	if (y <= -2.2e+263) {
		tmp = t * y;
	} else if (y <= -1.55e+142) {
		tmp = t_1;
	} else if (y <= 0.72) {
		tmp = fma(x, z, x);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	t_1 = Float64(y * Float64(-x))
	tmp = 0.0
	if (y <= -2.2e+263)
		tmp = Float64(t * y);
	elseif (y <= -1.55e+142)
		tmp = t_1;
	elseif (y <= 0.72)
		tmp = fma(x, z, x);
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -2.2e+263], N[(t * y), $MachinePrecision], If[LessEqual[y, -1.55e+142], t$95$1, If[LessEqual[y, 0.72], N[(x * z + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -2.2 \cdot 10^{+263}:\\
\;\;\;\;t \cdot y\\

\mathbf{elif}\;y \leq -1.55 \cdot 10^{+142}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 0.72:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -2.2e263

    1. Initial program 99.9%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
      2. lower--.f6468.2

        \[\leadsto t \cdot \color{blue}{\left(y - z\right)} \]
    5. Simplified68.2%

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    6. Taylor expanded in y around inf

      \[\leadsto \color{blue}{t \cdot y} \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot t} \]
      2. lower-*.f6467.5

        \[\leadsto \color{blue}{y \cdot t} \]
    8. Simplified67.5%

      \[\leadsto \color{blue}{y \cdot t} \]

    if -2.2e263 < y < -1.55e142 or 0.71999999999999997 < y

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(t - x\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(t - x\right) \cdot y} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(t - x\right) \cdot y} \]
      3. lower--.f6483.3

        \[\leadsto \color{blue}{\left(t - x\right)} \cdot y \]
    5. Simplified83.3%

      \[\leadsto \color{blue}{\left(t - x\right) \cdot y} \]
    6. Taylor expanded in t around 0

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

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot y \]
      2. lower-neg.f6450.3

        \[\leadsto \color{blue}{\left(-x\right)} \cdot y \]
    8. Simplified50.3%

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

    if -1.55e142 < y < 0.71999999999999997

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot \left(y - z\right)\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(-1 \cdot \left(y - z\right) + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{x \cdot \left(-1 \cdot \left(y - z\right)\right) + x \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto x \cdot \left(-1 \cdot \left(y - z\right)\right) + \color{blue}{x} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, -1 \cdot \left(y - z\right), x\right)} \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\mathsf{neg}\left(\left(y - z\right)\right)}, x\right) \]
      6. sub-negN/A

        \[\leadsto \mathsf{fma}\left(x, \mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(z\right)\right)\right)}\right), x\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x, \mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(z\right)\right) + y\right)}\right), x\right) \]
      8. distribute-neg-inN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}, x\right) \]
      9. unsub-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) - y}, x\right) \]
      10. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{z} - y, x\right) \]
      11. lower--.f6464.5

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{z - y}, x\right) \]
    5. Simplified64.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, z - y, x\right)} \]
    6. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x + x \cdot z} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{x \cdot z + x} \]
      2. lower-fma.f6460.8

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, z, x\right)} \]
    8. Simplified60.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, z, x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification57.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.2 \cdot 10^{+263}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq -1.55 \cdot 10^{+142}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq 0.72:\\ \;\;\;\;\mathsf{fma}\left(x, z, x\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 46.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.000105:\\ \;\;\;\;\mathsf{fma}\left(x, z, x\right)\\ \mathbf{elif}\;x \leq -6 \cdot 10^{-100}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;x \leq 1.26 \cdot 10^{-48}:\\ \;\;\;\;-t \cdot z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, z, x\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= x -0.000105)
   (fma x z x)
   (if (<= x -6e-100) (* t y) (if (<= x 1.26e-48) (- (* t z)) (fma x z x)))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -0.000105) {
		tmp = fma(x, z, x);
	} else if (x <= -6e-100) {
		tmp = t * y;
	} else if (x <= 1.26e-48) {
		tmp = -(t * z);
	} else {
		tmp = fma(x, z, x);
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if (x <= -0.000105)
		tmp = fma(x, z, x);
	elseif (x <= -6e-100)
		tmp = Float64(t * y);
	elseif (x <= 1.26e-48)
		tmp = Float64(-Float64(t * z));
	else
		tmp = fma(x, z, x);
	end
	return tmp
end
code[x_, y_, z_, t_] := If[LessEqual[x, -0.000105], N[(x * z + x), $MachinePrecision], If[LessEqual[x, -6e-100], N[(t * y), $MachinePrecision], If[LessEqual[x, 1.26e-48], (-N[(t * z), $MachinePrecision]), N[(x * z + x), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.000105:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\

\mathbf{elif}\;x \leq -6 \cdot 10^{-100}:\\
\;\;\;\;t \cdot y\\

\mathbf{elif}\;x \leq 1.26 \cdot 10^{-48}:\\
\;\;\;\;-t \cdot z\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.05e-4 or 1.2599999999999999e-48 < x

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot \left(y - z\right)\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(-1 \cdot \left(y - z\right) + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{x \cdot \left(-1 \cdot \left(y - z\right)\right) + x \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto x \cdot \left(-1 \cdot \left(y - z\right)\right) + \color{blue}{x} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, -1 \cdot \left(y - z\right), x\right)} \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\mathsf{neg}\left(\left(y - z\right)\right)}, x\right) \]
      6. sub-negN/A

        \[\leadsto \mathsf{fma}\left(x, \mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(z\right)\right)\right)}\right), x\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x, \mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(z\right)\right) + y\right)}\right), x\right) \]
      8. distribute-neg-inN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}, x\right) \]
      9. unsub-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) - y}, x\right) \]
      10. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{z} - y, x\right) \]
      11. lower--.f6484.7

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{z - y}, x\right) \]
    5. Simplified84.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, z - y, x\right)} \]
    6. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x + x \cdot z} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{x \cdot z + x} \]
      2. lower-fma.f6460.9

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, z, x\right)} \]
    8. Simplified60.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, z, x\right)} \]

    if -1.05e-4 < x < -6.0000000000000001e-100

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
      2. lower--.f6459.6

        \[\leadsto t \cdot \color{blue}{\left(y - z\right)} \]
    5. Simplified59.6%

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    6. Taylor expanded in y around inf

      \[\leadsto \color{blue}{t \cdot y} \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot t} \]
      2. lower-*.f6446.0

        \[\leadsto \color{blue}{y \cdot t} \]
    8. Simplified46.0%

      \[\leadsto \color{blue}{y \cdot t} \]

    if -6.0000000000000001e-100 < x < 1.2599999999999999e-48

    1. Initial program 99.9%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
      2. lower--.f6477.9

        \[\leadsto t \cdot \color{blue}{\left(y - z\right)} \]
    5. Simplified77.9%

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    6. Taylor expanded in y around 0

      \[\leadsto \color{blue}{-1 \cdot \left(t \cdot z\right)} \]
    7. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \color{blue}{\left(-1 \cdot t\right) \cdot z} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{z \cdot \left(-1 \cdot t\right)} \]
      3. lower-*.f64N/A

        \[\leadsto \color{blue}{z \cdot \left(-1 \cdot t\right)} \]
      4. mul-1-negN/A

        \[\leadsto z \cdot \color{blue}{\left(\mathsf{neg}\left(t\right)\right)} \]
      5. lower-neg.f6447.7

        \[\leadsto z \cdot \color{blue}{\left(-t\right)} \]
    8. Simplified47.7%

      \[\leadsto \color{blue}{z \cdot \left(-t\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification55.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.000105:\\ \;\;\;\;\mathsf{fma}\left(x, z, x\right)\\ \mathbf{elif}\;x \leq -6 \cdot 10^{-100}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;x \leq 1.26 \cdot 10^{-48}:\\ \;\;\;\;-t \cdot z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, z, x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 83.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -6 \cdot 10^{+102}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+22}:\\ \;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* z (- x t))))
   (if (<= z -6e+102) t_1 (if (<= z 9e+22) (fma (- t x) y x) t_1))))
double code(double x, double y, double z, double t) {
	double t_1 = z * (x - t);
	double tmp;
	if (z <= -6e+102) {
		tmp = t_1;
	} else if (z <= 9e+22) {
		tmp = fma((t - x), y, x);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	t_1 = Float64(z * Float64(x - t))
	tmp = 0.0
	if (z <= -6e+102)
		tmp = t_1;
	elseif (z <= 9e+22)
		tmp = fma(Float64(t - x), y, x);
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * N[(x - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6e+102], t$95$1, If[LessEqual[z, 9e+22], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := z \cdot \left(x - t\right)\\
\mathbf{if}\;z \leq -6 \cdot 10^{+102}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;z \leq 9 \cdot 10^{+22}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -5.9999999999999996e102 or 8.9999999999999996e22 < z

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \left(t - x\right)\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(z \cdot \left(t - x\right)\right)} \]
      2. distribute-rgt-neg-inN/A

        \[\leadsto \color{blue}{z \cdot \left(\mathsf{neg}\left(\left(t - x\right)\right)\right)} \]
      3. mul-1-negN/A

        \[\leadsto z \cdot \color{blue}{\left(-1 \cdot \left(t - x\right)\right)} \]
      4. lower-*.f64N/A

        \[\leadsto \color{blue}{z \cdot \left(-1 \cdot \left(t - x\right)\right)} \]
      5. mul-1-negN/A

        \[\leadsto z \cdot \color{blue}{\left(\mathsf{neg}\left(\left(t - x\right)\right)\right)} \]
      6. sub-negN/A

        \[\leadsto z \cdot \left(\mathsf{neg}\left(\color{blue}{\left(t + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right) \]
      7. +-commutativeN/A

        \[\leadsto z \cdot \left(\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + t\right)}\right)\right) \]
      8. distribute-neg-inN/A

        \[\leadsto z \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(t\right)\right)\right)} \]
      9. unsub-negN/A

        \[\leadsto z \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) - t\right)} \]
      10. remove-double-negN/A

        \[\leadsto z \cdot \left(\color{blue}{x} - t\right) \]
      11. lower--.f6483.6

        \[\leadsto z \cdot \color{blue}{\left(x - t\right)} \]
    5. Simplified83.6%

      \[\leadsto \color{blue}{z \cdot \left(x - t\right)} \]

    if -5.9999999999999996e102 < z < 8.9999999999999996e22

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in z around 0

      \[\leadsto \color{blue}{x + y \cdot \left(t - x\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{y \cdot \left(t - x\right) + x} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\left(t - x\right) \cdot y} + x \]
      3. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(t - x, y, x\right)} \]
      4. lower--.f6488.7

        \[\leadsto \mathsf{fma}\left(\color{blue}{t - x}, y, x\right) \]
    5. Simplified88.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(t - x, y, x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 76.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{fma}\left(x, z - y, x\right)\\ \mathbf{if}\;x \leq -2.7 \cdot 10^{-5}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{-17}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (fma x (- z y) x)))
   (if (<= x -2.7e-5) t_1 (if (<= x 1.22e-17) (* t (- y z)) t_1))))
double code(double x, double y, double z, double t) {
	double t_1 = fma(x, (z - y), x);
	double tmp;
	if (x <= -2.7e-5) {
		tmp = t_1;
	} else if (x <= 1.22e-17) {
		tmp = t * (y - z);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	t_1 = fma(x, Float64(z - y), x)
	tmp = 0.0
	if (x <= -2.7e-5)
		tmp = t_1;
	elseif (x <= 1.22e-17)
		tmp = Float64(t * Float64(y - z));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(z - y), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[x, -2.7e-5], t$95$1, If[LessEqual[x, 1.22e-17], N[(t * N[(y - z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(x, z - y, x\right)\\
\mathbf{if}\;x \leq -2.7 \cdot 10^{-5}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq 1.22 \cdot 10^{-17}:\\
\;\;\;\;t \cdot \left(y - z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.6999999999999999e-5 or 1.22e-17 < x

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot \left(y - z\right)\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(-1 \cdot \left(y - z\right) + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{x \cdot \left(-1 \cdot \left(y - z\right)\right) + x \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto x \cdot \left(-1 \cdot \left(y - z\right)\right) + \color{blue}{x} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, -1 \cdot \left(y - z\right), x\right)} \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\mathsf{neg}\left(\left(y - z\right)\right)}, x\right) \]
      6. sub-negN/A

        \[\leadsto \mathsf{fma}\left(x, \mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(z\right)\right)\right)}\right), x\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x, \mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(z\right)\right) + y\right)}\right), x\right) \]
      8. distribute-neg-inN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}, x\right) \]
      9. unsub-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) - y}, x\right) \]
      10. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{z} - y, x\right) \]
      11. lower--.f6487.6

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{z - y}, x\right) \]
    5. Simplified87.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, z - y, x\right)} \]

    if -2.6999999999999999e-5 < x < 1.22e-17

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
      2. lower--.f6474.0

        \[\leadsto t \cdot \color{blue}{\left(y - z\right)} \]
    5. Simplified74.0%

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

Alternative 7: 62.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.00038:\\ \;\;\;\;\mathsf{fma}\left(x, z, x\right)\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{+45}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, z, x\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= x -0.00038)
   (fma x z x)
   (if (<= x 4.5e+45) (* t (- y z)) (fma x z x))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -0.00038) {
		tmp = fma(x, z, x);
	} else if (x <= 4.5e+45) {
		tmp = t * (y - z);
	} else {
		tmp = fma(x, z, x);
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if (x <= -0.00038)
		tmp = fma(x, z, x);
	elseif (x <= 4.5e+45)
		tmp = Float64(t * Float64(y - z));
	else
		tmp = fma(x, z, x);
	end
	return tmp
end
code[x_, y_, z_, t_] := If[LessEqual[x, -0.00038], N[(x * z + x), $MachinePrecision], If[LessEqual[x, 4.5e+45], N[(t * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(x * z + x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.00038:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\

\mathbf{elif}\;x \leq 4.5 \cdot 10^{+45}:\\
\;\;\;\;t \cdot \left(y - z\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.8000000000000002e-4 or 4.4999999999999998e45 < x

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot \left(y - z\right)\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(-1 \cdot \left(y - z\right) + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{x \cdot \left(-1 \cdot \left(y - z\right)\right) + x \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto x \cdot \left(-1 \cdot \left(y - z\right)\right) + \color{blue}{x} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, -1 \cdot \left(y - z\right), x\right)} \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\mathsf{neg}\left(\left(y - z\right)\right)}, x\right) \]
      6. sub-negN/A

        \[\leadsto \mathsf{fma}\left(x, \mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(z\right)\right)\right)}\right), x\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x, \mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(z\right)\right) + y\right)}\right), x\right) \]
      8. distribute-neg-inN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}, x\right) \]
      9. unsub-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) - y}, x\right) \]
      10. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{z} - y, x\right) \]
      11. lower--.f6490.7

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{z - y}, x\right) \]
    5. Simplified90.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, z - y, x\right)} \]
    6. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x + x \cdot z} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{x \cdot z + x} \]
      2. lower-fma.f6465.4

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, z, x\right)} \]
    8. Simplified65.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, z, x\right)} \]

    if -3.8000000000000002e-4 < x < 4.4999999999999998e45

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
      2. lower--.f6470.6

        \[\leadsto t \cdot \color{blue}{\left(y - z\right)} \]
    5. Simplified70.6%

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

Alternative 8: 49.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.7 \cdot 10^{+116}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-27}:\\ \;\;\;\;\mathsf{fma}\left(x, z, x\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= y -3.7e+116) (* t y) (if (<= y 1.5e-27) (fma x z x) (* t y))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= -3.7e+116) {
		tmp = t * y;
	} else if (y <= 1.5e-27) {
		tmp = fma(x, z, x);
	} else {
		tmp = t * y;
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if (y <= -3.7e+116)
		tmp = Float64(t * y);
	elseif (y <= 1.5e-27)
		tmp = fma(x, z, x);
	else
		tmp = Float64(t * y);
	end
	return tmp
end
code[x_, y_, z_, t_] := If[LessEqual[y, -3.7e+116], N[(t * y), $MachinePrecision], If[LessEqual[y, 1.5e-27], N[(x * z + x), $MachinePrecision], N[(t * y), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{+116}:\\
\;\;\;\;t \cdot y\\

\mathbf{elif}\;y \leq 1.5 \cdot 10^{-27}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\

\mathbf{else}:\\
\;\;\;\;t \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.7000000000000001e116 or 1.5000000000000001e-27 < y

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
      2. lower--.f6454.7

        \[\leadsto t \cdot \color{blue}{\left(y - z\right)} \]
    5. Simplified54.7%

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    6. Taylor expanded in y around inf

      \[\leadsto \color{blue}{t \cdot y} \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot t} \]
      2. lower-*.f6441.5

        \[\leadsto \color{blue}{y \cdot t} \]
    8. Simplified41.5%

      \[\leadsto \color{blue}{y \cdot t} \]

    if -3.7000000000000001e116 < y < 1.5000000000000001e-27

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot \left(y - z\right)\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(-1 \cdot \left(y - z\right) + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{x \cdot \left(-1 \cdot \left(y - z\right)\right) + x \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto x \cdot \left(-1 \cdot \left(y - z\right)\right) + \color{blue}{x} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, -1 \cdot \left(y - z\right), x\right)} \]
      5. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\mathsf{neg}\left(\left(y - z\right)\right)}, x\right) \]
      6. sub-negN/A

        \[\leadsto \mathsf{fma}\left(x, \mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(z\right)\right)\right)}\right), x\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x, \mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(z\right)\right) + y\right)}\right), x\right) \]
      8. distribute-neg-inN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}, x\right) \]
      9. unsub-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) - y}, x\right) \]
      10. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{z} - y, x\right) \]
      11. lower--.f6466.8

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{z - y}, x\right) \]
    5. Simplified66.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, z - y, x\right)} \]
    6. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x + x \cdot z} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{x \cdot z + x} \]
      2. lower-fma.f6462.8

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, z, x\right)} \]
    8. Simplified62.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, z, x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification53.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.7 \cdot 10^{+116}:\\ \;\;\;\;t \cdot y\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-27}:\\ \;\;\;\;\mathsf{fma}\left(x, z, x\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 35.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.000105:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{+45}:\\ \;\;\;\;t \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= x -0.000105) (* x z) (if (<= x 4.5e+45) (* t y) (* x z))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -0.000105) {
		tmp = x * z;
	} else if (x <= 4.5e+45) {
		tmp = t * y;
	} else {
		tmp = x * z;
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (x <= (-0.000105d0)) then
        tmp = x * z
    else if (x <= 4.5d+45) then
        tmp = t * y
    else
        tmp = x * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -0.000105) {
		tmp = x * z;
	} else if (x <= 4.5e+45) {
		tmp = t * y;
	} else {
		tmp = x * z;
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if x <= -0.000105:
		tmp = x * z
	elif x <= 4.5e+45:
		tmp = t * y
	else:
		tmp = x * z
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (x <= -0.000105)
		tmp = Float64(x * z);
	elseif (x <= 4.5e+45)
		tmp = Float64(t * y);
	else
		tmp = Float64(x * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (x <= -0.000105)
		tmp = x * z;
	elseif (x <= 4.5e+45)
		tmp = t * y;
	else
		tmp = x * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[LessEqual[x, -0.000105], N[(x * z), $MachinePrecision], If[LessEqual[x, 4.5e+45], N[(t * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.000105:\\
\;\;\;\;x \cdot z\\

\mathbf{elif}\;x \leq 4.5 \cdot 10^{+45}:\\
\;\;\;\;t \cdot y\\

\mathbf{else}:\\
\;\;\;\;x \cdot z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.05e-4 or 4.4999999999999998e45 < x

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \left(t - x\right)\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(z \cdot \left(t - x\right)\right)} \]
      2. distribute-rgt-neg-inN/A

        \[\leadsto \color{blue}{z \cdot \left(\mathsf{neg}\left(\left(t - x\right)\right)\right)} \]
      3. mul-1-negN/A

        \[\leadsto z \cdot \color{blue}{\left(-1 \cdot \left(t - x\right)\right)} \]
      4. lower-*.f64N/A

        \[\leadsto \color{blue}{z \cdot \left(-1 \cdot \left(t - x\right)\right)} \]
      5. mul-1-negN/A

        \[\leadsto z \cdot \color{blue}{\left(\mathsf{neg}\left(\left(t - x\right)\right)\right)} \]
      6. sub-negN/A

        \[\leadsto z \cdot \left(\mathsf{neg}\left(\color{blue}{\left(t + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right) \]
      7. +-commutativeN/A

        \[\leadsto z \cdot \left(\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + t\right)}\right)\right) \]
      8. distribute-neg-inN/A

        \[\leadsto z \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(t\right)\right)\right)} \]
      9. unsub-negN/A

        \[\leadsto z \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) - t\right)} \]
      10. remove-double-negN/A

        \[\leadsto z \cdot \left(\color{blue}{x} - t\right) \]
      11. lower--.f6443.3

        \[\leadsto z \cdot \color{blue}{\left(x - t\right)} \]
    5. Simplified43.3%

      \[\leadsto \color{blue}{z \cdot \left(x - t\right)} \]
    6. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot z} \]
    7. Step-by-step derivation
      1. lower-*.f6440.1

        \[\leadsto \color{blue}{x \cdot z} \]
    8. Simplified40.1%

      \[\leadsto \color{blue}{x \cdot z} \]

    if -1.05e-4 < x < 4.4999999999999998e45

    1. Initial program 100.0%

      \[x + \left(y - z\right) \cdot \left(t - x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
      2. lower--.f6470.6

        \[\leadsto t \cdot \color{blue}{\left(y - z\right)} \]
    5. Simplified70.6%

      \[\leadsto \color{blue}{t \cdot \left(y - z\right)} \]
    6. Taylor expanded in y around inf

      \[\leadsto \color{blue}{t \cdot y} \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot t} \]
      2. lower-*.f6438.5

        \[\leadsto \color{blue}{y \cdot t} \]
    8. Simplified38.5%

      \[\leadsto \color{blue}{y \cdot t} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification39.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.000105:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{+45}:\\ \;\;\;\;t \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 23.0% accurate, 2.5× speedup?

\[\begin{array}{l} \\ x \cdot z \end{array} \]
(FPCore (x y z t) :precision binary64 (* x z))
double code(double x, double y, double z, double t) {
	return x * z;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x * z
end function
public static double code(double x, double y, double z, double t) {
	return x * z;
}
def code(x, y, z, t):
	return x * z
function code(x, y, z, t)
	return Float64(x * z)
end
function tmp = code(x, y, z, t)
	tmp = x * z;
end
code[x_, y_, z_, t_] := N[(x * z), $MachinePrecision]
\begin{array}{l}

\\
x \cdot z
\end{array}
Derivation
  1. Initial program 100.0%

    \[x + \left(y - z\right) \cdot \left(t - x\right) \]
  2. Add Preprocessing
  3. Taylor expanded in z around inf

    \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \left(t - x\right)\right)} \]
  4. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \color{blue}{\mathsf{neg}\left(z \cdot \left(t - x\right)\right)} \]
    2. distribute-rgt-neg-inN/A

      \[\leadsto \color{blue}{z \cdot \left(\mathsf{neg}\left(\left(t - x\right)\right)\right)} \]
    3. mul-1-negN/A

      \[\leadsto z \cdot \color{blue}{\left(-1 \cdot \left(t - x\right)\right)} \]
    4. lower-*.f64N/A

      \[\leadsto \color{blue}{z \cdot \left(-1 \cdot \left(t - x\right)\right)} \]
    5. mul-1-negN/A

      \[\leadsto z \cdot \color{blue}{\left(\mathsf{neg}\left(\left(t - x\right)\right)\right)} \]
    6. sub-negN/A

      \[\leadsto z \cdot \left(\mathsf{neg}\left(\color{blue}{\left(t + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right) \]
    7. +-commutativeN/A

      \[\leadsto z \cdot \left(\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + t\right)}\right)\right) \]
    8. distribute-neg-inN/A

      \[\leadsto z \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(t\right)\right)\right)} \]
    9. unsub-negN/A

      \[\leadsto z \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) - t\right)} \]
    10. remove-double-negN/A

      \[\leadsto z \cdot \left(\color{blue}{x} - t\right) \]
    11. lower--.f6445.8

      \[\leadsto z \cdot \color{blue}{\left(x - t\right)} \]
  5. Simplified45.8%

    \[\leadsto \color{blue}{z \cdot \left(x - t\right)} \]
  6. Taylor expanded in x around inf

    \[\leadsto \color{blue}{x \cdot z} \]
  7. Step-by-step derivation
    1. lower-*.f6425.5

      \[\leadsto \color{blue}{x \cdot z} \]
  8. Simplified25.5%

    \[\leadsto \color{blue}{x \cdot z} \]
  9. Add Preprocessing

Developer Target 1: 96.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right) \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (+ x (+ (* t (- y z)) (* (- x) (- y z)))))
double code(double x, double y, double z, double t) {
	return x + ((t * (y - z)) + (-x * (y - z)));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x + ((t * (y - z)) + (-x * (y - z)))
end function
public static double code(double x, double y, double z, double t) {
	return x + ((t * (y - z)) + (-x * (y - z)));
}
def code(x, y, z, t):
	return x + ((t * (y - z)) + (-x * (y - z)))
function code(x, y, z, t)
	return Float64(x + Float64(Float64(t * Float64(y - z)) + Float64(Float64(-x) * Float64(y - z))))
end
function tmp = code(x, y, z, t)
	tmp = x + ((t * (y - z)) + (-x * (y - z)));
end
code[x_, y_, z_, t_] := N[(x + N[(N[(t * N[(y - z), $MachinePrecision]), $MachinePrecision] + N[((-x) * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right)
\end{array}

Reproduce

?
herbie shell --seed 2024215 
(FPCore (x y z t)
  :name "Data.Metrics.Snapshot:quantile from metrics-0.3.0.2"
  :precision binary64

  :alt
  (! :herbie-platform default (+ x (+ (* t (- y z)) (* (- x) (- y z)))))

  (+ x (* (- y z) (- t x))))