# Input and output not recognized and missing \endcsname in algorithm

I want to write an algorithm, and I have the code segment shown below, but it provides multiple errors, such as input and output commands are not recognized and I get missing \endcsname error. Additionally, the line numbers are not inserted, any idea how to fix all the errors and also insert the line numbers?

\documentclass[a4paper]{paper}
\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithm}[H]
\Input{A vector \textbf{a}}
\Output{Bit reversed vector}
\Function{NTT}{$\textbf{a}$}
\State $m \gets 1$
\State $k \gets n / 2$
\While{$m < n$}
\For {$i = 0$ \To $m - 1$}
\State $jFirst \gets 2 \cdot i \cdot k$
\State $jLast \gets jFirst + k - 1$
\State $S \gets \psi_{rev}[m + i]$
\For {$j = jFirst$ \To $jLast$}
\State $l \gets j + k$
\State $t \gets \textbf{a}[j]$
\State $u \gets \textbf{a}[l] \cdot S$
\State $\textbf{a}[j] \gets t + u \mod q$
\State $\textbf{a}[l] \gets t - u \mod q$
\EndFor
\EndFor
\State $m \gets m \cdot 2$
\State $k \gets n / 2$
\EndWhile
\State \Return $\textbf{a}$
\EndFunction
\caption{Cooley-Tukey (CT) Forward NTT}
\label{CTAlgo}
\end{algorithm}

\end{document}

• It's \documentclass[a4paper]{paper} actually. I have no idea where it is defined. Just using it as I'm writing paper, and using xelatex. – pixel Aug 23 '17 at 17:54

algorithmicx's algpseudocode does not provide \Input or \Output commands. You'll have to create them in the same way (say) \Ensure and \Require are produced.

Also, for numbering of the lines, you need to also use the algorithmic environment:

\documentclass{article}

\usepackage{amsmath}

\usepackage{algorithm,algpseudocode}
\algnewcommand{\To}{\textbf{To }}
\algnewcommand\Input{\item[\textbf{Input:}]}%
\algnewcommand\Output{\item[\textbf{Output:}]}%

\begin{document}

\begin{algorithm}[H]
\begin{algorithmic}[1]
\Input{A vector \textbf{a}}
\Output{Bit reversed vector}
\Function{NTT}{$\textbf{a}$}
\State $m \gets 1$
\State $k \gets n / 2$
\While{$m < n$}
\For {$i = 0$ \To $m - 1$}
\State $jFirst \gets 2 \cdot i \cdot k$
\State $jLast \gets jFirst + k - 1$
\State $S \gets \psi_{rev}[m + i]$
\For {$j = jFirst$ \To $jLast$}
\State $l \gets j + k$
\State $t \gets \textbf{a}[j]$
\State $u \gets \textbf{a}[l] \cdot S$
\State $\textbf{a}[j] \gets t + u \mod q$
\State $\textbf{a}[l] \gets t - u \mod q$
\EndFor
\EndFor
\State $m \gets m \cdot 2$
\State $k \gets n / 2$
\EndWhile
\State \Return $\textbf{a}$
\EndFunction
\end{algorithmic}
\caption{Cooley-Tukey (CT) Forward NTT}
\label{CTAlgo}
\end{algorithm}

\end{document}