feat(frontends/lean): use '(* ... *)' instead of '(** ... **)' for script code blocks

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-01-05 10:32:47 -08:00
parent 028a9bd9bd
commit ce1213a020
62 changed files with 141 additions and 162 deletions

View file

@ -1,7 +1,7 @@
-- This example demonstrates how to specify a proof skeleton that contains
-- "holes" that must be filled using user-defined tactics.
(**
(*
-- Import useful macros for creating tactics
import("tactic.lua")
@ -10,7 +10,7 @@ auto = Repeat(OrElse(assumption_tac(), conj_tac(), conj_hyp_tac()))
conj_hyp = conj_hyp_tac()
conj = conj_tac()
**)
*)
-- The (by [tactic]) expression is essentially creating a "hole" and associating a "hint" to it.
-- The "hint" is a tactic that should be used to fill the "hole".

View file

@ -1,4 +1,4 @@
(**
(*
-- This example demonstrates how to create a new tactic using Lua.
-- The basic idea is to reimplement the tactic conj_tactic in Lua.
@ -62,10 +62,10 @@
end
conj_in_lua = tactic(conj_fn) -- Create a new tactic object using the Lua function conj_fn
-- Now, the tactic conj_in_lua can be used when proving theorems in Lean.
**)
*)
Theorem T (a b : Bool) : a => b => a /\ b := _.
(** Then(Repeat(OrElse(imp_tac(), conj_in_lua)), assumption_tac()) **)
(* Then(Repeat(OrElse(imp_tac(), conj_in_lua)), assumption_tac()) *)
done
-- Show proof created using our script

View file

