Dafny Dafny
首页
  • 入门介绍

    • 什么是dafny?
  • 用起来吧!

    • 安装
    • 快速上手
    • 可能遇到的问题?
  • Dafny快速入门

    • 基础学习 Basic
    • 方法 Method
    • 关键字 Keyword
    • 函数 Function
    • 类 Class
    • 泛型 Generics
    • 声明 Statement
    • 表达式 Expression
  • Dafny简单例子

    • 寻找最大最小数和
    • 斐波那契数列
    • 线性查询
    • 引理-计算序列非负元素个数
    • 集合
    • 终止
  • Dafny指导

    • 介绍
    • 方法 Methods
    • 前置/后置条件 Pre/Postconditions
    • 断言 Assertions
    • 函数 Functions
    • 循环不变体 Loop Invariants
    • 数组 Arrays
    • 量词(函数) Quantifiers
    • 谓词(函数) Predicates
    • 框架 Framing
    • 二分搜索 Binary Search
    • 总结
  • Dafny进阶语法

    • 引理和归纳 Lemmas and Induction
    • 模块 Modules
    • 集合 sets
    • 序列 sequence
    • 终止 Terminal
    • 值类型 Values Types
  • 实践探索

    • 自动归纳
    • 自动调用引理
    • 定义、证明、算法正确性
    • 各种推导式
    • 不同类型的证明
    • 集合元素上的函数
    • 在集合上的迭代
  • 常用工具

    • Type System
    • Style Guide
    • Cheet Sheet
✨收藏
  • 简体中文
  • English
💬社区留言板
GitHub (opens new window)

Dafny

新一代验证语言
首页
  • 入门介绍

    • 什么是dafny?
  • 用起来吧!

    • 安装
    • 快速上手
    • 可能遇到的问题?
  • Dafny快速入门

    • 基础学习 Basic
    • 方法 Method
    • 关键字 Keyword
    • 函数 Function
    • 类 Class
    • 泛型 Generics
    • 声明 Statement
    • 表达式 Expression
  • Dafny简单例子

    • 寻找最大最小数和
    • 斐波那契数列
    • 线性查询
    • 引理-计算序列非负元素个数
    • 集合
    • 终止
  • Dafny指导

    • 介绍
    • 方法 Methods
    • 前置/后置条件 Pre/Postconditions
    • 断言 Assertions
    • 函数 Functions
    • 循环不变体 Loop Invariants
    • 数组 Arrays
    • 量词(函数) Quantifiers
    • 谓词(函数) Predicates
    • 框架 Framing
    • 二分搜索 Binary Search
    • 总结
  • Dafny进阶语法

    • 引理和归纳 Lemmas and Induction
    • 模块 Modules
    • 集合 sets
    • 序列 sequence
    • 终止 Terminal
    • 值类型 Values Types
  • 实践探索

    • 自动归纳
    • 自动调用引理
    • 定义、证明、算法正确性
    • 各种推导式
    • 不同类型的证明
    • 集合元素上的函数
    • 在集合上的迭代
  • 常用工具

    • Type System
    • Style Guide
    • Cheet Sheet
✨收藏
  • 简体中文
  • English
💬社区留言板
GitHub (opens new window)
  • dafny-quick-start

    • Dafny Quick Reference
    • Getting Started with Dafny A Guide
    • cheet
      • Specification
  • dafny-tutorials

  • detailed-document

  • publication-lecture

  • 语言
  • dafny-quick-start
lijiahai
2022-03-26
目录

cheet

Keyword(s) What it does Snippet
var declares variables var nish: int;var m := 5; inferred type var i: int, j: nat;var x, y, z: bool := 1, 2, true;
:= assignment z := false;x, y := x+y, x-y; /* parallel assignment */
if..else conditional statement if z { x := x + 1; } /* braces are* / else{ y := y - 1; } /* mandatory */
if..then..else conditional expression m := if x < y then x else y;
while forall loops while x > y { x := x - y; } forall i | 0 <= i < m { Foo(i); }
method returns subroutines /* Without a return value*/ method Hello() { print “Hello Dafny”; } /*With a return value */ method Norm2(x: real, y: real) returns (z: real) /* return values */ { /* must be named */ z := x * x + y * y;}/* Multiple return values */ method Prod(x: int) returns(dbl: int, trpl: int){ dbl, trpl := x * 2, x * 3; }
class object classes class Point /* classes contain */{ /* variables and methods */ var x: real, y: real method Dist2(that: Point) returns (z: real) requires that != null { z := Norm2(x - that.x, y - that.y); }}
array typed arrays var a := new bool[2];a[0], a[1] := true, false;method Find(a: array<int>, v: int) returns (index: int)

# Specification

Keyword(s) What it does Snippet
requires precondition method Rot90(p: Point) returns (q: Point) requires p != null{ q := new Point; q.x, q.y := -p.y, p.x; }
ensures postcondition method max(a: nat, b: nat) returns (m: nat) ensures m >= a /* can have as many */ ensures m >= b /* as you like */{ if a > b { m := a; } else { m := b; } }
assert assume inline propositions assume x > 1;assert 2 * x + x / x > 3;
! && || ==> <== <==> logical connectives assume (z || !z) && x > y;assert j < a.Length ==> a[j]*a[j] >= 0;assert !(a && b) <==> !a || !b;
forall exists logical quantifiers assume forall n: nat :: n >= 0; assert forall k :: k + 1 > k; /* inferred k:int */
function predicate pure definitions function min(a: nat, b: nat): nat{ /* body must be an expression */ if a < b then a else b }predicate win(a: array<int>, j: int) requires a != null{ /* just like function(...): bool */ 0 <= j < a.Length }
modifies framing (for methods) method Reverse(a: array<int>) /* not allowed to */ modifies a /* assign to “a” otherwise */
reads framing (for functions) predicate Sorted(a: array<int>) /* not allowed to */ reads a /* refer to “a[_]” otherwise */
invariant loop invariants i := 0;while i < a.Length invariant 0 <= i <= a.Length invariant forall k :: 0 <= k < i ==> a[k] == 0{ a[i], i := 0, i + 1; } assert forall k :: 0 <= k < a.Length ==> a[k] == 0;
编辑 (opens new window)
上次更新: 2022/03/26, 19:35:15
Getting Started with Dafny A Guide
Getting Started with Dafny A Guide

← Getting Started with Dafny A Guide Getting Started with Dafny A Guide→

最近更新
01
寻找最大和最小数
04-06
02
斐波那契数列
04-06
03
线性查询
04-06
更多文章>
Theme by Vdoing | Copyright © 2022-2022 Li Jiahai | Dafny Community | 2022
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式