AFTD Auto-Formalizing Theoretical Domains

cyclic_shift

def

The right cyclic shift operator on a vector v : Fin n → F over a type F, mapping each index i to v ((i + n - 1) % n) when n ≠ 0, and returning v when n = 0.

Statement

def cyclic_shift (n : ℕ) {F : Type*} (v : Fin n → F) : Fin n → F
Defined in
arXiv:2610.28047 Section 2.3
Verified
21 Oct 2026
Axioms
none listed
Used by 2
  • is_cyclic_code_botThe zero subspace of Fin n → F is a cyclic code.
  • is_cyclic_codeA subspace C of Fin n → F over a field F is a cyclic code if for every v in C, cyclic_shift n v is in C.

Read back from the Lean

Given a natural number n, a type F, and a vector/function v : Fin n → F, cyclic_shift n v is the function Fin n → F defined as: if n = 0, it returns v; otherwise (if n ≠ 0), it maps each index i : Fin n to v ⟨(i.val + n - 1) % n, _⟩ (i.e., it cyclically shifts the entries by one position to the right, mapping index i to the entry of v at index (i + n - 1) % n).

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

Lean source view module on GitHub

/-- The right cyclic shift operator on vectors of length n. -/
def cyclic_shift (n : ℕ) {F : Type*} (v : Fin n → F) : Fin n → F := if hn : n = 0 then v
  else fun i => v ⟨(i.val + n - 1) % n, Nat.mod_lt _ (Nat.pos_of_ne_zero hn)⟩
See it in the graphDiscuss this resultChallenge it