arislople

Lean 4 AI slop

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
  101. 101
  102. 102
  103. 103
  104. 104
  105. 105
  106. 106
  107. 107
  108. 108
  109. 109
  110. 110
  111. 111
  112. 112
  113. 113
  114. 114
  115. 115
  116. 116
  117. 117
  118. 118
  119. 119
  120. 120
  121. 121
  122. 122
  123. 123
  124. 124
  125. 125
  126. 126
  127. 127
  128. 128
  129. 129
  130. 130
  131. 131
  132. 132
  133. 133
  134. 134
  135. 135
  136. 136
  137. 137
  138. 138
  139. 139
  140. 140
  141. 141
  142. 142
  143. 143
  144. 144
  145. 145
  146. 146
  147. 147
  148. 148
  149. 149
  150. 150
  151. 151
  152. 152
  153. 153
  154. 154
  155. 155
  156. 156
  157. 157
  158. 158
  159. 159
  160. 160
  161. 161
  162. 162
  163. 163
  164. 164
  165. 165
  166. 166
  167. 167
  168. 168
  169. 169
  170. 170
  171. 171
  172. 172
  173. 173
  174. 174
  175. 175
  176. 176
  177. 177
  178. 178
  179. 179
  180. 180
  181. 181
  182. 182
  183. 183
  184. 184
  185. 185
  186. 186
  187. 187
  188. 188
  189. 189
  190. 190
  191. 191
  192. 192
  193. 193
  194. 194
  195. 195
  196. 196
  197. 197
  198. 198
  199. 199
  200. 200
  201. 201
  202. 202
  203. 203
  204. 204
  205. 205
  206. 206
  207. 207
  208. 208
  209. 209
  210. 210
  211. 211
  212. 212
  213. 213
  214. 214
  215. 215
  216. 216
  217. 217
  218. 218
  219. 219
  220. 220
  221. 221
  222. 222
  223. 223
  224. 224
  225. 225
  226. 226
  227. 227
  228. 228
  229. 229
  230. 230
  231. 231
  232. 232
  233. 233
  234. 234
  235. 235
  236. 236
  237. 237
  238. 238
  239. 239
  240. 240
  241. 241
  242. 242
  243. 243
  244. 244
  245. 245
  246. 246
  247. 247
  248. 248
  249. 249
  250. 250
  251. 251
  252. 252
  253. 253
  254. 254
  255. 255
  256. 256
  257. 257
  258. 258
  259. 259
  260. 260
  261. 261
  262. 262
  263. 263
  264. 264
  265. 265
  266. 266
  267. 267
  268. 268
  269. 269
  270. 270
  271. 271
  272. 272
  273. 273
  274. 274
  275. 275
  276. 276
  277. 277
  278. 278
  279. 279
  280. 280
  281. 281
  282. 282
  283. 283
  284. 284
  285. 285
  286. 286
  287. 287
  288. 288
  289. 289
  290. 290
  291. 291
  292. 292
  293. 293
  294. 294
  295. 295
  296. 296
  297. 297
  298. 298
  299. 299
  300. 300
  301. 301
  302. 302
  303. 303
  304. 304
  305. 305
  306. 306
  307. 307
  308. 308
  309. 309
  310. 310
  311. 311
  312. 312
  313. 313
  314. 314
  315. 315
  316. 316
  317. 317
  318. 318
  319. 319
  320. 320
  321. 321
  322. 322
  323. 323
  324. 324
  325. 325
  326. 326
  327. 327
  328. 328
  329. 329
  330. 330
  331. 331
  332. 332
  333. 333
  334. 334
  335. 335
  336. 336
  337. 337
  338. 338
  339. 339
  340. 340
  341. 341
  342. 342
  343. 343
  344. 344
  345. 345
  346. 346
  347. 347
  348. 348
  349. 349
  350. 350
  351. 351
  352. 352
  353. 353
  354. 354
  355. 355
  356. 356
  357. 357
  358. 358
  359. 359
  360. 360
  361. 361
  362. 362
  363. 363
  364. 364
  365. 365
  366. 366
  367. 367
  368. 368
  369. 369
  370. 370
  371. 371
  372. 372
  373. 373
  374. 374
  375. 375
  376. 376
  377. 377
  378. 378
  379. 379
  380. 380
  381. 381
  382. 382
  383. 383
  384. 384
  385. 385
  386. 386
  387. 387
  388. 388
  389. 389
  390. 390
  391. 391
  392. 392
  393. 393
  394. 394
  395. 395
  396. 396
  397. 397
  398. 398
  399. 399
  400. 400
  401. 401
  402. 402
  403. 403
  404. 404
  405. 405
  406. 406
  407. 407
  408. 408
  409. 409
  410. 410
  411. 411
  412. 412
  413. 413
  414. 414
  415. 415
  416. 416
  417. 417
  418. 418
  419. 419
  420. 420
  421. 421
  422. 422
  423. 423
  424. 424
  425. 425
  426. 426
  427. 427
  428. 428
  429. 429
  430. 430
  431. 431
  432. 432
  433. 433
  434. 434
  435. 435
  436. 436
  437. 437
  438. 438
  439. 439
  440. 440
  441. 441
  442. 442
  443. 443
  444. 444
  445. 445
  446. 446
  447. 447
  448. 448
  449. 449
  450. 450
  451. 451
  452. 452
  453. 453
  454. 454
  455. 455
  456. 456
  457. 457
  458. 458
  459. 459
  460. 460
  461. 461
  462. 462
  463. 463
  464. 464
  465. 465
  466. 466
  467. 467
  468. 468
  469. 469
  470. 470
  471. 471
  472. 472
  473. 473
  474. 474
  475. 475
  476. 476
  477. 477
  478. 478
  479. 479
  480. 480
  481. 481
  482. 482
  483. 483
  484. 484
  485. 485
  486. 486
  487. 487
  488. 488
  489. 489
  490. 490
  491. 491
  492. 492
  493. 493
  494. 494
  495. 495
  496. 496
  497. 497
  498. 498
  499. 499
  500. 500
  501. 501
  502. 502
  503. 503
  504. 504
  505. 505
  506. 506
  507. 507
  508. 508
  509. 509
  510. 510
  511. 511
  512. 512
  513. 513
  514. 514
  515. 515
  516. 516
  517. 517
  518. 518
  519. 519
  520. 520
  521. 521
  522. 522
  523. 523
  524. 524
  525. 525
  526. 526
  527. 527
  528. 528
  529. 529
  530. 530
  531. 531
  532. 532
  533. 533
  534. 534
  535. 535
  536. 536
  537. 537
  538. 538
  539. 539
  540. 540
  541. 541
  542. 542
  543. 543
  544. 544
  545. 545
  546. 546
  547. 547
  548. 548
  549. 549
  550. 550
  551. 551
  552. 552
  553. 553
  554. 554
  555. 555
  556. 556
  557. 557
  558. 558
  559. 559
  560. 560
  561. 561
  562. 562
  563. 563
  564. 564
  565. 565
  566. 566
  567. 567
  568. 568
  569. 569
  570. 570
  571. 571
  572. 572
  573. 573
  574. 574
