-
-
Notifications
You must be signed in to change notification settings - Fork 656
Closed
Milestone
Description
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:
- It is mathematically more correct —
iter(ZZ^n)
now actually enumerates all ofℤ^n
rather than just a subset. - 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