Skip to content

Commit f3881db

Browse files
committed
dem
1 parent 8b58dde commit f3881db

14 files changed

Lines changed: 116 additions & 36 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Manifest.toml
12
local/*
23
docs/build/*
34
.vscode/*

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ uuid = "b4b868b0-69a7-11e9-2db0-173b4e8e576c"
33
version = "0.2.0"
44

55
[deps]
6+
Atom = "c52e3926-4ff0-5f6e-af25-54175e0327b1"
67
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
78
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
89
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
910
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
1011
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
1112
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1213
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
14+
Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d"
1315
Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a"
1416
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1517

1618
[compat]
17-
Nemo = ">= 0.14.3"
19+
Nemo = ">= 0.15.1"
1820
julia = ">= 1.2.0"

demos/DistributedQueens.jl

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
module QueensAlwaysPuzzleMe
22

3-
using Distributed
3+
using Distributed, BenchmarkTools
44

55
# For some background see: https://wp.me/paipV7-E
6+
# There is also a simple (i.e. not distributed) version:
7+
# https://github.com/PeterLuschny/IntegerSequences.jl/blob/master/demos/SimpleQueens.jl
68

79
function solve!(profile, level, size, start, cols, diag4, diag1)
810

@@ -57,22 +59,42 @@ function queens(n::Int)
5759
[profile[n-i+1] for i = 0:n]
5860
end
5961

60-
function demo(up_to)
61-
# The number of threads used for multithreading.
62-
println(Base.Sys.CPU_THREADS)
63-
println(Threads.nthreads())
64-
62+
function ProfileQueens(up_to)
6563
for n in 0:up_to
66-
print("elapsed: ")
67-
@time profile = queens(n)
68-
println("size: ", n)
69-
println("profile: ", profile)
70-
println("nodes: ", sum(profile))
71-
println("solutions: ", profile[n+1])
72-
println()
64+
profile = queens(n)
65+
#show_profile(n, profile)
7366
end
7467
end
7568

76-
demo(10)
69+
"""
70+
julia> show_profile(7, queens(7))
71+
size: 7
72+
profile: [1, 7, 30, 76, 140, 164, 94, 40]
73+
nodes: 552
74+
solutions: 40
75+
"""
76+
function show_profile(n, p)
77+
println("size: ", n)
78+
println("profile: ", p)
79+
println("nodes: ", sum(p))
80+
println("solutions: ", p[n+1])
81+
println()
82+
end
83+
84+
"""
85+
julia> BechmarkQueens()
86+
Number of cpu-threads : 4
87+
Number of threads used: 4
88+
95.699 ms (589 allocations: 48.88 KiB)
89+
"""
90+
function BechmarkQueens()
91+
println("Number of cpu-threads : ", Base.Sys.CPU_THREADS)
92+
println("Number of threads used: ", Threads.nthreads())
93+
println()
94+
95+
@btime ProfileQueens(12)
96+
end
97+
98+
BechmarkQueens()
7799

78100
end # module

demos/SimpleQueens.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module QueensAlwaysMakeProblems
22

33
# For some background see: https://wp.me/paipV7-E
4+
# There is also a 'distributed' version:
5+
# https://github.com/PeterLuschny/IntegerSequences.jl/blob/master/demos/DistributedQueens.jl
6+
47

58
function solve!(profile, level, size, start, cols, diag4, diag1)
69

docs/src/developerguide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ this short notations for the rising and the falling factorial powers are support
119119
FallingFactorial(n::Int, k::Int) = ∏(n - k + 1, n)
120120
```
121121

122-
## Muliti-dimensional sequences
122+
## Multi-dimensional sequences
123123

124124
### The concept of a sequence
125125

docs/src/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ ModuleSetPartitions
334334
ModuleSetPartitionsMType
335335
```
336336
```@docs
337+
ModuleSetPartitionsMType
338+
```
339+
```@docs
337340
ModuleStirlingNumbers
338341
```
339342
```@docs

docs/src/modules.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ GammaHyp: ``(a, b, c, d)`` ↦ ``Γ(a) `` Hypergeometric``1F1(b, c, d).``
235235
  🔶  [IntPartitions](https://github.com/OpenLibMathSeq/IntegerSequences.jl/blob/master/src/IntPartitions.jl)
236236

237237

238-
All integer partitions are listet by two orderings:
238+
All integer partitions are listed by two orderings:
239239
IntegerPartitions(n, byNumPart)
240240
IntegerPartitions(n, byMaxPart)
241241

@@ -416,6 +416,13 @@ Return the numbers of partitions of an ``n``-set into nonempty subsets.
416416
* SetNumber(n::Int, m::Int)
417417
Return the numbers of partitions of an ``n``-set into ``m`` nonempty subsets.
418418

419+
  🔶  [SetPartitionsByShape](https://github.com/OpenLibMathSeq/IntegerSequences.jl/blob/master/src/SetPartitionsByShape.jl)
420+
421+
422+
general Definition
423+
424+
* exported functions
425+
419426
  🔶  [SetPartitionsMType](https://github.com/OpenLibMathSeq/IntegerSequences.jl/blob/master/src/SetPartitionsMType.jl)
420427

421428

src/IntPartitions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export V000041, I072233, L072233, L036038, L078760, L005651, L262071, L292222
1313

1414
"""
1515
16-
All integer partitions are listet by two orderings:
16+
All integer partitions are listed by two orderings:
1717
IntegerPartitions(n, byNumPart)
1818
IntegerPartitions(n, byMaxPart)
1919

src/IntegerSequences.jl

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# Copyright Peter Luschny. License is MIT.
33
# This file includes parts from Combinatorics.jl in modified form.
44

5-
# Version of: UTC 2019-10-24 09:31:01
6-
# 3af04a00-f630-11e9-1ccb-3f8b137e1871
5+
# Version of: UTC 2019-10-26 10:41:45
6+
# 71458000-f7cc-11e9-0078-e76d536f0017
77

88
# Do not edit this file, it is generated from the modules and will be overwritten!
99
# Edit the modules in the src directory and build this file with BuildSequences.jl!
@@ -123,6 +123,7 @@ ModuleSeqUtils,
123123
ModuleSeriesExpansion,
124124
ModuleSetPartitions,
125125
ModuleSetPartitionsMType,
126+
ModuleSetPartitionsMType,
126127
ModuleStirlingNumbers,
127128
ModuleSwingFactorial,
128129
ModuleTriangles,
@@ -4764,7 +4765,7 @@ end
47644765
# *** IntPartitions.jl ****************
47654766
"""
47664767
4767-
All integer partitions are listet by two orderings:
4768+
All integer partitions are listed by two orderings:
47684769
IntegerPartitions(n, byNumPart)
47694770
IntegerPartitions(n, byMaxPart)
47704771
@@ -7881,6 +7882,45 @@ Return the numbers of partitions of an ``n``-set into nonempty subsets.
78817882
$(SIGNATURES)
78827883
"""
78837884
SetNumber(n::Int) = Int(Nemo.bell(n))
7885+
# *** SetPartitionsByShape.jl ****************
7886+
"""
7887+
7888+
general Definition
7889+
7890+
* exported functions
7891+
"""
7892+
const ModuleSetPartitionsMType = ""
7893+
function P(m, n)
7894+
R, x = PolynomialRing(ZZ, "x")
7895+
function recP(m, n, x)
7896+
n == 0 && return R(1)
7897+
sum(binomial(m*n, m*k)*recP(m, n-k, x)*x for k in 1:n)
7898+
end
7899+
n == 0 && return [ZZ(1)]
7900+
p = recP(m, n, x)
7901+
[coeff(p, k) for k in 0:n]
7902+
end
7903+
function xmSetPartitions(m, n, k)
7904+
shapes = (map(x -> x*m, p) for p in IntegerPartitions(n, k))
7905+
p = []
7906+
if shapes != Nothing
7907+
for s in shapes
7908+
if s != Nothing
7909+
vcat(p, [p for p in SetPartitions(s)]) |>println
7910+
end end
7911+
end
7912+
end
7913+
function SP_byLength(m, n)
7914+
n == 0 && return [n]
7915+
[sum(mSetPartitions(m, n, k)) for k in 1:n]
7916+
end
7917+
function SP_byShape(m, n)
7918+
[p for k in 1:n for p in mSetPartitions(m, n, k)]
7919+
end
7920+
RowSum(m, n) = sum(SP_byLength(m, n))
7921+
ARowSum(m, n) = sum((-1)^k*sum(mSetPartitions(m, n, k)) for k in 0:n)
7922+
Diagonal(m,n) = mSetPartitions(m, n, n)[0]
7923+
Central(m, n) = SP_byLength(m, 2n)[n]
78847924
# *** SetPartitionsMType.jl ****************
78857925
"""
78867926

src/QueensProblems.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Returns the profile of the backtrack tree for the n queens problem.
7070
"""
7171
L319284(n) = Queens(n)
7272

73+
7374
#START-TEST-########################################################
7475

7576
using Test
@@ -97,8 +98,7 @@ end
9798

9899
"""
99100
100-
L319284(15)
101-
18.731622 seconds (4 allocations: 480 bytes)
101+
L319284(15) :: 18.731622 seconds (4 allocations: 480 bytes)
102102
"""
103103
function perf()
104104
@time L319284(15)

0 commit comments

Comments
 (0)