0

I've just started to study FStar. I'd like to express the fact that for every natural number there exists a bigger one.

let _ = assert (forall (m:nat). exists (n: nat). n > m)

It fails and I'd like to know why. Thank you.

Attila Karoly
  • 951
  • 5
  • 13

1 Answers1

1

Quantified formulas such as the one you have here are handled, by default, using Z3's heuristics for pattern-based quantified instantiation. You can read more about Z3 patterns here: https://rise4fun.com/Z3/tutorialcontent/guide#h28 and https://github.com/FStarLang/FStar/wiki/Quantifiers-and-patterns

In short, you need to help F* and Z3 find a witness for the existential quantifier. One way to do it is like this:

let lem (m:nat)
  : Lemma (exists (n:nat). n > m)
  = assert (m + 1 > m)

which proves a lemma that for any m:nat there exists an n:nat greater than m. Its proof to F*+Z3 hints that m + 1 is a good witness to choose for n.

You can turn an lemma like this into a quantified assertion in many ways. See FStar.Classical for some examples of that. For example, this works:


let _ =
  FStar.Classical.forall_intro lem;
  assert (forall (m:nat). exists (n: nat). n > m)

Here's another approach that avoids defining an intermediate lemma, but uses an intermediate assertion instead.

let _ =
  assert (forall (m:nat). m + 1 > m);
  assert (forall (m:nat). exists (n: nat). n > m)
Nik Swamy
  • 281
  • 1
  • 2
  • Nik, thank you for your kind reply. Regarding the last approach, I've refined 'm' in the first term as {m > 10} and as {m > 11} in the second term to express the fact that there's a bigger n for all m > 11. The assertion failed. Could you show me how to fix it? – Attila Karoly May 19 '20 at 18:13