/-
Sorry, Aristotle was unable to complete the task in time.
-/
/-
This file was generated by Aristotle.

Lean version: leanprover/lean4:v4.24.0
Mathlib version: f897ebcf72cd16f89ab4577d0c826cd14afaafc7
-/

import Mathlib

open scoped BigOperators
open scoped Real
open scoped Nat
open scoped Classical
open scoped Pointwise

set_option maxHeartbeats 0
set_option maxRecDepth 4000
set_option synthInstance.maxHeartbeats 20000
set_option synthInstance.maxSize 128

set_option relaxedAutoImplicit false
set_option autoImplicit false

noncomputable section

/-
The Weyl group of type A_n is the Coxeter group associated with the Coxeter matrix A_n.
-/
open CoxeterMatrix

def WeylGroupA (n : ) := CoxeterMatrix.Group (Aₙ n)


/-
Checking definitions and instances.
-/
open CoxeterMatrix

#check CoxeterMatrix.Group
#check PresentedGroup.toGroup
#synth Group (CoxeterMatrix.Group (Aₙ 3))

/-
There is a homomorphism from the Weyl group of type A_n to the symmetric group S_{n+1}.
-/
open CoxeterMatrix

def perm_of_gen (n : ) (i : Fin n) : Equiv.Perm (Fin (n + 1)) :=
  Equiv.swap (Fin.castSucc i) (Fin.succ i)

