Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  Suc_Notation.thy

  Sprache: Isabelle
 

(*  Title:      HOL/Library/Suc_Notation.thy
    Author:     Manuel Eberl and Tobias Nipkow

Compact notation for nested \<open>Suc\<close> terms. Just notation. Use standard numerals for large numbers.
*)


theory Suc_Notation
imports Main
begin

text Nested Suc terms of depth 2 n 9 are abbreviated with new notations Sucn:

abbreviation (input) Suc2 where "Suc2 n Suc (Suc n)"
abbreviation (input) Suc3 where "Suc3 n Suc (Suc2 n)"
abbreviation (input) Suc4 where "Suc4 n Suc (Suc3 n)"
abbreviation (input) Suc5 where "Suc5 n Suc (Suc4 n)"
abbreviation (input) Suc6 where "Suc6 n Suc (Suc5 n)"
abbreviation (input) Suc7 where "Suc7 n Suc (Suc6 n)"
abbreviation (input) Suc8 where "Suc8 n Suc (Suc7 n)"
abbreviation (input) Suc9 where "Suc9 n Suc (Suc8 n)"

notation Suc2 ("Suc2")
notation Suc3 ("Suc3")
notation Suc4 ("Suc4")
notation Suc5 ("Suc5")
notation Suc6 ("Suc6")
notation Suc7 ("Suc7")
notation Suc8 ("Suc8")
notation Suc9 ("Suc9")

text Beyond 9, the syntax Suc kicks in:

syntax
  "_Suc_tower" :: "num_token nat nat"  ("Suc")

parse_translation 
 let
 fun mk_sucs_aux 0 t = t
 | mk_sucs_aux n t = mk_sucs_aux (n - 1) (constSuc $ t)
 fun mk_sucs n = Abs("n", typnat, mk_sucs_aux n (Bound 0))

 fun Suc_tr [Free (str, _)] = mk_sucs (the (Int.fromString str))

 in [(syntax_const_Suc_tower, K Suc_tr)] end
 


print_translation 
 let
 val digit_consts =
 [const_syntaxSuc2, const_syntaxSuc3, const_syntaxSuc4, const_syntaxSuc5,
 const_syntaxSuc6, const_syntaxSuc7, const_syntaxSuc8, const_syntaxSuc9]
 val num_token_T = Simple_Syntax.read_typ "num_token"
 val T = num_token_T --> HOLogic.natT --> HOLogic.natT
 fun mk_num_token n = Free (Int.toString n, num_token_T)
 fun dest_Suc_tower (Const (const_syntaxSuc, _) $ t) acc =
 dest_Suc_tower t (acc + 1)
 | dest_Suc_tower t acc = (t, acc)

 fun Suc_tr' [t] =
 let
 val (t', n) = dest_Suc_tower t 1
 in
 if n > 9 then
 Const (syntax_const_Suc_tower, T) $ mk_num_token n $ t'
 else if n > 1 then
 Const (List.nth (digit_consts, n - 2), T) $ t'
 else
 raise Match
 end

 in [(const_syntaxSuc, K Suc_tr')]
 end
 


(* Tests

ML \<open>
local
  fun mk 0 = \<^term>\<open>x :: nat\<close>
    | mk n = \<^const>\<open>Suc\<close> $ mk (n - 1)
  val ctxt' = Variable.add_fixes_implicit @{term "x :: nat"} @{context}
in
  val _ =
    map_range (fn n => (n + 1, mk (n + 1))) 20
    |> map (fn (n, t) => 
         Pretty.block [Pretty.str (Int.toString n ^ ": "),
           Syntax.pretty_term ctxt' t] |> Pretty.writeln)
end
\<close>

(* test parsing *)

term "Suc x"
term "Suc2 x"
term "Suc3 x"
term "Suc4 x"
term "Suc5 x"
term "Suc6 x"
term "Suc7 x"
term "Suc8 x"
term "Suc9 x"

term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"
term "Suc x"

(* check that the notation really means the right thing *)
lemma "Suc2 n = n+2 Suc3 n = n+3 Suc4 n = n+4 Suc5 n = n+5
   Suc6 n = n+6 Suc7 n = n+7 Suc8 n = n+8 Suc9 n = n+9"
by simp

lemma "Suc n = n+10 Suc n = n+11 Suc n = n+12 Suc n = n+13
   Suc n = n+14 Suc n = n+15 Suc n = n+16 Suc n = n+17
   Suc n = n+18 Suc n = n+19 Suc n = n+20"
by simp

*)

end

Messung V0.5 in Prozent
C=59 H=97 G=80

¤ Dauer der Verarbeitung: 0.10 Sekunden  (vorverarbeitet am  2026-06-30) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik