Require Import Arith. Compute 1+1. Compute 1+2*3. (* This is a comment. *) Definition add (x:nat) (y:nat) : nat := x+y. Compute add 3 4. Compute (add 3 4). Compute add (1+2) (2+2). Check add. Definition hypotenuse (x:nat) (y:nat) : nat := let xsquared := x*x in let ysquared := y*y in xsquared + ysquared. Compute hypotenuse 3 4. (* Compute xsquared. <-- Error, out of scope *) Compute Nat.mul 3 4. Compute 3*4. Print "*". Compute 3 <=? 4. Compute true. Compute false. Compute 4 <=? 3. Compute leb 3 4. Compute leb 4 3. Print "<=?". Compute if (leb 3 4) then (add 1 2) else (add 5 6). Compute andb true false. Compute orb false false. Open Scope bool_scope. Compute true && false. Compute false || false. (* Require Import String. Open Scope string_scope. Compute "foo". Compute "foo" ++ "bar". Compute (true,3). Compute (("hello",3),false). Compute ("hello",3,false). Compute ("hello",(3,false)). Compute fst (true,3). Compute fst ("hello",3,false). Compute snd (true,3). Compute snd (fst ("hello",3,false)). *) Inductive color : Type := | Red : color | Blue : color | Dark (c:color) : color | Light (c:color) : color. Compute Red. Compute Dark Blue. Compute Dark (Dark Blue). Compute Dark (Light Red). Compute Dark (Dark (Dark (Light Blue))). Definition isdark (c:color) : bool := match c with | Dark _ => true | _ => false end. Compute isdark Red. Compute isdark (Dark Red). Compute isdark (Dark (Dark (Light Blue))). Fixpoint isred (c:color) : bool := match c with | Red => true | Blue => false | Dark x => isred x | Light x => isred x end. Compute isred (Dark (Light (Dark (Dark Red)))). Compute isred (Dark (Light (Dark (Dark Blue)))). (* Fixpoint factorial (n:nat) : nat := if n <=? 1 then 1 else n*(factorial (n-1)). *) Print nat. Fixpoint factorial (n:nat) : nat := match n with | O => 1 | S m => n * factorial m end. Print "-".