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}
Best Answer
algorithmicx
'salgpseudocode
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: