Reasoning About Sound Programs Emilio Jess Gallego Arias Joint work - - PowerPoint PPT Presentation

reasoning about sound programs
SMART_READER_LITE
LIVE PREVIEW

Reasoning About Sound Programs Emilio Jess Gallego Arias Joint work - - PowerPoint PPT Presentation

Reasoning About Sound Programs Emilio Jess Gallego Arias Joint work with O. Hermant & P . Jouvelot MINES ParisTech, PSL Research University, France Rennes, 15 Avril 2015 Software verification? Software verification? What is our gain?


slide-1
SLIDE 1

Reasoning About Sound Programs

Emilio Jesús Gallego Arias

Joint work with O. Hermant & P . Jouvelot MINES ParisTech, PSL Research University, France

Rennes, 15 Avril 2015

slide-2
SLIDE 2
slide-3
SLIDE 3

Software verification?

slide-4
SLIDE 4

Software verification?

What is our gain?

slide-5
SLIDE 5

Let’s assume a simple IIR filter: smoothn “ p1 ´ cq ¨ xn ` c ¨ smoothn´1

slide-6
SLIDE 6

Let’s assume a simple IIR filter: smoothn “ p1 ´ cq ¨ xn ` c ¨ smoothn´1 What would we like to know about it?

slide-7
SLIDE 7

smoothn “ p1 ´ cq ¨ xn ` c ¨ smoothn´1 Natural questions are:

§ Frequency response; § Stability; § Linearity/Time Invariance.

Standard DSP theory gives answers.

slide-8
SLIDE 8

smoothn “ p1 ´ cq ¨ xn ` c ¨ smoothn´1 Natural questions are:

§ Frequency response; § Stability; § Linearity/Time Invariance.

Standard DSP theory gives answers. What about the implementation of the filter? We dive into the realm of PL theory!

slide-9
SLIDE 9

smoothn “ p1 ´ cq ¨ xn ` c ¨ smoothn´1 Natural questions are:

§ Frequency response; § Stability; § Linearity/Time Invariance.

Standard DSP theory gives answers. What about the implementation of the filter? We dive into the realm of PL theory!

Paradigm shift!

slide-10
SLIDE 10

Faust

§ Functional PL for digital signal processing. § Synchronous paradigm, geared towards audio. § Programs: circuits/block diagrams with feedback. § Semantics: streams of samples. § Efficiency is crucial. § Created in 2000 by Yann Orlarey et al. at GRAME. § Mature, compiles to more than 14 platforms.

slide-11
SLIDE 11

Faust’s Ecosystem

Users:

§ Grame: Multiple projects, main developer. § Stanford: Class/books on signal processing, STK

instrument toolkit, Faust2android, Mephisto. . .

§ Ircam: Acoustic libraries, effects libraries,. . . § Other: Guitarix, moForte guitar, etc...

slide-12
SLIDE 12

Faust’s Ecosystem

Users:

§ Grame: Multiple projects, main developer. § Stanford: Class/books on signal processing, STK

instrument toolkit, Faust2android, Mephisto. . .

§ Ircam: Acoustic libraries, effects libraries,. . . § Other: Guitarix, moForte guitar, etc...

It has its market! Much easier than dwelling into C.

slide-13
SLIDE 13

Faust’s Ecosystem

Users:

§ Grame: Multiple projects, main developer. § Stanford: Class/books on signal processing, STK

instrument toolkit, Faust2android, Mephisto. . .

§ Ircam: Acoustic libraries, effects libraries,. . . § Other: Guitarix, moForte guitar, etc...

It has its market! Much easier than dwelling into C.

Recent Events:

§ Faust day at Stanford, LAC 2015. § Faust program competition (e2,000). § FEEVER project :)

slide-14
SLIDE 14

Syntax and Well-Formedness

TERM $! : 1 Ñ 0 ID $ _ : 1 Ñ 1 PAR $ f1 : i1 Ñ o1

¨ ¨ ¨ $ fn : in Ñ on $ pf1, . . . , fnq :

n

ÿ

j

ij Ñ

n

ÿ

j

  • j

COMP $ f : i Ñ k

$ g : k Ñ o $ pf : gq : i Ñ o

PAN $ f : i Ñ k

$ g : k ˚ n Ñ o 0 ă k ^ 0 ă n $ f ă: g : i Ñ o

slide-15
SLIDE 15

Feedback

FEED $ f : og ` if Ñ ig ` of

$ g : ig Ñ og $ f „ g : if Ñ ig ` of Diagram for + „ sin:

slide-16
SLIDE 16

Back to the Filter

