ImageVerifierCode 换一换
格式:PPT , 页数:105 ,大小:513.29KB ,
资源ID:377949      下载积分:2000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-377949.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Abstract Refinement Types.ppt)为本站会员(orderah291)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

Abstract Refinement Types.ppt

1、Abstract Refinement Types,Niki Vazou1, Patrick M. Rondon2, and Ranjit Jhala1 1UC San Diego 2Google,1,Vanilla Types,12 : Int,2,Refinement Types,12 : v: Int | v 10 ,3,Refinement Types,12 : v: Int | v = 12 ,4,Refinement Types,12 : v: Int | v = 12 ,v = 12 0 v 20 even v,5,Refinement Types,12 : : v: Int |

2、 v = 12 : v: Int | 0 v 20 even v ,v = 12 0 v 20 even v,6,Refinement Types,12 : : v: Int | v = 12 12 : : v: Int | 0 v 20 even v ,7,A max function,max : Int - Int - Intmax x y = if x y then x else y,8,A refined max function,max:x:Int - y:Int - v:Int | v x v ymax x y = if x y then x else y,9,Using max,

3、max:x:Int - y:Int - v:Int | v x v ymax x y = if x y then x else y,b = max 8 12 - assert (b 0),max 8 12 : v : Int | v x v y 8/x12/y,10,Using max,max:x:Int - y:Int - v:Int | v x v ymax x y = if x y then x else y,max 8 12 : v : Int | v 8 v 12 ,11,b = max 8 12 - assert (b 0),Using max,max:x:Int - y:Int

4、- v:Int | v x v ymax x y = if x y then x else y,max 8 12 : v : Int | v 12 ,12,b = max 8 12 - assert (b 0),Using max,max:x:Int - y:Int - v:Int | v x v ymax x y = if x y then x else y,v 12 v 0,13,b = max 8 12 - assert (b 0),Using max,max:x:Int - y:Int - v:Int | v x v ymax x y = if x y then x else y,ma

5、x 8 12 : v : Int | v 0 ,14,b = max 8 12 - assert (b 0),b = max 8 12 - assert (b 0),Using max,max:x:Int - y:Int - v:Int | v x v ymax x y = if x y then x else y,max 8 12 : v : Int | v 0 ,15,Using max,max:x:Int - y:Int - v:Int | v x v ymax x y = if x y then x else y,We get max 3 5 : v : Int | v 5 ,We w

6、antmax 3 5 : v : Int | v 5 odd v ,16,b = max 8 12 - assert (b 0)c = max 3 5 - assert (odd c),Using max,Problem: Information of Input Refinements is Lost,We get max 3 5 : v : Int | v 5 ,17,We wantmax 3 5 : v : Int | v 5 odd v ,Problem: Information of Input Refinements is Lost,Solution: Parameterize T

7、ype Over Input Refinement,Our Solution,18,Abstract Refinements,Solution: Parameterize Type Over Input Refinement,max:forall Prop. Int - Int - Intmax x y = if x y then x else y,19,Abstract Refinements,Solution: Parameterize Type Over Input Refinement,max:forall Prop. Int - Int - Intmax x y = if x y t

8、hen x else y,20,Abstract refinement,“if both arguments satisfy p, then the result satisfies p”,Abstract Refinements,Solution: Parameterize Type Over Input Refinement,max:forall Prop. Int - Int - Intmax x y = if x y then x else y,21,Abstract refinement,“if both arguments satisfy p, then the result sa

9、tisfies p”,Abstract Refinements,Solution: Parameterize Type Over Input Refinement,max:forall Prop. Int - Int - Intmax x y = if x y then x else y,22,Abstract refinement,“if both arguments satisfy p, then the result satisfies p”,Abstract Refinements,Solution: Parameterize Type Over Input Refinement,ma

10、x:forall Prop. Int - Int - Intmax x y = if x y then x else y,23,Abstract refinement,“if both arguments satisfy p, then the result satisfies p”,Using max,max:forall Prop. Int - Int - Intmax x y = if x y then x else y,max : forall Prop. Int - Int - Int,24,b = max (0) 8 12 - assert (b 0)c = max odd 3 5

