社保跟医保有什么区别| 紫水晶属于五行属什么| 什么是碱性食物| 邪祟是什么意思| 三百年前是什么朝代| 心颤吃什么药效果好| 什么人不能吃芒果| 什么是砭石| 住院需要带什么| 低血压是什么原因引起的| 蚝油是干什么用的| 盆腔磁共振平扫能查出什么| 82年属狗是什么命| 这是什么英文| 多动症是什么原因造成| 12月8号是什么星座| 牙痛吃什么消炎药| 两手发麻是什么原因| 低血压吃什么补得最快| 线索是什么意思| 2017属什么| 三个小是什么字| 皮肤爱出油是什么原因| 硫酸对人体有什么危害| 属猴和什么属相最配| 冰瓷棉是什么面料| 一月19日是什么星座| 举措前面搭配什么| 一座什么| 叒字什么意思| 绿豆不能和什么同吃| 二尖瓣反流什么意思| 反应是什么意思| 冥想什么意思| 腊八节吃什么| 皮下出血是什么原因| 揣测是什么意思| 什么痣不能点| 开大是什么意思| 什么可以美白| 白带豆腐渣状用什么药| 元参别名叫什么| 阅字五行属什么| 什么是hpv感染| 开塞露是什么| 拉架棉是什么面料| 劳烦是什么意思| 早餐一般吃什么| 梦见猪是什么意思| 子宫内膜息肉样增生是什么意思| 打饱嗝是什么病的前兆| 皮肤过敏有什么好办法| 孩子大便出血什么原因| 新生儿吐奶什么原因| 乙肝病毒表面抗体阳性是什么意思| 女人手心热吃什么调理| 红光对皮肤有什么作用| 头发白是什么原因引起的| 什么是矢量| 发扬什么词语搭配| 月经有黑色血块是什么原因| 侄子叫我什么| 咳嗽两个月了一直不好是什么原因| 安德玛是什么牌子| 妈妈是什么| 走后门什么意思| 95年的猪是什么命| 大便出血吃什么药| hrv是什么| 苡米和薏米有什么区别| 尿液有泡沫是什么原因| 就此别过是什么意思| 经常想睡觉是什么原因| 申属于五行属什么| 打酱油是什么意思| 天伦之乐什么意思| 肠胃消化不好吃什么药| 武汉大学校长是什么级别| lane是什么意思| 蜘蛛属于什么类动物| 巨蟹座什么性格| 马甲线是什么| 更年期什么年龄开始| 天天晚上睡觉做梦是什么原因| 目前除皱最好的方法是什么| 痰湿吃什么中成药| 高的部首是什么| 什么首什么胸| 后背疼是什么病| 抬头纹用什么护肤品可以去除| pmi是什么| 撒贝宁是什么族| 痛风用什么药| 生气什么| 打饱嗝吃什么药| 脾胃湿热吃什么中成药| 中筋面粉适合做什么| 身上长小红点是什么原因| 水牛背满月脸是什么病| 榴莲吃了有什么好处| 不景气是什么意思| 小孩子手脱皮是什么原因引起的| 嗓子痒咳嗽吃什么药| 捌是什么数字| 加拿大货币叫什么| white是什么意思颜色| 婚检检查什么项目| 盛情难却是什么意思| 4岁小孩流鼻血是什么原因| 金国是现在的什么地方| 自己买什么药可以打胎| 油碟是什么| 用纸盒能做什么手工| 治脚气用什么药| 带状疱疹是什么病| 上感是什么意思| 红烧肉可以放什么配菜| 治疗风湿有什么好方法| 大头鱼是什么鱼| 肉沫炒什么好吃| 类风湿有什么特效药| 女人梦见自己掉牙齿是什么征兆| 什么玉便宜又养人| 冷幽默是什么意思| 胃糜烂吃什么药可以根治| 发烧头疼吃什么药| 副团长是什么军衔| 艾是什么意思| 广基息肉是什么意思| police是什么品牌| 警示是什么意思| 左下腹是什么器官| 耳语是什么意思| 脚心热什么原因| 证候是什么意思| 四大才子中状元是什么生肖| 人爱出汗是什么原因| 心烦意乱是什么意思| 女人梦到被蛇咬是什么意思| 梦到前任预示着什么| 梦见蟒蛇是什么预兆| 胆固醇高不可以吃什么| 草鱼喜欢吃什么| 江西的简称是什么| 鹿吃什么食物| 牛肉补什么| 液氨是什么| 串联质谱筛查是什么病| 拔牙第二天可以吃什么| 酸梅汤有什么功效| 甘油三酯偏高说明什么问题| 洁面液是干什么用的| 果是什么结构的字| 外感病是什么意思| 什么叫伪娘| 孩子为什么会得抽动症| 经常吃杏仁有什么好处| 五月二十日是什么星座| 芒种是什么季节| 蚊子为什么吸血| 肺部感染有什么症状| 男人经常熬夜喝什么汤| 金戈铁马是什么生肖| 环状肉芽肿是什么皮肤病| insun是什么牌子| 水瓶是什么星座| 尚可什么意思| 百合花什么时候开花| 年年有今日岁岁有今朝什么意思| 是什么原因| 2030年是什么年| 唐玄宗为什么叫唐明皇| 善存片适合什么人吃| 什么中华| 肛塞是什么| 引产和流产有什么区别| 撑台脚是什么意思| 南京有什么| 促甲状腺激素偏低是什么意思| 果肉属于什么组织| 折耳猫什么颜色最贵| 芦荟有什么用| giada是什么牌子| 背德是什么意思| 龟头责是什么意思| 静电是什么| 巴扎是什么意思| 月经几个月不来是什么原因| 睡眠不好吃什么中成药| 阑尾炎吃什么药最有效| 鼠目寸光是什么生肖| 莲雾吃了有什么好处| 白葡萄酒配什么食物| 米酒和黄酒有什么区别| 什么叫非萎缩性胃炎| 失物招领是什么意思| 维生素b是补什么的| 马来酸曲美布汀片什么时候吃| 儿童经常流鼻血什么原因造成的| 游园惊梦讲的是什么| 免疫球蛋白e高说明什么| 硫化氢什么味道| 胡子长得快是什么原因| 开通花呗有什么风险| 雪梨是什么梨| 妇科杆菌是什么引起的| 黉门是什么意思| 翻过山越过海是什么歌| 护理部主任是什么级别| 睡觉嗓子干是什么原因| 红曲红是什么| 吃什么药减肥效果好| 胸小是什么原因| 萩是什么意思| 栀子花什么时候开| 子卯相刑有什么危害| 辟谷期间可以吃什么| 趋是什么意思| 上火吃什么消炎药| 乳房疼挂什么科| 专情是什么意思| 喉咙发甜是什么原因| 花枝是什么食材| 手指麻木是什么原因| 砭石是什么石头| 尿液有白色絮状物是什么原因| 人中发红是什么原因| 备孕需要检查什么| 流汗有什么好处| 什么是色盲| 胡萝卜什么时间种| 荨麻疹用什么药| 电视开不了机是什么原因| 非赘生性囊肿什么意思| 三栖明星是什么意思| 怀孕一个月有点见红是什么情况| 穿刺活检是什么意思| 广州的市花是什么| 灰指甲医院挂什么科| 做扩胸运动有什么好处| 人中长痘痘什么原因| 江米是什么米| 作精是什么意思| 送什么礼物给女老师| 煮牛肉放什么调料| 身体发麻是什么原因| 综合内科是看什么病| 黄鼠狼进屋是什么兆头| 贴膏药发热是什么原因| 6月8号什么星座| 牛肉烧什么菜最好吃| 左行气右行血什么意思| 棕色皮鞋配什么颜色裤子| 排卵期一般在什么时候| 后背疼痛什么原因| 什么啤酒劲最大| 欣字属于五行属什么| 卵子是什么| eus是什么检查| 什么叫丹毒| 兔对冲生肖是什么| 什么是低密度脂蛋白| 冰箱冷藏室结冰是什么原因| 轮状胎盘是什么意思| 百度

