Defining functions between constants in Isabel

I'm a mathematician, just starting to get used to Isabelle, and something that should be incredibly simple turned out to be disappointing. How to define a function between two constants? Say the function f: {1,2,3} \ to {1,2,4} displays 1 to 1, 2 to 4, and 3 to 2?

I suppose I was able to define sets as constants t1 and t2 without incident, but (I think, since they are not data types), I can not try something like

    definition f ::"t1 => t2" where 
"f 1 = 1" |
"f 2 = 4" | 
"f 3 = 2"

I believe that there should be a fundamental fallacy behind this difficulty, so I appreciate any advice.

+4
source share
1 answer

There are a number of aspects to your question.

-, -, fun definition, :

fun test :: "nat ⇒ nat" where
  "test (Suc 0) = 1" |
  "test (Suc (Suc 0)) = 4" |
  "test (Suc (Suc (Suc 0))) = 2" |
  "test _ = undefined"

definition, fun. , (1, 2, 3 ..) nat (0 Suc) .

definition, , case, :

definition test2 :: "nat ⇒ nat" where
  "test2 x ≡
     case x of
       (Suc 0) ⇒ 1
     | (Suc (Suc 0)) ⇒ 4
     | (Suc (Suc (Suc 0))) ⇒ 2
     | _ ⇒ undefined"

, , test2, , test2_def , test2 .

( , , ), typedef, nat.

EDIT: typedef, - :

typedef t1 = "{x::nat. x = 1 ∨ x = 2 ∨ x = 3}"
  by auto

definition test :: "t1 ⇒ t1" where
  "test x ≡
     case (Rep_t1 x) of
     | Suc 0 ⇒ Abs_t1 1
     | Suc (Suc 0) ⇒ Abs_t1 4
     | Suc (Suc (Suc 0)) ⇒ Abs_t1 2"

, typedef , , - . typedef , , . , auto, , , , naturals , t1, . , Abs_t1 Rep_t1, naturals . print_theorems typedef, t1that Isabelle automatically generated for you.

+4
source

All Articles