11、 - assert (odd c),Using max,max:forall Prop. Int - Int - Intmax x y = if x y then x else y,max : forall Prop. Int - Int - Int,25,b = max (0) 8 12 - assert (b 0)c = max odd 3 5 - assert (odd c),Using max,max:forall Prop. Int - Int - Intmax x y = if x y then x else y,max odd : Int - Int - Int odd/p,26

12、,Using max,max:forall Prop. Int - Int - Intmax x y = if x y then x else y,max odd : v:Int | odd v - v:Int | odd v - v:Int | odd v ,27,Using max,max:forall Prop. Int - Int - Intmax x y = if x y then x else y,3 : v:Int | odd v ,max odd : v:Int | odd v - v:Int | odd v - v:Int | odd v ,28,Using max,max:

13、forall Prop. Int - Int - Intmax x y = if x y then x else y,max odd 3 : v:Int | odd v - v:Int | odd v ,3 : v:Int | odd v ,29,b = max (0) 8 12 - assert (b 0)c = max odd 3 5 - assert (odd c),Using max,max:forall Prop. Int - Int - Intmax x y = if x y then x else y,max odd 3 : v:Int | odd v - v:Int | odd

14、 v ,5 : v:Int | odd v ,30,b = max (0) 8 12 - assert (b 0)c = max odd 3 5 - assert (odd c),Using max,max:forall Prop. Int - Int - Intmax x y = if x y then x else y,max odd 3 5 : v:Int | odd v ,5 : v:Int | odd v ,31,b = max (0) 8 12 - assert (b 0)c = max odd 3 5 - assert (odd c),Using max,max:forall P

15、rop. Int - Int - Intmax x y = if x y then x else y,max odd 3 5 : v:Int | odd v ,32,b = max (0) 8 12 - assert (b 0)c = max odd 3 5 - assert (odd c),Abstract Refinements,Solution: Parameterize Type Over Input Refinement,max:forall Prop. Int - Int - Intmax x y = if x y then x else y,33,Abstract refinem

16、ent,“if both arguments satisfy p, then the result satisfies p”,Outline,Evaluation,Applications,Refinements and Type Classes,Inductive Refinements,Indexed Refinements,Recursive Refinements,34,Outline,Evaluation,Applications,Refinements and Type Classes,Inductive Refinements,Indexed Refinements,Recurs

17、ive Refinements,35,Outline,Evaluation,Applications,Refinements and Type Classes,Inductive Refinements,Indexed Refinements,Recursive Refinements,36,A polymorphic max function,max : a - a - amax x y = if x y then x else y,We get max v:Int | odd v 3 5 : v:Int | odd v ,We instantiate a := v:Int | odd v

18、,37,c = max 3 5 - assert (odd c),Type Class Constraints,max : Ord a = a - a - amax x y = if x y then x else y,We get max v:Int | odd v 3 5 : v:Int | odd v ,We instantiate a := v:Int | odd v ,38,c = max 3 5 - assert (odd c),b = max 3 5 - assert (odd b)c = minus 3 5 - assert (odd c),Unsound Reasoning,

19、minus : Num a = a - a - aminus x y = x - y,We get minus v:Int | odd v 3 5 : v:Int | odd v ,We instantiate a := v:Int | odd v ,Abstract Refinements and Type Classes,max :forall Prop. Ord a = a - a - amax x y = if x y then x else y,We get max Int odd 3 5 : v:Int | odd v ,40,b = max Int odd 3 5- assert

20、 (odd b),Abstract Refinements and Type Classes,41,b = max Int odd 3 5 - assert (odd b)c = minus Int 3 5 - assert (odd b),minus : Num a = a - a - aminus x y = x - y,We get minus Int 3 5 : Int,Outline,Evaluation,Applications,Refinements and Type Classes,Inductive Refinements,Indexed Refinements,Recurs

21、ive Refinements,42,Outline,Evaluation,Applications,Refinements and Type Classes,Inductive Refinements,Indexed Refinements,Recursive Refinements,43,A loop function,44,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = acc,A loop function,loop