揭秘:史上最难挖的帝王陵墓 武则天墓刀枪不惧

百度 举办春季车展,吸引市民购买新款和新能源车辆,倡导汽车4S店提升服务质量和水平,扩大汽车消费。

Dafny is an imperative and functional compiled language that compiles to other programming languages, such as C#, Java, JavaScript, Go, and Python. It supports formal specification through preconditions, postconditions, loop invariants, loop variants, termination specifications and read/write framing specifications. The language combines ideas from the functional programming and imperative programming paradigms; it includes support for object-oriented programming. Features include generic classes, dynamic allocation, inductive datatypes and a variation of separation logic known as implicit dynamic frames[1] for reasoning about side effects.[2] Dafny was created by Rustan Leino at Microsoft Research after his prior work on developing ESC/Modula-3, ESC/Java, and Spec#.

Dafny
ParadigmImperative, functional
Designed?byK. Rustan M. Leino
DeveloperMicrosoft Research
First?appeared2009; 16?years ago?(2009)
Stable release
4.9.0 / October?31, 2024; 9 months ago?(2025-08-14)
Typing disciplineStatic, strong, safe
LicenseMIT
Filename extensions.dfy
Websitedafny.org

Dafny is regularly featured in software verification competitions (e.g. VSTTE'08,[3] VSCOMP'10,[4] COST'11,[5] and VerifyThis'12[6]).

