Subset coercions in C M S under direction of C - - PowerPoint PPT Presentation

subset coercions in c
SMART_READER_LITE
LIVE PREVIEW

Subset coercions in C M S under direction of C - - PowerPoint PPT Presentation

Subset coercions in C M S under direction of C P -M Paris-Sud 11 University LRI - D Team & INRIA F - P


slide-1
SLIDE 1

Subset coercions in C

M S under direction of C P-M

Paris-Sud 11 University LRI - D´  Team & INRIA F - P Project

TYPES’06 Workshop 18-21 April 2006

slide-2
SLIDE 2

The Big Picture

slide-3
SLIDE 3

The Big Picture

slide-4
SLIDE 4

The Big Picture

slide-5
SLIDE 5

The Big Picture

slide-6
SLIDE 6

The Big Picture

slide-7
SLIDE 7

Outline

1

The idea

2

Theoretical development R Traduction in C

3

The implementation

slide-8
SLIDE 8

A simple idea

Definition

{ x : T | P } is the set of objects of set T verifying property P.

Useful for specifying, widely used in mathematics ; Separates object and property.

slide-9
SLIDE 9

A simple idea

Definition

{ x : T | P } is the set of objects of set T verifying property P.

Useful for specifying, widely used in mathematics ; Separates object and property. Adapting the idea

t : T P[t/x] t : { x : T | P } t : { x : T | P } t : T

slide-10
SLIDE 10

From “Predicate subtyping”. . .

PVS Specialized typing algorithm for subset types, generating Type-checking conditions.

t : { x : T | P }

used as

t : T

  • k

t : T

used as

t : { x : T | P }

if P[t/x]

slide-11
SLIDE 11

From “Predicate subtyping”. . .

PVS Specialized typing algorithm for subset types, generating Type-checking conditions.

t : { x : T | P }

used as

t : T

  • k

t : T

used as

t : { x : T | P }

if P[t/x] + Practical success ;

slide-12
SLIDE 12

From “Predicate subtyping”. . .

PVS Specialized typing algorithm for subset types, generating Type-checking conditions.

t : { x : T | P }

used as

t : T

  • k

t : T

used as

t : { x : T | P }

if P[t/x] + Practical success ; – No strong safety guarantee in PVS.

slide-13
SLIDE 13

. . . to Subset coercions

1

A property-irrelevant language (R) with decidable typing ;

Γ ⊢ t : { x : T | P } Γ ⊢ t : T Γ ⊢ t : T Γ, x : T ⊢ P : Prop t : { x : T | P }

slide-14
SLIDE 14

. . . to Subset coercions

1

A property-irrelevant language (R) with decidable typing ;

2

A total traduction to C terms with holes ;

Γ ⊢ t : { x : T | P } Γ ⊢ σ1 t : T Γ ⊢ t : T Γ, x : T ⊢ P : Prop Γ ⊢? : P[t/x] (t, ?) : { x : T | P }

slide-15
SLIDE 15

. . . to Subset coercions

1

A property-irrelevant language (R) with decidable typing ;

2

A total traduction to C terms with holes ;

3

A method to turn the holes into proof obligations.

slide-16
SLIDE 16

Outline

1

The idea

2

Theoretical development R Traduction in C

3

The implementation

slide-17
SLIDE 17

R’s typing ⊢ and coercion

Calculus of Constructions - C +

Γ ⊢ t : U Γ ⊢ T : s U T

C

Γ ⊢ t : T

slide-18
SLIDE 18

R’s typing ⊢ and coercion

Calculus of Constructions - C +

Γ ⊢ t : U Γ ⊢ T : s U T

C

Γ ⊢ t : T T ≡βπ U

S-C

T U S T T U

S-T

S U

slide-19
SLIDE 19

R’s typing ⊢ and coercion

Calculus of Constructions - C +

Γ ⊢ t : U Γ ⊢ T : s U T

C

