3
votes

I am trying to prove a lemma which in a certain part has a false hypothesis. In Coq I used to write "congruence" and it would get rid of the goal. However, I am not sure how to proceed in Isabelle Isar. I am trying to prove a lemma about my le function:

primrec le::"nat ⇒ nat ⇒ bool" where
"le 0 n = True" |
"le (Suc k) n = (case n of 0 ⇒ False | Suc j ⇒ le k j)"

lemma def_le: "le a b = True ⟷ (∃k. a + k = b)"
proof
  assume H:"le a b = True"
  show "∃k. a + k = b"
  proof (induct a)
    case 0
    show "∃k. 0 + k = b"
    proof -
      have "0 + b = b" by simp
      thus ?thesis by (rule exI)
    qed

    case Suc
    fix n::nat
    assume HI:"∃k. n + k = b"
    show "∃k. (Suc n) + k = b"
    proof (induct b)
      case 0
      show "∃k. (Suc n) + k = 0"
      proof -
        have "le (Suc n) 0 = False" by simp
        oops

Note that my le function is "less or equal". At this point of the proof I find I have the hypothesis H which states that le a b = True, or in this case that le (Suc n) 0 = True which is false. How can I solve this lemma?

Another little question: I would like to write have "le (Suc n) 0 = False" by (simp only:le.simps) but this does not work. It seems I need to add some rule for reducing case expressions. What am I missing?

Thank you very much for your help.

2

2 Answers

7
votes

The problem is not that it is hard to get rid of a False hypothesis in Isabelle. In fact, pretty much all of Isabelle's proof methods will instantly prove anything if there is False in the assumptions. No, the problem here is that at that point of the proof, you don't have the assumptions you need anymore, because you did not chain them into the induction. But first, allow me to make a few small remarks, and then give concrete suggestions to fix your proof.

A Few Remarks

  1. It is somewhat unidiomatic to write le a b = True or le a b = False in Isabelle. Just write le a b or ¬le a b.
  2. Writing the definition in a convenient form is very important to get good automation. Your definition works, of course, but I suggest the following one, which may be more natural and will give you a convenient induction rule for free:

Using the function package:

fun le :: "nat ⇒ nat ⇒ bool" where
  "le 0 n             = True"
| "le (Suc k) 0       = False"
| "le (Suc k) (Suc n) = le k n"
  1. Existentials can sometimes hide important information, and they tend mess with automation, since the automation never quite knows how to instantiate them.

If you prove the following lemma, the proof is fully automatic:

lemma def_le': "le a b ⟷ a + (b - a) = b"
  by (induction a arbitrary: b) (simp_all split: nat.split)

Using my function definition, it is:

lemma def_le': "le a b ⟷ (a + (b - a) = b)"
  by (induction a b rule: le.induct) simp_all

Your lemma then follows from that trivially:

lemma def_le: "le a b ⟷ (∃k. a + k = b)"
  using def_le' by auto

This is because the existential makes the search space explode. Giving the automation something concrete to follow helps a lot.

The actual answer

There are a number of problems. First of all, you will probably need to do induct a arbitrary: b, since the b will change during your induction (for le (Suc a) b, you will have to do a case analysis on b, and then in the case b = Suc b' you will go from le (Suc a) (Suc b') to le a b').

Second, at the very top, you have assume "le a b = True", but you do not chain this fact into the induction. If you do induction in Isabelle, you have to chain all required assumptions containing the induction variables into the induction command, or they will not be available in the induction proof. The assumption in question talks about a and b, but if you do induction over a, you will have to reason about some arbitrary variable a' that has nothing to do with a. So do e.g:

assume H:"le a b = True"
thus "∃k. a + k = b"

(and the same for the second induction over b)

Third, when you have several cases in Isar (e.g. during an induction or case analysis), you have to separate them with next if they have different assumptions. The next essentially throws away all the fixed variables and local assumptions. With the changes I mentioned before, you will need a next before the case Suc, or Isabelle will complain.

Fourth, the case command in Isar can fix variables. In your Suc case, the induction variable a is fixed; with the change to arbitrary: b, an a and a b are fixed. You should give explicit names to these variables; otherwise, Isabelle will invent them and you will have to hope that the ones it comes up with are the same as those that you use. That is not good style. So write e.g. case (Suc a b). Note that you do not have to fix variables or assume things when using case. The case command takes care of that for you and stores the local assumptions in a theorem collection with the same name as the case, e.g. Suc here. They are categorised as Suc.prems, Suc.IH, Suc.hyps. Also, the proof obligation for the current case is stored in ?case (not ?thesis!).

Conclusion

With that (and a little bit of cleanup), your proof looks like this:

lemma def_le: "le a b ⟷ (∃k. a + k = b)"
proof
  assume "le a b"
  thus "∃k. a + k = b"
  proof (induct a arbitrary: b)
    case 0
    show "∃k. 0 + k = b" by simp
  next
    case (Suc a b)
    thus ?case
    proof (induct b)
      case 0
      thus ?case by simp
    next
      case (Suc b)
      thus ?case by simp
    qed
  qed
