Comments (5)
I forgot to answer the issue
t's not clear why Compute (Var 0 (TBox TNat)).[ids]. returns Var 0 TNat instead of Var 0 (TBox TNat).
It is actually expected in terms of how things are defined (although of course not what we need).
t.[ids] is a term with the ids substitution applied
ids substitution is a substitution that is supposed to not change the term, but it works by replacing Var N with a fresh instance of Var N (I think that is done mostly for simplifying composability with other substitutions). As ids is defined as a function var -> term
where var
is just a nat
corresponding to the DeBruijn index.
As in our case Var also needs a type, the automatic derivation of Ids instance failed. So we provided it with an implementation that always returns type TNat (as we had to put something here). Of course it is not a good solution as the type will not always be TNat, but we can't do better as the only thing the ids function being defined "knows" is the DeBruijn index which is not enough to deduce the type.
Even if we somehow manage to use the HSubst with the new mutually recursive definition, we can't use ids
in subst for the TypedTerm version (but I guess we could use it in the hsubst with ids taken from the untyped version).
from quotedpatternmatchingproof.
For the following program:
Require Import List Omega.
Require Import Autosubst.Autosubst.
Require Import Context.
Inductive type :=
| TNat
| TAbs (t1: type) (t2: type)
| TBox (t: type).
Inductive term :=
| Nat (n : nat) (typ: type)
| Var (x : var) (typ: type)
| Lam (ebody : {bind term}) (typ: type)
| App (e1 e2 : term) (typ: type)
| Lift (e: term) (typ: type)
.
Instance Ids_term : Ids term. constructor 2.
exact H.
exact TNat.
Defined.
Instance Rename_term : Rename term. derive. Defined.
Instance Subst_term : Subst term. derive. Defined.
(* Instance SubstLemmas_term : SubstLemmas term. derive. Defined. *)
Compute (Var 0 (TBox TNat)).[ids].
The computation results in Var 0 TNat
but we would expect Var 0 (TBox TNat)
- we have erased the type by mistake.
I'm afraid this may make it impossible to use autosubst
in the project, unless Assumption 1 was false.
P.S.
Moreover the SubstLemmas instance is also not derived automatically and I think that is what autosubst was meant for in the first place, so even if we could derive Ids somehow correctly, it wouldn't help much.
from quotedpatternmatchingproof.
The assumption 1 is correct. For conjecture 1, I think you have an insight here, I'm not sure whether it works or not.
In the paper, the term languages have t
and u
, which are mutually recursive. If we look at u
, x
is a syntactic form of it, without type. Maybe there is still a chance.
It's not clear why Compute (Var 0 (TBox TNat)).[ids].
returns Var 0 TNat
instead of Var 0 (TBox TNat)
. Do you need someting like the follows:
Instance hsubst_term : HSubst type term. derive. Defined.
from quotedpatternmatchingproof.
This sounds like a good idea for a workaround. I cannot define Ids for typedterm, as that would require knowing the type, but maybe I may not need it.
I tried the following definition:
Inductive type :=
| TNat
| TAbs (t1: type) (t2: type)
| TBox (t: type).
Inductive typedterm :=
| TypedTerm (u: term) (t: type)
with
term :=
| Nat (n : nat)
| Var (x : var)
| Lam (argT: type) (ebody : {bind typedterm})
| App (e1 e2 : typedterm)
| Lift (e: term)
.
Instance Ids_term : Ids term. derive. Defined.
Instance Rename_term : Rename term. derive. Defined.
Instance Subst_term : Subst term. derive. Defined.
Instance SubstLemmas_term : SubstLemmas term. derive. Defined.
(* Instance Ids_typedterm : Ids typedterm. derive. Defined. *)
Instance Rename_typedterm : Rename typedterm. derive. Defined.
Instance Subst_typedterm : Subst typedterm. derive. Defined.
(* Instance SubstLemmas_typedterm : SubstLemmas typedterm. derive. Defined. *)
Instance HSubst_termtypedterm : HSubst term typedterm. derive. Defined.
Instance HSubst_termtypedterm2 : HSubst typedterm term. derive. Defined.
Unfortunately:
Compute (TypedTerm (App (TypedTerm (Var 1) (TAbs TNat TNat)) (TypedTerm (Var 0) TNat)) TNat).|[Nat 42/].
yields
TypedTerm
(App (TypedTerm (Var 1) (TAbs TNat TNat))
(TypedTerm (Var 0) TNat)) TNat
and not the expected
TypedTerm
(App (TypedTerm (Var 0) (TAbs TNat TNat))
(TypedTerm (Nat 42) TNat)) TNat
I may have to experiment further with how to handle this mutual recursion and if it is even possible to make it work with autosubst.
Unfortunately I couldn't find any examples of using autosubst with a mutually recursively defined type.
I conjecture that HSubst is meant for simple nesting but likely not for more complex case of mutual recursion.
For example:
Compute (TypedTerm (Var 0) TNat).|[Nat 42/].
correctly yields
TypedTerm (Nat 42) TNat
I think the issue is the hsubst only visits the term structure inside of the typedterm looking for replacements but it is unable to detect that actually the term can contain other typedterms that should be unpacked recursively.
from quotedpatternmatchingproof.
The workaround suggested by @liufengyun applied with the DbLib library seems to do the trick.
We can have an instance of nat -> term
that generates untyped VAR and we do substitution of terms inside a context of a typed term.
from quotedpatternmatchingproof.
Related Issues (17)
- Non-trivially recursive functions termination HOT 1
- Extend STLC with a boxed type and lift
- Add quotes and splices HOT 2
- Add pattern matching HOT 2
- Add fix operator HOT 1
- Extend STLC with explicit type annotations HOT 1
- Multiple binders in patterns HOT 3
- Inductive predicates vs Fixpoints
- Induction over mutually recursive types HOT 6
- Notation
- Hints for tactics HOT 2
- Case analysis of equality HOT 3
- Handling names / binders HOT 14
- Order of quantifiers in theorems proven by induction
- Quickly applying a hypothesis with a quantifier. HOT 1
- STLC with autosubst
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quotedpatternmatchingproof.