Γ ⊢ t : T T ≡βπ U

S-C

T U S T T U

S-T

S U U V

S-S { x : U | P } V

U V

S-P U { x : V | P }

slide-20
SLIDE 20

R’s typing ⊢ and coercion

Calculus of Constructions - C +

Γ ⊢ t : U Γ ⊢ T : s U T

C

Γ ⊢ t : T T ≡βπ U

S-C

T U S T T U

S-T

S U U V

S-S { x : U | P } V

U V

S-P U { x : V | P }

0 : nat nat { x : nat | x 0 } 0 : { x : nat | x 0 }

slide-21
SLIDE 21

R’s typing ⊢ and coercion

Calculus of Constructions - C +

Γ ⊢ t : U Γ ⊢ T : s U T

C

Γ ⊢ t : T T ≡βπ U

S-C

T U S T T U

S-T

S U U V

S-S { x : U | P } V

U V

S-P U { x : V | P }

0 : nat nat { x : nat | x 0 } 0 : { x : nat | x 0 } ? : 0 0

slide-22
SLIDE 22

R’s typing ⊢ and coercion

Calculus of Constructions - C +

Γ ⊢ t : U Γ ⊢ T : s U T

C

Γ ⊢ t : T T ≡βπ U

S-C

T U S T T U

S-T

S U U V

S-S { x : U | P } V

U V

S-P U { x : V | P }

U T V W

S-P Πx : T.V Πx : U.W

slide-23
SLIDE 23

Results

Theorem (Decidability of type checking)

Γ ⊢ t : T is decidable. Γ ⊢ f : T T Πx : A.B Γ ⊢ e : E E A

A

Γ ⊢ (f e) : B[e/x]

slide-24
SLIDE 24

Results

Theorem (Decidability of type checking)

Γ ⊢ t : T is decidable.

Lemma (Elimination of transitivity) If T U ∧ U V then T V.

Γ ⊢ f : T T Πx : A.B Γ ⊢ e : E E A

A

Γ ⊢ (f e) : B[e/x]

slide-25
SLIDE 25

Outline

1

The idea

2

Theoretical development R Traduction in C

3

The implementation

slide-26
SLIDE 26

The target system

CIC with metavariables

Γ ⊢? t : T Γ ⊢? p : P[t/x] Γ ⊢? elt T P t p : { x : T | P } Γ ⊢? t : { x : T | P } Γ ⊢? σ1 t : T Γ ⊢? t : { x : T | P } Γ ⊢? σ2 t : P[σ1 t/x] Γ ⊢? P : Prop Γ ⊢??P : P

slide-27
SLIDE 27

From C to R

The easy way

(σ1 t)◦ = t◦ (elt T P t p)◦ = t◦ (σ2 t)◦ = ⊥ (?P)◦ = ⊥

If Γ ⊢? t : T then Γ◦ ⊢ t◦ : T ◦ if ()◦ is defined on Γ, t and T.

slide-28
SLIDE 28

From C to R and back

The easy way

(σ1 t)◦ = t◦ (elt T P t p)◦ = t◦ (σ2 t)◦ = ⊥ (?P)◦ = ⊥

If Γ ⊢? t : T then Γ◦ ⊢ t◦ : T ◦ if ()◦ is defined on Γ, t and T. The hard way If Γ ⊢ t : T then Γ ⊢? tΓ : TΓ.

slide-29
SLIDE 29

Traduction : deriving explicit coercions

Traduction for coercions If T U then Γ ⊢? c[•] : T U which implies

Γ ⊢? λx : TΓ.c[x] : TΓ → UΓ.

slide-30
SLIDE 30

Traduction : deriving explicit coercions

Traduction for coercions If T U then Γ ⊢? c[•] : T U which implies

Γ ⊢? λx : TΓ.c[x] : TΓ → UΓ.

Definition

T ≡βπ U Γ ⊢? : T U

slide-31
SLIDE 31

Traduction : deriving explicit coercions

