Skip to content

make iter(ZZ^n) useful #33287

@yyyyx4

Description

@yyyyx4

At the moment, iterating over ZZ^n only ever produces vectors in ℤ × {0}^(n-1):

sage: for i,v in enumerate(ZZ^5):
....:     print(v)
....:     if i > 10: break
....:
(0, 0, 0, 0, 0)
(1, 0, 0, 0, 0)
(-1, 0, 0, 0, 0)
(2, 0, 0, 0, 0)
(-2, 0, 0, 0, 0)
(3, 0, 0, 0, 0)
(-3, 0, 0, 0, 0)
(4, 0, 0, 0, 0)
(-4, 0, 0, 0, 0)
(5, 0, 0, 0, 0)
(-5, 0, 0, 0, 0)
(6, 0, 0, 0, 0)

This patch makes Sage iterate over ZZ^n in a more natural order: Sorted primarily by 1‑norm, secondarily by ‑norm.

There are two motivations to prefer this behavior in particular:

  1. It is mathematically more correct — iter(ZZ^n) now actually enumerates all of ℤ^n rather than just a subset.
  2. It can be useful in some situations (such as in cryptography) when searching for a small error vector of some sort.

CC: @tscrim

Component: categories

Author: Lorenz Panny, Aleksei Udovenko

Branch: a001b6d

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/33287

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions