-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrianglesExplorer.jl
267 lines (235 loc) · 7.33 KB
/
TrianglesExplorer.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# This file is part of IntegerTriangles.jl.
# Copyright Peter Luschny. License is MIT.
(@__DIR__) ∉ LOAD_PATH && push!(LOAD_PATH, (@__DIR__))
module TrianglesExplorer
using Nemo, OrderedCollections
using TrianglesBase, TrianglesExamples, TrianglesUtils
export Explore, Triangles, SaveToCSV, Inspect
"""
Explore integer triangles via their traits.
The traits and their OEIS references will be saved
as csv-files in the data directory.
"""
const ModuleTrianglesExplorer = ""
const WARNING_ON_NOTFOUND = false
const Kind = ["Std", "Rev", "Inv", "RevInv", "InvRev"]
const Triangles = LittleDict{String, Function}(
"Aitken" => AitkenTriangle,
"Bessel1" => Bessel1Triangle,
"Binomial" => BinomialTriangle,
"Catalan" => CatalanTriangle,
"DArcais" => DArcaisTriangle,
"Delannoy" => DelannoyTriangle,
"Euler" => EulerTriangle,
"EulerS" => EulerSecTriangle,
"EulerT" => EulerTanTriangle,
"Eulerian" => EulerianTriangle,
"EulerianSO2" => EulerianSO2Triangle,
"FallingFact" => FallingFactTriangle,
"Fibonacci" => FibonacciTriangle,
"Fine" => FineTriangle,
"Fubini" => FubiniTriangle,
"Hermite" => HermiteTriangle,
"Laguerre" => LaguerreTriangle,
"Lah" => LahTriangle,
"Motzkin" => MotzkinTriangle,
"Narayana" => NarayanaTriangle,
"RisingFact" => RisingFactTriangle,
"SchroederB" => SchröderBTriangle,
"SchroederL" => SchröderLTriangle,
"StirlingCycle" => StirlingCycleTriangle,
"StirlingSet" => StirlingSetTriangle,
"Rencontres" => RencontresTriangle,
"Trinomial" => TrinomialTriangle,
"TTree" => TTreeTriangle,
"Uni" => UniTriangle,
"Worpitzky" => WorpitzkyTriangle
)
const TraitFunc = LittleDict{String, Function}(
"Triangle" => Flat,
"Reverse" => Reverse,
"Inverse" => Inverse,
"RevInv" => RevInv,
"InvRev" => InvRev,
"DiagTri" => DiagTri,
"PolyTri" => PolyTri,
"Sum" => sum,
"EvenSum" => EvenSum,
"OddSum" => OddSum,
"AltSum" => AltSum,
"DiagSum" => DiagSum,
"Middle" => Middle,
"Central" => Central,
"LeftSide" => LeftSide,
"RightSide" => RightSide,
"PosHalf" => PosHalf,
"NegHalf" => NegHalf,
"PolyVal2" => PolyVal2,
"PolyVal3" => PolyVal3,
"PolyValn" => PolyValn,
"BinConv" => BinomialTransform,
"IBinConv" => IBinomialTransform,
"TransSqrs" => TransSqrs,
"TransNat0" => TransNat0,
"TransNat1" => TransNat1
)
function Show(io, name, kind, trait, seq, savetofile=false)
seq == [] && return []
if typeof(seq) === ℤTri
seq = Flat(seq)
end
anum = GetSeqnum(seq, WARNING_ON_NOTFOUND)
if savetofile
print(".")
print(io, anum, ",", name, ",", kind, ",", trait, ",")
Println(io, SeqToString(seq, 10))
else
print(anum, " ", name, " ", kind, " ", trait, " ")
Println(IOContext(stdout), SeqToString(seq, 10))
end
end
function TriangleVariant(Tri, dim, kind="Std")
if ! (kind in Kind)
@warn("No valid kind!")
return []
end
M = Tri(dim)
kind == "Std" && return M
kind == "Rev" && return reverse.(M)
kind == "InvRev" && (M = reverse.(M))
invM = InverseTriangle(M)
(kind == "Inv" || kind == "InvRev"
|| invM == []) && return invM
return reverse.(invM)
end
const LEN = 19
# Prints full sequence
function Inspect(triangle, kind, trait, dim, oeissearch=false)
T = TriangleVariant(Triangles[triangle], dim, kind)
seq = TraitFunc[trait](T)
seq == [] && return []
if typeof(seq) === ℤTri
Println.(seq)
seq = Flat(seq)
end
anum = GetSeqnum(seq, oeissearch)
println(anum, " ", triangle, " ", kind, " ", trait)
println(SeqToString(seq))
end
"""
(SIGNATURES)
"""
function Explore(triangle, kind, trait, dim)
T = TriangleVariant(Triangles[triangle], dim, kind)
seq = TraitFunc[trait](T)
Show(stdout, triangle, kind, trait, seq)
end
function Explore(T::ℤTri, trait::Function)
seq = trait(T)
if seq == [] || seq === nothing
return []
end
typeof(seq) === ℤTri && (seq = Flat(seq))
println("$trait ")
anum = GetSeqnumUri(seq)
anum === nothing && (anum = "nothing")
seqstr = string(seq[1:min(10, end)])[max(0,11):max(0,end-1)]
String["$trait ", anum, seqstr]
end
"""
"""
function Explore(triangle, kind, trait)
dim = 19
T = TriangleVariant(Triangles[triangle], dim, kind)
seq = TraitFunc[trait](T)
anum = GetSeqnum(seq)
anum === nothing && (anum = "nothing")
seqstr = string(seq[1:min(10, end)])[max(0,11):max(0,end-1)]
String[anum, triangle, kind, trait, seqstr]
end
function Explore(trait::String, dim::Int)
for (name, triangle) in Triangles
for kind in Kind
T = TriangleVariant(triangle, dim, kind)
if T != []
seq = TraitFunc[trait](T)
Show(stdout, name, kind, trait, seq)
end
end
end
end
# The BIG LIST goes to data/profile.txt.
function Explore(savetofile::Bool)
@warn "This will take several minutes and produce the file 'BIGLIST.csv' in the data directory."
path = datapath("BIGLIST.csv")
rm(path; force=true)
open(path, "w") do io
println(io, "Anumber,Triangle,Type,Trait,Sequence")
for (name, triangle) in Triangles
#for kind in Kind
kind = "Std"
T = TriangleVariant(triangle, LEN, kind)
if T != []
for (trait, f) in TraitFunc
Show(io, name, kind, trait, f(T), savetofile)
end
end
#end
end
end
end
function SaveToCSV(name)
T = Triangles[name](LEN)
path = datapath(name * ".csv")
rm(path; force=true)
open(path, "w") do io
println(io, "Trait,ANumber,Sequence")
for (trait, f) in TraitFunc
seq = f(T)
seq == [] && continue
if typeof(seq) === ℤTri
seq = Flat(seq)
end
anum = GetSeqnum(seq)
anum === nothing && (anum = "nothing")
println(io, trait, ",", anum, ",", SeqToString(seq, 10))
end
end
end
function SaveAllToCSV()
@warn "This will take several minutes and produce the csv-files in the data directory."
for (name, f) in Triangles
println(name)
SaveToCSV(name)
end
end
# START-TEST-##############################################
function test()
TLEN = 19
Explore("SchroederB", "Inv", "AltSum", TLEN)
end
function demo()
TLEN = 19
Explore("Binomial", "Std", "PolyVal3", TLEN)
Explore("SchroederB", "Inv", "AltSum", TLEN)
Explore("SchroederL", "Inv", "AltSum", TLEN)
Explore("Motzkin", "Rev", "Central", TLEN)
Explore("Laguerre", "Std", "PosHalf", TLEN)
Explore("Laguerre", "Std", "TransNat0", TLEN)
Explore("Laguerre", "Std", "TransNat1", TLEN)
Explore("Lah", "Std", "TransSqrs", TLEN)
Inspect("Lah", "Std", "TransSqrs", TLEN)
println()
end
function perf()
#Explore(true)
#SaveToCSV("Laguerre")
#SaveAllToCSV()
end
function main()
test()
demo()
perf()
end
main()
end # module