Theorem Proving in Lean
Release 3.23.0constant m : nat -- m is a natural number constant n : nat constants b1 b2 : bool -- declare two constants at once /- check their types -/ #check m -- output: nat #check n #check n + 0 -- nat #check m m * (n + 0) -- nat #check b1 -- bool #check b1 && b2 -- "&&" is boolean and #check b1 || b2 -- boolean or #check tt -- boolean "true" -- Try some examples of your own. Any text between the /- and m n : nat constant f : nat → nat -- type the arrow as "\to" or "\r" constant f' : nat -> nat -- alternative ASCII notation constant f'' : N → N -- alternative notation for nat constant p : nat × nat0 码力 | 173 页 | 777.93 KB | 1 年前3
The Hitchhiker’s Guide to
Logical Verificationcan be defined as follows: inductive nat : Type | zero : nat | succ : nat → nat The first line announces to the world that we are introducing a new type called nat, intended to represent the natural numbers The second and third line de- clare two new constructors, nat.zero : nat and nat.succ : nat → nat, that can be used to build values of type nat. Following an established convention in com- puter science requires an argument of type nat to produce a value of type nat. The terms nat.zero nat.succ nat.zero nat.succ (nat.succ nat.zero) ... denote the diferent values of type nat—zero, its successor, its successor’s0 码力 | 215 页 | 1.95 MB | 1 年前3
An Introduction to Leanfreely and inductively by a constant, zero, and a unary function succ: inductive nat : Type | zero : nat | succ : nat → nat If you copy this definition into the editor window at right you will see that avoid conflicting with the standard definition, which is loaded by default. Even so, choosing the name nat means that within the namespace this identifier is overloaded, which can cause confusion. Thus we will go on to define addition by recursion on the second argument: def add : nat → nat → nat | m nat.zero := m | m (nat.succ n) := nat.succ (add m n) Lean compiles definitions like these down to a single axiomatic0 码力 | 48 页 | 191.92 KB | 1 年前3
The Lean Reference Manual
Release 3.3.0(x y z : N) : N := x + y + z #check ex1 1 2 3 def id1 (α : Type u) (x : α) : α := x #check id1 nat 3 3.3. Implicit Arguments 13 The Lean Reference Manual, Release 3.3.0 #check id1 _ 3 def id2 {α Assertions The core library contains a number of basic data types, such as the natural numbers (N, or nat), the integers (Z), the booleans (bool), and common operations on these, as well as the usual logical 5 in x + 3 def f x := x + 3 #reduce f 5 #eval f 5 #reduce @nat.rec (λ n, N) (0 : N) (λ n recval : N, recval + n + 1) (5 : N) #eval @nat.rec (λ n, N) (0 : N) (λ n recval : N, recval + n + 1) (5 : N)0 码力 | 67 页 | 266.23 KB | 1 年前3
Programming in Lean
Release 3.4.2computational interpretation, which is to say, they can be evaluated. Any closed term of type nat – that is, any term of type nat without free variables – evaluates to a numeral, as long as it is defined in the computational computational fragment of Lean’s foundational framework. Similarly, any closed term of type list nat evaluates to a list of numerals, and any closed term of type bool evaluates either to the boolean value interpretation. Lean’s standard library defines a number of data types, such as nat, int, list, and bool. #check nat #print nat #check int #print int #check list #print list #check bool #print bool 30 码力 | 51 页 | 220.07 KB | 1 年前3
Lean 2 Quick Referencedefinition or theorem, or using the attribute or local attribute commands. Example: local attribute nat.add nat.mul [reducible]. reducible : unfold at any time during elaboration if necessary quasireducible anonymous binders (like lambda, take, obtain, etc.) by enclosing the type in backticks, as in λ `nat`, `nat` + 1. This introduces a variable of the given type in the context with a hidden name. Tactic Mode Types Π Pi \Pi → -> \to, \r, \implies Σ Sigma \S, \Sigma × prod \times sum \union, \u+, \uplus N nat \nat Z int \int Q rat \rat R real \real When you open the namespaces prod and sum, you can use * and0 码力 | 9 页 | 62.97 KB | 1 年前3
Lean 4stxStack := s.stxStack.push n } def mkNode (s : ParserState) (k : SyntaxNodeKind) (iniStackSz : Nat) : ParserState := match s with | ⟨stack, pos, cache, err⟩ => let newNode := Syntax.node k (stack0 码力 | 20 页 | 1.78 MB | 1 年前3
Lean in LeanstxStack := s.stxStack.push n, .. s } def mkNode (s : ParserState) (k : SyntaxNodeKind) (iniStackSz : Nat) : ParserState := match s with | ⟨stack, pos, cache, err⟩ => let newNode := Syntax.node k (stack0 码力 | 54 页 | 4.78 MB | 1 年前3
共 8 条
- 1













