空白文字、改行、タブは空白とみなされる。
コメントは (* で始まり *) で終わる。コメントの中に他のコメントあるいは文字列を入れることができる。コメントは空白とみなされる。
識別子には、英字 (A, B, …)、下線 (_) その他 Unicode で識別子として利用可能とされている文字が使える。識別子の二文字目以降には数字およびプライム (') も使える。
特殊な意味を持つため識別子として使えないキーワードは以下の通り:
_asatcofixelseendexistsexists2fixforforallfunifIFinletmatchmodPropreturnSetthenTypeusingwherewithforall n, 0 <= nforall n : nat, 0 <= nforall i j k : nat, i <= j <= kforall (m n : nat) (b : bool), m <= n /\ b = truenat -> boolforall _ : nat, boolfun n => n + nfun n : nat => n + nfun i j k : nat => i + j + kfun (m n : nat) (b : bool) => (m - n, negb b)fix func n := match n with O => O | S n' => func n' endfix even n :=
match n with
| 0 => true
| S n' => negb (odd n')
end
with odd n :=
match n with
| 0 => true
| S n' => negb (even n')
end
for evenmatch 1 + 2 with O => true | S n => false endmatch le_n 0 as H in _ <= n return 0 < S n with … endif eq_nat_dec 1 2 then 3 else 4match eq_nat_dec 1 2 with left _ => 3 | right _ => 4 endlet z := 0 in z + zlet double z := 2 * z in double 3let fix func n := match n with O => O | S n' => func n' end in func 3let (a, b, c) := (1, 2, 3) in a + b + cmatch 1, 2, 3 with a, b, c => a + b + c endlet '((a, b), (c, d)) := ((1, 2), (3, 4)) in a + b + c + d(nat * nat)%typeplus 2 3ex (A := nat) (fun n => n = 0)@ ex nat (fun n => n = 0)Parameter P : Prop.Parameters i j k : nat.Axiom all_le_O_n : forall n : nat, 0 <= n.Conjecture all_le_O_n : forall n : nat, 0 <= n.Variable n : nat.Variables s t u : Set.Hypothesis H : n = 0.Hypotheses (H1 : n <= 3) (H2 : forall b : bool, b = true \/ b = false).宣言を行うキーワードは八つある。これらは言葉のニュアンスと宣言のスコープが違うだけで、他の点に違いはない。
Definition zero := 0.Definition zero : nat := 0.Definition negate : bool -> bool := fun b => if b then false else true.Definition negate (b : bool) : bool := if b then false else true.Definition negate b := if b then false else true.Example zero := 0.Let zero := 0.定義を行うキーワードは三つある。これらは言葉のニュアンスと宣言のスコープが違うだけで、他の点に違いはない。
Inductive nat : Set := O : nat | S : nat -> nat.Inductive nat : Set := O | S (_ : nat).Inductive list (A : Set) : Set := nil : list A | cons : A -> list A -> list A.Inductive even : nat -> Prop :=
| even_O : even O
| even_SS : forall n : nat, even n -> even (S (S n)).Inductive tree : Set :=
| node : nat -> forest -> tree
with forest : Set :=
| leaf : nat -> forest
| cons : tree -> forest -> forest.Fixpoint add m n := match m with O => n | S m' => S (add m' n) end.Fixpoint add (m n : nat) {struct m} : nat := match m with O => n | S m' => S (add m' n) end.Fixpoint tree_size (t : tree) :=
match t with node a f => S (forest_size f) end
with forest_size (f : forest) :=
match f with
| leaf b => 1
| cons t f' => (tree_size t + forest_size f')
end.不動点による定義では、{struct x} で再帰に伴い小さくなる引数を指定することができる。
CoInductive stream : Set := seq : nat -> stream -> stream.CoFixpoint from n := seq n (from (S n)).Record rational : Set := mkRat { n : nat; d : nat }.Record nonzero := { n : nat; H : n <> 0 }.レコードの定義では Record の代わりに Structure も使える。また Inductive/CoInductive を使うと(余)帰納的なレコードを定義できる。
レコードのフィールド名はレコードからそのフィールドを取り出す関数として使える: n (mkRat 1 2) = 1
Theorem all_le_O_n : forall n : nat, 0 <= n.Theorem even_odd_S : forall n, even n -> odd (S n) with odd_even_S : forall n, odd n -> even (S n). (証明に相互帰納法を使う場合)Goal forall n : nat, 0 <= n. (定理名を指定しない場合)Proof … Qed.Proof … Save.Proof … Defined.Proof … Admitted.Theorem の代わりに Lemma, Remark, Fact, Corollary, Proposition, Definition も使える (ニュアンスが違うだけで意味は同じ)。
Section Foo.End Foo.Print nat.Print Term nat.Print Section sect1.Print Assumptions theorem1.Print All.About nat.Inspect 3.Check (0 + 1 = 3 - 2).Eval cbv in (1 + 2). (→評価戦略)Extraction plus.Recursive Extraction plus.Search eq.Search eq inside Arith.Le.Search eq outside Arith.Le.SearchAbout plus.SearchAbout (?x * _ + ?x * _)%Z inside BinInt.SearchPattern (_ = _).SearchRewrite (_ + _).Locate eq.Locate "+".