Skip to content

Commit

Permalink
lll for Rational bases
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvwx committed Jan 24, 2021
1 parent 4bd785a commit 8641658
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "LLLplus"
uuid = "142c1900-a1c3-58ae-a66d-b187f9ca6423"
keywords = ["lattice reduction", "lattice basis reduction", "shortest vector problem", "closest vector problem", "LLL", "Lenstra-Lenstra-Lovász", "Seysen", "Brun", "VBLAST", "subset-sum problem", "Lagarias-Odlyzko", "Bailey–Borwein–Plouffe formula"]
license = "MIT"
version = "1.3.0"
version = "1.3.1"

[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Expand Down
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ and thereby decode multi-antenna signals.
Finally, to see how the LLL can be used to find spigot formulas for
irrationals, see `spigotBBP`.

### Examples

<details>
<summary><b>Examples</b> (click for details)</summary>
<p>

Each function contains documentation and examples available via Julia's
built-in documentation system, for example with `?lll`. Documentation
Expand Down Expand Up @@ -71,8 +74,12 @@ y=H*u+rand(N)/100;
uhat=cvp(Q'*y,R);
sum(abs.(u-uhat))
```
</p>
</details>

### Execution Time results
<details>
<summary><b>Execution Time results</b> (click for details)</summary>
<p>

In the first test we compare the `lll` function from LLLplus, the
`l2avx` function in the `src\l2.jl` file in LLLplus, the
Expand Down Expand Up @@ -115,20 +122,19 @@ BigFloat) as well as type from external packages (Float128 from
[Quadmath.jl](https://github.com/JuliaMath/Quadmath.jl) and Double64
from [DoubleFloat.jl](https://github.com/JuliaMath/DoubleFloats.jl))
which are used to
generate 40 128x128 matrices, over which execution time for the
generate 60 16x16 matrices, over which execution time for the
lattice reduction techniques is averaged. The vertical axis is a
logarithmic representation of execution time as in the previous
figure. This figure was generated using code in `test/perftest.jl`.

![Time vs data type](docs/src/assets/perfVsDataType.png)

### Notes
</p>
</details>

There are certainly many improvements and additions that could be made
to LLLplus. Even so, it would be hard to compete with
[fplll](https://github.com/fplll/fplll) on features. In fact, a Julia
wrapper around [fplll](https://github.com/fplll/fplll) would be the most
useful addition to lattice tools in Julia.
<details>
<summary><b>Notes</b> (click for details)</summary>
<p>

The algorithm pseudocode in a [survey paper by Wuebben](http://www.ant.uni-bremen.de/sixcms/media.php/102/10740/SPM_2011_Wuebben.pdf) and the
[monograph by Bremner](https://www.amazon.com/Lattice-Basis-Reduction-Introduction-Applications/dp/1439807027)
Expand Down
Binary file modified docs/src/assets/perfVsDataType.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion docs/src/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ end
integerfeasibility
rationalapprox
spigotBBP
hard_sphere
hkz
ishkzreduced
issizereduced
islllreduced
orthogonalitydefect
Expand Down
64 changes: 16 additions & 48 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@
CurrentModule = LLLplus
```

LLLplus includes
LLLplus provides
[Lenstra-Lenstra-Lovász](https://en.wikipedia.org/wiki/Lenstra%E2%80%93Lenstra%E2%80%93Lov%C3%A1sz_lattice_basis_reduction_algorithm)
(LLL), [Brun](https://en.wikipedia.org/wiki/Viggo_Brun), and Seysen
lattice reduction; and solvers for the
(LLL) lattice reduction, solvers for the
[shortest vector problem](https://en.wikipedia.org/wiki/Lattice_problem#Shortest_vector_problem_(SVP))
(SVP) and the [closest vector problem](https://en.wikipedia.org/wiki/Lattice_problem#Closest_vector_problem_.28CVP.29)
(CVP). These tools are
(CVP), and related algorithms. These tools are
used in cryptography, digital communication, and integer programming.
This package is experimental and not a robust tool; use at your own
risk :-)

LLL [1] lattice reduction is a powerful tool that is widely used in
LLL lattice reduction is a powerful tool that is widely used in
cryptanalysis, in cryptographic system design, in digital
communications, and to solve other integer problems. The historical
and practical prominence of the LLL technique in lattice tools is the
reason for its use in the name "LLLplus". LLL reduction is
often used as an approximate solution to the SVP.
We also include Brun [2] and Seysen [3]
lattice reduction techniques. The LLL, Brun, and Seysen algorithms are
based on [4]. The CVP solver is based on [5] and can handle lattices
and bounded integer constellations while the SVP solver is based on [6].
reason for its use in the name "LLLplus". LLL reduction is often used
as an approximate solution to the SVP. We also include
[Brun](https://archive.org/stream/skrifterutgitavv201chri#page/300/mode/2up)
integer relations,
[Seysen](http://link.springer.com/article/10.1007%2FBF01202355)
lattice reduction, and
[Hermite-Korkine-Zolotarev](http://www.cas.mcmaster.ca/~qiao/publications/ZQW11.pdf)
lattice reduction techniques.

One application of lattice tools is in cryptanalysis; as an demo of a
cryptanalytic attack, see the `subsetsum` function. The LLL algorithm
Expand Down Expand Up @@ -115,7 +116,7 @@ BigFloat) as well as type from external packages (Float128 from
[Quadmath.jl](https://github.com/JuliaMath/Quadmath.jl) and Double64
from [DoubleFloat.jl](https://github.com/JuliaMath/DoubleFloats.jl))
which are used to
generate 40 128x128 matrices, over which execution time for the
generate 60 16x16 matrices, over which execution time for the
lattice reduction techniques is averaged. The vertical axis is a
logarithmic representation of execution time as in the previous
figure. This figure was generated using code in `test/perftest.jl`.
Expand All @@ -124,14 +125,9 @@ figure. This figure was generated using code in `test/perftest.jl`.

### Notes

There are certainly many improvements and additions that could be made
to LLLplus. Even so, it would be hard to compete with
[fplll](https://github.com/fplll/fplll) on features. In fact, a Julia
wrapper around [fplll](https://github.com/fplll/fplll) would be the most
useful addition to lattice tools in Julia.

The algorithm pseudocode in the monograph [7] and the survey paper [4]
were very helpful in writing the lattice reduction tools in LLLplus
The algorithm pseudocode in a [survey paper by Wuebben](http://www.ant.uni-bremen.de/sixcms/media.php/102/10740/SPM_2011_Wuebben.pdf) and the
[monograph by Bremner](https://www.amazon.com/Lattice-Basis-Reduction-Introduction-Applications/dp/1439807027)
were helpful in writing the lattice reduction tools in LLLplus
and are a good resource for further study. If you are trying to break
one of the [Lattice Challenge](http://www.latticechallenge.org)
records or are looking for robust, well-proven lattice tools, look at
Expand All @@ -141,31 +137,3 @@ number-theoretic problems the
it uses the [FLINT](http://flintlib.org/) C library to do LLL
reduction on Nemo-specific data types. Finally, no number theorists
have worked on LLLplus; please treat the package as experimental.

### References

[1] A. K. Lenstra; H. W. Lenstra Jr.; L. Lovász, ["Factoring polynomials with rational coefficients"](http://ftp.cs.elte.hu/~lovasz/scans/lll.pdf). Mathematische Annalen 261, 1982.

[2] V. Brun,
["En generalisation av kjedebrøken I,"](https://archive.org/stream/skrifterutgitavv201chri#page/300/mode/2up)
Skr. Vidensk. Selsk. Kristiana, Mat. Nat. Klasse, 1919.

[3] M. Seysen, ["Simultaneous reduction of a lattice basis and its reciprocal basis"](http://link.springer.com/article/10.1007%2FBF01202355) Combinatorica, 1993.

[4] D. Wuebben, D. Seethaler, J. Jalden, and G. Matz, ["Lattice Reduction - A Survey with Applications in Wireless Communications"](http://www.ant.uni-bremen.de/sixcms/media.php/102/10740/SPM_2011_Wuebben.pdf). IEEE Signal Processing Magazine, 2011.

[5] A. Ghasemmehdi, E. Agrell, ["Faster Recursions in Sphere Decoding"](https://publications.lib.chalmers.se/records/fulltext/local_141586.pdf) IEEE
Transactions on Information Theory, vol 57, issue 6 , June 2011.

[6] E. Agrell, T. Eriksson, A. Vardy, and K. Zeger, ["Closest Point Search in
Lattices"](https://www.researchgate.net/publication/3080772_Closest_point_search_in_lattices_IEEE_Trans_Inf_Theory)
IEEE Transactions on Information Theory, vol. 48, no. 8, August 2002.

[7] M. R. Bremner, ["Lattice Basis Reduction: An Introduction to the LLL
Algorithm and Its Applications"](https://www.amazon.com/Lattice-Basis-Reduction-Introduction-Applications/dp/1439807027) CRC Press, 2012.



## List of Functions
```@index
```
1 change: 1 addition & 0 deletions src/LLLplus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export
dataTypeForGram,intTypeGivenBitsRequired

include("lll.jl") # lll, gauss, sizereduction
include("l2.jl") # lll on Rational{Integer} with `l2`
include("cvp.jl") # cvp, svp
include("hkz.jl")
include("brun.jl")
Expand Down
2 changes: 2 additions & 0 deletions src/applications.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ values around the nominal k. This technique is related to that in
robust tool, just a demo.
[1] https://scholarworks.rit.edu/theses/64/
[2] https://pdfs.semanticscholar.org/21a7/c2f9ff29507f1153aefcca04d1cd308e45c0.pdf
# Examples
Expand Down Expand Up @@ -406,6 +407,7 @@ function spigotBBPvec(Td::Type{Tr},s,b,n,K) where {Tr<:Number}
end
return v
end

"""
spigotBBP(α::Td,s,b,n,K,verbose=false) where {Td}
Expand Down
2 changes: 1 addition & 1 deletion src/hkz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ julia> B*Z
1 -1
-1 -1
julia> N=9; Bo=rand(0:10,N,N); Z,_=LLLplus.hkz_red(Bo); B=Bo*Z;
julia> N=10; Bo=rand(0:100,N,N); Z,_=LLLplus.hkz_red(Bo); B=Bo*Z;
julia> ishkzreduced(B)
true
Expand Down
30 changes: 16 additions & 14 deletions src/l2.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
lll(H::AbstractArray{Rational{Td},2}=.75=.51) where {Td<:Integer} =
l2(H,Rational{Td},δ,η)

"""
B = l2(H::AbstractArray{Td,2},TG::Type{Tg},δ=.75,η=.51) where {Td<:Number,Tg<:Number}
Expand All @@ -16,32 +19,30 @@ generally faster than `lll` on small bases, say of dimensions less than 80.
# Examples
```jldoctest
julia> using LLLplus
julia> include("src/l2.jl")
julia> H= [1 2; 3 4];B = l2(H)
julia> H= [1 2; 3 4];B,_ = LLLplus.l2(H); B
┌ Warning: l2 is in a raw (alpha) state and may change. See the help text.
└ @ LLLplus ~/shared/LLLplus/src/l2.jl:42
└ @ LLLplus src/l2.jl:45
2×2 Array{Int64,2}:
1 -1
1 1
julia> H= [.5 2; 3 4]; B= l2(H)
julia> H= [.5 2; 3 4]; B,_= LLLplus.l2(H); B
┌ Warning: l2 is in a raw (alpha) state and may change. See the help text.
└ @ LLLplus src/l2.jl:45
2×2 Array{Float64,2}:
1.5 -1.0
1.0 2.0
julia> H= BigFloat.([1.5 2; 3 4]) .+ 2im; B= l2(H);
┌ Error: `l2` does not handle complex data yet; try `lll`.
└ @ LLLplus ~/shared/LLLplus/src/l2.jl:50
julia> N=30;H = randn(N,N); B = l2(H);
julia> N=30;H = randn(N,N); B,T = LLLplus.l2(H);
┌ Warning: l2 is in a raw (alpha) state and may change. See the help text.
└ @ LLLplus src/l2.jl:45
```
"""
function l2(H::AbstractArray{Td,2},TG::Type{Tg}=Td,δ=.75=.51) where
{Td<:Number,Tg<:Number}

@warn "l2 is in a raw (alpha) state and may change. See the help text." maxlog=1
@warn "l2 is in a raw (alpha) state and may change. See the help text." maxlog=1 _file="src/l2.jl"

if !(0.25 < δ < 1.0)
error("δ must be between 1/4 and 1.");
Expand Down Expand Up @@ -128,7 +129,8 @@ function l2(H::AbstractArray{Td,2},TG::Type{Tg}=Td,δ=.75,η=.51) where
end
κ+=1
end
return B
T = Ti.(round.(inv(H)*B))
return B,T
end

function lazysizereduction!(ηb,κ,B,G,r,μ,s,X,n,d,Tg)
Expand Down Expand Up @@ -176,7 +178,7 @@ function lazysizereduction!(ηb,κ,B,G,r,μ,s,X,n,d,Tg)
end
@goto startCholesky
end

#=
"""
B = l2avx(H::AbstractArray{Td,2},TG::Type{Tg},δ=.75,η=.51) where
{Td<:Number,Tg<:Number}
Expand All @@ -188,7 +190,6 @@ from the `LoopVectorization.jl` package. See the `l2` help text
```julia
julia> using LLLplus
julia> using LoopVectorization
julia> include("src/l2.jl")
julia> H= [1 2; 3 4];B = l2avx(H)
┌ Warning: l2avx is in a raw (alpha) state and may change. See the help text.
└ @ LLLplus ~/shared/LLLplus/src/l2.jl:42
Expand Down Expand Up @@ -336,6 +337,7 @@ function lazysizereductionAVX!(ηb,κ,B,G,r,μ,s,X,n,d,Tg)
end
@goto startCholesky
end
=#



Expand Down
2 changes: 1 addition & 1 deletion src/lll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end
B = copy(H);
N,L = size(B);
Qt,R = qr(B);
Q = Matrix(Qt); # A few cycles can be saved by skipping updates of the Q matrix.
Q = Matrix(Qt); # A few cycles can be saved by removing Q and T

Ti= getIntType(Td)
T = Matrix{Ti}(I, L, L)
Expand Down
4 changes: 2 additions & 2 deletions test/lrtest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ those used in lattice cryptography).
# As function of Integer width
lrtest(50,2.^[4;],[100;],[Int32,Int64,Int128,Float64,BigInt,BigFloat],"rand")
# As function of N
lrtest(50,2.^[0:6;],[100;],[Float64],"rand")
lrtest(50,2 .^[0:6;],[100;],[Float64],"rand")
"""
function lrtest(Ns::Int,N::Array{Int,1},L::Array{Int,1},
dataType::Array{DataType,1},distType)

lrAlgs = [brun,lll, seysen,hkz,]
lrAlgs = [hkz,lll,seysen, sizereduction,brun,]

@printf(" Ns N L dataType")
for ax = 1:min(length(lrAlgs),6)
Expand Down

2 comments on commit 8641658

@chrisvwx
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/28571

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.1 -m "<description of version>" 86416580d974bf121ec8b972cc7ed6a6ba09f32b
git push origin v1.3.1

Also, note the warning: Version 1.3.1 skips over 1.3.0
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

Please sign in to comment.