1600 proof |
1732 proof |
1601 assume "(n1, n2) \<in> RAG s" |
1733 assume "(n1, n2) \<in> RAG s" |
1602 thus ?thesis |
1734 thus ?thesis |
1603 proof(cases rule:in_RAG_E) |
1735 proof(cases rule:in_RAG_E) |
1604 case (waiting th' cs') |
1736 case (waiting th' cs') |
1605 find_theorems waiting e s |
1737 from waiting_kept[OF this(3)] |
1606 qed |
1738 show ?thesis using waiting(1,2) |
1607 qed |
1739 by (unfold s_RAG_def, fold waiting_eq, auto) |
1608 qed |
1740 next |
1609 |
1741 case (holding th' cs') |
1610 end |
1742 from holding_kept[OF this(3)] |
1611 |
1743 show ?thesis using holding(1,2) |
1612 |
1744 by (unfold s_RAG_def, fold holding_eq, auto) |
1613 |
1745 qed |
1614 lemma "RAG (e # s) = (if (wq s cs = []) then RAG s \<union> {(Cs cs, Th th)} |
1746 next |
1615 else RAG s \<union> {(Th th, Cs cs)})" |
1747 assume "n1 = Cs cs \<and> n2 = Th th" |
|
1748 with holding_es_th_cs |
|
1749 show ?thesis |
|
1750 by (unfold s_RAG_def, fold holding_eq, auto) |
|
1751 qed |
|
1752 qed |
|
1753 |
|
1754 end |
|
1755 |
|
1756 context valid_trace_p |
|
1757 begin |
|
1758 |
|
1759 lemma RAG_es': "RAG (e # s) = (if (wq s cs = []) then RAG s \<union> {(Cs cs, Th th)} |
|
1760 else RAG s \<union> {(Th th, Cs cs)})" |
|
1761 proof(cases "wq s cs = []") |
|
1762 case True |
|
1763 interpret vt_p: valid_trace_p_h using True |
|
1764 by (unfold_locales, simp) |
|
1765 show ?thesis by (simp add: vt_p.RAG_es vt_p.we) |
|
1766 next |
|
1767 case False |
|
1768 interpret vt_p: valid_trace_p_w using False |
|
1769 by (unfold_locales, simp) |
|
1770 show ?thesis by (simp add: vt_p.RAG_es vt_p.wne) |
|
1771 qed |
|
1772 |
|
1773 end |
|
1774 |
|
1775 lemma (in valid_trace_v_n) finite_waiting_set: |
|
1776 "finite {(Th th', Cs cs) |th'. next_th s th cs th'}" |
|
1777 by (simp add: waiting_set_eq) |
|
1778 |
|
1779 lemma (in valid_trace_v_n) finite_holding_set: |
|
1780 "finite {(Cs cs, Th th') |th'. next_th s th cs th'}" |
|
1781 by (simp add: holding_set_eq) |
|
1782 |
|
1783 lemma (in valid_trace_v_e) finite_waiting_set: |
|
1784 "finite {(Th th', Cs cs) |th'. next_th s th cs th'}" |
|
1785 by (simp add: waiting_set_eq) |
|
1786 |
|
1787 lemma (in valid_trace_v_e) finite_holding_set: |
|
1788 "finite {(Cs cs, Th th') |th'. next_th s th cs th'}" |
|
1789 by (simp add: holding_set_eq) |
|
1790 |
|
1791 context valid_trace_v |
|
1792 begin |
|
1793 |
|
1794 lemma |
|
1795 finite_RAG_kept: |
|
1796 assumes "finite (RAG s)" |
|
1797 shows "finite (RAG (e#s))" |
|
1798 proof(cases "rest = []") |
|
1799 case True |
|
1800 interpret vt: valid_trace_v_e using True |
|
1801 by (unfold_locales, simp) |
|
1802 show ?thesis using assms |
|
1803 by (unfold RAG_es vt.waiting_set_eq vt.holding_set_eq, simp) |
|
1804 next |
|
1805 case False |
|
1806 interpret vt: valid_trace_v_n using False |
|
1807 by (unfold_locales, simp) |
|
1808 show ?thesis using assms |
|
1809 by (unfold RAG_es vt.waiting_set_eq vt.holding_set_eq, simp) |
|
1810 qed |
|
1811 |
|
1812 end |
|
1813 |
|
1814 context valid_trace_v_e |
|
1815 begin |
|
1816 |
|
1817 lemma |
|
1818 acylic_RAG_kept: |
|
1819 assumes "acyclic (RAG s)" |
|
1820 shows "acyclic (RAG (e#s))" |
|
1821 proof(rule acyclic_subset[OF assms]) |
|
1822 show "RAG (e # s) \<subseteq> RAG s" |
|
1823 by (unfold RAG_es waiting_set_eq holding_set_eq, auto) |
|
1824 qed |
|
1825 |
|
1826 end |
|
1827 |
|
1828 context valid_trace_v_n |
|
1829 begin |
|
1830 |
|
1831 lemma waiting_taker: "waiting s taker cs" |
|
1832 apply (unfold s_waiting_def, fold wq_def, unfold wq_s_cs taker_def) |
|
1833 using eq_wq' th'_in_inv wq'_def by fastforce |
|
1834 |
|
1835 lemma |
|
1836 acylic_RAG_kept: |
|
1837 assumes "acyclic (RAG s)" |
|
1838 shows "acyclic (RAG (e#s))" |
|
1839 proof - |
|
1840 have "acyclic ((RAG s - {(Cs cs, Th th)} - {(Th taker, Cs cs)}) \<union> |
|
1841 {(Cs cs, Th taker)})" (is "acyclic (?A \<union> _)") |
|
1842 proof - |
|
1843 from assms |
|
1844 have "acyclic ?A" |
|
1845 by (rule acyclic_subset, auto) |
|
1846 moreover have "(Th taker, Cs cs) \<notin> ?A^*" |
|
1847 proof |
|
1848 assume otherwise: "(Th taker, Cs cs) \<in> ?A^*" |
|
1849 hence "(Th taker, Cs cs) \<in> ?A^+" |
|
1850 by (unfold rtrancl_eq_or_trancl, auto) |
|
1851 from tranclD[OF this] |
|
1852 obtain cs' where h: "(Th taker, Cs cs') \<in> ?A" |
|
1853 "(Th taker, Cs cs') \<in> RAG s" |
|
1854 by (unfold s_RAG_def, auto) |
|
1855 from this(2) have "waiting s taker cs'" |
|
1856 by (unfold s_RAG_def, fold waiting_eq, auto) |
|
1857 from waiting_unique[OF this waiting_taker] |
|
1858 have "cs' = cs" . |
|
1859 from h(1)[unfolded this] show False by auto |
|
1860 qed |
|
1861 ultimately show ?thesis by auto |
|
1862 qed |
|
1863 thus ?thesis |
|
1864 by (unfold RAG_es waiting_set_eq holding_set_eq, simp) |
|
1865 qed |
|
1866 |
|
1867 end |
|
1868 |
|
1869 context valid_trace_p_h |
|
1870 begin |
|
1871 |
|
1872 lemma |
|
1873 acylic_RAG_kept: |
|
1874 assumes "acyclic (RAG s)" |
|
1875 shows "acyclic (RAG (e#s))" |
|
1876 proof - |
|
1877 have "acyclic (RAG s \<union> {(Cs cs, Th th)})" (is "acyclic (?A \<union> _)") |
|
1878 proof - |
|
1879 from assms |
|
1880 have "acyclic ?A" |
|
1881 by (rule acyclic_subset, auto) |
|
1882 moreover have "(Th th, Cs cs) \<notin> ?A^*" |
|
1883 proof |
|
1884 assume otherwise: "(Th th, Cs cs) \<in> ?A^*" |
|
1885 hence "(Th th, Cs cs) \<in> ?A^+" |
|
1886 by (unfold rtrancl_eq_or_trancl, auto) |
|
1887 from tranclD[OF this] |
|
1888 obtain cs' where h: "(Th th, Cs cs') \<in> RAG s" |
|
1889 by (unfold s_RAG_def, auto) |
|
1890 hence "waiting s th cs'" |
|
1891 by (unfold s_RAG_def, fold waiting_eq, auto) |
|
1892 with th_not_waiting show False by auto |
|
1893 qed |
|
1894 ultimately show ?thesis by auto |
|
1895 qed |
|
1896 thus ?thesis by (unfold RAG_es, simp) |
|
1897 qed |
|
1898 |
|
1899 end |
|
1900 |
|
1901 context valid_trace_p_w |
|
1902 begin |
|
1903 |
|
1904 lemma |
|
1905 acylic_RAG_kept: |
|
1906 assumes "acyclic (RAG s)" |
|
1907 shows "acyclic (RAG (e#s))" |
|
1908 proof - |
|
1909 have "acyclic (RAG s \<union> {(Th th, Cs cs)})" (is "acyclic (?A \<union> _)") |
|
1910 proof - |
|
1911 from assms |
|
1912 have "acyclic ?A" |
|
1913 by (rule acyclic_subset, auto) |
|
1914 moreover have "(Cs cs, Th th) \<notin> ?A^*" |
|
1915 proof |
|
1916 assume otherwise: "(Cs cs, Th th) \<in> ?A^*" |
|
1917 from pip_e[unfolded is_p] |
|
1918 show False |
|
1919 proof(cases) |
|
1920 case (thread_P) |
|
1921 moreover from otherwise have "(Cs cs, Th th) \<in> ?A^+" |
|
1922 by (unfold rtrancl_eq_or_trancl, auto) |
|
1923 ultimately show ?thesis by auto |
|
1924 qed |
|
1925 qed |
|
1926 ultimately show ?thesis by auto |
|
1927 qed |
|
1928 thus ?thesis by (unfold RAG_es, simp) |
|
1929 qed |
|
1930 |
|
1931 end |
|
1932 |
|
1933 context valid_trace |
|
1934 begin |
|
1935 |
|
1936 lemma finite_RAG: |
|
1937 shows "finite (RAG s)" |
|
1938 proof(induct rule:ind) |
|
1939 case Nil |
|
1940 show ?case |
|
1941 by (auto simp: s_RAG_def cs_waiting_def |
|
1942 cs_holding_def wq_def acyclic_def) |
|
1943 next |
|
1944 case (Cons s e) |
|
1945 interpret vt_e: valid_trace_e s e using Cons by simp |
|
1946 show ?case |
|
1947 proof(cases e) |
|
1948 case (Create th prio) |
|
1949 interpret vt: valid_trace_create s e th prio using Create |
|
1950 by (unfold_locales, simp) |
|
1951 show ?thesis using Cons by (simp add: vt.RAG_unchanged) |
|
1952 next |
|
1953 case (Exit th) |
|
1954 interpret vt: valid_trace_exit s e th using Exit |
|
1955 by (unfold_locales, simp) |
|
1956 show ?thesis using Cons by (simp add: vt.RAG_unchanged) |
|
1957 next |
|
1958 case (P th cs) |
|
1959 interpret vt: valid_trace_p s e th cs using P |
|
1960 by (unfold_locales, simp) |
|
1961 show ?thesis using Cons using vt.RAG_es' by auto |
|
1962 next |
|
1963 case (V th cs) |
|
1964 interpret vt: valid_trace_v s e th cs using V |
|
1965 by (unfold_locales, simp) |
|
1966 show ?thesis using Cons by (simp add: vt.finite_RAG_kept) |
|
1967 next |
|
1968 case (Set th prio) |
|
1969 interpret vt: valid_trace_set s e th prio using Set |
|
1970 by (unfold_locales, simp) |
|
1971 show ?thesis using Cons by (simp add: vt.RAG_unchanged) |
|
1972 qed |
|
1973 qed |
|
1974 |
|
1975 lemma acyclic_RAG: |
|
1976 shows "acyclic (RAG s)" |
|
1977 proof(induct rule:ind) |
|
1978 case Nil |
|
1979 show ?case |
|
1980 by (auto simp: s_RAG_def cs_waiting_def |
|
1981 cs_holding_def wq_def acyclic_def) |
|
1982 next |
|
1983 case (Cons s e) |
|
1984 interpret vt_e: valid_trace_e s e using Cons by simp |
|
1985 show ?case |
|
1986 proof(cases e) |
|
1987 case (Create th prio) |
|
1988 interpret vt: valid_trace_create s e th prio using Create |
|
1989 by (unfold_locales, simp) |
|
1990 show ?thesis using Cons by (simp add: vt.RAG_unchanged) |
|
1991 next |
|
1992 case (Exit th) |
|
1993 interpret vt: valid_trace_exit s e th using Exit |
|
1994 by (unfold_locales, simp) |
|
1995 show ?thesis using Cons by (simp add: vt.RAG_unchanged) |
|
1996 next |
|
1997 case (P th cs) |
|
1998 interpret vt: valid_trace_p s e th cs using P |
|
1999 by (unfold_locales, simp) |
|
2000 show ?thesis |
|
2001 proof(cases "wq s cs = []") |
|
2002 case True |
|
2003 then interpret vt_h: valid_trace_p_h s e th cs |
|
2004 by (unfold_locales, simp) |
|
2005 show ?thesis using Cons by (simp add: vt_h.acylic_RAG_kept) |
|
2006 next |
|
2007 case False |
|
2008 then interpret vt_w: valid_trace_p_w s e th cs |
|
2009 by (unfold_locales, simp) |
|
2010 show ?thesis using Cons by (simp add: vt_w.acylic_RAG_kept) |
|
2011 qed |
|
2012 next |
|
2013 case (V th cs) |
|
2014 interpret vt: valid_trace_v s e th cs using V |
|
2015 by (unfold_locales, simp) |
|
2016 show ?thesis |
|
2017 proof(cases "vt.rest = []") |
|
2018 case True |
|
2019 then interpret vt_e: valid_trace_v_e s e th cs |
|
2020 by (unfold_locales, simp) |
|
2021 show ?thesis by (simp add: Cons.hyps(2) vt_e.acylic_RAG_kept) |
|
2022 next |
|
2023 case False |
|
2024 then interpret vt_n: valid_trace_v_n s e th cs |
|
2025 by (unfold_locales, simp) |
|
2026 show ?thesis by (simp add: Cons.hyps(2) vt_n.acylic_RAG_kept) |
|
2027 qed |
|
2028 next |
|
2029 case (Set th prio) |
|
2030 interpret vt: valid_trace_set s e th prio using Set |
|
2031 by (unfold_locales, simp) |
|
2032 show ?thesis using Cons by (simp add: vt.RAG_unchanged) |
|
2033 qed |
|
2034 qed |
|
2035 |
|
2036 lemma wf_RAG: "wf (RAG s)" |
|
2037 proof(rule finite_acyclic_wf) |
|
2038 from finite_RAG show "finite (RAG s)" . |
|
2039 next |
|
2040 from acyclic_RAG show "acyclic (RAG s)" . |
|
2041 qed |
|
2042 |
|
2043 lemma sgv_wRAG: "single_valued (wRAG s)" |
|
2044 using waiting_unique |
|
2045 by (unfold single_valued_def wRAG_def, auto) |
|
2046 |
|
2047 lemma sgv_hRAG: "single_valued (hRAG s)" |
|
2048 using held_unique |
|
2049 by (unfold single_valued_def hRAG_def, auto) |
|
2050 |
|
2051 lemma sgv_tRAG: "single_valued (tRAG s)" |
|
2052 by (unfold tRAG_def, rule single_valued_relcomp, |
|
2053 insert sgv_wRAG sgv_hRAG, auto) |
|
2054 |
|
2055 lemma acyclic_tRAG: "acyclic (tRAG s)" |
|
2056 proof(unfold tRAG_def, rule acyclic_compose) |
|
2057 show "acyclic (RAG s)" using acyclic_RAG . |
|
2058 next |
|
2059 show "wRAG s \<subseteq> RAG s" unfolding RAG_split by auto |
|
2060 next |
|
2061 show "hRAG s \<subseteq> RAG s" unfolding RAG_split by auto |
|
2062 qed |
|
2063 |
|
2064 lemma unique_RAG: "\<lbrakk>(n, n1) \<in> RAG s; (n, n2) \<in> RAG s\<rbrakk> \<Longrightarrow> n1 = n2" |
|
2065 apply(unfold s_RAG_def, auto, fold waiting_eq holding_eq) |
|
2066 by(auto elim:waiting_unique held_unique) |
|
2067 |
|
2068 lemma sgv_RAG: "single_valued (RAG s)" |
|
2069 using unique_RAG by (auto simp:single_valued_def) |
|
2070 |
|
2071 lemma rtree_RAG: "rtree (RAG s)" |
|
2072 using sgv_RAG acyclic_RAG |
|
2073 by (unfold rtree_def rtree_axioms_def sgv_def, auto) |
|
2074 |
|
2075 end |
|
2076 |
|
2077 sublocale valid_trace < rtree_RAG: rtree "RAG s" |
|
2078 proof |
|
2079 show "single_valued (RAG s)" |
|
2080 apply (intro_locales) |
|
2081 by (unfold single_valued_def, |
|
2082 auto intro:unique_RAG) |
|
2083 |
|
2084 show "acyclic (RAG s)" |
|
2085 by (rule acyclic_RAG) |
|
2086 qed |
|
2087 |
|
2088 sublocale valid_trace < rtree_s: rtree "tRAG s" |
|
2089 proof(unfold_locales) |
|
2090 from sgv_tRAG show "single_valued (tRAG s)" . |
|
2091 next |
|
2092 from acyclic_tRAG show "acyclic (tRAG s)" . |
|
2093 qed |
|
2094 |
|
2095 sublocale valid_trace < fsbtRAGs : fsubtree "RAG s" |
|
2096 proof - |
|
2097 show "fsubtree (RAG s)" |
|
2098 proof(intro_locales) |
|
2099 show "fbranch (RAG s)" using finite_fbranchI[OF finite_RAG] . |
|
2100 next |
|
2101 show "fsubtree_axioms (RAG s)" |
|
2102 proof(unfold fsubtree_axioms_def) |
|
2103 from wf_RAG show "wf (RAG s)" . |
|
2104 qed |
|
2105 qed |
|
2106 qed |
|
2107 |
|
2108 context valid_trace |
|
2109 begin |
|
2110 |
|
2111 lemma finite_subtree_threads: |
|
2112 "finite {th'. Th th' \<in> subtree (RAG s) (Th th)}" (is "finite ?A") |
|
2113 proof - |
|
2114 have "?A = the_thread ` {Th th' | th' . Th th' \<in> subtree (RAG s) (Th th)}" |
|
2115 by (auto, insert image_iff, fastforce) |
|
2116 moreover have "finite {Th th' | th' . Th th' \<in> subtree (RAG s) (Th th)}" |
|
2117 (is "finite ?B") |
|
2118 proof - |
|
2119 have "?B = (subtree (RAG s) (Th th)) \<inter> {Th th' | th'. True}" |
|
2120 by auto |
|
2121 moreover have "... \<subseteq> (subtree (RAG s) (Th th))" by auto |
|
2122 moreover have "finite ..." by (simp add: finite_subtree) |
|
2123 ultimately show ?thesis by auto |
|
2124 qed |
|
2125 ultimately show ?thesis by auto |
|
2126 qed |
|
2127 |
|
2128 lemma le_cp: |
|
2129 shows "preced th s \<le> cp s th" |
|
2130 proof(unfold cp_alt_def, rule Max_ge) |
|
2131 show "finite (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)})" |
|
2132 by (simp add: finite_subtree_threads) |
|
2133 next |
|
2134 show "preced th s \<in> the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th)}" |
|
2135 by (simp add: subtree_def the_preced_def) |
|
2136 qed |
|
2137 |
|
2138 lemma cp_le: |
|
2139 assumes th_in: "th \<in> threads s" |
|
2140 shows "cp s th \<le> Max (the_preced s ` threads s)" |
|
2141 proof(unfold cp_alt_def, rule Max_f_mono) |
|
2142 show "finite (threads s)" by (simp add: finite_threads) |
|
2143 next |
|
2144 show " {th'. Th th' \<in> subtree (RAG s) (Th th)} \<noteq> {}" |
|
2145 using subtree_def by fastforce |
|
2146 next |
|
2147 show "{th'. Th th' \<in> subtree (RAG s) (Th th)} \<subseteq> threads s" |
|
2148 using assms |
|
2149 by (smt Domain.DomainI dm_RAG_threads mem_Collect_eq |
|
2150 node.inject(1) rtranclD subsetI subtree_def trancl_domain) |
|
2151 qed |
|
2152 |
|
2153 lemma max_cp_eq: |
|
2154 shows "Max ((cp s) ` threads s) = Max (the_preced s ` threads s)" |
|
2155 (is "?L = ?R") |
|
2156 proof - |
|
2157 have "?L \<le> ?R" |
|
2158 proof(cases "threads s = {}") |
|
2159 case False |
|
2160 show ?thesis |
|
2161 by (rule Max.boundedI, |
|
2162 insert cp_le, |
|
2163 auto simp:finite_threads False) |
|
2164 qed auto |
|
2165 moreover have "?R \<le> ?L" |
|
2166 by (rule Max_fg_mono, |
|
2167 simp add: finite_threads, |
|
2168 simp add: le_cp the_preced_def) |
|
2169 ultimately show ?thesis by auto |
|
2170 qed |
|
2171 |
|
2172 lemma max_cp_eq_the_preced: |
|
2173 shows "Max ((cp s) ` threads s) = Max (the_preced s ` threads s)" |
|
2174 using max_cp_eq using the_preced_def by presburger |
|
2175 |
|
2176 lemma wf_RAG_converse: |
|
2177 shows "wf ((RAG s)^-1)" |
|
2178 proof(rule finite_acyclic_wf_converse) |
|
2179 from finite_RAG |
|
2180 show "finite (RAG s)" . |
|
2181 next |
|
2182 from acyclic_RAG |
|
2183 show "acyclic (RAG s)" . |
|
2184 qed |
|
2185 |
|
2186 lemma chain_building: |
|
2187 assumes "node \<in> Domain (RAG s)" |
|
2188 obtains th' where "th' \<in> readys s" "(node, Th th') \<in> (RAG s)^+" |
|
2189 proof - |
|
2190 from assms have "node \<in> Range ((RAG s)^-1)" by auto |
|
2191 from wf_base[OF wf_RAG_converse this] |
|
2192 obtain b where h_b: "(b, node) \<in> ((RAG s)\<inverse>)\<^sup>+" "\<forall>c. (c, b) \<notin> (RAG s)\<inverse>" by auto |
|
2193 obtain th' where eq_b: "b = Th th'" |
|
2194 proof(cases b) |
|
2195 case (Cs cs) |
|
2196 from h_b(1)[unfolded trancl_converse] |
|
2197 have "(node, b) \<in> ((RAG s)\<^sup>+)" by auto |
|
2198 from tranclE[OF this] |
|
2199 obtain n where "(n, b) \<in> RAG s" by auto |
|
2200 from this[unfolded Cs] |
|
2201 obtain th1 where "waiting s th1 cs" |
|
2202 by (unfold s_RAG_def, fold waiting_eq, auto) |
|
2203 from waiting_holding[OF this] |
|
2204 obtain th2 where "holding s th2 cs" . |
|
2205 hence "(Cs cs, Th th2) \<in> RAG s" |
|
2206 by (unfold s_RAG_def, fold holding_eq, auto) |
|
2207 with h_b(2)[unfolded Cs, rule_format] |
|
2208 have False by auto |
|
2209 thus ?thesis by auto |
|
2210 qed auto |
|
2211 have "th' \<in> readys s" |
|
2212 proof - |
|
2213 from h_b(2)[unfolded eq_b] |
|
2214 have "\<forall>cs. \<not> waiting s th' cs" |
|
2215 by (unfold s_RAG_def, fold waiting_eq, auto) |
|
2216 moreover have "th' \<in> threads s" |
|
2217 proof(rule rg_RAG_threads) |
|
2218 from tranclD[OF h_b(1), unfolded eq_b] |
|
2219 obtain z where "(z, Th th') \<in> (RAG s)" by auto |
|
2220 thus "Th th' \<in> Range (RAG s)" by auto |
|
2221 qed |
|
2222 ultimately show ?thesis by (auto simp:readys_def) |
|
2223 qed |
|
2224 moreover have "(node, Th th') \<in> (RAG s)^+" |
|
2225 using h_b(1)[unfolded trancl_converse] eq_b by auto |
|
2226 ultimately show ?thesis using that by metis |
|
2227 qed |
|
2228 |
|
2229 text {* \noindent |
|
2230 The following is just an instance of @{text "chain_building"}. |
|
2231 *} |
|
2232 lemma th_chain_to_ready: |
|
2233 assumes th_in: "th \<in> threads s" |
|
2234 shows "th \<in> readys s \<or> (\<exists> th'. th' \<in> readys s \<and> (Th th, Th th') \<in> (RAG s)^+)" |
|
2235 proof(cases "th \<in> readys s") |
|
2236 case True |
|
2237 thus ?thesis by auto |
|
2238 next |
|
2239 case False |
|
2240 from False and th_in have "Th th \<in> Domain (RAG s)" |
|
2241 by (auto simp:readys_def s_waiting_def s_RAG_def wq_def cs_waiting_def Domain_def) |
|
2242 from chain_building [rule_format, OF this] |
|
2243 show ?thesis by auto |
|
2244 qed |
|
2245 |
|
2246 end |
|
2247 |
|
2248 lemma count_rec1 [simp]: |
|
2249 assumes "Q e" |
|
2250 shows "count Q (e#es) = Suc (count Q es)" |
|
2251 using assms |
|
2252 by (unfold count_def, auto) |
|
2253 |
|
2254 lemma count_rec2 [simp]: |
|
2255 assumes "\<not>Q e" |
|
2256 shows "count Q (e#es) = (count Q es)" |
|
2257 using assms |
|
2258 by (unfold count_def, auto) |
|
2259 |
|
2260 lemma count_rec3 [simp]: |
|
2261 shows "count Q [] = 0" |
|
2262 by (unfold count_def, auto) |
|
2263 |
|
2264 lemma cntP_simp1[simp]: |
|
2265 "cntP (P th cs'#s) th = cntP s th + 1" |
|
2266 by (unfold cntP_def, simp) |
|
2267 |
|
2268 lemma cntP_simp2[simp]: |
|
2269 assumes "th' \<noteq> th" |
|
2270 shows "cntP (P th cs'#s) th' = cntP s th'" |
|
2271 using assms |
|
2272 by (unfold cntP_def, simp) |
|
2273 |
|
2274 lemma cntP_simp3[simp]: |
|
2275 assumes "\<not> isP e" |
|
2276 shows "cntP (e#s) th' = cntP s th'" |
|
2277 using assms |
|
2278 by (unfold cntP_def, cases e, simp+) |
|
2279 |
|
2280 lemma cntV_simp1[simp]: |
|
2281 "cntV (V th cs'#s) th = cntV s th + 1" |
|
2282 by (unfold cntV_def, simp) |
|
2283 |
|
2284 lemma cntV_simp2[simp]: |
|
2285 assumes "th' \<noteq> th" |
|
2286 shows "cntV (V th cs'#s) th' = cntV s th'" |
|
2287 using assms |
|
2288 by (unfold cntV_def, simp) |
|
2289 |
|
2290 lemma cntV_simp3[simp]: |
|
2291 assumes "\<not> isV e" |
|
2292 shows "cntV (e#s) th' = cntV s th'" |
|
2293 using assms |
|
2294 by (unfold cntV_def, cases e, simp+) |
|
2295 |
|
2296 lemma cntP_diff_inv: |
|
2297 assumes "cntP (e#s) th \<noteq> cntP s th" |
|
2298 shows "isP e \<and> actor e = th" |
|
2299 proof(cases e) |
|
2300 case (P th' pty) |
|
2301 show ?thesis |
|
2302 by (cases "(\<lambda>e. \<exists>cs. e = P th cs) (P th' pty)", |
|
2303 insert assms P, auto simp:cntP_def) |
|
2304 qed (insert assms, auto simp:cntP_def) |
|
2305 |
|
2306 lemma cntV_diff_inv: |
|
2307 assumes "cntV (e#s) th \<noteq> cntV s th" |
|
2308 shows "isV e \<and> actor e = th" |
|
2309 proof(cases e) |
|
2310 case (V th' pty) |
|
2311 show ?thesis |
|
2312 by (cases "(\<lambda>e. \<exists>cs. e = V th cs) (V th' pty)", |
|
2313 insert assms V, auto simp:cntV_def) |
|
2314 qed (insert assms, auto simp:cntV_def) |
|
2315 |
|
2316 lemma children_RAG_alt_def: |
|
2317 "children (RAG (s::state)) (Th th) = Cs ` {cs. holding s th cs}" |
|
2318 by (unfold s_RAG_def, auto simp:children_def holding_eq) |
|
2319 |
|
2320 fun the_cs :: "node \<Rightarrow> cs" where |
|
2321 "the_cs (Cs cs) = cs" |
|
2322 |
|
2323 lemma holdents_alt_def: |
|
2324 "holdents s th = the_cs ` (children (RAG (s::state)) (Th th))" |
|
2325 by (unfold children_RAG_alt_def holdents_def, simp add: image_image) |
|
2326 |
|
2327 lemma cntCS_alt_def: |
|
2328 "cntCS s th = card (children (RAG s) (Th th))" |
|
2329 apply (unfold children_RAG_alt_def cntCS_def holdents_def) |
|
2330 by (rule card_image[symmetric], auto simp:inj_on_def) |
|
2331 |
|
2332 context valid_trace |
|
2333 begin |
|
2334 |
|
2335 lemma finite_holdents: "finite (holdents s th)" |
|
2336 by (unfold holdents_alt_def, insert finite_children, auto) |
|
2337 |
|
2338 end |
|
2339 |
|
2340 context valid_trace_p_w |
|
2341 begin |
|
2342 |
|
2343 lemma holding_s_holder: "holding s holder cs" |
|
2344 by (unfold s_holding_def, fold wq_def, unfold wq_s_cs, auto) |
|
2345 |
|
2346 lemma holding_es_holder: "holding (e#s) holder cs" |
|
2347 by (unfold s_holding_def, fold wq_def, unfold wq_es_cs wq_s_cs, auto) |
|
2348 |
|
2349 lemma holdents_es: |
|
2350 shows "holdents (e#s) th' = holdents s th'" (is "?L = ?R") |
|
2351 proof - |
|
2352 { fix cs' |
|
2353 assume "cs' \<in> ?L" |
|
2354 hence h: "holding (e#s) th' cs'" by (auto simp:holdents_def) |
|
2355 have "holding s th' cs'" |
|
2356 proof(cases "cs' = cs") |
|
2357 case True |
|
2358 from held_unique[OF h[unfolded True] holding_es_holder] |
|
2359 have "th' = holder" . |
|
2360 thus ?thesis |
|
2361 by (unfold True holdents_def, insert holding_s_holder, simp) |
|
2362 next |
|
2363 case False |
|
2364 hence "wq (e#s) cs' = wq s cs'" by simp |
|
2365 from h[unfolded s_holding_def, folded wq_def, unfolded this] |
|
2366 show ?thesis |
|
2367 by (unfold s_holding_def, fold wq_def, auto) |
|
2368 qed |
|
2369 hence "cs' \<in> ?R" by (auto simp:holdents_def) |
|
2370 } moreover { |
|
2371 fix cs' |
|
2372 assume "cs' \<in> ?R" |
|
2373 hence h: "holding s th' cs'" by (auto simp:holdents_def) |
|
2374 have "holding (e#s) th' cs'" |
|
2375 proof(cases "cs' = cs") |
|
2376 case True |
|
2377 from held_unique[OF h[unfolded True] holding_s_holder] |
|
2378 have "th' = holder" . |
|
2379 thus ?thesis |
|
2380 by (unfold True holdents_def, insert holding_es_holder, simp) |
|
2381 next |
|
2382 case False |
|
2383 hence "wq s cs' = wq (e#s) cs'" by simp |
|
2384 from h[unfolded s_holding_def, folded wq_def, unfolded this] |
|
2385 show ?thesis |
|
2386 by (unfold s_holding_def, fold wq_def, auto) |
|
2387 qed |
|
2388 hence "cs' \<in> ?L" by (auto simp:holdents_def) |
|
2389 } ultimately show ?thesis by auto |
|
2390 qed |
|
2391 |
|
2392 lemma cntCS_es_th[simp]: "cntCS (e#s) th' = cntCS s th'" |
|
2393 by (unfold cntCS_def holdents_es, simp) |
|
2394 |
|
2395 lemma th_not_ready_es: |
|
2396 shows "th \<notin> readys (e#s)" |
|
2397 using waiting_es_th_cs |
|
2398 by (unfold readys_def, auto) |
|
2399 |
|
2400 end |
|
2401 |
|
2402 context valid_trace_p_h |
|
2403 begin |
|
2404 |
|
2405 lemma th_not_waiting': |
|
2406 "\<not> waiting (e#s) th cs'" |
|
2407 proof(cases "cs' = cs") |
|
2408 case True |
|
2409 show ?thesis |
|
2410 by (unfold True s_waiting_def, fold wq_def, unfold wq_es_cs', auto) |
|
2411 next |
|
2412 case False |
|
2413 from th_not_waiting[of cs', unfolded s_waiting_def, folded wq_def] |
|
2414 show ?thesis |
|
2415 by (unfold s_waiting_def, fold wq_def, insert False, simp) |
|
2416 qed |
|
2417 |
|
2418 lemma ready_th_es: |
|
2419 shows "th \<in> readys (e#s)" |
|
2420 using th_not_waiting' |
|
2421 by (unfold readys_def, insert live_th_es, auto) |
|
2422 |
|
2423 lemma holdents_es_th: |
|
2424 "holdents (e#s) th = (holdents s th) \<union> {cs}" (is "?L = ?R") |
|
2425 proof - |
|
2426 { fix cs' |
|
2427 assume "cs' \<in> ?L" |
|
2428 hence "holding (e#s) th cs'" |
|
2429 by (unfold holdents_def, auto) |
|
2430 hence "cs' \<in> ?R" |
|
2431 by (cases rule:holding_esE, auto simp:holdents_def) |
|
2432 } moreover { |
|
2433 fix cs' |
|
2434 assume "cs' \<in> ?R" |
|
2435 hence "holding s th cs' \<or> cs' = cs" |
|
2436 by (auto simp:holdents_def) |
|
2437 hence "cs' \<in> ?L" |
|
2438 proof |
|
2439 assume "holding s th cs'" |
|
2440 from holding_kept[OF this] |
|
2441 show ?thesis by (auto simp:holdents_def) |
|
2442 next |
|
2443 assume "cs' = cs" |
|
2444 thus ?thesis using holding_es_th_cs |
|
2445 by (unfold holdents_def, auto) |
|
2446 qed |
|
2447 } ultimately show ?thesis by auto |
|
2448 qed |
|
2449 |
|
2450 lemma cntCS_es_th: "cntCS (e#s) th = cntCS s th + 1" |
|
2451 proof - |
|
2452 have "card (holdents s th \<union> {cs}) = card (holdents s th) + 1" |
|
2453 proof(subst card_Un_disjoint) |
|
2454 show "holdents s th \<inter> {cs} = {}" |
|
2455 using not_holding_s_th_cs by (auto simp:holdents_def) |
|
2456 qed (auto simp:finite_holdents) |
|
2457 thus ?thesis |
|
2458 by (unfold cntCS_def holdents_es_th, simp) |
|
2459 qed |
|
2460 |
|
2461 lemma no_holder: |
|
2462 "\<not> holding s th' cs" |
|
2463 proof |
|
2464 assume otherwise: "holding s th' cs" |
|
2465 from this[unfolded s_holding_def, folded wq_def, unfolded we] |
|
2466 show False by auto |
|
2467 qed |
|
2468 |
|
2469 lemma holdents_es_th': |
|
2470 assumes "th' \<noteq> th" |
|
2471 shows "holdents (e#s) th' = holdents s th'" (is "?L = ?R") |
|
2472 proof - |
|
2473 { fix cs' |
|
2474 assume "cs' \<in> ?L" |
|
2475 hence h_e: "holding (e#s) th' cs'" by (auto simp:holdents_def) |
|
2476 have "cs' \<noteq> cs" |
|
2477 proof |
|
2478 assume "cs' = cs" |
|
2479 from held_unique[OF h_e[unfolded this] holding_es_th_cs] |
|
2480 have "th' = th" . |
|
2481 with assms show False by simp |
|
2482 qed |
|
2483 from h_e[unfolded s_holding_def, folded wq_def, unfolded wq_neq_simp[OF this]] |
|
2484 have "th' \<in> set (wq s cs') \<and> th' = hd (wq s cs')" . |
|
2485 hence "cs' \<in> ?R" |
|
2486 by (unfold holdents_def s_holding_def, fold wq_def, auto) |
|
2487 } moreover { |
|
2488 fix cs' |
|
2489 assume "cs' \<in> ?R" |
|
2490 hence "holding s th' cs'" by (auto simp:holdents_def) |
|
2491 from holding_kept[OF this] |
|
2492 have "holding (e # s) th' cs'" . |
|
2493 hence "cs' \<in> ?L" |
|
2494 by (unfold holdents_def, auto) |
|
2495 } ultimately show ?thesis by auto |
|
2496 qed |
|
2497 |
|
2498 lemma cntCS_es_th'[simp]: |
|
2499 assumes "th' \<noteq> th" |
|
2500 shows "cntCS (e#s) th' = cntCS s th'" |
|
2501 by (unfold cntCS_def holdents_es_th'[OF assms], simp) |
|
2502 |
|
2503 end |
|
2504 |
|
2505 context valid_trace_p |
|
2506 begin |
|
2507 |
|
2508 lemma readys_kept1: |
|
2509 assumes "th' \<noteq> th" |
|
2510 and "th' \<in> readys (e#s)" |
|
2511 shows "th' \<in> readys s" |
|
2512 proof - |
|
2513 { fix cs' |
|
2514 assume wait: "waiting s th' cs'" |
|
2515 have n_wait: "\<not> waiting (e#s) th' cs'" |
|
2516 using assms(2)[unfolded readys_def] by auto |
|
2517 have False |
|
2518 proof(cases "cs' = cs") |
|
2519 case False |
|
2520 with n_wait wait |
|
2521 show ?thesis |
|
2522 by (unfold s_waiting_def, fold wq_def, auto) |
|
2523 next |
|
2524 case True |
|
2525 show ?thesis |
|
2526 proof(cases "wq s cs = []") |
|
2527 case True |
|
2528 then interpret vt: valid_trace_p_h |
|
2529 by (unfold_locales, simp) |
|
2530 show ?thesis using n_wait wait waiting_kept by auto |
|
2531 next |
|
2532 case False |
|
2533 then interpret vt: valid_trace_p_w by (unfold_locales, simp) |
|
2534 show ?thesis using n_wait wait waiting_kept by blast |
|
2535 qed |
|
2536 qed |
|
2537 } with assms(2) show ?thesis |
|
2538 by (unfold readys_def, auto) |
|
2539 qed |
|
2540 |
|
2541 lemma readys_kept2: |
|
2542 assumes "th' \<noteq> th" |
|
2543 and "th' \<in> readys s" |
|
2544 shows "th' \<in> readys (e#s)" |
|
2545 proof - |
|
2546 { fix cs' |
|
2547 assume wait: "waiting (e#s) th' cs'" |
|
2548 have n_wait: "\<not> waiting s th' cs'" |
|
2549 using assms(2)[unfolded readys_def] by auto |
|
2550 have False |
|
2551 proof(cases "cs' = cs") |
|
2552 case False |
|
2553 with n_wait wait |
|
2554 show ?thesis |
|
2555 by (unfold s_waiting_def, fold wq_def, auto) |
|
2556 next |
|
2557 case True |
|
2558 show ?thesis |
|
2559 proof(cases "wq s cs = []") |
|
2560 case True |
|
2561 then interpret vt: valid_trace_p_h |
|
2562 by (unfold_locales, simp) |
|
2563 show ?thesis using n_wait vt.waiting_esE wait by blast |
|
2564 next |
|
2565 case False |
|
2566 then interpret vt: valid_trace_p_w by (unfold_locales, simp) |
|
2567 show ?thesis using assms(1) n_wait vt.waiting_esE wait by auto |
|
2568 qed |
|
2569 qed |
|
2570 } with assms(2) show ?thesis |
|
2571 by (unfold readys_def, auto) |
|
2572 qed |
|
2573 |
|
2574 lemma readys_simp [simp]: |
|
2575 assumes "th' \<noteq> th" |
|
2576 shows "(th' \<in> readys (e#s)) = (th' \<in> readys s)" |
|
2577 using readys_kept1[OF assms] readys_kept2[OF assms] |
|
2578 by metis |
|
2579 |
|
2580 lemma cnp_cnv_cncs_kept: |
|
2581 assumes "cntP s th' = cntV s th' + cntCS s th' + pvD s th'" |
|
2582 shows "cntP (e#s) th' = cntV (e#s) th' + cntCS (e#s) th' + pvD (e#s) th'" |
|
2583 proof(cases "th' = th") |
|
2584 case True |
|
2585 note eq_th' = this |
|
2586 show ?thesis |
1616 proof(cases "wq s cs = []") |
2587 proof(cases "wq s cs = []") |
1617 case True |
2588 case True |
1618 from wq_es_cs[unfolded this] |
2589 then interpret vt: valid_trace_p_h by (unfold_locales, simp) |
1619 have "th \<in> set (wq (e#s) cs)" "th = hd (wq (e#s) cs)" by auto |
2590 show ?thesis |
1620 hence "holding (e#s) th cs" |
2591 using assms eq_th' is_p ready_th_s vt.cntCS_es_th vt.ready_th_es pvD_def by auto |
1621 using cs_holding_def holding_eq by blast |
2592 next |
1622 thus |
2593 case False |
1623 qed |
2594 then interpret vt: valid_trace_p_w by (unfold_locales, simp) |
1624 end |
2595 show ?thesis |
1625 |
2596 using add.commute add.left_commute assms eq_th' is_p live_th_s |
1626 text {* |
2597 ready_th_s vt.th_not_ready_es pvD_def |
1627 The following @{text "step_RAG_p"} lemma charaterizes how @{text "RAG"} is changed |
2598 apply (auto) |
1628 with the happening of @{text "P"}-events: |
2599 by (fold is_p, simp) |
1629 *} |
2600 qed |
1630 lemma step_RAG_p: |
2601 next |
1631 "vt (P th cs#s) \<Longrightarrow> |
2602 case False |
1632 RAG (P th cs # s) = (if (wq s cs = []) then RAG s \<union> {(Cs cs, Th th)} |
2603 note h_False = False |
1633 else RAG s \<union> {(Th th, Cs cs)})" |
2604 thus ?thesis |
1634 apply(simp only: s_RAG_def wq_def) |
2605 proof(cases "wq s cs = []") |
1635 apply (auto split:list.splits prod.splits simp:Let_def wq_def cs_waiting_def cs_holding_def) |
2606 case True |
1636 apply(case_tac "csa = cs", auto) |
2607 then interpret vt: valid_trace_p_h by (unfold_locales, simp) |
1637 apply(fold wq_def) |
2608 show ?thesis using assms |
1638 apply(drule_tac step_back_step) |
2609 by (insert True h_False pvD_def, auto split:if_splits,unfold is_p, auto) |
1639 apply(ind_cases " step s (P (hd (wq s cs)) cs)") |
2610 next |
1640 apply(simp add:s_RAG_def wq_def cs_holding_def) |
2611 case False |
1641 apply(auto) |
2612 then interpret vt: valid_trace_p_w by (unfold_locales, simp) |
1642 done |
2613 show ?thesis using assms |
1643 |
2614 by (insert False h_False pvD_def, auto split:if_splits,unfold is_p, auto) |
1644 |
2615 qed |
1645 |
2616 qed |
1646 end |
2617 |
|
2618 end |
|
2619 |
|
2620 |
|
2621 context valid_trace_v (* ccc *) |
|
2622 begin |
|
2623 |
|
2624 lemma holding_th_cs_s: |
|
2625 "holding s th cs" |
|
2626 by (unfold s_holding_def, fold wq_def, unfold wq_s_cs, auto) |
|
2627 |
|
2628 lemma th_ready_s [simp]: "th \<in> readys s" |
|
2629 using runing_th_s |
|
2630 by (unfold runing_def readys_def, auto) |
|
2631 |
|
2632 lemma th_live_s [simp]: "th \<in> threads s" |
|
2633 using th_ready_s by (unfold readys_def, auto) |
|
2634 |
|
2635 lemma th_ready_es [simp]: "th \<in> readys (e#s)" |
|
2636 using runing_th_s neq_t_th |
|
2637 by (unfold is_v runing_def readys_def, auto) |
|
2638 |
|
2639 lemma th_live_es [simp]: "th \<in> threads (e#s)" |
|
2640 using th_ready_es by (unfold readys_def, auto) |
|
2641 |
|
2642 lemma pvD_th_s[simp]: "pvD s th = 0" |
|
2643 by (unfold pvD_def, simp) |
|
2644 |
|
2645 lemma pvD_th_es[simp]: "pvD (e#s) th = 0" |
|
2646 by (unfold pvD_def, simp) |
|
2647 |
|
2648 lemma cntCS_s_th [simp]: "cntCS s th > 0" |
|
2649 proof - |
|
2650 have "cs \<in> holdents s th" using holding_th_cs_s |
|
2651 by (unfold holdents_def, simp) |
|
2652 moreover have "finite (holdents s th)" using finite_holdents |
|
2653 by simp |
|
2654 ultimately show ?thesis |
|
2655 by (unfold cntCS_def, |
|
2656 auto intro!:card_gt_0_iff[symmetric, THEN iffD1]) |
|
2657 qed |
|
2658 |
|
2659 end |
|
2660 |
|
2661 context valid_trace_v_n |
|
2662 begin |
|
2663 |
|
2664 lemma not_ready_taker_s[simp]: |
|
2665 "taker \<notin> readys s" |
|
2666 using waiting_taker |
|
2667 by (unfold readys_def, auto) |
|
2668 |
|
2669 lemma taker_live_s [simp]: "taker \<in> threads s" |
|
2670 proof - |
|
2671 have "taker \<in> set wq'" by (simp add: eq_wq') |
|
2672 from th'_in_inv[OF this] |
|
2673 have "taker \<in> set rest" . |
|
2674 hence "taker \<in> set (wq s cs)" by (simp add: wq_s_cs) |
|
2675 thus ?thesis using wq_threads by auto |
|
2676 qed |
|
2677 |
|
2678 lemma taker_live_es [simp]: "taker \<in> threads (e#s)" |
|
2679 using taker_live_s threads_es by blast |
|
2680 |
|
2681 lemma taker_ready_es [simp]: |
|
2682 shows "taker \<in> readys (e#s)" |
|
2683 proof - |
|
2684 { fix cs' |
|
2685 assume "waiting (e#s) taker cs'" |
|
2686 hence False |
|
2687 proof(cases rule:waiting_esE) |
|
2688 case 1 |
|
2689 thus ?thesis using waiting_taker waiting_unique by auto |
|
2690 qed simp |
|
2691 } thus ?thesis by (unfold readys_def, auto) |
|
2692 qed |
|
2693 |
|
2694 lemma neq_taker_th: "taker \<noteq> th" |
|
2695 using th_not_waiting waiting_taker by blast |
|
2696 |
|
2697 lemma not_holding_taker_s_cs: |
|
2698 shows "\<not> holding s taker cs" |
|
2699 using holding_cs_eq_th neq_taker_th by auto |
|
2700 |
|
2701 lemma holdents_es_taker: |
|
2702 "holdents (e#s) taker = holdents s taker \<union> {cs}" (is "?L = ?R") |
|
2703 proof - |
|
2704 { fix cs' |
|
2705 assume "cs' \<in> ?L" |
|
2706 hence "holding (e#s) taker cs'" by (auto simp:holdents_def) |
|
2707 hence "cs' \<in> ?R" |
|
2708 proof(cases rule:holding_esE) |
|
2709 case 2 |
|
2710 thus ?thesis by (auto simp:holdents_def) |
|
2711 qed auto |
|
2712 } moreover { |
|
2713 fix cs' |
|
2714 assume "cs' \<in> ?R" |
|
2715 hence "holding s taker cs' \<or> cs' = cs" by (auto simp:holdents_def) |
|
2716 hence "cs' \<in> ?L" |
|
2717 proof |
|
2718 assume "holding s taker cs'" |
|
2719 hence "holding (e#s) taker cs'" |
|
2720 using holding_esI2 holding_taker by fastforce |
|
2721 thus ?thesis by (auto simp:holdents_def) |
|
2722 next |
|
2723 assume "cs' = cs" |
|
2724 with holding_taker |
|
2725 show ?thesis by (auto simp:holdents_def) |
|
2726 qed |
|
2727 } ultimately show ?thesis by auto |
|
2728 qed |
|
2729 |
|
2730 lemma cntCS_es_taker [simp]: "cntCS (e#s) taker = cntCS s taker + 1" |
|
2731 proof - |
|
2732 have "card (holdents s taker \<union> {cs}) = card (holdents s taker) + 1" |
|
2733 proof(subst card_Un_disjoint) |
|
2734 show "holdents s taker \<inter> {cs} = {}" |
|
2735 using not_holding_taker_s_cs by (auto simp:holdents_def) |
|
2736 qed (auto simp:finite_holdents) |
|
2737 thus ?thesis |
|
2738 by (unfold cntCS_def, insert holdents_es_taker, simp) |
|
2739 qed |
|
2740 |
|
2741 lemma pvD_taker_s[simp]: "pvD s taker = 1" |
|
2742 by (unfold pvD_def, simp) |
|
2743 |
|
2744 lemma pvD_taker_es[simp]: "pvD (e#s) taker = 0" |
|
2745 by (unfold pvD_def, simp) |
|
2746 |
|
2747 lemma pvD_th_s[simp]: "pvD s th = 0" |
|
2748 by (unfold pvD_def, simp) |
|
2749 |
|
2750 lemma pvD_th_es[simp]: "pvD (e#s) th = 0" |
|
2751 by (unfold pvD_def, simp) |
|
2752 |
|
2753 lemma holdents_es_th: |
|
2754 "holdents (e#s) th = holdents s th - {cs}" (is "?L = ?R") |
|
2755 proof - |
|
2756 { fix cs' |
|
2757 assume "cs' \<in> ?L" |
|
2758 hence "holding (e#s) th cs'" by (auto simp:holdents_def) |
|
2759 hence "cs' \<in> ?R" |
|
2760 proof(cases rule:holding_esE) |
|
2761 case 2 |
|
2762 thus ?thesis by (auto simp:holdents_def) |
|
2763 qed (insert neq_taker_th, auto) |
|
2764 } moreover { |
|
2765 fix cs' |
|
2766 assume "cs' \<in> ?R" |
|
2767 hence "cs' \<noteq> cs" "holding s th cs'" by (auto simp:holdents_def) |
|
2768 from holding_esI2[OF this] |
|
2769 have "cs' \<in> ?L" by (auto simp:holdents_def) |
|
2770 } ultimately show ?thesis by auto |
|
2771 qed |
|
2772 |
|
2773 lemma cntCS_es_th [simp]: "cntCS (e#s) th = cntCS s th - 1" |
|
2774 proof - |
|
2775 have "card (holdents s th - {cs}) = card (holdents s th) - 1" |
|
2776 proof - |
|
2777 have "cs \<in> holdents s th" using holding_th_cs_s |
|
2778 by (auto simp:holdents_def) |
|
2779 moreover have "finite (holdents s th)" |
|
2780 by (simp add: finite_holdents) |
|
2781 ultimately show ?thesis by auto |
|
2782 qed |
|
2783 thus ?thesis by (unfold cntCS_def holdents_es_th) |
|
2784 qed |
|
2785 |
|
2786 lemma holdents_kept: |
|
2787 assumes "th' \<noteq> taker" |
|
2788 and "th' \<noteq> th" |
|
2789 shows "holdents (e#s) th' = holdents s th'" (is "?L = ?R") |
|
2790 proof - |
|
2791 { fix cs' |
|
2792 assume h: "cs' \<in> ?L" |
|
2793 have "cs' \<in> ?R" |
|
2794 proof(cases "cs' = cs") |
|
2795 case False |
|
2796 hence eq_wq: "wq (e#s) cs' = wq s cs'" by simp |
|
2797 from h have "holding (e#s) th' cs'" by (auto simp:holdents_def) |
|
2798 from this[unfolded s_holding_def, folded wq_def, unfolded eq_wq] |
|
2799 show ?thesis |
|
2800 by (unfold holdents_def s_holding_def, fold wq_def, auto) |
|
2801 next |
|
2802 case True |
|
2803 from h[unfolded this] |
|
2804 have "holding (e#s) th' cs" by (auto simp:holdents_def) |
|
2805 from held_unique[OF this holding_taker] |
|
2806 have "th' = taker" . |
|
2807 with assms show ?thesis by auto |
|
2808 qed |
|
2809 } moreover { |
|
2810 fix cs' |
|
2811 assume h: "cs' \<in> ?R" |
|
2812 have "cs' \<in> ?L" |
|
2813 proof(cases "cs' = cs") |
|
2814 case False |
|
2815 hence eq_wq: "wq (e#s) cs' = wq s cs'" by simp |
|
2816 from h have "holding s th' cs'" by (auto simp:holdents_def) |
|
2817 from this[unfolded s_holding_def, folded wq_def, unfolded eq_wq] |
|
2818 show ?thesis |
|
2819 by (unfold holdents_def s_holding_def, fold wq_def, insert eq_wq, simp) |
|
2820 next |
|
2821 case True |
|
2822 from h[unfolded this] |
|
2823 have "holding s th' cs" by (auto simp:holdents_def) |
|
2824 from held_unique[OF this holding_th_cs_s] |
|
2825 have "th' = th" . |
|
2826 with assms show ?thesis by auto |
|
2827 qed |
|
2828 } ultimately show ?thesis by auto |
|
2829 qed |
|
2830 |
|
2831 lemma cntCS_kept [simp]: |
|
2832 assumes "th' \<noteq> taker" |
|
2833 and "th' \<noteq> th" |
|
2834 shows "cntCS (e#s) th' = cntCS s th'" |
|
2835 by (unfold cntCS_def holdents_kept[OF assms], simp) |
|
2836 |
|
2837 lemma readys_kept1: |
|
2838 assumes "th' \<noteq> taker" |
|
2839 and "th' \<in> readys (e#s)" |
|
2840 shows "th' \<in> readys s" |
|
2841 proof - |
|
2842 { fix cs' |
|
2843 assume wait: "waiting s th' cs'" |
|
2844 have n_wait: "\<not> waiting (e#s) th' cs'" |
|
2845 using assms(2)[unfolded readys_def] by auto |
|
2846 have False |
|
2847 proof(cases "cs' = cs") |
|
2848 case False |
|
2849 with n_wait wait |
|
2850 show ?thesis |
|
2851 by (unfold s_waiting_def, fold wq_def, auto) |
|
2852 next |
|
2853 case True |
|
2854 have "th' \<in> set (th # rest) \<and> th' \<noteq> hd (th # rest)" |
|
2855 using wait[unfolded True s_waiting_def, folded wq_def, unfolded wq_s_cs] . |
|
2856 moreover have "\<not> (th' \<in> set rest \<and> th' \<noteq> hd (taker # rest'))" |
|
2857 using n_wait[unfolded True s_waiting_def, folded wq_def, |
|
2858 unfolded wq_es_cs set_wq', unfolded eq_wq'] . |
|
2859 ultimately have "th' = taker" by auto |
|
2860 with assms(1) |
|
2861 show ?thesis by simp |
|
2862 qed |
|
2863 } with assms(2) show ?thesis |
|
2864 by (unfold readys_def, auto) |
|
2865 qed |
|
2866 |
|
2867 lemma readys_kept2: |
|
2868 assumes "th' \<noteq> taker" |
|
2869 and "th' \<in> readys s" |
|
2870 shows "th' \<in> readys (e#s)" |
|
2871 proof - |
|
2872 { fix cs' |
|
2873 assume wait: "waiting (e#s) th' cs'" |
|
2874 have n_wait: "\<not> waiting s th' cs'" |
|
2875 using assms(2)[unfolded readys_def] by auto |
|
2876 have False |
|
2877 proof(cases "cs' = cs") |
|
2878 case False |
|
2879 with n_wait wait |
|
2880 show ?thesis |
|
2881 by (unfold s_waiting_def, fold wq_def, auto) |
|
2882 next |
|
2883 case True |
|
2884 have "th' \<in> set rest \<and> th' \<noteq> hd (taker # rest')" |
|
2885 using wait [unfolded True s_waiting_def, folded wq_def, |
|
2886 unfolded wq_es_cs set_wq', unfolded eq_wq'] . |
|
2887 moreover have "\<not> (th' \<in> set (th # rest) \<and> th' \<noteq> hd (th # rest))" |
|
2888 using n_wait[unfolded True s_waiting_def, folded wq_def, unfolded wq_s_cs] . |
|
2889 ultimately have "th' = taker" by auto |
|
2890 with assms(1) |
|
2891 show ?thesis by simp |
|
2892 qed |
|
2893 } with assms(2) show ?thesis |
|
2894 by (unfold readys_def, auto) |
|
2895 qed |
|
2896 |
|
2897 lemma readys_simp [simp]: |
|
2898 assumes "th' \<noteq> taker" |
|
2899 shows "(th' \<in> readys (e#s)) = (th' \<in> readys s)" |
|
2900 using readys_kept1[OF assms] readys_kept2[OF assms] |
|
2901 by metis |
|
2902 |
|
2903 lemma cnp_cnv_cncs_kept: |
|
2904 assumes "cntP s th' = cntV s th' + cntCS s th' + pvD s th'" |
|
2905 shows "cntP (e#s) th' = cntV (e#s) th' + cntCS (e#s) th' + pvD (e#s) th'" |
|
2906 proof - |
|
2907 { assume eq_th': "th' = taker" |
|
2908 have ?thesis |
|
2909 apply (unfold eq_th' pvD_taker_es cntCS_es_taker) |
|
2910 by (insert neq_taker_th assms[unfolded eq_th'], unfold is_v, simp) |
|
2911 } moreover { |
|
2912 assume eq_th': "th' = th" |
|
2913 have ?thesis |
|
2914 apply (unfold eq_th' pvD_th_es cntCS_es_th) |
|
2915 by (insert assms[unfolded eq_th'], unfold is_v, simp) |
|
2916 } moreover { |
|
2917 assume h: "th' \<noteq> taker" "th' \<noteq> th" |
|
2918 have ?thesis using assms |
|
2919 apply (unfold cntCS_kept[OF h], insert h, unfold is_v, simp) |
|
2920 by (fold is_v, unfold pvD_def, simp) |
|
2921 } ultimately show ?thesis by metis |
|
2922 qed |
|
2923 |
|
2924 end |
|
2925 |
|
2926 context valid_trace_v_e |
|
2927 begin |
|
2928 |
|
2929 lemma holdents_es_th: |
|
2930 "holdents (e#s) th = holdents s th - {cs}" (is "?L = ?R") |
|
2931 proof - |
|
2932 { fix cs' |
|
2933 assume "cs' \<in> ?L" |
|
2934 hence "holding (e#s) th cs'" by (auto simp:holdents_def) |
|
2935 hence "cs' \<in> ?R" |
|
2936 proof(cases rule:holding_esE) |
|
2937 case 1 |
|
2938 thus ?thesis by (auto simp:holdents_def) |
|
2939 qed |
|
2940 } moreover { |
|
2941 fix cs' |
|
2942 assume "cs' \<in> ?R" |
|
2943 hence "cs' \<noteq> cs" "holding s th cs'" by (auto simp:holdents_def) |
|
2944 from holding_esI2[OF this] |
|
2945 have "cs' \<in> ?L" by (auto simp:holdents_def) |
|
2946 } ultimately show ?thesis by auto |
|
2947 qed |
|
2948 |
|
2949 lemma cntCS_es_th [simp]: "cntCS (e#s) th = cntCS s th - 1" |
|
2950 proof - |
|
2951 have "card (holdents s th - {cs}) = card (holdents s th) - 1" |
|
2952 proof - |
|
2953 have "cs \<in> holdents s th" using holding_th_cs_s |
|
2954 by (auto simp:holdents_def) |
|
2955 moreover have "finite (holdents s th)" |
|
2956 by (simp add: finite_holdents) |
|
2957 ultimately show ?thesis by auto |
|
2958 qed |
|
2959 thus ?thesis by (unfold cntCS_def holdents_es_th) |
|
2960 qed |
|
2961 |
|
2962 lemma holdents_kept: |
|
2963 assumes "th' \<noteq> th" |
|
2964 shows "holdents (e#s) th' = holdents s th'" (is "?L = ?R") |
|
2965 proof - |
|
2966 { fix cs' |
|
2967 assume h: "cs' \<in> ?L" |
|
2968 have "cs' \<in> ?R" |
|
2969 proof(cases "cs' = cs") |
|
2970 case False |
|
2971 hence eq_wq: "wq (e#s) cs' = wq s cs'" by simp |
|
2972 from h have "holding (e#s) th' cs'" by (auto simp:holdents_def) |
|
2973 from this[unfolded s_holding_def, folded wq_def, unfolded eq_wq] |
|
2974 show ?thesis |
|
2975 by (unfold holdents_def s_holding_def, fold wq_def, auto) |
|
2976 next |
|
2977 case True |
|
2978 from h[unfolded this] |
|
2979 have "holding (e#s) th' cs" by (auto simp:holdents_def) |
|
2980 from this[unfolded s_holding_def, folded wq_def, |
|
2981 unfolded wq_es_cs nil_wq'] |
|
2982 show ?thesis by auto |
|
2983 qed |
|
2984 } moreover { |
|
2985 fix cs' |
|
2986 assume h: "cs' \<in> ?R" |
|
2987 have "cs' \<in> ?L" |
|
2988 proof(cases "cs' = cs") |
|
2989 case False |
|
2990 hence eq_wq: "wq (e#s) cs' = wq s cs'" by simp |
|
2991 from h have "holding s th' cs'" by (auto simp:holdents_def) |
|
2992 from this[unfolded s_holding_def, folded wq_def, unfolded eq_wq] |
|
2993 show ?thesis |
|
2994 by (unfold holdents_def s_holding_def, fold wq_def, insert eq_wq, simp) |
|
2995 next |
|
2996 case True |
|
2997 from h[unfolded this] |
|
2998 have "holding s th' cs" by (auto simp:holdents_def) |
|
2999 from held_unique[OF this holding_th_cs_s] |
|
3000 have "th' = th" . |
|
3001 with assms show ?thesis by auto |
|
3002 qed |
|
3003 } ultimately show ?thesis by auto |
|
3004 qed |
|
3005 |
|
3006 lemma cntCS_kept [simp]: |
|
3007 assumes "th' \<noteq> th" |
|
3008 shows "cntCS (e#s) th' = cntCS s th'" |
|
3009 by (unfold cntCS_def holdents_kept[OF assms], simp) |
|
3010 |
|
3011 lemma readys_kept1: |
|
3012 assumes "th' \<in> readys (e#s)" |
|
3013 shows "th' \<in> readys s" |
|
3014 proof - |
|
3015 { fix cs' |
|
3016 assume wait: "waiting s th' cs'" |
|
3017 have n_wait: "\<not> waiting (e#s) th' cs'" |
|
3018 using assms(1)[unfolded readys_def] by auto |
|
3019 have False |
|
3020 proof(cases "cs' = cs") |
|
3021 case False |
|
3022 with n_wait wait |
|
3023 show ?thesis |
|
3024 by (unfold s_waiting_def, fold wq_def, auto) |
|
3025 next |
|
3026 case True |
|
3027 have "th' \<in> set (th # rest) \<and> th' \<noteq> hd (th # rest)" |
|
3028 using wait[unfolded True s_waiting_def, folded wq_def, unfolded wq_s_cs] . |
|
3029 hence "th' \<in> set rest" by auto |
|
3030 with set_wq' have "th' \<in> set wq'" by metis |
|
3031 with nil_wq' show ?thesis by simp |
|
3032 qed |
|
3033 } thus ?thesis using assms |
|
3034 by (unfold readys_def, auto) |
|
3035 qed |
|
3036 |
|
3037 lemma readys_kept2: |
|
3038 assumes "th' \<in> readys s" |
|
3039 shows "th' \<in> readys (e#s)" |
|
3040 proof - |
|
3041 { fix cs' |
|
3042 assume wait: "waiting (e#s) th' cs'" |
|
3043 have n_wait: "\<not> waiting s th' cs'" |
|
3044 using assms[unfolded readys_def] by auto |
|
3045 have False |
|
3046 proof(cases "cs' = cs") |
|
3047 case False |
|
3048 with n_wait wait |
|
3049 show ?thesis |
|
3050 by (unfold s_waiting_def, fold wq_def, auto) |
|
3051 next |
|
3052 case True |
|
3053 have "th' \<in> set [] \<and> th' \<noteq> hd []" |
|
3054 using wait[unfolded True s_waiting_def, folded wq_def, |
|
3055 unfolded wq_es_cs nil_wq'] . |
|
3056 thus ?thesis by simp |
|
3057 qed |
|
3058 } with assms show ?thesis |
|
3059 by (unfold readys_def, auto) |
|
3060 qed |
|
3061 |
|
3062 lemma readys_simp [simp]: |
|
3063 shows "(th' \<in> readys (e#s)) = (th' \<in> readys s)" |
|
3064 using readys_kept1[OF assms] readys_kept2[OF assms] |
|
3065 by metis |
|
3066 |
|
3067 lemma cnp_cnv_cncs_kept: |
|
3068 assumes "cntP s th' = cntV s th' + cntCS s th' + pvD s th'" |
|
3069 shows "cntP (e#s) th' = cntV (e#s) th' + cntCS (e#s) th' + pvD (e#s) th'" |
|
3070 proof - |
|
3071 { |
|
3072 assume eq_th': "th' = th" |
|
3073 have ?thesis |
|
3074 apply (unfold eq_th' pvD_th_es cntCS_es_th) |
|
3075 by (insert assms[unfolded eq_th'], unfold is_v, simp) |
|
3076 } moreover { |
|
3077 assume h: "th' \<noteq> th" |
|
3078 have ?thesis using assms |
|
3079 apply (unfold cntCS_kept[OF h], insert h, unfold is_v, simp) |
|
3080 by (fold is_v, unfold pvD_def, simp) |
|
3081 } ultimately show ?thesis by metis |
|
3082 qed |
|
3083 |
|
3084 end |
|
3085 |
|
3086 context valid_trace_v |
|
3087 begin |
|
3088 |
|
3089 lemma cnp_cnv_cncs_kept: |
|
3090 assumes "cntP s th' = cntV s th' + cntCS s th' + pvD s th'" |
|
3091 shows "cntP (e#s) th' = cntV (e#s) th' + cntCS (e#s) th' + pvD (e#s) th'" |
|
3092 proof(cases "rest = []") |
|
3093 case True |
|
3094 then interpret vt: valid_trace_v_e by (unfold_locales, simp) |
|
3095 show ?thesis using assms using vt.cnp_cnv_cncs_kept by blast |
|
3096 next |
|
3097 case False |
|
3098 then interpret vt: valid_trace_v_n by (unfold_locales, simp) |
|
3099 show ?thesis using assms using vt.cnp_cnv_cncs_kept by blast |
|
3100 qed |
|
3101 |
|
3102 end |
|
3103 |
|
3104 context valid_trace_create |
|
3105 begin |
|
3106 |
|
3107 lemma th_not_live_s [simp]: "th \<notin> threads s" |
|
3108 proof - |
|
3109 from pip_e[unfolded is_create] |
|
3110 show ?thesis by (cases, simp) |
|
3111 qed |
|
3112 |
|
3113 lemma th_not_ready_s [simp]: "th \<notin> readys s" |
|
3114 using th_not_live_s by (unfold readys_def, simp) |
|
3115 |
|
3116 lemma th_live_es [simp]: "th \<in> threads (e#s)" |
|
3117 by (unfold is_create, simp) |
|
3118 |
|
3119 lemma not_waiting_th_s [simp]: "\<not> waiting s th cs'" |
|
3120 proof |
|
3121 assume "waiting s th cs'" |
|
3122 from this[unfolded s_waiting_def, folded wq_def, unfolded wq_neq_simp] |
|
3123 have "th \<in> set (wq s cs')" by auto |
|
3124 from wq_threads[OF this] have "th \<in> threads s" . |
|
3125 with th_not_live_s show False by simp |
|
3126 qed |
|
3127 |
|
3128 lemma not_holding_th_s [simp]: "\<not> holding s th cs'" |
|
3129 proof |
|
3130 assume "holding s th cs'" |
|
3131 from this[unfolded s_holding_def, folded wq_def, unfolded wq_neq_simp] |
|
3132 have "th \<in> set (wq s cs')" by auto |
|
3133 from wq_threads[OF this] have "th \<in> threads s" . |
|
3134 with th_not_live_s show False by simp |
|
3135 qed |
|
3136 |
|
3137 lemma not_waiting_th_es [simp]: "\<not> waiting (e#s) th cs'" |
|
3138 proof |
|
3139 assume "waiting (e # s) th cs'" |
|
3140 from this[unfolded s_waiting_def, folded wq_def, unfolded wq_neq_simp] |
|
3141 have "th \<in> set (wq s cs')" by auto |
|
3142 from wq_threads[OF this] have "th \<in> threads s" . |
|
3143 with th_not_live_s show False by simp |
|
3144 qed |
|
3145 |
|
3146 lemma not_holding_th_es [simp]: "\<not> holding (e#s) th cs'" |
|
3147 proof |
|
3148 assume "holding (e # s) th cs'" |
|
3149 from this[unfolded s_holding_def, folded wq_def, unfolded wq_neq_simp] |
|
3150 have "th \<in> set (wq s cs')" by auto |
|
3151 from wq_threads[OF this] have "th \<in> threads s" . |
|
3152 with th_not_live_s show False by simp |
|
3153 qed |
|
3154 |
|
3155 lemma ready_th_es [simp]: "th \<in> readys (e#s)" |
|
3156 by (simp add:readys_def) |
|
3157 |
|
3158 lemma holdents_th_s: "holdents s th = {}" |
|
3159 by (unfold holdents_def, auto) |
|
3160 |
|
3161 lemma holdents_th_es: "holdents (e#s) th = {}" |
|
3162 by (unfold holdents_def, auto) |
|
3163 |
|
3164 lemma cntCS_th_s [simp]: "cntCS s th = 0" |
|
3165 by (unfold cntCS_def, simp add:holdents_th_s) |
|
3166 |
|
3167 lemma cntCS_th_es [simp]: "cntCS (e#s) th = 0" |
|
3168 by (unfold cntCS_def, simp add:holdents_th_es) |
|
3169 |
|
3170 lemma pvD_th_s [simp]: "pvD s th = 0" |
|
3171 by (unfold pvD_def, simp) |
|
3172 |
|
3173 lemma pvD_th_es [simp]: "pvD (e#s) th = 0" |
|
3174 by (unfold pvD_def, simp) |
|
3175 |
|
3176 lemma holdents_kept: |
|
3177 assumes "th' \<noteq> th" |
|
3178 shows "holdents (e#s) th' = holdents s th'" (is "?L = ?R") |
|
3179 proof - |
|
3180 { fix cs' |
|
3181 assume h: "cs' \<in> ?L" |
|
3182 hence "cs' \<in> ?R" |
|
3183 by (unfold holdents_def s_holding_def, fold wq_def, |
|
3184 unfold wq_neq_simp, auto) |
|
3185 } moreover { |
|
3186 fix cs' |
|
3187 assume h: "cs' \<in> ?R" |
|
3188 hence "cs' \<in> ?L" |
|
3189 by (unfold holdents_def s_holding_def, fold wq_def, |
|
3190 unfold wq_neq_simp, auto) |
|
3191 } ultimately show ?thesis by auto |
|
3192 qed |
|
3193 |
|
3194 lemma cntCS_kept [simp]: |
|
3195 assumes "th' \<noteq> th" |
|
3196 shows "cntCS (e#s) th' = cntCS s th'" (is "?L = ?R") |
|
3197 using holdents_kept[OF assms] |
|
3198 by (unfold cntCS_def, simp) |
|
3199 |
|
3200 lemma readys_kept1: |
|
3201 assumes "th' \<noteq> th" |
|
3202 and "th' \<in> readys (e#s)" |
|
3203 shows "th' \<in> readys s" |
|
3204 proof - |
|
3205 { fix cs' |
|
3206 assume wait: "waiting s th' cs'" |
|
3207 have n_wait: "\<not> waiting (e#s) th' cs'" |
|
3208 using assms by (auto simp:readys_def) |
|
3209 from wait[unfolded s_waiting_def, folded wq_def] |
|
3210 n_wait[unfolded s_waiting_def, folded wq_def, unfolded wq_neq_simp] |
|
3211 have False by auto |
|
3212 } thus ?thesis using assms |
|
3213 by (unfold readys_def, auto) |
|
3214 qed |
|
3215 |
|
3216 lemma readys_kept2: |
|
3217 assumes "th' \<noteq> th" |
|
3218 and "th' \<in> readys s" |
|
3219 shows "th' \<in> readys (e#s)" |
|
3220 proof - |
|
3221 { fix cs' |
|
3222 assume wait: "waiting (e#s) th' cs'" |
|
3223 have n_wait: "\<not> waiting s th' cs'" |
|
3224 using assms(2) by (auto simp:readys_def) |
|
3225 from wait[unfolded s_waiting_def, folded wq_def, unfolded wq_neq_simp] |
|
3226 n_wait[unfolded s_waiting_def, folded wq_def] |
|
3227 have False by auto |
|
3228 } with assms show ?thesis |
|
3229 by (unfold readys_def, auto) |
|
3230 qed |
|
3231 |
|
3232 lemma readys_simp [simp]: |
|
3233 assumes "th' \<noteq> th" |
|
3234 shows "(th' \<in> readys (e#s)) = (th' \<in> readys s)" |
|
3235 using readys_kept1[OF assms] readys_kept2[OF assms] |
|
3236 by metis |
|
3237 |
|
3238 lemma pvD_kept [simp]: |
|
3239 assumes "th' \<noteq> th" |
|
3240 shows "pvD (e#s) th' = pvD s th'" |
|
3241 using assms |
|
3242 by (unfold pvD_def, simp) |
|
3243 |
|
3244 lemma cnp_cnv_cncs_kept: |
|
3245 assumes "cntP s th' = cntV s th' + cntCS s th' + pvD s th'" |
|
3246 shows "cntP (e#s) th' = cntV (e#s) th' + cntCS (e#s) th' + pvD (e#s) th'" |
|
3247 proof - |
|
3248 { |
|
3249 assume eq_th': "th' = th" |
|
3250 have ?thesis using assms |
|
3251 by (unfold eq_th', simp, unfold is_create, simp) |
|
3252 } moreover { |
|
3253 assume h: "th' \<noteq> th" |
|
3254 hence ?thesis using assms |
|
3255 by (simp, simp add:is_create) |
|
3256 } ultimately show ?thesis by metis |
|
3257 qed |
|
3258 |
|
3259 end |
|
3260 |
|
3261 context valid_trace_exit |
|
3262 begin |
|
3263 |
|
3264 lemma th_live_s [simp]: "th \<in> threads s" |
|
3265 proof - |
|
3266 from pip_e[unfolded is_exit] |
|
3267 show ?thesis |
|
3268 by (cases, unfold runing_def readys_def, simp) |
|
3269 qed |
|
3270 |
|
3271 lemma th_ready_s [simp]: "th \<in> readys s" |
|
3272 proof - |
|
3273 from pip_e[unfolded is_exit] |
|
3274 show ?thesis |
|
3275 by (cases, unfold runing_def, simp) |
|
3276 qed |
|
3277 |
|
3278 lemma th_not_live_es [simp]: "th \<notin> threads (e#s)" |
|
3279 by (unfold is_exit, simp) |
|
3280 |
|
3281 lemma not_holding_th_s [simp]: "\<not> holding s th cs'" |
|
3282 proof - |
|
3283 from pip_e[unfolded is_exit] |
|
3284 show ?thesis |
|
3285 by (cases, unfold holdents_def, auto) |
|
3286 qed |
|
3287 |
|
3288 lemma cntCS_th_s [simp]: "cntCS s th = 0" |
|
3289 proof - |
|
3290 from pip_e[unfolded is_exit] |
|
3291 show ?thesis |
|
3292 by (cases, unfold cntCS_def, simp) |
|
3293 qed |
|
3294 |
|
3295 lemma not_holding_th_es [simp]: "\<not> holding (e#s) th cs'" |
|
3296 proof |
|
3297 assume "holding (e # s) th cs'" |
|
3298 from this[unfolded s_holding_def, folded wq_def, unfolded wq_neq_simp] |
|
3299 have "holding s th cs'" |
|
3300 by (unfold s_holding_def, fold wq_def, auto) |
|
3301 with not_holding_th_s |
|
3302 show False by simp |
|
3303 qed |
|
3304 |
|
3305 lemma ready_th_es [simp]: "th \<notin> readys (e#s)" |
|
3306 by (simp add:readys_def) |
|
3307 |
|
3308 lemma holdents_th_s: "holdents s th = {}" |
|
3309 by (unfold holdents_def, auto) |
|
3310 |
|
3311 lemma holdents_th_es: "holdents (e#s) th = {}" |
|
3312 by (unfold holdents_def, auto) |
|
3313 |
|
3314 lemma cntCS_th_es [simp]: "cntCS (e#s) th = 0" |
|
3315 by (unfold cntCS_def, simp add:holdents_th_es) |
|
3316 |
|
3317 lemma pvD_th_s [simp]: "pvD s th = 0" |
|
3318 by (unfold pvD_def, simp) |
|
3319 |
|
3320 lemma pvD_th_es [simp]: "pvD (e#s) th = 0" |
|
3321 by (unfold pvD_def, simp) |
|
3322 |
|
3323 lemma holdents_kept: |
|
3324 assumes "th' \<noteq> th" |
|
3325 shows "holdents (e#s) th' = holdents s th'" (is "?L = ?R") |
|
3326 proof - |
|
3327 { fix cs' |
|
3328 assume h: "cs' \<in> ?L" |
|
3329 hence "cs' \<in> ?R" |
|
3330 by (unfold holdents_def s_holding_def, fold wq_def, |
|
3331 unfold wq_neq_simp, auto) |
|
3332 } moreover { |
|
3333 fix cs' |
|
3334 assume h: "cs' \<in> ?R" |
|
3335 hence "cs' \<in> ?L" |
|
3336 by (unfold holdents_def s_holding_def, fold wq_def, |
|
3337 unfold wq_neq_simp, auto) |
|
3338 } ultimately show ?thesis by auto |
|
3339 qed |
|
3340 |
|
3341 lemma cntCS_kept [simp]: |
|
3342 assumes "th' \<noteq> th" |
|
3343 shows "cntCS (e#s) th' = cntCS s th'" (is "?L = ?R") |
|
3344 using holdents_kept[OF assms] |
|
3345 by (unfold cntCS_def, simp) |
|
3346 |
|
3347 lemma readys_kept1: |
|
3348 assumes "th' \<noteq> th" |
|
3349 and "th' \<in> readys (e#s)" |
|
3350 shows "th' \<in> readys s" |
|
3351 proof - |
|
3352 { fix cs' |
|
3353 assume wait: "waiting s th' cs'" |
|
3354 have n_wait: "\<not> waiting (e#s) th' cs'" |
|
3355 using assms by (auto simp:readys_def) |
|
3356 from wait[unfolded s_waiting_def, folded wq_def] |
|
3357 n_wait[unfolded s_waiting_def, folded wq_def, unfolded wq_neq_simp] |
|
3358 have False by auto |
|
3359 } thus ?thesis using assms |
|
3360 by (unfold readys_def, auto) |
|
3361 qed |
|
3362 |
|
3363 lemma readys_kept2: |
|
3364 assumes "th' \<noteq> th" |
|
3365 and "th' \<in> readys s" |
|
3366 shows "th' \<in> readys (e#s)" |
|
3367 proof - |
|
3368 { fix cs' |
|
3369 assume wait: "waiting (e#s) th' cs'" |
|
3370 have n_wait: "\<not> waiting s th' cs'" |
|
3371 using assms(2) by (auto simp:readys_def) |
|
3372 from wait[unfolded s_waiting_def, folded wq_def, unfolded wq_neq_simp] |
|
3373 n_wait[unfolded s_waiting_def, folded wq_def] |
|
3374 have False by auto |
|
3375 } with assms show ?thesis |
|
3376 by (unfold readys_def, auto) |
|
3377 qed |
|
3378 |
|
3379 lemma readys_simp [simp]: |
|
3380 assumes "th' \<noteq> th" |
|
3381 shows "(th' \<in> readys (e#s)) = (th' \<in> readys s)" |
|
3382 using readys_kept1[OF assms] readys_kept2[OF assms] |
|
3383 by metis |
|
3384 |
|
3385 lemma pvD_kept [simp]: |
|
3386 assumes "th' \<noteq> th" |
|
3387 shows "pvD (e#s) th' = pvD s th'" |
|
3388 using assms |
|
3389 by (unfold pvD_def, simp) |
|
3390 |
|
3391 lemma cnp_cnv_cncs_kept: |
|
3392 assumes "cntP s th' = cntV s th' + cntCS s th' + pvD s th'" |
|
3393 shows "cntP (e#s) th' = cntV (e#s) th' + cntCS (e#s) th' + pvD (e#s) th'" |
|
3394 proof - |
|
3395 { |
|
3396 assume eq_th': "th' = th" |
|
3397 have ?thesis using assms |
|
3398 by (unfold eq_th', simp, unfold is_exit, simp) |
|
3399 } moreover { |
|
3400 assume h: "th' \<noteq> th" |
|
3401 hence ?thesis using assms |
|
3402 by (simp, simp add:is_exit) |
|
3403 } ultimately show ?thesis by metis |
|
3404 qed |
|
3405 |
|
3406 end |
|
3407 |
|
3408 context valid_trace_set |
|
3409 begin |
|
3410 |
|
3411 lemma th_live_s [simp]: "th \<in> threads s" |
|
3412 proof - |
|
3413 from pip_e[unfolded is_set] |
|
3414 show ?thesis |
|
3415 by (cases, unfold runing_def readys_def, simp) |
|
3416 qed |
|
3417 |
|
3418 lemma th_ready_s [simp]: "th \<in> readys s" |
|
3419 proof - |
|
3420 from pip_e[unfolded is_set] |
|
3421 show ?thesis |
|
3422 by (cases, unfold runing_def, simp) |
|
3423 qed |
|
3424 |
|
3425 lemma th_not_live_es [simp]: "th \<in> threads (e#s)" |
|
3426 by (unfold is_set, simp) |
|
3427 |
|
3428 |
|
3429 lemma holdents_kept: |
|
3430 shows "holdents (e#s) th' = holdents s th'" (is "?L = ?R") |
|
3431 proof - |
|
3432 { fix cs' |
|
3433 assume h: "cs' \<in> ?L" |
|
3434 hence "cs' \<in> ?R" |
|
3435 by (unfold holdents_def s_holding_def, fold wq_def, |
|
3436 unfold wq_neq_simp, auto) |
|
3437 } moreover { |
|
3438 fix cs' |
|
3439 assume h: "cs' \<in> ?R" |
|
3440 hence "cs' \<in> ?L" |
|
3441 by (unfold holdents_def s_holding_def, fold wq_def, |
|
3442 unfold wq_neq_simp, auto) |
|
3443 } ultimately show ?thesis by auto |
|
3444 qed |
|
3445 |
|
3446 lemma cntCS_kept [simp]: |
|
3447 shows "cntCS (e#s) th' = cntCS s th'" (is "?L = ?R") |
|
3448 using holdents_kept |
|
3449 by (unfold cntCS_def, simp) |
|
3450 |
|
3451 lemma threads_kept[simp]: |
|
3452 "threads (e#s) = threads s" |
|
3453 by (unfold is_set, simp) |
|
3454 |
|
3455 lemma readys_kept1: |
|
3456 assumes "th' \<in> readys (e#s)" |
|
3457 shows "th' \<in> readys s" |
|
3458 proof - |
|
3459 { fix cs' |
|
3460 assume wait: "waiting s th' cs'" |
|
3461 have n_wait: "\<not> waiting (e#s) th' cs'" |
|
3462 using assms by (auto simp:readys_def) |
|
3463 from wait[unfolded s_waiting_def, folded wq_def] |
|
3464 n_wait[unfolded s_waiting_def, folded wq_def, unfolded wq_neq_simp] |
|
3465 have False by auto |
|
3466 } moreover have "th' \<in> threads s" |
|
3467 using assms[unfolded readys_def] by auto |
|
3468 ultimately show ?thesis |
|
3469 by (unfold readys_def, auto) |
|
3470 qed |
|
3471 |
|
3472 lemma readys_kept2: |
|
3473 assumes "th' \<in> readys s" |
|
3474 shows "th' \<in> readys (e#s)" |
|
3475 proof - |
|
3476 { fix cs' |
|
3477 assume wait: "waiting (e#s) th' cs'" |
|
3478 have n_wait: "\<not> waiting s th' cs'" |
|
3479 using assms by (auto simp:readys_def) |
|
3480 from wait[unfolded s_waiting_def, folded wq_def, unfolded wq_neq_simp] |
|
3481 n_wait[unfolded s_waiting_def, folded wq_def] |
|
3482 have False by auto |
|
3483 } with assms show ?thesis |
|
3484 by (unfold readys_def, auto) |
|
3485 qed |
|
3486 |
|
3487 lemma readys_simp [simp]: |
|
3488 shows "(th' \<in> readys (e#s)) = (th' \<in> readys s)" |
|
3489 using readys_kept1 readys_kept2 |
|
3490 by metis |
|
3491 |
|
3492 lemma pvD_kept [simp]: |
|
3493 shows "pvD (e#s) th' = pvD s th'" |
|
3494 by (unfold pvD_def, simp) |
|
3495 |
|
3496 lemma cnp_cnv_cncs_kept: |
|
3497 assumes "cntP s th' = cntV s th' + cntCS s th' + pvD s th'" |
|
3498 shows "cntP (e#s) th' = cntV (e#s) th' + cntCS (e#s) th' + pvD (e#s) th'" |
|
3499 using assms |
|
3500 by (unfold is_set, simp, fold is_set, simp) |
|
3501 |
|
3502 end |
|
3503 |
|
3504 context valid_trace |
|
3505 begin |
|
3506 |
|
3507 lemma cnp_cnv_cncs: "cntP s th' = cntV s th' + cntCS s th' + pvD s th'" |
|
3508 proof(induct rule:ind) |
|
3509 case Nil |
|
3510 thus ?case |
|
3511 by (unfold cntP_def cntV_def pvD_def cntCS_def holdents_def |
|
3512 s_holding_def, simp) |
|
3513 next |
|
3514 case (Cons s e) |
|
3515 interpret vt_e: valid_trace_e s e using Cons by simp |
|
3516 show ?case |
|
3517 proof(cases e) |
|
3518 case (Create th prio) |
|
3519 interpret vt_create: valid_trace_create s e th prio |
|
3520 using Create by (unfold_locales, simp) |
|
3521 show ?thesis using Cons by (simp add: vt_create.cnp_cnv_cncs_kept) |
|
3522 next |
|
3523 case (Exit th) |
|
3524 interpret vt_exit: valid_trace_exit s e th |
|
3525 using Exit by (unfold_locales, simp) |
|
3526 show ?thesis using Cons by (simp add: vt_exit.cnp_cnv_cncs_kept) |
|
3527 next |
|
3528 case (P th cs) |
|
3529 interpret vt_p: valid_trace_p s e th cs using P by (unfold_locales, simp) |
|
3530 show ?thesis using Cons by (simp add: vt_p.cnp_cnv_cncs_kept) |
|
3531 next |
|
3532 case (V th cs) |
|
3533 interpret vt_v: valid_trace_v s e th cs using V by (unfold_locales, simp) |
|
3534 show ?thesis using Cons by (simp add: vt_v.cnp_cnv_cncs_kept) |
|
3535 next |
|
3536 case (Set th prio) |
|
3537 interpret vt_set: valid_trace_set s e th prio |
|
3538 using Set by (unfold_locales, simp) |
|
3539 show ?thesis using Cons by (simp add: vt_set.cnp_cnv_cncs_kept) |
|
3540 qed |
|
3541 qed |
|
3542 |
|
3543 lemma not_thread_holdents: |
|
3544 assumes not_in: "th \<notin> threads s" |
|
3545 shows "holdents s th = {}" |
|
3546 proof - |
|
3547 { fix cs |
|
3548 assume "cs \<in> holdents s th" |
|
3549 hence "holding s th cs" by (auto simp:holdents_def) |
|
3550 from this[unfolded s_holding_def, folded wq_def] |
|
3551 have "th \<in> set (wq s cs)" by auto |
|
3552 with wq_threads have "th \<in> threads s" by auto |
|
3553 with assms |
|
3554 have False by simp |
|
3555 } thus ?thesis by auto |
|
3556 qed |
|
3557 |
|
3558 lemma not_thread_cncs: |
|
3559 assumes not_in: "th \<notin> threads s" |
|
3560 shows "cntCS s th = 0" |
|
3561 using not_thread_holdents[OF assms] |
|
3562 by (simp add:cntCS_def) |
|
3563 |
|
3564 lemma cnp_cnv_eq: |
|
3565 assumes "th \<notin> threads s" |
|
3566 shows "cntP s th = cntV s th" |
|
3567 using assms cnp_cnv_cncs not_thread_cncs pvD_def |
|
3568 by (auto) |
|
3569 |
|
3570 lemma runing_unique: |
|
3571 assumes runing_1: "th1 \<in> runing s" |
|
3572 and runing_2: "th2 \<in> runing s" |
|
3573 shows "th1 = th2" |
|
3574 proof - |
|
3575 from runing_1 and runing_2 have "cp s th1 = cp s th2" |
|
3576 unfolding runing_def by auto |
|
3577 from this[unfolded cp_alt_def] |
|
3578 have eq_max: |
|
3579 "Max (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th1)}) = |
|
3580 Max (the_preced s ` {th'. Th th' \<in> subtree (RAG s) (Th th2)})" |
|
3581 (is "Max ?L = Max ?R") . |
|
3582 have "Max ?L \<in> ?L" |
|
3583 proof(rule Max_in) |
|
3584 show "finite ?L" by (simp add: finite_subtree_threads) |
|
3585 next |
|
3586 show "?L \<noteq> {}" using subtree_def by fastforce |
|
3587 qed |
|
3588 then obtain th1' where |
|
3589 h_1: "Th th1' \<in> subtree (RAG s) (Th th1)" "the_preced s th1' = Max ?L" |
|
3590 by auto |
|
3591 have "Max ?R \<in> ?R" |
|
3592 proof(rule Max_in) |
|
3593 show "finite ?R" by (simp add: finite_subtree_threads) |
|
3594 next |
|
3595 show "?R \<noteq> {}" using subtree_def by fastforce |
|
3596 qed |
|
3597 then obtain th2' where |
|
3598 h_2: "Th th2' \<in> subtree (RAG s) (Th th2)" "the_preced s th2' = Max ?R" |
|
3599 by auto |
|
3600 have "th1' = th2'" |
|
3601 proof(rule preced_unique) |
|
3602 from h_1(1) |
|
3603 show "th1' \<in> threads s" |
|
3604 proof(cases rule:subtreeE) |
|
3605 case 1 |
|
3606 hence "th1' = th1" by simp |
|
3607 with runing_1 show ?thesis by (auto simp:runing_def readys_def) |
|
3608 next |
|
3609 case 2 |
|
3610 from this(2) |
|
3611 have "(Th th1', Th th1) \<in> (RAG s)^+" by (auto simp:ancestors_def) |
|
3612 from tranclD[OF this] |
|
3613 have "(Th th1') \<in> Domain (RAG s)" by auto |
|
3614 from dm_RAG_threads[OF this] show ?thesis . |
|
3615 qed |
|
3616 next |
|
3617 from h_2(1) |
|
3618 show "th2' \<in> threads s" |
|
3619 proof(cases rule:subtreeE) |
|
3620 case 1 |
|
3621 hence "th2' = th2" by simp |
|
3622 with runing_2 show ?thesis by (auto simp:runing_def readys_def) |
|
3623 next |
|
3624 case 2 |
|
3625 from this(2) |
|
3626 have "(Th th2', Th th2) \<in> (RAG s)^+" by (auto simp:ancestors_def) |
|
3627 from tranclD[OF this] |
|
3628 have "(Th th2') \<in> Domain (RAG s)" by auto |
|
3629 from dm_RAG_threads[OF this] show ?thesis . |
|
3630 qed |
|
3631 next |
|
3632 have "the_preced s th1' = the_preced s th2'" |
|
3633 using eq_max h_1(2) h_2(2) by metis |
|
3634 thus "preced th1' s = preced th2' s" by (simp add:the_preced_def) |
|
3635 qed |
|
3636 from h_1(1)[unfolded this] |
|
3637 have star1: "(Th th2', Th th1) \<in> (RAG s)^*" by (auto simp:subtree_def) |
|
3638 from h_2(1)[unfolded this] |
|
3639 have star2: "(Th th2', Th th2) \<in> (RAG s)^*" by (auto simp:subtree_def) |
|
3640 from star_rpath[OF star1] obtain xs1 |
|
3641 where rp1: "rpath (RAG s) (Th th2') xs1 (Th th1)" |
|
3642 by auto |
|
3643 from star_rpath[OF star2] obtain xs2 |
|
3644 where rp2: "rpath (RAG s) (Th th2') xs2 (Th th2)" |
|
3645 by auto |
|
3646 show ?thesis |
|
3647 proof(cases rule:rtree_RAG.rpath_overlap[OF rp1 rp2]) |
|
3648 case (1 xs') |
|
3649 moreover have "xs' = []" |
|
3650 proof(rule ccontr) |
|
3651 assume otherwise: "xs' \<noteq> []" |
|
3652 find_theorems rpath "_@_" |
|
3653 qed |
|
3654 ultimately have "xs2 = xs1" by simp |
|
3655 from rpath_dest_eq[OF rp1 rp2[unfolded this]] |
|
3656 show ?thesis by simp |
|
3657 next |
|
3658 case (2 xs') |
|
3659 moreover have "xs' = []" sorry |
|
3660 ultimately have "xs2 = xs1" by simp |
|
3661 from rpath_dest_eq[OF rp1 rp2[unfolded this]] |
|
3662 show ?thesis by simp |
|
3663 qed |
|
3664 qed |
|
3665 |
|
3666 end |
|
3667 |
|
3668 |
|
3669 |
|
3670 end |
|
3671 |