def toPerm (n : ) : CoxeterMatrix.Group (Aₙ n) * Equiv.Perm (Fin (n + 1)) :=
  PresentedGroup.toGroup (f := perm_of_gen n) (by
  unfold CoxeterMatrix.Aₙ;
  simp ( config := { decide := Bool.true } ) [ CoxeterMatrix.relationsSet ];
  unfold CoxeterMatrix.relation; aesop;
  · ext i ; unfold perm_of_gen ; aesop;
  · ext i;
    unfold perm_of_gen;
    rcases x with  _ | x, hx  <;> rcases x_1 with  _ | x_1, hx_1  <;> norm_num [ Fin.ext_iff, pow_succ', Equiv.swap_apply_def ] at *;
    · aesop;
      rcases i with  _ | _ | _ | i, hi  <;> norm_num [ pow_three, Equiv.swap_apply_def ];
      simp +arith +decide [ Fin.ext_iff ];
    · grind;
  · ext y ; simp ( config := { decide := Bool.true } ) [ *, perm_of_gen ];
    rcases x with  _ | x, hx  <;> rcases x_1 with  _ | x_1, hx_1  <;> norm_num [ Fin.ext_iff, Equiv.swap_apply_def ] at *;
    · aesop;
      rcases y with  _ | _ | _ | y, hy  <;> norm_num [ pow_succ, Equiv.swap_apply_def ];
      simp ( config := { decide := Bool.true } ) [ Fin.ext_iff, Nat.succ_eq_add_one ] at *;
    · -- By definition of permutation multiplication, we can see that applying the permutation three times returns each element to its original position.
      simp [Equiv.swap_apply_def, pow_succ'];
      grind;
  · -- Since $x \neq x_1$, the permutations $perm_of_gen n x$ and $perm_of_gen n x_1$ commute.
    have h_comm : perm_of_gen n x * perm_of_gen n x_1 = perm_of_gen n x_1 * perm_of_gen n x := by
      ext y; simp [perm_of_gen];
      by_cases hy : y = x.castSucc <;> by_cases hy' : y = x.succ <;> by_cases hy'' : y = x_1.castSucc <;> by_cases hy''' : y = x_1.succ <;> simp_all +decide [ Equiv.swap_apply_def ];
      all_goals simp_all ( config := { decide := Bool.true } ) [ Fin.ext_iff, Fin.val_add ];
      · aesop;
      · aesop;
    simp_all +decide [ pow_succ, mul_assoc ];
    simp_all +decide [  mul_assoc ];
    simp_all +decide [ mul_assoc, perm_of_gen ])

/-
The homomorphism `toPerm` from the Weyl group of type A_n to the symmetric group S_{n+1} is surjective.
-/
theorem toPerm_surjective (n : ) : Function.Surjective (toPerm n) := by
  -- To prove surjectivity, it suffices to show that the image of `toPerm` contains all the adjacent transpositions, which generate the symmetric group.
  have h_adj_transpositions :  i : Fin n,  g : CoxeterMatrix.Group (Aₙ n), toPerm n g = Equiv.swap (Fin.castSucc i) (Fin.succ i) := by
    intro i;
    exact  PresentedGroup.of i, by aesop ;
  -- Since the symmetric group is generated by the adjacent transpositions, and we have shown that the image of `toPerm` contains all these transpositions, the image must be the entire symmetric group.
  have h_image :  p : Equiv.Perm (Fin (n + 1)),  g : CoxeterMatrix.Group (Aₙ n), toPerm n g = p := by
    intro p
    have h_gen : p  Subgroup.closure (Set.range (fun i : Fin n => Equiv.swap (Fin.castSucc i) (Fin.succ i))) := by
      -- The symmetric group $S_{n+1}$ is generated by the adjacent transpositions $(i, i+1)$ for $i \in \{0, 1, \ldots, n-1\}$.
      have h_gen :  p : Equiv.Perm (Fin (n + 1)), p  Subgroup.closure (Set.range (fun i : Fin n => Equiv.swap (Fin.castSucc i) (Fin.succ i))) := by
        intro p
        have h_adj_transpositions :  i : Fin (n + 1),  j : Fin (n + 1), i < j  Equiv.swap i j  Subgroup.closure (Set.range (fun i : Fin n => Equiv.swap (Fin.castSucc i) (Fin.succ i))) := by
          intro i j hij; induction' j using Fin.inductionOn with j ih ih; aesop;
          cases lt_or_eq_of_le ( show i  Fin.castSucc j from Nat.le_of_lt_succ hij ) <;> simp_all +decide [ Subgroup.mem_closure ];
          · intro K hK; specialize ih K hK; specialize hK ( Set.mem_range_self j ) ; aesop;
            exact?;
          · exact fun K hK => hK  j, rfl 
        induction' p using Equiv.Perm.swap_induction_on' with p i j hij ih;
        · exact OneMemClass.one_mem _;
        · exact Subgroup.mul_mem _ ih ( if hij' : i < j then h_adj_transpositions i j hij' else by simpa only [ Equiv.swap_comm ] using h_adj_transpositions j i ( lt_of_le_of_ne ( le_of_not_gt hij' ) hij.symm ) );
      exact h_gen p
    refine' Subgroup.closure_induction ( fun x hx => _ ) _ _ _ h_gen;
    · aesop;
    · exact  1, map_one _ ;
    · rintro x y hx hy  g, rfl   h, rfl  ; exact  g * h, by simp +decide  ;
    · rintro x hx  g, rfl  ; exact  g⁻¹, by simp +decide  ;
  exact h_image

/-
We define the index set for the roots of type A_n as the set of pairs of distinct indices from 0 to n. We prove it is a finite type.
-/
variable (n : )

def TypeA.ι := { x : Fin (n + 1) × Fin (n + 1) // x.1  x.2 }

instance : Fintype (TypeA.ι n) :=
  have : DecidablePred (fun x : Fin (n + 1) × Fin (n + 1) => x.1  x.2) := fun _ => inferInstance
  inferInstanceAs (Fintype { x : Fin (n + 1) × Fin (n + 1) // x.1  x.2 })

instance : DecidableEq (TypeA.ι n) := inferInstance

/-
We define the index set for the roots of type A_n as the set of pairs of distinct indices from 0 to n. We prove it is a finite type.
-/
variable (n : )

abbrev TypeA_Indices := { x : Fin (n + 1) × Fin (n + 1) // x.1  x.2 }

instance : Fintype (TypeA_Indices n) := inferInstance
instance : DecidableEq (TypeA_Indices n) := inferInstance

/-
We define the roots and coroots for the root system of type A. For each index pair (i, j), the root and coroot are both the vector e_i - e_j in Z^{n+1}.
-/
variable (n : )

def TypeA.root (i : TypeA_Indices n) : Fin (n + 1)   :=
  Pi.single i.1.1 1 - Pi.single i.1.2 1

def TypeA.coroot (i : TypeA_Indices n) : Fin (n + 1)   :=
  Pi.single i.1.1 1 - Pi.single i.1.2 1

/-
Checking the type of Matrix.toBilin.
-/
#check Matrix.toBilin

/-
We define the perfect pairing for the root system of type A as the standard dot product. We also define the reflection permutation associated with a root index (i, j) as the permutation of indices induced by the transposition (i, j).
-/
variable (n : )

def TypeA.pairing : PerfectPairing  (Fin (n + 1)  ) (Fin (n + 1)  ) :=
  { toLinearMap := LinearMap.mk₂  dotProduct (by
      -- The dot product is linear in the first argument, so we can split the sum into two parts.
      intros m₁ m₂ n
      simp [dotProduct, add_mul, Finset.sum_add_distrib]) (by
      -- The dot product is linear in both arguments, so we can distribute the scalar multiplication over the dot product.
      intros c m n
      simp [dotProduct, mul_assoc, mul_comm, mul_left_comm];
      -- Apply the distributive property of multiplication over addition.
      rw [Finset.mul_sum]) (by
      -- By the distributive property of multiplication over addition, we can split the sum into two separate sums.
      intros m n₁ n₂
      simp [mul_add, Finset.sum_add_distrib]) (by
      -- The dot product is linear, so we can distribute the scalar multiplication over the dot product.
      intros c m n_1
      simp [dotProduct, smul_eq_mul];
      -- By the properties of multiplication, we can factor out the scalar $c$ from the sum.
      simp [mul_assoc, mul_comm, mul_left_comm, Finset.mul_sum])
    bijective_left := by
      constructor;
      · intro m m' h; ext i; replace h := congr_arg ( fun f => f ( Pi.single i 1 ) ) h; aesop;
      · -- To show surjectivity, take any linear functional $f$ on $\mathbb{Z}^{n+1}$. We can represent $f$ as the dot product with some vector $v$.
        intro f
        use fun i => f (Pi.single i 1);
        bound
    bijective_right := by
      constructor <;> intro f <;> aesop
      generalize_proofs at *;
      ext i; have := congr_arg ( fun f => f ( Pi.single i 1 ) ) a; norm_num at this; aesop; }

def TypeA.reflectionPerm (i : TypeA_Indices n) : Equiv.Perm (TypeA_Indices n) :=
  let σ := Equiv.swap i.1.1 i.1.2
  { toFun := fun x => (σ x.1.1, σ x.1.2), by
      intro h
      apply x.2
      apply σ.injective
      exact h
    invFun := fun x => (σ x.1.1, σ x.1.2), by
      intro h
      apply x.2
      apply σ.injective
      exact h
    left_inv := by intro x; simp; apply Subtype.ext; simp; rw [Equiv.swap_apply_self, Equiv.swap_apply_self]
    right_inv := by intro x; simp; apply Subtype.ext; simp; rw [Equiv.swap_apply_self, Equiv.swap_apply_self] }

/-
Checking the definition of RootPairing.
-/
#print RootPairing

/-
Checking if TypeA.pairing and TypeA.reflectionPerm are already defined.
-/
variable (n : )

#check TypeA.pairing
#check TypeA.reflectionPerm

/-
We define the embedding of the roots of type A into the ambient space. The injectivity proof is left as a sorry.
-/
variable (n : )

def TypeA.rootEmbedding : TypeA_Indices n  (Fin (n + 1)  ) :=
  Function.Embedding.mk (TypeA.root n) (by
  intro x y hxy;
  unfold TypeA.root at hxy;
  replace hxy := congr_fun hxy;
  have := hxy x.1.1; have := hxy x.1.2; have := hxy y.1.1; have := hxy y.1.2; simp_all +decide [ Fin.ext_iff, Pi.single_apply ] ;
  grind +ring)

/-
We define the embedding of the coroots of type A into the ambient space. The injectivity proof is identical to that of the roots.
-/
variable (n : )

def TypeA.corootEmbedding : TypeA_Indices n  (Fin (n + 1)  ) :=
  Function.Embedding.mk (TypeA.coroot n) (by
  intro x y hxy;
  unfold TypeA.coroot at hxy;
  replace hxy := congr_fun hxy;
  have := hxy x.1.1; have := hxy x.1.2; have := hxy y.1.1; have := hxy y.1.2; simp_all +decide [ Fin.ext_iff, Pi.single_apply ] ;
  grind +ring)

/-
The map `TypeA.root` is injective.
-/
variable (n : )

lemma TypeA.root_injective : Function.Injective (TypeA.root n) := by
  intro i j h
  unfold TypeA.root at h
  -- We have e_i - e_j = e_k - e_l
  -- This implies {i, l} = {k, j} as multisets if we look at the support,
  -- but since i != j and k != l, we can deduce i = k and j = l.
  -- We can use function extensionality to look at specific coordinates.
  have h_i := congr_fun h i.1.1
  have h_j := congr_fun h i.1.2
  simp [Pi.single_apply] at h_i h_j
  -- We need to handle cases where indices might coincide.
  -- Since i.1.1 != i.1.2, we know the value at i.1.1 is 1 and at i.1.2 is -1.
  -- The RHS must match this.
  grind

/-
We define the root pairing for type A_n. We register the perfect pairing instance and then construct the `RootPairing` structure using the embeddings and permutations defined earlier. We leave the verification of the axioms as sorries.
-/
variable (n : )

instance : LinearMap.IsPerfPair (TypeA.pairing n).toLinearMap :=
  { bijective_left := (TypeA.pairing n).bijective_left
    bijective_right := (TypeA.pairing n).bijective_right }

def RootPairingA : RootPairing (TypeA_Indices n)  (Fin (n + 1)  ) (Fin (n + 1)  ) where
  toLinearMap := (TypeA.pairing n).toLinearMap
  root := TypeA.rootEmbedding n
  coroot := TypeA.corootEmbedding n
  root_coroot_two := by
    unfold TypeA.rootEmbedding TypeA.corootEmbedding;
    unfold TypeA.pairing;
    unfold TypeA.root TypeA.coroot; aesop
  reflectionPerm := TypeA.reflectionPerm n
  reflectionPerm_root := by
    unfold TypeA.rootEmbedding TypeA.corootEmbedding TypeA.reflectionPerm;
    -- By definition of reflection permutation, we have that the reflection of j under i is equal to the permutation of j under the swap of i's components.
    simp [TypeA.root, TypeA.coroot, Equiv.swap_apply_def];
    intro a b hab a' b' hab'; ext i; aesop;
    unfold TypeA.pairing; simp +decide [ Pi.single_apply ] ;
    grind +ring
  reflectionPerm_coroot := by
    bound;
    unfold TypeA.corootEmbedding TypeA.rootEmbedding TypeA.pairing TypeA.reflectionPerm;
    -- By definition of reflection permutation, we have σ(j.1) = snd and σ(j.2) = fst if j.1 = fst and j.2 = snd, and vice versa.
    simp [Equiv.swap_apply_def];
    unfold TypeA.root TypeA.coroot; aesop;
    · ext; simp ( config := { decide := Bool.true } ) [ two_mul, sub_eq_add_neg ] ; ring;
    · ext; norm_num; ring

/-
We define the root pairing for type A_n. We register the perfect pairing instance and then construct the `RootPairing` structure using the embeddings and permutations defined earlier. We leave the verification of the axioms as sorries.
-/
variable (n : )

def RootPairingTypeA : RootPairing (TypeA_Indices n)  (Fin (n + 1)  ) (Fin (n + 1)  ) where
  toLinearMap := (TypeA.pairing n).toLinearMap
  root := TypeA.rootEmbedding n
  coroot := TypeA.corootEmbedding n
  root_coroot_two := by
    intro i
    unfold TypeA.rootEmbedding TypeA.corootEmbedding TypeA.pairing TypeA.root TypeA.coroot
    simp only [Function.Embedding.coeFn_mk]
    -- We need to evaluate the pairing of (e_i - e_j) with itself.
    -- The pairing is the dot product.
    -- (e_i - e_j) . (e_i - e_j) = e_i.e_i - e_i.e_j - e_j.e_i + e_j.e_j
    -- Since i != j, e_i.e_j = 0.
    -- e_i.e_i = 1, e_j.e_j = 1.
    -- So 1 - 0 - 0 + 1 = 2.
    aesop
  reflectionPerm := TypeA.reflectionPerm n
  reflectionPerm_root := by
    -- By definition of reflection, we know that $s_i(j) = j - \langle j, i^\vee \rangle i$.
    intros i j
    simp [TypeA.reflectionPerm, TypeA.rootEmbedding, TypeA.corootEmbedding];
    unfold TypeA.pairing TypeA.root TypeA.coroot; aesop;
    simp ( config := { decide := Bool.true } ) [ Pi.single_apply, Equiv.swap_apply_def ];
    grind +ring
  reflectionPerm_coroot := by
    -- By definition of reflection permutation, we have that the reflection of j by i is the swap of the indices.
    simp [TypeA.reflectionPerm];
    intro a b hab a' b' hab'; ext x; simp +decide [ Equiv.swap_apply_def ] ;
    unfold TypeA.corootEmbedding TypeA.rootEmbedding; simp +decide [ TypeA.pairing ] ;
    simp +decide [ TypeA.coroot, TypeA.root, dotProduct ];
    simp +decide [ Finset.sum_add_distrib, sub_mul, mul_sub, Pi.single_apply ];
    grind +ring

/-
The reflection corresponding to the root indexed by `i` acts on the basis vector `e_k` by swapping indices according to the transposition `(i.1, i.2)`.
-/
variable (n : )

def WeylGroupTypeA := (RootPairingTypeA n).weylGroup

lemma reflection_apply_basis (i : TypeA_Indices n) (k : Fin (n + 1)) :
  (RootPairingTypeA n).reflection i (Pi.single k 1) = Pi.single (Equiv.swap i.1.1 i.1.2 k) 1 := by
    unfold RootPairingTypeA;
    -- By definition of reflection, we have that the reflection of the root i on the basis vector e_k is equal to the basis vector e_{σ(k)}, where σ is the transposition (i.1, i.2).
    simp [RootPairing.reflection, TypeA.reflectionPerm];
    simp +decide [ Module.reflection ];
    unfold Module.preReflection TypeA.pairing TypeA.corootEmbedding TypeA.rootEmbedding; aesop;
    unfold TypeA.coroot TypeA.root; aesop;
    by_cases hk : k = fst <;> by_cases hk' : k = snd <;> simp +decide [ *, Pi.single_apply ];
    rw [ Equiv.swap_apply_of_ne_of_ne hk hk' ]

/-
Checking the definition of RootPairing.Equiv.
-/
#print RootPairing.Equiv

/-
For every element `w` in the Weyl group of type A, there exists a permutation `σ` of the indices such that `w` acts on the basis vectors by permuting them according to `σ`.
-/
variable (n : )

lemma basis_perm_exists (w : WeylGroupTypeA n) :
   σ : Equiv.Perm (Fin (n + 1)),  k, (w.val.weightMap : (Fin (n + 1)  ) [] (Fin (n + 1)  )) (Pi.single k 1) = Pi.single (σ k) 1 := by
    -- By definition of the Weyl group, each element w corresponds to a permutation of the indices.
    have h_perm :  w : WeylGroupTypeA n,  σ : Equiv.Perm (Fin (n + 1)),  k : Fin (n + 1), (w.val.weightMap (Pi.single k 1)) = Pi.single (σ k) 1 := by
      intro w
      have h_gen :  i : TypeA_Indices n,  σ : Equiv.Perm (Fin (n + 1)),  k : Fin (n + 1), (RootPairingTypeA n).reflection i (Pi.single k 1) = Pi.single (σ k) 1 := by
        -- By definition of reflectionPerm, we know that it swaps the indices i.1.1 and i.1.2.
        intro i
        use Equiv.swap i.1.1 i.1.2;
        -- By definition of reflection, we know that it swaps the indices i.1.1 and i.1.2. Therefore, for any k, the reflection of e_k is equal to the single vector at the swapped position.
        intros k
        apply reflection_apply_basis
      induction' w with w hw;
      induction hw using Subgroup.closure_induction;
      · aesop;
      · exact  Equiv.refl _, fun k => rfl ;
      · rename_i hx hy;
        obtain  σ,   := hx; obtain  τ,   := hy; use σ * τ; intro k; simp +decide [ ,  ] ;
      · rename_i hx;
        obtain  σ,   := hx;
        use σ⁻¹;
        -- By definition of the inverse automorphism, we have that $x⁻¹.weightMap (Pi.single (σ k) 1) = Pi.single k 1$.
        have h_inv :  k : Fin (n + 1), ((RootPairingTypeA n).Aut⁻¹).weightMap (Pi.single (σ k) 1) = Pi.single k 1 := by
          intro k;
          rw [   k ];
          convert LinearEquiv.symm_apply_apply _ _;
        intro k; specialize h_inv ( σ⁻¹ k ) ; aesop;
    exact h_perm w

/-
For every element `w` in the Weyl group of type A, there exists a permutation `σ` of the indices such that `w` acts on the basis vectors by permuting them according to `σ`.
-/
variable (n : )

lemma weyl_group_acts_as_perm (w : WeylGroupTypeA n) :
   σ : Equiv.Perm (Fin (n + 1)),  k, w.val.weightMap (Pi.single k 1) = Pi.single (σ k) 1 := by
    exact?

/-
Checking the type of Pi.single_injective.
-/
#check Pi.single_injective

/-
We define the map from the Weyl group to the symmetric group by extracting the permutation that acts on the basis vectors.
-/
variable (n : )

def weylToPerm (w : WeylGroupTypeA n) : Equiv.Perm (Fin (n + 1)) :=
  Classical.choose (basis_perm_exists n w)

lemma weylToPerm_apply (w : WeylGroupTypeA n) (k : Fin (n + 1)) :
  (w.val.weightMap : (Fin (n + 1)  ) [] (Fin (n + 1)  )) (Pi.single k 1) = Pi.single (weylToPerm n w k) 1 :=
  Classical.choose_spec (basis_perm_exists n w) k

/-
We define the group homomorphism from the Weyl group to the symmetric group.
-/
variable (n : )

def weylToPermHom : WeylGroupTypeA n * Equiv.Perm (Fin (n + 1)) where
  toFun := weylToPerm n
  map_one' := by
    have h_id : (1 : WeylGroupTypeA n).val.weightMap (Pi.single 0 1) = Pi.single (weylToPerm n 1 0) 1 := by
      exact?;
    ext i; replace h_id := congr_fun h_id i; aesop;
    have := Classical.choose_spec ( basis_perm_exists n ( w := 1 ) ) i; aesop;
    replace this := congr_fun this ( ( Classical.choose ( basis_perm_exists n ( w := 1 ) ) ) i ) ; aesop;
    rw [ Pi.single_apply ] at this ; aesop;
    exact congr_arg Fin.val this
  map_mul' := by
    -- By definition of weylToPerm, we have that for any x and y in the Weyl group, weylToPerm n (x * y) is the permutation that acts on the basis vectors by first applying y and then x.
    intros x y
    apply Equiv.Perm.ext
    intro k
    simp [weylToPerm_apply];
    have h_comp :  (x y : WeylGroupTypeA n), (x * y).val.weightMap (Pi.single k 1) = (x.val.weightMap) ((y.val.weightMap) (Pi.single k 1)) := by
      exact?;
    have h_comp : (weylToPerm n (x * y)) k = (weylToPerm n x) ((weylToPerm n y) k) := by
      have := h_comp x y
      rw [ weylToPerm_apply, weylToPerm_apply, weylToPerm_apply ] at * ; aesop;
      replace this := congr_fun this ( ( weylToPerm n  val, property  ) ( ( weylToPerm n  val_1, property_1  ) k ) ) ; aesop;
      rw [ Pi.single_apply ] at this ; aesop;
    exact h_comp

/-
The homomorphism from the Weyl group of type A to the symmetric group is bijective.
-/
variable (n : )

theorem weylToPermHom_bijective : Function.Bijective (weylToPermHom n) := by
  -- To show surjectivity, notice that every permutation can be written as a product of simple reflections, which are in the image of the homomorphism.
  have h_surjective : Function.Surjective (weylToPermHom n) := by
    intro σ;
    -- Let's choose any permutation σ of the indices.
    obtain w, hw :  w : WeylGroupTypeA n,  k : Fin (n + 1), (w.val.weightMap : (Fin (n + 1)  ) [] (Fin (n + 1)  )) (Pi.single k 1) = Pi.single (σ k) 1 := by
      -- Since the Weyl group is generated by the simple reflections, any permutation σ can be written as a product of these transpositions.
      have h_gen :  σ : Equiv.Perm (Fin (n + 1)),  w : WeylGroupTypeA n,  k : Fin (n + 1), (w.val.weightMap : (Fin (n + 1)  ) [] (Fin (n + 1)  )) (Pi.single k 1) = Pi.single (σ k) 1 := by
        intro σ;
        induction' σ using Equiv.Perm.swap_induction_on with σ a b hab ;
        · refine'   1, _ , _  <;> aesop;
        · obtain  w, hw  := ;
          -- Let $w'$ be the reflection corresponding to the transposition $(a, b)$.
          obtain w', hw' :  w' : WeylGroupTypeA n,  k : Fin (n + 1), (w'.val.weightMap : (Fin (n + 1)  ) [] (Fin (n + 1)  )) (Pi.single k 1) = Pi.single (Equiv.swap a b k) 1 := by
            have h_reflection :  i : TypeA_Indices n,  w' : WeylGroupTypeA n,  k : Fin (n + 1), (w'.val.weightMap : (Fin (n + 1)  ) [] (Fin (n + 1)  )) (Pi.single k 1) = Pi.single (Equiv.swap i.1.1 i.1.2 k) 1 := by
              bound;
              exact   _, Subgroup.subset_closure <| Set.mem_range_self   fst, snd , property_1  , reflection_apply_basis _ _ ;
            exact h_reflection  ( a, b ), hab ;
          use w' * w;
          aesop;
      exact h_gen σ;
    use w;
    -- Since the permutation is determined by its action on the basis vectors, and we have shown that w and σ act the same on all basis vectors, they must be the same permutation.
    have h_perm_eq :  k : Fin (n + 1), (weylToPerm n w) k = σ k := by
      intro k; specialize hw k; replace hw := congr_fun hw ( σ k ) ; aesop;
      have := weylToPerm_apply n  val, property  k; aesop;
      rw [ Pi.single_apply ] at hw ; aesop;
    exact Equiv.Perm.ext h_perm_eq;
  -- To show injectivity, we need to show that the kernel of the homomorphism is trivial.
  have h_kernel_trivial :  w : WeylGroupTypeA n, weylToPermHom n w = 1  w = 1 := by
    bound;
    -- If the permutation induced by the Weyl group element is the identity, then the Weyl group element itself must be the identity.
    have h_id :  k : Fin (n + 1), val.weightMap (Pi.single k 1) = Pi.single k 1 := by
      intro k; have := Classical.choose_spec ( basis_perm_exists n  val, property  ) k; aesop;
      replace a := congr_arg ( fun f => f k ) a ; aesop;
      congr;
    -- Since the weight map of the Weyl group element is the identity, the Weyl group element itself must be the identity.
    have h_val_id : val.weightMap = LinearMap.id := by
      aesop;
    cases val ; aesop;
    cases toHom ; aesop;
    congr;
    · ext x;
      replace weight_coweight_transpose := congr_arg ( fun f => f ( Pi.single x 1 ) ) weight_coweight_transpose ; aesop;
      replace weight_coweight_transpose := congr_arg ( fun f => f ( Pi.single x_1 1 ) ) weight_coweight_transpose ; aesop;
      simp_all +decide [ RootPairingTypeA ];
      simp_all +decide [ TypeA.pairing ];
      simp_all +decide [ Pi.single_apply ];
      grind;
    · -- Since the root function is injective, we can conclude that indexEquiv is the identity permutation.
      have h_inj : Function.Injective (RootPairingTypeA n).root := by
        exact?;
      exact Equiv.ext fun x => h_inj <| by simpa using congr_fun root_weightMap.symm x;
  refine'  _, h_surjective ;
  exact?

/-
The homomorphism from the Weyl group of type A to the symmetric group is surjective.
-/
variable (n : )

theorem weylToPermHom_surjective : Function.Surjective (weylToPermHom n) := by
  -- Since the homomorphism is bijective, it is surjective.
  apply Function.Bijective.surjective; exact weylToPermHom_bijective n

/-
If an element of the Weyl group acts as the identity on the basis vectors, then it is the identity element. This proves the action is faithful.
-/
variable (n : )

lemma weyl_group_faithful (w : WeylGroupTypeA n) (h :  k, w.val.weightMap (Pi.single k 1) = Pi.single k 1) : w = 1 := by
  -- Since the homomorphism is bijective, if it's the identity, the element must be the identity.
  have h_bijective : Function.Bijective (weylToPermHom n) := by
    exact?;
  have h_eq_1 : weylToPermHom n w = 1 := by
    ext k;
    have := weylToPerm_apply n w k; aesop;
    replace this := congr_fun this ( weylToPerm n  val, property  k ) ; aesop;
    rw [ Pi.single_apply ] at this ; aesop;
    exact congr_arg Fin.val this;
  exact h_bijective.injective <| by simpa using h_eq_1;

/-
The cardinality of the Weyl group for the root system A_n is (n+1)!. We prove this by establishing a bijection with the symmetric group S_{n+1}.
-/
variable (n : )

theorem card_WeylGroupTypeA : Nat.card (WeylGroupTypeA n) = (n + 1).factorial := by
  have h_bij : Function.Bijective (weylToPermHom n) := weylToPermHom_bijective n
  have h_equiv : WeylGroupTypeA n  Equiv.Perm (Fin (n + 1)) := Equiv.ofBijective (weylToPermHom n) h_bij
  rw [Nat.card_congr h_equiv]
  rw [Nat.card_perm]
  simp

/-
The homomorphism from the Weyl group of type A to the symmetric group is injective.
-/
variable (n : )

theorem weylToPermHom_injective : Function.Injective (weylToPermHom n) := by
  -- Since the homomorphism is bijective, it is injective.
  apply (weylToPermHom_bijective n).injective

/-
If an element of the Weyl group acts as the identity on the basis vectors, then it is the identity element. This proves the action is faithful.
-/
variable (n : )

lemma weyl_group_faithful' (w : WeylGroupTypeA n) (h :  k, w.val.weightMap (Pi.single k 1) = Pi.single k 1) : w = 1 := by
  exact?

/-
The Weyl group of type A_n is finite, and its cardinality is (n+1)!.
-/
variable (n : )

instance instFiniteWeylGroupTypeA : Finite (WeylGroupTypeA n) := Finite.of_injective (weylToPermHom n) (weylToPermHom_injective n)

theorem card_WeylGroupTypeA_eq_fact : Nat.card (WeylGroupTypeA n) = (n + 1).factorial := by
  exact?