smoothn “ p1 ´ cqxn ` c ¨ smoothn´1 Using Faust:

smooth(c) = *(1-c) : + „ *(c)

[For c = 0.9]

slide-17
SLIDE 17

Feedback Delay Network

fdnrev(N, dp, freqs, durs, loopgainmax) = delaylines „ (delayfilters : feedbackmatrix) where delaylines = rep(N,i,delay(dp[i]))); delayfilters = rep(N,filter(freqs,durs)); feedbackmatrix = bhadamard(N);

slide-18
SLIDE 18

Feedback Delay Network

fdnrev(N, dp, freqs, durs, loopgainmax) = delaylines „ (delayfilters : feedbackmatrix) where delaylines = rep(N,i,delay(dp[i]))); delayfilters = rep(N,filter(freqs,durs)); feedbackmatrix = bhadamard(N);

slide-19
SLIDE 19

PL & Faust

§ Causal/Synchronous Programming.

See next week’s talk!

§ Functional Reactive Programming/Arrows. § String Diagrams, Monoidal Closed Categories. § Stream/Data Flow Programming.

slide-20
SLIDE 20

PL & Faust

§ Causal/Synchronous Programming.

See next week’s talk!

§ Functional Reactive Programming/Arrows. § String Diagrams, Monoidal Closed Categories. § Stream/Data Flow Programming.

Data-intensive vs control-intensive require quite different control techniques. [Berry, 2000]

slide-21
SLIDE 21

PL & Faust

§ Causal/Synchronous Programming.

See next week’s talk!

§ Functional Reactive Programming/Arrows. § String Diagrams, Monoidal Closed Categories. § Stream/Data Flow Programming.

Data-intensive vs control-intensive require quite different control techniques. [Berry, 2000] Spectral processing may open a new gap from all of those!

slide-22
SLIDE 22

PL & Faust

§ Causal/Synchronous Programming.

See next week’s talk!

§ Functional Reactive Programming/Arrows. § String Diagrams, Monoidal Closed Categories. § Stream/Data Flow Programming.

Data-intensive vs control-intensive require quite different control techniques. [Berry, 2000] Spectral processing may open a new gap from all of those! Some related DSL: VOBLA, Ziria, Halide, Darkroom, Julia.

slide-23
SLIDE 23

DSP & Faust

§ Real-time Linear Processing. § Real-time Non-linear Processing. § Frequency Domain Processing. § Non-necessarily causal. § Filters, Feedback Networks, Interpolation. § Windowing! § Numerical issues. § Nyquist/precision/aliasing.

slide-24
SLIDE 24

Verification in DSP/Faust

Use mechanized techniques to ensure correct behavior.

slide-25
SLIDE 25

Verification in DSP/Faust

Use mechanized techniques to ensure correct behavior.

§ Model checking/automata. § Program analysis/logics. § Strong type systems/correct by construction.

slide-26
SLIDE 26

Verification in DSP/Faust

Use mechanized techniques to ensure correct behavior.

§ Model checking/automata. § Program analysis/logics. § Strong type systems/correct by construction. § Main efforts in DSP audio are numeric so far

[Souari,Tahar, et al].

slide-27
SLIDE 27

Verification in DSP/Faust

Use mechanized techniques to ensure correct behavior.

§ Model checking/automata. § Program analysis/logics. § Strong type systems/correct by construction. § Main efforts in DSP audio are numeric so far

[Souari,Tahar, et al].

§ Other non-DSP efforts (Antescofo, [Poncelet et. al]).

slide-28
SLIDE 28

Verification in DSP/Faust

Use mechanized techniques to ensure correct behavior.

§ Model checking/automata. § Program analysis/logics. § Strong type systems/correct by construction. § Main efforts in DSP audio are numeric so far

[Souari,Tahar, et al].

§ Other non-DSP efforts (Antescofo, [Poncelet et. al]).

Problems with Audio:

bad sound, stability/glitches, under/overflows, time, safety/security, remote distribution. We need more!

slide-29
SLIDE 29

A Case Study: Stability

Test-bed: use Coq Coq is a theorem prover that provides very strong evidence as compared to Mathlab, etc. . .

slide-30
SLIDE 30

A Case Study: Stability

Test-bed: use Coq Coq is a theorem prover that provides very strong evidence as compared to Mathlab, etc. . .

Stability of Smooth

When is smooth stable? smoothn “ p1 ´ cqxn ` c ¨ smoothn´1

slide-31
SLIDE 31

A Case Study: Stability

Test-bed: use Coq Coq is a theorem prover that provides very strong evidence as compared to Mathlab, etc. . .

Stability of Smooth