Traduction for coercions If T U then Γ ⊢? c[•] : T U which implies

Γ ⊢? λx : TΓ.c[x] : TΓ → UΓ.

Definition

T ≡βπ U Γ ⊢? • : T U

slide-32
SLIDE 32

Traduction : deriving explicit coercions

Traduction for coercions If T U then Γ ⊢? c[•] : T U which implies

Γ ⊢? λx : TΓ.c[x] : TΓ → UΓ.

Definition

T ≡βπ U Γ ⊢? • : T U Γ ⊢? : { x : T | P } T

slide-33
SLIDE 33

Traduction : deriving explicit coercions

Traduction for coercions If T U then Γ ⊢? c[•] : T U which implies

Γ ⊢? λx : TΓ.c[x] : TΓ → UΓ.

Definition

T ≡βπ U Γ ⊢? • : T U Γ ⊢? σ1 • : { x : T | P } T

slide-34
SLIDE 34

Traduction : deriving explicit coercions

Traduction for coercions If T U then Γ ⊢? c[•] : T U which implies

Γ ⊢? λx : TΓ.c[x] : TΓ → UΓ.

Definition

T ≡βπ U Γ ⊢? • : T U Γ ⊢? σ1 • : { x : T | P } T Γ ⊢? : T { x : T | P }

slide-35
SLIDE 35

Traduction : deriving explicit coercions

Traduction for coercions If T U then Γ ⊢? c[•] : T U which implies

Γ ⊢? λx : TΓ.c[x] : TΓ → UΓ.

Definition

T ≡βπ U Γ ⊢? • : T U Γ ⊢? σ1 • : { x : T | P } T Γ ⊢? elt • ?PΓ,x:T [•/x] : T { x : T | P }

slide-36
SLIDE 36

Traduction : deriving explicit coercions

Traduction for coercions If T U then Γ ⊢? c[•] : T U which implies

Γ ⊢? λx : TΓ.c[x] : TΓ → UΓ.

Definition

T ≡βπ U Γ ⊢? • : T U Γ ⊢? σ1 • : { x : T | P } T Γ ⊢? elt • ?PΓ,x:T [•/x] : T { x : T | P }

Example

Γ ⊢? 0 : nat Γ ⊢? c : nat { x : nat | x 0 } Γ ⊢? (elt • ?(x0)[•/x])[0] = elt 0 ?00 : { x : nat | x 0 }

slide-37
SLIDE 37

Traduction : interpretation of terms Γ

Example (Application)

Γ ⊢ f : T T Πx : V.W : s Γ ⊢ u : U U V Γ ⊢ (f u) : W[u/x] f uΓ =

let π = coerceΓ T (Πx : V.W) in let c = coerceΓ U V in

(π[fΓ]) (c[uΓ])

Theorem (Soundness) If Γ ⊢ t : T then Γ ⊢? tΓ : TΓ.

slide-38
SLIDE 38

Theoretical matters

⊢?’s equational theory : (β) (λx : X.e) v ≡ e[v/x] (σi) σi (elt E P e1 e2) ≡ ei (η) (λx : X.e x) ≡ e

if x FV(e)

(SP)

elt E P (σ1 e) (σ2 e)

≡ e

slide-39
SLIDE 39

Theoretical matters

⊢?’s equational theory : (β) (λx : X.e) v ≡ e[v/x] (σi) σi (elt E P e1 e2) ≡ ei (η) (λx : X.e x) ≡ e

if x FV(e)

(SP)

elt E P (σ1 e) (σ2 e)

≡ e (σ)

elt E P t p

elt E P t′ p′ if t ≡ t′

⇒ Proof Irrelevance

slide-40
SLIDE 40

Outline

1

The idea

2

Theoretical development R Traduction in C

3

The implementation

slide-41
SLIDE 41

The P vernacular

Architecture Wrap around C’s vernacular commands (Definition,

Fixpoint, . . . ).

