GithubHelp home page GithubHelp logo

Comments (6)

radeusgd avatar radeusgd commented on September 21, 2024

First thing I tried is writing mutual induction schemes, as described in https://coq.inria.fr/refman/user-extensions/proof-schemes.html

However I was unable to get it to work, but maybe it is possible to fix this by diving deeper into writing custom schemes.

from quotedpatternmatchingproof.

radeusgd avatar radeusgd commented on September 21, 2024

In the end I just refactored the definitions and proofs to the following form

Inductive Term :=
| Lit : nat -> Term
| Lam : label -> TType -> Term -> Term
| Var : label -> Term
| App : Term -> Term -> Term

which in general seems much better suited for proofs.

(The original form was slightly inspired by how I would go about writing an interpreter for STLC and wanting to have a separate type for values, that for example would be held in an environment etc. But for proofs it seems to have more drawbacks than advantages)

from quotedpatternmatchingproof.

radeusgd avatar radeusgd commented on September 21, 2024

As we need mutually recursive types to correctly handle #15 we need to revisit this issue.

from quotedpatternmatchingproof.

radeusgd avatar radeusgd commented on September 21, 2024

Careful analysis of Coq's manual leads to:

Scheme typedterm_mutualind := Induction for typedterm Sort Prop
  with term_mutualind := Induction for term Sort Prop.

Which indeed yields a mutually inductive scheme.

At first I didn't know how to use it however, finally I figured out I need to do induction term using SchemeName.

from quotedpatternmatchingproof.

radeusgd avatar radeusgd commented on September 21, 2024

This was still not enough, as this scheme has 2 predicates: one for terms and one for typed terms. This predicates are independent and the proof has to somehow 'connect' them.
This is however difficult inside a complex proof, and just using the scheme directly always lead to one of the predicates being left as an existential variable and very hard to instantiate with something reasonable.

from quotedpatternmatchingproof.

radeusgd avatar radeusgd commented on September 21, 2024

I carefully inspected the form of the generated scheme:

typedterm_mutualind
     : forall (P : typedterm -> Prop) (P0 : term -> Prop),
       (forall u : term, P0 u -> forall t : type, P (u : t)) ->
       (forall n : nat, P0 (Nat n)) ->
       (forall x : DeBruijnIndex, P0 (VAR x)) ->
       (forall (argT : type) (ebody : typedterm),
        P ebody -> P0 (Lam argT ebody)) ->
       (forall e1 : typedterm,
        P e1 -> forall e2 : typedterm, P e2 -> P0 (App e1 e2)) ->
       (forall e : typedterm, P e -> P0 (Lift e)) ->
       (forall e : typedterm, P e -> P0 (Quote e)) ->
       (forall e : typedterm, P e -> P0 (Splice e)) ->
       forall t : typedterm, P t

I thought that it may be reasonable to replace the predicate P in such a way that we have forall u T, P0 u -> P (u : T) (so that if P0 holds for all untyped terms, we prove that P holds for all typed terms, ignoring their type).

This led to manually writing the following induction scheme:

Lemma syntactic :
  forall (P : typedterm -> Prop),
    (forall n : nat, forall T : type, P (Nat n : T)) ->
    (forall x : DeBruijnIndex, forall T : type, P (VAR x : T)) ->
    (forall (argT : type)
       (ebody : typedterm),
        P ebody -> forall T : type, P (Lam argT ebody : T)) ->
    (forall e1 : typedterm,
        P e1 ->
        forall e2 : typedterm,
          P e2 -> forall T : type, P (App e1 e2 : T)) ->
    (forall e : typedterm,
        P e -> forall T : type, P (Lift e : T)) ->
    (forall e : typedterm,
        P e -> forall T : type, P (Quote e : T)) ->
    (forall e : typedterm,
        P e -> forall T : type, P (Splice e : T)) ->
    forall t : typedterm, P t.

Which now has only one predicate so it can be automatically instantiated correctly by Coq with induction term using syntactic.
I have proved this scheme using the automatically generated one.

I was concerned that 'ignoring' the types in the predicate may be an issue, but for now it works well in the proofs. I think it should be enough, as we can get the type information from 'other places'.
For example we have a lemma:

Lemma AscribedTypeIsCorrect : forall G L t T T',
    G ⊢(L) (t : T) ∈ T' -> T = T'.

which allows us to narrow down the ascribed type to the actual type, so that having the forall in the induction scheme is not an issue.

from quotedpatternmatchingproof.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.