When is smooth stable? smoothn “ p1 ´ cqxn ` c ¨ smoothn´1 Smooth is stable when c Ps0, 1r. Formally: @i P ra, bs, c Ps0, 1rÑ smoothpcq i P ra, bs Let’s build a mechanized constructive proof.

slide-32
SLIDE 32

What’s the plan?

  • 1. Define the syntax of Faust inside Coq.
slide-33
SLIDE 33

What’s the plan?

  • 1. Define the syntax of Faust inside Coq.
  • 2. Define a representation for (sampled) sound.
slide-34
SLIDE 34

What’s the plan?

  • 1. Define the syntax of Faust inside Coq.
  • 2. Define a representation for (sampled) sound.
  • 3. Link the two: Interpretation.
slide-35
SLIDE 35

What’s the plan?

  • 1. Define the syntax of Faust inside Coq.
  • 2. Define a representation for (sampled) sound.
  • 3. Link the two: Interpretation.
  • 4. Define a logic to simplify reasoning.
slide-36
SLIDE 36

What’s the plan?

  • 1. Define the syntax of Faust inside Coq.
  • 2. Define a representation for (sampled) sound.
  • 3. Link the two: Interpretation.
  • 4. Define a logic to simplify reasoning.
  • 5. Verify!
slide-37
SLIDE 37

Mechanized Semantics for Streams

§ Coinductive semantics [Boulmé, et al]: problematic. § Didn’t consider PACO, etc. . . . § Our wish: Sequences S of a base type R [Auger2013]

slide-38
SLIDE 38

Mechanized Semantics for Streams

§ Coinductive semantics [Boulmé, et al]: problematic. § Didn’t consider PACO, etc. . . . § Our wish: Sequences S of a base type R [Auger2013]

Soundness needs stronger semantics (also [Guatto2014]): $ f : i Ñ on : R ˆ . . . ˆ R l jh n

i

n Ñ R ˆ . . . ˆ R l jh n

  • n

Index by number of steps; equality of streams more intensional wrt to (N Ñ R).

slide-39
SLIDE 39

The Second Piece: Real Analysis

What about the base type R?

§ Reals not in Mathcomp – algebraic structures good

enough for most of our experiments so far.

§ There are lots of work to do here. We lack convenient

complex numbers, exponentials, etc...

slide-40
SLIDE 40

The Second Piece: Real Analysis

What about the base type R?

§ Reals not in Mathcomp – algebraic structures good

enough for most of our experiments so far.

§ There are lots of work to do here. We lack convenient

complex numbers, exponentials, etc...

slide-41
SLIDE 41

Proving Stability

We could do the proof directly in Coq; it is not difficult, but a bit cumbersome in general. What is worse, the same patterns with minor variations are repeated in each proof: Not practical.

slide-42
SLIDE 42

Proving Stability

We could do the proof directly in Coq; it is not difficult, but a bit cumbersome in general. What is worse, the same patterns with minor variations are repeated in each proof: Not practical. To remedy this, we define a program logic for sample-level properties.

slide-43
SLIDE 43

Sampled-Level Predicates

Definition (Sample-Level Property)

A property P : S Ñ B is sample-level if there exists a characteristic predicate ϕ : R Ñ B such that for all streams s: Ppsq ð ñ @n.ϕpsrnsq

slide-44
SLIDE 44

Sampled-Level Predicates

Definition (Sample-Level Property)

A property P : S Ñ B is sample-level if there exists a characteristic predicate ϕ : R Ñ B such that for all streams s: Ppsq ð ñ @n.ϕpsrnsq Boundedness x P ra, bs is a sample-level property!

slide-45
SLIDE 45

Sampled-Level Predicates

Definition (Sample-Level Property)

A property P : S Ñ B is sample-level if there exists a characteristic predicate ϕ : R Ñ B such that for all streams s: Ppsq ð ñ @n.ϕpsrnsq Boundedness x P ra, bs is a sample-level property! Properties can be made sample-level by self-composition, e.g: ratio: f ñ xf, f 1y : { We can also prove this way equivalence of filter implementation.

slide-46
SLIDE 46

A Sampled Logic

Definition (Sampled Judgment)

Given two characteristic predicates ϕ, ψ, we write tϕu f tψu “for all input i meeting ϕ, the fi satisfies ψ.”

Example

The stability judgment for smooth is written as: tx P ra, bsu smooth tx P ra, bsu

slide-47
SLIDE 47

Rules for The Sampled Logic

@i1, i2, pϕ1pi1q ^ ϕ1pi2qq ù ñ ψpi1 ` i2q tϕ1, ϕ2u ` tψu Prim tϕu f tθu tθu g tψu tϕu f : g tψu Comp | ù ψpx0q tθ, ϕu f tψu tψu g tθu tϕu f „ g tψu Feed

slide-48
SLIDE 48

Soundness of the Logic

Definition (Validity)

tϕu f tψu ” @i.p@t.ϕpiptqqq ù ñ p@t, ψpfqpiqptqq

Theorem (Soundness)

For any program f of type i o, if tϕ1, . . . , ϕiu f tψ1, . . . , ψou is derivable then, tϕ1, . . . , ϕiu f tψ1, . . . , ψou is valid.

slide-49
SLIDE 49

Stability Proof for Smooth

l tIabu ˚p1 ´ cq tIabcu l tIabc, Iabcu ` tIabu l tIabu ˚pcq tIabcu tIabcu ` „ ˚pcq tIabu ti P ra, bsu ˚p1 ´ cq : ` „ ˚pcq to P ra, bsu with: Iabpxq ” x P ra, bs Iabcpxq ” x P ra ˚ c, b ˚ cs Iabcpxq ” x P ra ˚ p1 ´ cq, b ˚ p1 ´ cqs