22、: (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = acc,45,loop iteration,next acc,final result,A loop function,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = acc,46,initial index,loop f

23、 n z = fn(z),initial acc,A loop function,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = acc,loop f n z = fn(z),A loop function,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = ac

24、c,incr : Int - Int - Int incr n z = loop f n z where f i acc = acc + 1,48,A loop function,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = acc,incr : Int - Int - Int incr n z = loop f n z where f i acc = acc + 1,49,incr acc by 1,A loop func

25、tion,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = acc,incr : Int - Int - Int incr n z = loop f n z where f i acc = acc + 1,50,incr acc by 1,Inductive Proof,R : (Int, a),51,Loop Invariant:,loop : (Int - a - a) - Int - a - aloop f n z = g

26、o 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = acc,loop iteration,accumulator,Inductive Proof,R(0, z),R(i, acc) R(i+1, f i acc),R : (Int, a),52,Base:,Inductive Step:,Loop Invariant:,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwi

27、se = acc,R(n, loop f n z),Conclusion:,Induction via Abstract Refinements,53,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = acc,z : a,Induction via Abstract Refinements,54,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i ac

28、c | i n = go (i+1) (f i acc)| otherwise = acc,R(0, z),R(i, acc) R(i+1, f i acc),R : (Int, a),R(n, loop f n z),r : Int - a - Prop,f : i:Int - a - a,Induction via Abstract Refinements,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = acc,R(0,

29、z),R(i, acc) R(i+1, f i acc),R : (Int, a),R(n, loop f n z),r : Int - a - Prop,z : a,Induction via Abstract Refinements,56,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = acc,R(0, z),R(i, acc) R(i+1, f i acc),R : (Int, a),R(n, loop f n z),r

30、 : Int - a - Prop,z : a,f : i:Int - a - a,loop f n z : a,0,Induction via Abstract Refinements,57,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = acc,r : Int - a - Prop,z : a,f : i:Int - a - a,loop f n z : a,Induction via Abstract Refinemen

31、ts,loop : forall a - Prop.f:(i:Int - a - a) - n: v:Int | v=0 - z:a- a,58,loop : (Int - a - a) - Int - a - aloop f n z = go 0 z where go i acc | i n = go (i+1) (f i acc)| otherwise = acc,Induction via Abstract Refinements,incr : Int - Int - Int incr n z = loop f n z where f i acc = acc + 1,R(i, acc)

32、acc = i + z,loop : forall a - Prop.f:(i:Int - a - a) - n: v:Int | v=0 - z:a- a,59,incr acc by 1,Induction via Abstract Refinements,incr : Int - Int - Int incr n z = loop f n z where f i acc = acc + 1,R(i, acc) acc = i + z,loop i acc - acc = i + z: f:(i:Int - v:a | v=i+z - v:a | v=(i+1)+z) - n:v:Int

33、| v=0- z:Int- v:Int | v=n+z,60,Induction via Abstract Refinements,incr : Int - Int - Int incr n z = loop f n z where f i acc = acc + 1,R(i, acc) acc = i + z,loop i acc - acc = i + z: f:(i:Int - v:a | v=i+z - v:a | v=(i+1)+z) - n:v:Int | v=0- z:Int- v:Int | v=n+z,61,Induction via Abstract Refinements

34、,incr : Int - Int - Int incr n z = loop f n z where f i acc = acc + 1,R(i, acc) acc = i + z,loop i acc - acc = i + z f: n:v:Int | v=0- z:Int- v:Int | v=n+z,62,Induction via Abstract Refinements,incr : Int - Int - Int incr n z = loop f n z where f i acc = acc + 1,R(i, acc) acc = i + z,loop i acc - ac

35、c = i + z f: n:v:Int | v=0- z:Int- v:Int | v=n+z,63,Induction via Abstract Refinements,incr : Int - Int - Int incr n z = loop f n z where f i acc = acc + 1,R(i, acc) acc = i + z,incr: n:v:Int | v=0- z:Int- v:Int | v=n+z,64,Induction via Abstract Refinements,incr : n:v:Int | v=0- z:Int- v:Int | v=n+z

36、incr n z = loop f n z where f i acc = acc + 1,65,Outline,Evaluation,Applications,Refinements and Type Classes,Inductive Refinements,Indexed Refinements,Recursive Refinements,66,Outline,Evaluation,Applications,Refinements and Type Classes,Inductive Refinements,Indexed Refinements,Recursive Refinement

37、s,67,A Vector Data Type,data Vec a = V f : i:Int - a,68,Goal: Encode the domain of Vector,Encoding the Domain of a Vector,data Vec Prop a = V f : i:Int - a,69,Abstract refinement,index satisfies d,Encoding the Domain of a Vector,70,data Vec Prop a = V f : i:Int - a,Encoding the Domain of a Vector,da

38、ta Vec Prop a = V f : i:Int - a,“vector defined on positive integers”,71,Vec v 0 a,Encoding the Domain of a Vector,data Vec Prop a = V f : i:Int - a,“vector defined only on 1”,72,Vec v = 1 a,Encoding the Domain of a Vector,data Vec Prop a = V f : i:Int - a,“vector defined on the range 0 n”,73,Vec 0

39、v a,data Vec Prop, r:Int - a - Prop a = V f : i:Int - a,Encoding Domain and Range of a Vector,74,Encoding Domain and Range of a Vector,75,data Vec Prop, r:Int - a - Prop a = V f : i:Int - a,Encoding Domain and Range of a Vector,“vector defined on positive integers, with values equal to their index”,

40、76,Vec v 0, i v - i = v Int,data Vec Prop, r:Int - a - Prop a = V f : i:Int - a,Encoding Domain and Range of a Vector,77,Vec v = 1, i v - v = 12 Int,“vector defined only on 1, with values equal to 12”,data Vec Prop, r:Int - a - Prop a = V f : i:Int - a,Null Terminating Strings,“vector defined on the

41、 range 0 n, with its last value equal to 0”,78,Vec 0 v i = n-1 = v = 0 Char,data Vec Prop, r:Int - a - Prop a = V f : i:Int - a,Fibonacci Memoization,“vector defined on positives, with i-th value equal to zero or i-th fibonacci”,79,Vec 0 v, i v - v != 0 = v = fib(i) Int,data Vec Prop, r:Int - a - Pr

42、op a = V f : i:Int - a,Using Vectors,80,Abstract over d and r in vector op (get, set, )Specify vector properties (NullTerm, FibV, )Verify that user functions preserve properties,81,Using Vectors,type NullTerm n = Vec 0 i=n-1 = v=0 Char upperCase : n:v: Int| v0 - NullTerm n - NullTerm n upperCase n s

43、 = ucs 0 s where ucs i s = case get i s of 0 - s c - ucs (i + 1) (set i (toUpper c) s),Outline,Evaluation,Applications,Refinements and Type Classes,Inductive Refinements,Indexed Refinements,Recursive Refinements,82,Outline,Evaluation,Applications,Refinements and Type Classes,Inductive Refinements,In

44、dexed Refinements,Recursive Refinements,83,List Data Type,Goal: Relate tail elements with the head,data List a= N| C (h : a) (tl : List a),84,data List a a - Prop= N| C (h : a) (tl : List (a),Recursive Refinements,85,Abstract refinement,tail elements satisfy p at h,Unfolding Recursive Refinements,86

45、,data List a a - Prop= N| C (h : a) (tl : List (a),Unfolding Recursive Refinements,87,h1 C h2 C h3 C N : List a,data List a a - Prop= N| C (h : a) (tl : List (a),Unfolding Recursive Refinements (1/3),88,h1 C h2 C h3 C N : List a,h1 : a tl1 : List (a),data List a a - Prop= N| C (h : a) (tl : List (a)

46、,Unfolding Recursive Refinements (2/3),89,h1 C h2 C h3 C N : List a,h1 : a h2 : a tl2 : List (a),data List a a - Prop= N| C (h : a) (tl : List (a),Unfolding Recursive Refinements (3/3),h1 C h2 C h3 C N : List a,h1 : a h2 : a h3 : a N : List (a),90,data List a a - Prop= N| C (h : a) (tl : List (a),In

47、creasing Lists,91,h1 C h2 C h3 C N : IncrL a,data List a a - Prop= N| C (h : a) (tl : List (a),type IncrL a = List hd v a,Increasing Lists,h1 C h2 C h3 C N : IncrL a,h1 : a h2 : v:a | h1 v h3 : v:a | h1 v h2 v N : IncrL v:a | h1 v h2 v h3 v ,92,type IncrL a = List hd v a,data List a a - Prop= N| C (h : a) (tl : List (a),

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1