# 循环移位

循环移位（亦称端回移位）是对序列（如向量或字符串）的一种操作：将元素移动给定的位数，从一端掉出的元素重新插入另一端，序列长度保持不变。将长度为 n 的序列移动 k 位，等价于移动 k mod n 位，因为该操作以 n 为周期重复。

| 关键事实 | 细节 |
|---|---|
| 定义 | 移出末位的元素重新从首位插入；输出的形状与输入相同<sup>[1](https://numpy.org/doc/1.20/reference/generated/numpy.roll.html)</sup> |
| 索引映射 | 移动 k 位将索引 i 映射到 (i + k) mod n |
| 矩阵形式 | 该操作是乘以一个由标准基向量构成的 n×n 置换矩阵 P<sup>[2](https://terpconnect.umd.edu/~adrian/enee222/lecture_notes/enee222lectures.pdf)</sup><sup> • </sup><sup>[3](https://scg.ece.ucsb.edu/publications/theses/Pals_2005_Thesis.pdf)</sup> |
| 傅里叶行为 | 向量的循环移位，使其离散傅里叶变换各分量逐项乘以一个三角函数（调制）<sup>[3](https://scg.ece.ucsb.edu/publications/theses/Pals_2005_Thesis.pdf)</sup> |
| 编码理论 | 一个线性码是循环码，当且仅当每个码字的循环移位仍是码字<sup>[4](https://bpb-us-w2.wpmucdn.com/sites.umassd.edu/dist/f/1260/files/2022/08/bwj-bookchapter.pdf)</sup> |
| 词的组合学 | 循环移位生成等价类，称为项链词，或称循环词<sup>[5](https://drops.dagstuhl.de/storage/00lipics/lipics-vol345-mfcs2025/html/LIPIcs.MFCS.2025.48/LIPIcs.MFCS.2025.48.html)</sup> |

## 操作

对于长度为 n 的序列，右循环移位一位将最后一个元素移到最前，其余每个元素右移一位；左移一位则将第一个元素移到末尾。NumPy 的 `numpy.roll` 对数组实现了这一操作：将十元素数组 `[0, 1, ..., 9]` 滚动 2 位得到 `[8, 9, 0, 1, 2, 3, 4, 5, 6, 7]`，滚动 −2 位得到 `[2, 3, 4, 5, 6, 7, 8, 9, 0, 1]`<sup>[1](https://numpy.org/doc/1.20/reference/generated/numpy.roll.html)</sup>。该函数接受 `axis` 参数；默认情况下数组在移位前被展平、移位后恢复原形状，自 1.12.0 版起支持同时在多个维度上滚动<sup>[1](https://numpy.org/doc/1.20/reference/generated/numpy.roll.html)</sup>。

由于移动 n 位重现原序列，移位量自然对 n 取模。

## 矩阵形式与傅里叶联系

循环移位是线性算子。作用于长度为 n 的列向量时，移动一位相当于乘以由移位后的标准基向量构成的 n×n 置换矩阵 P<sup>[2](https://terpconnect.umd.edu/~adrian/enee222/lecture_notes/enee222lectures.pdf)</sup>。移动 k 位相当于乘以该矩阵的 k 次幂，索引映射为

i ↦ (i + k) mod n。

离散傅里叶变换的移位性质指出，向量 x 的循环移位等价于其傅里叶谱的调制，即与一个三角函数逐项相乘。记傅里叶矩阵为 F，设 y 为 x 的循环移位，则该性质表达为 Fy = Fx 逐项乘以某个三角函数<sup>[3](https://scg.ece.ucsb.edu/publications/theses/Pals_2005_Thesis.pdf)</sup>。由于这对任意 x 成立，移位矩阵的幂被傅里叶矩阵同时对角化；对角化后的 P 的对角元是 F 的第二列<sup>[3](https://scg.ece.ucsb.edu/publications/theses/Pals_2005_Thesis.pdf)</sup>。这正是离散傅里叶变换把信号视为周期的、即循环的，而非视为有限片段的原因<sup>[6](https://spseducation.tue.nl/disciplines/discrete/discretesignalprocessing_transforms_dft_properties/)</sup>。

## 循环码

在编码理论中，域上长度为 n 的线性码 C 若在循环移位变换下不变，则称为循环码<sup>[7](https://repositorio.udec.cl/bitstreams/a07549a0-ce11-4cd4-8487-e9de06a93c1c/download)</sup>。等价地说，码字的任何端回移位都产生另一个码字<sup>[4](https://bpb-us-w2.wpmucdn.com/sites.umassd.edu/dist/f/1260/files/2022/08/bwj-bookchapter.pdf)</sup>。循环移位映射是空间上的线性算子，循环码可作为在该算子下不变的线性子空间来研究<sup>[8](https://store.fmi.uni-sofia.bg/fmi/algebra/bojilov/CYCLIC_CODES_AS_INVARIANT.pdf)</sup>。

这种不变性赋予循环码实用优势：编码操作可用带反馈连接的简单移位寄存器实现，这是循环码广泛用于数据链路以及磁带、磁盘等顺序存取设备的原因之一<sup>[4](https://bpb-us-w2.wpmucdn.com/sites.umassd.edu/dist/f/1260/files/2022/08/bwj-bookchapter.pdf)</sup>。代数上，将向量与次数小于 n 的多项式等同起来，可知循环码由其在模 x^n − 1 的多项式环中生成多项式 g 的所有倍式组成<sup>[9](https://personalpages.manchester.ac.uk/staff/yuri.bazlov/code/notes/ch9.html)</sup>。推广情形将坐标划分为若干子集，各子集各自循环移位，如双重循环码和三重循环码<sup>[10](https://arxiv.org/abs/1410.5604)</sup>。

## 词、项链词与 Lyndon 词

在词的组合学中，若两个词互为循环移位则称等价，其等价类称为项链词，或称循环词<sup>[5](https://drops.dagstuhl.de/storage/00lipics/lipics-vol345-mfcs2025/html/LIPIcs.MFCS.2025.48/LIPIcs.MFCS.2025.48.html)</sup><sup> • </sup><sup>[11](https://lib.ysu.am/disciplines_bk/df8ef580dc1f3f479cab7a36e31f6b13.pdf)</sup>。词的重量（某个符号的计数）等性质在移位下不变，因此项链词的重量可由其任一代表元定义<sup>[5](https://drops.dagstuhl.de/storage/00lipics/lipics-vol345-mfcs2025/html/LIPIcs.MFCS.2025.48/LIPIcs.MFCS.2025.48.html)</sup>。

Lyndon 词是在其字符的所有循环排列中字典序最小的本原串——即不是更短词的幂的字符串<sup>[12](https://arxiv.org/abs/1301.0103)</sup>。Lyndon 词用于构造自由李代数的基、构造 de Bruijn 序列，以及求字符串字典序最小的旋转<sup>[12](https://arxiv.org/abs/1301.0103)</sup>。

## 其他应用

在网络编码中，GF(2) 上维数为 n、次数为 l 的循环移位线性码，将其局部编码核限制为至多 l 个大小为 n×n 的循环置换矩阵之和<sup>[13](https://arxiv.org/abs/1707.02163)</sup>。循环移位置换矩阵也出现在准循环码的构造中，其中一个置换矩阵对奇偶校验矩阵的各行进行向下循环移位<sup>[14](https://ycassuto.net.technion.ac.il/files/2018/05/5-8.pdf)</sup>。

## References

1. [numpy.roll, NumPy v1.20 Manual](https://numpy.org/doc/1.20/reference/generated/numpy.roll.html)
2. [ENEE 222 lecture notes: circular shift and reversal, University of Maryland](https://terpconnect.umd.edu/~adrian/enee222/lecture_notes/enee222lectures.pdf)
3. [Pals 2005 thesis, UCSB](https://scg.ece.ucsb.edu/publications/theses/Pals_2005_Thesis.pdf)
4. [Cyclic codes book chapter, University of Massachusetts Dartmouth](https://bpb-us-w2.wpmucdn.com/sites.umassd.edu/dist/f/1260/files/2022/08/bwj-bookchapter.pdf)
5. [Generalized De Bruijn Words, Invertible Necklaces, and the Burrows–Wheeler Transform, MFCS 2025](https://drops.dagstuhl.de/storage/00lipics/lipics-vol345-mfcs2025/html/LIPIcs.MFCS.2025.48/LIPIcs.MFCS.2025.48.html)
6. [DFT properties, SPS Education, TU Eindhoven](https://spseducation.tue.nl/disciplines/discrete/discretesignalprocessing_transforms_dft_properties/)
7. [Cyclic Codes chapter, Universidad de Concepción](https://repositorio.udec.cl/bitstreams/a07549a0-ce11-4cd4-8487-e9de06a93c1c/download)
8. [Cyclic Codes as Invariant Subspaces, Radkova and Bojilov, Sofia University](https://store.fmi.uni-sofia.bg/fmi/algebra/bojilov/CYCLIC_CODES_AS_INVARIANT.pdf)
9. [Cyclic codes notes, Yuri Bazlov, University of Manchester](https://personalpages.manchester.ac.uk/staff/yuri.bazlov/code/notes/ch9.html)
10. [Z2-double cyclic codes, arXiv](https://arxiv.org/abs/1410.5604)
11. [Cyclic shifts and primitive words, course text](https://lib.ysu.am/disciplines_bk/df8ef580dc1f3f479cab7a36e31f6b13.pdf)
12. [2D Lyndon Words and Applications, arXiv](https://arxiv.org/abs/1301.0103)
13. [Circular-shift Linear Network Coding, arXiv](https://arxiv.org/abs/1707.02163)
14. [Quasi-cyclic codes construction, Technion](https://ycassuto.net.technion.ac.il/files/2018/05/5-8.pdf)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › General discrete mathematics and discrete structures › Combinatorics › Enumerative combinatorics › Combinatorics on words › Necklaces and bracelets

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/circular-shift

English original: https://www.edgepedia.org/circular-shift