slide-50
SLIDE 50

Stability of Smooth

Three main VC in the proof:

(* (1 - c) * i \in [(1 - c) * a, (1 - c) * b] *) by rewrite ?ler_wpmul2r ?ler_subr_addr ?add0r. have Ha: a = a ∗ c + a ∗ (1 ´ c) by rewrite ´mulrDr addrC addrNK mulr1. have Hb: b = b ∗ c + b ∗ (1 ´ c) by rewrite ´mulrDr addrC addrNK mulr1. by rewrite Ha Hb !ler_add. (* c * i \in [c * a, c * b] *) by rewrite ?ler_wpmul2r.

We pushed the VCs to Why3 with success. Interval technique ready to go into the main compiler.

slide-51
SLIDE 51

Stability Proof

slide-52
SLIDE 52

One Step Beyond

Extending the logic

Allow predicates to refer to windows. ϕpiq ” ti{il “ 0.8u where il is the sample produced in the execution step.

slide-53
SLIDE 53

Linear System Theory

Consider the following subset of Faust: ˚pcq scaling by c ` addition : composition „ addition Then every Faust program is LTI. Very related to [Bonchi et

  • al. 2015]

A consequence of that is that every program can be viewed as a polynomial.

slide-54
SLIDE 54

Two Poles IIR Filter

twopole = fir : + „ feedback where fir(x) = (x - x’’) * g * (1-RR) / 2; feedback(v) = 2*R*cos(T) * v - RR * v’; ....

slide-55
SLIDE 55

Two Poles IIR Filter

twopole = fir : + „ feedback where fir(x) = (x - x’’) * g * (1-RR) / 2; feedback(v) = 2*R*cos(T) * v - RR * v’; ....

Get and verify its transfer function: Hpzq “ 1 ´ z´2 1 ´ 2R cospΘcqz´1 ` R2z´2

slide-56
SLIDE 56

Ongoing: Frequency Domain Analysis

Recall the Fourier Matrix: W “ 1{ ? N » — — — — — – 1 1 1 ¨ ¨ ¨ 1 1 ω ω2 ¨ ¨ ¨ ωN´1 1 ω2 ω4 ¨ ¨ ¨ ω2pN´1q . . . . . . . . . ... . . . 1 ωN´1 ω2pN´1q ¨ ¨ ¨ ω pN´1qpN´1q fi ffi ffi ffi ffi ffi fl

  • r:

W “ ˆ ωjk ? N ˙

j,k“0,...,pN´1q

where ω the nth-root of the unity. Then the DFT can be expressed as: X “ Wx

slide-57
SLIDE 57

Fourier Properties Formally

Linearity, shifting and scaling follow from lemmas already in the MathComp linear algebra library! Parseval’s theorem is work in progress:

N´1

ÿ

n“0

|xn|2 “

N´1

ÿ

n“0

|Xn|2

slide-58
SLIDE 58

Transfer Functions

§ We can use a similar approach for the certification of

transfer functions.

§ We use the finite Z-transform, plus some caveats,

mainly about the bounds.

slide-59
SLIDE 59

Transfer Functions

§ We can use a similar approach for the certification of

transfer functions.

§ We use the finite Z-transform, plus some caveats,

mainly about the bounds.

§ C.f: Algebraic Signal Processing [Puesel, Moura]

Paper with our adventures coming end

  • f month.
slide-60
SLIDE 60

Conclusions

§ It was an interesting exercise; we learned a lot! § The full Faust language is basically done. § So far verification has been about math verification. § Floating point issues ignored. . . § Help from audio people. What are important things to

certify?

§ Non-Linear systems. § We are investigating a different approaches to

certification beyond program logics.

§ Verified FFT/DSP computation. Trying CoqEAL. § Improving the language for spectral processing. § Non-linear Wave Filter, Scattered Delays Networks.