Dafny was designed as a verification-aware programming language, requiring verification along with code development. It thus fits the Correct by Construction software development paradigm. Verification proofs are supported by a mathematical toolbox that includes mathematical integers and reals, bit-vectors, sequences, sets, multisets, infinite sequences and sets, induction, co-induction, and calculational proofs. Verification obligations are discharged automatically, given sufficient specification. Dafny uses some program analysis to infer many specification assertions, reducing the burden on the user of writing specifications. The general proof framework is that of Hoare logic.

Dafny builds on the Boogie intermediate language which uses the Z3 automated theorem prover for discharging proof obligations.[7][8]

Data types

edit

Dafny provides methods for implementation which may have side-effects and functions for use in specification which are pure.[9] Methods consist of sequences of statements following a familiar imperative style whilst, in contrast, the body of a function is simply an expression. Any side-effecting statements in a method (e.g. assigning an element of an array parameter) must be accounted for by noting which parameters can be mutated, using the modifies clause. Dafny also provides a range of immutable collection types including: sequences (e.g. seq<int>), sets (e.g. set<int>), maps (map<int,int>), tuples, inductive datatypes and mutable arrays (e.g. array<int>).

Imperative features

edit

The following illustrates many of the features in Dafny, including the use of preconditions, postconditions, loop invariants and loop variants.

method max(arr:array<int>) returns (max:int)
 // Array must have at least one element
 requires arr.Length > 0
 // Return cannot be smaller than any element in array
 ensures forall j : int ::   j >= 0 && j < arr.Length  ==>  max >= arr[j]
 // Return must match some element in array
 ensures exists j : int ::   j>=0 && j < arr.Length && max == arr[j]
{
  max := arr[0];
  var i: int := 1;
  //
  while(i < arr.Length)
  // Index at most arr.Length (needed to show i==arr.Length after loop)
  invariant i <= arr.Length
  // No element seen so far larger than max
  invariant forall j:int :: j >= 0 && j < i  ==>  max >= arr[j]
  // Some element seen so far matches max
  invariant exists j:int :: j >= 0 && j < i && max == arr[j]
  // arr.Length - i decreases at every step and is lower-bounded by 0
  decreases arr.Length - i
  {
    // Update max if larger element encountered
    if (arr[i] > max) {
      max := arr[i];
    }
    // Continue through array
    i := i + 1;
  }
}

