2

Assuming I have already defined an inductive_set, for example, the inductive set "Even" such that:

inductive_set Even :: "int set" 
  where  ZERO : "0 ∈ Even"
          | PLUS :"x ∈ Even ⟹x+2 ∈ Even"
          | MIN :"x ∈ Even ⟹ x-2 ∈ Even"

lemma aux : "x= ((x::int)-2) + 2" by simp

It's fairly easy to prove lemma : "2 ∈ Even" by doing a subst to replace 2 by 2-2+2

But I'm wondering how do prove lemma : "1 ∉ Even"?

Edit:

(*Javier Diaz's answer*)
lemma Even_divisible_by_2: "n ∈ Even ⟹ 2 dvd n"
  by (induction rule: Even.induct) (simp, presburger+)
lemma "1 ∉ Even"
proof
  assume "1 ∈ Even"
  then have "2 dvd 1"
    using Even_divisible_by_2 by fastforce
  then show False
    using odd_one by blast 
qed

What would be the equivalent way to do it for 3?

lemma "3 ∉ Even"
proof
  assume "3 ∈ Even"
  then have "2 dvd 3"
(*how to continue?*)
qed

Thanks in advance

user206904
  • 504
  • 4
  • 16
  • 2
    Javier Diaz already provided an answer, but I wanted to make a couple of side remarks with regard to the partial proof outline in the question. Firstly, the invocation of `auto` removes the effects of `subst aux`. Thus, `apply(subst aux)` followed by `apply (auto)` should be equivalent to `apply (auto)` with the standard setup. Secondly, it is not considered to be a good style to begin a proof with `auto`, e.g. see https://proofcraft.org/blog/isabelle-style.html. Lastly, there already exists a more general predicate `even` whose behaviour should be equivalent to `(λx. x ∈ Even)` on `int`s. – user9716869 - supports Ukraine Jan 23 '21 at 11:46
  • I already noticed that auto removes the effect of subst after posting :) Thanks for the link and for the tip on the general predicate even :) – user206904 Jan 23 '21 at 12:11

1 Answers1

4

I would prove an intermediate result first, namely that each number in your inductive set is divisible by 2:

lemma Even_divisible_by_2: "n ∈ Even ⟹ 2 dvd n"
  by (induction rule: Even.induct) simp_all

And then prove your result by contradiction:

lemma "1 ∉ Even"
proof
  assume "1 ∈ Even"
  then have "2 dvd 1"
    using Even_divisible_by_2 by fastforce
  then show False
    using odd_one by blast 
qed

I strongly recommend that you use Isabelle/Isar instead of proof scripts.

NOTE: As request by the post author, I'm adding a proof that 3 ∉ Even in the style of the above proof:

lemma "3 ∉ Even"
proof
  assume "3 ∈ Even"
  then have "2 dvd 3"
    using Even_divisible_by_2 by fastforce
  then show False
    using odd_numeral by blast
qed

Alternative solution: @user9716869 provided the following more general and efficient solution based on the use of Even_divisible_by_2:

lemma n2k1_not_Even: "odd n ⟹ n ∉ Even"
  using Even_divisible_by_2 by auto

lemma "1 ∉ Even" and "3 ∉ Even" and "11 ∉ Even"
  by (simp_all add: n2k1_not_Even)
