Autoformalize your Math

7. How to contribute🔗

Finally, we have reached the point where all the setup is done. All that we did in the previous chapters only had to be done once, and we are done. I know, it was a long journey, but I hope you learned something in the process. Now I will show you the workflow you will have to follow to make contributions to the library. It may look cumbersome at first, but you will get used to it. The goal of this workflow is to collaborate effectively and without making each other's lives miserable. As always, I will explain the reason and goal of every single command. Instead of trying to memorize the commands (there is no point in doing that), try to follow the big picture of the workflow. You will realize that it makes a lot of sense, and you will not forget it.

7.1. git branches🔗

It would be a mess if everyone that passed by could make changes to the library freely without someone in charge supervising. To make sure that all the new content that is added to the library has the necessary quality and is correct (i.e., Lean still compiles after the change), we have to use git branches.

The idea is the following: we will check first that our fork of the library is up to date with the original one, then we will create a branch in our fork, make our changes, and finally ask the maintainers of the main library to incorporate the changes of our branch into the main repository. Let's do it.

  1. First things first: open the terminal and navigate to the banlat folder. Remember that you can also use the terminal inside VS Code (if you have the banlat folder open in VS Code, the terminal it spawns will already be inside that folder).

  2. Run

    $
    git switch master

    to make sure you are in the master branch.

  3. Run

    $
    git pull

    If your local repository is up to date with davidmunozlahoz/banlat, you will see a message saying so. Otherwise, it will apply the new changes from the repository, and you will see something similar to this:

    git pull output

    Now the state of our local repository is exactly the same as that of davidmunozlahoz/banlat.

  4. Create a new branch, with a descriptive name of the additions or changes to be made to the library. In this particular example, we are going to add the definition and very basic properties of order convergence. You don't need to know what this means: it is just an example. For this reason, we call the new branch basic-order-conv and create it with

    $
    git switch -c basic-order-conv
    Switched to new branch 'basic-order-conv'

    The -c flag means: create a new branch with this name, and switch to it immediately. As explained by the output, we are now in the branch basic-order-conv.

7.2. Making our changes🔗

We can now safely write our own Lean code. In this particular case, just as an example, I am going to ask Codex to create a new file Convergences/Order.lean with the definition of order convergence and some very basic properties. I will do this in state mode using the following prompt:

Enter state mode. Create a file @Convergence/Order.lean with the
definition of order convergence (the general one, in which the
regulating net need not have the same index set as the original
net), then state that an increasing supremum is a particular case of order
convergence, and that the linear and lattice operations are order
continuous.

After thinking for a while, Codex has proposed a patch with the definitions and facts I asked for.

Codex proposed patch

After carefully reviewing the patch, I have approved it and Codex has created the file you can see below.

Order convergence file

This file compiles modulo sorries, meaning that the statements and definitions compile, but there are no proofs (they are replaced by sorries). Now it is time to start a new conversation with Codex and ask it to enter prove mode and fill in the sorries in the file:

Enter prove mode and fill in the sorries in @Convergences/Order.lean

After a while, and if they are within reach (i.e., the adequate infrastructure is already available), Codex will have filled in the proofs, creating auxiliary lemmas when needed.

Codex proof conversation

7.3. Saving our changes🔗

We have thus contributed to the library! We now have to "save" these changes (that is, commit them), and then upload them, first to our own fork of banlat, and then to the original one. In the terminal you have open, run

$
git status

to see what files have been modified since the last commit (remember: a commit is nothing more than a snapshot of the current state of the repository).

We are going to create a new commit with the changes we have made. To add files to be committed, use git add. For instance, to add the file BanLat.lean, run git add BanLat.lean, as I did below. You can see that now the file has a new status, and appears under "Changes to be committed:"

git status after staging

This is useful if you only want to add certain files to the next commit. If you want to add all the modified files, just run:

$
git add .

These files are now staged and ready to be committed.

We can now commit our changes. Each commit has a message (that should consist of no more than one line) describing the changes made. In my case, the commit looks something like this:

$
git commit -m "feat: add order convergence definition and order continuity of operations"

The changes are now committed; it is time to

$
git push

We can now go to our repository on GitHub, click on the branches button (the button where it says master by default and there is an arrow to expand it), and see our branch there.

GitHub branch selector

Click on that branch. The repository will show the new commit we made, and the changes it incorporates.

7.4. Pull requesting🔗

The moment of truth has come. We want to add the changes of this branch to the main banlat library. For this we have to do a pull request.

In order to do this, click on the "Contribute" button that GitHub shows in a banner, then click on "Open pull request".

GitHub open pull request prompt

Write a clear title, and description if needed, so as to make the life of the maintainer of the library (i.e., me) easy.

GitHub pull request form

Your pull request is created now. In order for your commits to be incorporated into the main repository, this pull request has to be merged. Before that, the maintainer may send you messages asking for clarifications or corrections. You can interact with the maintainer using the conversation window in the pull request. Once the pull request has been merged:

Merged pull request

You can now safely delete the branch from your repository doing

$
git switch master
git branch -d basic-order-conv

And get everything up to date with

$
git pull
git push

We are done! Your contribution is now accessible to everyone through the banlat library!