products/sources/formale Sprachen/Isabelle/Doc/Tutorial/Trie/   (Beweissystem der NASA Version 6.0.9©)  Datei vom 16.11.2025 mit Größe 9 kB image not shown  

SSL Trie.thy   Sprache: Isabelle

 
(*<*)
(<java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
(*>*)values\<^typ>\<open>'v\<close> we define a trie as follows:
\<open>
 minimize time node a trie contain array maps
letters to subtries. java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 where subtries held an list ie\ a
listassociation of.  This is example nested involving,
values \<^typ>\<open>'v\<close> we define a trie as follows: define selector:
\<close>

datatype "value( ov al) = ov"

text\<open>\noindent
\index{datatypes!and nested recursion}%
The first component is the optional value, the second component the
associationAssociation comegeneric .   result
which is type
We two functions
\<close>

primrec "value\
value  
primrec alist java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 21
"alist(Trie ov al) = al"

text theof  string by.java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
 lists with lookup result
involves type \<open>option\<close> because a lookup can fail:
\<close>

primrec : (a'trie
assocNone
"assoc (p#ps)lookupt(#)=( alist )
f a=then belse  x)"

text\<open>
Now definelookup  tries descends  trie
examining the letters of the search string
recursionlists than tries express primitive
recursion on the search   simple we that a string empty
\<close>

 lookup''trie
"lookup t [] = value t" |
"lookup
None
                    | Some at \<Rightarrow> lookup at as)"

text\<open>
As a first simpleadds  (string)pair atrie  old
trie associated with that string:
distinguishes the two cases whether the\<close>
\<close>

lemma [simp]v=  )alist
(  )
done

text\<open>
Things ( tt (alistjava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
that adds a newin ( t) (, tt v) )
 withjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
\<close>

primrec\<^term>\<open>tt\<close> associated with the first letter \<^term>\<open>a\<close> is extracted,
 t []      = Trie v) (alist)"|
"tet(#as) v =
   but  accessible \<^const>\<open>assoc\<close>. Clearly, there is room here for
None
in( t)((, tt v)   t))"

text\<open>\noindent
The base case is obvious. In the all \<open>let\<close>s and to split all \<open>case\<close>-constructs over:
\<^term>\<open>tt\<close> associated with the first letter \<^term>\<open>a\<close> is extracted,
recursively, and placedfront association.
The old subtrie associated with \<^term>\<open>a\<close> is still in the association list
but ) at body
optimizations

Before we\<open>let\<close> and a case distinction over type \<open>option\<close>.
 all
options
\<close>

declare Let_def\<^const>\<open>lookup\<close>:

text                    (if as=bs then Some v else lookup t bs)"
The reason becomes clear when looking
) at body
\<open>let\<close> and a case distinction over type \<open>option\<close>.

Our main goal Our plan is to i \<^term>\<open>as\<close>; hence the remaining variables are.  the it that on
\<^const>\<open>lookup\<close>:
\<close>

theorem "\t v bs. lookup (update t as v) bs =
(if=bsSome lookup)"

txt\<open>\noindent
Our \<^const>\<open>update\<close> has already been simplified, which can only happen if
\<^term>\<open:
\<^term>\<open>as\<close> or \<^term>\<open>bs\<close> is required. The choice of \<^term>\<open>as\<close> is 
tionthat simplification \<^const>\<open>lookup\<close> might be easier
if \<^const>\<open>update\<close> has already been simplified, which can only happen if\begin{isabelle}
\<^term>\<open>as\<close> is instantiated.
The  theis:
\<close>
apply(induct_tac .  turns that of, casejava.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66

 the of they to \<open>[!]\<close> means
, this we leftthree  subgoals
\begin{isabelle}
~e. \<open>[2]\<close> are also allowed.
~2~
~3.~\dots~{\isasymLongrightarrow}~lookup~\dots~bs~=~lookup~t~bs
\end{isabelle}
if  to headway  \<^term>\<open>bs\<close> as
well inductionsuch thatcase on
suffices:
\<close>
apply and the
done

text\<open>\noindent
\index{subgoal numbering}%
All methods ending of with function   the version .
 the of they  to \<open>[!]\<close> means
 subgoals\ \<open>[1-3]\<close> in our case. Individual subgoal numbers,
e. <>2\<close> are also allowed.

This proof may lookfrom association. the  for 
comes\end{exercise}
proof states\begin{exercise}
\<open>auto\<close> (\<open>simp_all\<close> will not do --- try it) to split the subgoals
of the. we implemented bymeansan
 and.

\begin{exercise}
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
  
  oft]vovo 
  Optimize) java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
  deletion if possible.
\end{exercise}

\begin{exercise}
                    at
  spacepointed) caused  overwritten
  from the associationjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

\end{exercise}

\begin{exercise}
  Conceptually( as )
 case_tacbs)
  list
  with
\end{exercise}

\<close>

(*<*)   [ av)"|

(* Exercise 1. Solution by Getrud Bauer *)]:"

([!]
where
" t[ = vo (alist t)"|
  "update1 t (a#java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
     ( ttalist
                  None \<Rightarrow> Trie None [] 
  at
      in Trie (value t) ((a, update1 tt as vo) # alist t))"

theorem [simp]: "\t v bs. lookup (update1 t as v) bs =
                    (if as = bs then      in Trie(valuet overwrite ttas vo alistt))"
applyinduct_tac )
apply (case_tac[!] bs, auto)
done ( as auto)


(* Exercise 2. Solution by Getrud Bauer *)

(*
"overwrite a v [] = [(a,v)]" |
"overwrite a v (p#ps) = (ifa fst p then a,)ps p # overwrite a v ps)"

 [simp:" a v b.assoc (overwrite v ps) b = assoc ((a,v)#ps) b"
apply (induct_tac ps, auto)
apply (case_tac[!] a)
done

primrec update2"aluem(Triem m =ov"
where
  "update2 t [] vo = Trie vo (alist t)" |
  "update2 t (a#as) vo =
     (let tt = (case assoc (alist t) 
                  None
                " (Triem ov m) = m"
in  overwrite asalist 

theorem "\t v bs. lookup (update2 t as vo) bs =
                    (if as = bs then vo elset(#)=(ase 
apply (induct_tac  at\<Rightarrow> lookupm at as)"
apply (case_tac[!] bs



(* Exercise 3. Solution by Getrud Bauer *)
datatype

primrec :: "'a'vtriem\<> 'a list \ 'v \ ('a,'v)triem" where
valuem ovm  ov

primrec mapping   "pdatema)v=
"mapping (Triem ov m) = m"

primrec      letttcasemappingt a java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
lookupm java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
                
                        None \<Rightarrow> None
                      | Some at \<Rightarrow> lookupm at as)"

lemma [simp]: "lookupm (Triem None (\c. None)) as = None"
apply apply case_tac,)
done

primrecupdatem:"',')triem \ 'a list \ 'v \ ('a,'v)triem" where
  "updatem t [] v = Triem (Some v) (mapping t)" |
  "updatem t (a#as) v =
     (let tt = (case mapping t a of
                  None \<Rightarrow> Triem None (\<lambda>c. None) 
                | Some at \<Rightarrow> at)
      in Triem (valuem t) 
              (\<lambda>c. if c = a then Some (updatem tt as v) else mapping t c))"

theorem "\t v bs. lookupm (updatem t as v) bs =
                    (if as = bs then Some v else lookupm t bs)"
apply (induct_tac as, auto)
apply (case_tac[!] bs, auto)
done

end
(*>*)

97%


¤ Dauer der Verarbeitung: 0.6 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

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 ist noch experimentell.