"
-| (atom.compound_procedure _ args body) := "(λ (" ++ string.intercalate " " args ++ ") " ++ (atom.repr body) ++ ")"
-| (atom.symbol sym) := sym
-| (atom.list lst) := "(" ++ string.intercalate " " (list.map atom.repr lst) ++ ")"
-| (atom.cell car cdr) := "(" ++ atom.repr car ++ " . " ++ atom.repr cdr ++ ")"
-meta instance : has_repr atom := ⟨atom.repr⟩
-#+END_SRC
-
-The parser is fairly simple, too, but we have to deal with mutual recursion.
-
-#+BEGIN_SRC lean
-meta def parse_until_rparen : ℤ → list token → option (list token × list token)
-| 0 (list.cons (token.rparen) rest) := some ([], rest)
-| n (list.cons (token.rparen) rest) :=
- match parse_until_rparen (n - 1) rest with
- | none := none
- | some result := some (list.cons token.rparen result.fst, result.snd)
- end
-| n (list.cons (token.lparen) rest) :=
- match parse_until_rparen (n + 1) rest with
- | none := none
- | some result := (list.cons token.lparen result.fst, result.snd)
- end
-| n (list.cons tok rest) :=
- match parse_until_rparen n rest with
- | none := none
- | some result := some (list.cons tok result.fst, result.snd)
- end
-| n (list.nil) := none
-
-meta mutual def parse_one, parse
-with parse_one : list token → option (atom × list token)
-| (list.cons token.lparen rest) :=
- match parse_until_rparen 0 rest with
- | none := none
- | some result := some (atom.list (parse result.fst), result.snd)
- end
-| (list.cons token.quot rest) :=
- match parse_one rest with
- | none := none
- | some result := some (atom.list [(atom.symbol "quote"), result.fst], result.snd)
- end
-| (list.cons (token.numeral n) rest) := some (atom.number n, rest)
-| (list.cons (token.symbol "#t") rest) := some (atom.boolean tt, rest)
-| (list.cons (token.symbol "#f") rest) := some (atom.boolean ff, rest)
-| (list.cons (token.symbol sym) rest) := some (atom.symbol sym, rest)
-| _ := none
-with parse : list token → list atom
-| (list.nil) := []
-| stream := match parse_one stream with
-| none := []
-| some (result, (list.nil)) := [result]
-| some (result, rest) := (list.cons result (parse rest))
-end
-
-#eval list.map atom.repr (parse (tokenize "(+ 2 4)"))
-#eval list.map atom.repr (parse (tokenize "(define (list-of-values exps env)
- (if (no-operands? exps)
- '()
- (cons (eval (first-operand exps) env)
- (list-of-values (rest-operands exps) env))))"))
-#+END_SRC
-
-The evaluator has a notion of errors, whereas the language semantics doesn't, so we'll introduce a type for that as well.
-
-#+BEGIN_SRC lean
-inductive lisp_error : Type
-| expected_number : lisp_error
-| expected_symbol : lisp_error
-| expected_list : lisp_error
-| no_such_variable : string → lisp_error
-| bad_lambda : lisp_error
-| bad_begin : lisp_error
-| bad_if : lisp_error
-| bad_define : lisp_error
-| bad_arity : lisp_error
-| excessive_recursion : lisp_error
-| unknown_form : lisp_error
-
-def lisp_error.repr : lisp_error → string
-| (lisp_error.expected_number) := "Expected number"
-| (lisp_error.expected_symbol) := "Expected symbol"
-| (lisp_error.expected_list) := "Expected list"
-| (lisp_error.no_such_variable sym) := "No such variable: " ++ sym
-| (lisp_error.bad_lambda) := "Bad lambda form"
-| (lisp_error.bad_begin) := "Bad begin form"
-| (lisp_error.bad_if) := "Bad if form"
-| (lisp_error.bad_define) := "Bad define form"
-| (lisp_error.bad_arity) := "Compound procedure called with wrong number of arguments"
-| (lisp_error.excessive_recursion) := "Maximum recursion depth exceeded"
-| (lisp_error.unknown_form) := "Unknown form"
-instance : has_repr lisp_error := ⟨lisp_error.repr⟩
-
-def lisp_result (α : Type) := except lisp_error α
-
-meta def lisp_result_atom.repr : lisp_result atom → string
-| (except.ok result) := atom.repr result
-| (except.error err) := "ERROR: " ++ lisp_error.repr err
--- instance : has_repr lisp_result := ⟨lisp_result.repr⟩
-
-meta def lisp_result.repr {α : Type} : lisp_result (atom × α) → string
-| (except.ok (result, _)) := atom.repr result
-| (except.error err) := "ERROR: " ++ lisp_error.repr err
-#+END_SRC
-
-Now, we also need a notion of "state" and "frame."
-
-#+BEGIN_SRC lean
-def state : Type := string → option atom
-instance state_inhabited : inhabited state :=
-inhabited.mk (λ x, none)
-
-def state.update (name : string) (val : atom) (s : state) : state :=
-λname', if name' = name then some val else s name'
-
-notation s `{` name ` ↦ ` val `}` := state.update name val s
-
-def lookup_var : string → list state → option atom
-| var (list.nil) := none
-| var (list.cons s rest) :=
- match s var with
- | some result := some result
- | none := lookup_var var rest
- end
-
--- If we've just pushed a frame onto the environment, and a variable exists in
--- that frame, then looking up that variable in the environment is equivalent to
--- looking it up in the frame.
-lemma lookup_head (x : string) (y : state) (ys : list state) (z : atom) :
- y x = some z → lookup_var x (y :: ys) = some z :=
-begin
- intro h,
- simp [h, lookup_var],
-end
-
-def set_var : string → atom → list state → lisp_result (list state)
-| place new_value (list.nil) := except.error (lisp_error.no_such_variable place)
-| place new_value (list.cons s rest) :=
- match s place with
- | (some _) := except.ok (list.cons (s{place ↦ new_value}) rest)
- | none :=
- match set_var place new_value rest with
- | (except.ok rest') := except.ok (list.cons s rest')
- | (except.error e) := except.error e
- end
- end
-
--- This is only well-defined if |names| = |values|.
-def new_frame : list string → list atom → state
-| (list.cons name rest₁) (list.cons value rest₂) := (new_frame rest₁ rest₂){name ↦ value}
-| _ _ := λ _, none
-#+END_SRC
-
-And, finally, we can get into the implementation of evaluation. First, we'll implement evaluation of procedures. Either the procedure is primitive (or built-in), like =+=, it's a named compound procedure, it's a lambda form, or the name doesn't exist in the environment.
-
-#+BEGIN_EXPORT html
-
-#+END_EXPORT
-
-#+BEGIN_SRC lean
-def collect_params : atom → option (list string)
-| (atom.list (list.cons (atom.symbol param) rest)) :=
- match collect_params (atom.list rest) with
- | some rest' := some (list.cons param rest')
- | none := none
- end
-| (atom.list (list.nil)) := some []
-| _ := none
-
-#eval collect_params (atom.list [atom.symbol "x"])
-#eval collect_params (atom.list [atom.symbol "x", atom.symbol "y"])
-
-def mk_compound_procedure
- (closure_env : list state)
- (paramlist : atom)
- (body : list atom)
- : lisp_result atom :=
-match collect_params paramlist with
-| some params :=
- except.ok
- (atom.compound_procedure
- (λ x, lookup_var x closure_env)
- params
- (atom.list (list.cons (atom.symbol "begin") body)))
-| none := except.error (lisp_error.bad_lambda)
-end
-
-#eval lisp_result_atom.repr
- (mk_compound_procedure
- [(λ _, none)]
- (atom.list [atom.symbol "x"])
- [(atom.symbol "+"), (atom.number 2), (atom.number 4)])
-
-def symbol_name : atom → option string
-| (atom.symbol name) := some name
-| _ := none
-
-def is_primitive_procedure (name : string) : bool :=
- name ∈ ["+", "-", "*", "/", "=", "car", "cdr", "cons", "null?", "eqv?"]
-
-@[simp]
-lemma add_is_primitive : is_primitive_procedure "+" := by exact rfl
-@[simp]
-lemma sub_is_primitive : is_primitive_procedure "-" := by exact rfl
-@[simp]
-lemma mul_is_primitive : is_primitive_procedure "*" := by exact rfl
-@[simp]
-lemma div_is_primitive : is_primitive_procedure "/" := by exact rfl
-@[simp]
-lemma eq_is_primitive : is_primitive_procedure "=" := by exact rfl
-@[simp]
-lemma car_is_primitive : is_primitive_procedure "car" := by exact rfl
-@[simp]
-lemma cdr_is_primitive : is_primitive_procedure "cdr" := by exact rfl
-@[simp]
-lemma cons_is_primitive : is_primitive_procedure "cons" := by exact rfl
-@[simp]
-lemma null_is_primitive : is_primitive_procedure "null?" := by exact rfl
-@[simp]
-lemma eqv_is_primitive : is_primitive_procedure "eqv?" := by exact rfl
-
-def fold_maybe_numeric : (ℤ → ℤ → ℤ) → ℤ → list atom → option ℤ
-| op nil (list.cons (atom.number n) rest) :=
- do {
- rest_sum ← fold_maybe_numeric op nil rest,
- pure (op n rest_sum) }
-| op nil (list.nil) := some nil
-| _ _ _ := none
-
-def primitive_add (args : list atom) : lisp_result atom :=
-match fold_maybe_numeric (λ x y, x + y) 0 args with
-| some result := except.ok (atom.number result)
-| none := except.error lisp_error.expected_number
-end
-
-def primitive_sub (args : list atom) : lisp_result atom :=
-match fold_maybe_numeric (λ x y, x - y) 0 args with
-| some result := except.ok (atom.number result)
-| none := except.error lisp_error.expected_number
-end
-
-def primitive_mul (args : list atom) : lisp_result atom :=
-match fold_maybe_numeric (λ x y, x * y) 1 args with
-| some result := except.ok (atom.number result)
-| none := except.error lisp_error.expected_number
-end
-
-def primitive_div (args : list atom) : lisp_result atom :=
-match fold_maybe_numeric (λ x y, x / y) 1 args with
-| some result := except.ok (atom.number result)
-| none := except.error lisp_error.expected_number
-end
-
-def attach_state : lisp_result atom → list state → lisp_result (atom × list state)
-| (except.ok result) s := except.ok (result, s)
-| (except.error e) _ := except.error e
-
--- TODO: Error reporting could be better.
-def primitive_eq (args : list atom) : lisp_result atom :=
-match args with
-| (list.cons (atom.number x) (list.cons (atom.number y) _)) :=
- except.ok (if x = y then atom.boolean tt else atom.boolean ff)
-| _ := except.error lisp_error.expected_number
-end
-
--- This is where I got sick of being explicit about the return types.
-def primitive_car (args : list atom) : lisp_result atom :=
-match args with
-| (list.cons (atom.cell car cdr) _) := except.ok car
-| (list.cons car cdr) := except.ok car
-| _ := except.error lisp_error.expected_list
-end
-
-def primitive_cdr (args : list atom) : lisp_result atom :=
-match args with
-| (list.cons (atom.cell car cdr) _) := except.ok cdr
-| (list.cons car cdr) := except.ok (atom.list cdr)
-| _ := except.error lisp_error.expected_list
-end
-
-def primitive_cons (args : list atom) : lisp_result atom :=
-match args with
-| (list.cons car (list.cons (atom.list cdr) _)) := except.ok (atom.list (list.cons car cdr))
-| (list.cons car (list.cons cdr _)) := except.ok (atom.cell car cdr)
-| _ := except.error lisp_error.expected_list
-end
-
-def primitive_null (args : list atom) : lisp_result atom :=
-match args with
-| (list.cons (atom.list (list.nil)) _) := except.ok (atom.boolean tt)
-| (list.cons (atom.list _) _) := except.ok (atom.boolean ff)
-| _ := except.error lisp_error.expected_list
-end
-
-def primitive_eqv (args : list atom) : lisp_result atom :=
-match args with
-| (list.cons (atom.symbol x) (list.cons (atom.symbol y) _)) := except.ok (if x = y then atom.boolean tt else atom.boolean ff)
-| _ := except.error lisp_error.expected_symbol
-end
-#+END_SRC
-
-#+BEGIN_EXPORT html
-
-#+END_EXPORT
-
-We can't actually encode a "proper" Scheme implementation in Lean because there'a possibility that we write a program that doesn't terminate. If we cap the maximum evaluation depth, though, we can prove that the evaluator is well-founded. This more accurately models the real world, anyway, since computers have a finite amount of memory. So we have an =evaluation_state= which maintains the current =stack_depth=, and we'll use that as both a guardrail that allows us to prove that our recursive =eval= function eventually terminates.
-
-#+BEGIN_EXPORT html
-
-#+END_EXPORT
-
-#+BEGIN_SRC lean
-structure evaluation_state :=
-(stack_depth : ℕ)
-(environment : list state)
-(form : atom)
-
-def evaluation_state_measure : psum evaluation_state (psum evaluation_state evaluation_state) → ℕ
-| (psum.inl state) := state.stack_depth
-| (psum.inr (psum.inl state)) := state.stack_depth
-| (psum.inr (psum.inr state)) := state.stack_depth
-
-mutual def eval, apply, eval_param_list
-
-with eval : evaluation_state → lisp_result (atom × list state)
-| (evaluation_state.mk 0 _ _) :=
- except.error (lisp_error.excessive_recursion)
-| (evaluation_state.mk (stack_depth + 1) s (atom.undefined)) :=
- except.ok (atom.undefined, s)
-| (evaluation_state.mk (stack_depth + 1) s (atom.boolean bool)) :=
- except.ok (atom.boolean bool, s)
-| (evaluation_state.mk (stack_depth + 1) s (atom.number n)) :=
- except.ok (atom.number n, s)
-| (evaluation_state.mk (stack_depth + 1) s (atom.cell car cdr)) :=
- except.ok (atom.cell car cdr, s)
-| (evaluation_state.mk (stack_depth + 1) s (atom.primitive_procedure name)) :=
- except.ok (atom.primitive_procedure name, s)
-| (evaluation_state.mk (stack_depth + 1) s (atom.compound_procedure closure_env paramlist body)) :=
- except.ok (atom.compound_procedure closure_env paramlist body, s)
-| (evaluation_state.mk (stack_depth + 1) s (atom.symbol sym)) :=
- if sym = "+" then
- except.ok (atom.primitive_procedure "+", s)
- else if sym = "-" then
- except.ok (atom.primitive_procedure "-", s)
- else if sym = "*" then
- except.ok (atom.primitive_procedure "*", s)
- else if sym = "/" then
- except.ok (atom.primitive_procedure "/", s)
- else if sym = "=" then
- except.ok (atom.primitive_procedure "=", s)
- else if sym = "car" then
- except.ok (atom.primitive_procedure "car", s)
- else if sym = "cdr" then
- except.ok (atom.primitive_procedure "cdr", s)
- else if sym = "cons" then
- except.ok (atom.primitive_procedure "cons", s)
- else if sym = "null?" then
- except.ok (atom.primitive_procedure "null?", s)
- else if sym = "eqv?" then
- except.ok (atom.primitive_procedure "eqv?", s)
- else match (lookup_var sym s) with
- | none := except.error (lisp_error.no_such_variable sym)
- | some value := except.ok (value, s)
- end
-| (evaluation_state.mk (stack_depth + 1) s (atom.list (list.cons func rest))) :=
- if symbol_name func = some "quote" then
- except.ok (list.head rest, s)
- else if symbol_name func = some "lambda" then
- match mk_compound_procedure s (list.head rest) (list.tail rest) with
- | (except.ok lambda) := except.ok (lambda, s)
- | (except.error err) := except.error err
- end
- else if symbol_name func = some "begin" then
- match rest with
- | (list.cons head (list.nil)) :=
- eval (evaluation_state.mk stack_depth s head)
- | (list.cons head tail) :=
- match eval (evaluation_state.mk stack_depth s head) with
- | (except.ok (result, s')) :=
- eval (evaluation_state.mk stack_depth s' (atom.list (list.cons (atom.symbol "begin") tail)))
- | (except.error e) := (except.error e)
- end
- | _ := (except.error lisp_error.bad_begin)
- end
- else if symbol_name func = some "set!" then
- match rest with
- | (list.cons (atom.symbol place) (list.cons value _)) :=
- match set_var place value s with
- | (except.ok s') := except.ok (atom.undefined, s')
- | (except.error e) := except.error e
- end
- | _ := except.error lisp_error.bad_arity
- end
- else if symbol_name func = some "if" then
- match rest with
- | (list.cons cond (list.cons ite_true (list.nil))) :=
- match eval (evaluation_state.mk stack_depth s cond) with
- | except.ok ((atom.boolean ff), s') := except.ok (atom.undefined, s')
- | except.ok (_, s') :=
- match eval (evaluation_state.mk stack_depth s ite_true) with
- | except.ok (result, s'') := except.ok (result, s'')
- | except.error e := except.error e
- end
- | except.error e := except.error e
- end
- | (list.cons cond (list.cons ite_true (list.cons ite_false _))) :=
- match eval (evaluation_state.mk stack_depth s cond) with
- | except.ok ((atom.boolean ff), s') :=
- match eval (evaluation_state.mk stack_depth s ite_false) with
- | except.ok (result, s'') := except.ok (result, s'')
- | except.error e := except.error e
- end
- | except.ok (_, s') :=
- match eval (evaluation_state.mk stack_depth s ite_true) with
- | except.ok (result, s'') := except.ok (result, s'')
- | except.error e := except.error e
- end
- | except.error e := except.error e
- end
- | _ := except.error lisp_error.bad_if
- end
- else if symbol_name func = some "define" then
- match rest with
- -- Function definition.
- | (list.cons (atom.list (list.cons (atom.symbol name) args)) body) :=
- match mk_compound_procedure s (atom.list args) body with
- | (except.ok procedure) := except.ok (atom.undefined, list.cons ((list.head s){name ↦ procedure}) (list.tail s))
- | (except.error e) := except.error e
- end
- | (list.cons (atom.symbol name) body) :=
- match eval (evaluation_state.mk stack_depth s (list.head body)) with
- | (except.ok (result, _)) := except.ok (atom.undefined, list.cons ((list.head s){name ↦ result}) (list.tail s))
- | (except.error e) := except.error e
- end
- | _ := except.error lisp_error.bad_define
- end
- else apply (evaluation_state.mk stack_depth s (atom.list (list.cons func rest)))
-| _ := except.error lisp_error.unknown_form
-
-with apply : evaluation_state → lisp_result (atom × list state)
-| (evaluation_state.mk 0 _ _) :=
- except.error (lisp_error.excessive_recursion)
-| (evaluation_state.mk (stack_depth + 1) s (atom.list (list.cons func args))) :=
- let func' := eval (evaluation_state.mk stack_depth s func),
- args_evaluated := eval_param_list (evaluation_state.mk stack_depth s (atom.list args)) in
- match func' with
- | (except.ok ((atom.primitive_procedure "+"), _)) :=
- match args_evaluated with
- | (except.ok (args', s')) := attach_state (primitive_add args') s
- | (except.error e) := except.error e
- end
- | (except.ok ((atom.primitive_procedure "-"), _)) :=
- match args_evaluated with
- | (except.ok (args', s')) := attach_state (primitive_sub args') s
- | (except.error e) := except.error e
- end
- | (except.ok ((atom.primitive_procedure "*"), _)) :=
- match args_evaluated with
- | (except.ok (args', s')) := attach_state (primitive_mul args') s
- | (except.error e) := except.error e
- end
- | (except.ok ((atom.primitive_procedure "/"), _)) :=
- match args_evaluated with
- | (except.ok (args', s')) := attach_state (primitive_div args') s
- | (except.error e) := except.error e
- end
- | (except.ok ((atom.primitive_procedure "="), _)) :=
- match args_evaluated with
- | (except.ok (args', s')) := attach_state (primitive_eq args') s
- | (except.error e) := except.error e
- end
- | (except.ok ((atom.primitive_procedure "car"), _)) :=
- match args_evaluated with
- | (except.ok (args', s')) := attach_state (primitive_car args') s
- | (except.error e) := except.error e
- end
- | (except.ok ((atom.primitive_procedure "cdr"), _)) :=
- match args_evaluated with
- | (except.ok (args', s')) := attach_state (primitive_cdr args') s
- | (except.error e) := except.error e
- end
- | (except.ok ((atom.primitive_procedure "cons"), _)) :=
- match args_evaluated with
- | (except.ok (args', s')) := attach_state (primitive_cons args') s
- | (except.error e) := except.error e
- end
- | (except.ok ((atom.primitive_procedure "null?"), _)) :=
- match args_evaluated with
- | (except.ok (args', s')) := attach_state (primitive_null args') s
- | (except.error e) := except.error e
- end
- | (except.ok ((atom.primitive_procedure "eqv?"), _)) :=
- match args_evaluated with
- | (except.ok (args', s')) := attach_state (primitive_eqv args') s
- | (except.error e) := except.error e
- end
- | (except.ok ((atom.primitive_procedure name), _)) :=
- except.error (lisp_error.no_such_variable name)
- | (except.ok ((atom.compound_procedure closure_env paramlist body), s')) :=
- match args_evaluated with
- | (except.ok (args', s')) :=
- let s'' := (list.cons (new_frame paramlist args') (list.cons closure_env s')) in
- eval (evaluation_state.mk stack_depth s'' body)
- | (except.error e) := except.error e
- end
- | _ := except.error (lisp_error.unknown_form)
- end
-| _ := except.error lisp_error.unknown_form
-
-with eval_param_list : evaluation_state → lisp_result (list atom × list state)
-| (evaluation_state.mk 0 _ _) :=
- except.error (lisp_error.excessive_recursion)
-| (evaluation_state.mk stack_depth s (atom.list (list.nil))) :=
- except.ok ([], s)
-| (evaluation_state.mk (stack_depth + 1) s (atom.list (list.cons elt rest))) :=
- match eval (evaluation_state.mk stack_depth s elt) with
- | (except.ok (result_head, s')) :=
- match eval_param_list (evaluation_state.mk stack_depth s' (atom.list rest)) with
- | except.ok (result_rest, s'') := except.ok (list.cons result_head result_rest, s'')
- | (except.error e) := except.error e
- end
- | (except.error e) := except.error e
- end
-| _ := except.error lisp_error.unknown_form
-
-using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf evaluation_state_measure⟩]}
-#+END_SRC
-
-#+BEGIN_EXPORT html
-
-#+END_EXPORT
-
-I found the evaluation state structure to actually be quite convenient in reasoning about things like whether or not an evaluation is finite.
-
-#+BEGIN_SRC lean
-lemma finite_implies_nonzero_stack_depth
- (form result : atom)
- (environment environment' : list state)
- (stack_depth : ℕ)
- (h_finite : ¬ (eval (evaluation_state.mk stack_depth environment form) = except.error (lisp_error.excessive_recursion))) :
- stack_depth > 0 :=
-begin
- by_contra',
- apply h_finite,
- simp [le_of_eq] at this,
- simp [this, eval],
-end
-#+END_SRC
-
-The approach I've taken for the program semantics is to compile the expression to a "statement" type, and then reason about the big step semantics of those statements.
-
-At the beginning, I was doing small step semantics, until I realized that it was really hard to reason about a language where everything is an expression without being able to assume hypotheses about the transitive nature of small steps, which Lean didn't like at all. Something about nesting inductive predicates.
-
-#+BEGIN_EXPORT html
-
-#+END_EXPORT
-
-#+BEGIN_SRC lean
-inductive stmt : Type
-| expr : atom → stmt -- 1, #tt, symbol, ...
-| var : string → stmt -- var-name
-| seq : stmt → stmt → stmt -- (begin form ... rest)
-| assign : string → stmt → stmt -- (set! name expr)
-| define : string → stmt → stmt -- (define name expr)
-| ite : stmt → stmt → stmt → stmt -- (if cond expr-true expr-false)
-| app : stmt → list stmt → stmt -- ((lambda (arg1 ... argn) body) param1 ... paramn)
-
-meta def stmt.repr : stmt → string
-| (stmt.expr expr) := "(expr " ++ atom.repr expr ++ ")"
-| (stmt.var name) := "(deref " ++ name ++ ")"
-| (stmt.seq car cdr) := "(seq " ++ stmt.repr car ++ " " ++ stmt.repr cdr ++ ")"
-| (stmt.assign place rhs) := "(assign " ++ place ++ " " ++ stmt.repr rhs ++ ")"
-| (stmt.define place rhs) := "(define " ++ place ++ " " ++ stmt.repr rhs ++ ")"
-| (stmt.ite cond if_true if_false) := "(if " ++ stmt.repr cond ++ " " ++ stmt.repr if_true ++ " " ++ stmt.repr if_false ++ ")"
-| (stmt.app func args) := "(application " ++ stmt.repr func ++ " " ++ string.intercalate " " (list.map stmt.repr args) ++ ")"
-
-instance stmt_inhabited : inhabited stmt :=
-inhabited.mk (stmt.expr (atom.undefined))
-
-def is_some {α : Type} : option α → Prop
-| (some _) := true
-| _ := false
-
-def is_lambda : atom → Prop
-| (atom.list (list.cons (atom.symbol "lambda") _)) := true
-| _ := false
-
-def seq_from_list_stmt : list stmt → stmt
-| (list.nil) := stmt.expr atom.undefined
-| (list.cons head (list.nil)) := head
-| (list.cons head tail) := stmt.seq head (seq_from_list_stmt tail)
-
-mutual def compile_stmt, compile_stmt_list
-with compile_stmt : atom → option stmt
--- Arity 0
-| (atom.list (list.cons func (list.nil))) :=
- do {
- result ← compile_stmt func,
- pure (stmt.app result []) }
--- Arity 1
-| (atom.list (list.cons func (list.cons rest (list.nil)))) :=
- match func with
- | (atom.symbol "begin") := compile_stmt rest
- | (atom.symbol "quote") := some (stmt.expr rest)
- | _ := do {
- result₁ ← compile_stmt func,
- result₂ ← compile_stmt rest,
- pure (stmt.app result₁ [result₂]) }
- end
--- Arity 2
-| (atom.list (list.cons func (list.cons place (list.cons rhs (list.nil))))) :=
- match func with
- | (atom.symbol "begin") :=
- do {
- result₁ ← compile_stmt func,
- result₂ ← compile_stmt place,
- result₃ ← compile_stmt rhs,
- pure (stmt.seq result₂ result₃) }
- | (atom.symbol "set!") :=
- match place with
- | (atom.symbol place) :=
- do {
- rhs_result ← compile_stmt rhs,
- pure (stmt.assign place rhs_result) }
- | _ := none
- end
- -- We'll convert lambda expressions into compound procedures at evaluation
- -- time. We don't have scope information at compile time, so we can't
- -- construct closed environments.
- | (atom.symbol "lambda") := some (stmt.expr (atom.list [func, place, rhs]))
- | (atom.symbol "define") :=
- match place with
- -- Syntax sugar for (define func (lambda (param₁ ...) body))
- | (atom.list (list.cons (atom.symbol func_name) params)) :=
- some (stmt.expr
- (atom.list ([
- (atom.symbol "lambda"),
- (atom.list params),
- (atom.list [(atom.symbol "begin"), rhs])])))
- | (atom.symbol place) :=
- do {
- rhs_result ← compile_stmt rhs,
- pure (stmt.define place rhs_result) }
- | _ := none
- end
- | _ := do {
- result₁ ← compile_stmt func,
- result₂ ← compile_stmt place,
- result₃ ← compile_stmt rhs,
- pure (stmt.app result₁ [result₂, result₃]) }
- end
--- Arity 3
-| (atom.list (list.cons func (list.cons rest_head (list.cons rest_tail₁ (list.cons rest_tail₂ (list.nil)))))) :=
-match func with
- | (atom.symbol "if") :=
- do {
- result₁ ← compile_stmt rest_head,
- result₂ ← compile_stmt rest_tail₁,
- result₃ ← compile_stmt rest_tail₂,
- pure (stmt.ite result₁ result₂ result₃)}
- | (atom.symbol "begin") :=
- do {
- result₁ ← compile_stmt rest_head,
- result₂ ← compile_stmt rest_tail₁,
- result₃ ← compile_stmt rest_tail₂,
- pure (stmt.seq result₁ (stmt.seq result₂ result₃))}
- | _ := do {
- result₁ ← compile_stmt func,
- result₂ ← compile_stmt rest_head,
- result₃ ← compile_stmt rest_tail₁,
- result₄ ← compile_stmt rest_tail₂,
- pure (stmt.app result₁ [result₂, result₃, result₄])}
- end
--- Arity n > 3
-| (atom.list (list.cons func (list.cons rest_head (list.cons rest_tail₁ rest_tail₂)))) :=
- match func with
- | (atom.symbol "begin") :=
- do {
- result₁ ← compile_stmt rest_head,
- result₂ ← compile_stmt rest_tail₁,
- result₃ ← compile_stmt_list rest_tail₂,
- pure (stmt.seq result₁ (stmt.seq result₂ (seq_from_list_stmt result₃)))}
- -- Generalization of `lambda` above.
- -- We're duplicating code to make the equation compiler happy.
- | (atom.symbol "lambda") := some (stmt.expr (atom.list (list.cons func (list.cons rest_head (list.cons rest_tail₁ rest_tail₂)))))
- -- Syntax sugar for (define func (lambda (param₁ ...) body))
- -- We're duplicating code to make the equation compiler happy.
- | (atom.symbol "define") :=
- match rest_head with
- | (atom.list (list.cons (atom.symbol func_name) params)) :=
- some (stmt.expr
- (atom.list ([
- (atom.symbol "lambda"),
- (atom.list params),
- (atom.list ([(atom.symbol "begin")] ++ (list.cons rest_tail₁ rest_tail₂)))])))
- | _ := none
- end
- | _ := do {
- result₁ ← compile_stmt func,
- result₂ ← compile_stmt_list (list.cons rest_head (list.cons rest_tail₁ rest_tail₂)),
- pure (stmt.app result₁ result₂) }
- end
-| (atom.list (list.nil)) := none
-| (atom.symbol sym) :=
- if is_primitive_procedure sym then
- some (stmt.expr (atom.primitive_procedure sym))
- else some (stmt.var sym)
-| e := some (stmt.expr e)
-
-with compile_stmt_list : list atom → option (list stmt)
-| (list.cons head rest) :=
- match compile_stmt head with
- | (some result) :=
- match (compile_stmt_list rest) with
- | some result_rest := some (list.cons result result_rest)
- | none := none
- end
- | none := none
- end
-| (list.nil) := some []
-
-def unwrap_option {α : Type} [inhabited α] : option α → α
-| (some x) := x
-| _ := inhabited.default
-
-mutual inductive args_step, big_step
-with args_step : list stmt × list state → list atom × list state → Prop
-| nil {s} :
- args_step
- ((list.nil), s)
- ((list.nil), s)
-
-| cons {S T s s' s'' u r}
- (hstep : big_step (S, s) (u, s'))
- (hrest : args_step (T, s') (r, s'')) :
- args_step
- (list.cons S T, s)
- (list.cons u r, s'')
-
-with big_step : stmt × list state → atom × list state → Prop
--- I'm not especially happy with this particular rule. I don't think it's
--- unsound, but I'm not 100% confident about that. Unfortunately it's necessary
--- if I don't want to completely rework how function bodies are represented.
-| drop_frame {expr u s s' f rest}
- (heval_in_frame : big_step (expr, s) (u, s'))
- (h_has_frame : s = list.cons f rest) :
- big_step (expr, s) (u, rest)
-
-| self_evaluating {expr s}
- (h_not_lambda : ¬ is_lambda expr):
- big_step
- (stmt.expr expr, s)
- (expr, s)
-
-| construct_compound_procedure {args body closure s}
- (h_well_formed : mk_compound_procedure s args body = except.ok closure):
- big_step
- (stmt.expr (atom.list ([(atom.symbol "lambda"), args] ++ body)), s)
- (closure, s)
-
-| var_deref {x u s}
- (h_lookup_var : lookup_var x s = some u):
- big_step
- (stmt.var x, s)
- (u, s)
-
-| seq {S S' T s t t' u}
- (hS : big_step (S, s) (S', t))
- (hT : big_step (T, t) (u, t')) :
- big_step
- (stmt.seq S T, s)
- (u, t')
-
-| assign {x rhs rhs_expr s s' s''}
- (h_rhs_eval : big_step (rhs, s) (rhs_expr, s'))
- (h_var_exists : set_var x rhs_expr s' = except.ok s'') :
- big_step
- (stmt.assign x rhs, s)
- (atom.undefined, s'')
-
-| define {x rhs rhs_expr s s'}
- (h_rhs_eval : big_step (rhs, s) (rhs_expr, s')) :
- big_step
- (stmt.define x rhs, s)
- (atom.undefined, list.cons ((list.head s'){x ↦ rhs_expr}) (list.tail s'))
-
-| ite_true {b S T s s' t u}
- (hcond : big_step (b, s) ((atom.boolean tt), s'))
- (heval : big_step (S, s') (u, t)) :
- big_step
- (stmt.ite b S T, s)
- (u, t)
-
-| ite_false {b S T s s' t u}
- (hcond : big_step (b, s) ((atom.boolean ff), s'))
- (heval : big_step (T, s') (u, t)) :
- big_step
- (stmt.ite b S T, s)
- (u, t)
-
-| application {closed func params body body' args args' expr s s' s'' s'''}
- (h_func : big_step (func, s) ((atom.compound_procedure closed params body), s'))
- (h_args : args_step (args, s') (args', s''))
- (h_well_formed : compile_stmt body = some body')
- (heval : big_step (body',
- (list.cons (new_frame params args')
- (list.cons closed s')))
- (expr, s'')) :
- big_step
- (stmt.app func args, s)
- (expr, s''')
-
-| application_primitive_add {s s' args args' n}
- (h_args : args_step (args, s) (args', s'))
- (heval: primitive_add args' = except.ok (atom.number n)):
- big_step
- (stmt.app
- (stmt.expr (atom.primitive_procedure "+"))
- args, s)
- (atom.number n, s)
-
-| application_primitive_sub {s s' args args' n}
- (h_args : args_step (args, s) (args', s'))
- (heval: primitive_sub args' = except.ok (atom.number n)):
- big_step
- (stmt.app
- (stmt.expr (atom.primitive_procedure "-"))
- args, s)
- (atom.number n, s)
-
-| application_primitive_mul {s s' args args' n}
- (h_args : args_step (args, s) (args', s'))
- (heval: primitive_mul args' = except.ok (atom.number n)):
- big_step
- (stmt.app
- (stmt.expr (atom.primitive_procedure "*"))
- args, s)
- (atom.number n, s)
-
-| application_primitive_div {s s' args args' n}
- (h_args : args_step (args, s) (args', s'))
- (heval: primitive_div args' = except.ok (atom.number n)):
- big_step
- (stmt.app
- (stmt.expr (atom.primitive_procedure "/"))
- args, s)
- (atom.number n, s)
-
-| application_primitive_eq {s s' args args' b}
- (h_args : args_step (args, s) (args', s'))
- (heval: primitive_eq args' = except.ok (atom.boolean b)):
- big_step
- (stmt.app
- (stmt.expr (atom.primitive_procedure "="))
- args, s)
- (atom.boolean b, s)
-
-| application_primitive_car {s s' args args' u}
- (h_args : args_step (args, s) (args', s'))
- (heval: primitive_car args' = except.ok u):
- big_step
- (stmt.app
- (stmt.expr (atom.primitive_procedure "car"))
- args, s)
- (u, s)
-
-| application_primitive_cdr {s s' args args' u}
- (h_args : args_step (args, s) (args', s'))
- (heval: primitive_cdr args' = except.ok u):
- big_step
- (stmt.app
- (stmt.expr (atom.primitive_procedure "cdr"))
- args, s)
- (u, s)
-
-| application_primitive_cons {s s' args args' u}
- (h_args : args_step (args, s) (args', s'))
- (heval: primitive_cons args' = except.ok u):
- big_step
- (stmt.app
- (stmt.expr (atom.primitive_procedure "cons"))
- args, s)
- (u, s)
-
-| application_primitive_null {s s' args args' u}
- (h_args : args_step (args, s) (args', s'))
- (heval: primitive_null args' = except.ok u):
- big_step
- (stmt.app
- (stmt.expr (atom.primitive_procedure "null?"))
- args, s)
- (u, s)
-
-| application_primitive_eqv {s s' args args' u}
- (h_args : args_step (args, s) (args', s'))
- (heval: primitive_null args' = except.ok u):
- big_step
- (stmt.app
- (stmt.expr (atom.primitive_procedure "eqv?"))
- args, s)
- (u, s)
-#+END_SRC
-
-#+BEGIN_EXPORT html
-
-#+END_EXPORT
-
-This is the simplest program I could think of to show that the program semantics are at least usable.
-
-#+BEGIN_SRC lean
-lemma var_lookup :
- big_step
- (stmt.var "x", [(λ x, none){"x" ↦ atom.number 1}])
- ((atom.number 1), [(λ x, none){"x" ↦ atom.number 1}]) :=
-begin
- apply big_step.var_deref,
- let my_state := [(λ x, none){"x" ↦ atom.number 1}],
- apply lookup_head,
- simp [state.update],
-end
-#+END_SRC
-
-This is a much more involved proof: that the factorial program at the top of this file is "correct," in the sense that it computes `int.factorial`.
-
-As you'll see, my approach to proving this statement involved many obligations, and ended up being very tedious. It's effectively the "intro to algorithms" proof of correctness for factorial, except that we're appealing to the big-step semantics above. By which I mean -- we're doing a rather poor job of leveraging the mathematical tools we just spent pages of code developing. Had I more time to work on this assignment, I might have naturally come to one of the refinement-based solutions, but I chose to be stubborn and just press forward.
-
-#+BEGIN_EXPORT html
-
-#+END_EXPORT
-
-#+BEGIN_SRC lean
-def nat.factorial : ℕ → ℤ
-| 0 := 1
-| (n + 1) := (n + 1) * (nat.factorial n)
-
-def int.factorial : ℤ → ℤ
-| (int.of_nat n) := nat.factorial n
-| (int.neg_succ_of_nat n) := nat.factorial (n + 1)
-
--- Would be trivial if there wasn't casting.
-lemma sub1_cast (n : ℕ) :
- primitive_sub [atom.number (↑n + 1), atom.number 1] = except.ok (atom.number ↑n) :=
-sorry
-
--- Would be trivial (unfold `int.factorial`) if there wasn't casting.
-lemma primitive_mul_fact (n : ℕ) :
- primitive_mul [atom.number (↑n + 1), atom.number (int.factorial ↑n)] = except.ok (atom.number (int.factorial ↑(nat.succ n))) :=
-sorry
-
--- Would be trivial if comparison was decidable.
-lemma factorial_program_compile_inner :
- (compile_stmt
- (atom.list
- [atom.symbol "if", atom.list [atom.symbol "=", atom.number 0, atom.symbol "x"], atom.number 1, atom.list
- [atom.symbol "*", atom.symbol "x", atom.list
- [atom.symbol "factorial", atom.list [atom.symbol "-", atom.symbol "x", atom.number 1]]]])) =
- some
- (stmt.ite (stmt.app (stmt.expr (atom.primitive_procedure "="))
- [stmt.expr (atom.number 0), stmt.var "x"])
- (stmt.expr (atom.number 1))
- (stmt.app (stmt.expr (atom.primitive_procedure "*"))
- [stmt.var "x",
- stmt.app (stmt.var "factorial")
- [stmt.app (stmt.expr (atom.primitive_procedure "-"))
- [stmt.var "x", stmt.expr (atom.number 1)]]])) :=
-sorry
-
--- For convenience -- the `factorial` function definition is pretty unwieldy to
--- be passing around in theorem statements.
-def define_factorial (s : list state) : list state :=
-list.cons ((λ _, none){"factorial" ↦
- (atom.compound_procedure (λ x, none) ["x"]
- (atom.list [
- (atom.symbol "if"),
- (atom.list [(atom.symbol "="), (atom.number 0), (atom.symbol "x")]),
- (atom.number 1),
- (atom.list [
- (atom.symbol "*"),
- (atom.symbol "x"),
- (atom.list [
- (atom.symbol "factorial"),
- (atom.list [
- (atom.symbol "-"),
- (atom.symbol "x"),
- (atom.number 1)])])])]))}) s
-
-lemma factorial_program_correct (n : ℕ) (s : list state) (arg : stmt)
- (h_eval_to_n : big_step
- (arg, define_factorial s)
- (atom.number n, define_factorial s)) :
- big_step
- (stmt.app (stmt.var "factorial") [arg], define_factorial s)
- (atom.number (int.factorial n), define_factorial s) :=
-begin
- let fundef :=
- (atom.compound_procedure (λ x, none) ["x"]
- (atom.list [
- (atom.symbol "if"),
- (atom.list [(atom.symbol "="), (atom.number 0), (atom.symbol "x")]),
- (atom.number 1),
- (atom.list [
- (atom.symbol "*"),
- (atom.symbol "x"),
- (atom.list [
- (atom.symbol "factorial"),
- (atom.list [
- (atom.symbol "-"),
- (atom.symbol "x"),
- (atom.number 1)])])])])),
- have h_lookup_factorial : lookup_var "factorial" (define_factorial s) = some fundef, by
- begin
- simp [define_factorial],
- apply lookup_head,
- simp [state.update],
- end,
- induction' n,
- { apply big_step.application,
- { apply big_step.var_deref,
- simp [h_lookup_factorial, fundef],
- apply and.intro,
- { refl, },
- { apply and.intro,
- { refl, },
- { refl, }}},
- { apply args_step.cons,
- { apply h_eval_to_n, },
- { apply args_step.nil, }},
- { exact factorial_program_compile_inner, },
- { apply big_step.ite_true,
- { apply big_step.application_primitive_eq,
- { apply args_step.cons,
- { apply big_step.self_evaluating, simp [is_lambda], },
- { apply args_step.cons,
- { apply big_step.var_deref,
- simp [new_frame],
- apply lookup_head,
- simp [state.update], },
- { apply args_step.nil, }}},
- { unfold primitive_eq, simp, }},
- { apply drop_two_frames,
- apply big_step.self_evaluating,
- simp [is_lambda], }}},
- { apply big_step.application,
- { apply big_step.var_deref,
- simp [h_lookup_factorial, fundef],
- apply and.intro,
- { refl, },
- { apply and.intro,
- { refl, },
- { refl, }}},
- { apply args_step.cons,
- { apply h_eval_to_n, },
- { apply args_step.nil, }},
- { exact factorial_program_compile_inner, },
- { apply big_step.ite_false,
- { apply big_step.application_primitive_eq,
- { apply args_step.cons,
- { apply big_step.self_evaluating, simp [is_lambda], },
- { apply args_step.cons,
- { apply big_step.var_deref,
- simp [new_frame],
- apply lookup_head,
- simp [state.update], },
- { apply args_step.nil, }}},
- { unfold primitive_eq,
- norm_cast, }},
- { apply drop_two_frames,
- apply big_step.application_primitive_mul,
- { apply args_step.cons,
- { apply big_step.var_deref,
- simp [new_frame, state.update],
- apply lookup_head,
- simp, },
- { apply args_step.cons,
- { have hsimp : ∀ (arg : stmt) (u : atom) (s : list state),
- big_step (arg, new_frame ["x"] [atom.number ↑(nat.succ n)] :: (λ (x : string), none) :: define_factorial s)
- (u, new_frame ["x"] [atom.number ↑(nat.succ n)] :: (λ (x : string), none) :: define_factorial s) ↔
- big_step (arg, define_factorial (new_frame ["x"] [atom.number ↑(nat.succ n)] :: (λ (x : string), none) :: define_factorial s))
- (u, define_factorial (new_frame ["x"] [atom.number ↑(nat.succ n)] :: (λ (x : string), none) :: define_factorial s)),
- by sorry, -- Nontrivial but obvious.
- rw hsimp,
- apply ih,
- { exact h_lookup_factorial, },
- { apply big_step.application_primitive_sub,
- { apply args_step.cons,
- { have hsimp₂ : lookup_var "x"
- (define_factorial
- (new_frame ["x"] [atom.number ↑(nat.succ n)] :: (λ (x : string), none) :: define_factorial s)) =
- lookup_var "x" (new_frame ["x"] [atom.number ↑(nat.succ n)] :: (λ (x : string), none) :: define_factorial s),
- by sorry, -- Nontrivial but obvious.
- apply big_step.var_deref,
- rw hsimp₂,
- simp [new_frame, state.update],
- apply lookup_head,
- simp, },
- { apply args_step.cons,
- { apply big_step.self_evaluating,
- simp [is_lambda], },
- { apply args_step.nil, }}},
- { apply sub1_cast, }}},
- { apply args_step.nil, }}},
- apply primitive_mul_fact, }}}
-end
-#+END_SRC
-
-#+BEGIN_EXPORT html
-
-#+END_EXPORT
-
-The =sorry= keyword lets you pretend to be Pierre de Fermat and say "this should be provable but I don't want to write the proof down." It's helpful in making some progress when you're working towards a deadline, but it completely violates the soundness of Lean's logic.
-
-I'm not sure how enlightening any of this is, but I think it does highlight how much goes into using these sorts of tools for program verification compared to the ease with which we used Alloy to check my answer to a homework problem.
-
-* What I Have Yet to Learn
-
-Quite a bit!
-
-I've alluded to a few things in the previous sections. I have much more to learn about the specification of programming language semantics, and how to apply data refinement in practice. I'm also interested in learning TLA+ and SPARK. They seem to meet somewhere in the middle of Alloy and Lean, which I expect to be the right fit for what I do professionally. I want to learn about the mathematics that underpins SMT, and the algorithms that enable fast SAT solving. I want to learn about how Lean works at a low-level, and the different approaches to encoding logic in a proof assistant.
-
-In short, I've barely scratched the surface. I know enough to be dangerous, but I have a ways to go before I'm the "domain expert" I strive to be.
-
-* Conclusions
-
-In this article, we've introduced what formal methods are and gained a cursory understanding of the techniques suited to "high-level" verification and "low-level" verification. "Formal methods" refers to the use of mathematical techniques to establish properties about software and verify that those properties hold true -- to provide a higher level of confidence to practitioners about the correctness of software than testing alone. Alloy and Forge are well-suited to working with systems at a high-level and leverage SAT solving to verify properties of interest. Lean, Isabelle, and Coq are well-suited to working with systems at a lower level, and work as a mechanization of mathematical logic: a proof in a proof assistant is equivalent to (but typically more formal than) a proof that a mathematician or computer scientist might write on a piece of paper.
-
-Now that I've got that out of my system, it's time to get back to keeping my head down and working on applying what I've learned to something useful. I hope to write about what I'm working on soon, but this blog can be a bit of a distraction, so I'll be taking a short break from writing for now. See you soon!
-
-* Appendix: Using the Tools
-
-Lean 3 is packaged in the Gentoo repositories, but Lean 4 is not. I have an ebuild for it in [[https://git.sr.ht/~jakob/zerodaysfordays][my overlay]] if you use Gentoo and you'd like to experiment with Lean 4.
-
-[[https://github.com/leanprover/lean-mode][lean-mode]] was great but [[https://github.com/leanprover/lean4-mode][lean4-mode]] forces you into using [[https://github.com/emacs-lsp/lsp-mode][lsp-mode]], which I don't like. (I much prefer [[https://github.com/joaotavora/eglot][eglot]].) I'm currently using [[https://github.com/akirak/lean4-mode/commits/modular][this fork]], which isolates the parts which are specific to =lsp-mode=. Then all I need to do is set =/usr/bin/lake serve= as the language server for =lean4-mode= in =eglot-server-programs= and add
-
-#+BEGIN_SRC elisp
-(defvar lean4-goal-buffer (get-buffer-create "*lean4-goal*"))
-
-(defun lean4-update-goal-buffer ()
- (when (eq 'lean4-mode major-mode)
- (jsonrpc-async-request
- (eglot--current-server-or-lose)
- :$/lean/plainGoal (eglot--TextDocumentPositionParams)
- :success-fn
- (lambda (&rest args)
- (let ((goals (seq-reduce #'concat (plist-get (car args) :goals) "")))
- (save-excursion
- (set-buffer lean4-goal-buffer)
- (erase-buffer)
- (insert goals))
- (message goals)))
- :error-fn
- (lambda (&rest args) (message (format "JSONrpc error %s" args))))))
-
-(defun lean4-update-goal-buffer-wrap ()
- (unless (or (window-minibuffer-p) (not (eq major-mode 'lean4-mode)))
- (lean4-update-goal-buffer)))
-
-(add-hook 'post-command-hook #'lean4-update-goal-buffer-wrap)
-#+END_SRC
-
-to my =init.el= and I get a goal buffer similar to the old lean-mode or Proof General.
-
----
-
-[fn:1] [[https://people.cs.umass.edu/~immerman/cs691/cs691.html][CS 691M]] was last offered in 1996. [[https://people.cs.umass.edu/~hconboy/class/2023Spring/CS520/][CS 520]] purportedly discusses "formal specification methods." If you read over the syllabus, you'll quickly understand that to be an empty claim. Perhaps I could have self-taught as part of an [[https://www.cics.umass.edu/content/undergraduate-independent-study-information][independent study]], but the department (at the time) didn't count independent study credits toward your graduation requirements, and I had another offer (with money involved) to do a REU in cryptography, so that's how I spent the limited time I had available to me.
-
-[fn:2] I've allowed myself to move the goalposts: my purpose is now to learn enough to demonstrate that there would be value in sending me back to school to get my Ph.D. and then truly become a domain expert!
-
-[fn:3] It's uncommon to include stochastic tests such as this one in a "test suite". It's desirable to have a test suite that always passes or always fails.
-
-[fn:4] One thing also worth noting is that being able to sleep at night /now/ doesn't necessarily mean you won't have to work on safety-critical or mission-critical software later on in your career. If you're merely a hobbyist, maybe these points aren't especially convincing to you.
-
-[fn:5] Jackson, D. (2002). [[https://homepage.cs.uiowa.edu/~tinelli/classes/181/Spring03/Readings/Jack02b.pdf][Alloy: a lightweight object modelling notation]]. ACM Transactions on software engineering and methodology (TOSEM), 11(2), 256-290.
-
-[fn:6] Boolean SATisfiability and Satisfiability Modulo Theories, respectively.
-
-[fn:7] Nelson, T., Barratt, C., Dougherty, D. J., Fisler, K., & Krishnamurthi, S. (2010, November). The Margrave Tool for Firewall Analysis. In LISA (Vol. 10, pp. 1-18).
-
-[fn:8] There is some risk involved in using a new tool that doesn't have a reputation of stability, but there has to be a critical mass of folks taking that risk and being at the forefront of using the tool to help it get a good reputation. I'm choosing to take that risk.
-
-[fn:9] To be clear: this wasn't my motivation to engage with a study of formal methods.
-
-[fn:10] In temporal mode, Forge always generates traces of infinite length, but there will be a loop somewhere within it.
-
-[fn:11] Even so, I'm covering only a small part of the problem, so I wouldn't expect this article to be that useful to someone trying to cheese a homework assignment.
-
-[fn:12] For more realistic examples of property testing in Scheme, see [[https://ngyro.com/software/guile-quickcheck.html][guile-quickcheck]].
--
cgit v1.3