欢迎来到麦多课文档分享! | 帮助中心 海量文档,免费浏览,给你所需,享你所想!
麦多课文档分享
全部分类
  • 标准规范>
  • 教学课件>
  • 考试资料>
  • 办公文档>
  • 学术论文>
  • 行业资料>
  • 易语言源码>
  • ImageVerifierCode 换一换
    首页 麦多课文档分享 > 资源分类 > PPT文档下载
    分享到微信 分享到微博 分享到QQ空间

    Abstract Refinement Types.ppt

    • 资源ID:377949       资源大小:513.29KB        全文页数:105页
    • 资源格式: PPT        下载积分:2000积分
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    二维码
    微信扫一扫登录
    下载资源需要2000积分(如需开发票,请勿充值!)
    邮箱/手机:
    温馨提示:
    如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如需开发票,请勿充值!如填写123,账号就是123,密码也是123。
    支付方式: 支付宝扫码支付    微信扫码支付   
    验证码:   换一换

    加入VIP,交流精品资源
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    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),


    注意事项

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




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

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

    收起
    展开