我想证明这一点:
lemma NatDivision(a: nat, b: nat)
requires b != 0
ensures a / b == (a as real / b as real).Floor
我不知道从哪里开始 - 这似乎是不言自明的。
如果我知道 的公理是什么,我可以从那里开始工作,但是我在Dafny源代码中探究过,并且无法找到nat
除法的公理。 ( This Is Boogie 2 声称Boogie要求你定义自己的,所以我想他们会在某处,也许是在C#代码中。)
(更广泛的背景:我尝试使用this approach来证明自然数字为(a + n * b) % b == a % b
。这里是almost-working Dafny proof。
答案 0 :(得分:3)
可以分为三行:
lemma NatDivision(a: nat, b: nat)
requires b != 0
ensures a / b == (a as real / b as real).Floor
{
// A basic fact about the natural division and modulo operations:
assert a == (a / b) * b + (a % b);
// Cast some values to `real`, because this is a programming language.
// (In math, 7 and 7.0 are the same object and this wouldn't be needed...)
assert a as real == (a / b) as real * b as real + (a % b) as real;
// Divide through by b.
assert a as real / b as real == (a / b) as real + (a % b) as real / b as real;
// Aha! That reveals that the real quotient `a as real / b as real` is equal
// to the natural quotient `a / b` (a natural number) plus a fraction.
// This looks enough like `Floor` that Dafny can take it from here.
}
我仍然没有找到分裂的公理。
我是如何找到这个证据的:首先,我认为Dafny 不根据另一个来定义自然分裂或真正分裂。那么它们是如何定义的呢?我写下了我最好的猜测:
// natural division
a / b == the unique number q | a == q * b + r, 0 <= r < b.
// real division
a / b == the unique number q | q * b == a
从那里开始,尝试每一个可能的死胡同都是一件简单的事情,可以从这两个事实中得出,然后再绊倒上面的伎俩。
我有一种预感,证据将取决于每个定义中某些不适用于另一个定义的内容。果然,第一个定义成为证明的第一个断言,其余的术语很重要。第二个定义不是直接使用的,但如果你仔细观察,你可以看到一个我们假设真实乘法* b as real
取消真实除法/ b as real
的地方。
答案 1 :(得分:1)