Skip to the content.

Getting Started in PhysLean

This is a guide for getting started with PhysLean, aimed at people with no Lean experience or who are new to the project.
Click here for ideas of how to get involved

Useful resources

šŸŽ® The Natural Numbers Game šŸ“ŗ Lean for Scientists and Engineers Lectures by Tyler Josephson

Installing

Lean Installation Guide

Ready to get started with Lean? Click the button below to see the installation instructions:

Install Lean

PhysLean Installation Steps

Follow these steps to install PhysLean:

  1. Clone the repository: https://github.com/HEPLean/PhysLean
  2. Run the following commands in the top-level PhysLean directory:
        
lake update 
lake exe cache get
lake build
        
    
Here lake build may take around 20 minutes.

Trouble-shooting

Sometimes things go wrong due to no fault of your own. PhysLean or one of its dependencies may have been updated to a new version of Lean for example. In these cases you can try the following:

            
    rm -rf .lake
    lake update
    lake exe cache get
    lake build
            
        

Writing results

Things to bear in mind:

Definitions

Definitions are used to introduce new concepts or objects in a precise and formal way. In PhysLean we give all definitions doc-strings.

        
/-- For a harmonic oscillator, the Schrodinger Operator corresponding to it
is defined as the function from `ā„ → ā„‚` to `ā„ → ā„‚` taking

`ψ ↦ - ā„^2 / (2 * m) * ψ'' + 1/2 * m * ω^2 * x^2 * ψ`. -/
noncomputable def schrodingerOperator (ψ : ā„ → ā„‚) : ā„ → ā„‚ :=
    fun x => - Q.ā„ ^ 2 / (2 * Q.m) * (deriv (deriv ψ) x) + 1/2 * Q.m * Q.ω^2 * x^2 * ψ x
    
    
structure, inductive and abbrev also introduce new concepts in a similar way to def.

Lemmas

In PhysLean we use lemmas for every theorem which is not a main one. For every lemma you must provide a proof e.g.

        
lemma schrodingerOperator_parity (ψ : ā„ → ā„‚) :
    Q.schrodingerOperator (parity ψ) = parity (Q.schrodingerOperator ψ) := by
    funext x
    have (ψ : ā„ → ā„‚) : (fun x => (deriv fun x => ψ (-x)) x) = fun x => - deriv ψ (-x) := by
    funext x
    rw [← deriv_comp_neg]
    simp [schrodingerOperator, parity, this]
    

Theorems

Theorems are significant results, but are otherwise exactly the same as lemmas.

        
theorem wicks_theorem_normal_order : (φs : List š“•.FieldOp) →
    š“£(š“(ofFieldOpList φs)) =
    āˆ‘ (φsĪ› : {φsĪ› : WickContraction φs.length // ¬ HaveEqTime φsĪ›}), φsĪ›.1.wickTerm := by 
  ...
        
    

Informal Definitions

Informal definitions are definitions written in English rather than in Lean. They are given a tag (you can get a tag using lake exe make_tag), and a list of dependencies. The definition itself is written in the doc-string. They can not be used in further results.

        
/-- The hubble constant defined in terms of the scale factor
as `(dā‚œ a) / a`.

The notation `H` is used for the `hubbleConstant`. -/
informal_definition hubbleConstant where
    deps := []
    tag := "6Z2NB"
        
    

Informal Lemmas

Informal lemmas are lemmas written in English rather than in Lean. They are given a tag (you can get a tag using lake exe make_tag), and a list of dependencies. The lemma and proof itself are written in the doc-string. They can not be used in further results.

        
/-- The time evolution of the hubble parameter is equal to `dā‚œ H = - H^2 (1 + q)`. -/
informal_lemma time_evolution_hubbleConstant where
    deps := [hubbleConstant]
    tag := "6Z3BS"
        
    

Semi-Formal Results

Semi-formal results are like informal definitions and lemmas except the type of the definition or statement of the lemma is made formal. They are half-way between informal definitions and lemmas and formal statements. They cannot be used in further results. They are also given a tag.

        
/-- The force on the classical harmonic oscillator is `- k x`. -/
semiformal_result "6YB2U" force_is_linear (x : ā„ → ā„) :
    force S x = - S.k • x
        
    

TODO items

Todo items are used to indicate things which are to be done. The consist of a tag and a string statement of what is to be done.

        
TODO "6VZHC" "Create a new folder for the damped harmonic oscillator, initially as a place-holder."
        
    

Making a new file

When to make a new file?

New files should be made when there is a natural seperation of results in an existing file. Or when a new result is being added to the project which does not fit in any existing file.

Making a New File

Linting

What is Linting?

Linting is the process of checking your code for potential errors, stylistic issues, and adherence to coding standards. It helps ensure that your code is clean, consistent, and free from common mistakes.

On making a pull-request to PhysLean, GitHub workflows will lint your code automatically.

Linting Locally

You can also check your code locally using the following commands:

        
lake exe lint_all
./scripts/lint-style.sh
        
    

Ensuring these commands do not bring up errors helps maintain the quality of PhysLean!

Making a pull-request

Things to bear in mind:

Using Forks

  • Fork the PhysLean repository to your GitHub account.
  • Clone your forked repository to your local machine.
  • Make your changes on your local version.
  • Push your changes to your forked repository.
  • Open a pull request from your forked version to the main PhysLean repository.
  • Using Branches