1

Use the C parser : Program Definition f : T := t. ;

slide-42
SLIDE 42

The P vernacular

Architecture Wrap around C’s vernacular commands (Definition,

Fixpoint, . . . ).

1

Use the C parser : Program Definition f : T := t. ;

2

Typecheck Γ◦ ⊢ t : T and generate Γ◦ ⊢? tΓ◦ : TΓ◦ ;

Program Definition f : TΓ◦ := tΓ◦ .

slide-43
SLIDE 43

The P vernacular

Architecture Wrap around C’s vernacular commands (Definition,

Fixpoint, . . . ).

1

Use the C parser : Program Definition f : T := t. ;

2

Typecheck Γ◦ ⊢ t : T and generate Γ◦ ⊢? tΓ◦ : TΓ◦ ;

3

Interactive proving of obligations ;

Program Definition f : TΓ◦ := tΓ◦ + obligations.

slide-44
SLIDE 44

The P vernacular

Architecture Wrap around C’s vernacular commands (Definition,

Fixpoint, . . . ).

1

Use the C parser : Program Definition f : T := t. ;

2

Typecheck Γ◦ ⊢ t : T and generate Γ◦ ⊢? tΓ◦ : TΓ◦ ;

3

Interactive proving of obligations ;

4

Final definition. Definition f : TΓ◦ := tΓ◦ + obligations.

slide-45
SLIDE 45

The P vernacular

Architecture Wrap around C’s vernacular commands (Definition,

Fixpoint, . . . ).

1

Use the C parser : Program Definition f : T := t. ;

2

Typecheck Γ◦ ⊢ t : T and generate Γ◦ ⊢? tΓ◦ : TΓ◦ ;

3

Interactive proving of obligations ;

4

Final definition. Definition f : TΓ◦ := tΓ◦ + obligations. Remark (Restriction) We assume Γ◦ = Γ and Γ ⊢CCI TΓ : s.

slide-46
SLIDE 46

P : The list example

slide-47
SLIDE 47

P : The list example

slide-48
SLIDE 48

P : The list example

slide-49
SLIDE 49

P : The list example

slide-50
SLIDE 50

P : The list example

slide-51
SLIDE 51

P : The list example

slide-52
SLIDE 52

P : The list example

slide-53
SLIDE 53

P : The list example

slide-54
SLIDE 54

P : The list example

slide-55
SLIDE 55

Conclusion

Our contribution A more flexible programming language, (almost) conservative over CIC, integrated with the existing environment and a formal justification of “Predicate subtyping”.

slide-56
SLIDE 56

Conclusion

Our contribution A more flexible programming language, (almost) conservative over CIC, integrated with the existing environment and a formal justification of “Predicate subtyping”. Future work Application to more constructs ((co-)inductive types) and commands. Improvements of C (existential variables, type inference, proof irrelevance). Complete and useful interpretation of ML languages.

slide-57
SLIDE 57

Addendum : some practical enhancements

Handling of dependent existential variables (WIP).

slide-58
SLIDE 58

Addendum : some practical enhancements

Handling of dependent existential variables (WIP). Pattern-matching and equalities. match v return T with p1 ⇒ t1 · · · pn ⇒ tn

(match µv as t′

return

t′ = µ(v) → T) with p1 ⇒ fun h ⇒ t1 . . . pn ⇒ fun h ⇒ tn) (refl equal µ(v))

slide-59
SLIDE 59

Addendum : some practical enhancements

Handling of dependent existential variables (WIP). Pattern-matching and equalities. Well-founded recursion.

Program Fixpoint f (a : nat) {wf lt a} : nat := t

slide-60
SLIDE 60

Addendum : some practical enhancements

Handling of dependent existential variables (WIP). Pattern-matching and equalities. Well-founded recursion.

Program Fixpoint f (a : nat) {wf lt a} : nat := t a : nat f : {x : nat | x < a} → nat t : nat