Repository navigation
Expand file tree
/
Copy pathtemplate.typ
More file actions
1025 lines (964 loc) · 28.2 KB
/
Copy pathtemplate.typ
File metadata and controls
1025 lines (964 loc) · 28.2 KB
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 参考 https://github.com/Fr4nk1in-USTC/typst-notebook
//#import "typst-sympy-calculator.typ": *
#import "@preview/lemmify:0.1.8": *
// #import "@preview/commute:0.2.0": node, arr, commutative-diagram
#import "@preview/oxifmt:1.0.0": strfmt
#import "@preview/showybox:2.0.3": showybox
#import "./autoArithExp/lib.typ": *
#let __print_commute = true
// #let old-commutative-diagram = commutative-diagram
// #let commutative-diagram(print: __print_commute, ..args) = {
// if print {
// old-commutative-diagram(..args)
// }
// else {
// align(center)[
// #text(style: "italic", font: "New Computer Modern")[
// _Commutative diagram_
// ]
// ]
// }
// }
#let en-font = "New Computer Modern"
#let TODO = [#text("TODO", fill: red, font: en-font)]
#let _der(y, x, times, sign) = {
if checkOne(times) {
[$(#sign #autoBraceIfAddOrSub(y)) / (#sign #x)$]
}
else {
[$(#sign^#times #autoBraceIfAddOrSub(y)) / (#sign #x^#times)$]
}
}
#let der(y, x) = _der(y, x, $1$, $dif$)
#let derN(y, x, times) = _der(y, x, times, $dif$)
#let partialDer(y, x) = _der(y, x, $1$, $partial$)
#let partialDerN(y, x, times) = _der(y, x, times, $partial$)
#let elasticity(P, Q) = $((partial #Q)/(partial #P))/(#Q / #P)$
#let autoVec3(a, delim: "(" ) = $vec(#a _1, #a _2, #a _3, delim: delim)$
#let autoVecN(a, n, delim: "(" ) = $vec(#a _1, #a _2, dots.v, #a _#n, delim: delim)$
#let autoVecNF(f, n, delim: "(" ) = $vec(#(f(1)), #(f(2)), dots.v, #(f(n)), delim: delim)$
#let autoRListNF(f, n) = $#(f(1)), #(f(2)), dots, #(f(n))$
#let autoRVecNF(f, n ) = $(autoRListNF(#f, #n))$
#let autoRListN(a, n) = $#a _1, #a _2, dots, #a _#n$
#let autoRVecN(a, n) = $(autoRListN(#a, #n))$
#let autoMat3(delim: "(", ..var) = {
let varList = var.pos()
let row(n) = varList.map(v => $#v _#n$)
let data = (row(1), row(2), row(3))
math.mat(delim: delim, ..data)
}
#let autoMat(delim: "(", n, pre: 3, interval: 2, post: 3, f) = {
let rows_pre = ();
for i in range(1, pre + 1) {
let row = ();
row = row + range(1, pre + 1).map(j => f(i, j))
row.push($dots$)
row = row + range(post - 1, -1, step: -1).map(j => f(i, autoSub(n, j)))
rows_pre.push(row)
}
let row_dots = ()
for i in range(0, interval) {
let row = range(1, pre + 1).map(i => $dots.v$) + ($dots.down$,) + range(post - 1, -1, step: -1).map(i => $dots.v$)
row_dots.push(row)
}
let rows_post = ()
for i in range(post - 1, -1, step: -1) {
let row = ();
row = row + range(1, pre + 1).map(j => f(autoSub(n, i), j))
row.push($dots$)
row = row + range(post - 1, -1, step: -1).map(j => f(autoSub(n, i), autoSub(n, j)))
rows_post.push(row)
}
math.mat(delim: delim, ..rows_pre, ..row_dots, ..rows_post)
}
// #let autoMat(delim: "(", f) =
#let sep(..xs) = xs.pos().join($space$)
#let where = "where"
#let with = "with"
#let suchThat = $ space "s.t." space $
#let andC = $" 且 "$
#let orC = $" 或 "$
#let hb = $hat(bold(beta))$
#let sb = $bold(beta)^star$
#let bbeta = $bold(beta)$
#let balpha = $bold(alpha)$
#let bgamma = $bold(gamma)$
#let htheta = $hat(theta)$
#let halpha = $hat(alpha)$
#let hbeta = $hat(beta)$
#let tbeta = $tilde(beta)$
#let hgamma = $hat(gamma)$
#let btheta = $bold(theta)$
#let bphi = $bold(phi)$
#let bpsi = $bold(psi)$
#let hX = $hat(X)$
#let hY = $hat(Y)$
#let hy = $hat(y)$
#let by = $bold(y)$
#let bY = $bold(Y)$
#let bx = $bold(x)$
#let bX = $bold(X)$
#let bu = $bold(u)$
#let bU = $bold(U)$
#let bv = $bold(v)$
#let be = $bold(e)$
#let bp = $bold(p)$
#let bE = $bold(E)$
#let bF = $bold(F)$
#let ba = $bold(a)$
#let bA = $bold(A)$
#let bB = $bold(B)$
#let bC = $bold(C)$
#let bD = $bold(D)$
#let bO = $bold(O)$
#let bP = $bold(P)$
#let bp = $bold(p)$
#let bG = $bold(G)$
#let bH = $bold(H)$
#let bi = $bold(i)$
#let bj = $bold(j)$
#let bk = $bold(k)$
#let bI = $bold(I)$
#let bJ = $bold(J)$
#let bK = $bold(K)$
#let bsigma = $bold(sigma)$
#let bxi = $bold(xi)$
#let xbar = $overline(x)$
#let Xbar = $overline(X)$
#let Ybar = $overline(Y)$
#let ybar = $overline(y)$
#let zbar = $overline(z)$
#let Zbar = $overline(Z)$
#let mubar = $overline(mu)$
#let vbar = $overline(v)$
#let duel(X) = autoPow(X, $*$)
#let duelSpace(X) = duel(X)
#let cov = math.op("Cov")
#let var = math.op("Var")
#let cor = math.op("Cor")
#let weakConverge = $limits(harpoon)^w$
#let weakSConverge = $limits(harpoon)^(w*)$
#let inner(x, y) = $〈#x, #y〉$
#let span(..x) = $<#(x.pos().join($, $))>$
#let HomoCoor = math.vec.with(delim: "[")
#let autoHomoCoor3 = autoVec3.with(delim: "[")
#let Det = math.mat.with(delim: "|")
#let notModels = sym.tack.rr.not
#let Gal = math.op("Gal")
#let Hom = math.op("Hom")
#let Ext = math.op("Ext")
#let Ob = math.op("Ob")
#let cone = math.op("cone")
#let Proj = math.op("Proj")
#let Spec = math.op("Spec")
#let Spv = math.op("Spv")
#let Tor = math.op("Tor")
#let ht = math.op("height")
#let Ann = math.op("Ann")
#let Ass = math.op("Ass")
#let Sylow(p) = $"Sylow"-#p$
#let Isom = math.op("Isom")
#let diag = math.op("diag")
#let rank = math.op("rank")
#let dist = math.op("dist")
#let convexHull = math.op("co")
#let approxVar(R) = $tilde(R)$
#let GL = math.op("GL")
#let char = math.op("char")
#let Frac = math.op("Frac")
// #let Inv(a) = $#a^(-1)$
#let conjugateLeft(g, a) = $#g^(-1) #a #g$
#let conjugateRight(g, a) = $#g #a #g^(-1)$
#let quotient(G, H) = $#G\\#H$
#let empty = ""
#let lift = math.arrow.t
#let quo = math.class("relation", $slash$)
#let ord = math.op("ord")
#let ei(x) = $e^(i #x)$
#let eiB(x) = $e^(#x i)$ // i Behind
#let sgn = math.op("sgn")
#let arctanh = math.op("arctanh")
#let Res(f, i) = $op("Res") (#f \; #i)$
#let closure(X) = $overline(#X)$
#let lcm = math.op("lcm")
#let Der = math.op("Der")
#let Arg = math.op("Arg")
#let End = math.op("End")
#let ReT = math.op("Re")
#let ImT = math.op("Im")
#let ev = math.op("ev")
#let coev = math.op("coev")
#let natTransb = math.arrow.double.b
#let natTranst = math.arrow.double.t
#let eqv = sym.tilde.equiv
#let Inter = math.inter.big
#let Union = math.union.big
#let Tot = math.op("Tot")
#let arrowb = $arrow.bar$
#let ite(cond, r1, r2) = $"if" autoBraceIfAddOrSub(#cond) "then" autoBraceIfAddOrSub(#r1) "else" autoBraceIfAddOrSub(#r2) $
#let ignoreOne(x) = {
if x == [1] {
[]
} else {
[#x]
}
}
#let argmax = math.op("argmax")
#let argmin = math.op("argmin")
#let incrementSign(x, i, k) = {
let i1 = int(i)
if i1 = 0 {
$#x_#k$
}
else {
$#x_#(i + k)$
}
}
#let linearCombination(name: $C$, start: 1, ..args) = {
let fun(list) = list.enumerate().map(
l => {
let (i, x) = l
$#name _(#(i + start)) #x $
})
.join(" + ")
// 不能这么写
// let fun_error(list) = list.enumerate().map(
// (i, x) => {
// $C_(#(i + 1)) #x $
// })
// .join(" + ")
fun(args.pos())
}
#let linearCombinationC = linearCombination.with(name: $C$)
#let linearCombinationA = linearCombination.with(name: $A$)
#let linearCombinationa = linearCombination.with(name: $a$)
#let linearCombinationb = linearCombination.with(name: $b$)
#let linearCombinationlambda = linearCombination.with(name: $lambda$)
#let linearCombinationmu = linearCombination.with(name: $mu$)
// e^(x^2)
#let eX2(x) = autoPow($e$, autoPow(x, 2))
// e^(-x^2)
#let eNX2(x) = autoPow($e$, autoNeg(autoPow(x, 2)))
// e^(x i)
#let eXi(x) = autoPow($e$, autoMul(x, $i$))
// e^(x / y)
#let eXdY(x, y) = autoPow($e$, autoFraction(x, y))
// e^(- x/y)
#let eNXdY(x, y) = autoPow($e$, autoNeg(autoFraction(x, y)))
// e^(- x^2/y)
#let eNX2dY(x, y) = eNXdY(autoPow(x, 2), y)
#let Inv(x) = autoPow(x, -1)
// generalized inverse
#let gInv(x) = autoPow(x, $-$)
// Moore-Penrose inverse
#let MPInv(x) = autoPow(x, $+$)
#let NormalDis(x, mu, sigma) = autoMul(
autoFraction(
oneContent, autoMul(
autoSqrt($2 pi$), sigma
)
),
eNX2dY(autoSub(x, mu), autoMul(2, autoPow(sigma, 2)))
)
// $checkAttachT(sigma)$
// #(type(repr(getBodyArr(math.sigma).at(0))) == str)
// $eNX2dY(x, 2 )$
// #repr(getBodyArr($e$).at(0))
// $NormalDis(x, mu, sigma)$
// #getBodyArr($e^(-1/2 (x - mu)^2/sigma^2)$)
#let NormalDisN(x, mu, sigma, n) = autoMul(
autoPow($2 pi$, autoNeg(autoFraction(n, 2))),
autoMul(autoPow(autoDet(sigma), $- 1/2$),
autoPow($e$,
autoNeg(
// $1/2 autoSub(x, mu)^T autoPow(sigma, -1) autoSub(x, mu)$
autoMul($1/2$,
autoMul(
autoPow(autoSub(x, mu), $T$),
autoMul(
autoPow(sigma, -1),
autoSub(x, mu)
)
)
)
)
)
)
)
#let ExpDis(x, lambda) = autoMul(lambda, autoPow($e$, autoNeg(autoMul(lambda, x))))
#let PoissonDis(k, lambda) = autoFraction(
autoMul(autoPow(lambda, k),
autoPow($e$, autoNeg(lambda))),
autoFactorial(k)
)
#let quadForm(x, A, y, trans-inner: false) = autoMul(
autoTrans(x, trans-inner: trans-inner),
autoMul(A,
y)
)
#let quadFormSym(x, A) = quadForm(x, A, x)
#let tMul(A, trans-inner: false) = autoMul(autoTrans(A, trans-inner: trans-inner), A)
#let mulT(A, trans-inner: false) = autoMul(A, autoTrans(A, trans-inner: trans-inner))
#let orthogonal = math.op($tack.t$)
#let orthogonalCom(x) = autoPow(x, orthogonal)
#let defaultSum = (
Var: $n$,
Lower: $0$,
Upper: $+infinity$,
Op: $sum$
)
#let defaultProd = (
Var: $n$,
Lower: $1$,
Upper: $+infinity$,
Op: $product$
)
#let directSum = math.plus.o
#let defaultDirectSum = (
Var: $n$,
Lower: $0$,
Upper: $+infinity$,
Op: $directSum$
)
#let sumf(var: defaultSum.Var, lower: defaultSum.Lower, upper: defaultSum.Upper) = $sum_(#var = #lower)^(#upper)$
#let prodf(var: defaultProd.Var, lower: defaultProd.Lower, upper: defaultProd.Upper) = $product_(#var = #lower)^(#upper)$
#let directSumf(var: defaultDirectSum.Var, lower: defaultDirectSum.Lower, upper: defaultDirectSum.Upper) = $directSum_(#var = #lower)^(#upper)$
#let bigOpBr(config, body) = $#(config.Op)_(#config.Var #showIf(not checkEmpty(config.Lower))[=] #config.Lower)^(#config.Upper) #autoBraceIfAddOrSub(body)$
#let sumfBr(config: defaultSum, body) = bigOpBr((Op: $sum$) + config, body)
#let prodfBr(config: defaultProd, body) = bigOpBr((Op: $product$) + config, body)
#let directSumfBr(config: defaultDirectSum, body) = bigOpBr((Op: $directSum$) + config, body)
// #let prodfBr(config, body) = $product_(#config.var = #config.lower)^(#config.upper) #autoBraceIfAddOrSub(Body)$
// #let directSumfBr(var: defaultDirectSum.Var, lower: defaultDirectSum.Lower, upper: defaultDirectSum.Upper, body) = $directSum_(#var = #lower)^(#upper) #autoBraceIfAddOrSub(Body)$
#let all_configs = {
let res = ()
let vars = ($i$, $j$, $k$)
let lowers = ($0$, $1$, $2$)
let uppers = ($n$, $m$, $N$, $M$, $+infinity$)
for var in vars {
for lower in lowers {
for upper in uppers {
res.push((Var: var, Lower: lower, Upper: upper))
}
}
}
res
}
#let config1iN = (
Var: $i$,
Lower: $1$,
Upper: $n$,
)
#let config1iinf = (
Var: $i$,
Lower: $1$,
Upper: $+infinity$,
)
#let config0iN = (
Var: $i$,
Lower: $0$,
Upper: $n$,
)
#let config0iinf = (
Var: $i$,
Lower: $0$,
Upper: $+infinity$,
)
#let _gen_big_expressions(configs, fBr, body_transformer) = {
configs.map(config => {
body => {
fBr(config: config, body_transformer(body))
}
})
}
#let (
sumi0n, sumi0m, sumi0N, sumi0M, sumi0inf,
sumi1n, sumi1m, sumi1N, sumi1M, sumi1inf,
sumi2n, sumi2m, sumi2N, sumi2M, sumi2inf,
sumj0n, sumj0m, sumj0N, sumj0M, sumj0inf,
sumj1n, sumj1m, sumj1N, sumj1M, sumj1inf,
sumj2n, sumj2m, sumj2N, sumj2M, sumj2inf,
sumk0n, sumk0m, sumk0N, sumk0M, sumk0inf,
sumk1n, sumk1m, sumk1N, sumk1M, sumk1inf,
sumk2n, sumk2m, sumk2N, sumk2M, sumk2inf,
) = _gen_big_expressions(
all_configs,
sumfBr,
(n => n)
)
#let (
prodi0n, prodi0m, prodi0N, prodi0M, prodi0inf,
prodi1n, prodi1m, prodi1N, prodi1M, prodi1inf,
prodi2n, prodi2m, prodi2N, prodi2M, prodi2inf,
prodj0n, prodj0m, prodj0N, prodj0M, prodj0inf,
prodj1n, prodj1m, prodj1N, prodj1M, prodj1inf,
prodj2n, prodj2m, prodj2N, prodj2M, prodj2inf,
prodk0n, prodk0m, prodk0N, prodk0M, prodk0inf,
prodk1n, prodk1m, prodk1N, prodk1M, prodk1inf,
prodk2n, prodk2m, prodk2N, prodk2M, prodk2inf,
) = _gen_big_expressions(
all_configs,
prodfBr,
(n => n)
)
#let (
sumi0n2, sumi0m2, sumi0N2, sumi0M2, sumi0inf2,
sumi1n2, sumi1m2, sumi1N2, sumi1M2, sumi1inf2,
sumi2n2, sumi2m2, sumi2N2, sumi2M2, sumi2inf2,
sumj0n2, sumj0m2, sumj0N2, sumj0M2, sumj0inf2,
sumj1n2, sumj1m2, sumj1N2, sumj1M2, sumj1inf2,
sumj2n2, sumj2m2, sumj2N2, sumj2M2, sumj2inf2,
sumk0n2, sumk0m2, sumk0N2, sumk0M2, sumk0inf2,
sumk1n2, sumk1m2, sumk1N2, sumk1M2, sumk1inf2,
sumk2n2, sumk2m2, sumk2N2, sumk2M2, sumk2inf2,
) = _gen_big_expressions(
all_configs,
sumfBr,
(body => autoPow(body, 2))
)
#let (
sumi0nnr, sumi0mnr, sumi0Nnr, sumi0Mnr, sumi0infnr,
sumi1nnr, sumi1mnr, sumi1Nnr, sumi1Mnr, sumi1infnr,
sumi2nnr, sumi2mnr, sumi2Nnr, sumi2Mnr, sumi2infnr,
sumj0nnr, sumj0mnr, sumj0Nnr, sumj0Mnr, sumj0infnr,
sumj1nnr, sumj1mnr, sumj1Nnr, sumj1Mnr, sumj1infnr,
sumj2nnr, sumj2mnr, sumj2Nnr, sumj2Mnr, sumj2infnr,
sumk0nnr, sumk0mnr, sumk0Nnr, sumk0Mnr, sumk0infnr,
sumk1nnr, sumk1mnr, sumk1Nnr, sumk1Mnr, sumk1infnr,
sumk2nnr, sumk2mnr, sumk2Nnr, sumk2Mnr, sumk2infnr,
) = _gen_big_expressions(
all_configs,
sumfBr,
(body => $norm(#body)$)
)
#let (
sumi0nnr2, sumi0mnr2, sumi0Nnr2, sumi0Mnr2, sumi0infnr2,
sumi1nnr2, sumi1mnr2, sumi1Nnr2, sumi1Mnr2, sumi1infnr2,
sumi2nnr2, sumi2mnr2, sumi2Nnr2, sumi2Mnr2, sumi2infnr2,
sumj0nnr2, sumj0mnr2, sumj0Nnr2, sumj0Mnr2, sumj0infnr2,
sumj1nnr2, sumj1mnr2, sumj1Nnr2, sumj1Mnr2, sumj1infnr2,
sumj2nnr2, sumj2mnr2, sumj2Nnr2, sumj2Mnr2, sumj2infnr2,
sumk0nnr2, sumk0mnr2, sumk0Nnr2, sumk0Mnr2, sumk0infnr2,
sumk1nnr2, sumk1mnr2, sumk1Nnr2, sumk1Mnr2, sumk1infnr2,
sumk2nnr2, sumk2mnr2, sumk2Nnr2, sumk2Mnr2, sumk2infnr2,
) = _gen_big_expressions(
all_configs,
sumfBr,
(body => norm2(body))
)
#let sumBrN1(body) = sumfBr(body, config: config1iN)
#let prodBrN1(body) = prodfBr(body, config: config1iN)
#let sumBrN0(body) = sumfBr(body, config: config0iN)
#let prodBrN0(body) = prodfBr(body, config: config0iN)
#let sumBrN1inf(body) = sumfBr(body, config: config1iinf)
#let prodBrN1inf(body) = prodfBr(body, config: config1iinf)
#let sumBrN0inf(body) = sumfBr(body, config: config0iinf)
#let prodBrN0inf(body) = prodfBr(body, config: config0iinf)
#let limn(body) = $lim_(n -> +infinity) autoBraceIfAddOrSub(#body)$
#let liminfn(body) = $liminf_(n -> +infinity) autoBraceIfAddOrSub(#body)$
#let limsupn(body) = $limsup_(n -> +infinity) autoBraceIfAddOrSub(#body)$
#let coker = math.op("coker")
#let coim = math.op("coim")
#let Ad1(x, G) = $"Ad"_#G (#x)$
#let Ad = math.op("Ad")
#let Aut = math.op("Aut")
#let algClosure(F) = $#F^"alg"$
#let inverseLimit = $limits(lim)_(arrow.l.long)$
#let directLimit = $limits(lim)_(arrow.long)$
#let AModule(A) = [$#A -$模]
#let closedBall(a, r) = $overline(B(#a, #r))$
#let GEquiv(G) = {
$#G -$
"等变"
}
#let Mod = math.op("Mod")
#let ModCat(R) = $#R - bold(Mod)$
#let ComplexCat(R) = $bold("Comp")(#R)$
#let SetCat = $bold("Set")$
#let FunctorCat(A, B) = $bold("Func")(#A, #B)$
#let AdjoinPair(F, G) = $(#F, #G)$
#let tensorProduct = math.times.o
#let generatedBy(body) = $chevron.l #body chevron.r$
#let norm2(x) = $norm(#x)^2$
#let normalSub(H, G) = $#H lt.tri.eq #G$
#let norS = math.class("relation", math.lt.closed.eq)
#let semiProd = math.class("relation", math.times.r)
#let diam = math.op("diam")
//#let quot = math.class("relation", $\/$)
#let Stab = math.op("Stab")
#let Orb = math.op("Orb")
#let arrowCir = $limits(arrow)^(circle)$
#let existsST(var, condition) = $exists #var space s.t. space #condition$
#let forallSa(var, condition) = $forall #var space , space #condition$
#let funcDef(f, A, B, x, fx) = $#f: space #A &-> #B \ #x &|-> #fx$
#let seqLimit(n) = $lim_(#n -> +infinity)$
#let seqLimitn = $seqLimit(n)$
#let inj_str = "inj"
#let inja = math.arrow.hook
#let surj_str = "surj"
#let surja = math.arrow.twohead
#let bij_str = "bij"
#let fourierTrans(f) = $hat(#f)$
#let def_str = "def"
#let nat_str = "nat"
#let dashed_str = "dashed"
#let sep(..xs) = xs.pos().join($space$)
// Theorem and definition environments.
#let base_env(type: "Theorem", numbered: true, fg: black, bg: white, name, body) = locate(
location => {
let lvl = counter(heading).at(location)
let top = if lvl.len() > 0 { lvl.first() } else { 0 }
let i = counter(type + str(top)).at(location).first()
// show: block.with(spacing: 11.5pt)
// stack(
// dir: ttb,
// rect(fill: fg, radius: (top-right: 5pt), stroke: fg)[
// #strong(
// text(white)[
// #type
// #if numbered {
// counter(type).step()
// [ #top.#(i+1).]
// }
// #if name != none [ (#name) ]
// ]
// )
// ],
// rect(width: 100%,
// fill: bg,
// radius: ( right: 5pt ),
// stroke: (
// left: fg,
// right: bg + 0pt,
// top: bg + 0pt,
// bottom: bg + 0pt,
// )
// )[
// #emph(body)
// ]
// )
parbreak()
strong($#type
#if numbered {
counter(type + str(top)).step()
if top > 0{
[ #top.#(i+1).]
}
else{
[ #(i+1).]
}
}
$)
$#if name != [] [
(#name)
]$
set enum(numbering: "1)")
" "
body
// if name != none {
// label(name)
// }
parbreak()
}
)
#let noneNameChecker(name) = {
if name == [] {
none
}
else {
name
}
}
#let frame-map = (
Proposition: (
border-color: blue,
title-color: blue.lighten(30%),
body-color: blue.lighten(95%),
footer-color: blue.lighten(80%)
),
Theorem: (
title-color: green.darken(40%),
body-color: green.lighten(80%),
footer-color: green.lighten(60%),
border-color: green.darken(60%),
),
Lemma: (
title-color: orange.darken(40%),
body-color: orange.lighten(80%),
footer-color: orange.lighten(60%),
border-color: orange.darken(60%),
),
Corollary: (
title-color: red.darken(40%),
body-color: red.lighten(80%),
footer-color: red.lighten(60%),
border-color: red.darken(60%),
),
Definition: (
title-color: purple.darken(40%),
body-color: purple.lighten(80%),
footer-color: purple.lighten(60%),
border-color: purple.darken(60%),
),
Example: (
border-color: red.darken(40%),
title-color: red.darken(30%),
body-color: red.lighten(90%),
radius: 0pt,
thickness: 2pt,
body-inset: 1em,
),
Remark: (
border-color: green.darken(40%),
title-color: green.darken(30%),
body-color: green.lighten(90%),
radius: 0pt,
thickness: 2pt,
body-inset: 1em,
),
Algorithm: (
border-color: blue.darken(40%),
title-color: blue.darken(30%),
body-color: blue.lighten(90%),
radius: 0pt,
thickness: 2pt,
body-inset: 1em,
),
)
#let theorem-like-style(thm-type, name, number, body) = {
showybox(
body,
breakable: true,
title: [#strong(thm-type) #number #if name != none [ (#name) ]],
frame: frame-map.at(thm-type),
footer: ""
)
}
#let proof-style(thm-type, name, number, body) = {
showybox(
breakable: true,
title: "Proof",
frame: (
border-color: red.darken(30%),
title-color: red.darken(30%),
body-color: red.lighten(90%),
radius: 0pt,
thickness: 2pt,
body-inset: 1em,
dash: "densely-dash-dotted"
),
)[
#body
#linebreak()
#h(1fr)
#box(scale(100%, origin: bottom + right, sym.square.stroked))
]
}
#let (
theorem: theo, lemma: lem, corollary: cor_,
remark: rem, proposition: prop, example:ex , definition:def,
proof: pr, rules: thm-rules
) = default-theorems("thm-group", lang: "en", thm-styling: theorem-like-style, proof-styling: proof-style)
#let (
theorem: theo1, lemma: lem1, corollary: cor1,
remark: rem1, proposition: prop1, example:ex1 , definition:def1,
proof: pr1, rules: thm-rules1
) = default-theorems("thm-group-linear", lang: "en", thm-numbering: thm-numbering-linear, thm-styling: theorem-like-style, proof-styling: proof-style)
#let my-ans-style(
thm-type, name, number, body
) = block(spacing: 11.5pt, {
set enum(numbering: "Step 1.1.")
body
linebreak()
h(1fr)
box(scale(160%, origin: bottom + right, sym.square.stroked))
})
#let my-styling = (
thm-styling: my-ans-style,
thm-numbering: thm-numbering-linear
)
#let (answer, rules:ans-rules) = new-theorems("thm-ans", ("answer": "Answer"), ..my-styling)
#let _convert(f, footer,name, body) = f(name: noneNameChecker(name))[
#body
#parbreak()
]
#let (alg, rules: alg-rules) = new-theorems("thm-group", ("alg": "Algorithm"), thm-styling: theorem-like-style)
#let (alg1, rules: alg-rules1) = new-theorems("thm-group-linear", ("alg1": "Algorithm"), thm-numbering: thm-numbering-linear, thm-styling: theorem-like-style)
#let theorem(footer: "",name, body) = _convert(theo, footer, name, body)
#let lemma(footer: "",name, body) = _convert(lem, footer,name, body)
#let corollary(footer: "",name, body) = _convert(cor_, footer, name, body)
#let proposition(footer: "",name, body) = _convert(prop, footer, name, body)
#let definition(footer: "",name, body) = _convert(def, footer, name, body)
#let example(footer: "",name, body) = _convert(ex, footer, name, body)
#let remark(footer: "",name, body) = _convert(rem, footer, name, body)
#let proof(body) = [#pr[
#set text(size: 10pt)
#body
]
#linebreak()
]
#let algorithm(footer: "",name, body) = _convert(alg, footer,name, body)
#let theoremLinear(footer: "",name, body) = _convert(theo1, footer,name, body)
#let lemmaLinear(footer: "",name, body) = _convert(lem1, footer,name, body)
#let corollaryLinear(footer: "",name, body) = _convert(cor1, footer,name, body)
#let propositionLinear(footer: "",name, body) = _convert(prop1, footer: "",name, body)
#let exampleLinear(footer: "",name, body) = _convert(ex1, footer,name, body)
#let remarkLinear(footer: "",name, body) = _convert(rem1, footer,name, body)
#let definitionLinear(footer: "",name, body) = _convert(def1, footer,name, body)
#let proofLinear(body) = [#pr1[
#set text(size: 10pt)
#body
]
#linebreak()
]
#let algorithmLinear(footer: "",name, body) = _convert(alg1, footer: "",name, body)
// show raw.where(block: false): box.with(
// fill: luma(240),
// inset: (x: 3pt, y: 0pt),
// outset: (y: 3pt),
// radius: 2pt,
// )
// show raw.where(block: true): block.with(
// width: 100%,
// fill: luma(240),
// inset: 10pt,
// radius: 4pt,
// )
#let Code(body) = {
set text(font: ("JetBrains Mono"))
box(
body,
fill: luma(240),
inset: (x: 3pt, y: 0pt),
outset: (y: 3pt),
radius: 2pt,
)
}
#let nspace(n) = $space$ * n
#let CodeBlock(body) = {
set text(font: ("JetBrains Mono"))
let indentCounter = counter("indent")
context indentCounter.update(0)
block(
body,
width: 100%,
fill: luma(240),
inset: 10pt,
radius: 4pt,
)
}
#let Lines(..lines) = lines.pos().join(linebreak())
// 请将该函数作为 CodeBlock 的一部分使用
// 行号暂时只能从头计数
#let CodeLines(indent: 0, withCountNumber: false, start: 1, ..lines) = context {
let indentCounter = counter("indent")
let prevIndent = indentCounter.get().at(0)
indentCounter.update(prevIndent + indent)
lines.pos().enumerate().map(iline => context {
let (i, line) = iline
let indent = indentCounter.get().at(0)
if withCountNumber {
line = $space$ + strfmt("{:<4}", i + start) + [ ] + line
}
nspace(indent) + line
}).join(linebreak())
indentCounter.update(prevIndent)
}
// 请将该函数作为 CodeLines 的一部分使用
#let CodeBraces(pre, ..lines) = Lines[#pre {][
#CodeLines(indent: 4, ..lines)
][
#CodeLines(indent: 0, "}")
]
#let note(title: "Note title", author: "Name", logo: none, date: none,
preface: none, code_with_line_number: true, withOutlined: true, withTitle: true, withHeadingNumbering: true,
withChapterNewPage: false,
body) = {
// Set the document's basic properties.
set document(author: (author, ), title: title)
show list: set align(top + left)
show list: set block(breakable: true)
// show block: set align(top + left)
set block(breakable: true)
show enum: set block(breakable: true)
set page(
numbering: "1",
number-align: end,
// Running header.
header-ascent: 14pt,
header: [
#context [
#let i = here().position().at("page")
#{
if i == 1 { return }
set text(size: 8pt)
if calc.odd(i) { align(end, title) } else { align(start, title) }
}
]
]
)
set text(font: "Noto Serif CJK SC", lang: "zh")
show: thm-rules
show: ans-rules
show: thm-rules1
show: alg-rules
show: alg-rules1
show emph: it => {
text(it, weight: "bold")
}
show math.equation: set text(font: ("New Computer Modern Math", "Noto Serif CJK SC",))
show math.equation: it => {
show block: set align(center)
it
}
show math.equation.where(block: true): set align(center)
set math.equation(numbering: "(1)")
set math.equation(numbering: num =>
"(" + (counter(heading).get() + (num,)).map(str).join(".") + ")") if withHeadingNumbering == true
let headingfunc = (it => it)
if withHeadingNumbering == false {
}
else {
headingfunc = (it => {
counter(math.equation).update(0)
it
})
}
show heading: headingfunc
// set ref(supplement: it => {
// let eq = math.equation
// let el = it
// if el.func() == heading {
// "章节"
// } else if el.func() == eq {
// "式"
// } else {
// ""
// }
//}
// )
// Set paragraph spacing.
set par(spacing: 1.2em)
let headingfunc1 = it => it
if withChapterNewPage == true{
headingfunc1 = it => {
pagebreak()
it
}
}
if withTitle{
// Title page.
// The page can contain a logo if you pass one with `logo: "logo.png"`.
v(0.6fr)
if logo != none {
align(right, image(logo, width: 26%))
}
v(9.6fr)
text(1.1em, date)
v(1.2em, weak: true)
text(2em, weight: 700, title)
// Author information.
pad(
top: 0.7em,
right: 20%,
align(start, author)
)
v(2.4fr)
pagebreak()
if withOutlined {
if preface != none {
[
= Preface
]
preface
pagebreak()
// Table of contents
[
= Contents
]
outline(title: none, depth: 3, indent: auto)
} else {
outline(depth: 3, indent: auto)
}
if withChapterNewPage == false{
pagebreak() // 补上目录的换页
}
}
}
show heading.where(level: 1) : headingfunc1
// Main body
set par(justify: true, first-line-indent: (
amount: 22pt,
all: false
))
set heading(numbering: "1.")
set heading(numbering: none) if withHeadingNumbering == false
// Code
show raw.where(block: false): box.with(
fill: luma(240),
inset: (x: 3pt, y: 0pt),
outset: (y: 3pt),
radius: 2pt,
)
show raw.where(block: true): block.with(
width: 100%,
fill: luma(240),
inset: 10pt,
radius: 4pt,
)
show raw: it => {
// set text(font: ("Serif Italic", "Noto Serif CJK SC"))
it
}
// Code block with line numbers
show raw.where(block: true): it => {
if not code_with_line_number { return it }
let lines = it.text.split("\n")
let length = lines.len()
let i = 0
let left_str = while i < length {
i = i + 1
str(i) + "\n"
}
grid(
columns: (auto, 1fr),
align(
right,
block(
inset: (
top: 10pt,
bottom: 10pt,
left: 0pt,
right: 5pt
),
left_str
)
),
align(left, it),
)
}
body
}
#let prop = sym.prop
// sum(x^2)