AutoMathText / data /code /github-lean-train /0.10-0.15.jsonl
March07's picture
add batch 4/5 (200 files)
5697766 verified
Raw
History Blame Contribute Delete
27.6 kB
{"text": "import .lovelib\n\n\n/- # LoVe Preface\n\n## Proof Assistants\n\nProof assistants (also called interactive theorem provers)\n\n* check and help develop formal proofs;\n* can be used to prove big theorems, not only logic puzzles;\n* can be tedious to use;\n* are highly addictive (think video games).\n\nA selection of proof assistants, classified by logical foundations:\n\n* set theory: Isabelle/ZF, Metamath, Mizar;\n* simple type theory: HOL4, HOL Light, Isabelle/HOL;\n* **dependent type theory**: Agda, Coq, **Lean**, Matita, PVS.\n\n\n## Success Stories\n\nMathematics:\n\n* the four-color theorem (in Coq);\n* the odd-order theorem (in Coq);\n* the Kepler conjecture (in HOL Light and Isabelle/HOL).\n\nComputer science:\n\n* hardware\n* operating systems\n* programming language theory\n* compilers\n* security\n\n\n## Lean\n\nLean is a proof assistant developed primarily by Leonardo de Moura (Microsoft\nResearch) since 2012.\n\nIts mathematical library, `mathlib`, is developed under the leadership of\nJeremy Avigad (Carnegie Mellon University).\n\nWe use community version 3.20.0. We use its basic libraries, `mathlib`, and\n`LoVelib`. Lean is a research project.\n\nStrengths:\n\n* highly expressive logic based on a dependent type theory called the\n **calculus of inductive constructions**;\n* extended with classical axioms and quotient types;\n* metaprogramming framework;\n* modern user interface;\n* documentation;\n* open source;\n* endless source of puns (Lean Forward, Lean Together, Boolean, …).\n\n\n## This Course\n\n### Web Site\n\n https://lean-forward.github.io/logical-verification/2020/index.html\n\n\n### Installation Instructions\n\n https://github.com/blanchette/logical_verification_2020/blob/master/README.md#logical-verification-2020---installation-instructions\n\n\n### Repository (Demos, Exercises, Homework)\n\n https://github.com/blanchette/logical_verification_2020\n\nThe file you are currently looking at is a demo. There are\n\n* 13 demo files;\n* 13 exercise sheets;\n* 11 homework sheets (10 points each);\n* 1 project (20 points).\n\nYou may submit at most 10 homework, or at most 8 homework and the project.\nHomework, including the project, must be done individually. The homework builds\non the exercises, which build on the demos.\n\n\n### The Hitchhiker's Guide to Logical Verification\n\n https://github.com/blanchette/logical_verification_2020/blob/master/hitchhikers_guide.pdf\n https://github.com/blanchette/logical_verification_2020/blob/master/hitchhikers_guide_tablet.pdf\n\nThe lecture notes consist of a preface and 13 chapters. They cover the same\nmaterial as the corresponding lectures but with more details. Sometimes there\nwill not be enough time to cover everything in class, so reading the lecture\nnotes will be necessary.\n\n\n### Final Exam\n\nThe course aims at teaching concepts, not syntax. Therefore, the final exam is\non paper.\n\n\n## Our Goal\n\nWe want you to\n\n* master fundamental theory and techniques in interactive theorem proving;\n* familiarize yourselves with some application areas;\n* develop some practical skills you can apply on a larger project (as a hobby,\n for an MSc or PhD, or in industry);\n* feel ready to move to another proof assistant and apply what you have learned;\n* understand the domain well enough to start reading scientific papers.\n\nThis course is neither a pure logical foundations course nor a Lean tutorial.\nLean is our vehicle, not an end in itself.\n\n\n# LoVe Demo 1: Definitions and Statements\n\nWe introduce the basics of Lean and proof assistants, without trying to carry\nout actual proofs yet. We focus on specifying objects and statements of their\nintended properties. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## A View of Lean\n\nIn a first approximation:\n\n Lean = functional programming + logic\n\nIn today's lecture, we cover inductive types, recursive functions, and lemma\nstatements.\n\nIf you are not familiar with typed functional programming (e.g., Haskell, ML,\nOCaml, Scala), we recommend that you study a tutorial, such as the first\nchapters of the online tutorial __Learn You a Haskell for Great Good!__:\n\n http://learnyouahaskell.com/chapters\n\nMake sure to at least reach the section titled \"Lambdas\".\n\n\n## Types and Terms\n\nSimilar to simply typed Ξ»-calculus or typed functional programming languages\n(ML, OCaml, Haskell).\n\nTypes `Οƒ`, `Ο„`, `Ο…`:\n\n* type variables `Ξ±`;\n* basic types `T`;\n* complex types `T Οƒ1 … ΟƒN`.\n\nSome type constructors `T` are written infix, e.g., `β†’` (function type).\n\nThe function arrow is right-associative:\n`σ₁ β†’ Οƒβ‚‚ β†’ σ₃ β†’ Ο„` = `σ₁ β†’ (Οƒβ‚‚ β†’ (σ₃ β†’ Ο„))`.\n\nPolymorphic types are also possible. In Lean, the type variables must be bound\nusing `βˆ€`, e.g., `βˆ€Ξ±, Ξ± β†’ Ξ±`.\n\nTerms `t`, `u`:\n\n* constants `c`;\n* variables `x`;\n* applications `t u`;\n* Ξ»-expressions `Ξ»x, t`.\n\n__Currying__: functions can be\n\n* fully applied (e.g., `f x y z` if `f` is ternary);\n* partially applied (e.g., `f x y`, `f x`);\n* left unapplied (e.g., `f`).\n\nApplication is left-associative: `f x y z` = `((f x) y) z`. -/\n\n#check β„•\n#check β„€\n\n#check empty\n#check unit\n#check bool\n\n#check β„• β†’ β„€\n#check β„€ β†’ β„•\n#check bool β†’ β„• β†’ β„€\n#check (bool β†’ β„•) β†’ β„€\n#check β„• β†’ (bool β†’ β„•) β†’ β„€\n\n#check Ξ»x : β„•, x\n#check Ξ»f : β„• β†’ β„•, Ξ»g : β„• β†’ β„•, Ξ»h : β„• β†’ β„•, Ξ»x : β„•, h (g (f x))\n#check Ξ»(f g h : β„• β†’ β„•) (x : β„•), h (g (f x))\n\nconstants a b : β„€\nconstant f : β„€ β†’ β„€\nconstant g : β„€ β†’ β„€ β†’ β„€\n\n#check Ξ»x : β„€, g (f (g a x)) (g x b)\n#check Ξ»x, g (f (g a x)) (g x b)\n\n#check Ξ»x, x\n\nconstant trool : Type\nconstants trool.true trool.false trool.maybe : trool\n\n\n/- ### Type Checking and Type Inference\n\nType checking and type inference are decidable problems, but this property is\nquickly lost if features such as overloading or subtyping are added.\n\nType judgment: `C ⊒ t : Οƒ`, meaning `t` has type `Οƒ` in local context `C`.\n\nTyping rules:\n\n β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” Cst if c is declared with type Οƒ\n C ⊒ c : Οƒ\n\n β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” Var if x : Οƒ occurs in C\n C ⊒ x : Οƒ\n\n C ⊒ t : Οƒ β†’ Ο„ C ⊒ u : Οƒ\n β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” App\n C ⊒ t u : Ο„\n\n C, x : Οƒ ⊒ t : Ο„\n β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” Lam\n C ⊒ (Ξ»x : Οƒ, t) : Οƒ β†’ Ο„\n\n\n### Type Inhabitation\n\nGiven a type `Οƒ`, the __type inhabitation__ problem consists of finding a term\nof that type.\n\nRecursive procedure:\n\n1. If `Οƒ` is of the form `Ο„ β†’ Ο…`, a candidate inhabitant is an anonymous\n function of the form `Ξ»x, _`.\n\n2. Alternatively, you can use any constant or variable `x : τ₁ β†’ β‹― β†’ Ο„N β†’ Οƒ` to\n build the term `x _ … _`. -/\n\nconstants Ξ± Ξ² Ξ³ : Type\n\ndef some_fun_of_type : (Ξ± β†’ Ξ² β†’ Ξ³) β†’ ((Ξ² β†’ Ξ±) β†’ Ξ²) β†’ Ξ± β†’ Ξ³ :=\nΞ»f g a, f a (g (Ξ»b, a))\n\n\n/- ## Type Definitions\n\nAn __inductive type__ (also called __inductive datatype__,\n__algebraic datatype__, or just __datatype__) is a type that consists all the\nvalues that can be built using a finite number of applications of its\n__constructors__, and only those.\n\n\n### Natural Numbers -/\n\nnamespace my_nat\n\n/- Definition of type `nat` (= `β„•`) of natural numbers, using Peano-style unary\nnotation: -/\n\ninductive nat : Type\n| zero : nat\n| succ : nat β†’ nat\n\n#check nat\n#check nat.zero\n#check nat.succ\n\nend my_nat\n\n#print nat\n#print β„•\n\n\n/- ### Arithmetic Expressions -/\n\ninductive aexp : Type\n| num : β„€ β†’ aexp\n| var : string β†’ aexp\n| add : aexp β†’ aexp β†’ aexp\n| sub : aexp β†’ aexp β†’ aexp\n| mul : aexp β†’ aexp β†’ aexp\n| div : aexp β†’ aexp β†’ aexp\n\n\n/- ### Lists -/\n\nnamespace my_list\n\ninductive list (Ξ± : Type) : Type\n| nil : list\n| cons : Ξ± β†’ list β†’ list\n\n#check list.nil\n#check list.cons\n\nend my_list\n\n#print list\n\n\n/- ## Function Definitions\n\nThe syntax for defining a function operating on an inductive type is very\ncompact: We define a single function and use __pattern matching__ to extract the\narguments to the constructors. -/\n\ndef add : β„• β†’ β„• β†’ β„•\n| m nat.zero := m\n| m (nat.succ n) := nat.succ (add m n)\n\n#eval add 2 7\n#reduce add 2 7\n\ndef mul : β„• β†’ β„• β†’ β„•\n| _ nat.zero := nat.zero\n| m (nat.succ n) := add m (mul m n)\n\n#eval mul 2 7\n\n#print mul\n#print mul._main\n\ndef power : β„• β†’ β„• β†’ β„•\n| _ nat.zero := 1\n| m (nat.succ n) := m * power m n\n\n#eval power 2 5\n\ndef powerβ‚‚ (m : β„•) : β„• β†’ β„•\n| nat.zero := 1\n| (nat.succ n) := m * powerβ‚‚ n\n\n#eval powerβ‚‚ 2 5\n\ndef iter (Ξ± : Type) (z : Ξ±) (f : Ξ± β†’ Ξ±) : β„• β†’ Ξ±\n| nat.zero := z\n| (nat.succ n) := f (iter n)\n\n#check iter\n\ndef power₃ (m n : β„•) : β„• :=\niter β„• 1 (Ξ»l, m * l) n\n\n#eval power₃ 2 5\n\ndef append (Ξ± : Type) : list Ξ± β†’ list Ξ± β†’ list Ξ±\n| list.nil ys := ys\n| (list.cons x xs) ys := list.cons x (append xs ys)\n\n#check append\n#eval append _ [3, 1] [4, 1, 5]\n\n/- Aliases:\n\n `[]` := `nil`\n `x :: xs` := `cons x xs`\n `[x₁, …, xN]` := `x₁ :: … :: xN :: []` -/\n\ndef appendβ‚‚ {Ξ± : Type} : list Ξ± β†’ list Ξ± β†’ list Ξ±\n| list.nil ys := ys\n| (list.cons x xs) ys := list.cons x (appendβ‚‚ xs ys)\n\n#check appendβ‚‚\n#eval appendβ‚‚ [3, 1] [4, 1, 5]\n\n#check @appendβ‚‚\n#eval @appendβ‚‚ _ [3, 1] [4, 1, 5]\n\ndef append₃ {Ξ± : Type} : list Ξ± β†’ list Ξ± β†’ list Ξ±\n| [] ys := ys\n| (x :: xs) ys := x :: append₃ xs ys\n\ndef reverse {Ξ± : Type} : list Ξ± β†’ list Ξ±\n| [] := []\n| (x :: xs) := reverse xs ++ [x]\n\ndef eval (env : string β†’ β„€) : aexp β†’ β„€\n| (aexp.num i) := i\n| (aexp.var x) := env x\n| (aexp.add e₁ eβ‚‚) := eval e₁ + eval eβ‚‚\n| (aexp.sub e₁ eβ‚‚) := eval e₁ - eval eβ‚‚\n| (aexp.mul e₁ eβ‚‚) := eval e₁ * eval eβ‚‚\n| (aexp.div e₁ eβ‚‚) := eval e₁ / eval eβ‚‚\n\n/- Lean only accepts the function definitions for which it can prove\ntermination. In particular, it accepts __structurally recursive__ functions,\nwhich peel off exactly one constructor at a time.\n\n\n## Lemma Statements\n\nNotice the similarity with `def` commands. -/\n\nnamespace sorry_lemmas\n\nlemma add_comm (m n : β„•) :\n add m n = add n m :=\nsorry\n\nlemma add_assoc (l m n : β„•) :\n add (add l m) n = add l (add m n) :=\nsorry\n\nlemma mul_comm (m n : β„•) :\n mul m n = mul n m :=\nsorry\n\nlemma mul_assoc (l m n : β„•) :\n mul (mul l m) n = mul l (mul m n) :=\nsorry\n\nlemma mul_add (l m n : β„•) :\n mul l (add m n) = add (mul l m) (mul l n) :=\nsorry\n\nlemma reverse_reverse {Ξ± : Type} (xs : list Ξ±) :\n reverse (reverse xs) = xs :=\nsorry\n\n/- Axioms are like lemmas but without proofs (`:= …`). Constant declarations\nare like definitions but without bodies (`:= …`). -/\n\nconstants a b : β„€\n\naxiom a_less_b :\n a < b\n\nend sorry_lemmas\n\nend LoVe\n", "meta": {"author": "blanchette", "repo": "logical_verification_2020", "sha": "7a9f4bd73498189d9beb5d4591e0f2b3ca316111", "save_path": "github-repos/lean/blanchette-logical_verification_2020", "path": "github-repos/lean/blanchette-logical_verification_2020/logical_verification_2020-7a9f4bd73498189d9beb5d4591e0f2b3ca316111/lean/love01_definitions_and_statements_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. NO\n2. NO\n\n", "lm_q1_score": 0.46490157137338844, "lm_q2_score": 0.28140560140262283, "lm_q1q2_score": 0.13082590628535276}}
{"text": "import .lovelib\n\n\n/-! # LoVe Demo 1: Definitions and Statements\n\nWe introduce the basics of Lean and proof assistants, without trying to carry\nout actual proofs yet. We focus on specifying objects and statements of their\nintended properties. -/\n\n\nset_option pp.beta true\n\nnamespace LoVe\n\n\n/-! ## Proof Assistants\n\nProof assistants (also called interactive theorem provers)\n\n* check and help develop formal proofs;\n* can be used to prove big theorems, not only logic puzzles;\n* can be tedious to use;\n* are highly addictive (think video games).\n\nA selection of proof assistants, classified by logical foundations:\n\n* set theory: Isabelle/ZF, Metamath, Mizar;\n* simple type theory: HOL4, HOL Light, Isabelle/HOL;\n* **dependent type theory**: Agda, Coq, **Lean**, Matita, PVS.\n\n\n## Success Stories\n\nMathematics:\n\n* the four-color theorem (in Coq);\n* the odd-order theorem (in Coq);\n* the Kepler conjecture (in HOL Light and Isabelle/HOL).\n\nComputer science:\n\n* hardware\n* operating systems\n* programming language theory\n* compilers\n* security\n\n\n## Lean\n\nLean is a fairly new proof assistant developed primarily by Leonardo de Moura\n(Microsoft Research) since 2012.\n\nIts mathematical library, `mathlib`, is developed under the leadership of\nJeremy Avigad (Carnegie Mellon University).\n\nWe use community version 3.5.1. We use its basic libraries, `mathlib`, and\nLoVelib`. Lean is a research project, with some rough edges.\n\nStrengths:\n\n* highly expressive logic based on a dependent type theory called the\n **calculus of inductive constructions**;\n* extended with classical axioms and quotient types;\n* metaprogramming framework;\n* modern user interface;\n* documentation;\n* open source;\n* endless source of puns (Lean Forward, Lean Together, Boolean, …).\n\n\n## This Course\n\n### Web Site\n\n https://lean-forward.github.io/logical-verification/2020/index.html\n\n\n### Installation Instructions\n\n https://github.com/blanchette/logical_verification_2020/blob/master/README.md#logical-verification-2020---installation-instructions\n\n\n### Repository (Demos, Exercises, Homework)\n\n https://github.com/blanchette/logical_verification_2020\n\nThe file you are currently looking at is a demo. There are\n\n* 13 demo files;\n* 13 exercise sheets;\n* 11 homework sheets (10 points each);\n* 1 project (20 points).\n\nYou may submit at most 10 homework, or at most 8 homework and the project.\nHomework, including the project, must be done individually. The homework builds\non the exercises, which build on the demoes.\n\n\n### The Hitchhiker's Guide to Logical Verification\n\n https://github.com/blanchette/logical_verification_2020/blob/master/hitchhikers_guide.pdf\n\nThe lecture notes consist of a preface and 13 chapters. They cover the same\nmaterial as the corresponding lectures but with more details. Sometimes there\nwill not be enough time to cover everything in class, so reading the lecture\nnotes will be necessary.\n\n\n### Final Exam\n\nThe course aims at teaching concepts, not syntax. Therefore, the final exam is\non paper.\n\n\n## Our Goal\n\nWe want you to\n\n* master fundamental theory and techniques in interactive theorem proving;\n* famliarize yourselves with some application areas;\n* develop some practical skills which you can apply on a larger project (as a\n hobby, for an MSc or PhD, or in industry);\n* feel ready to move to another proof assistant and apply what you have learned;\n* understand the domain well enough to start reading scientific papers.\n\nThis course is neither a pure metatheory course nor a Lean tutorial. Lean is our\nvehicle, not an end in itself.\n\n\n## A View of Lean\n\nIn a first approximation:\n\n Lean = typed functional programming + logic\n\nIn today's lecture, we cover inductive types, recursive functions, and lemma\nstatements.\n\nIf you are not familiar with typed functional programming (e.g., Haskell, ML,\nOCaml, Scala), we recommend that you study a tutorial, such as the first five\nand a half chapters of __Learn You a Haskell for Great Good!__:\n\n http://learnyouahaskell.com/chapters\n\n\n## Types and Terms\n\nSimilar to simply typed Ξ»-calculus or typed functional programming languages\n(ML, OCaml, Haskell).\n\nTypes `Οƒ`, `Ο„`, `Ο…`:\n\n* type variables `Ξ±`;\n* basic types `T`;\n* complex types `T Οƒ1 … ΟƒN`.\n\nSome type constructors `T` are written infix, e.g., `β†’` (function type).\n\nThe function arrow is right-associative:\n`σ₁ β†’ Οƒβ‚‚ β†’ σ₃ β†’ Ο„` = `σ₁ β†’ (Οƒβ‚‚ β†’ (σ₃ β†’ Ο„))`.\n\nIn Lean, type variables must be bound using `βˆ€`, e.g., `βˆ€Ξ±, Ξ± β†’ Ξ±`.\n\nTerms `t`, `u`:\n\n* constants `c`;\n* variables `x`;\n* applications `t u`;\n* Ξ»-expressions `Ξ»x, t`.\n\n__Currying__: functions can be\n\n* fully applied (e.g., `f x y z` if `f` is ternary);\n* partially applied (e.g., `f x y`, `f x`);\n* left unapplied (e.g., `f`).\n\nApplication is left-associative: `f x y z` = `((f x) y) z`. -/\n\n#check β„•\n#check β„€\n\n#check empty\n#check unit\n#check bool\n\n#check β„• β†’ β„€\n#check β„€ β†’ β„•\n#check bool β†’ β„• β†’ β„€\n#check (bool β†’ β„•) β†’ β„€\n#check β„• β†’ (bool β†’ β„•) β†’ β„€\n\n#check Ξ»x : β„•, x\n#check Ξ»f : β„• β†’ β„•, Ξ»g : β„• β†’ β„•, Ξ»h : β„• β†’ β„•, Ξ»x : β„•, h (g (f x))\n#check Ξ»(f g h : β„• β†’ β„•) (x : β„•), h (g (f x))\n\nconstants a b : β„€\nconstant f : β„€ β†’ β„€\nconstant g : β„€ β†’ β„€ β†’ β„€\n\n#check Ξ»x : β„€, g (f (g a x)) (g x b)\n#check Ξ»x, g (f (g a x)) (g x b)\n\n#check Ξ»x, x\n\nconstant trool : Type\nconstants trool.true trool.false trool.maybe : trool\n\n\n/-! ### Type Checking and Type Inference\n\nType checking and type inference are decidable problems, but this property is\nquickly lost if features such as overloading or subtyping are added.\n\nType judgment: `C ⊒ t : Οƒ`, meaning `t` has type `Οƒ` in local context `C`.\n\nTyping rules:\n\n β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” Cst if c is declared with type Οƒ\n C ⊒ c : Οƒ\n\n β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” Var if x : Οƒ occurs in C\n C ⊒ x : Οƒ\n\n C ⊒ t : Οƒ β†’ Ο„ C ⊒ u : Οƒ\n β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” App\n C ⊒ t u : Ο„\n\n C, x : Οƒ ⊒ t : Ο„\n β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” Lam\n C ⊒ (Ξ»x : Οƒ, t) : Οƒ β†’ Ο„\n\n\n### Type Inhabitation\n\nGiven a type `Οƒ`, the __type inhabitation__ problem consists of finding a term\nof that type.\n\nRecursive procedure:\n\n1. If `Οƒ` is of the form `Ο„ β†’ Ο…`, a candidate inhabitant is an anonymous\n function of the form `Ξ»x, _`.\n\n2. Alternatively, you can use any constant or variable `x : τ₁ β†’ β‹― β†’ Ο„N β†’ Οƒ` to\n build the term `x _ … _`. -/\n\nconstants Ξ± Ξ² Ξ³ : Type\n\ndef some_fun_of_type : (Ξ± β†’ Ξ² β†’ Ξ³) β†’ ((Ξ² β†’ Ξ±) β†’ Ξ²) β†’ Ξ± β†’ Ξ³ :=\nΞ»f g a, f a (g (Ξ»b, a))\n#check some_fun_of_type\n\n/-! ## Type Definitions\n\nAn __inductive type__ (also called __inductive datatype__,\n__algebraic datatype__, or just __datatype__) is a type that consists all the\nvalues that can be built using a finite number of applications of its\n__constructors__, and only those.\n\n\n### Natural Numbers -/\n\nnamespace my_nat\n\n/-! Definition of type `nat` (= `β„•`) of natural numbers, using Peano-style unary\nnotation: -/\n\ninductive nat : Type\n| zero : nat\n| succ : nat β†’ nat\n\n#check nat\n#check nat.zero\n#check nat.succ\n\nend my_nat\n\n#print nat\n#print β„•\n\n\n/-! ### Arithmetic Expressions -/\n\ninductive aexp : Type\n| num : β„€ β†’ aexp\n| var : string β†’ aexp\n| add : aexp β†’ aexp β†’ aexp\n| sub : aexp β†’ aexp β†’ aexp\n| mul : aexp β†’ aexp β†’ aexp\n| div : aexp β†’ aexp β†’ aexp\n\n\n/-! ### Lists -/\n\nnamespace my_list\n\ninductive list (Ξ± : Type) : Type\n| nil : list\n| cons : Ξ± β†’ list β†’ list\n\n#check list.nil\n#check list.cons\n\nend my_list\n\n#print list\n\n\n/-! ## Function Definitions\n\nThe syntax for defining a function operating on an inductive type is very\ncompact: We define a single function and use __pattern matching__ to extract the\narguments to the constructors. -/\n\ndef add : β„• β†’ β„• β†’ β„•\n| m nat.zero := m\n| m (nat.succ n) := nat.succ (add m n)\n\n#eval add 2 7\n#reduce add 2 7\n\ndef mul : β„• β†’ β„• β†’ β„•\n| _ nat.zero := nat.zero\n| m (nat.succ n) := add m (mul m n)\n\n#eval mul 2 7\n\n#print mul\n#print mul._main\n\ndef power : β„• β†’ β„• β†’ β„•\n| _ nat.zero := 1\n| m (nat.succ n) := m * power m n\n\n#eval power 2 5\n#check power\n\ndef powerβ‚‚ (m : β„•) : β„• β†’ β„•\n| nat.zero := 1\n| (nat.succ n) := m * powerβ‚‚ n\n\n#eval powerβ‚‚ 2 5\n#check powerβ‚‚\n\ndef iter (Ξ± : Type) (z : Ξ±) (f : Ξ± β†’ Ξ±) : β„• β†’ Ξ±\n| nat.zero := z\n| (nat.succ n) := f (iter n)\n\n#check iter\n\ndef power₃ (m n : β„•) : β„• :=\niter β„• 1 (Ξ»l, m * l) n\n\n#eval power₃ 2 5\n\ndef append (Ξ± : Type) : list Ξ± β†’ list Ξ± β†’ list Ξ±\n| list.nil ys := ys\n| (list.cons x xs) ys := list.cons x (append xs ys)\n\n#check append\n#eval append _ [3, 1] [4, 1, 5]\n\n/-! Aliases:\n\n `[]` := `nil`\n `x :: xs` := `cons x xs`\n `[x₁, …, xN]` := `x₁ :: … :: xN` -/\n\ndef appendβ‚‚ {Ξ± : Type} : list Ξ± β†’ list Ξ± β†’ list Ξ±\n| list.nil ys := ys\n| (list.cons x xs) ys := list.cons x (appendβ‚‚ xs ys)\n\n#check appendβ‚‚\n#eval appendβ‚‚ [3, 1] [4, 1, 5]\n\n#check @appendβ‚‚\n#eval @appendβ‚‚ β„• [3, 1] [4, 1, 5]\n\ndef append₃ {Ξ± : Type} : list Ξ± β†’ list Ξ± β†’ list Ξ±\n| [] ys := ys\n| (x :: xs) ys := x :: append₃ xs ys\n\ndef reverse {Ξ± : Type} : list Ξ± β†’ list Ξ±\n| [] := []\n| (x :: xs) := reverse xs ++ [x]\n\ndef eval (env : string β†’ β„€) : aexp β†’ β„€\n| (aexp.num i) := i\n| (aexp.var x) := env x\n| (aexp.add e₁ eβ‚‚) := eval e₁ + eval eβ‚‚\n| (aexp.sub e₁ eβ‚‚) := eval e₁ - eval eβ‚‚\n| (aexp.mul e₁ eβ‚‚) := eval e₁ * eval eβ‚‚\n| (aexp.div e₁ eβ‚‚) := eval e₁ / eval eβ‚‚\n\n/-! Lean only accepts the function definitions for which it can prove\ntermination. In particular, it accepts __structurally recursive__ functions,\nwhich peel off exactly one constructor at a time.\n\n\n## Lemma Statements\n\nNotice the similarity with `def` commands. -/\n\nnamespace sorry_lemmas\n\nlemma add_comm (m n : β„•) :\n add m n = add n m :=\nsorry\n\nlemma add_assoc (l m n : β„•) :\n add (add l m) n = add l (add m n) :=\nsorry\n\nlemma mul_comm (m n : β„•) :\n mul m n = mul n m :=\nsorry\n\nlemma mul_assoc (l m n : β„•) :\n mul (mul l m) n = mul l (mul m n) :=\nsorry\n\nlemma mul_add (l m n : β„•) :\n mul l (add m n) = add (mul l m) (mul l n) :=\nsorry\n\nlemma reverse_reverse {Ξ± : Type} (xs : list Ξ±) :\n reverse (reverse xs) = xs :=\nbegin\n induction xs,\n {refl},\n {\n sorry\n }\nend\n\n/-! Axioms are like lemmas but without proofs (`:= …`). Constant declarations\nare like definitions but without bodies (`:= …`). -/\n\nconstants a b : β„€\n\naxiom a_less_b :\n a < b\n\nend sorry_lemmas\n\nend LoVe\n", "meta": {"author": "yizhou7", "repo": "learning-lean", "sha": "91fb366c624df6e56e19555b2e482ce767cd8224", "save_path": "github-repos/lean/yizhou7-learning-lean", "path": "github-repos/lean/yizhou7-learning-lean/learning-lean-91fb366c624df6e56e19555b2e482ce767cd8224/my_project/src/love01_definitions_and_statements_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. NO\n2. NO", "lm_q1_score": 0.4532618480153861, "lm_q2_score": 0.2751297357103299, "lm_q1q2_score": 0.1247058124520489}}
{"text": "/- TEXT:\nGetting Started\n---------------\n\nThe goal of this book is to teach you to formalize mathematics using the\nLean 3 interactive proof assistant.\nIt assumes that you know some mathematics, but it does not require much.\nAlthough we will cover examples ranging from number theory\nto measure theory and analysis,\nwe will focus on elementary aspects of those fields,\nin the hopes that if they are not familiar to you,\nyou can pick them up as you go.\nWe also don't presuppose any background in formalization.\nFormalization can be seen as a kind of computer programming:\nwe will write mathematical definitions, theorems, and proofs in\na regimented language, like a programming language,\nthat Lean can understand.\nIn return, Lean provides feedback and information,\ninterprets expressions and guarantees that they are well-formed,\nand ultimately certifies the correctness of our proofs.\n\nYou can learn more about Lean from the\n`Lean project page <https://leanprover.github.io>`_\nand the\n`Lean community web pages <https://leanprover-community.github.io/>`_.\nThis tutorial is based on Lean's large and ever-growing library, *mathlib*.\nWe also strongly recommend taking a look at the\n`Lean Zulip online chat group <https://leanprover.zulipchat.com/>`_\nif you haven't already.\nYou'll find a lively and welcoming community of Lean enthusiasts there,\nhappy to answer questions and offer moral support.\n\nAlthough you can read a pdf or html version of this book online,\nit designed to be read interactively,\nrunning Lean from inside the VS Code editor.\nTo get started:\n\n#. Install Lean, VS Code, and mathlib following the instructions\n on the `community web site <https://leanprover-community.github.io/>`_.\n\n#. In a terminal, type ``leanproject get mathematics_in_lean``\n to set up a working directory for this tutorial.\n\n#. Type ``code mathematics_in_lean`` to open that directory in\n ``VS Code``.\n\nOpening any Lean file will simultaneously open this\nbook in a VS Code window. You can update to a newer version by tying\n``git pull`` followed by ``leanproject get-mathlib-cache`` inside\nthe ``mathematics_in_lean`` folder.\n\nAlternatively, you can run Lean and VS Code in the cloud,\nusing `Gitpod <https://gitpod.io/>`_.\nYou can find instructions as to how to do that on the Mathematics in Lean\n`project page <https://github.com/leanprover-community/mathematics_in_lean>`_\non Github.\n\nEach section in this book has an associated Lean file with examples\nand exercises. You can find them in the folder `src`,\norganized by chapter. We recommend making a copy of that folder\nso that you can experiment with the files as you go,\nwhile leaving the originals intact.\nThe text will often include examples, like this one:\nTEXT. -/\n-- QUOTE:\n#eval \"Hello, World!\"\n-- QUOTE.\n/- TEXT:\nYou should be able to find the corresponding example in the associated\nLean file.\nIf you click on the line, VS Code will show you Lean's feedback in\nthe ``Lean Goal`` window, and if you hover\nyour cursor over the ``#eval`` command VS Code will show you Lean's response\nto this command in a pop-up window.\nYou are encouraged to edit the file and try examples of your own.\n\nThis book moreover provides lots of challenging exercises for you to try.\nDon't rush past these!\nLean is about *doing* mathematics interactively, not just reading about it.\nWorking through the exercises is central to the experience.\nYou can always compare your solutions to the ones in the ``solutions``\nfolder associated with each section.\nTEXT. -/", "meta": {"author": "avigad", "repo": "mathematics_in_lean_source", "sha": "4eeb8c43762522c1acaa7f799599609d6a48f59e", "save_path": "github-repos/lean/avigad-mathematics_in_lean_source", "path": "github-repos/lean/avigad-mathematics_in_lean_source/mathematics_in_lean_source-4eeb8c43762522c1acaa7f799599609d6a48f59e/lean_source/01_Introduction/source_01_Getting_Started.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. NO\n2. NO", "lm_q1_score": 0.3886180267058489, "lm_q2_score": 0.2909808785120009, "lm_q1q2_score": 0.11308041481646813}}