@ -380,23 +380,11 @@ scanner::token scanner::read_script_block() {
next();
if (c1 == '*') {
char c2 = curr();
next();
if (c2 == EOF)
throw_exception("unexpected end of script");
next();
if (c2 == '*') {
char c3 = curr();
if (c3 == EOF)
throw_exception("unexpected end of script");
next();
if (c3 == ')') {
return token::ScriptBlock;
} else {
if (c3 == '\n')
new_line();
m_buffer += c1;
m_buffer += c2;
m_buffer += c3;
}
if (c2 == ')') {
return token::ScriptBlock;
} else {
if (c2 == '\n')
new_line();
@ -441,13 +429,7 @@ scanner::token scanner::scan() {
next();
if (curr() == '*') {
next();
if (curr() == '*') {
next();
return read_script_block();
} else {
throw_exception("old comment style");
break;
}
return read_script_block();
} else {
return token::LeftParen;
}

View file

@ -11,9 +11,9 @@ Theorem T1 (a : Int) : (P a a) => (f a a).
done.
Variable b : Int
Axiom Ax2 (x : Int) : (f x b)
(**
(*
simple_tac = Repeat(OrElse(imp_tac(), assumption_tac(), apply_tac("Ax2"), apply_tac("Ax1")))
**)
*)
Theorem T2 (a : Int) : (P a a) => (f a a).
simple_tac.
done.

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Check @Discharge
Theorem T (a b : Bool) : a => b => b => a.
apply Discharge.

View file

@ -2,17 +2,17 @@ Import tactic
Theorem T1 (a b : Bool) : a \/ b => b \/ a.
apply Discharge.
(** disj_hyp_tac() **)
(** disj_tac() **)
(* disj_hyp_tac() *)
(* disj_tac() *)
back
exact.
(** disj_tac() **)
(* disj_tac() *)
exact.
done.
(**
(*
simple_tac = Repeat(OrElse(imp_tac(), assumption_tac(), disj_hyp_tac(), disj_tac())) .. now_tac()
**)
*)
Theorem T2 (a b : Bool) : a \/ b => b \/ a.
simple_tac.

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Variables a b c : Bool
Axiom H : a \/ b
Theorem T (a b : Bool) : a \/ b => b \/ a.

View file

@ -1,4 +1,4 @@
(** import("find.lua") **)
(* import("find.lua") *)
Find "^.ongr"
Find "foo"
Find "(ab"

View file

@ -1,9 +1,9 @@
(**
(*
-- The elaborator does not expand definitions marked as 'opaque'.
-- To be able to prove the following theorem, we have to unmark the
-- 'forall'
local env = get_environment()
env:set_opaque("forall", false)
**)
*)
Theorem ForallIntro2 (A : (Type U)) (P : A -> Bool) (H : Pi x, P x) : forall x, P x :=
Abst (fun x, EqTIntro (H x))

View file

@ -1,12 +1,12 @@
Theorem T2 (a b : Bool) : a => b => a /\ b.
done.
done.
(** imp_tac() **).
(* imp_tac() *).
imp_tac2.
foo.
(** imp_tac() **).
(** imp_tac() **).
(** conj_tac() **).
(* imp_tac() *).
(* imp_tac() *).
(* conj_tac() *).
back.
(** assumption_tac() **).
(* assumption_tac() *).
done.

View file

@ -1,6 +1,6 @@
(**
(*
simple_tac = Repeat(OrElse(conj_hyp_tac(), conj_tac(), assumption_tac()))
**)
*)
Theorem T2 (A B : Bool) : A /\ B => B /\ A :=
Discharge (fun H : A /\ B,

View file

@ -1,6 +1,6 @@
(**
(*
auto = Repeat(OrElse(conj_hyp_tac(), conj_tac(), assumption_tac()))
**)
*)
Theorem T2 (A B : Bool) : A /\ B -> B /\ A :=
fun assumption : A /\ B,

View file

@ -1,8 +1,8 @@
(**
(*
import("tactic.lua")
-- Define a simple tactic using Lua
auto = Repeat(OrElse(assumption_tac(), conj_tac(), conj_hyp_tac()))
**)
*)
Theorem T1 (A B : Bool) : A /\ B -> B /\ A :=
fun assumption : A /\ B,

View file

@ -1,7 +1,7 @@
(**
(*
-- Define a simple tactic using Lua
auto = Repeat(OrElse(assumption_tac(), conj_tac(), conj_hyp_tac()))
**)
*)
Theorem T1 (A B : Bool) : A /\ B -> B /\ A :=
fun assumption : A /\ B,

View file

@ -1,8 +1,8 @@
Theorem T2 (a b : Bool) : a => b => a /\ b.
(** imp_tac() **)
(** imp_tac2() **)
(* imp_tac() *)
(* imp_tac2() *)
foo.
(** imp_tac() **)
(* imp_tac() *)
abort.
Variables a b : Bool.

View file

@ -1,8 +1,8 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Theorem T2 (a b : Bool) : b => a \/ b.
(** imp_tac() **).
(** disj_tac() **).
(* imp_tac() *).
(* disj_tac() *).
back.
back.
exact.

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Axiom magic (a : Bool) : a.
Theorem T (a : Bool) : a.

View file

@ -1,7 +1,7 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Theorem T1 (a b : Bool) : a => b => a /\ b.
(** imp_tac() **).
(** imp_tac() **).
(* imp_tac() *).
(* imp_tac() *).
apply Conj.
exact.
done.

View file

@ -1,11 +1,11 @@
Import Int.
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Variable q : Int -> Int -> Bool.
Variable p : Int -> Bool.
Axiom Ax (a b : Int) (H : q a b) : p b.
Variable a : Int.
Theorem T (x : Int) : (q a x) => (p x).
(** imp_tac() **).
(* imp_tac() *).
apply (Ax a).
exact.
done.

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
SetOption tactic::proof_state::goal_names true.
Theorem T (a : Bool) : a => a /\ a.
apply Discharge.

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Theorem T1 (A B : Bool) : A /\ B => B /\ A :=
Discharge (fun H : A /\ B,
let main : B /\ A :=
@ -16,9 +16,9 @@ Theorem T1 (A B : Bool) : A /\ B => B /\ A :=
exact.
done.
(**
(*
simple_tac = Repeat(OrElse(conj_hyp_tac(), conj_tac(), assumption_tac()))
**)
*)
Theorem T2 (A B : Bool) : A /\ B => B /\ A :=
Discharge (fun H : A /\ B,

View file

@ -1,11 +1,11 @@
(**
(*
-- This example ask uses the parses to process a Lean string that
-- contains a nested script block. The nexted script block will
-- invoke the leanlua_state recursively. It also demonstrates that we
-- need to use std::recursive_mutex instead of std::mutex at
-- leanlua_state. Otherwise, it will deadlock trying to get a lock on
-- the mutex.
code = "(*" .. "*" .. "print('hello')" .. "*" .. "*)"
code = "(" .. "*" .. "print('hello')" .. "*" .. ")"
print("executing: " .. code)
parse_lean_cmds(code)
**)
*)

View file

@ -1,4 +1,4 @@
Set: pp::colors
Set: pp::unicode
executing: (**print('hello')**)
executing: (*print('hello')*)
hello

View file

@ -1,8 +1,8 @@
Import Int.
(**
(*
function add_paren(code)
return "(" .. "** " .. code .. " **" .. ")"
return "(" .. "* " .. code .. " *" .. ")"
end
parse_lean_cmds(add_paren([[
local env = get_environment()
@ -10,4 +10,4 @@ Import Int.
print(env:find_object("x"))
]]))
print("done")
**)
*)

View file

@ -1,8 +1,8 @@
Import Int.
Variable x : Int
(**
(*
print("hello world from Lua")
**)
*)
Variable y : Int

View file

@ -1,8 +1,7 @@
Variables x1 x2 x3 : Bool
Definition F : Bool := x1 /\ (x2 \/ x3)
(**
(*
local env = get_environment()
local F = env:find_object("F"):get_value()
print(F)
@ -15,5 +14,4 @@ Definition F : Bool := x1 /\ (x2 \/ x3)
print(expr_size(F))
**)
*)

View file

@ -1,5 +1,5 @@
Import Int.
(**
(*
local env = get_environment()
local o1 = env:find_object(name("Int", "add"))
@ -49,4 +49,4 @@ Import Int.
assert(env:find_object("Refl"):is_axiom())
assert(env:find_object(name("Int", "sub")):is_definition())
assert(env:find_object("x"):is_var_decl())
**)
*)

View file

@ -1,7 +1,7 @@
Import Int.
Variables x y z : Int
(**
(*
import("util.lua")
local env = get_environment()
local plus = Const{"Int", "add"}
@ -9,6 +9,6 @@ Variables x y z : Int
local def = plus(plus(x, y), iVal(1000))
print(def, ":", env:type_check(def))
env:add_definition("sum", def)
**)
*)
Eval sum + 3

View file

@ -2,7 +2,7 @@ Import Int.
Variables x y z : Int
Variable f : Int -> Int -> Int
(**
(*
local t = parse_lean("fun w, f w (f y 0)")
print(t)
assert(t:closed())
@ -11,4 +11,4 @@ Variable f : Int -> Int -> Int
assert(not b:closed())
local env = get_environment()
assert(env:find_object("Int"):get_name() == name("Int"))
**)
*)

View file

@ -2,7 +2,7 @@ Import Int.
Variables x y z : Int
Variable f : Int -> Int -> Int
(**
(*
local t = parse_lean("fun w, f w (f y 0)")
print(t)
assert(t:closed())
@ -17,6 +17,6 @@ Variable f : Int -> Int -> Int
Variable g : Int -> Int
]])
**)
*)
Check g (f x 10)

View file

@ -2,7 +2,7 @@ Import Int.
Variables i j : Int
Variable p : Bool
(**
(*
local env = get_environment()
ok, ex = pcall(
function()
@ -12,4 +12,4 @@ Variable p : Bool
assert(is_exception(ex))
print(ex:what())
ex:rethrow()
**)
*)

View file

@ -1,8 +1,8 @@
Import Int.
Variables a b : Int
(**
(*
local ios = io_state()
ios:print(parse_lean("a + b"))
print(parse_lean("a + b"))
**)
*)

View file

@ -1,7 +1,7 @@
Import Int.
Variables a b : Int
Show Options
(**
(*
local ios = io_state()
print(get_options())
@ -9,6 +9,6 @@ Show Options
ios:print(parse_lean("a + b"))
print(parse_lean("fun x, a + x"))
print(get_options())
**)
*)
Show Options
Show Environment 2

View file

@ -1,5 +1,5 @@
Import Int.
(**
(*
macro("MyMacro", { macro_arg.Expr, macro_arg.Comma, macro_arg.Expr },
function (env, e1, e2)
return Const({"Int", "add"})(e1, e2)
@ -16,7 +16,7 @@ macro("Sum", { macro_arg.Exprs },
end
return r
end)
**)
*)
Show (MyMacro 10, 20) + 20
Show (Sum)

View file

@ -1,6 +1,6 @@
Variable x : Bool
(**
(*
a = {}
print("hello world")
print ("ok")
@ -9,7 +9,6 @@ Variable x : Bool
y = 20
}
rint ("ok")
**)
*)
Variable y : Bool

View file

@ -1,6 +1,6 @@
Import Int.
Variable x : Int
(**
(*
dofile("script.lua")
**)
*)

View file

@ -1,7 +1,7 @@
Import Int.
Variable x : Int
(**
(*
-- Add a variable to the environment using Lua
-- The type of the new variable is equal to the type
-- of x
@ -9,6 +9,6 @@ local env = get_environment()
typeofx = env:type_check(Const("x"))
print("type of x is " .. tostring(typeofx))
env:add_var("y", typeofx)
**)
*)
Check x + y

View file

@ -1,7 +1,7 @@
Import Int.
Variable x : Int
(**
(*
local N = 100
local env = get_environment()
-- Create N variables with the same type of x
@ -9,7 +9,7 @@ typeofx = env:type_check(Const("x"))
for i = 1, N do
env:add_var("y_" .. i, typeofx)
end
**)
*)
Show Environment 101
Check x + y_1 + y_2

View file

@ -1,20 +1,20 @@
Import Int.
Variable x : Int
SetOption pp::notation false
(**
(*
print(get_options())
**)
*)
Check x + 2
(**
(*
o = get_options()
o = o:update(name('lean', 'pp', 'notation'), true)
set_options(o)
print(get_options())
**)
*)
Check x + 2
(**
(*
set_option(name('lean', 'pp', 'notation'), false)
print(get_options())
**)
*)
Variable y : Int
Check x + y

View file

@ -1,6 +1,6 @@
(**
(*
x = Const("x")
y = Const("y")
N = Const("N")
print(fun({{x, N}, {y, N}}, x))
**)
*)

View file

@ -1,7 +1,7 @@
Import Int.
Variable x : Int
(**
(*
local env = get_environment()
ty_x = env:type_check(Const("x"))
c = context()
@ -12,4 +12,4 @@ o = env:find_object("x")
print(o)
o = env:find_object("y")
print(o)
**)
*)

View file

@ -1,7 +1,7 @@
Import Int.
Variable x : Bool
(**
(*
import("util.lua")
local env = get_environment()
local Int = Const("Int")
@ -31,7 +31,7 @@ Variable x : Bool
print(s)
print(env:type_check(s))
env:add_definition("sum1", s)
**)
*)
Show Environment 1
Eval sum1

View file

@ -1,11 +1,11 @@
Import cast
Import cast
(**
(*
local env = environment() -- create new environment
parse_lean_cmds([[
Import cast
Import cast
Check @cast
]], env)
**)
*)
Check @cast

View file

@ -1,4 +1,4 @@
(**
(*
cmd_macro("Simple",
{ macro_arg.String },
function (env, str)
@ -9,12 +9,12 @@ cmd_macro("Simple",
parse_lean_cmds([[
Simple "foo"
]])
**)
*)
Simple "testing"
(**
(*
parse_lean_cmds([[
Simple "bla"
]])
**)
*)

View file

@ -10,4 +10,4 @@ Definition D := read V1 1 (by trivial)
Show Environment 1
Variable b : Bool
Definition a := b
Theorem T : b => a := (by (** imp_tac() .. normalize_tac() .. assumption_tac() **))
Theorem T : b => a := (by (* imp_tac() .. normalize_tac() .. assumption_tac() *))

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Theorem T (C A B : Bool) : C -> A -> B -> A.
exact.
done.

View file

@ -2,7 +2,7 @@ Import Int.
Definition double {A : Type} (f : A -> A) : A -> A := fun x, f (f x).
Definition big {A : Type} (f : A -> A) : A -> A := (double (double (double (double (double (double (double f))))))).
(**
(*
-- Tactic for trying to prove goal using Reflexivity, Congruence and available assumptions
local congr_tac = Repeat(OrElse(apply_tac("Refl"), apply_tac("Congr"), assumption_tac()))
@ -18,7 +18,7 @@ eager_tac = Then(-- unfold homogeneous equality
lazy_tac = OrElse(Then(Try(unfold_tac("eq")), congr_tac, now_tac()),
eager_tac)
**)
*)
Theorem T1 (a b : Int) (f : Int -> Int) (H : a = b) : (big f a) = (big f b).
eager_tac.

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Theorem T (A : Type) (p : A -> Bool) (f : A -> A -> A) : forall x y z, p (f x x) => x = y => x = z => p (f y z).
apply ForallIntro.
beta.

View file

@ -1,4 +1,4 @@
(** import("macros.lua") **)
(* import("macros.lua") *)
Theorem T (A : Type) (p : A -> Bool) (f : A -> A -> A) : forall x y z, p (f x x) => x = y => x = z => p (f y z) :=
For x y z, Assume (H1 : p (f x x)) (H2 : x = y) (H3 : x = z),

View file

@ -1,11 +1,11 @@
Variables p q r : Bool
(**
(*
local env = get_environment()
local conjecture = parse_lean('p => q => p && q')
local tac = Repeat(conj_tac() ^ imp_tac() ^ assumption_tac())
local proof = tac:solve(env, context(), conjecture)
env:add_theorem("T1", conjecture, proof)
**)
*)
Show Environment 1.

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Definition f(a : Bool) : Bool := not a.
Definition g(a b : Bool) : Bool := a \/ b.
@ -11,9 +11,9 @@ Theorem T1 (a b : Bool) : (g a b) => (f b) => a := _.
absurd
done.
(**
(*
simple_tac = Repeat(unfold_tac()) .. Repeat(OrElse(imp_tac(), conj_hyp_tac(), assumption_tac(), absurd_tac(), conj_hyp_tac(), disj_hyp_tac()))
**)
*)
Definition h(a b : Bool) : Bool := g a b.

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Theorem T (a b : Bool) : ((fun x, x /\ b) a) => ((fun x, x) a) := _ .
beta.
apply Discharge.

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Theorem T (a b : Bool) : ((fun x, x /\ b) a) => ((fun x, x) a).
beta.
apply Discharge.

View file

@ -1,15 +1,15 @@
Import Int.
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Variable f : Int -> Int -> Int
(**
(*
refl_tac = apply_tac("Refl")
congr_tac = apply_tac("Congr")
symm_tac = apply_tac("Symm")
trans_tac = apply_tac("Trans")
unfold_homo_eq_tac = unfold_tac("eq")
auto = unfold_homo_eq_tac .. Repeat(OrElse(refl_tac, congr_tac, assumption_tac(), Then(symm_tac, assumption_tac(), now_tac())))
**)
*)
Theorem T1 (a b c : Int) (H1 : a = b) (H2 : a = c) : (f (f a a) b) = (f (f b c) a).
auto.

View file

@ -1,10 +1,10 @@
Import Int.
(**
(*
-- Tactic for trying to prove goal using Reflexivity, Congruence and available assumptions
congr_tac = Try(unfold_tac("eq")) .. Repeat(OrElse(apply_tac("Refl"), apply_tac("Congr"), assumption_tac()))
**)
*)
Theorem T1 (a b : Int) (f : Int -> Int) : a = b -> (f (f a)) = (f (f b)) :=
fun assumption : a = b,

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Variables p q r : Bool
Theorem T1 : p => q => p /\ q :=
@ -13,9 +13,9 @@ Theorem T1 : p => q => p /\ q :=
exact -- solve second metavar
done
(**
(*
simple_tac = Repeat(imp_tac() ^ conj_tac() ^ assumption_tac())
**)
*)
Theorem T2 : p => q => p /\ q /\ p := _.
simple_tac
@ -24,7 +24,7 @@ Theorem T2 : p => q => p /\ q /\ p := _.
Show Environment 1
Theorem T3 : p => p /\ q => r => q /\ r /\ p := _.
(** Repeat(OrElse(imp_tac(), conj_tac(), conj_hyp_tac(), assumption_tac())) **)
(* Repeat(OrElse(imp_tac(), conj_tac(), conj_hyp_tac(), assumption_tac())) *)
done
-- Display proof term generated by previous tac

View file

@ -1,8 +1,8 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Variables p q r : Bool
Theorem T1 : p => p /\ q => r => q /\ r /\ p := _.
(** Repeat(OrElse(imp_tac(), conj_tac(), conj_hyp_tac(), assumption_tac())) **)
(* Repeat(OrElse(imp_tac(), conj_tac(), conj_hyp_tac(), assumption_tac())) *)
done
-- Display proof term generated by previous tactic

View file

@ -1,6 +1,6 @@
(**
(*
simple_tac = Repeat(OrElse(imp_tac(), conj_tac())) .. assumption_tac()
**)
*)
Theorem T4 (a b : Bool) : a => b => a /\ b := _.
simple_tac

View file

@ -1,6 +1,6 @@
(**
(*
simple_tac = Repeat(OrElse(imp_tac(), conj_tac())) .. assumption_tac()
**)
*)
Theorem T4 (a b : Bool) : a => b => a /\ b /\ a := _.
simple_tac

View file

@ -1,10 +1,10 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Theorem T (a b c : Bool): a => b /\ c => c /\ a /\ b := _.
apply Discharge
apply Discharge
conj_hyp
apply Conj
(** Focus(Then(show_tac(), conj_tac(), show_tac(), assumption_tac()), 2) **)
(* Focus(Then(show_tac(), conj_tac(), show_tac(), assumption_tac()), 2) *)
exact
done
@ -13,10 +13,10 @@ Theorem T2 (a b c : Bool): a => b /\ c => c /\ a /\ b := _.
apply Discharge
conj_hyp
apply Conj
(** show_tac() **)
(** Focus(Then(show_tac(), conj_tac(), Focus(assumption_tac(), 1)), 2) **)
(** show_tac() **)
(** Focus(assumption_tac(), 1) **)
(** show_tac() **)
(** Focus(assumption_tac(), 1) **)
(* show_tac() *)
(* Focus(Then(show_tac(), conj_tac(), Focus(assumption_tac(), 1)), 2) *)
(* show_tac() *)
(* Focus(assumption_tac(), 1) *)
(* show_tac() *)
(* Focus(assumption_tac(), 1) *)
done

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Theorem T (a b : Bool) : a \/ b => (not b) => a := _.
apply Discharge
apply Discharge

View file

@ -1,4 +1,4 @@
(** import("tactic.lua") **)
(* import("tactic.lua") *)
Definition f(a : Bool) : Bool := not a.
Theorem T (a b : Bool) : a \/ b => (f b) => a := _.