Add a real example. Fix bug in the parser

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-08-31 19:30:42 -07:00
parent 51640ecff8
commit e54338f4a8
3 changed files with 40 additions and 1 deletions

37
examples/ex1.lean Normal file
View file

@ -0,0 +1,37 @@
Variable N : Type
Variable h : N -> N -> N
(* Specialize congruence theorem for h-applications *)
Theorem CongrH {a1 a2 b1 b2 : N} (H1 : a1 = b1) (H2 : a2 = b2) : (h a1 a2) = (h b1 b2) :=
Congr (Congr (Refl h) H1) H2
(* Declare some variables *)
Variable a : N
Variable b : N
Variable c : N
Variable d : N
Variable e : N
(* Add axioms stating facts about these variables *)
Axiom H1 : (a = b ∧ b = c) (a = d ∧ d = c)
Axiom H2 : b = e
(* Proof that (h a b) = (h c e) *)
Theorem T1 : (h a b) = (h c e) :=
DisjCases H1
(fun C1 : _,
CongrH (Trans (Conjunct1 C1) (Conjunct2 C1)) H2)
(fun C2 : _,
CongrH (Trans (Conjunct1 C2) (Conjunct2 C2)) H2)
(* We can use theorem T1 to prove other theorems *)
Theorem T2 : (h a (h a b)) = (h a (h c e)) :=
CongrH (Refl a) T1
(* Display the last two objects (i.e., theorems) added to the environment *)
Show Environment 2
(* Show implicit arguments *)
Set lean::pp::implicit true
Set pp::width 150
Show Environment 2

View file

@ -1282,11 +1282,13 @@ class parser::imp {
m_frontend.set_option(id, false);
else
throw parser_error("invalid Boolean option value, 'true' or 'false' expected", pos());
next();
break;
case scanner::token::StringVal:
if (k != StringOption)
throw parser_error("invalid option value, given option is not a string", pos());
m_frontend.set_option(id, curr_string());
next();
break;
case scanner::token::IntVal:
if (k != IntOption && k != UnsignedOption)
@ -1304,7 +1306,6 @@ class parser::imp {
updt_options();
if (m_verbose)
regular(m_frontend) << " Set option: " << id << endl;
next();
}
void parse_import() {

View file

@ -2,6 +2,7 @@ configure_file("${LEAN_SOURCE_DIR}/shell/version.h.in" "${LEAN_BINARY_DIR}/versi
include_directories("${LEAN_BINARY_DIR}")
add_executable(lean lean.cpp)
target_link_libraries(lean ${EXTRA_LIBS})
add_test(example1 ${CMAKE_CURRENT_BINARY_DIR}/lean "${LEAN_SOURCE_DIR}/../examples/ex1.lean")
add_test(NAME leantests
WORKING_DIRECTORY "${LEAN_SOURCE_DIR}/../tests/lean"
COMMAND "./test.sh" "${CMAKE_CURRENT_BINARY_DIR}/lean")