Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
A Transformational Approach to Resource Analysis
with Typed-Norms
Elvira Albert1, Samir Genaim1, and Ra´ul Guti´errez2,3
1...
Motivation
Automated resource analysis needs to infer how the sizes of data are
modified along program’s execution.
Norms d...
Main Contribution
1 We propose a transformational approach to use multiple type-norms
in resource analysis:
1 transform th...
Outline
1 Leading Example
2 Size Abstraction using Typed-Norms
3 Inference of Typed-Norms
4 Experiments
5 Conclusions
Albe...
Example: A Simple Functional Language
1 def Int fibonacci(Int n)
2 = case (n <= 0) {
3 true => case n {
4 0 => 0 ;
5 1 => 1...
Intermediate Form: An Abstract Syntax
r ::= m(¯x, y) → g, b1, . . . , bn.
b ::= x:=t | m(¯x, y)
g ::= true | g ∧ g | e op ...
Example: Intermediate Representation
fibonacci list(xs,ys)
→ case0(xs,ys).
case0(xs,ys)
→ match(xs,Nil),
ys := Nil.
case0(x...
Outline
1 Leading Example
2 Size Abstraction using Typed-Norms
3 Inference of Typed-Norms
4 Experiments
5 Conclusions
Albe...
Term Size Norm
t ts =
1 + n
i=1 ti ts if t = Co(t1, . . . , tn)
1 otherwise
2 3 1 3 4 1 5 2 5 4
Example: Fibonacci List
Al...
Term Size Norm
t ts =
1 + n
i=1 ti ts if t = Co(t1, . . . , tn)
1 otherwise
2 3 1 3 4 1 5 2 5 4
Example: Fibonacci List
Al...
Term Size Norm
t ts =
1 + n
i=1 ti ts if t = Co(t1, . . . , tn)
1 otherwise
2 3 1 3 4 1 5 2 5 4
Example: Fibonacci List
Al...
Term Size Norm
t ts =
1 + n
i=1 ti ts if t = Co(t1, . . . , tn)
1 otherwise
2 3 1 3 4 1 5 2 5 4
Example: Fibonacci List
O(...
Typed-Norms
t σ =



t σ = Int and t is an integer
length(t) σ = String and t is an string
1 +
n
i=1 ti σ if t = Co...
Typed-Norms
t σ =



t σ = Int and t is an integer
length(t) σ = String and t is an string
1 +
n
i=1 ti σ if t = Co...
Typed-Norms
t σ =



t σ = Int and t is an integer
length(t) σ = String and t is an string
1 +
n
i=1 ti σ if t = Co...
Typed-Norms
t σ =



t σ = Int and t is an integer
length(t) σ = String and t is an string
1 +
n
i=1 ti σ if t = Co...
Typed-Norms
t σ =



t σ = Int and t is an integer
length(t) σ = String and t is an string
1 +
n
i=1 ti σ if t = Co...
Typed-Norms
t σ =



t σ = Int and t is an integer
length(t) σ = String and t is an string
1 +
n
i=1 ti σ if t = Co...
Size Abstraction Transformation
Given a program P, its size abstraction Pα is a program obtained by
replacing each rule p(...
Example: Size Abstraction
fibonacci list(xs,ys)
→ case0(xs,ys).
case0(xs,ys)
→ match(xs,Nil),
ys := Nil.
case0(xs,ys)
→ non...
Example: Size Abstraction
fibonacci list(xs,ys)
→ case0(xs,ys).
case0(xs,ys)
→ match(xs,Nil),
ys := Nil.
case0(xs,ys)
→ non...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(xs,ys)
→ match(xs,Nil),
ys :=...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Size Abstraction
fibonacci list(XSI ,XSL,YSI ,YSL)
→ case0(XSI ,XSL,YSI ,YSL).
case0(XSI ,XSL,YSI ,YSL)
→ {XSL = 1...
Example: Complexity
t σ =



t σ = Int and t is an integer
length(t) σ = String and t is an string
1 +
n
i=1 ti σ i...
Outline
1 Leading Example
2 Size Abstraction using Typed-Norms
3 Inference of Typed-Norms
4 Experiments
5 Conclusions
Albe...
Inference of Typed-Norms
Automated resource analysis needs to infer how the sizes of data are
modified along program’s exec...
Inference of Typed-Norms
Allowing multiple norms simultaneously give us more chances to
success, but the efficiency of the a...
Inference of Typed-Norms: Algorithm
Initialization. This step starts by setting typed norms(x) to ∅ for each
variable x in...
Inference of Typed-Norms: Algorithm
fibonacci list(xs∅,ys∅)
→ case0(xs∅,ys∅).
case0(xs∅,ys∅)
→ match(xs{L},Nil),
ys∅ := Nil...
Inference of Typed-Norms: Algorithm
Propagation. The initial information computed in the first step must
be propagated back...
Inference of Typed-Norms: Algorithm
fibonacci list(xs∅,ys∅)
→ case0(xs∅,ys∅).
case0(xs∅,ys∅)
→ match(xs{L},Nil),
ys∅ := Nil...
Inference of Typed-Norms: Algorithm
fibonacci list(xs∅,ys∅)
→ case0(xs∅,ys∅).
case0(xs{L},ys∅)
→ match(xs{L},Nil),
ys∅ := N...
Inference of Typed-Norms: Algorithm
fibonacci list(xs{L},ys∅)
→ case0(xs{L},ys∅).
case0(xs{L},ys∅)
→ match(xs{L},Nil),
ys∅ ...
Inference of Typed-Norms: Algorithm
fibonacci list(xs{L},ys∅)
→ case0(xs{L},ys∅).
case0(xs{L},ys∅)
→ match(xs{L},Nil),
ys∅ ...
Inference of Typed-Norms: Algorithm
fibonacci list(xs{L},ys∅)
→ case0(xs{L},ys∅).
case0(xs{I,L},ys∅)
→ match(xs{I,L},Nil),
...
Inference of Typed-Norms: Algorithm
fibonacci list(xs{I,L},ys∅)
→ case0(xs{I,L},ys∅).
case0(xs{I,L},ys∅)
→ match(xs{I,L},Ni...
Inference of Typed-Norms: Algorithm
fibonacci list(xs{I,L},ys∅)
→ case0(xs{I,L},ys∅).
case0(xs{I,L},ys∅)
→ match(xs{I,L},Ni...
Inference of Typed-Norms: Algorithm
fibonacci list(xs{I,L},ys∅)
→ case0(xs{I,L},ys∅).
case0(xs{I,L},ys∅)
→ match(xs{I,L},Ni...
Outline
1 Leading Example
2 Size Abstraction using Typed-Norms
3 Inference of Typed-Norms
4 Experiments
5 Conclusions
Albe...
Experiments
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
1.1
1.2
0 5 10 15 20 25 30 35
TypeNorm/TermSize
Albert, Genaim, Guti´e...
Experiments
The experiments have been performed on an Intel Core 2 Duo at 2.4GHz
with 8GB of RAM, running OS X 10.9.
Table...
Outline
1 Leading Example
2 Size Abstraction using Typed-Norms
3 Inference of Typed-Norms
4 Experiments
5 Conclusions
Albe...
Conclusions
We have presented a novel transformational approach to resource
analysis with typed-norms.
This transformation...
Upcoming SlideShare
Loading in …5
×

A Transformational Approach to Resource Analysis with Typed-Norms

162 views

Published on

In order to automatically infer the resource consumption of programs, analyzers track how data sizes change along a program’s execution. Typically, analyzers measure the sizes of data by applying norms which are mappings from data to natural numbers that represent the sizes of the corresponding data. When norms are defined by taking type information into account, they are named typed-norms. We define a transformational approach to resource analysis with typed-norms. The analysis is based on a transformation of the program into an intermediate abstract program in which each variable is abstracted with respect to all considered norms which are valid for its type. We also sketch a simple analysis that can be used to automatically infer the required, useful, typed-norms from programs.

Published in: Engineering
  • Be the first to comment

  • Be the first to like this

A Transformational Approach to Resource Analysis with Typed-Norms

  1. 1. A Transformational Approach to Resource Analysis with Typed-Norms Elvira Albert1, Samir Genaim1, and Ra´ul Guti´errez2,3 1Universidad Complutense de Madrid 2Universidad Polit´ecnica de Madrid 3Universitat Polit`ecnica de Val`encia Universidad Complutense de Madrid June 14, 2016 Madrid, Spain Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 1 / 25
  2. 2. Motivation Automated resource analysis needs to infer how the sizes of data are modified along program’s execution. Norms define how the size of term are computed (list-length, tree-depth, term-size, . . . ). Type-norms allow defining norms based on type information. The choice of the right norm is crucial to obtain a proof for termination and get accurate upper and lower bounds. Allowing multiple norms simultaneously give us more chances to success, but the efficiency of the analysis can be degraded considerably. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 2 / 25
  3. 3. Main Contribution 1 We propose a transformational approach to use multiple type-norms in resource analysis: 1 transform the program into an intermediate abstract program in which the relation among data and control flow are preserved, 2 from such intermediate abstract program, together with a the size relations, we obtain a cost relation system, in which each variable is abstracted with respect to all considered norms valid for its type, 3 if a solution if obtained from the cost relation system constraints (using a constraint solver), then the solution is transformed into upper and lower resource bounds automatically. 2 we outline an algorithm for the inference of typed-norms which can detect which norms are useful to later infer the resource consumption, and discard norms that are useless for this purpose. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 3 / 25
  4. 4. Outline 1 Leading Example 2 Size Abstraction using Typed-Norms 3 Inference of Typed-Norms 4 Experiments 5 Conclusions Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 4 / 25
  5. 5. Example: A Simple Functional Language 1 def Int fibonacci(Int n) 2 = case (n <= 0) { 3 true => case n { 4 0 => 0 ; 5 1 => 1 ; 6 m => fibonacci(m − 1) + fibonacci(m − 2) ; 7 } ; 8 false => −1 ; 9 }; 10 11 def List<Int> fibonacci list(List<Int> l) 12 = case l { 13 Nil => Nil ; 14 Cons(n,rest l) => Cons(fibonacci(n),fibonacci list(rest l)) ; 15 }; Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 5 / 25
  6. 6. Intermediate Form: An Abstract Syntax r ::= m(¯x, y) → g, b1, . . . , bn. b ::= x:=t | m(¯x, y) g ::= true | g ∧ g | e op e | match(x, t) | nonmatch(x, t) t ::= e | Co(¯t) e ::= x | n | e+e | e−e where op ∈ {>, =, ≥}, m(¯x, ¯y) is the head of the rule, g specifies the conditions for the rule to be applicable and b1, . . . , bn is the rule’s body. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 6 / 25
  7. 7. Example: Intermediate Representation fibonacci list(xs,ys) → case0(xs,ys). case0(xs,ys) → match(xs,Nil), ys := Nil. case0(xs,ys) → nonmatch(xs,Nil), match(xs,Cons(n,zs)), fibonacci(n,x), fibonacci list(zs,ws), ys := Cons(x,ws). fibonacci(n,m) → x := 0, case1(x,n,m). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 7 / 25
  8. 8. Outline 1 Leading Example 2 Size Abstraction using Typed-Norms 3 Inference of Typed-Norms 4 Experiments 5 Conclusions Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 8 / 25
  9. 9. Term Size Norm t ts = 1 + n i=1 ti ts if t = Co(t1, . . . , tn) 1 otherwise 2 3 1 3 4 1 5 2 5 4 Example: Fibonacci List Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 9 / 25
  10. 10. Term Size Norm t ts = 1 + n i=1 ti ts if t = Co(t1, . . . , tn) 1 otherwise 2 3 1 3 4 1 5 2 5 4 Example: Fibonacci List Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 9 / 25
  11. 11. Term Size Norm t ts = 1 + n i=1 ti ts if t = Co(t1, . . . , tn) 1 otherwise 2 3 1 3 4 1 5 2 5 4 Example: Fibonacci List Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 9 / 25
  12. 12. Term Size Norm t ts = 1 + n i=1 ti ts if t = Co(t1, . . . , tn) 1 otherwise 2 3 1 3 4 1 5 2 5 4 Example: Fibonacci List O(lts × 2lts ) Complexity (Upper Bound): Fibonacci List Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 9 / 25
  13. 13. Typed-Norms t σ =    t σ = Int and t is an integer length(t) σ = String and t is an string 1 + n i=1 ti σ if t = Co(t1, . . . , tn) and type(t) = σ n i=1 ti σ if t = Co(t1, . . . , tn) and type(t) = σ 2 3 1 3 4 1 5 2 5 4 Example: Fibonacci List Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 10 / 25
  14. 14. Typed-Norms t σ =    t σ = Int and t is an integer length(t) σ = String and t is an string 1 + n i=1 ti σ if t = Co(t1, . . . , tn) and type(t) = σ n i=1 ti σ if t = Co(t1, . . . , tn) and type(t) = σ 2 3 1 3 4 1 5 2 5 4 Example: Fibonacci List Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 10 / 25
  15. 15. Typed-Norms t σ =    t σ = Int and t is an integer length(t) σ = String and t is an string 1 + n i=1 ti σ if t = Co(t1, . . . , tn) and type(t) = σ n i=1 ti σ if t = Co(t1, . . . , tn) and type(t) = σ 2 3 1 3 4 1 5 2 5 4 Example: Fibonacci List Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 10 / 25
  16. 16. Typed-Norms t σ =    t σ = Int and t is an integer length(t) σ = String and t is an string 1 + n i=1 ti σ if t = Co(t1, . . . , tn) and typet = σ maxn i=1 ti σ if t = Co(t1, . . . , tn) and typet = σ 2 3 1 3 4 1 5 2 5 4 Example: Fibonacci List Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 11 / 25
  17. 17. Typed-Norms t σ =    t σ = Int and t is an integer length(t) σ = String and t is an string 1 + n i=1 ti σ if t = Co(t1, . . . , tn) and typet = σ maxn i=1 ti σ if t = Co(t1, . . . , tn) and typet = σ 2 3 1 3 4 1 5 2 5 4 Example: Fibonacci List Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 11 / 25
  18. 18. Typed-Norms t σ =    t σ = Int and t is an integer length(t) σ = String and t is an string 1 + n i=1 ti σ if t = Co(t1, . . . , tn) and typet = σ maxn i=1 ti σ if t = Co(t1, . . . , tn) and typet = σ 2 3 1 3 4 1 5 2 5 4 Example: Fibonacci List Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 11 / 25
  19. 19. Size Abstraction Transformation Given a program P, its size abstraction Pα is a program obtained by replacing each rule p(x, y) → g, b1, . . . , bn ∈ P by p(X, Y ) → gα, bα 1 , . . . , bα n where: g1 ∧ g2 is transformed into gα 1 ∧ gα 2 , nonmatch(x, t) is transformed into true, p(¯x, ¯y) is transformed into p( ¯X, ¯Y ), match(x, t) and x := t is transformed into ∧{Xσ = t σ | σ ∈ typed norms(x)}, where typed norms(x) corresponds to the set of types we want x to be measured, e1 op e2 is transformed into (e1 op e2)[y/YInt] if Int ∈ typed norms(x) and true otherwise. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 12 / 25
  20. 20. Example: Size Abstraction fibonacci list(xs,ys) → case0(xs,ys). case0(xs,ys) → match(xs,Nil), ys := Nil. case0(xs,ys) → nonmatch(xs,Nil), match(xs,Cons(n,zs)) fibonacci(n,x), fibonacci list(zs,ws), ys := Cons(x,ws) fibonacci(n,m) → x := 0, case1(x,n,m). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  21. 21. Example: Size Abstraction fibonacci list(xs,ys) → case0(xs,ys). case0(xs,ys) → match(xs,Nil), ys := Nil. case0(xs,ys) → nonmatch(xs,Nil), match(xs,Cons(n,zs)) fibonacci(n,x), fibonacci list(zs,ws), ys := Cons(x,ws) fibonacci(n,m) → x := 0, case1(x,n,m). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  22. 22. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(xs,ys) → match(xs,Nil), ys := Nil. case0(xs,ys) → nonmatch(xs,Nil), match(xs,Cons(n,zs)) fibonacci(n,x), fibonacci list(zs,ws), ys := Cons(x,ws) fibonacci(n,m) → x := 0, case1(x,n,m). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  23. 23. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, ys := Nil. case0(xs,ys) → nonmatch(xs,Nil), match(xs,Cons(n,zs)) fibonacci(n,x), fibonacci list(zs,ws), ys := Cons(x,ws) fibonacci(n,m) → x := 0, case1(x,n,m). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. {YSL = 1}, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  24. 24. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(xs,ys) → nonmatch(xs,Nil), match(xs,Cons(n,zs)) fibonacci(n,x), fibonacci list(zs,ws), ys := Cons(x,ws) fibonacci(n,m) → x := 0, case1(x,n,m). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. case0(XSI ,XSL,YSI ,YSL) → true, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  25. 25. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → match(xs,Cons(n,zs)) fibonacci(n,x), fibonacci list(zs,ws), ys := Cons(x,ws) fibonacci(n,m) → x := 0, case1(x,n,m). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  26. 26. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(n,x), fibonacci list(zs,ws), ys := Cons(x,ws) fibonacci(n,m) → x := 0, case1(x,n,m). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. fibonacci(NI ,XI ), Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  27. 27. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(zs,ws), ys := Cons(x,ws) fibonacci(n,m) → x := 0, case1(x,n,m). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. fibonacci list(ZSI ,ZSL,WSI ,WSL), Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  28. 28. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), ys := Cons(x,ws) fibonacci(n,m) → x := 0, case1(x,n,m). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  29. 29. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(n,m) → x := 0, case1(x,n,m). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. fibonacci(NI ,MI ) → {XI = 0}, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  30. 30. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(x,n,m). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. case1(XI ,NI ,MI ). Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  31. 31. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(x,n,m) → n ≥ x, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. case1(XI ,NI ,MI ) → {NI ≥ XI }, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  32. 32. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(n,m). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. case2(NI ,MI ). Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  33. 33. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(x,n,m) → n < x, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  34. 34. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, m := -1. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. {MI = −1}. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  35. 35. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(n,m) → match(n,0), m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. case2(NI ,MI ) → {NI = 0}, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  36. 36. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(NI ,MI ) → {NI = 0}, m := 0. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. {MI = 0}. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  37. 37. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(NI ,MI ) → {NI = 0}, {MI = 0}. case2(n,m) → nonmatch(n,0), match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. case2(NI ,MI ) → true, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  38. 38. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(NI ,MI ) → {NI = 0}, {MI = 0}. case2(NI ,MI ) match(n,1), m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. {NI = 1}, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  39. 39. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(NI ,MI ) → {NI = 0}, {MI = 0}. case2(NI ,MI ) {NI = 1}, m := 1. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. {MI = 1}. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  40. 40. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(NI ,MI ) → {NI = 0}, {MI = 0}. case2(NI ,MI ) {NI = 1}, {MI = 1}. case2(n,m) → nonmatch(n,0), nonmatch(n,1), match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. case2(NI ,MI ) → true, true, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  41. 41. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(NI ,MI ) → {NI = 0}, {MI = 0}. case2(NI ,MI ) {NI = 1}, {MI = 1}. case2(NI ,MI ) → match(n,x), y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. {NI = XI }, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  42. 42. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(NI ,MI ) → {NI = 0}, {MI = 0}. case2(NI ,MI ) {NI = 1}, {MI = 1}. case2(NI ,MI ) → {NI = XI }, y := x - 1, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. {YI = XI − 1}, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  43. 43. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(NI ,MI ) → {NI = 0}, {MI = 0}. case2(NI ,MI ) {NI = 1}, {MI = 1}. case2(NI ,MI ) → {NI = XI }, {YI = XI − 1}, fibonacci(y,z), v := x - 2, fibonacci(v,w), m := z + w. fibonacci(YI ,ZI ), Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  44. 44. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(NI ,MI ) → {NI = 0}, {MI = 0}. case2(NI ,MI ) {NI = 1}, {MI = 1}. case2(NI ,MI ) → {NI = XI }, {YI = XI − 1}, fibonacci(YI ,ZI ), v := x - 2, fibonacci(v,w), m := z + w. {VI = XI − 2}, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  45. 45. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(NI ,MI ) → {NI = 0}, {MI = 0}. case2(NI ,MI ) {NI = 1}, {MI = 1}. case2(NI ,MI ) → {NI = XI }, {YI = XI − 1}, fibonacci(YI ,ZI ), {VI = XI − 2}, fibonacci(v,w), m := z + w. fibonacci(VI ,WI ), Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  46. 46. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(NI ,MI ) → {NI = 0}, {MI = 0}. case2(NI ,MI ) {NI = 1}, {MI = 1}. case2(NI ,MI ) → {NI = XI }, {YI = XI − 1}, fibonacci(YI ,ZI ), {VI = XI − 2}, fibonacci(VI ,WI ), m := z + w. {MI = ZI + WI }, Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  47. 47. Example: Size Abstraction fibonacci list(XSI ,XSL,YSI ,YSL) → case0(XSI ,XSL,YSI ,YSL). case0(XSI ,XSL,YSI ,YSL) → {XSL = 1}, {YSL = 1}. case0(XSI ,XSL,YSI ,YSL) → {XSI ≥ NI , XSI ≥ ZSI , XSL = ZSL + 1, ZSL ≥ 1}, fibonacci(NI ,XI ), fibonacci list(ZSI ,ZSL,WSI ,WSL), {YSI ≥ XI , YSI ≥ WSI , YSL = WSL + 1, WSL ≥ 1}, fibonacci(NI ,MI ) → {XI = 0}, case1(XI ,NI ,MI ). case1(XI ,NI ,MI ) → {NI ≥ XI }, case2(NI ,MI ). case1(XI ,NI ,MI ) → {XI ≥ NI + 1}, {MI = −1}. case2(NI ,MI ) → {NI = 0}, {MI = 0}. case2(NI ,MI ) {NI = 1}, {MI = 1}. case2(NI ,MI ) → {NI = XI }, {YI = XI − 1}, fibonacci(YI ,ZI ), {VI = XI − 2}, fibonacci(VI ,WI ), {MI = ZI + WI }. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 13 / 25
  48. 48. Example: Complexity t σ =    t σ = Int and t is an integer length(t) σ = String and t is an string 1 + n i=1 ti σ if t = Co(t1, . . . , tn) and typet = σ maxn i=1 ti σ if t = Co(t1, . . . , tn) and typet = σ 2 3 1 3 4 1 5 2 5 4 Example: Fibonacci List O(lList<Int> × 2lInt ) Complexity (Upper Bound): Fibonacci List Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 14 / 25
  49. 49. Outline 1 Leading Example 2 Size Abstraction using Typed-Norms 3 Inference of Typed-Norms 4 Experiments 5 Conclusions Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 15 / 25
  50. 50. Inference of Typed-Norms Automated resource analysis needs to infer how the sizes of data are modified along program’s execution. Norms define how the size of term are computed (list-length, tree-depth, term-size, . . . ). Type-norms allow defining norms based on type information. The choice of the right norm is crucial to obtain a proof for termination and get accurate upper and lower bounds. Allowing multiple norms simultaneously give us more chances to success, but the efficiency of the analysis can be degraded considerably. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 16 / 25
  51. 51. Inference of Typed-Norms Allowing multiple norms simultaneously give us more chances to success, but the efficiency of the analysis can be degraded considerably. Goal: develop an analysis that eliminates useless abstractions: Remove variables that do not affect the cost. Remove useless (typed) size information. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 16 / 25
  52. 52. Inference of Typed-Norms: Algorithm Initialization. This step starts by setting typed norms(x) to ∅ for each variable x in the program. Then, it identifies the set of cost-significant guards, and uses each such guard to modify related typed norms(x) as follows: If the guard is match(x, t), variable x has a type T, and T is a recursive type, then T is added to typed norms(x). If the guard is of the form e1 op e2, and variable x appears in e1 or e2, then Int is added to typed norms(x). Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 17 / 25
  53. 53. Inference of Typed-Norms: Algorithm fibonacci list(xs∅,ys∅) → case0(xs∅,ys∅). case0(xs∅,ys∅) → match(xs{L},Nil), ys∅ := Nil. case0(xs∅,ys∅) → nonmatch(xs∅,Nil), match(xs{L},Cons(n∅,zs∅)), fibonacci(n∅,x∅), fibonacci list(zs∅,ws∅), ys∅ := Cons(x∅,ws∅). fibonacci(n∅,m∅) → x∅ := 0, case1(x∅,n∅,m∅). case1(x∅,n∅,m∅) → n{I} ≥ x{I}, case2(n∅,m∅). case1(x∅,n∅,m∅) → n{I} < x{I}, m∅ := -1. case2(n∅,m∅) → match(n{I},0), m∅ := 0. case2(n∅,m∅) → nonmatch(n∅,0), match(n{I},1), m∅ := 1. case2(n∅,m∅) → nonmatch(n∅,0), nonmatch(n∅,1), match(n{I},x∅), y := x∅ - 1, fibonacci(y∅,z∅), v∅ := x∅ - 2, fibonacci(v∅,w∅), m := z∅ + w∅. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 18 / 25
  54. 54. Inference of Typed-Norms: Algorithm Propagation. The initial information computed in the first step must be propagated backwards to other variables in the program: For match(x,t) and nonmatch(x,t), if y in vars(t), and T in typed norms(y), then we add T to typed norms(x). For x := t, if T in typed norms(x) we add T to typed norms(y) for each variable y in vars(t) as far as type(y) ≤ T. Built-in functions propagate norms to its arguments. All other instructions do not modify any information. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 19 / 25
  55. 55. Inference of Typed-Norms: Algorithm fibonacci list(xs∅,ys∅) → case0(xs∅,ys∅). case0(xs∅,ys∅) → match(xs{L},Nil), ys∅ := Nil. case0(xs∅,ys∅) → nonmatch(xs∅,Nil), match(xs{L},Cons(n∅,zs∅)), fibonacci(n∅,x∅), fibonacci list(zs∅,ws∅), ys∅ := Cons(x∅,ws∅). fibonacci(n∅,m∅) → x∅ := 0, case1(x∅,n∅,m∅). case1(x∅,n∅,m∅) → n{I} ≥ x{I}, case2(n∅,m∅). case1(x∅,n∅,m∅) → n{I} < x{I}, m∅ := -1. case2(n∅,m∅) → match(n{I},0), m∅ := 0. case2(n∅,m∅) → nonmatch(n∅,0), match(n{I},1), m∅ := 1. case2(n∅,m∅) → nonmatch(n∅,0), nonmatch(n∅,1), match(n{I},x∅), y∅ := x∅ - 1, fibonacci(y∅,z∅), v∅ := x∅ - 2, fibonacci(v∅,w∅), m∅ := z∅ + w∅. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 20 / 25
  56. 56. Inference of Typed-Norms: Algorithm fibonacci list(xs∅,ys∅) → case0(xs∅,ys∅). case0(xs{L},ys∅) → match(xs{L},Nil), ys∅ := Nil. case0(xs{L},ys∅) → nonmatch(xs{L},Nil), match(xs{L},Cons(n∅,zs∅)), fibonacci(n∅,x∅), fibonacci list(zs∅,ws∅), ys∅ := Cons(x∅,ws∅). fibonacci(n∅,m∅) → x∅ := 0, case1(x∅,n∅,m∅). case1(x{I},n{I},m∅) → n{I} ≥ x{I}, case2(n{I},m∅). case1(x{I},n{I},m∅) → n{I} < x{I}, m∅ := -1. case2(n{I},m∅) → match(n{I},0), m∅ := 0. case2(n{I},m∅) → nonmatch(n{I},0), match(n{I},1), m∅ := 1. case2(n{I},m∅) → nonmatch(n{I},0), nonmatch(n{I},1), match(n{I},x∅), y∅ := x∅ - 1, fibonacci(y∅,z∅), v∅ := x∅ - 2, fibonacci(v∅,w∅), m∅ := z∅ + w∅. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 20 / 25
  57. 57. Inference of Typed-Norms: Algorithm fibonacci list(xs{L},ys∅) → case0(xs{L},ys∅). case0(xs{L},ys∅) → match(xs{L},Nil), ys∅ := Nil. case0(xs{L},ys∅) → nonmatch(xs{L},Nil), match(xs{L},Cons(n∅,zs∅)), fibonacci(n∅,x∅), fibonacci list(zs∅,ws∅), ys∅ := Cons(x∅,ws∅). fibonacci(n{I},m∅) → x{I} := 0, case1(x{I},n{I},m∅). case1(x{I},n{I},m∅) → n{I} ≥ x{I}, case2(n{I},m∅). case1(x{I},n{I},m∅) → n{I} < x{I}, m∅ := -1. case2(n{I},m∅) → match(n{I},0), m∅ := 0. case2(n{I},m∅) → nonmatch(n{I},0), match(n{I},1), m∅ := 1. case2(n{I},m∅) → nonmatch(n{I},0), nonmatch(n{I},1), match(n{I},x∅), y∅ := x∅ - 1, fibonacci(y∅,z∅), v∅ := x∅ - 2, fibonacci(v∅,w∅), m∅ := z∅ + w∅. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 20 / 25
  58. 58. Inference of Typed-Norms: Algorithm fibonacci list(xs{L},ys∅) → case0(xs{L},ys∅). case0(xs{L},ys∅) → match(xs{L},Nil), ys∅ := Nil. case0(xs{L},ys∅) → nonmatch(xs{L},Nil), match(xs{L},Cons(n{I},zs{L})), fibonacci(n{I},x∅), fibonacci list(zs{L},ws∅), ys∅ := Cons(x∅,ws∅). fibonacci(n{I},m∅) → x{I} := 0, case1(x{I},n{I},m∅). case1(x{I},n{I},m∅) → n{I} ≥ x{I}, case2(n{I},m∅). case1(x{I},n{I},m∅) → n{I} < x{I}, m∅ := -1. case2(n{I},m∅) → match(n{I},0), m∅ := 0. case2(n{I},m∅) → nonmatch(n{I},0), match(n{I},1), m∅ := 1. case2(n{I},m∅) → nonmatch(n{I},0), nonmatch(n{I},1), match(n{I},x∅), y{I} := x∅ - 1, fibonacci(y{I},z∅), v{I} := x∅ - 2, fibonacci(v{I},w∅), m∅ := z∅ + w∅. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 20 / 25
  59. 59. Inference of Typed-Norms: Algorithm fibonacci list(xs{L},ys∅) → case0(xs{L},ys∅). case0(xs{I,L},ys∅) → match(xs{I,L},Nil), ys∅ := Nil. case0(xs{I,L},ys∅) → nonmatch(xs{I,L},Nil), match(xs{I,L},Cons(n{I},zs{L})), fibonacci(n{I},x∅), fibonacci list(zs{L},ws∅), ys∅ := Cons(x∅,ws∅). fibonacci(n{I},m∅) → x{I} := 0, case1(x{I},n{I},m∅). case1(x{I},n{I},m∅) → n{I} ≥ x{I}, case2(n{I},m∅). case1(x{I},n{I},m∅) → n{I} < x{I}, m∅ := -1. case2(n{I},m∅) → match(n{I},0), m∅ := 0. case2(n{I},m∅) → nonmatch(n{I},0), match(n{I},1), m∅ := 1. case2(n{I},m∅) → nonmatch(n{I},0), nonmatch(n{I},1), match(n{I},x{I}), y{I} := x{I} - 1, fibonacci(y{I},z∅), v{I} := x{I} - 2, fibonacci(v{I},w∅), m∅ := z∅ + w∅. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 20 / 25
  60. 60. Inference of Typed-Norms: Algorithm fibonacci list(xs{I,L},ys∅) → case0(xs{I,L},ys∅). case0(xs{I,L},ys∅) → match(xs{I,L},Nil), ys∅ := Nil. case0(xs{I,L},ys∅) → nonmatch(xs{I,L},Nil), match(xs{I,L},Cons(n{I},zs{L})), fibonacci(n{I},x∅), fibonacci list(zs{L},ws∅), ys∅ := Cons(x∅,ws∅). fibonacci(n{I},m∅) → x{I} := 0, case1(x{I},n{I},m∅). case1(x{I},n{I},m∅) → n{I} ≥ x{I}, case2(n{I},m∅). case1(x{I},n{I},m∅) → n{I} < x{I}, m∅ := -1. case2(n{I},m∅) → match(n{I},0), m∅ := 0. case2(n{I},m∅) → nonmatch(n{I},0), match(n{I},1), m∅ := 1. case2(n{I},m∅) → nonmatch(n{I},0), nonmatch(n{I},1), match(n{I},x{I}), y{I} := x{I} - 1, fibonacci(y{I},z∅), v{I} := x{I} - 2, fibonacci(v{I},w∅), m∅ := z∅ + w∅. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 20 / 25
  61. 61. Inference of Typed-Norms: Algorithm fibonacci list(xs{I,L},ys∅) → case0(xs{I,L},ys∅). case0(xs{I,L},ys∅) → match(xs{I,L},Nil), ys∅ := Nil. case0(xs{I,L},ys∅) → nonmatch(xs{I,L},Nil), match(xs{I,L},Cons(n{I},zs{I,L})), fibonacci(n{I},x∅), fibonacci list(zs{I,L},ws∅), ys∅ := Cons(x∅,ws∅). fibonacci(n{I},m∅) → x{I} := 0, case1(x{I},n{I},m∅). case1(x{I},n{I},m∅) → n{I} ≥ x{I}, case2(n{I},m∅). case1(x{I},n{I},m∅) → n{I} < x{I}, m∅ := -1. case2(n{I},m∅) → match(n{I},0), m∅ := 0. case2(n{I},m∅) → nonmatch(n{I},0), match(n{I},1), m∅ := 1. case2(n{I},m∅) → nonmatch(n{I},0), nonmatch(n{I},1), match(n{I},x{I}), y{I} := x{I} - 1, fibonacci(y{I},z∅), v{I} := x{I} - 2, fibonacci(v{I},w∅), m∅ := z∅ + w∅. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 20 / 25
  62. 62. Inference of Typed-Norms: Algorithm fibonacci list(xs{I,L},ys∅) → case0(xs{I,L},ys∅). case0(xs{I,L},ys∅) → match(xs{I,L},Nil), ys∅ := Nil. case0(xs{I,L},ys∅) → nonmatch(xs{I,L},Nil), match(xs{I,L},Cons(n{I},zs{I,L})), fibonacci(n{I},x∅), fibonacci list(zs{I,L},ws∅), ys∅ := Cons(x∅,ws∅). fibonacci(n{I},m∅) → x{I} := 0, case1(x{I},n{I},m∅). case1(x{I},n{I},m∅) → n{I} ≥ x{I}, case2(n{I},m∅). case1(x{I},n{I},m∅) → n{I} < x{I}, m∅ := -1. case2(n{I},m∅) → match(n{I},0), m∅ := 0. case2(n{I},m∅) → nonmatch(n{I},0), match(n{I},1), m∅ := 1. case2(n{I},m∅) → nonmatch(n{I},0), nonmatch(n{I},1), match(n{I},x{I}), y{I} := x{I} - 1, fibonacci(y{I},z∅), v{I} := x{I} - 2, fibonacci(v{I},w∅), m∅ := z∅ + w∅. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 20 / 25
  63. 63. Outline 1 Leading Example 2 Size Abstraction using Typed-Norms 3 Inference of Typed-Norms 4 Experiments 5 Conclusions Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 21 / 25
  64. 64. Experiments 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 0 5 10 15 20 25 30 35 TypeNorm/TermSize Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 22 / 25
  65. 65. Experiments The experiments have been performed on an Intel Core 2 Duo at 2.4GHz with 8GB of RAM, running OS X 10.9. Table: Run-Time statistics (in ms.) on 61 functions: (1) using term-size; (2) using all type-norms; and (3) using only significant typed-norms. Total is Tsa+Tac +Tub. Configuration Tsa Av. Tsa Tac Av. Tac Tub Av. Tub Total (1) 0 0 120 2 3911 65 4031 (2) 1633 27 631 11 14230 234 16494 (3) 2161 36 255 5 4488 74 6904 Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 23 / 25
  66. 66. Outline 1 Leading Example 2 Size Abstraction using Typed-Norms 3 Inference of Typed-Norms 4 Experiments 5 Conclusions Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 24 / 25
  67. 67. Conclusions We have presented a novel transformational approach to resource analysis with typed-norms. This transformation has the advantage that its formalization can be done by only adapting the first phase of cost analysis in which the program is transformed into an intermediate abstract program. We also outlined an algorithm for the inference of typed-norms which can detect automatically which norms are useful to later infer the resource consumption. Albert, Genaim, Guti´errez Resource Analysis with Typed-Norms UCM - Madrid 25 / 25

×