Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added theorem keyword #1263

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/haz3lcore/dynamics/Elaborator.re
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ let rec dhexp_of_uexp =
| Test(test) =>
let+ dtest = dhexp_of_uexp(m, test);
DHExp.Test(id, dtest);
| Theorem(_) => Some(DHExp.Tuple([]))
| Filter(act, cond, body) =>
let* dcond = dhexp_of_uexp(~in_filter=true, m, cond);
let+ dbody = dhexp_of_uexp(m, body);
Expand Down
3 changes: 3 additions & 0 deletions src/haz3lcore/lang/Form.re
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ let keywords = [
"type",
"case",
"test",
"theorem",
"if",
"then",
"else",
Expand Down Expand Up @@ -300,6 +301,7 @@ let forms: list((string, t)) = [
("ap_typ", mk(ii, ["(", ")"], mk_post(P.ap, Typ, [Typ]))),
("case", mk(ds, ["case", "end"], mk_op(Exp, [Rul]))),
("test", mk(ds, ["test", "end"], mk_op(Exp, [Exp]))),
("theorem", mk(ds, ["theorem", "end"], mk_op(Exp, [Exp]))),
("fun_", mk(ds, ["fun", "->"], mk_pre(P.fun_, Exp, [Pat]))),
(
"rule",
Expand Down Expand Up @@ -328,6 +330,7 @@ let delims: list(Token.t) =
|> List.fold_left((acc, (_, {label, _}: t)) => {label @ acc}, [])
|> List.sort_uniq(compare);

// TODO(nishant): do I need to handle theorem here too?
let atomic_molds: Token.t => list(Mold.t) =
s =>
List.fold_left(
Expand Down
1 change: 1 addition & 0 deletions src/haz3lcore/statics/MakeTerm.re
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ and exp_term: unsorted => (UExp.term, list(Id.t)) = {
| term => ret(ListLit([term]))
}
| (["test", "end"], [Exp(test)]) => ret(Test(test))
| (["theorem", "end"], [Exp(theorem)]) => ret(Theorem(theorem))
| (["case", "end"], [Rul({ids, term: Rules(scrut, rules)})]) => (
Match(scrut, rules),
ids,
Expand Down
4 changes: 4 additions & 0 deletions src/haz3lcore/statics/Statics.re
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ and uexp_to_info_map =
| Test(e) =>
let (e, m) = go(~mode=Ana(Bool), e, m);
add(~self=Just(Prod([])), ~co_ctx=e.co_ctx, m);
// TODO(nishant): add code for Theorem here
| Theorem(e) =>
let (e, m) = go(~mode=Syn, e, m);
add(~self=Just(Prod([])), ~co_ctx=e.co_ctx, m);
| Filter(_, cond, body) =>
let (cond, m) = go(~mode, cond, m, ~is_in_filter=true);
let (body, m) = go(~mode, body, m);
Expand Down
11 changes: 8 additions & 3 deletions src/haz3lcore/statics/Term.re
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ module UExp = {
| UnOp(op_un)
| BinOp(op_bin)
| Match
| ListConcat;
| ListConcat
| Theorem;

let hole = (tms: list(any)): term =>
switch (tms) {
Expand Down Expand Up @@ -488,7 +489,8 @@ module UExp = {
| ListConcat(_) => ListConcat
| UnOp(op, _) => UnOp(op)
| BinOp(op, _, _) => BinOp(op)
| Match(_) => Match;
| Match(_) => Match
| Theorem(_) => Theorem;

let show_op_un_meta: op_un_meta => string =
fun
Expand Down Expand Up @@ -582,7 +584,8 @@ module UExp = {
| ListConcat => "List Concatenation"
| BinOp(op) => show_binop(op)
| UnOp(op) => show_unop(op)
| Match => "Case expression";
| Match => "Case expression"
| Theorem => "Theorem";

let rec is_fun = (e: t) => {
switch (e.term) {
Expand Down Expand Up @@ -612,6 +615,7 @@ module UExp = {
| UnOp(_)
| BinOp(_)
| Match(_)
| Theorem(_)
| Constructor(_) => false
};
};
Expand Down Expand Up @@ -646,6 +650,7 @@ module UExp = {
| UnOp(_)
| BinOp(_)
| Match(_)
| Theorem(_)
| Constructor(_) => false
}
);
Expand Down
4 changes: 4 additions & 0 deletions src/haz3lcore/statics/TermBase.re
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ and UExp: {
| If
| Seq
| Test
| Theorem
| Filter
| Parens
| Cons
Expand Down Expand Up @@ -152,6 +153,7 @@ and UExp: {
| If(t, t, t)
| Seq(t, t)
| Test(t)
| Theorem(t)
| Filter(FilterAction.t, t, t)
| Parens(t) // (
| Cons(t, t)
Expand Down Expand Up @@ -253,6 +255,7 @@ and UExp: {
| If
| Seq
| Test
| Theorem
| Filter
| Parens
| Cons
Expand Down Expand Up @@ -283,6 +286,7 @@ and UExp: {
| If(t, t, t)
| Seq(t, t)
| Test(t)
| Theorem(t)
| Filter(FilterAction.t, t, t)
| Parens(t) // (
| Cons(t, t)
Expand Down
1 change: 1 addition & 0 deletions src/haz3lcore/zipper/EditorUtil.re
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ let rec append_exp = (e1: TermBase.UExp.t, e2: TermBase.UExp.t) => {
| Pipeline(_)
| If(_)
| Test(_)
| Theorem(_)
| Parens(_)
| Cons(_)
| ListConcat(_)
Expand Down
4 changes: 4 additions & 0 deletions src/haz3lschool/SyntaxTest.re
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ let rec var_mention = (name: string, uexp: Term.UExp.t): bool => {
find_var_upat(name, p)
? false : var_mention(name, def) || var_mention(name, body)
| Test(u)
| Theorem(u)
| Parens(u)
| UnOp(_, u)
| TyAlias(_, _, u)
Expand Down Expand Up @@ -97,6 +98,7 @@ let rec var_applied = (name: string, uexp: Term.UExp.t): bool => {
find_var_upat(name, p)
? false : var_applied(name, def) || var_applied(name, body)
| Test(u)
| Theorem(u)
| Parens(u)
| UnOp(_, u)
| TyAlias(_, _, u)
Expand Down Expand Up @@ -189,6 +191,7 @@ let rec find_fn =
| UnOp(_, u1)
| TyAlias(_, _, u1)
| Test(u1)
| Theorem(u1)
| Filter(_, _, u1) => l |> find_fn(name, u1)
| Ap(u1, u2)
| Pipeline(u1, u2)
Expand Down Expand Up @@ -252,6 +255,7 @@ let rec tail_check = (name: string, uexp: Term.UExp.t): bool => {
//If l has no recursive calls then true
!List.fold_left((acc, ue) => {acc || var_mention(name, ue)}, false, l)
| Test(_) => false
| Theorem(_) => false
| TyAlias(_, _, u)
| Filter(_, _, u)
| Parens(u) => tail_check(name, u)
Expand Down
17 changes: 17 additions & 0 deletions src/haz3lweb/view/ExplainThis.re
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,23 @@ let get_doc =
),
TestExp.tests,
);
// TODO(nishant): add explanation for Theorem(body) here in the style of Test above
| Theorem(body) =>
let body_id = List.nth(body.ids, 0);
get_message(
// TODO: add coloring for theorem
~colorings=TestExp.test_exp_coloring_ids(~body_id),
~format=
Some(
msg =>
Printf.sprintf(
Scanf.format_from_string(msg, "%s"),
Id.to_string(body_id),
),
),
// TODO change below to Theorem equivalent
TestExp.tests,
);
| Parens(term) => get_message_exp(term.term) // No Special message?
| Cons(hd, tl) =>
let hd_id = List.nth(hd.ids, 0);
Expand Down
Loading