Javier Díaz
  • 1,071
  • 4
  • 7
  • thx a lot for answering, but could you please explain what the odd_one does exactly? For the fun of it, I'm trying to make this proof but mod instead of div `lemma even_mod: "n ∈ Even ⟹ n mod 2=0" by (induction rule: Even.induct) (simp, presburger+) lemma "3 ∉ Even" proof assume "3 ∈ Even" then have "3 mod 2=0" using even_mod by fastforce then show False using odd_one by blast qed` But I'm stuck... – user206904 Jan 23 '21 at 12:06
  • 3
    @user206904 you can control-click on theorems to see where they are defined. `thm odd_one` will also show you what the theorem is (this approach is more efficient that asking here ;-)). – Mathias Fleury Jan 23 '21 at 12:34
  • @MathiasFleury , Thanks a lot for the hint, I checked as you indicated, but I still don't understand the idea of its usage exactly in this proof... – user206904 Jan 23 '21 at 13:36
  • @user206904 I believe that there might be an easier way to prove `1 ∉ Even` once `Even_divisible_by_2 ` is proven: `proof assume "1 ∈ Even" from Even_divisible_by_2[OF this] show False using [[simp_trace]] by simp qed`. I left the `simp_trace` to showcase the steps that are performed by `simp` internally. However, I am only confident that this works in Isabelle2021-RC2 (if it also works in the latest stable release, it might worth augmenting the answer, unless I missed some deeper reason for stating the proof the way it is stated in the answer). – user9716869 - supports Ukraine Jan 23 '21 at 14:00
  • 2
    One other note. Oddly, in Isabelle2021-RC2, one can prove `Even_divisible_by_2` using `by (induction rule: Even.induct) simp_all`. – user9716869 - supports Ukraine Jan 23 '21 at 14:12
  • @user9716869 That's correct, `simp_all` is sufficient, thanks for pointing that out. – Javier Díaz Jan 23 '21 at 14:25
  • @user206904: When dealing with natural numbers, it's usually a good idea to help Isabelle a bit by representing them using `Suc`. In this way you can easily prove that `3 ∉ Even` as follows: `lemma "3 ∉ Even" using even_mod[of "Suc (Suc (Suc 0))"] by auto`. – Javier Díaz Jan 23 '21 at 14:46
  • @JavierDíaz Oh... It's true things would be a bit easier if I used Suc... Thanks! Still curious to know the equivalent of your answer that works for 3, I edited the main question. Do you mind editing your answer if you have time... Thanks for you precious time and sorry for the trouble – user206904 Jan 23 '21 at 14:57
  • 1
    @user206904 I just edited my answer to include a similar proof that works for 3. – Javier Díaz Jan 23 '21 at 23:58
  • Oh! it's the odd_numeral that does the trick! I really appreciate you taking the time to answer my questions, thanks a lot! – user206904 Jan 24 '21 at 00:23
  • @JavierDíaz Sorry for being annoying. I am not entirely convinced that the methodology chosen for the proofs of `1 ∉ Even` and `3 ∉ Even` is optimal. In one of my previous comments, I already mentioned that it is possible to produce, effectively, a one line `simp`-based proof of these theorems in Isabelle2021-RC2. The same methodology can be used to produce a one-line `simp`-based proof of `n2k1_not_Even`: `n = 2*k + 1 ⟹ n ∉ Even`, which can then be instantiated for any odd `n` and finished by `simp` like so: `"11 ∉ Even" by (rule n2k1_not_Even) simp`. – user9716869 - supports Ukraine Jan 24 '21 at 13:08
  • To ensure that my previous comment is self-contained, I provide the statement and the proof of `n2k1_not_Even` below: `lemma n2k1_not_Even: "n = 2*k + 1 ⟹ n ∉ Even" proof assume prems: "n = 2*k + 1" "n ∈ Even" from prems(1) Even_divisible_by_2[OF prems(2)] show False by simp qed` – user9716869 - supports Ukraine Jan 24 '21 at 13:12
  • @user9716869 Thanks for the comment. I'm not stating that the methodology chosen is optimal whatsoever, I just provided a possible answer and then the post author asked me to edit the answer to include a similar proof for 3. – Javier Díaz Jan 24 '21 at 13:50
  • @JavierDíaz You are right, I can now see how the conversation has unfolded... However, I believe that it would still be useful to provide more concise solutions as part of the answer (perhaps, in an explicit 'alternative solution' section). Do you have any arguments against updating the answer in this manner? – user9716869 - supports Ukraine Jan 24 '21 at 15:28
  • @user9716869 Absolutely not, I just edited my answer to include your solution. And thanks for raising the issue. – Javier Díaz Jan 24 '21 at 16:08
  • @JavierDíaz Thank you. It appears that there is an even more concise proof (not certain whether it would be computationally more efficient though, but any discrepancy will be very minor). I took the liberty to edit the post; I have also replaced the invocation of `(simp, presburger+)` with `simp_all`. This goes to show that there is hardly an end to how much one can optimize any given implementation :-). – user9716869 - supports Ukraine Jan 24 '21 at 19:26