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

Percentage Accurate: 99.7% → 99.8%
Time: 6.1s
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-rgt-in99.4%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 6, \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.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.68 \lor \neg \left(x \leq 0.68\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.68) (not (<= x 0.68))) (* x (* x -9.0)) (* x 6.0)))
double code(double x) {
	double tmp;
	if ((x <= -0.68) || !(x <= 0.68)) {
		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.68d0)) .or. (.not. (x <= 0.68d0))) 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.68) || !(x <= 0.68)) {
		tmp = x * (x * -9.0);
	} else {
		tmp = x * 6.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (x <= -0.68) or not (x <= 0.68):
		tmp = x * (x * -9.0)
	else:
		tmp = x * 6.0
	return tmp
function code(x)
	tmp = 0.0
	if ((x <= -0.68) || !(x <= 0.68))
		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.68) || ~((x <= 0.68)))
		tmp = x * (x * -9.0);
	else
		tmp = x * 6.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[Or[LessEqual[x, -0.68], N[Not[LessEqual[x, 0.68]], $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.68 \lor \neg \left(x \leq 0.68\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.680000000000000049 or 0.680000000000000049 < 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.8%

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

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

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

    if -0.680000000000000049 < x < 0.680000000000000049

    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 97.1%

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

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

Alternative 3: 97.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.68:\\ \;\;\;\;x \cdot \left(x \cdot -9\right)\\ \mathbf{elif}\;x \leq 0.68:\\ \;\;\;\;x \cdot 6\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{-0.1111111111111111}{x}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -0.68)
   (* x (* x -9.0))
   (if (<= x 0.68) (* x 6.0) (/ x (/ -0.1111111111111111 x)))))
double code(double x) {
	double tmp;
	if (x <= -0.68) {
		tmp = x * (x * -9.0);
	} else if (x <= 0.68) {
		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.68d0)) then
        tmp = x * (x * (-9.0d0))
    else if (x <= 0.68d0) 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.68) {
		tmp = x * (x * -9.0);
	} else if (x <= 0.68) {
		tmp = x * 6.0;
	} else {
		tmp = x / (-0.1111111111111111 / x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -0.68:
		tmp = x * (x * -9.0)
	elif x <= 0.68:
		tmp = x * 6.0
	else:
		tmp = x / (-0.1111111111111111 / x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -0.68)
		tmp = Float64(x * Float64(x * -9.0));
	elseif (x <= 0.68)
		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.68)
		tmp = x * (x * -9.0);
	elseif (x <= 0.68)
		tmp = x * 6.0;
	else
		tmp = x / (-0.1111111111111111 / x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -0.68], N[(x * N[(x * -9.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.68], N[(x * 6.0), $MachinePrecision], N[(x / N[(-0.1111111111111111 / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq 0.68:\\
\;\;\;\;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.680000000000000049

    1. Initial program 99.8%

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

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

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

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

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

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

        \[\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.7%

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

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

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

    if -0.680000000000000049 < x < 0.680000000000000049

    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 97.1%

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

    if 0.680000000000000049 < 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.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-in98.3%

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

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

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

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

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

        \[\leadsto \frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \color{blue}{\left(-9 \cdot \left(x \cdot x\right)\right)} \cdot \left(\left(x \cdot -9\right) \cdot x\right)}{x \cdot 6 - x \cdot \left(x \cdot -9\right)} \]
      7. pow225.1%

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

        \[\leadsto \frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \left(-9 \cdot {x}^{2}\right) \cdot \left(\color{blue}{\left(-9 \cdot x\right)} \cdot x\right)}{x \cdot 6 - x \cdot \left(x \cdot -9\right)} \]
      9. associate-*l*25.0%

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

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

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

        \[\leadsto \frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \left(-9 \cdot {x}^{2}\right) \cdot \left(-9 \cdot {x}^{2}\right)}{x \cdot 6 - \color{blue}{\left(-9 \cdot x\right)} \cdot x} \]
      13. associate-*l*25.1%

        \[\leadsto \frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \left(-9 \cdot {x}^{2}\right) \cdot \left(-9 \cdot {x}^{2}\right)}{x \cdot 6 - \color{blue}{-9 \cdot \left(x \cdot x\right)}} \]
      14. pow225.1%

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

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

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

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

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

        \[\leadsto \frac{\left(\color{blue}{\left(x \cdot x\right)} \cdot -9 + x \cdot 6\right) \cdot \left(x \cdot 6 - -9 \cdot {x}^{2}\right)}{x \cdot 6 - -9 \cdot {x}^{2}} \]
      5. associate-*r*25.2%

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

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

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

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

        \[\leadsto \frac{x \cdot \mathsf{fma}\left(x, -9, 6\right)}{\color{blue}{1}} \]
      10. associate-/l*99.6%

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

      \[\leadsto \color{blue}{\frac{x}{\frac{1}{\mathsf{fma}\left(x, -9, 6\right)}}} \]
    9. Taylor expanded in x around inf 97.9%

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

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

Alternative 4: 52.0% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;x \cdot 6\\

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


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

    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 68.5%

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

    if 0.680000000000000049 < 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.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-in98.3%

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

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

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

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

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

        \[\leadsto \frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \color{blue}{\left(-9 \cdot \left(x \cdot x\right)\right)} \cdot \left(\left(x \cdot -9\right) \cdot x\right)}{x \cdot 6 - x \cdot \left(x \cdot -9\right)} \]
      7. pow225.1%

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

        \[\leadsto \frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \left(-9 \cdot {x}^{2}\right) \cdot \left(\color{blue}{\left(-9 \cdot x\right)} \cdot x\right)}{x \cdot 6 - x \cdot \left(x \cdot -9\right)} \]
      9. associate-*l*25.0%

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

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

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

        \[\leadsto \frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \left(-9 \cdot {x}^{2}\right) \cdot \left(-9 \cdot {x}^{2}\right)}{x \cdot 6 - \color{blue}{\left(-9 \cdot x\right)} \cdot x} \]
      13. associate-*l*25.1%

        \[\leadsto \frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \left(-9 \cdot {x}^{2}\right) \cdot \left(-9 \cdot {x}^{2}\right)}{x \cdot 6 - \color{blue}{-9 \cdot \left(x \cdot x\right)}} \]
      14. pow225.1%

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

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

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

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

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

        \[\leadsto \frac{\left(\color{blue}{\left(x \cdot x\right)} \cdot -9 + x \cdot 6\right) \cdot \left(x \cdot 6 - -9 \cdot {x}^{2}\right)}{x \cdot 6 - -9 \cdot {x}^{2}} \]
      5. associate-*r*25.2%

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

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

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

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

        \[\leadsto \frac{x \cdot \mathsf{fma}\left(x, -9, 6\right)}{\color{blue}{1}} \]
      10. associate-/l*99.6%

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

      \[\leadsto \color{blue}{\frac{x}{\frac{1}{\mathsf{fma}\left(x, -9, 6\right)}}} \]
    9. Taylor expanded in x around 0 0.5%

      \[\leadsto \frac{x}{\color{blue}{0.16666666666666666}} \]
    10. Step-by-step derivation
      1. div-inv0.5%

        \[\leadsto \color{blue}{x \cdot \frac{1}{0.16666666666666666}} \]
      2. metadata-eval0.5%

        \[\leadsto x \cdot \color{blue}{6} \]
      3. *-commutative0.5%

        \[\leadsto \color{blue}{6 \cdot x} \]
      4. metadata-eval0.5%

        \[\leadsto \color{blue}{\left(2 \cdot 3\right)} \cdot x \]
      5. associate-*r*0.5%

        \[\leadsto \color{blue}{2 \cdot \left(3 \cdot x\right)} \]
      6. add-sqr-sqrt0.5%

        \[\leadsto 2 \cdot \color{blue}{\left(\sqrt{3 \cdot x} \cdot \sqrt{3 \cdot x}\right)} \]
      7. sqrt-unprod0.5%

        \[\leadsto 2 \cdot \color{blue}{\sqrt{\left(3 \cdot x\right) \cdot \left(3 \cdot x\right)}} \]
      8. *-commutative0.5%

        \[\leadsto 2 \cdot \sqrt{\color{blue}{\left(x \cdot 3\right)} \cdot \left(3 \cdot x\right)} \]
      9. *-commutative0.5%

        \[\leadsto 2 \cdot \sqrt{\left(x \cdot 3\right) \cdot \color{blue}{\left(x \cdot 3\right)}} \]
      10. swap-sqr0.5%

        \[\leadsto 2 \cdot \sqrt{\color{blue}{\left(x \cdot x\right) \cdot \left(3 \cdot 3\right)}} \]
      11. metadata-eval0.5%

        \[\leadsto 2 \cdot \sqrt{\left(x \cdot x\right) \cdot \color{blue}{9}} \]
      12. metadata-eval0.5%

        \[\leadsto 2 \cdot \sqrt{\left(x \cdot x\right) \cdot \color{blue}{\left(-3 \cdot -3\right)}} \]
      13. swap-sqr0.5%

        \[\leadsto 2 \cdot \sqrt{\color{blue}{\left(x \cdot -3\right) \cdot \left(x \cdot -3\right)}} \]
      14. sqrt-unprod0.0%

        \[\leadsto 2 \cdot \color{blue}{\left(\sqrt{x \cdot -3} \cdot \sqrt{x \cdot -3}\right)} \]
      15. add-sqr-sqrt8.1%

        \[\leadsto 2 \cdot \color{blue}{\left(x \cdot -3\right)} \]
      16. *-commutative8.1%

        \[\leadsto 2 \cdot \color{blue}{\left(-3 \cdot x\right)} \]
      17. associate-*r*8.1%

        \[\leadsto \color{blue}{\left(2 \cdot -3\right) \cdot x} \]
      18. metadata-eval8.1%

        \[\leadsto \color{blue}{-6} \cdot x \]
    11. Applied egg-rr8.1%

      \[\leadsto \color{blue}{-6 \cdot x} \]
    12. Step-by-step derivation
      1. *-commutative8.1%

        \[\leadsto \color{blue}{x \cdot -6} \]
    13. Simplified8.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;x \cdot 6\\ \mathbf{else}:\\ \;\;\;\;x \cdot -6\\ \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: 3.8% 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. Step-by-step derivation
    1. distribute-lft-in99.4%

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

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

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

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

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

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

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

      \[\leadsto \frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \left(-9 \cdot {x}^{2}\right) \cdot \left(\color{blue}{\left(-9 \cdot x\right)} \cdot x\right)}{x \cdot 6 - x \cdot \left(x \cdot -9\right)} \]
    9. associate-*l*40.2%

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

      \[\leadsto \frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \left(-9 \cdot {x}^{2}\right) \cdot \left(-9 \cdot \color{blue}{{x}^{2}}\right)}{x \cdot 6 - x \cdot \left(x \cdot -9\right)} \]
    11. *-commutative40.2%

      \[\leadsto \frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \left(-9 \cdot {x}^{2}\right) \cdot \left(-9 \cdot {x}^{2}\right)}{x \cdot 6 - \color{blue}{\left(x \cdot -9\right) \cdot x}} \]
    12. *-commutative40.2%

      \[\leadsto \frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \left(-9 \cdot {x}^{2}\right) \cdot \left(-9 \cdot {x}^{2}\right)}{x \cdot 6 - \color{blue}{\left(-9 \cdot x\right)} \cdot x} \]
    13. associate-*l*40.2%

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

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

    \[\leadsto \color{blue}{\frac{\left(x \cdot 6\right) \cdot \left(x \cdot 6\right) - \left(-9 \cdot {x}^{2}\right) \cdot \left(-9 \cdot {x}^{2}\right)}{x \cdot 6 - -9 \cdot {x}^{2}}} \]
  7. Step-by-step derivation
    1. difference-of-squares40.3%

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

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

      \[\leadsto \frac{\left(\color{blue}{{x}^{2} \cdot -9} + x \cdot 6\right) \cdot \left(x \cdot 6 - -9 \cdot {x}^{2}\right)}{x \cdot 6 - -9 \cdot {x}^{2}} \]
    4. unpow240.3%

      \[\leadsto \frac{\left(\color{blue}{\left(x \cdot x\right)} \cdot -9 + x \cdot 6\right) \cdot \left(x \cdot 6 - -9 \cdot {x}^{2}\right)}{x \cdot 6 - -9 \cdot {x}^{2}} \]
    5. associate-*r*40.3%

      \[\leadsto \frac{\left(\color{blue}{x \cdot \left(x \cdot -9\right)} + x \cdot 6\right) \cdot \left(x \cdot 6 - -9 \cdot {x}^{2}\right)}{x \cdot 6 - -9 \cdot {x}^{2}} \]
    6. distribute-lft-in40.3%

      \[\leadsto \frac{\color{blue}{\left(x \cdot \left(x \cdot -9 + 6\right)\right)} \cdot \left(x \cdot 6 - -9 \cdot {x}^{2}\right)}{x \cdot 6 - -9 \cdot {x}^{2}} \]
    7. fma-udef40.3%

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

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

      \[\leadsto \frac{x \cdot \mathsf{fma}\left(x, -9, 6\right)}{\color{blue}{1}} \]
    10. associate-/l*99.6%

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

    \[\leadsto \color{blue}{\frac{x}{\frac{1}{\mathsf{fma}\left(x, -9, 6\right)}}} \]
  9. Taylor expanded in x around 0 49.9%

    \[\leadsto \frac{x}{\color{blue}{0.16666666666666666}} \]
  10. Step-by-step derivation
    1. div-inv50.0%

      \[\leadsto \color{blue}{x \cdot \frac{1}{0.16666666666666666}} \]
    2. metadata-eval50.0%

      \[\leadsto x \cdot \color{blue}{6} \]
    3. *-commutative50.0%

      \[\leadsto \color{blue}{6 \cdot x} \]
    4. metadata-eval50.0%

      \[\leadsto \color{blue}{\left(2 \cdot 3\right)} \cdot x \]
    5. associate-*r*50.0%

      \[\leadsto \color{blue}{2 \cdot \left(3 \cdot x\right)} \]
    6. add-sqr-sqrt27.4%

      \[\leadsto 2 \cdot \color{blue}{\left(\sqrt{3 \cdot x} \cdot \sqrt{3 \cdot x}\right)} \]
    7. sqrt-unprod19.2%

      \[\leadsto 2 \cdot \color{blue}{\sqrt{\left(3 \cdot x\right) \cdot \left(3 \cdot x\right)}} \]
    8. *-commutative19.2%

      \[\leadsto 2 \cdot \sqrt{\color{blue}{\left(x \cdot 3\right)} \cdot \left(3 \cdot x\right)} \]
    9. *-commutative19.2%

      \[\leadsto 2 \cdot \sqrt{\left(x \cdot 3\right) \cdot \color{blue}{\left(x \cdot 3\right)}} \]
    10. swap-sqr19.1%

      \[\leadsto 2 \cdot \sqrt{\color{blue}{\left(x \cdot x\right) \cdot \left(3 \cdot 3\right)}} \]
    11. metadata-eval19.1%

      \[\leadsto 2 \cdot \sqrt{\left(x \cdot x\right) \cdot \color{blue}{9}} \]
    12. metadata-eval19.1%

      \[\leadsto 2 \cdot \sqrt{\left(x \cdot x\right) \cdot \color{blue}{\left(-3 \cdot -3\right)}} \]
    13. swap-sqr19.2%

      \[\leadsto 2 \cdot \sqrt{\color{blue}{\left(x \cdot -3\right) \cdot \left(x \cdot -3\right)}} \]
    14. sqrt-unprod0.9%

      \[\leadsto 2 \cdot \color{blue}{\left(\sqrt{x \cdot -3} \cdot \sqrt{x \cdot -3}\right)} \]
    15. add-sqr-sqrt4.1%

      \[\leadsto 2 \cdot \color{blue}{\left(x \cdot -3\right)} \]
    16. *-commutative4.1%

      \[\leadsto 2 \cdot \color{blue}{\left(-3 \cdot x\right)} \]
    17. associate-*r*4.1%

      \[\leadsto \color{blue}{\left(2 \cdot -3\right) \cdot x} \]
    18. metadata-eval4.1%

      \[\leadsto \color{blue}{-6} \cdot x \]
  11. Applied egg-rr4.1%

    \[\leadsto \color{blue}{-6 \cdot x} \]
  12. Step-by-step derivation
    1. *-commutative4.1%

      \[\leadsto \color{blue}{x \cdot -6} \]
  13. Simplified4.1%

    \[\leadsto \color{blue}{x \cdot -6} \]
  14. Final simplification4.1%

    \[\leadsto x \cdot -6 \]
  15. Add Preprocessing

Alternative 7: 2.4% 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.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/90.7%

      \[\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-eval90.7%

      \[\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-sqr90.7%

      \[\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. pow290.7%

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

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

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

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

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

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

    \[\leadsto \frac{\color{blue}{36 \cdot x}}{6 + 9 \cdot x} \]
  8. Step-by-step derivation
    1. *-commutative49.1%

      \[\leadsto \frac{\color{blue}{x \cdot 36}}{6 + 9 \cdot x} \]
  9. Simplified49.1%

    \[\leadsto \frac{\color{blue}{x \cdot 36}}{6 + 9 \cdot x} \]
  10. Taylor expanded in x around inf 2.5%

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

    \[\leadsto 4 \]
  12. 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 2024019 
(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))