| 85 |      1 | theory Folds
 | 
| 203 |      2 | imports "Regular_Exp"
 | 
| 85 |      3 | begin
 | 
|  |      4 | 
 | 
| 203 |      5 | section {* ``Summation'' for regular expressions *}
 | 
| 85 |      6 | 
 | 
|  |      7 | text {*
 | 
|  |      8 |   To obtain equational system out of finite set of equivalence classes, a fold operation
 | 
|  |      9 |   on finite sets @{text "folds"} is defined. The use of @{text "SOME"} makes @{text "folds"}
 | 
|  |     10 |   more robust than the @{text "fold"} in the Isabelle library. The expression @{text "folds f"}
 | 
|  |     11 |   makes sense when @{text "f"} is not @{text "associative"} and @{text "commutitive"},
 | 
|  |     12 |   while @{text "fold f"} does not.  
 | 
|  |     13 | *}
 | 
|  |     14 | 
 | 
|  |     15 | 
 | 
|  |     16 | definition 
 | 
|  |     17 |   folds :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b"
 | 
|  |     18 | where
 | 
|  |     19 |   "folds f z S \<equiv> SOME x. fold_graph f z S x"
 | 
|  |     20 | 
 | 
| 203 |     21 | text {* Plus-combination for a set of regular expressions *}
 | 
|  |     22 | 
 | 
|  |     23 | abbreviation
 | 
|  |     24 |   Setalt :: "'a rexp set \<Rightarrow> 'a rexp" ("\<Uplus>_" [1000] 999) 
 | 
|  |     25 | where
 | 
|  |     26 |   "\<Uplus>A \<equiv> folds Plus Zero A"
 | 
|  |     27 | 
 | 
|  |     28 | text {* 
 | 
|  |     29 |   For finite sets, @{term Setalt} is preserved under @{term lang}.
 | 
|  |     30 | *}
 | 
|  |     31 | 
 | 
|  |     32 | lemma folds_plus_simp [simp]:
 | 
|  |     33 |   fixes rs::"('a rexp) set"
 | 
|  |     34 |   assumes a: "finite rs"
 | 
|  |     35 |   shows "lang (\<Uplus>rs) = \<Union> (lang ` rs)"
 | 
|  |     36 | unfolding folds_def
 | 
|  |     37 | apply(rule set_eqI)
 | 
|  |     38 | apply(rule someI2_ex)
 | 
|  |     39 | apply(rule_tac finite_imp_fold_graph[OF a])
 | 
|  |     40 | apply(erule fold_graph.induct)
 | 
|  |     41 | apply(auto)
 | 
|  |     42 | done
 | 
| 85 |     43 | 
 | 
|  |     44 | end |