4

I want to use the nat type in Isabelle but I want to overload some existing definitions like for example addition. I wrote the following code:

theory Prueba
imports Main HOL
begin

primrec suma::"nat ⇒ nat ⇒ nat" where
"suma 0 n = 0" |
"suma (Suc x) n = 0"
no_notation suma (infix "+" 65)

value "2 + (1 :: nat)"

I tried to overload addition with a new definition that always outputs 0. However when I evaluate 2 + (1 :: nat) I get "Suc (Suc (Suc 0))" :: "nat", which means Isabelle is still using the plus definition from Nat. How can I get it to use my new definition of +?

Thank you

Martin Copes
  • 931
  • 1
  • 7
  • 14

1 Answers1

5

Your must use no_notation to remove the default plus-syntax which comes from the plus type class of the Groups theory.

no_notation Groups.plus_class.plus (infixl "+" 65)

Then you can use

notation suma (infixl "+" 65)

to add your own syntax.

(I have never tried to override such basic parts of the definitions. I guess it might lead to strange situations – especially for other people trying to work with your theory afterwards.)

Ben Keks
  • 671
  • 4
  • 11
  • Thank you for your answer. If I do that I then get an error when trying to specify a lemma about plus, like: `lemma suma_0: "∀m::nat. m + 0 = m"`, gives a Inner syntax error. – Martin Copes Dec 26 '15 at 21:05
  • I cannot reproduce the problem here. Are you sure that you added the `notation suma (infixl "+" 65)` line at the right place? – Ben Keks Dec 26 '15 at 21:18
  • (Just changed my answer to use your function name `suma` instead of `plus`.) – Ben Keks Dec 26 '15 at 21:20
  • @Ben_Keks Indeed. I placed the line just after my `suma` definition. I am using Isabelle2015 IDE. When I put your line whenever I write the `+` sign I get an inner syntax error `Failed to parse term` – Martin Copes Dec 26 '15 at 21:31
  • 1
    The following code works on my Isabelle2015. `primrec suma::"nat ⇒ nat ⇒ nat" where "suma 0 n = 0" | "suma (Suc x) n = 0" no_notation Groups.plus_class.plus (infixl "+" 65) notation suma (infixl "+" 65) value "2 + (1 :: nat)" lemma suma_0: "∀m::nat. m + 0 = m" oops` – Ben Keks Dec 26 '15 at 21:34
  • @Ben_Keks How can I overload the "<" and "<=" symbols? What Group do I need to reference? – Martin Copes Dec 28 '15 at 20:11
  • @Ben_Keks, I tried with `no_notation Orderings.ord_class.less (infixl "<" 50) `, but I still get an `Ambiguous input` error when I try to use `<` – Martin Copes Dec 28 '15 at 20:47
  • 1
    @MartinCopes It usually works when you copy the precedence-information from the [declaration site](http://isabelle.in.tum.de/website-Isabelle2013/dist/library/HOL/Orderings.html) literally. So in this case, this would read `no_notation Orderings.ord_class.less ("(_/ < _)" [51, 51] 50)`. – Ben Keks Dec 29 '15 at 01:34