Put reference to arXiv preprint in README.
[fgc-section-5.git] / s5.myr
blobd007a8702e0f0b293e0ac6ec365a8d9c716994c9
1 use std
2 use iter
4 use t
5 use quiver
6 use yakmo
8 use "types"
9 use "expound"
10 use "factorization-coords"
11 use "kc"
12 use "latex"
13 use "mkQ"
14 use "M"
15 use "mutations"
16 use "roots"
17 use "util"
18 use "verification"
20 const main = {args
21         var seed : uint32 = (std.now() : uint32)
22         var fast_mutations : bool = false
23         var kc : KC_type
24         var optdef = [
25                 .argdesc = "([clav | latex]-[Q | Qdv | Qdh] | print-M | [print | test]-[murot | muflip ])",
26                 .minargs = 1,
27                 .maxargs = 1,
28                 .opts = [
29                      [ .opt = 'g', .arg = "group", .desc = "something like ‘F4’ or ‘B10’", .optional = false ],
30                      [ .opt = 'f', .desc = "when testing mutations, skip reordering", .optional = true ],
31                      [ .opt = 'S', .arg = "seed", .desc = "Something like ‘0x123’ or ‘101’", .optional = true],
32                 ][:],
33         ]
34         var cmd = std.optparse(args, &optdef)
36         for opt : cmd.opts
37                 match opt
38                 | ('g', s):
39                         match parse_KC_type(s)
40                         | `std.Ok x: kc = x
41                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
42                         ;;
43                 | ('f', _): fast_mutations = true
44                 | ('S', s):
45                         match std.intparse(s)
46                         | `std.Some x: seed = x
47                         | `std.None: std.fatal("{}: Cannot parse seed ‘{}’\n", s)
48                         ;;
49                 | _: /* impossible */
50                 ;;
51         ;;
53         for arg : cmd.args
54                 if std.eq(arg, "clav-Q")
55                         match mk_Q(kc)
56                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
57                         | `std.Ok q: std.put("{}\n", quiver.to_bytes(q))
58                         ;;
59                 elif std.eq(arg, "latex-Q")
60                         match mk_Q(kc)
61                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
62                         | `std.Ok q: std.put("{}\n", latex_from_quiver(q))
63                         ;;
64                 elif std.eq(arg, "clav-Qdv")
65                         match mk_Qdv(kc)
66                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
67                         | `std.Ok Qdv: std.put("{}\n", quiver.to_bytes(Qdv))
68                         ;;
69                 elif std.eq(arg, "latex-Qdv")
70                         match mk_Qdv(kc)
71                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
72                         | `std.Ok Qdv: std.put("{}\n", latex_from_quiver(Qdv))
73                         ;;
74                 elif std.eq(arg, "clav-Qdh")
75                         match mk_Qdh(kc)
76                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
77                         | `std.Ok Qdh: std.put("{}\n", quiver.to_bytes(Qdh))
78                         ;;
79                 elif std.eq(arg, "latex-Qdh")
80                         match mk_Qdh(kc)
81                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
82                         | `std.Ok Qdh: std.put("{}\n", latex_from_quiver(Qdh))
83                         ;;
84                 elif std.eq(arg, "print-murot")
85                         var mures
87                         if fast_mutations
88                                 mures = get_mutwistingrot(kc)
89                         else
90                                 mures = get_murot(kc)
91                         ;;
93                         match mures
94                         | `std.Err e: std.fatal("{}:  Error: {}\n", cmd.prog, e)
95                         | `std.Ok mu:
96                                 std.put("mu =")
97                                 for vertex : mu
98                                         std.put(" {}", vertex)
99                                 ;;
100                                 std.put("\n")
101                         ;;
102                 elif std.eq(arg, "print-muflip")
103                         var mures
105                         if fast_mutations
106                                 mures = get_mutwistingflip(kc)
107                         else
108                                 mures = get_muflip(kc)
109                         ;;
111                         match mures
112                         | `std.Err e: std.fatal("{}:  Error: {}\n", cmd.prog, e)
113                         | `std.Ok mu:
114                                 std.put("mu =")
115                                 for vertex : mu
116                                         std.put(" {}", vertex)
117                                 ;;
118                                 std.put("\n")
119                         ;;
120                 elif std.eq(arg, "print-M")
121                         var c
122                         match get_coxeter_elt(kc)
123                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
124                         | `std.Ok cc: c = cc
125                         ;;
126                         var rank = get_n(kc)
127                         var w0 = get_w0(kc)
128                         var m = w0.len
129                         var h1 = [][:]
130                         var h2 = [][:]
131                         var h3 = [][:]
132                         var u = [][:]
133                         var sigmaG = [][:]
134                         match get_sigmaG_permutation(kc)
135                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
136                         | `std.Ok perm: sigmaG = perm
137                         ;;
138                         for var j = 0; j < rank; ++j
139                                 std.slpush(&h1, [
140                                         .k = j + 1,
141                                         .c = std.try(yakmo.ratfuncfromS(std.fmt("h1{}", c[j]), "1")),
142                                 ])
143                                 std.slpush(&h2, [
144                                         .k = j + 1,
145                                         .c = std.try(yakmo.ratfuncfromS(std.fmt("h2{}", c[j]), "1")),
146                                 ])
147                                 std.slpush(&h3, [
148                                         .k = j + 1,
149                                         .c = std.try(yakmo.ratfuncfromS(std.fmt("h3{}", c[j]), "1")),
150                                 ])
151                         ;;
152                         for var j = rank + 1; j <= m; ++j
153                                 std.slpush(&u, [
154                                         .k = j,
155                                         .c = std.try(yakmo.ratfuncfromS(std.fmt("g{}", j), "1")),
156                                 ])
157                         ;;
159                         var alpha : conf_3_star = [ .h1 = h1, .h2 = h2, .h3 = h3, .u = u ]
160                         var d = get_trivial_Dynkin_automorphism(kc)
161                         var T_Q0
162                         match apply_M(kc, &alpha, d)
163                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
164                         | `std.Ok (lT_Q, _): T_Q0 = lT_Q
165                         ;;
167                         std.put("A : {}\n", T_Q0.A[1:])
168                         std.put("B : {}\n", T_Q0.B[1:])
169                         std.put("C : {}\n", T_Q0.C[1:])
170                         std.put("v : \n")
171                         var h = coxeter_num(kc)
172                         var trivial : yakmo.ratfunc# = yakmo.rid()
173                         auto trivial
174                         for var j = 1; j < (h / 2); ++j
175                                 for i : c
176                                         yakmo.reduceratfunc(T_Q0.v[i][j])
178                                         var name = vname(i, j)
179                                         std.put("{w=8} : {}", name, T_Q0.v[i][j])
180                                         std.put("\n")
181                                 ;;
182                         ;;
183                 elif std.eq(arg, "test-murot")
184                         match numerically_test_rotate(kc, seed, fast_mutations)
185                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
186                         | `std.Ok void:
187                         ;;
188                 elif std.eq(arg, "test-muflip")
189                         match numerically_test_flip(kc, seed, fast_mutations)
190                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
191                         | `std.Ok void:
192                         ;;
193                 elif std.eq(arg, "variables-murot")
194                         /*
195                            undocumented -- probably not of use to anyone else.
197                            Print the intermediate Laurent polynomials
198                            describing the quiver mutation corresponding
199                            to murot. TODO: now that you have code for
200                            Laurent polynomials, use those instead.
201                          */
202                         var mures
203                         if fast_mutations
204                                 mures = get_mutwistingrot(kc)
205                         else
206                                 mures = get_murot(kc)
207                         ;;
209                         match mures
210                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
211                         | `std.Ok mu:
212                                 match mk_Q(kc)
213                                 | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
214                                 | `std.Ok q:
215                                         expound_mutation(q, mu)
216                                 ;;
217                         ;;
218                 elif std.eq(arg, "print-cartan-matrix")
219                         /*
220                            undocumented -- probably not of use to anyone else
222                            Print the Cartan matrix for g. Useful for
223                            checking whether conventions agree.
224                          */
225                         var A = get_cartan_matrix(kc)
226                         for row : A
227                                 std.put("[")
228                                 for val : row
229                                         std.put(" {w=2,p= }", val)
230                                 ;;
231                                 std.put(" ]\n")
232                         ;;
233                 elif std.eq(arg, "print-sigmaG")
234                         /*
235                            undocumented -- probably not of use to anyone else
237                            Print the Cartan matrix for g. Useful for
238                            checking whether conventions agree.
239                          */
240                         std.put("σG = {}\n", std.try(get_sigmaG_permutation(kc)))
241                 elif std.eq(arg, "print-bkl")
242                         /*
243                            undocumented -- probably not of use to anyone else
245                            Print the matrix for ⟨γ_k, (a^i_l)^v⟩ in
246                            terms of k and l. Useful for converting
247                            between minor coordinates and factorization
248                            coordinates by hand.
249                          */
250                         match get_bkl(kc)
251                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
252                         | `std.Ok bkl:
253                                 var text : byte[:][:][:] = [][:]
254                                 var max_width = 0
255                                 for var k = 0; k < bkl.len; ++k
256                                         var this_row = [][:]
257                                         for var l = 0; l < bkl[k].len; ++l
258                                                 var this_entry = std.fmt("{}", bkl[k][l])
259                                                 max_width = std.max(max_width, this_entry.len)
260                                                 std.slpush(&this_row, this_entry)
261                                         ;;
262                                         std.slpush(&text, this_row)
263                                 ;;
264                                 var fmt = std.fmt(" {{w={},p= }} ", max_width)
265                                 var dashes = [][:]
266                                 for var k = 0; k < max_width + 2; ++k
267                                         std.slpush(&dashes, ('-' : byte))
268                                 ;;
269                                 std.put(" ⟨γ_k, (a^i_l)^v⟩ :\n")
270                                 std.put("   k \\    l\n")
271                                 std.put("      |")
272                                 for var l = 0; l < bkl[0].len; ++l
273                                         std.put(fmt, l + 1)
274                                 ;;
275                                 std.put("\n")
277                                 std.put("  ----+")
278                                 for var l = 0; l < bkl[0].len; ++l
279                                         std.put("{}", dashes)
280                                 ;;
281                                 std.put("\n")
283                                 for var k = 0; k < bkl.len; ++k
284                                         std.put(" {w=4,p= } |", k + 1)
285                                         for var l = 0; l < bkl[0].len; ++l
286                                                 std.put(fmt, text[k][l])
287                                         ;;
288                                         std.put("\n")
289                                 ;;
290                         ;;
291                 elif std.eq(arg, "test-bkl")
292                         /*
293                            undocumented -- probably not of use to anyone else
295                            Test that my formula for ⟨γ_k, (a^i_l)^v⟩ has
296                            no off-by-ones.
297                          */
298                         var right_bkl
299                         var predicted_bkl
300                         match get_bkl(kc)
301                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
302                         | `std.Ok bkl: right_bkl = bkl
303                         ;;
304                         match predict_bkl(kc)
305                         | `std.Err e: std.fatal("{}: Error: {}\n", cmd.prog, e)
306                         | `std.Ok bkl: predicted_bkl = bkl
307                         ;;
309                         var right_text : byte[:][:][:] = [][:]
310                         var predicted_text : byte[:][:][:] = [][:]
311                         var max_width = 0
312                         var good_color = "\u{001b}[48;2;12;55;55m"
313                         var bad_color = "\u{001b}[48;2;85;12;12m"
314                         var end_color = "\u{001b}[0m"
315                         for var k = 0; k < right_bkl.len; ++k
316                                 var right_row = [][:]
317                                 var predicted_row = [][:]
318                                 for var l = 0; l < right_bkl[k].len; ++l
319                                         var right_entry = std.fmt("{}", right_bkl[k][l])
320                                         var predicted_entry = std.fmt("{}", predicted_bkl[k][l])
321                                         max_width = std.max(max_width, right_entry.len)
322                                         max_width = std.max(max_width, predicted_entry.len)
323                                         std.slpush(&right_row, right_entry)
324                                         std.slpush(&predicted_row, predicted_entry)
325                                 ;;
326                                 std.slpush(&right_text, right_row)
327                                 std.slpush(&predicted_text, predicted_row)
328                         ;;
329                         var fmt = std.fmt(" {{w={},p= }} ", max_width)
330                         var dashes = [][:]
331                         for var k = 0; k < max_width + 2; ++k
332                                 std.slpush(&dashes, ('-' : byte))
333                         ;;
334                         std.put(" ⟨γ_k, (a^i_l)^v⟩ :\n")
335                         std.put("   k \\    l\n")
336                         for text : [right_text, predicted_text][:]
337                                 std.put("      |")
338                                 for var l = 0; l < right_bkl[0].len; ++l
339                                         std.put(fmt, l + 1)
340                                 ;;
341                                 std.put("\n")
343                                 std.put("  ----+")
344                                 for var l = 0; l < right_bkl[0].len; ++l
345                                         std.put("{}", dashes)
346                                 ;;
347                                 std.put("\n")
349                                 for var k = 0; k < right_bkl.len; ++k
350                                         std.put(" {w=4,p= } |", k + 1)
351                                         for var l = 0; l < right_bkl[0].len; ++l
352                                                 if std.eq(right_bkl[k][l], predicted_bkl[k][l])
353                                                         std.put(good_color)
354                                                 else
355                                                         std.put(bad_color)
356                                                 ;;
357                                                 std.put(fmt, text[k][l])
358                                                 std.put(end_color)
359                                         ;;
360                                         std.put("\n")
361                                 ;;
362                                 std.put("\n")
363                         ;;
364                 elif std.eq(arg, "print-fc-from-mc")
365                         /*
366                            undocumented -- probably not of use to anyone else
368                            Given interior minor coordinates u1, u2, ...,
369                            compute the formula for each factorization
370                            coordinate tk.
371                          */
372                         var mc : minor_coordinate[:] = [][:]
373                         var w0 : weyl_reflection[:] = get_w0(kc)
374                         for var k = 1; k <= w0.len; ++k
375                                 std.slpush(&mc, [ .k = k, .c = std.try(yakmo.ratfuncfromS(std.fmt("u{}", k), "1")) ])
376                         ;;
378                         match interior_fc_from_mc(kc, mc)
379                         | `std.Err e: std.put("interior_fc_from_mc: {}\n", e)
380                         | `std.Ok fc:
381                                 for var k = 0; k < fc.len; ++k
382                                         match fc[k]
383                                         | `X(_, expr): std.put("t{}    =    {}\n", k + 1, expr)
384                                         | _: std.put("t{} was {}, should have been some x_i(...)\n", k + 1, fc[k])
385                                         ;;
386                                 ;;
387                         ;;
388                 elif std.eq(arg, "print-mc-from-fc")
389                         /*
390                            undocumented -- probably not of use to anyone else
392                            Given interior factorization coordinates t1,
393                            t2, ..., compute the formula for each minor
394                            coordinate uk.
395                          */
396                         var fc : factorization_coordinate[:] = [][:]
397                         var w0 : weyl_reflection[:] = get_w0(kc)
398                         for var k = 1; k <= w0.len; ++k
399                                 std.slpush(&fc, `X(w0[k - 1], std.try(yakmo.ratfuncfromS(std.fmt("t{}", k), "1"))))
400                         ;;
402                         match interior_mc_from_fc(kc, fc)
403                         | `std.Err e: std.put("interior_mc_from_fc: {}\n", e)
404                         | `std.Ok mc:
405                                 for var k = 0; k < mc.len; ++k
406                                         std.put("u{}    =    {}\n", mc[k].k, mc[k].c)
407                                 ;;
408                         ;;
409                 else
411                         std.optusage(cmd.prog, &optdef)
412                         std.exit(1)
413                 ;;
414         ;;