Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, E

Percentage Accurate: 99.7% → 99.8%
Time: 6.3s
Alternatives: 7
Speedup: 1.3×

Specification

?
\[\begin{array}{l} \\ \left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \end{array} \]
(FPCore (x) :precision binary64 (* (* 3.0 (- 2.0 (* x 3.0))) x))
double code(double x) {
	return (3.0 * (2.0 - (x * 3.0))) * x;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (3.0d0 * (2.0d0 - (x * 3.0d0))) * x
end function
public static double code(double x) {
	return (3.0 * (2.0 - (x * 3.0))) * x;
}
def code(x):
	return (3.0 * (2.0 - (x * 3.0))) * x
function code(x)
	return Float64(Float64(3.0 * Float64(2.0 - Float64(x * 3.0))) * x)
end
function tmp = code(x)
	tmp = (3.0 * (2.0 - (x * 3.0))) * x;
end
code[x_] := N[(N[(3.0 * N[(2.0 - N[(x * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}

\\
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
\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 7 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: 99.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \end{array} \]
(FPCore (x) :precision binary64 (* (* 3.0 (- 2.0 (* x 3.0))) x))
double code(double x) {
	return (3.0 * (2.0 - (x * 3.0))) * x;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (3.0d0 * (2.0d0 - (x * 3.0d0))) * x
end function
public static double code(double x) {
	return (3.0 * (2.0 - (x * 3.0))) * x;
}
def code(x):
	return (3.0 * (2.0 - (x * 3.0))) * x
function code(x)
	return Float64(Float64(3.0 * Float64(2.0 - Float64(x * 3.0))) * x)
end
function tmp = code(x)
	tmp = (3.0 * (2.0 - (x * 3.0))) * x;
end
code[x_] := N[(N[(3.0 * N[(2.0 - N[(x * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}

\\
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
\end{array}

Alternative 1: 99.8% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(x, 6, -9 \cdot {x}^{2}\right) \end{array} \]
(FPCore (x) :precision binary64 (fma x 6.0 (* -9.0 (pow x 2.0))))
double code(double x) {
	return fma(x, 6.0, (-9.0 * pow(x, 2.0)));
}
function code(x)
	return fma(x, 6.0, Float64(-9.0 * (x ^ 2.0)))
end
code[x_] := N[(x * 6.0 + N[(-9.0 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(x, 6, -9 \cdot {x}^{2}\right)
\end{array}
Derivation
  1. Initial program 99.7%

    \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
  2. Step-by-step derivation
    1. *-commutative99.7%

      \[\leadsto \color{blue}{x \cdot \left(3 \cdot \left(2 - x \cdot 3\right)\right)} \]
    2. cancel-sign-sub-inv99.7%

      \[\leadsto x \cdot \left(3 \cdot \color{blue}{\left(2 + \left(-x\right) \cdot 3\right)}\right) \]
    3. distribute-rgt-in99.7%

      \[\leadsto x \cdot \color{blue}{\left(2 \cdot 3 + \left(\left(-x\right) \cdot 3\right) \cdot 3\right)} \]
    4. metadata-eval99.7%

      \[\leadsto x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]
    5. distribute-lft-neg-out99.7%

      \[\leadsto x \cdot \left(6 + \color{blue}{\left(-x \cdot 3\right)} \cdot 3\right) \]
    6. distribute-rgt-neg-in99.7%

      \[\leadsto x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]
    7. associate-*l*99.8%

      \[\leadsto x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]
    8. metadata-eval99.8%

      \[\leadsto x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]
    9. metadata-eval99.8%

      \[\leadsto x \cdot \left(6 + x \cdot \color{blue}{-9}\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. distribute-lft-in99.8%

      \[\leadsto \color{blue}{x \cdot 6 + x \cdot \left(x \cdot -9\right)} \]
    2. fma-def99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 6, x \cdot \left(x \cdot -9\right)\right)} \]
    3. *-commutative99.8%

      \[\leadsto \mathsf{fma}\left(x, 6, \color{blue}{\left(x \cdot -9\right) \cdot x}\right) \]
    4. *-commutative99.8%

      \[\leadsto \mathsf{fma}\left(x, 6, \color{blue}{\left(-9 \cdot x\right)} \cdot x\right) \]
    5. associate-*l*99.8%

      \[\leadsto \mathsf{fma}\left(x, 6, \color{blue}{-9 \cdot \left(x \cdot x\right)}\right) \]
    6. pow299.8%

      \[\leadsto \mathsf{fma}\left(x, 6, -9 \cdot \color{blue}{{x}^{2}}\right) \]
  6. Applied egg-rr99.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, 6, -9 \cdot {x}^{2}\right)} \]
  7. Final simplification99.8%

    \[\leadsto \mathsf{fma}\left(x, 6, -9 \cdot {x}^{2}\right) \]
  8. Add Preprocessing

Alternative 2: 97.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.66:\\ \;\;\;\;x \cdot \left(x \cdot -9\right)\\ \mathbf{elif}\;x \leq 0.66:\\ \;\;\;\;x \cdot 6\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \frac{x}{\frac{1}{x}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -0.66)
   (* x (* x -9.0))
   (if (<= x 0.66) (* x 6.0) (* -9.0 (/ x (/ 1.0 x))))))
double code(double x) {
	double tmp;
	if (x <= -0.66) {
		tmp = x * (x * -9.0);
	} else if (x <= 0.66) {
		tmp = x * 6.0;
	} else {
		tmp = -9.0 * (x / (1.0 / x));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-0.66d0)) then
        tmp = x * (x * (-9.0d0))
    else if (x <= 0.66d0) then
        tmp = x * 6.0d0
    else
        tmp = (-9.0d0) * (x / (1.0d0 / x))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -0.66) {
		tmp = x * (x * -9.0);
	} else if (x <= 0.66) {
		tmp = x * 6.0;
	} else {
		tmp = -9.0 * (x / (1.0 / x));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -0.66:
		tmp = x * (x * -9.0)
	elif x <= 0.66:
		tmp = x * 6.0
	else:
		tmp = -9.0 * (x / (1.0 / x))
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -0.66)
		tmp = Float64(x * Float64(x * -9.0));
	elseif (x <= 0.66)
		tmp = Float64(x * 6.0);
	else
		tmp = Float64(-9.0 * Float64(x / Float64(1.0 / x)));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -0.66)
		tmp = x * (x * -9.0);
	elseif (x <= 0.66)
		tmp = x * 6.0;
	else
		tmp = -9.0 * (x / (1.0 / x));
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -0.66], N[(x * N[(x * -9.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.66], N[(x * 6.0), $MachinePrecision], N[(-9.0 * N[(x / N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.66:\\
\;\;\;\;x \cdot \left(x \cdot -9\right)\\

\mathbf{elif}\;x \leq 0.66:\\
\;\;\;\;x \cdot 6\\

\mathbf{else}:\\
\;\;\;\;-9 \cdot \frac{x}{\frac{1}{x}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -0.660000000000000031

    1. Initial program 99.9%

      \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{x \cdot \left(3 \cdot \left(2 - x \cdot 3\right)\right)} \]
      2. cancel-sign-sub-inv99.9%

        \[\leadsto x \cdot \left(3 \cdot \color{blue}{\left(2 + \left(-x\right) \cdot 3\right)}\right) \]
      3. distribute-rgt-in99.9%

        \[\leadsto x \cdot \color{blue}{\left(2 \cdot 3 + \left(\left(-x\right) \cdot 3\right) \cdot 3\right)} \]
      4. metadata-eval99.9%

        \[\leadsto x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]
      5. distribute-lft-neg-out99.9%

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(-x \cdot 3\right)} \cdot 3\right) \]
      6. distribute-rgt-neg-in99.9%

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]
      7. associate-*l*99.9%

        \[\leadsto x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]
      8. metadata-eval99.9%

        \[\leadsto x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]
      9. metadata-eval99.9%

        \[\leadsto x \cdot \left(6 + x \cdot \color{blue}{-9}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 97.2%

      \[\leadsto x \cdot \color{blue}{\left(-9 \cdot x\right)} \]
    6. Step-by-step derivation
      1. *-commutative97.2%

        \[\leadsto x \cdot \color{blue}{\left(x \cdot -9\right)} \]
    7. Simplified97.2%

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

    if -0.660000000000000031 < x < 0.660000000000000031

    1. Initial program 99.7%

      \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
    2. Step-by-step derivation
      1. *-commutative99.7%

        \[\leadsto \color{blue}{x \cdot \left(3 \cdot \left(2 - x \cdot 3\right)\right)} \]
      2. cancel-sign-sub-inv99.7%

        \[\leadsto x \cdot \left(3 \cdot \color{blue}{\left(2 + \left(-x\right) \cdot 3\right)}\right) \]
      3. distribute-rgt-in99.7%

        \[\leadsto x \cdot \color{blue}{\left(2 \cdot 3 + \left(\left(-x\right) \cdot 3\right) \cdot 3\right)} \]
      4. metadata-eval99.7%

        \[\leadsto x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]
      5. distribute-lft-neg-out99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(-x \cdot 3\right)} \cdot 3\right) \]
      6. distribute-rgt-neg-in99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]
      7. associate-*l*99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]
      8. metadata-eval99.7%

        \[\leadsto x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]
      9. metadata-eval99.7%

        \[\leadsto x \cdot \left(6 + x \cdot \color{blue}{-9}\right) \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 96.3%

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

    if 0.660000000000000031 < x

    1. Initial program 99.6%

      \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
    2. Step-by-step derivation
      1. *-commutative99.6%

        \[\leadsto \color{blue}{x \cdot \left(3 \cdot \left(2 - x \cdot 3\right)\right)} \]
      2. cancel-sign-sub-inv99.6%

        \[\leadsto x \cdot \left(3 \cdot \color{blue}{\left(2 + \left(-x\right) \cdot 3\right)}\right) \]
      3. distribute-rgt-in99.6%

        \[\leadsto x \cdot \color{blue}{\left(2 \cdot 3 + \left(\left(-x\right) \cdot 3\right) \cdot 3\right)} \]
      4. metadata-eval99.6%

        \[\leadsto x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]
      5. distribute-lft-neg-out99.6%

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

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]
      7. associate-*l*99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]
      8. metadata-eval99.7%

        \[\leadsto x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]
      9. metadata-eval99.7%

        \[\leadsto x \cdot \left(6 + x \cdot \color{blue}{-9}\right) \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative99.7%

        \[\leadsto \color{blue}{\left(6 + x \cdot -9\right) \cdot x} \]
      2. flip-+98.1%

        \[\leadsto \color{blue}{\frac{6 \cdot 6 - \left(x \cdot -9\right) \cdot \left(x \cdot -9\right)}{6 - x \cdot -9}} \cdot x \]
      3. associate-*l/83.2%

        \[\leadsto \color{blue}{\frac{\left(6 \cdot 6 - \left(x \cdot -9\right) \cdot \left(x \cdot -9\right)\right) \cdot x}{6 - x \cdot -9}} \]
      4. metadata-eval83.2%

        \[\leadsto \frac{\left(\color{blue}{36} - \left(x \cdot -9\right) \cdot \left(x \cdot -9\right)\right) \cdot x}{6 - x \cdot -9} \]
      5. swap-sqr83.2%

        \[\leadsto \frac{\left(36 - \color{blue}{\left(x \cdot x\right) \cdot \left(-9 \cdot -9\right)}\right) \cdot x}{6 - x \cdot -9} \]
      6. pow283.2%

        \[\leadsto \frac{\left(36 - \color{blue}{{x}^{2}} \cdot \left(-9 \cdot -9\right)\right) \cdot x}{6 - x \cdot -9} \]
      7. metadata-eval83.2%

        \[\leadsto \frac{\left(36 - {x}^{2} \cdot \color{blue}{81}\right) \cdot x}{6 - x \cdot -9} \]
      8. *-commutative83.2%

        \[\leadsto \frac{\left(36 - {x}^{2} \cdot 81\right) \cdot x}{6 - \color{blue}{-9 \cdot x}} \]
      9. cancel-sign-sub-inv83.2%

        \[\leadsto \frac{\left(36 - {x}^{2} \cdot 81\right) \cdot x}{\color{blue}{6 + \left(--9\right) \cdot x}} \]
      10. metadata-eval83.2%

        \[\leadsto \frac{\left(36 - {x}^{2} \cdot 81\right) \cdot x}{6 + \color{blue}{9} \cdot x} \]
    6. Applied egg-rr83.2%

      \[\leadsto \color{blue}{\frac{\left(36 - {x}^{2} \cdot 81\right) \cdot x}{6 + 9 \cdot x}} \]
    7. Step-by-step derivation
      1. frac-2neg83.2%

        \[\leadsto \color{blue}{\frac{-\left(36 - {x}^{2} \cdot 81\right) \cdot x}{-\left(6 + 9 \cdot x\right)}} \]
      2. div-inv83.2%

        \[\leadsto \color{blue}{\left(-\left(36 - {x}^{2} \cdot 81\right) \cdot x\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)}} \]
      3. *-commutative83.2%

        \[\leadsto \left(-\color{blue}{x \cdot \left(36 - {x}^{2} \cdot 81\right)}\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
      4. distribute-rgt-neg-in83.2%

        \[\leadsto \color{blue}{\left(x \cdot \left(-\left(36 - {x}^{2} \cdot 81\right)\right)\right)} \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
      5. sub-neg83.2%

        \[\leadsto \left(x \cdot \left(-\color{blue}{\left(36 + \left(-{x}^{2} \cdot 81\right)\right)}\right)\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
      6. distribute-rgt-neg-in83.2%

        \[\leadsto \left(x \cdot \left(-\left(36 + \color{blue}{{x}^{2} \cdot \left(-81\right)}\right)\right)\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
      7. metadata-eval83.2%

        \[\leadsto \left(x \cdot \left(-\left(36 + {x}^{2} \cdot \color{blue}{-81}\right)\right)\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
      8. +-commutative83.2%

        \[\leadsto \left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot \frac{1}{-\color{blue}{\left(9 \cdot x + 6\right)}} \]
      9. *-commutative83.2%

        \[\leadsto \left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot \frac{1}{-\left(\color{blue}{x \cdot 9} + 6\right)} \]
      10. fma-def83.2%

        \[\leadsto \left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot \frac{1}{-\color{blue}{\mathsf{fma}\left(x, 9, 6\right)}} \]
    8. Applied egg-rr83.2%

      \[\leadsto \color{blue}{\left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot \frac{1}{-\mathsf{fma}\left(x, 9, 6\right)}} \]
    9. Step-by-step derivation
      1. associate-*r/83.2%

        \[\leadsto \color{blue}{\frac{\left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot 1}{-\mathsf{fma}\left(x, 9, 6\right)}} \]
      2. *-rgt-identity83.2%

        \[\leadsto \frac{\color{blue}{x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)}}{-\mathsf{fma}\left(x, 9, 6\right)} \]
      3. associate-/l*98.0%

        \[\leadsto \color{blue}{\frac{x}{\frac{-\mathsf{fma}\left(x, 9, 6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}}} \]
      4. fma-udef98.0%

        \[\leadsto \frac{x}{\frac{-\color{blue}{\left(x \cdot 9 + 6\right)}}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      5. distribute-neg-in98.0%

        \[\leadsto \frac{x}{\frac{\color{blue}{\left(-x \cdot 9\right) + \left(-6\right)}}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      6. *-commutative98.0%

        \[\leadsto \frac{x}{\frac{\left(-\color{blue}{9 \cdot x}\right) + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      7. metadata-eval98.0%

        \[\leadsto \frac{x}{\frac{\left(-\color{blue}{\left(--9\right)} \cdot x\right) + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      8. distribute-lft-neg-in98.0%

        \[\leadsto \frac{x}{\frac{\left(-\color{blue}{\left(--9 \cdot x\right)}\right) + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      9. remove-double-neg98.0%

        \[\leadsto \frac{x}{\frac{\color{blue}{-9 \cdot x} + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      10. *-commutative98.0%

        \[\leadsto \frac{x}{\frac{\color{blue}{x \cdot -9} + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      11. metadata-eval98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + \color{blue}{-6}}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      12. +-commutative98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{-\color{blue}{\left({x}^{2} \cdot -81 + 36\right)}}} \]
      13. distribute-neg-in98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{\color{blue}{\left(-{x}^{2} \cdot -81\right) + \left(-36\right)}}} \]
      14. distribute-rgt-neg-in98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{\color{blue}{{x}^{2} \cdot \left(--81\right)} + \left(-36\right)}} \]
      15. metadata-eval98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{{x}^{2} \cdot \color{blue}{81} + \left(-36\right)}} \]
      16. fma-def98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{\color{blue}{\mathsf{fma}\left({x}^{2}, 81, -36\right)}}} \]
      17. metadata-eval98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{\mathsf{fma}\left({x}^{2}, 81, \color{blue}{-36}\right)}} \]
    10. Simplified98.0%

      \[\leadsto \color{blue}{\frac{x}{\frac{x \cdot -9 + -6}{\mathsf{fma}\left({x}^{2}, 81, -36\right)}}} \]
    11. Taylor expanded in x around inf 97.3%

      \[\leadsto \frac{x}{\color{blue}{\frac{-0.1111111111111111}{x}}} \]
    12. Step-by-step derivation
      1. *-un-lft-identity97.3%

        \[\leadsto \frac{\color{blue}{1 \cdot x}}{\frac{-0.1111111111111111}{x}} \]
      2. div-inv97.2%

        \[\leadsto \frac{1 \cdot x}{\color{blue}{-0.1111111111111111 \cdot \frac{1}{x}}} \]
      3. times-frac97.3%

        \[\leadsto \color{blue}{\frac{1}{-0.1111111111111111} \cdot \frac{x}{\frac{1}{x}}} \]
      4. metadata-eval97.3%

        \[\leadsto \color{blue}{-9} \cdot \frac{x}{\frac{1}{x}} \]
    13. Applied egg-rr97.3%

      \[\leadsto \color{blue}{-9 \cdot \frac{x}{\frac{1}{x}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.66:\\ \;\;\;\;x \cdot \left(x \cdot -9\right)\\ \mathbf{elif}\;x \leq 0.66:\\ \;\;\;\;x \cdot 6\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \frac{x}{\frac{1}{x}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 97.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.66 \lor \neg \left(x \leq 0.66\right):\\ \;\;\;\;x \cdot \left(x \cdot -9\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 6\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (or (<= x -0.66) (not (<= x 0.66))) (* x (* x -9.0)) (* x 6.0)))
double code(double x) {
	double tmp;
	if ((x <= -0.66) || !(x <= 0.66)) {
		tmp = x * (x * -9.0);
	} else {
		tmp = x * 6.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((x <= (-0.66d0)) .or. (.not. (x <= 0.66d0))) then
        tmp = x * (x * (-9.0d0))
    else
        tmp = x * 6.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if ((x <= -0.66) || !(x <= 0.66)) {
		tmp = x * (x * -9.0);
	} else {
		tmp = x * 6.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (x <= -0.66) or not (x <= 0.66):
		tmp = x * (x * -9.0)
	else:
		tmp = x * 6.0
	return tmp
function code(x)
	tmp = 0.0
	if ((x <= -0.66) || !(x <= 0.66))
		tmp = Float64(x * Float64(x * -9.0));
	else
		tmp = Float64(x * 6.0);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if ((x <= -0.66) || ~((x <= 0.66)))
		tmp = x * (x * -9.0);
	else
		tmp = x * 6.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[Or[LessEqual[x, -0.66], N[Not[LessEqual[x, 0.66]], $MachinePrecision]], N[(x * N[(x * -9.0), $MachinePrecision]), $MachinePrecision], N[(x * 6.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.66 \lor \neg \left(x \leq 0.66\right):\\
\;\;\;\;x \cdot \left(x \cdot -9\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -0.660000000000000031 or 0.660000000000000031 < x

    1. Initial program 99.7%

      \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
    2. Step-by-step derivation
      1. *-commutative99.7%

        \[\leadsto \color{blue}{x \cdot \left(3 \cdot \left(2 - x \cdot 3\right)\right)} \]
      2. cancel-sign-sub-inv99.7%

        \[\leadsto x \cdot \left(3 \cdot \color{blue}{\left(2 + \left(-x\right) \cdot 3\right)}\right) \]
      3. distribute-rgt-in99.7%

        \[\leadsto x \cdot \color{blue}{\left(2 \cdot 3 + \left(\left(-x\right) \cdot 3\right) \cdot 3\right)} \]
      4. metadata-eval99.7%

        \[\leadsto x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]
      5. distribute-lft-neg-out99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(-x \cdot 3\right)} \cdot 3\right) \]
      6. distribute-rgt-neg-in99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]
      7. associate-*l*99.8%

        \[\leadsto x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]
      8. metadata-eval99.8%

        \[\leadsto x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]
      9. metadata-eval99.8%

        \[\leadsto x \cdot \left(6 + x \cdot \color{blue}{-9}\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 97.2%

      \[\leadsto x \cdot \color{blue}{\left(-9 \cdot x\right)} \]
    6. Step-by-step derivation
      1. *-commutative97.2%

        \[\leadsto x \cdot \color{blue}{\left(x \cdot -9\right)} \]
    7. Simplified97.2%

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

    if -0.660000000000000031 < x < 0.660000000000000031

    1. Initial program 99.7%

      \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
    2. Step-by-step derivation
      1. *-commutative99.7%

        \[\leadsto \color{blue}{x \cdot \left(3 \cdot \left(2 - x \cdot 3\right)\right)} \]
      2. cancel-sign-sub-inv99.7%

        \[\leadsto x \cdot \left(3 \cdot \color{blue}{\left(2 + \left(-x\right) \cdot 3\right)}\right) \]
      3. distribute-rgt-in99.7%

        \[\leadsto x \cdot \color{blue}{\left(2 \cdot 3 + \left(\left(-x\right) \cdot 3\right) \cdot 3\right)} \]
      4. metadata-eval99.7%

        \[\leadsto x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]
      5. distribute-lft-neg-out99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(-x \cdot 3\right)} \cdot 3\right) \]
      6. distribute-rgt-neg-in99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]
      7. associate-*l*99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]
      8. metadata-eval99.7%

        \[\leadsto x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]
      9. metadata-eval99.7%

        \[\leadsto x \cdot \left(6 + x \cdot \color{blue}{-9}\right) \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 96.3%

      \[\leadsto x \cdot \color{blue}{6} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.66 \lor \neg \left(x \leq 0.66\right):\\ \;\;\;\;x \cdot \left(x \cdot -9\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 6\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 97.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.66:\\ \;\;\;\;x \cdot \left(x \cdot -9\right)\\ \mathbf{elif}\;x \leq 0.66:\\ \;\;\;\;x \cdot 6\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{-0.1111111111111111}{x}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -0.66)
   (* x (* x -9.0))
   (if (<= x 0.66) (* x 6.0) (/ x (/ -0.1111111111111111 x)))))
double code(double x) {
	double tmp;
	if (x <= -0.66) {
		tmp = x * (x * -9.0);
	} else if (x <= 0.66) {
		tmp = x * 6.0;
	} else {
		tmp = x / (-0.1111111111111111 / x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-0.66d0)) then
        tmp = x * (x * (-9.0d0))
    else if (x <= 0.66d0) then
        tmp = x * 6.0d0
    else
        tmp = x / ((-0.1111111111111111d0) / x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -0.66) {
		tmp = x * (x * -9.0);
	} else if (x <= 0.66) {
		tmp = x * 6.0;
	} else {
		tmp = x / (-0.1111111111111111 / x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -0.66:
		tmp = x * (x * -9.0)
	elif x <= 0.66:
		tmp = x * 6.0
	else:
		tmp = x / (-0.1111111111111111 / x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -0.66)
		tmp = Float64(x * Float64(x * -9.0));
	elseif (x <= 0.66)
		tmp = Float64(x * 6.0);
	else
		tmp = Float64(x / Float64(-0.1111111111111111 / x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -0.66)
		tmp = x * (x * -9.0);
	elseif (x <= 0.66)
		tmp = x * 6.0;
	else
		tmp = x / (-0.1111111111111111 / x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -0.66], N[(x * N[(x * -9.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.66], N[(x * 6.0), $MachinePrecision], N[(x / N[(-0.1111111111111111 / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.66:\\
\;\;\;\;x \cdot \left(x \cdot -9\right)\\

\mathbf{elif}\;x \leq 0.66:\\
\;\;\;\;x \cdot 6\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{-0.1111111111111111}{x}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -0.660000000000000031

    1. Initial program 99.9%

      \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{x \cdot \left(3 \cdot \left(2 - x \cdot 3\right)\right)} \]
      2. cancel-sign-sub-inv99.9%

        \[\leadsto x \cdot \left(3 \cdot \color{blue}{\left(2 + \left(-x\right) \cdot 3\right)}\right) \]
      3. distribute-rgt-in99.9%

        \[\leadsto x \cdot \color{blue}{\left(2 \cdot 3 + \left(\left(-x\right) \cdot 3\right) \cdot 3\right)} \]
      4. metadata-eval99.9%

        \[\leadsto x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]
      5. distribute-lft-neg-out99.9%

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(-x \cdot 3\right)} \cdot 3\right) \]
      6. distribute-rgt-neg-in99.9%

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]
      7. associate-*l*99.9%

        \[\leadsto x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]
      8. metadata-eval99.9%

        \[\leadsto x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]
      9. metadata-eval99.9%

        \[\leadsto x \cdot \left(6 + x \cdot \color{blue}{-9}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 97.2%

      \[\leadsto x \cdot \color{blue}{\left(-9 \cdot x\right)} \]
    6. Step-by-step derivation
      1. *-commutative97.2%

        \[\leadsto x \cdot \color{blue}{\left(x \cdot -9\right)} \]
    7. Simplified97.2%

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

    if -0.660000000000000031 < x < 0.660000000000000031

    1. Initial program 99.7%

      \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
    2. Step-by-step derivation
      1. *-commutative99.7%

        \[\leadsto \color{blue}{x \cdot \left(3 \cdot \left(2 - x \cdot 3\right)\right)} \]
      2. cancel-sign-sub-inv99.7%

        \[\leadsto x \cdot \left(3 \cdot \color{blue}{\left(2 + \left(-x\right) \cdot 3\right)}\right) \]
      3. distribute-rgt-in99.7%

        \[\leadsto x \cdot \color{blue}{\left(2 \cdot 3 + \left(\left(-x\right) \cdot 3\right) \cdot 3\right)} \]
      4. metadata-eval99.7%

        \[\leadsto x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]
      5. distribute-lft-neg-out99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(-x \cdot 3\right)} \cdot 3\right) \]
      6. distribute-rgt-neg-in99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]
      7. associate-*l*99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]
      8. metadata-eval99.7%

        \[\leadsto x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]
      9. metadata-eval99.7%

        \[\leadsto x \cdot \left(6 + x \cdot \color{blue}{-9}\right) \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 96.3%

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

    if 0.660000000000000031 < x

    1. Initial program 99.6%

      \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
    2. Step-by-step derivation
      1. *-commutative99.6%

        \[\leadsto \color{blue}{x \cdot \left(3 \cdot \left(2 - x \cdot 3\right)\right)} \]
      2. cancel-sign-sub-inv99.6%

        \[\leadsto x \cdot \left(3 \cdot \color{blue}{\left(2 + \left(-x\right) \cdot 3\right)}\right) \]
      3. distribute-rgt-in99.6%

        \[\leadsto x \cdot \color{blue}{\left(2 \cdot 3 + \left(\left(-x\right) \cdot 3\right) \cdot 3\right)} \]
      4. metadata-eval99.6%

        \[\leadsto x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]
      5. distribute-lft-neg-out99.6%

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

        \[\leadsto x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]
      7. associate-*l*99.7%

        \[\leadsto x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]
      8. metadata-eval99.7%

        \[\leadsto x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]
      9. metadata-eval99.7%

        \[\leadsto x \cdot \left(6 + x \cdot \color{blue}{-9}\right) \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative99.7%

        \[\leadsto \color{blue}{\left(6 + x \cdot -9\right) \cdot x} \]
      2. flip-+98.1%

        \[\leadsto \color{blue}{\frac{6 \cdot 6 - \left(x \cdot -9\right) \cdot \left(x \cdot -9\right)}{6 - x \cdot -9}} \cdot x \]
      3. associate-*l/83.2%

        \[\leadsto \color{blue}{\frac{\left(6 \cdot 6 - \left(x \cdot -9\right) \cdot \left(x \cdot -9\right)\right) \cdot x}{6 - x \cdot -9}} \]
      4. metadata-eval83.2%

        \[\leadsto \frac{\left(\color{blue}{36} - \left(x \cdot -9\right) \cdot \left(x \cdot -9\right)\right) \cdot x}{6 - x \cdot -9} \]
      5. swap-sqr83.2%

        \[\leadsto \frac{\left(36 - \color{blue}{\left(x \cdot x\right) \cdot \left(-9 \cdot -9\right)}\right) \cdot x}{6 - x \cdot -9} \]
      6. pow283.2%

        \[\leadsto \frac{\left(36 - \color{blue}{{x}^{2}} \cdot \left(-9 \cdot -9\right)\right) \cdot x}{6 - x \cdot -9} \]
      7. metadata-eval83.2%

        \[\leadsto \frac{\left(36 - {x}^{2} \cdot \color{blue}{81}\right) \cdot x}{6 - x \cdot -9} \]
      8. *-commutative83.2%

        \[\leadsto \frac{\left(36 - {x}^{2} \cdot 81\right) \cdot x}{6 - \color{blue}{-9 \cdot x}} \]
      9. cancel-sign-sub-inv83.2%

        \[\leadsto \frac{\left(36 - {x}^{2} \cdot 81\right) \cdot x}{\color{blue}{6 + \left(--9\right) \cdot x}} \]
      10. metadata-eval83.2%

        \[\leadsto \frac{\left(36 - {x}^{2} \cdot 81\right) \cdot x}{6 + \color{blue}{9} \cdot x} \]
    6. Applied egg-rr83.2%

      \[\leadsto \color{blue}{\frac{\left(36 - {x}^{2} \cdot 81\right) \cdot x}{6 + 9 \cdot x}} \]
    7. Step-by-step derivation
      1. frac-2neg83.2%

        \[\leadsto \color{blue}{\frac{-\left(36 - {x}^{2} \cdot 81\right) \cdot x}{-\left(6 + 9 \cdot x\right)}} \]
      2. div-inv83.2%

        \[\leadsto \color{blue}{\left(-\left(36 - {x}^{2} \cdot 81\right) \cdot x\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)}} \]
      3. *-commutative83.2%

        \[\leadsto \left(-\color{blue}{x \cdot \left(36 - {x}^{2} \cdot 81\right)}\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
      4. distribute-rgt-neg-in83.2%

        \[\leadsto \color{blue}{\left(x \cdot \left(-\left(36 - {x}^{2} \cdot 81\right)\right)\right)} \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
      5. sub-neg83.2%

        \[\leadsto \left(x \cdot \left(-\color{blue}{\left(36 + \left(-{x}^{2} \cdot 81\right)\right)}\right)\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
      6. distribute-rgt-neg-in83.2%

        \[\leadsto \left(x \cdot \left(-\left(36 + \color{blue}{{x}^{2} \cdot \left(-81\right)}\right)\right)\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
      7. metadata-eval83.2%

        \[\leadsto \left(x \cdot \left(-\left(36 + {x}^{2} \cdot \color{blue}{-81}\right)\right)\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
      8. +-commutative83.2%

        \[\leadsto \left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot \frac{1}{-\color{blue}{\left(9 \cdot x + 6\right)}} \]
      9. *-commutative83.2%

        \[\leadsto \left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot \frac{1}{-\left(\color{blue}{x \cdot 9} + 6\right)} \]
      10. fma-def83.2%

        \[\leadsto \left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot \frac{1}{-\color{blue}{\mathsf{fma}\left(x, 9, 6\right)}} \]
    8. Applied egg-rr83.2%

      \[\leadsto \color{blue}{\left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot \frac{1}{-\mathsf{fma}\left(x, 9, 6\right)}} \]
    9. Step-by-step derivation
      1. associate-*r/83.2%

        \[\leadsto \color{blue}{\frac{\left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot 1}{-\mathsf{fma}\left(x, 9, 6\right)}} \]
      2. *-rgt-identity83.2%

        \[\leadsto \frac{\color{blue}{x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)}}{-\mathsf{fma}\left(x, 9, 6\right)} \]
      3. associate-/l*98.0%

        \[\leadsto \color{blue}{\frac{x}{\frac{-\mathsf{fma}\left(x, 9, 6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}}} \]
      4. fma-udef98.0%

        \[\leadsto \frac{x}{\frac{-\color{blue}{\left(x \cdot 9 + 6\right)}}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      5. distribute-neg-in98.0%

        \[\leadsto \frac{x}{\frac{\color{blue}{\left(-x \cdot 9\right) + \left(-6\right)}}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      6. *-commutative98.0%

        \[\leadsto \frac{x}{\frac{\left(-\color{blue}{9 \cdot x}\right) + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      7. metadata-eval98.0%

        \[\leadsto \frac{x}{\frac{\left(-\color{blue}{\left(--9\right)} \cdot x\right) + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      8. distribute-lft-neg-in98.0%

        \[\leadsto \frac{x}{\frac{\left(-\color{blue}{\left(--9 \cdot x\right)}\right) + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      9. remove-double-neg98.0%

        \[\leadsto \frac{x}{\frac{\color{blue}{-9 \cdot x} + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      10. *-commutative98.0%

        \[\leadsto \frac{x}{\frac{\color{blue}{x \cdot -9} + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      11. metadata-eval98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + \color{blue}{-6}}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
      12. +-commutative98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{-\color{blue}{\left({x}^{2} \cdot -81 + 36\right)}}} \]
      13. distribute-neg-in98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{\color{blue}{\left(-{x}^{2} \cdot -81\right) + \left(-36\right)}}} \]
      14. distribute-rgt-neg-in98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{\color{blue}{{x}^{2} \cdot \left(--81\right)} + \left(-36\right)}} \]
      15. metadata-eval98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{{x}^{2} \cdot \color{blue}{81} + \left(-36\right)}} \]
      16. fma-def98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{\color{blue}{\mathsf{fma}\left({x}^{2}, 81, -36\right)}}} \]
      17. metadata-eval98.0%

        \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{\mathsf{fma}\left({x}^{2}, 81, \color{blue}{-36}\right)}} \]
    10. Simplified98.0%

      \[\leadsto \color{blue}{\frac{x}{\frac{x \cdot -9 + -6}{\mathsf{fma}\left({x}^{2}, 81, -36\right)}}} \]
    11. Taylor expanded in x around inf 97.3%

      \[\leadsto \frac{x}{\color{blue}{\frac{-0.1111111111111111}{x}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.66:\\ \;\;\;\;x \cdot \left(x \cdot -9\right)\\ \mathbf{elif}\;x \leq 0.66:\\ \;\;\;\;x \cdot 6\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{-0.1111111111111111}{x}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 99.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ x \cdot \left(6 + x \cdot -9\right) \end{array} \]
(FPCore (x) :precision binary64 (* x (+ 6.0 (* x -9.0))))
double code(double x) {
	return x * (6.0 + (x * -9.0));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x * (6.0d0 + (x * (-9.0d0)))
end function
public static double code(double x) {
	return x * (6.0 + (x * -9.0));
}
def code(x):
	return x * (6.0 + (x * -9.0))
function code(x)
	return Float64(x * Float64(6.0 + Float64(x * -9.0)))
end
function tmp = code(x)
	tmp = x * (6.0 + (x * -9.0));
end
code[x_] := N[(x * N[(6.0 + N[(x * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(6 + x \cdot -9\right)
\end{array}
Derivation
  1. Initial program 99.7%

    \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
  2. Step-by-step derivation
    1. *-commutative99.7%

      \[\leadsto \color{blue}{x \cdot \left(3 \cdot \left(2 - x \cdot 3\right)\right)} \]
    2. cancel-sign-sub-inv99.7%

      \[\leadsto x \cdot \left(3 \cdot \color{blue}{\left(2 + \left(-x\right) \cdot 3\right)}\right) \]
    3. distribute-rgt-in99.7%

      \[\leadsto x \cdot \color{blue}{\left(2 \cdot 3 + \left(\left(-x\right) \cdot 3\right) \cdot 3\right)} \]
    4. metadata-eval99.7%

      \[\leadsto x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]
    5. distribute-lft-neg-out99.7%

      \[\leadsto x \cdot \left(6 + \color{blue}{\left(-x \cdot 3\right)} \cdot 3\right) \]
    6. distribute-rgt-neg-in99.7%

      \[\leadsto x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]
    7. associate-*l*99.8%

      \[\leadsto x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]
    8. metadata-eval99.8%

      \[\leadsto x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]
    9. metadata-eval99.8%

      \[\leadsto x \cdot \left(6 + x \cdot \color{blue}{-9}\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
  4. Add Preprocessing
  5. Final simplification99.8%

    \[\leadsto x \cdot \left(6 + x \cdot -9\right) \]
  6. Add Preprocessing

Alternative 6: 50.3% accurate, 3.0× speedup?

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

\\
x \cdot 6
\end{array}
Derivation
  1. Initial program 99.7%

    \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
  2. Step-by-step derivation
    1. *-commutative99.7%

      \[\leadsto \color{blue}{x \cdot \left(3 \cdot \left(2 - x \cdot 3\right)\right)} \]
    2. cancel-sign-sub-inv99.7%

      \[\leadsto x \cdot \left(3 \cdot \color{blue}{\left(2 + \left(-x\right) \cdot 3\right)}\right) \]
    3. distribute-rgt-in99.7%

      \[\leadsto x \cdot \color{blue}{\left(2 \cdot 3 + \left(\left(-x\right) \cdot 3\right) \cdot 3\right)} \]
    4. metadata-eval99.7%

      \[\leadsto x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]
    5. distribute-lft-neg-out99.7%

      \[\leadsto x \cdot \left(6 + \color{blue}{\left(-x \cdot 3\right)} \cdot 3\right) \]
    6. distribute-rgt-neg-in99.7%

      \[\leadsto x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]
    7. associate-*l*99.8%

      \[\leadsto x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]
    8. metadata-eval99.8%

      \[\leadsto x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]
    9. metadata-eval99.8%

      \[\leadsto x \cdot \left(6 + x \cdot \color{blue}{-9}\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 52.3%

    \[\leadsto x \cdot \color{blue}{6} \]
  6. Final simplification52.3%

    \[\leadsto x \cdot 6 \]
  7. Add Preprocessing

Alternative 7: 2.3% accurate, 9.0× speedup?

\[\begin{array}{l} \\ 4 \end{array} \]
(FPCore (x) :precision binary64 4.0)
double code(double x) {
	return 4.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 4.0d0
end function
public static double code(double x) {
	return 4.0;
}
def code(x):
	return 4.0
function code(x)
	return 4.0
end
function tmp = code(x)
	tmp = 4.0;
end
code[x_] := 4.0
\begin{array}{l}

\\
4
\end{array}
Derivation
  1. Initial program 99.7%

    \[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
  2. Step-by-step derivation
    1. *-commutative99.7%

      \[\leadsto \color{blue}{x \cdot \left(3 \cdot \left(2 - x \cdot 3\right)\right)} \]
    2. cancel-sign-sub-inv99.7%

      \[\leadsto x \cdot \left(3 \cdot \color{blue}{\left(2 + \left(-x\right) \cdot 3\right)}\right) \]
    3. distribute-rgt-in99.7%

      \[\leadsto x \cdot \color{blue}{\left(2 \cdot 3 + \left(\left(-x\right) \cdot 3\right) \cdot 3\right)} \]
    4. metadata-eval99.7%

      \[\leadsto x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]
    5. distribute-lft-neg-out99.7%

      \[\leadsto x \cdot \left(6 + \color{blue}{\left(-x \cdot 3\right)} \cdot 3\right) \]
    6. distribute-rgt-neg-in99.7%

      \[\leadsto x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]
    7. associate-*l*99.8%

      \[\leadsto x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]
    8. metadata-eval99.8%

      \[\leadsto x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]
    9. metadata-eval99.8%

      \[\leadsto x \cdot \left(6 + x \cdot \color{blue}{-9}\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. *-commutative99.8%

      \[\leadsto \color{blue}{\left(6 + x \cdot -9\right) \cdot x} \]
    2. flip-+99.4%

      \[\leadsto \color{blue}{\frac{6 \cdot 6 - \left(x \cdot -9\right) \cdot \left(x \cdot -9\right)}{6 - x \cdot -9}} \cdot x \]
    3. associate-*l/93.8%

      \[\leadsto \color{blue}{\frac{\left(6 \cdot 6 - \left(x \cdot -9\right) \cdot \left(x \cdot -9\right)\right) \cdot x}{6 - x \cdot -9}} \]
    4. metadata-eval93.8%

      \[\leadsto \frac{\left(\color{blue}{36} - \left(x \cdot -9\right) \cdot \left(x \cdot -9\right)\right) \cdot x}{6 - x \cdot -9} \]
    5. swap-sqr93.8%

      \[\leadsto \frac{\left(36 - \color{blue}{\left(x \cdot x\right) \cdot \left(-9 \cdot -9\right)}\right) \cdot x}{6 - x \cdot -9} \]
    6. pow293.8%

      \[\leadsto \frac{\left(36 - \color{blue}{{x}^{2}} \cdot \left(-9 \cdot -9\right)\right) \cdot x}{6 - x \cdot -9} \]
    7. metadata-eval93.8%

      \[\leadsto \frac{\left(36 - {x}^{2} \cdot \color{blue}{81}\right) \cdot x}{6 - x \cdot -9} \]
    8. *-commutative93.8%

      \[\leadsto \frac{\left(36 - {x}^{2} \cdot 81\right) \cdot x}{6 - \color{blue}{-9 \cdot x}} \]
    9. cancel-sign-sub-inv93.8%

      \[\leadsto \frac{\left(36 - {x}^{2} \cdot 81\right) \cdot x}{\color{blue}{6 + \left(--9\right) \cdot x}} \]
    10. metadata-eval93.8%

      \[\leadsto \frac{\left(36 - {x}^{2} \cdot 81\right) \cdot x}{6 + \color{blue}{9} \cdot x} \]
  6. Applied egg-rr93.8%

    \[\leadsto \color{blue}{\frac{\left(36 - {x}^{2} \cdot 81\right) \cdot x}{6 + 9 \cdot x}} \]
  7. Step-by-step derivation
    1. frac-2neg93.8%

      \[\leadsto \color{blue}{\frac{-\left(36 - {x}^{2} \cdot 81\right) \cdot x}{-\left(6 + 9 \cdot x\right)}} \]
    2. div-inv93.7%

      \[\leadsto \color{blue}{\left(-\left(36 - {x}^{2} \cdot 81\right) \cdot x\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)}} \]
    3. *-commutative93.7%

      \[\leadsto \left(-\color{blue}{x \cdot \left(36 - {x}^{2} \cdot 81\right)}\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
    4. distribute-rgt-neg-in93.7%

      \[\leadsto \color{blue}{\left(x \cdot \left(-\left(36 - {x}^{2} \cdot 81\right)\right)\right)} \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
    5. sub-neg93.7%

      \[\leadsto \left(x \cdot \left(-\color{blue}{\left(36 + \left(-{x}^{2} \cdot 81\right)\right)}\right)\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
    6. distribute-rgt-neg-in93.7%

      \[\leadsto \left(x \cdot \left(-\left(36 + \color{blue}{{x}^{2} \cdot \left(-81\right)}\right)\right)\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
    7. metadata-eval93.7%

      \[\leadsto \left(x \cdot \left(-\left(36 + {x}^{2} \cdot \color{blue}{-81}\right)\right)\right) \cdot \frac{1}{-\left(6 + 9 \cdot x\right)} \]
    8. +-commutative93.7%

      \[\leadsto \left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot \frac{1}{-\color{blue}{\left(9 \cdot x + 6\right)}} \]
    9. *-commutative93.7%

      \[\leadsto \left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot \frac{1}{-\left(\color{blue}{x \cdot 9} + 6\right)} \]
    10. fma-def93.7%

      \[\leadsto \left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot \frac{1}{-\color{blue}{\mathsf{fma}\left(x, 9, 6\right)}} \]
  8. Applied egg-rr93.7%

    \[\leadsto \color{blue}{\left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot \frac{1}{-\mathsf{fma}\left(x, 9, 6\right)}} \]
  9. Step-by-step derivation
    1. associate-*r/93.8%

      \[\leadsto \color{blue}{\frac{\left(x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)\right) \cdot 1}{-\mathsf{fma}\left(x, 9, 6\right)}} \]
    2. *-rgt-identity93.8%

      \[\leadsto \frac{\color{blue}{x \cdot \left(-\left(36 + {x}^{2} \cdot -81\right)\right)}}{-\mathsf{fma}\left(x, 9, 6\right)} \]
    3. associate-/l*99.2%

      \[\leadsto \color{blue}{\frac{x}{\frac{-\mathsf{fma}\left(x, 9, 6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}}} \]
    4. fma-udef99.2%

      \[\leadsto \frac{x}{\frac{-\color{blue}{\left(x \cdot 9 + 6\right)}}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
    5. distribute-neg-in99.2%

      \[\leadsto \frac{x}{\frac{\color{blue}{\left(-x \cdot 9\right) + \left(-6\right)}}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
    6. *-commutative99.2%

      \[\leadsto \frac{x}{\frac{\left(-\color{blue}{9 \cdot x}\right) + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
    7. metadata-eval99.2%

      \[\leadsto \frac{x}{\frac{\left(-\color{blue}{\left(--9\right)} \cdot x\right) + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
    8. distribute-lft-neg-in99.2%

      \[\leadsto \frac{x}{\frac{\left(-\color{blue}{\left(--9 \cdot x\right)}\right) + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
    9. remove-double-neg99.2%

      \[\leadsto \frac{x}{\frac{\color{blue}{-9 \cdot x} + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
    10. *-commutative99.2%

      \[\leadsto \frac{x}{\frac{\color{blue}{x \cdot -9} + \left(-6\right)}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
    11. metadata-eval99.2%

      \[\leadsto \frac{x}{\frac{x \cdot -9 + \color{blue}{-6}}{-\left(36 + {x}^{2} \cdot -81\right)}} \]
    12. +-commutative99.2%

      \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{-\color{blue}{\left({x}^{2} \cdot -81 + 36\right)}}} \]
    13. distribute-neg-in99.2%

      \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{\color{blue}{\left(-{x}^{2} \cdot -81\right) + \left(-36\right)}}} \]
    14. distribute-rgt-neg-in99.2%

      \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{\color{blue}{{x}^{2} \cdot \left(--81\right)} + \left(-36\right)}} \]
    15. metadata-eval99.2%

      \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{{x}^{2} \cdot \color{blue}{81} + \left(-36\right)}} \]
    16. fma-def99.2%

      \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{\color{blue}{\mathsf{fma}\left({x}^{2}, 81, -36\right)}}} \]
    17. metadata-eval99.2%

      \[\leadsto \frac{x}{\frac{x \cdot -9 + -6}{\mathsf{fma}\left({x}^{2}, 81, \color{blue}{-36}\right)}} \]
  10. Simplified99.2%

    \[\leadsto \color{blue}{\frac{x}{\frac{x \cdot -9 + -6}{\mathsf{fma}\left({x}^{2}, 81, -36\right)}}} \]
  11. Taylor expanded in x around 0 52.0%

    \[\leadsto \frac{x}{\color{blue}{0.16666666666666666 + 0.25 \cdot x}} \]
  12. Step-by-step derivation
    1. *-commutative52.0%

      \[\leadsto \frac{x}{0.16666666666666666 + \color{blue}{x \cdot 0.25}} \]
  13. Simplified52.0%

    \[\leadsto \frac{x}{\color{blue}{0.16666666666666666 + x \cdot 0.25}} \]
  14. Taylor expanded in x around inf 2.5%

    \[\leadsto \color{blue}{4} \]
  15. Final simplification2.5%

    \[\leadsto 4 \]
  16. Add Preprocessing

Developer target: 99.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 6 \cdot x - 9 \cdot \left(x \cdot x\right) \end{array} \]
(FPCore (x) :precision binary64 (- (* 6.0 x) (* 9.0 (* x x))))
double code(double x) {
	return (6.0 * x) - (9.0 * (x * x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (6.0d0 * x) - (9.0d0 * (x * x))
end function
public static double code(double x) {
	return (6.0 * x) - (9.0 * (x * x));
}
def code(x):
	return (6.0 * x) - (9.0 * (x * x))
function code(x)
	return Float64(Float64(6.0 * x) - Float64(9.0 * Float64(x * x)))
end
function tmp = code(x)
	tmp = (6.0 * x) - (9.0 * (x * x));
end
code[x_] := N[(N[(6.0 * x), $MachinePrecision] - N[(9.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
6 \cdot x - 9 \cdot \left(x \cdot x\right)
\end{array}

Reproduce

?
herbie shell --seed 2024021 
(FPCore (x)
  :name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, E"
  :precision binary64

  :herbie-target
  (- (* 6.0 x) (* 9.0 (* x x)))

  (* (* 3.0 (- 2.0 (* x 3.0))) x))