Towards a Formal Semantics for FHM: Part 2 Joey Capper and Henrik - - PowerPoint PPT Presentation

towards a formal semantics for fhm part 2
SMART_READER_LITE
LIVE PREVIEW

Towards a Formal Semantics for FHM: Part 2 Joey Capper and Henrik - - PowerPoint PPT Presentation

Towards a Formal Semantics for FHM: Part 2 Joey Capper and Henrik Nilsson School of Computer Science, University of Nottingham FPLab Away Day, Buxton, 8th of July 2011 Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day


slide-1
SLIDE 1

Towards a Formal Semantics for FHM: Part 2

Joey Capper and Henrik Nilsson

School of Computer Science, University of Nottingham

FPLab Away Day, Buxton, 8th of July 2011

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 1 / 18

slide-2
SLIDE 2

Introduction

What are we trying to achieve?

Evaluation of models in FHM.

1 Normalisation of functional level terms 2 Reducing signal level terms 3 Handling of simulation runtime events. Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 2 / 18

slide-3
SLIDE 3

Introduction

What are we trying to achieve?

Evaluation of models in FHM.

1 Normalisation of functional level terms 2 Reducing signal level terms 3 Handling of simulation runtime events. Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 2 / 18

slide-4
SLIDE 4

Introduction

What are we trying to achieve?

Evaluation of models in FHM.

1 Normalisation of functional level terms 2 Reducing signal level terms 3 Handling of simulation runtime events. Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 2 / 18

slide-5
SLIDE 5

Introduction

Partial Evaluation

The evaluation should be partial in some sense.

1 Permit only simple symbolic simplification at the signal level, e.g:

β-reduction of signal level products. fst(x, y) + z = 0

  • x + z = 0

2 Switch blocks may depend on an event payload. For example, state

transfer between structural configurations.

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 3 / 18

slide-6
SLIDE 6

Introduction

Partial Evaluation

The evaluation should be partial in some sense.

1 Permit only simple symbolic simplification at the signal level, e.g:

β-reduction of signal level products. fst(x, y) + z = 0

  • x + z = 0

2 Switch blocks may depend on an event payload. For example, state

transfer between structural configurations.

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 3 / 18

slide-7
SLIDE 7

Introduction

Partial Evaluation

The evaluation should be partial in some sense.

1 Permit only simple symbolic simplification at the signal level, e.g:

β-reduction of signal level products. fst(x, y) + z = 0

  • x + z = 0

2 Switch blocks may depend on an event payload. For example, state

transfer between structural configurations.

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 3 / 18

slide-8
SLIDE 8

Introduction

Discrete Semantics

We are only interested in the discrete aspects of FHM.

1 Not concerned with continuous semantics 2 Want to keep a clean divide between the discrete and continuous

aspects, allowing the continuous aspects to specified independently.

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 4 / 18

slide-9
SLIDE 9

Introduction

Discrete Semantics

We are only interested in the discrete aspects of FHM.

1 Not concerned with continuous semantics 2 Want to keep a clean divide between the discrete and continuous

aspects, allowing the continuous aspects to specified independently.

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 4 / 18

slide-10
SLIDE 10

Normalisation by Evaluation

How do we achieve this?

We use Normalisation by Evaluation (NbE), but why?

1 Reduction free view of normalisation 2 Symbolic method, enabling partial evaluation 3 We get use Agda as the meta-language! Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 5 / 18

slide-11
SLIDE 11

Normalisation by Evaluation

How do we achieve this?

We use Normalisation by Evaluation (NbE), but why?

1 Reduction free view of normalisation 2 Symbolic method, enabling partial evaluation 3 We get use Agda as the meta-language! Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 5 / 18

slide-12
SLIDE 12

Normalisation by Evaluation

How do we achieve this?

We use Normalisation by Evaluation (NbE), but why?

1 Reduction free view of normalisation 2 Symbolic method, enabling partial evaluation 3 We get use Agda as the meta-language! Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 5 / 18

slide-13
SLIDE 13

Normalisation by Evaluation

What is NbE?

1 Closely related to type-directed partial evaluation 2 Proceeds by interpreting terms into an appropriate model 3 Objects of the model are then reified back into the normal forms that

represent them.

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 6 / 18

slide-14
SLIDE 14

Normalisation by Evaluation

What is NbE?

1 Closely related to type-directed partial evaluation 2 Proceeds by interpreting terms into an appropriate model 3 Objects of the model are then reified back into the normal forms that

represent them.

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 6 / 18

slide-15
SLIDE 15

Normalisation by Evaluation

What is NbE?

1 Closely related to type-directed partial evaluation 2 Proceeds by interpreting terms into an appropriate model 3 Objects of the model are then reified back into the normal forms that

represent them.

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 6 / 18