This example computes the maximum element of an array. The method's precondition and postcondition are given with the requires and ensures clauses (respectively). Likewise, the loop invariant and loop variant are given through the invariant and decreases clauses (respectively).

Loop invariants

edit

The treatment of loop invariants in Dafny differs from traditional Hoare logic. Variables mutated in a loop are treated such that (most) information known about them before the loop is discarded. Information required to prove properties of such variables must be expressed explicitly in the loop invariant. In contrast, variables not mutated in the loop retain all information known about them beforehand. The following example illustrates using loops:

method sumAndZero(arr: array<int>) returns (sum: nat)
  requires forall i :: 0 <= i < arr.Length  ==>  arr[i] >= 0
  modifies arr
{
  var i: int := 0;
  sum := 0;
  //
  while(i < arr.Length) {
    sum := sum + arr[i];
    arr[i] := arr[i];
    i := i + 1;
  }
}

This fails verification because Dafny cannot establish that (sum + arr[i]) >= 0 holds at the assignment. From the precondition, intuitively, forall i?:: 0 <= i < arr.Length ==> arr[i] >= 0 holds in the loop since arr[i]?:= arr[i]; is a NOP. However, this assignment causes Dafny to treat arr as a mutable variable and drop information known about it from before the loop. To verify this program in Dafny we can either (a) remove the redundant assignment arr[i]?:= arr[i];; or (b) add the loop invariant invariant forall i?:: 0 <= i < arr.Length ==> arr[i] >= 0

Dafny also employs limited static program analysis to infer simple loop invariants where possible. In the example above, it would seem that the loop invariant invariant i >= 0 is also required as variable i is mutated within the loop. Whilst the underlying logic requires such an invariant, Dafny infers this automatically, and hence, it can be omitted at the source level.

Proof features

edit

Dafny includes features which further support its use as a proof assistant. Although proofs of simple properties within a function or method (as shown above) are not unusual for tools of this nature, Dafny also allows the proof of properties between one function and another. As is common for a proof assistant, such proofs are often inductive in nature. Dafny may be unusual in employing method invocation as a mechanism for applying the inductive hypothesis. The following illustrates:

datatype List = Nil | Link(data: int, next: List)

function sum(l: List): int {
  match l
    case Nil => 0
    case Link(d, n) => d + sum(n)
}

predicate isNatList(l: List) {
  match l
    case Nil => true
    case Link(d, n) => d >= 0 && isNatList(n)
}

lemma NatSumLemma(l: List, n: int)
  requires isNatList(l) && n == sum(l)
  ensures n >= 0 
{
  match l
    case Nil =>
      // Discharged Automatically
    case Link(data, next) => {
      // Apply Inductive Hypothesis
      NatSumLemma(next, sum(next));
      // Check what known by Dafny
      assert data >= 0;
    }
}

Here, NatSumLemma proves a useful property between sum() and isNatList() (i.e. that isNatList(l) ==> (sum(l) >= 0)). The use of a ghost method for encoding lemmas and theorems is standard in Dafny with recursion employed for induction (typically, structural induction). Case analysis is performed using match statements and non-inductive cases are often discharged automatically. The verifier must also have complete access to the contents of a function or predicate to unroll them as necessary. This has implications when used in conjunction with access modifiers. Specifically, hiding the contents of a function using the protected modifier can limit what properties can be established about it.

See also

edit

References

