introduction.tex 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. Systems based on proposition-as-types provide an elegant approach to interactive
  2. proof assistants: the problem of proof checking is reduced to type checking and
  3. these systems combine in a natural way deduction and computation. A well understood
  4. formulation relies on lambda calculus with dependent types, \cite{nordstrom:book,barendregt92lambda,deBruijn:WLF}. The main problem is then checking the judgement $M:A$ expressing that a given term (proof), $M$, is of type (is a correct proof of the proposition) $A$.
  5. % A central typing rule in any dependent type theory, is the
  6. % equality rule for types:
  7. %
  8. % \[ \infer{\HasTypeC \Gamma M A}
  9. % { \HasTypeC \Gamma M B
  10. % & \EqualTypeC \Gamma A B
  11. % }
  12. % \]
  13. A type checking algorithm can be naturally divided in two
  14. stages\cite{deBruijn:WLF}. In the first stage we go through the terms and
  15. whenever we type check a term $M$ of type $A$ against a type $B$ we collect the
  16. equality constraint $A = B$.
  17. In the second phase we check these constraints by
  18. verifying that the terms are convertible with each other. With dependent types it is important to check the
  19. constraints in the right order, and to fail as soon as an equality is invalid, since well typedness of a
  20. constraint may dependend on previous constraints being satisfied.
  21. %The correctness for this strategy for
  22. %checking equality hence depends on that we as invariant has that the two terms
  23. %in the constrains have the same type.
  24. For representing proof search in these frameworks it is convenient to extend the notion
  25. of terms with {\it meta-variables} that stands for yet undetermined terms (proofs). Meta variables
  26. are also useful for structure editing, as placeholders for information to be filled in by
  27. the user. In this paper we will however focus on type reconstruction where
  28. meta-variables are used for representing omitted
  29. information that can be recovered from typing constraints through unification.
  30. \input{exintro}
  31. This problem has some negative consequence for the typechecking algorithm. With dependent types,
  32. verifying convertibility between two
  33. terms relies on normalising these terms, which is only safe if these terms are well typed. But, as we
  34. have seen, in presence of meta-variables, we may not be sure that these terms are well typed, and the
  35. typechecker may loop. Furthermore, producing ill-typed terms is not very elegant.
  36. It is still the case however that if all constraints can be solved, then we have a correct solution; so we
  37. have some form of ``partial correctness'' and this is indeed the approach taken in
  38. \cite{magnussonnordstrom:alf,coquand:stt-lfm99}. In \cite{elliot:unification}, a similar problem of generating
  39. ill-typed terms occur. This is however less problematic in his context, since these terms can still be shown
  40. to be normalisable in the logical framework he uses, which is more restricted than the one we consider.
  41. Another problem is that when we get a constraint of the form $? = M$, we cannot be sure that $M$ is a solution
  42. for $?$, since we are not sure that $M$ is well-typed. In \cite{magnussonnordstrom:alf,coquand:stt-lfm99,munoz:synthesis}
  43. this difficulty is avoided by retypechecking $M$ at this point, which is costly.
  44. The main contribution of this paper is to present a type checking algorithm
  45. which produces only well-typed constraints for a logical framework extended
  46. with meta-variables. The main idea is,
  47. for a type-checking problem $N:C$,
  48. to produce an optimal well-typed approximation $N'$ of $N$.
  49. Whenever we need to verify $M:B$, for a subterm $M:A$ of $N$, where we cannot
  50. yet solve $A=B$,
  51. we replace the subterm $M$
  52. by a {\em guarded constant} $p$ of type $B$. This constant $p$ will compute to $M$ only when the
  53. constraint $A=B$ has been solved. The approximated term $N'$ is in a trivial
  54. way well-typed the logical framework without meta-variables. In the
  55. example above the type $\PI x {F ~?} {F~ (not~x)}$ will be replaced by $\PI x
  56. {F ~?} {F~ (p ~ x)}$ where $p~x : Bool$ will compute to $not ~ x$ when the
  57. meta-variable is replaced with the term $true$.
  58. One interesting application of our work is implicit syntax which allows for a
  59. more compact and readable representation of terms. In
  60. \cite{necula:representation} they show that terms where type information is
  61. omitted is more efficient to validate than type checking the complete proof
  62. term. This is only possible if constraints are known to be well typed. Their
  63. work differs from ours in that they consider a weaker framework where the
  64. constraint solving is guaranteed to succeed. The algorithm that we present has
  65. been implemented and we have made experiments with examples with several
  66. hundreds of meta-variables, which shows that our algorithm scales up to at
  67. least medium sized problems.