owned this note
owned this note
Published
Linked with GitHub
---
tags: sage-days-114
---
# Sage Club at CMI
These are our records of to the Sage Club at CMI in Chennai, India in 2022. Anybody can edit these records, so please **plunge forward** and edit this document :+1:
There's a related page in the SageMath wiki at https://wiki.sagemath.org/days114/club.
# Generalities
Samuel Lelièvre and [Julian Rüth](mailto:julian.rueth@fsfe.org) are visiting CMI from 28/7/2022 until 27/08/2022. If you want to discuss something (related to SageMath or not) please drop by their offices anytime, **FR-03** and **FR-05**, respectively.
We scheduled Sage Club on **Mondays & Thursdays from 2pm-4pm in LH-6** at CMI. On Thursdays, we have the lecture hall also after 4pm, so we can extend the session easily.
In any case, Sage Club is not limited to these times. We can arrange sessions at any other time or you can just drop by our offices.
# Sessions
Here's a rough record of the sessions we had and what's planned for the future.
## Thursday 25/8 -- Parallel Computations in SageMath
There's a recording of much of the session at https://us02web.zoom.us/rec/share/dXuHoGKLWUG5KSiyQlWJYgUYDeo9DAEVs77x52lNYk3TaoyTOZO9wsLyXI9TP-j3.7UqenXb11_C_jPvt
During the session we'll parallelize some code originally written by Krishna Menon, namely:
```python=3
class FencePolynomials:
def __init__(self):
from sage.all import QQ
R = QQ["q", "t", "u"]
self._q, self._t, self._u = R.gens()
def _fence(self, composition):
elements = list(range(1, composition.size() + 2))
relations = []
for i, a in enumerate(composition):
s = sum(composition[:i], 1)
if i % 2 == 0:
for j in range(s, s + a):
relations.append([j, j + 1])
else:
for j in range(s, s + a):
relations.append([j + 1, j])
from sage.all import Poset
return Poset((elements, relations))
def _minimal_elements_of_complement(self, poset, ideal):
count = 0
for p in poset:
if p in ideal:
continue
for below in poset.lower_covers_iterator(p):
if below not in ideal:
break
else:
count += 1
return count
def _polynomial(self, composition):
poset = self._fence(composition)
return sum(
self._q ** len(ideal := poset.order_ideal(a)) *
self._t ** len(a) *
self._u ** self._minimal_elements_of_complement(poset, ideal)
for a in poset.antichains()
)
def _compositions_without_even_length_reverses(self, size):
from sage.all import Compositions
for c in Compositions(size):
if len(c) % 2 or c < c.reversed():
yield c
def check_collisions(self, size):
polynomial_to_composition = {}
compositions = self._compositions_without_even_length_reverses(size)
from rich.progress import track
for composition in track(compositions):
polynomial = self._polynomial(composition)
if polynomial in polynomial_to_composition:
raise Exception(
f"Found collision for polynomial {polynomial} corresponding to both {polynomial_to_composition[polynomial]} and {composition}"
)
polynomial_to_composition[polynomial] = composition
```
## Wednesday 24/8
Samuel and Julian at IMSc for informal Sage Club.
- finish up ticket 34373 on multimajor index for permutations
### Bug in coinversions of nonattacking fillings
```
sage: fill = [[4, 3], [2], [], [2]]
sage: perm = PermutationGroupElement([4, 2, 1, 3])
sage: f = AugmentedLatticeDiagramFilling(fill, perm)
sage: f
[[4, 4, 3], [2, 2], [1], [3, 2]]
```
## Tuesday 23/8 -- IMSc
Samuel and Julian at IMSc for informal Sage Club.
### Lie algebras
Aritra is interested in the paper
- Pamela E. Harris, Erik Insko, Anthony Simpson.
Computing weight q-multiplicities for the representations of the simple Lie algebras
https://arxiv.org/abs/1710.02183
links to a code repository hosted at
- https://github.com/antman1935/lie_algebras
We clone that repository:
```bash
$ git clone https://github.com/antman1935/lie_algebras.git
```
We change to the resulting directory:
```bash
$ cd lie_algebras
```
We run the Python file:
```bash
$ sage --python lie_algebra_multiplicity.py
6006
```
### Multimajor index for permutations
We resume last week's work on implementing multimajor index for permutations.
https://trac.sagemath.org/ticket/34373
To get the branch from the ticket:
```bash
$ git fetch trac u/gh-25shriya/34373
$ git switch -c t-34373 FETCH_HEAD
```
## Monday 22/8 -- Debugging SageMath
We want to look at bugs in SageMath. Please suggest things that don't work right. We want to find out how to report things properly, and how to find out what is causing a problem.
## Thursday 18/8 -- Implement new Structures in SageMath
We will walk you through implementing a new mathematical object in SageMath. Please bring your laptops to follow along.
We will try to implement [Plactic Monoids](https://en.wikipedia.org/wiki/Plactic_monoid) since they don't seem to be present in SageMath yet.
The code we wrote is at https://gist.github.com/saraedum/7c88d7735edb124fba730116b62a76e8
A good tutorial is also at https://doc.sagemath.org/html/en/thematic_tutorials/coercion_and_categories.html#coercion-and-categories
## Wednesday 17/8 -- IMSc
Samuel and Julian at IMSc for informal Sage Club.
- more installation steps on WSL
- work on multimajor index for permutations
## Tuesday 16/8 -- IMSc
Samuel and Julian at IMSc for informal Sage Club.
- install Sage on Windows using WSL and Conda
- released version
- latest version for development
- work on multimajor index for permutations
## Monday, 15/8 -- No Sage Club -- Enjoy the Holiday!
## Thursday, 11/8 -- Version Control with Git
We'll do a [Software Carpentry](https://software-carpentry.org/) style [Introduction to Git](https://swcarpentry.github.io/git-novice/). Please bring your laptops.
Please make sure that you have the Bash shell and Git installed. Instructions for Linux, macOS, and Windows can be found here:
- [Installing Bash](https://carpentries.github.io/workshop-template/#shell)
- [Installing Git](https://carpentries.github.io/workshop-template/#git)
## Monday, 8/8 -- Parametric curves in Sage
We will see how to use Sage to study and plot a parametric curve.
This will use Sage's symbolic ring.
## Thursday, 4/8 -- An Introduction to SageMath
We'll probably do another introduction to SageMath & install session for students that were not here during SageDays at IMSc.
### Installing SageMath
We walked some people through installing SageMath, see https://doc.sagemath.org/html/en/installation/index.html.
### Finding Duplicates
We looked at the problem of finding duplicates in a recursive generating function. Here's the code we ended up with:
```python=
q = var('q')
def f(A):
if len(A) == 1:
return 1 + q^A[0]
return q^A[-1] * f(A[:-1])
from collections import defaultdict
D = defaultdict(lambda: set())
for length in range(1, 5):
for c in cartesian_product([range(1, 6)] * length):
value = f(c)
D[value].add(c)
for value in D:
if len(D[value]) > 1:
print(D[value], value)
```
### Computations with Power Series
```python=
R.<x, y> = QQ[[]]
g = (1 + x).log(prec=123) * (1 + y).log(3)
```
## Monday, 1/8 -- Python Best Practices
We'll use a package called [stallings_graphs](https://plmlab.math.cnrs.fr/pascalweil/stallings_graphs/)
```bash
sage -pip install stallings_graphs
```
### Know your Editor
e.g., shortcuts to (un)indent, set a shortcut to restart & run all in the notebook
### Writing Good Code
Show your code to others and
import this
### Code Formatting
black directory/
### Linters
Instally any/all of pylint, pyright, pylance[^1], … and teach your editor to actually use them.
### Optimizing Code
> We should forget about small efficiencies, say about 97% of the time:
> premature optimization is the root of all evil.
> -- [Tony Hoare](https://en.wikipedia.org/wiki/Tony_Hoare)
Running `py-spy record --format=speedscope -- sage something.sage` often fails. Preprocess with `sage --preprocess something.sage`, then `py-spy record --format=speedscope -- python something.sage.py`. Open the output in [speedscope.app](https://speedscope.app). You can also see native C/C++/… calls with `--native` but you might want to lower the sampling rate to, 10Hz or so (check the other command line flags…)
We lookd at SageMath's `@cached_function` and `@cached_method`. There's also a builtin LRU cache in Python.
## Thursday, 28/7 -- An Introduction to SageMath
A tour of SageMath, [where is the notebook?](); we collected ideas about future sessions, namely
### Topics for Sage Club
* SageMath Development Process
* Commutative Algebra in SageMath, in particular interfacing with Singular
* Combinatoris in SageMath, in particular 4ti2 and Widgets to interact with partially ordered sets (posets)
* Best Practices of Python Programming
* Findstat
* Writing Python/SageMath Packages / How to Share your Code / Zenodo
* Introduction to Git
Please add more topics, and let us know about other things you would like to discuss :+1:
[^1]: pylance is not free (as in freedom) software; also, it does not currently understand imports from `sage`.