edit
  1. ^ Smans, Jan; Jacobs, Bart; Piessens, Frank (2009). Implicit Dynamic Frames: Combining Dynamic Frames and Separation Logic (PDF). Proceedings of the Conference on European Conference on Object-Oriented Programming. pp.?148–172. doi:10.1007/978-3-642-03013-0_8.
  2. ^ Leino, Rustan (2010). Dafny: An Automatic Program Verifier for Functional Correctness. Proceedings of the Conference on Logic for Programming, Artificial Intelligence, and Reasoning. pp.?348–370. doi:10.1007/978-3-642-17511-4_20.
  3. ^ Leino, Rustan; Monahan, Rosemary (2010). Dafny Meets the Verification Benchmarks Challenge (PDF). International Conference on Verified Software: Theories, Tools, and Experiments. pp.?112–116. doi:10.1007/978-3-642-15057-9_8.
  4. ^ Klebanov, Vladimir; et?al. (2011). The 1st Verified Software Competition: Experience Report. Proceedings of the Conference on Formal Methods. pp.?154–168. CiteSeerX?10.1.1.221.6890. doi:10.1007/978-3-642-21437-0_14.
  5. ^ Bormer, Thorsten; et?al. (2011). The COST IC0701 Verification Competition 2011. Proceedings of the Conference on Formal Verification of Object-Oriented Software. pp.?3–21. CiteSeerX?10.1.1.396.6170. doi:10.1007/978-3-642-31762-0_2.
  6. ^ Huisman, Marieke; Klebanov, Vladimir; Monahan, Rosemary (2015). "VerifyThis 2012" (PDF). International Journal on Software Tools for Technology Transfer. 17 (6): 647–657. doi:10.1007/s10009-015-0396-8. S2CID?14301377.
  7. ^ "Z3 Homepage". GitHub. 2025-08-14.
  8. ^ de Moura, Leonardo; Bj?rner, Nikolaj (2008). Z3: An Efficient SMT Solver. Proceedings of the Conference on Tools and Algorithms for the Construction and Analysis. pp.?337–340. doi:10.1007/978-3-540-78800-3_24.
  9. ^ "Dafny Programming Language". 2025-08-14.

Further reading

edit
  • Meyer, Bertrand; Nordio, Martin, eds. (2012). Tools for Practical Software Verification: International Summer School, LASER 2011, Elba Island, Italy, Revised Tutorial Lectures. Springer. ISBN?978-3642357459.
  • Sitnikovski, Boro (2022). Introducing Software Verification with Dafny Language: Proving Program Correctness. Apress. ISBN?978-1484279779.
edit
乙型肝炎表面抗体高是什么意思 桑黄长在什么树上 什么是文员 孬种是什么意思 感冒适合吃什么水果
联系是什么意思 为什么最迷人的最危险是什么歌 山药炒什么好吃 母乳是什么颜色 窦性心律过速是什么意思
脉细是什么意思 内分泌科看什么病 三十七岁属什么生肖 dr是什么意思 包皮龟头炎用什么药
消防大队长是什么级别 份子钱是什么意思 峰值是什么意思 颈椎轻度退行性变是什么意思 胃萎缩是什么原因
间质瘤是什么性质的瘤hcv7jop7ns3r.cn afp检查是什么意思hcv7jop9ns2r.cn 染发膏用什么能洗掉hcv8jop4ns0r.cn 用盐袋子热敷小肚子有什么功效hcv8jop3ns4r.cn 2027年属什么生肖hcv8jop9ns5r.cn
西施是什么生肖hcv8jop3ns5r.cn ch表示什么意思hcv9jop6ns8r.cn 焦虑症是什么意思hcv8jop8ns5r.cn 细菌感染用什么药hcv8jop5ns3r.cn 什么是政策hcv8jop9ns8r.cn
甲亢病是一种什么病hcv8jop4ns2r.cn 氮肥是什么肥hcv9jop6ns5r.cn 大便是黑色是什么原因hcv9jop0ns6r.cn 瓢虫吃什么jinxinzhichuang.com 甲状腺有什么功能hcv8jop0ns8r.cn
维生素k2是什么hcv9jop7ns9r.cn 蔓字五行属什么hcv8jop3ns9r.cn 脊椎和脊柱有什么区别hcv9jop6ns5r.cn 翡翠属于什么五行hcv7jop9ns9r.cn 三尖瓣轻度反流是什么意思hcv9jop4ns2r.cn
百度