slide-16
SLIDE 16

Normalisation by Evaluation

How do we know our normaliser is correct?

The correctness of normalisation can be specified in terms of the equational theory (∼βη) of the language. Soundness t ∼βη t′ = ⇒ norm t = norm t′ Completeness t ∼βη norm t

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 7 / 18

slide-17
SLIDE 17

Normalisation by Evaluation

How do we know our normaliser is correct?

The correctness of normalisation can be specified in terms of the equational theory (∼βη) of the language. Soundness t ∼βη t′ = ⇒ norm t = norm t′ Completeness t ∼βη norm t

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 7 / 18

slide-18
SLIDE 18

FHM language

The language

We consider an equation based language embedded into the simply typed λ-calculus. Syntax t ::= x | t1 t2 | λx.t | sigrel z where q | . . . etc q ::= t ⋄ s | s1 = s2 | init s1 = s2 | . . . etc

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 8 / 18

slide-19
SLIDE 19

FHM language

The language

With a signal level language as follows: Syntax s ::= z | t | s1 + s2 | s1 ∗ s2 | zero | suc s | fst s | snd s | pair s1 s2 | . . . etc

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 9 / 18

slide-20
SLIDE 20

FHM language

Types

With a simple language of types: Syntax τ ::= τ1 ˙ →τ2 | SR σ | Nat σ ::=⊤ | σ1 ˙ ×σ2 | Nat

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 10 / 18

slide-21
SLIDE 21

FHM language

Equational Theory

We need to extend the equational theory (∼βη): β-convertibility at s : σ. (sigrel z where q) ⋄ s ∼βη q[s/z] η-convertibility at t : SR σ. t ∼βη sigrel z where (t ⋄ z) + new congruence rules, and βη for signal level products.

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 11 / 18

slide-22
SLIDE 22

FHM language

Equational Theory

We need to extend the equational theory (∼βη): β-convertibility at s : σ. (sigrel z where q) ⋄ s ∼βη q[s/z] η-convertibility at t : SR σ. t ∼βη sigrel z where (t ⋄ z) + new congruence rules, and βη for signal level products.

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 11 / 18

slide-23
SLIDE 23

FHM language

Equational Theory

We need to extend the equational theory (∼βη): β-convertibility at s : σ. (sigrel z where q) ⋄ s ∼βη q[s/z] η-convertibility at t : SR σ. t ∼βη sigrel z where (t ⋄ z) + new congruence rules, and βη for signal level products.

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 11 / 18

slide-24
SLIDE 24

Agda Implementation

Term Representation

Some signatures: Term representation. STerm (Γ ∆ : Ctx) : (σ : SType)→Set Term (Γ : Ctx) : (τ : Type)→Set EqTerm (Γ ∆ : Ctx) : Set

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 12 / 18

slide-25
SLIDE 25

Agda Implementation

The Model

A type directed interpretation into the model (roughly!). Nrm is the redex-free representation of terms. First, the signal types. Model interpretation SVal : (Γ ∆ : Ctx)→SType →Set SVal Γ ∆ Unit = SNrm Γ ∆ Unit SVal Γ ∆ Nat = SNrm Γ ∆ Nat SVal Γ ∆ (σ1 ˙ ×σ2) = SVal Γ ∆ σ1×SVal Γ ∆ σ2

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 13 / 18

slide-26
SLIDE 26

Agda Implementation

The Model

And the functional types. Model interpretation Val : (Γ : Ctx)→Type →Set Val Γ Nat = Nrm Γ ∆ Nat Val Γ (τ1 ˙ →τ2) = Val Γ τ1 →Val Γ τ2 Val Γ (SR σ) = SVal Γ σ→EqNrm Γ ∆

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 14 / 18

slide-27
SLIDE 27

Agda Implementation

It is now possible to give our interpreter. Interpreter type signatures · s : STerm Γ ∆ σ→Env Γ→Env ∆→SVal ∆ σ · : Term Γ τ →Env Γ→Val Γ τ Env is just an environment of values for each variable in the indexing context.

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 15 / 18

slide-28
SLIDE 28

Agda Implementation

The final step is to take our representative in the model, and convert it back into a normal form. Reification reify : Val Γ τ →Nrm Γ τ reifys : SVal ∆ σ→SNrm ∆ σ Composition of interpretation and reification is normalisation!

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 16 / 18

slide-29
SLIDE 29

Agda Implementation

The handling of events is quite rudimentary at the moment. But maybe there is a better way? Coinduction maybe?

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 17 / 18

slide-30
SLIDE 30

Agda Implementation

The end

Questions? For further details, see our draft at cs.nott.ac.uk/~jjc

Joey Capper and Henrik Nilsson (UoN) Verified FHM Semantics FPLab Away Day 18 / 18