src/Doc/Tutorial/Documents/Documents.thy
changeset 80983 2cc651d3ce8e
parent 80914 d97fdabd9e2b
equal deleted inserted replaced
80982:7638776e0977 80983:2cc651d3ce8e
    35   Infix declarations\index{infix annotations} provide a useful special
    35   Infix declarations\index{infix annotations} provide a useful special
    36   case of mixfixes.  The following example of the exclusive-or
    36   case of mixfixes.  The following example of the exclusive-or
    37   operation on boolean values illustrates typical infix declarations.
    37   operation on boolean values illustrates typical infix declarations.
    38 \<close>
    38 \<close>
    39 
    39 
    40 definition xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl \<open>[+]\<close> 60)
    40 definition xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "[+]" 60)
    41 where "A [+] B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
    41 where "A [+] B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
    42 
    42 
    43 text \<open>
    43 text \<open>
    44   \noindent Now \<open>xor A B\<close> and \<open>A [+] B\<close> refer to the
    44   \noindent Now \<open>xor A B\<close> and \<open>A [+] B\<close> refer to the
    45   same expression internally.  Any curried function with at least two
    45   same expression internally.  Any curried function with at least two
   136 
   136 
   137 (*<*)
   137 (*<*)
   138 hide_const xor
   138 hide_const xor
   139 setup \<open>Sign.add_path "version1"\<close>
   139 setup \<open>Sign.add_path "version1"\<close>
   140 (*>*)
   140 (*>*)
   141 definition xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl \<open>\<oplus>\<close> 60)
   141 definition xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "\<oplus>" 60)
   142 where "A \<oplus> B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
   142 where "A \<oplus> B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
   143 (*<*)
   143 (*<*)
   144 setup \<open>Sign.local_path\<close>
   144 setup \<open>Sign.local_path\<close>
   145 (*>*)
   145 (*>*)
   146 
   146 
   154 
   154 
   155 (*<*)
   155 (*<*)
   156 hide_const xor
   156 hide_const xor
   157 setup \<open>Sign.add_path "version2"\<close>
   157 setup \<open>Sign.add_path "version2"\<close>
   158 (*>*)
   158 (*>*)
   159 definition xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl \<open>[+]\<ignore>\<close> 60)
   159 definition xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "[+]\<ignore>" 60)
   160 where "A [+]\<ignore> B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
   160 where "A [+]\<ignore> B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
   161 
   161 
   162 notation (xsymbols) xor (infixl \<open>\<oplus>\<ignore>\<close> 60)
   162 notation (xsymbols) xor (infixl "\<oplus>\<ignore>" 60)
   163 (*<*)
   163 (*<*)
   164 setup \<open>Sign.local_path\<close>
   164 setup \<open>Sign.local_path\<close>
   165 (*>*)
   165 (*>*)
   166 
   166 
   167 text \<open>\noindent
   167 text \<open>\noindent
   184   priorities --- just some literal syntax.  The following example
   184   priorities --- just some literal syntax.  The following example
   185   associates common symbols with the constructors of a datatype.
   185   associates common symbols with the constructors of a datatype.
   186 \<close>
   186 \<close>
   187 
   187 
   188 datatype currency =
   188 datatype currency =
   189     Euro nat    (\<open>\<euro>\<close>)
   189     Euro nat    ("\<euro>")
   190   | Pounds nat  (\<open>\<pounds>\<close>)
   190   | Pounds nat  ("\<pounds>")
   191   | Yen nat     (\<open>\<yen>\<close>)
   191   | Yen nat     ("\<yen>")
   192   | Dollar nat  (\<open>$\<close>)
   192   | Dollar nat  ("$")
   193 
   193 
   194 text \<open>
   194 text \<open>
   195   \noindent Here the mixfix annotations on the rightmost column happen
   195   \noindent Here the mixfix annotations on the rightmost column happen
   196   to consist of a single Isabelle symbol each: \verb,\,\verb,<euro>,,
   196   to consist of a single Isabelle symbol each: \verb,\,\verb,<euro>,,
   197   \verb,\,\verb,<pounds>,, \verb,\,\verb,<yen>,, and \verb,$,.  Recall
   197   \verb,\,\verb,<pounds>,, \verb,\,\verb,<yen>,, and \verb,$,.  Recall
   221 A typical use of abbreviations is to introduce relational notation for
   221 A typical use of abbreviations is to introduce relational notation for
   222 membership in a set of pairs, replacing \<open>(x, y) \<in> sim\<close> by
   222 membership in a set of pairs, replacing \<open>(x, y) \<in> sim\<close> by
   223 \<open>x \<approx> y\<close>. We assume that a constant \<open>sim\<close> of type
   223 \<open>x \<approx> y\<close>. We assume that a constant \<open>sim\<close> of type
   224 \<^typ>\<open>('a \<times> 'a) set\<close> has been introduced at this point.\<close>
   224 \<^typ>\<open>('a \<times> 'a) set\<close> has been introduced at this point.\<close>
   225 (*<*)consts sim :: "('a \<times> 'a) set"(*>*)
   225 (*<*)consts sim :: "('a \<times> 'a) set"(*>*)
   226 abbreviation sim2 :: "'a \<Rightarrow> 'a \<Rightarrow> bool"   (infix \<open>\<approx>\<close> 50)
   226 abbreviation sim2 :: "'a \<Rightarrow> 'a \<Rightarrow> bool"   (infix "\<approx>" 50)
   227 where "x \<approx> y  \<equiv>  (x, y) \<in> sim"
   227 where "x \<approx> y  \<equiv>  (x, y) \<in> sim"
   228 
   228 
   229 text \<open>\noindent The given meta-equality is used as a rewrite rule
   229 text \<open>\noindent The given meta-equality is used as a rewrite rule
   230 after parsing (replacing \mbox{\<^prop>\<open>x \<approx> y\<close>} by \<open>(x,y) \<in>
   230 after parsing (replacing \mbox{\<^prop>\<open>x \<approx> y\<close>} by \<open>(x,y) \<in>
   231 sim\<close>) and before printing (turning \<open>(x,y) \<in> sim\<close> back into
   231 sim\<close>) and before printing (turning \<open>(x,y) \<in> sim\<close> back into
   236 provide variant versions of fundamental relational expressions, such
   236 provide variant versions of fundamental relational expressions, such
   237 as \<open>\<noteq>\<close> for negated equalities.  The following declaration
   237 as \<open>\<noteq>\<close> for negated equalities.  The following declaration
   238 stems from Isabelle/HOL itself:
   238 stems from Isabelle/HOL itself:
   239 \<close>
   239 \<close>
   240 
   240 
   241 abbreviation not_equal :: "'a \<Rightarrow> 'a \<Rightarrow> bool"    (infixl \<open>~=\<ignore>\<close> 50)
   241 abbreviation not_equal :: "'a \<Rightarrow> 'a \<Rightarrow> bool"    (infixl "~=\<ignore>" 50)
   242 where "x ~=\<ignore> y  \<equiv>  \<not> (x = y)"
   242 where "x ~=\<ignore> y  \<equiv>  \<not> (x = y)"
   243 
   243 
   244 notation (xsymbols) not_equal (infix \<open>\<noteq>\<ignore>\<close> 50)
   244 notation (xsymbols) not_equal (infix "\<noteq>\<ignore>" 50)
   245 
   245 
   246 text \<open>\noindent The notation \<open>\<noteq>\<close> is introduced separately to restrict it
   246 text \<open>\noindent The notation \<open>\<noteq>\<close> is introduced separately to restrict it
   247 to the \emph{xsymbols} mode.
   247 to the \emph{xsymbols} mode.
   248 
   248 
   249 Abbreviations are appropriate when the defined concept is a
   249 Abbreviations are appropriate when the defined concept is a