4

I define a very simple function replace which replaces 1 with 0 while preserving other input values. I want to prove that the output of the function cannot be 1. How to achieve this?

Here's the code.

theory Question
  imports Main
begin
fun replace :: "nat ⇒ nat" where
"replace (Suc 0) = 0" |
"replace x = x"

theorem no1: "replace x ≠ (Suc 0)"
  sorry
end

Thanks!

Dev-XYS
  • 249
  • 2
  • 5

1 Answers1

4

There exist several approaches for proving the statement that you are trying to prove.


You can make an attempt to use sledgehammer to find the proof automatically, e.g.

theorem no1: "replace x ≠ (Suc 0)"
  by sledgehammer
  (*using replace.elims by blast*)

Once the proof is found, you can delete the explicit invocation of the command sledgehammer.

Perhaps, a slightly better way to state the proof found by the sledgehammer would be

theorem no1': "replace x ≠ (Suc 0)"
  by (auto elim: replace.elims)

You can also try to provide a more specialized proof. For example,

theorem no1: "replace x ≠ (Suc 0)"
  by (cases x rule: replace.cases) simp_all

This proof looks at the different cases the value of x can have and then uses simplifier (in conjunction with the simp rules provided by the command fun during the definition of your function) to finish the proof. You can see all theorems that are generated by the command fun by typing print_theorems immediately after the specification of replace, e.g.

fun replace :: "nat ⇒ nat" where
  "replace (Suc 0) = 0" |
  "replace x = x"

print_theorems 

Of course, there are other ways to prove the result that you are trying to prove. One good way to improve your ability to find such proofs is by reading the documentation and tutorials on Isabelle. My own starting point for learning Isabelle was the book "Concrete Semantics" by Tobias Nipkow and Gerwin Klein.

  • Thanks for your answer. I'm trying some more complex proofs which need more than one variable in case splitting. I've tried `xxx.cases[of x y]`, `xxx.cases[of (x, y)]` and something similar to that, but they did not work. I've actually searched for solution in the book _Concrete Semantics_ but didn't find any useful information. Could you tell me in which section the book discusses these? – Dev-XYS Apr 20 '20 at 09:15
  • @Dev-XYS I am not certain if this particular problem is covered in "Concrete Semantics". Once you are comfortable with the foundations, it is best to rely on the official documentation as the primary reference. The method `cases` is described in section 6.5 in Isar-ref. Also, see the answers to this question: https://stackoverflow.com/questions/60683091/case-analysis-on-function-definition-in-isabelle. If you provide an update to the question, I can update my answer. However, it may take a while before I get a chance to do it. – user9716869 - supports Ukraine Apr 20 '20 at 10:25