next

It can be condensed to

lemma def_le: "le a b ⟷ (∃k. a + k = b)"
proof
  assume "le a b"
  thus "∃k. a + k = b"
  proof (induct a arbitrary: b)
    case (Suc a b)
    thus ?case by (induct b) simp_all
  qed simp
next

But really, I would suggest that you simply prove a concrete result like le a b ⟷ a + (b - a) = b first and then prove the existential statement using that.

2
votes

Manuel Eberl did the hard part, and I just respond to your question on how to try and control simp, etc.

Before continuing, I go off topic and clarify something said on another site. The word "a tip" was used to give credit to M.E., but it should have been "3 explanations provided over 2 answers". Emails on mailing lists can't be corrected without spamming the list.

Some short answers are these:

  • There is no guarantee of completely controlling simp, but attributes del and only, shown below, will many times control it to the extent that you desire. To see that it's not doing more than you want, traces need to be used; an example of traces is given below.
  • To get complete control of proof steps, you would use "controlled" simp, along with rule, drule, and erule, and other methods. Someone else would need to give an exhaustive list.
  • Most anyone with the expertise to be able to answer "what's the detailed proof of what simp, auto, blast, etc does" will very rarely be willing to put in the work to answer the question. It can be plain, tedious work to investigate what simp is doing.
  • "Black box proofs" are always optional, as far as I can tell, if we want them to be and have the expertise to make them optional. Expertise to make them optional is generally a major limiting factor. With expertise, motivation becomes the limiting factor.

What's simp up to? It can't please everyone

If you watch, you'll see. People complain there's too much automation, or they complain there's too little automation with Isabelle.

There can never be too much automation, but that's because with Isabelle/HOL, automation is mostly optional. The possibility of no automation is what makes proving potentially interesting, but with only no automation, proving is nothing but pure tediousness, in the grand scheme.

There are attributes only and del, which can be used to mostly control simp. Speaking only from experimenting with traces, even simp will call other proof methods, similar to how auto calls simp, blast, and others.

I think you cannot prevent simp from calling linear arithmetic methods. But linear arithmetic doesn't apply much of the time.

Get set up for traces, and even the blast trace

My answer here is generalized for also trying to determine what auto is up to. One of the biggest methods that auto resorts to is blast.

You don't need the attribute_setups if you don't care about seeing when blast is used by auto, or called directly. Makarius Wenzel took the blast trace out, but then was nice enough to show the code on how to implement it.

Without the blast part, there is just the use of declare. In a proof, you can use using instead of declare. Take out what you don't want. Make sure you look at the new simp_trace_new info in the PIDE Simplifier Trace panel.

attribute_setup blast_trace = {*
  Scan.lift
   (Parse.$$$ "=" -- Args.$$$ "true" >> K true ||
    Parse.$$$ "=" -- Args.$$$ "false" >> K false ||
    Scan.succeed true) >>
  (fn b => Thm.declaration_attribute (K (Config.put_generic Blast.trace b)))
*}
attribute_setup blast_stats = {*
  Scan.lift
   (Parse.$$$ "=" -- Args.$$$ "true" >> K true ||
    Parse.$$$ "=" -- Args.$$$ "false" >> K false ||
    Scan.succeed true) >>
  (fn b => Thm.declaration_attribute (K (Config.put_generic Blast.stats b)))
*} 
declare[[simp_trace_new mode=full]]
declare[[linarith_trace,rule_trace,blast_trace,blast_stats]]

Try and control simp, to your heart's content with only & del

I don't want to work hard by using the formula in your question. With simp, what you're looking for with only and the traces is that no rule was used that you weren't expecting.

Look at the simp trace to see what basic rewrites are done that will always be done, like basic rewrites for True and False. If you don't even want that, then you have to resort to methods like rule.

A starting point to see if you can completely shut down simp is apply(simp only:).

Here are a few examples. I would have to work harder to find an example to show when linear arithmetic is automatically being used:

lemma
  "a = 0 --> a + b = (b::'a::comm_monoid_add)"
  apply(simp only:) (*
    ERROR: simp can't apply any magic whatsoever.
  *)
oops

lemma
  "a = 0 --> a + b = (b::'a::comm_monoid_add)"
  apply(simp only: add_0) (*
    ERROR: Still can't. Rule 'add_0' is used, but it can't be used first.
  *)
oops

lemma
  "a = 0 --> a + b = (b::'a::comm_monoid_add)"
  apply(simp del: add_0) (*
  A LITTLE MAGIC:
    It applied at least one rule. See the simp trace. It tried to finish
    the job automatically, but couldn't. It says "Trying to refute subgoal 1,
    etc.".
      Don't trust me about this, but it looks typical of blast. I was under
    the impressions that simp doesn't call blast.*)
oops

lemma
  "a = 0 --> a + b = (b::'a::comm_monoid_add)"
by(simp) (*
 This is your question. I don't want to step through the rules that simp
 uses to prove it all.
*)