--- a/doc-src/IsarAdvanced/Classes/Thy/Classes.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/doc-src/IsarAdvanced/Classes/Thy/Classes.thy Fri Jan 16 13:07:44 2009 -0800
@@ -368,14 +368,14 @@
text {*
\noindent The connection to the type system is done by means
of a primitive axclass
-*}
+*} setup %invisible {* Sign.add_path "foo" *}
axclass %quote idem < type
- idem: "f (f x) = f x"
+ idem: "f (f x) = f x" setup %invisible {* Sign.parent_path *}
text {* \noindent together with a corresponding interpretation: *}
-interpretation %quote idem_class': (* FIXME proper prefix? *)
+interpretation %quote idem_class:
idem "f \<Colon> (\<alpha>\<Colon>idem) \<Rightarrow> \<alpha>"
proof qed (rule idem)
@@ -459,7 +459,7 @@
of monoids for lists:
*}
-class_interpretation %quote list_monoid: monoid [append "[]"]
+interpretation %quote list_monoid!: monoid append "[]"
proof qed auto
text {*
@@ -474,10 +474,10 @@
"replicate 0 _ = []"
| "replicate (Suc n) xs = xs @ replicate n xs"
-class_interpretation %quote list_monoid: monoid [append "[]"] where
+interpretation %quote list_monoid!: monoid append "[]" where
"monoid.pow_nat append [] = replicate"
proof -
- class_interpret monoid [append "[]"] ..
+ interpret monoid append "[]" ..
show "monoid.pow_nat append [] = replicate"
proof
fix n
--- a/doc-src/IsarAdvanced/Classes/Thy/document/Classes.tex Thu Jan 15 14:33:38 2009 -0800
+++ b/doc-src/IsarAdvanced/Classes/Thy/document/Classes.tex Fri Jan 16 13:07:44 2009 -0800
@@ -655,7 +655,23 @@
\end{isamarkuptext}%
\isamarkuptrue%
%
+\isadeliminvisible
+\ %
+\endisadeliminvisible
+%
+\isataginvisible
+\isacommand{setup}\isamarkupfalse%
+\ {\isacharverbatimopen}\ Sign{\isachardot}add{\isacharunderscore}path\ {\isachardoublequote}foo{\isachardoublequote}\ {\isacharverbatimclose}%
+\endisataginvisible
+{\isafoldinvisible}%
+%
+\isadeliminvisible
+%
+\endisadeliminvisible
+\isanewline
+%
\isadelimquote
+\isanewline
%
\endisadelimquote
%
@@ -670,6 +686,20 @@
%
\endisadelimquote
%
+\isadeliminvisible
+\ %
+\endisadeliminvisible
+%
+\isataginvisible
+\isacommand{setup}\isamarkupfalse%
+\ {\isacharverbatimopen}\ Sign{\isachardot}parent{\isacharunderscore}path\ {\isacharverbatimclose}%
+\endisataginvisible
+{\isafoldinvisible}%
+%
+\isadeliminvisible
+%
+\endisadeliminvisible
+%
\begin{isamarkuptext}%
\noindent together with a corresponding interpretation:%
\end{isamarkuptext}%
@@ -681,7 +711,7 @@
%
\isatagquote
\isacommand{interpretation}\isamarkupfalse%
-\ idem{\isacharunderscore}class{\isacharprime}{\isacharcolon}\ \ \ \ \isanewline
+\ idem{\isacharunderscore}class{\isacharcolon}\isanewline
\ \ idem\ {\isachardoublequoteopen}f\ {\isasymColon}\ {\isacharparenleft}{\isasymalpha}{\isasymColon}idem{\isacharparenright}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\isanewline
\isacommand{proof}\isamarkupfalse%
\ \isacommand{qed}\isamarkupfalse%
@@ -843,8 +873,8 @@
\endisadelimquote
%
\isatagquote
-\isacommand{class{\isacharunderscore}interpretation}\isamarkupfalse%
-\ list{\isacharunderscore}monoid{\isacharcolon}\ monoid\ {\isacharbrackleft}append\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}{\isacharbrackright}\isanewline
+\isacommand{interpretation}\isamarkupfalse%
+\ list{\isacharunderscore}monoid{\isacharbang}{\isacharcolon}\ monoid\ append\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline
\ \ \isacommand{proof}\isamarkupfalse%
\ \isacommand{qed}\isamarkupfalse%
\ auto%
@@ -874,13 +904,13 @@
\ \ {\isachardoublequoteopen}replicate\ {\isadigit{0}}\ {\isacharunderscore}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline
\ \ {\isacharbar}\ {\isachardoublequoteopen}replicate\ {\isacharparenleft}Suc\ n{\isacharparenright}\ xs\ {\isacharequal}\ xs\ {\isacharat}\ replicate\ n\ xs{\isachardoublequoteclose}\isanewline
\isanewline
-\isacommand{class{\isacharunderscore}interpretation}\isamarkupfalse%
-\ list{\isacharunderscore}monoid{\isacharcolon}\ monoid\ {\isacharbrackleft}append\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}{\isacharbrackright}\ \isakeyword{where}\isanewline
+\isacommand{interpretation}\isamarkupfalse%
+\ list{\isacharunderscore}monoid{\isacharbang}{\isacharcolon}\ monoid\ append\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
\ \ {\isachardoublequoteopen}monoid{\isachardot}pow{\isacharunderscore}nat\ append\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ replicate{\isachardoublequoteclose}\isanewline
\isacommand{proof}\isamarkupfalse%
\ {\isacharminus}\isanewline
-\ \ \isacommand{class{\isacharunderscore}interpret}\isamarkupfalse%
-\ monoid\ {\isacharbrackleft}append\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}{\isacharbrackright}\ \isacommand{{\isachardot}{\isachardot}}\isamarkupfalse%
+\ \ \isacommand{interpret}\isamarkupfalse%
+\ monoid\ append\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\ \isacommand{{\isachardot}{\isachardot}}\isamarkupfalse%
\isanewline
\ \ \isacommand{show}\isamarkupfalse%
\ {\isachardoublequoteopen}monoid{\isachardot}pow{\isacharunderscore}nat\ append\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ replicate{\isachardoublequoteclose}\isanewline
--- a/doc-src/IsarAdvanced/Codegen/Thy/Setup.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/doc-src/IsarAdvanced/Codegen/Thy/Setup.thy Fri Jan 16 13:07:44 2009 -0800
@@ -4,7 +4,7 @@
begin
ML {* no_document use_thys
- ["Efficient_Nat", "Code_Char_chr", "Product_ord", "Imperative_HOL",
+ ["Efficient_Nat", "Code_Char_chr", "Product_ord", "~~/src/HOL/Imperative_HOL/Imperative_HOL",
"~~/src/HOL/ex/ReflectedFerrack"] *}
ML_val {* Code_Target.code_width := 74 *}
--- a/src/FOL/ex/LocaleTest.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/FOL/ex/LocaleTest.thy Fri Jan 16 13:07:44 2009 -0800
@@ -8,9 +8,6 @@
imports FOL
begin
-ML_val {* set Toplevel.debug *}
-
-
typedecl int arities int :: "term"
consts plus :: "int => int => int" (infixl "+" 60)
zero :: int ("0")
@@ -483,6 +480,4 @@
thm local_free.lone [where ?zero = 0]
qed
-ML_val {* reset Toplevel.debug *}
-
end
--- a/src/HOL/Dense_Linear_Order.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/Dense_Linear_Order.thy Fri Jan 16 13:07:44 2009 -0800
@@ -301,7 +301,7 @@
text {* Linear order without upper bounds *}
-class_locale linorder_stupid_syntax = linorder
+locale linorder_stupid_syntax = linorder
begin
notation
less_eq ("op \<sqsubseteq>") and
@@ -311,7 +311,7 @@
end
-class_locale linorder_no_ub = linorder_stupid_syntax +
+locale linorder_no_ub = linorder_stupid_syntax +
assumes gt_ex: "\<exists>y. less x y"
begin
lemma ge_ex: "\<exists>y. x \<sqsubseteq> y" using gt_ex by auto
@@ -360,7 +360,7 @@
text {* Linear order without upper bounds *}
-class_locale linorder_no_lb = linorder_stupid_syntax +
+locale linorder_no_lb = linorder_stupid_syntax +
assumes lt_ex: "\<exists>y. less y x"
begin
lemma le_ex: "\<exists>y. y \<sqsubseteq> x" using lt_ex by auto
@@ -407,12 +407,12 @@
end
-class_locale constr_dense_linear_order = linorder_no_lb + linorder_no_ub +
+locale constr_dense_linear_order = linorder_no_lb + linorder_no_ub +
fixes between
assumes between_less: "less x y \<Longrightarrow> less x (between x y) \<and> less (between x y) y"
and between_same: "between x x = x"
-class_interpretation constr_dense_linear_order < dense_linear_order
+sublocale constr_dense_linear_order < dense_linear_order
apply unfold_locales
using gt_ex lt_ex between_less
by (auto, rule_tac x="between x y" in exI, simp)
@@ -635,9 +635,9 @@
using eq_diff_eq[where a= x and b=t and c=0] by simp
-class_interpretation class_ordered_field_dense_linear_order: constr_dense_linear_order
- ["op <=" "op <"
- "\<lambda> x y. 1/2 * ((x::'a::{ordered_field,recpower,number_ring}) + y)"]
+interpretation class_ordered_field_dense_linear_order!: constr_dense_linear_order
+ "op <=" "op <"
+ "\<lambda> x y. 1/2 * ((x::'a::{ordered_field,recpower,number_ring}) + y)"
proof (unfold_locales, dlo, dlo, auto)
fix x y::'a assume lt: "x < y"
from less_half_sum[OF lt] show "x < (x + y) /2" by simp
--- a/src/HOL/Divides.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/Divides.thy Fri Jan 16 13:07:44 2009 -0800
@@ -20,7 +20,7 @@
subsection {* Abstract division in commutative semirings. *}
-class semiring_div = comm_semiring_1_cancel + div +
+class semiring_div = comm_semiring_1_cancel + div +
assumes mod_div_equality: "a div b * b + a mod b = a"
and div_by_0 [simp]: "a div 0 = 0"
and div_0 [simp]: "0 div a = 0"
@@ -800,7 +800,7 @@
text {* @{term "op dvd"} is a partial order *}
-class_interpretation dvd: order ["op dvd" "\<lambda>n m \<Colon> nat. n dvd m \<and> \<not> m dvd n"]
+interpretation dvd!: order "op dvd" "\<lambda>n m \<Colon> nat. n dvd m \<and> \<not> m dvd n"
proof qed (auto intro: dvd_refl dvd_trans dvd_anti_sym)
lemma dvd_diff: "[| k dvd m; k dvd n |] ==> k dvd (m-n :: nat)"
--- a/src/HOL/Finite_Set.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/Finite_Set.thy Fri Jan 16 13:07:44 2009 -0800
@@ -873,7 +873,7 @@
subsection {* Generalized summation over a set *}
-class_interpretation comm_monoid_add: comm_monoid_mult ["0::'a::comm_monoid_add" "op +"]
+interpretation comm_monoid_add!: comm_monoid_mult "0::'a::comm_monoid_add" "op +"
proof qed (auto intro: add_assoc add_commute)
definition setsum :: "('a => 'b) => 'a set => 'b::comm_monoid_add"
@@ -1760,7 +1760,7 @@
proof (induct rule: finite_induct)
case empty then show ?case by simp
next
- class_interpret ab_semigroup_mult ["op Un"]
+ interpret ab_semigroup_mult "op Un"
proof qed auto
case insert
then show ?case by simp
@@ -2198,7 +2198,7 @@
assumes "finite A" "A \<noteq> {}"
shows "x \<le> fold1 inf A \<longleftrightarrow> (\<forall>a\<in>A. x \<le> a)"
proof -
- class_interpret ab_semigroup_idem_mult [inf]
+ interpret ab_semigroup_idem_mult inf
by (rule ab_semigroup_idem_mult_inf)
show ?thesis using assms by (induct rule: finite_ne_induct) simp_all
qed
@@ -2213,7 +2213,7 @@
proof (induct rule: finite_ne_induct)
case singleton thus ?case by simp
next
- class_interpret ab_semigroup_idem_mult [inf]
+ interpret ab_semigroup_idem_mult inf
by (rule ab_semigroup_idem_mult_inf)
case (insert x F)
from insert(5) have "a = x \<or> a \<in> F" by simp
@@ -2288,7 +2288,7 @@
and "A \<noteq> {}"
shows "sup x (\<Sqinter>\<^bsub>fin\<^esub>A) = \<Sqinter>\<^bsub>fin\<^esub>{sup x a|a. a \<in> A}"
proof -
- class_interpret ab_semigroup_idem_mult [inf]
+ interpret ab_semigroup_idem_mult inf
by (rule ab_semigroup_idem_mult_inf)
from assms show ?thesis
by (simp add: Inf_fin_def image_def
@@ -2303,7 +2303,7 @@
case singleton thus ?case
by (simp add: sup_Inf1_distrib [OF B] fold1_singleton_def [OF Inf_fin_def])
next
- class_interpret ab_semigroup_idem_mult [inf]
+ interpret ab_semigroup_idem_mult inf
by (rule ab_semigroup_idem_mult_inf)
case (insert x A)
have finB: "finite {sup x b |b. b \<in> B}"
@@ -2333,7 +2333,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "inf x (\<Squnion>\<^bsub>fin\<^esub>A) = \<Squnion>\<^bsub>fin\<^esub>{inf x a|a. a \<in> A}"
proof -
- class_interpret ab_semigroup_idem_mult [sup]
+ interpret ab_semigroup_idem_mult sup
by (rule ab_semigroup_idem_mult_sup)
from assms show ?thesis
by (simp add: Sup_fin_def image_def hom_fold1_commute [where h="inf x", OF inf_sup_distrib1])
@@ -2357,7 +2357,7 @@
thus ?thesis by(simp add: insert(1) B(1))
qed
have ne: "{inf a b |a b. a \<in> A \<and> b \<in> B} \<noteq> {}" using insert B by blast
- class_interpret ab_semigroup_idem_mult [sup]
+ interpret ab_semigroup_idem_mult sup
by (rule ab_semigroup_idem_mult_sup)
have "inf (\<Squnion>\<^bsub>fin\<^esub>(insert x A)) (\<Squnion>\<^bsub>fin\<^esub>B) = inf (sup x (\<Squnion>\<^bsub>fin\<^esub>A)) (\<Squnion>\<^bsub>fin\<^esub>B)"
using insert by (simp add: fold1_insert_idem_def [OF Sup_fin_def])
@@ -2386,7 +2386,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "\<Sqinter>\<^bsub>fin\<^esub>A = Inf A"
proof -
- class_interpret ab_semigroup_idem_mult [inf]
+ interpret ab_semigroup_idem_mult inf
by (rule ab_semigroup_idem_mult_inf)
from assms show ?thesis
unfolding Inf_fin_def by (induct A set: finite)
@@ -2397,7 +2397,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "\<Squnion>\<^bsub>fin\<^esub>A = Sup A"
proof -
- class_interpret ab_semigroup_idem_mult [sup]
+ interpret ab_semigroup_idem_mult sup
by (rule ab_semigroup_idem_mult_sup)
from assms show ?thesis
unfolding Sup_fin_def by (induct A set: finite)
@@ -2446,7 +2446,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "x < fold1 min A \<longleftrightarrow> (\<forall>a\<in>A. x < a)"
proof -
- class_interpret ab_semigroup_idem_mult [min]
+ interpret ab_semigroup_idem_mult min
by (rule ab_semigroup_idem_mult_min)
from assms show ?thesis
by (induct rule: finite_ne_induct)
@@ -2457,7 +2457,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "fold1 min A \<le> x \<longleftrightarrow> (\<exists>a\<in>A. a \<le> x)"
proof -
- class_interpret ab_semigroup_idem_mult [min]
+ interpret ab_semigroup_idem_mult min
by (rule ab_semigroup_idem_mult_min)
from assms show ?thesis
by (induct rule: finite_ne_induct)
@@ -2468,7 +2468,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "fold1 min A < x \<longleftrightarrow> (\<exists>a\<in>A. a < x)"
proof -
- class_interpret ab_semigroup_idem_mult [min]
+ interpret ab_semigroup_idem_mult min
by (rule ab_semigroup_idem_mult_min)
from assms show ?thesis
by (induct rule: finite_ne_induct)
@@ -2481,7 +2481,7 @@
proof cases
assume "A = B" thus ?thesis by simp
next
- class_interpret ab_semigroup_idem_mult [min]
+ interpret ab_semigroup_idem_mult min
by (rule ab_semigroup_idem_mult_min)
assume "A \<noteq> B"
have B: "B = A \<union> (B-A)" using `A \<subseteq> B` by blast
@@ -2515,7 +2515,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "Min (insert x A) = min x (Min A)"
proof -
- class_interpret ab_semigroup_idem_mult [min]
+ interpret ab_semigroup_idem_mult min
by (rule ab_semigroup_idem_mult_min)
from assms show ?thesis by (rule fold1_insert_idem_def [OF Min_def])
qed
@@ -2524,7 +2524,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "Max (insert x A) = max x (Max A)"
proof -
- class_interpret ab_semigroup_idem_mult [max]
+ interpret ab_semigroup_idem_mult max
by (rule ab_semigroup_idem_mult_max)
from assms show ?thesis by (rule fold1_insert_idem_def [OF Max_def])
qed
@@ -2533,7 +2533,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "Min A \<in> A"
proof -
- class_interpret ab_semigroup_idem_mult [min]
+ interpret ab_semigroup_idem_mult min
by (rule ab_semigroup_idem_mult_min)
from assms fold1_in show ?thesis by (fastsimp simp: Min_def min_def)
qed
@@ -2542,7 +2542,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "Max A \<in> A"
proof -
- class_interpret ab_semigroup_idem_mult [max]
+ interpret ab_semigroup_idem_mult max
by (rule ab_semigroup_idem_mult_max)
from assms fold1_in [of A] show ?thesis by (fastsimp simp: Max_def max_def)
qed
@@ -2551,7 +2551,7 @@
assumes "finite A" and "A \<noteq> {}" and "finite B" and "B \<noteq> {}"
shows "Min (A \<union> B) = min (Min A) (Min B)"
proof -
- class_interpret ab_semigroup_idem_mult [min]
+ interpret ab_semigroup_idem_mult min
by (rule ab_semigroup_idem_mult_min)
from assms show ?thesis
by (simp add: Min_def fold1_Un2)
@@ -2561,7 +2561,7 @@
assumes "finite A" and "A \<noteq> {}" and "finite B" and "B \<noteq> {}"
shows "Max (A \<union> B) = max (Max A) (Max B)"
proof -
- class_interpret ab_semigroup_idem_mult [max]
+ interpret ab_semigroup_idem_mult max
by (rule ab_semigroup_idem_mult_max)
from assms show ?thesis
by (simp add: Max_def fold1_Un2)
@@ -2572,7 +2572,7 @@
and "finite N" and "N \<noteq> {}"
shows "h (Min N) = Min (h ` N)"
proof -
- class_interpret ab_semigroup_idem_mult [min]
+ interpret ab_semigroup_idem_mult min
by (rule ab_semigroup_idem_mult_min)
from assms show ?thesis
by (simp add: Min_def hom_fold1_commute)
@@ -2583,7 +2583,7 @@
and "finite N" and "N \<noteq> {}"
shows "h (Max N) = Max (h ` N)"
proof -
- class_interpret ab_semigroup_idem_mult [max]
+ interpret ab_semigroup_idem_mult max
by (rule ab_semigroup_idem_mult_max)
from assms show ?thesis
by (simp add: Max_def hom_fold1_commute [of h])
@@ -2593,7 +2593,7 @@
assumes "finite A" and "x \<in> A"
shows "Min A \<le> x"
proof -
- class_interpret lower_semilattice ["op \<le>" "op <" min]
+ interpret lower_semilattice "op \<le>" "op <" min
by (rule min_lattice)
from assms show ?thesis by (simp add: Min_def fold1_belowI)
qed
@@ -2602,7 +2602,7 @@
assumes "finite A" and "x \<in> A"
shows "x \<le> Max A"
proof -
- invoke lower_semilattice ["op \<ge>" "op >" max]
+ interpret lower_semilattice "op \<ge>" "op >" max
by (rule max_lattice)
from assms show ?thesis by (simp add: Max_def fold1_belowI)
qed
@@ -2611,7 +2611,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "x \<le> Min A \<longleftrightarrow> (\<forall>a\<in>A. x \<le> a)"
proof -
- class_interpret lower_semilattice ["op \<le>" "op <" min]
+ interpret lower_semilattice "op \<le>" "op <" min
by (rule min_lattice)
from assms show ?thesis by (simp add: Min_def below_fold1_iff)
qed
@@ -2620,7 +2620,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "Max A \<le> x \<longleftrightarrow> (\<forall>a\<in>A. a \<le> x)"
proof -
- invoke lower_semilattice ["op \<ge>" "op >" max]
+ interpret lower_semilattice "op \<ge>" "op >" max
by (rule max_lattice)
from assms show ?thesis by (simp add: Max_def below_fold1_iff)
qed
@@ -2629,7 +2629,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "x < Min A \<longleftrightarrow> (\<forall>a\<in>A. x < a)"
proof -
- class_interpret lower_semilattice ["op \<le>" "op <" min]
+ interpret lower_semilattice "op \<le>" "op <" min
by (rule min_lattice)
from assms show ?thesis by (simp add: Min_def strict_below_fold1_iff)
qed
@@ -2639,7 +2639,7 @@
shows "Max A < x \<longleftrightarrow> (\<forall>a\<in>A. a < x)"
proof -
note Max = Max_def
- class_interpret linorder ["op \<ge>" "op >"]
+ interpret linorder "op \<ge>" "op >"
by (rule dual_linorder)
from assms show ?thesis
by (simp add: Max strict_below_fold1_iff [folded dual_max])
@@ -2649,7 +2649,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "Min A \<le> x \<longleftrightarrow> (\<exists>a\<in>A. a \<le> x)"
proof -
- class_interpret lower_semilattice ["op \<le>" "op <" min]
+ interpret lower_semilattice "op \<le>" "op <" min
by (rule min_lattice)
from assms show ?thesis
by (simp add: Min_def fold1_below_iff)
@@ -2660,7 +2660,7 @@
shows "x \<le> Max A \<longleftrightarrow> (\<exists>a\<in>A. x \<le> a)"
proof -
note Max = Max_def
- class_interpret linorder ["op \<ge>" "op >"]
+ interpret linorder "op \<ge>" "op >"
by (rule dual_linorder)
from assms show ?thesis
by (simp add: Max fold1_below_iff [folded dual_max])
@@ -2670,7 +2670,7 @@
assumes "finite A" and "A \<noteq> {}"
shows "Min A < x \<longleftrightarrow> (\<exists>a\<in>A. a < x)"
proof -
- class_interpret lower_semilattice ["op \<le>" "op <" min]
+ interpret lower_semilattice "op \<le>" "op <" min
by (rule min_lattice)
from assms show ?thesis
by (simp add: Min_def fold1_strict_below_iff)
@@ -2681,7 +2681,7 @@
shows "x < Max A \<longleftrightarrow> (\<exists>a\<in>A. x < a)"
proof -
note Max = Max_def
- class_interpret linorder ["op \<ge>" "op >"]
+ interpret linorder "op \<ge>" "op >"
by (rule dual_linorder)
from assms show ?thesis
by (simp add: Max fold1_strict_below_iff [folded dual_max])
@@ -2691,7 +2691,7 @@
assumes "M \<subseteq> N" and "M \<noteq> {}" and "finite N"
shows "Min N \<le> Min M"
proof -
- class_interpret distrib_lattice ["op \<le>" "op <" min max]
+ interpret distrib_lattice "op \<le>" "op <" min max
by (rule distrib_lattice_min_max)
from assms show ?thesis by (simp add: Min_def fold1_antimono)
qed
@@ -2701,7 +2701,7 @@
shows "Max M \<le> Max N"
proof -
note Max = Max_def
- class_interpret linorder ["op \<ge>" "op >"]
+ interpret linorder "op \<ge>" "op >"
by (rule dual_linorder)
from assms show ?thesis
by (simp add: Max fold1_antimono [folded dual_max])
--- a/src/HOL/HOL.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/HOL.thy Fri Jan 16 13:07:44 2009 -0800
@@ -35,7 +35,7 @@
"~~/src/Tools/code/code_ml.ML"
"~~/src/Tools/code/code_haskell.ML"
"~~/src/Tools/nbe.ML"
- ("~~/src/HOL/Tools/recfun_codegen.ML")
+ ("Tools/recfun_codegen.ML")
begin
subsection {* Primitive logic *}
@@ -1690,7 +1690,7 @@
text {* Module setup *}
-use "~~/src/HOL/Tools/recfun_codegen.ML"
+use "Tools/recfun_codegen.ML"
setup {*
Code_ML.setup
--- a/src/HOL/IsaMakefile Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/IsaMakefile Fri Jan 16 13:07:44 2009 -0800
@@ -6,7 +6,7 @@
default: HOL
generate: HOL-Generate-HOL HOL-Generate-HOLLight
-images: HOL-Plain HOL-Main HOL HOL-Algebra HOL-Nominal HOL-NSA HOL-Word TLA HOL4
+images: HOL HOL-Base HOL-Plain HOL-Main HOL-Algebra HOL-Nominal HOL-NSA HOL-Word TLA HOL4
#Note: keep targets sorted (except for HOL-Library and HOL-ex)
test: \
@@ -66,6 +66,8 @@
HOL: Pure $(OUT)/HOL
+HOL-Base: Pure $(OUT)/HOL-Base
+
HOL-Plain: Pure $(OUT)/HOL-Plain
HOL-Main: Pure $(OUT)/HOL-Main
@@ -75,15 +77,50 @@
$(OUT)/Pure: Pure
-PLAIN_DEPENDENCIES = $(OUT)/Pure \
+BASE_DEPENDENCIES = $(OUT)/Pure \
Code_Setup.thy \
+ HOL.thy \
+ Tools/hologic.ML \
+ Tools/recfun_codegen.ML \
+ Tools/simpdata.ML \
+ $(SRC)/Tools/atomize_elim.ML \
+ $(SRC)/Tools/code/code_funcgr.ML \
+ $(SRC)/Tools/code/code_funcgr.ML \
+ $(SRC)/Tools/code/code_name.ML \
+ $(SRC)/Tools/code/code_printer.ML \
+ $(SRC)/Tools/code/code_target.ML \
+ $(SRC)/Tools/code/code_ml.ML \
+ $(SRC)/Tools/code/code_haskell.ML \
+ $(SRC)/Tools/code/code_thingol.ML \
+ $(SRC)/Tools/induct.ML \
+ $(SRC)/Tools/induct_tacs.ML \
+ $(SRC)/Tools/IsaPlanner/isand.ML \
+ $(SRC)/Tools/IsaPlanner/rw_inst.ML \
+ $(SRC)/Tools/IsaPlanner/rw_tools.ML \
+ $(SRC)/Tools/IsaPlanner/zipper.ML \
+ $(SRC)/Tools/nbe.ML \
+ $(SRC)/Tools/random_word.ML \
+ $(SRC)/Tools/value.ML \
+ $(SRC)/Provers/blast.ML \
+ $(SRC)/Provers/clasimp.ML \
+ $(SRC)/Provers/classical.ML \
+ $(SRC)/Provers/coherent.ML \
+ $(SRC)/Provers/eqsubst.ML \
+ $(SRC)/Provers/hypsubst.ML \
+ $(SRC)/Provers/project_rule.ML \
+ $(SRC)/Provers/quantifier1.ML \
+ $(SRC)/Provers/splitter.ML \
+
+$(OUT)/HOL-Base: base.ML $(BASE_DEPENDENCIES)
+ @$(ISABELLE_TOOL) usedir -b -f base.ML -g true $(OUT)/Pure HOL-Base
+
+PLAIN_DEPENDENCIES = $(BASE_DEPENDENCIES)\
Datatype.thy \
Divides.thy \
Extraction.thy \
Finite_Set.thy \
Fun.thy \
FunDef.thy \
- HOL.thy \
Inductive.thy \
Lattices.thy \
Nat.thy \
@@ -131,7 +168,6 @@
Tools/function_package/size.ML \
Tools/function_package/sum_tree.ML \
Tools/function_package/termination.ML \
- Tools/hologic.ML \
Tools/inductive_codegen.ML \
Tools/inductive_package.ML \
Tools/inductive_realizer.ML \
@@ -140,14 +176,12 @@
Tools/old_primrec_package.ML \
Tools/primrec_package.ML \
Tools/prop_logic.ML \
- Tools/recfun_codegen.ML \
Tools/record_package.ML \
Tools/refute.ML \
Tools/refute_isar.ML \
Tools/rewrite_hol_proof.ML \
Tools/sat_funcs.ML \
Tools/sat_solver.ML \
- Tools/simpdata.ML \
Tools/split_rule.ML \
Tools/typecopy_package.ML \
Tools/typedef_codegen.ML \
@@ -159,35 +193,8 @@
$(SRC)/Provers/Arith/cancel_div_mod.ML \
$(SRC)/Provers/Arith/cancel_sums.ML \
$(SRC)/Provers/Arith/fast_lin_arith.ML \
- $(SRC)/Provers/blast.ML \
- $(SRC)/Provers/clasimp.ML \
- $(SRC)/Provers/classical.ML \
- $(SRC)/Provers/coherent.ML \
- $(SRC)/Provers/eqsubst.ML \
- $(SRC)/Provers/hypsubst.ML \
$(SRC)/Provers/order.ML \
- $(SRC)/Provers/project_rule.ML \
- $(SRC)/Provers/quantifier1.ML \
- $(SRC)/Provers/splitter.ML \
$(SRC)/Provers/trancl.ML \
- $(SRC)/Tools/IsaPlanner/isand.ML \
- $(SRC)/Tools/IsaPlanner/rw_inst.ML \
- $(SRC)/Tools/IsaPlanner/rw_tools.ML \
- $(SRC)/Tools/IsaPlanner/zipper.ML \
- $(SRC)/Tools/atomize_elim.ML \
- $(SRC)/Tools/code/code_funcgr.ML \
- $(SRC)/Tools/code/code_funcgr.ML \
- $(SRC)/Tools/code/code_name.ML \
- $(SRC)/Tools/code/code_printer.ML \
- $(SRC)/Tools/code/code_target.ML \
- $(SRC)/Tools/code/code_ml.ML \
- $(SRC)/Tools/code/code_haskell.ML \
- $(SRC)/Tools/code/code_thingol.ML \
- $(SRC)/Tools/induct.ML \
- $(SRC)/Tools/induct_tacs.ML \
- $(SRC)/Tools/value.ML \
- $(SRC)/Tools/nbe.ML \
- $(SRC)/Tools/random_word.ML \
$(SRC)/Tools/rat.ML
$(OUT)/HOL-Plain: plain.ML $(PLAIN_DEPENDENCIES)
@@ -280,7 +287,6 @@
GCD.thy \
Order_Relation.thy \
Parity.thy \
- Univ_Poly.thy \
Lubs.thy \
Polynomial.thy \
PReal.thy \
@@ -327,7 +333,7 @@
Library/Code_Char_chr.thy Library/Code_Integer.thy \
Library/Numeral_Type.thy \
Library/Boolean_Algebra.thy Library/Countable.thy \
- Library/RBT.thy \
+ Library/RBT.thy Library/Univ_Poly.thy \
Library/Enum.thy Library/Float.thy $(SRC)/Tools/float.ML $(SRC)/HOL/Tools/float_arith.ML
@cd Library; $(ISABELLE_TOOL) usedir $(OUT)/HOL Library
--- a/src/HOL/Lattices.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/Lattices.thy Fri Jan 16 13:07:44 2009 -0800
@@ -300,8 +300,7 @@
by auto
qed (auto simp add: min_def max_def not_le less_imp_le)
-class_interpretation min_max:
- distrib_lattice ["op \<le> \<Colon> 'a\<Colon>linorder \<Rightarrow> 'a \<Rightarrow> bool" "op <" min max]
+interpretation min_max!: distrib_lattice "op \<le> :: 'a::linorder \<Rightarrow> 'a \<Rightarrow> bool" "op <" min max
by (rule distrib_lattice_min_max)
lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{lower_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
--- a/src/HOL/Library/Countable.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/Library/Countable.thy Fri Jan 16 13:07:44 2009 -0800
@@ -1,5 +1,4 @@
(* Title: HOL/Library/Countable.thy
- ID: $Id$
Author: Alexander Krauss, TU Muenchen
*)
--- a/src/HOL/Library/Library.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/Library/Library.thy Fri Jan 16 13:07:44 2009 -0800
@@ -1,4 +1,3 @@
-(* $Id$ *)
(*<*)
theory Library
imports
@@ -38,6 +37,7 @@
Ramsey
RBT
State_Monad
+ Univ_Poly
While_Combinator
Word
Zorn
--- a/src/HOL/Library/Multiset.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/Library/Multiset.thy Fri Jan 16 13:07:44 2009 -0800
@@ -1,5 +1,4 @@
(* Title: HOL/Library/Multiset.thy
- ID: $Id$
Author: Tobias Nipkow, Markus Wenzel, Lawrence C Paulson, Norbert Voelker
*)
@@ -1080,16 +1079,16 @@
apply simp
done
-class_interpretation mset_order: order ["op \<le>#" "op <#"]
+interpretation mset_order!: order "op \<le>#" "op <#"
proof qed (auto intro: order.intro mset_le_refl mset_le_antisym
mset_le_trans simp: mset_less_def)
-class_interpretation mset_order_cancel_semigroup:
- pordered_cancel_ab_semigroup_add ["op +" "op \<le>#" "op <#"]
+interpretation mset_order_cancel_semigroup!:
+ pordered_cancel_ab_semigroup_add "op +" "op \<le>#" "op <#"
proof qed (erule mset_le_mono_add [OF mset_le_refl])
-class_interpretation mset_order_semigroup_cancel:
- pordered_ab_semigroup_add_imp_le ["op +" "op \<le>#" "op <#"]
+interpretation mset_order_semigroup_cancel!:
+ pordered_ab_semigroup_add_imp_le "op +" "op \<le>#" "op <#"
proof qed simp
@@ -1156,7 +1155,7 @@
then show ?case using T by simp
qed
-lemmas mset_less_trans = mset_order.less_eq_less.less_trans
+lemmas mset_less_trans = mset_order.less_trans
lemma mset_less_diff_self: "c \<in># B \<Longrightarrow> B - {#c#} \<subset># B"
by (auto simp: mset_le_def mset_less_def multi_drop_mem_not_eq)
--- a/src/HOL/Library/SetsAndFunctions.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/Library/SetsAndFunctions.thy Fri Jan 16 13:07:44 2009 -0800
@@ -107,26 +107,26 @@
apply simp
done
-class_interpretation set_semigroup_add: semigroup_add ["op \<oplus> :: ('a::semigroup_add) set => 'a set => 'a set"]
+interpretation set_semigroup_add!: semigroup_add "op \<oplus> :: ('a::semigroup_add) set => 'a set => 'a set"
apply default
apply (unfold set_plus_def)
apply (force simp add: add_assoc)
done
-class_interpretation set_semigroup_mult: semigroup_mult ["op \<otimes> :: ('a::semigroup_mult) set => 'a set => 'a set"]
+interpretation set_semigroup_mult!: semigroup_mult "op \<otimes> :: ('a::semigroup_mult) set => 'a set => 'a set"
apply default
apply (unfold set_times_def)
apply (force simp add: mult_assoc)
done
-class_interpretation set_comm_monoid_add: comm_monoid_add ["{0}" "op \<oplus> :: ('a::comm_monoid_add) set => 'a set => 'a set"]
+interpretation set_comm_monoid_add!: comm_monoid_add "{0}" "op \<oplus> :: ('a::comm_monoid_add) set => 'a set => 'a set"
apply default
apply (unfold set_plus_def)
apply (force simp add: add_ac)
apply force
done
-class_interpretation set_comm_monoid_mult: comm_monoid_mult ["{1}" "op \<otimes> :: ('a::comm_monoid_mult) set => 'a set => 'a set"]
+interpretation set_comm_monoid_mult!: comm_monoid_mult "{1}" "op \<otimes> :: ('a::comm_monoid_mult) set => 'a set => 'a set"
apply default
apply (unfold set_times_def)
apply (force simp add: mult_ac)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/HOL/Library/Univ_Poly.thy Fri Jan 16 13:07:44 2009 -0800
@@ -0,0 +1,1050 @@
+(* Title: Univ_Poly.thy
+ Author: Amine Chaieb
+*)
+
+header {* Univariate Polynomials *}
+
+theory Univ_Poly
+imports Plain List
+begin
+
+text{* Application of polynomial as a function. *}
+
+primrec (in semiring_0) poly :: "'a list => 'a => 'a" where
+ poly_Nil: "poly [] x = 0"
+| poly_Cons: "poly (h#t) x = h + x * poly t x"
+
+
+subsection{*Arithmetic Operations on Polynomials*}
+
+text{*addition*}
+
+primrec (in semiring_0) padd :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" (infixl "+++" 65)
+where
+ padd_Nil: "[] +++ l2 = l2"
+| padd_Cons: "(h#t) +++ l2 = (if l2 = [] then h#t
+ else (h + hd l2)#(t +++ tl l2))"
+
+text{*Multiplication by a constant*}
+primrec (in semiring_0) cmult :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list" (infixl "%*" 70) where
+ cmult_Nil: "c %* [] = []"
+| cmult_Cons: "c %* (h#t) = (c * h)#(c %* t)"
+
+text{*Multiplication by a polynomial*}
+primrec (in semiring_0) pmult :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" (infixl "***" 70)
+where
+ pmult_Nil: "[] *** l2 = []"
+| pmult_Cons: "(h#t) *** l2 = (if t = [] then h %* l2
+ else (h %* l2) +++ ((0) # (t *** l2)))"
+
+text{*Repeated multiplication by a polynomial*}
+primrec (in semiring_0) mulexp :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where
+ mulexp_zero: "mulexp 0 p q = q"
+| mulexp_Suc: "mulexp (Suc n) p q = p *** mulexp n p q"
+
+text{*Exponential*}
+primrec (in semiring_1) pexp :: "'a list \<Rightarrow> nat \<Rightarrow> 'a list" (infixl "%^" 80) where
+ pexp_0: "p %^ 0 = [1]"
+| pexp_Suc: "p %^ (Suc n) = p *** (p %^ n)"
+
+text{*Quotient related value of dividing a polynomial by x + a*}
+(* Useful for divisor properties in inductive proofs *)
+primrec (in field) "pquot" :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a list" where
+ pquot_Nil: "pquot [] a= []"
+| pquot_Cons: "pquot (h#t) a = (if t = [] then [h]
+ else (inverse(a) * (h - hd( pquot t a)))#(pquot t a))"
+
+text{*normalization of polynomials (remove extra 0 coeff)*}
+primrec (in semiring_0) pnormalize :: "'a list \<Rightarrow> 'a list" where
+ pnormalize_Nil: "pnormalize [] = []"
+| pnormalize_Cons: "pnormalize (h#p) = (if ( (pnormalize p) = [])
+ then (if (h = 0) then [] else [h])
+ else (h#(pnormalize p)))"
+
+definition (in semiring_0) "pnormal p = ((pnormalize p = p) \<and> p \<noteq> [])"
+definition (in semiring_0) "nonconstant p = (pnormal p \<and> (\<forall>x. p \<noteq> [x]))"
+text{*Other definitions*}
+
+definition (in ring_1)
+ poly_minus :: "'a list => 'a list" ("-- _" [80] 80) where
+ "-- p = (- 1) %* p"
+
+definition (in semiring_0)
+ divides :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infixl "divides" 70) where
+ [code del]: "p1 divides p2 = (\<exists>q. poly p2 = poly(p1 *** q))"
+
+ --{*order of a polynomial*}
+definition (in ring_1) order :: "'a => 'a list => nat" where
+ "order a p = (SOME n. ([-a, 1] %^ n) divides p &
+ ~ (([-a, 1] %^ (Suc n)) divides p))"
+
+ --{*degree of a polynomial*}
+definition (in semiring_0) degree :: "'a list => nat" where
+ "degree p = length (pnormalize p) - 1"
+
+ --{*squarefree polynomials --- NB with respect to real roots only.*}
+definition (in ring_1)
+ rsquarefree :: "'a list => bool" where
+ "rsquarefree p = (poly p \<noteq> poly [] &
+ (\<forall>a. (order a p = 0) | (order a p = 1)))"
+
+context semiring_0
+begin
+
+lemma padd_Nil2[simp]: "p +++ [] = p"
+by (induct p) auto
+
+lemma padd_Cons_Cons: "(h1 # p1) +++ (h2 # p2) = (h1 + h2) # (p1 +++ p2)"
+by auto
+
+lemma pminus_Nil[simp]: "-- [] = []"
+by (simp add: poly_minus_def)
+
+lemma pmult_singleton: "[h1] *** p1 = h1 %* p1" by simp
+end
+
+lemma (in semiring_1) poly_ident_mult[simp]: "1 %* t = t" by (induct "t", auto)
+
+lemma (in semiring_0) poly_simple_add_Cons[simp]: "[a] +++ ((0)#t) = (a#t)"
+by simp
+
+text{*Handy general properties*}
+
+lemma (in comm_semiring_0) padd_commut: "b +++ a = a +++ b"
+proof(induct b arbitrary: a)
+ case Nil thus ?case by auto
+next
+ case (Cons b bs a) thus ?case by (cases a, simp_all add: add_commute)
+qed
+
+lemma (in comm_semiring_0) padd_assoc: "\<forall>b c. (a +++ b) +++ c = a +++ (b +++ c)"
+apply (induct a arbitrary: b c)
+apply (simp, clarify)
+apply (case_tac b, simp_all add: add_ac)
+done
+
+lemma (in semiring_0) poly_cmult_distr: "a %* ( p +++ q) = (a %* p +++ a %* q)"
+apply (induct p arbitrary: q,simp)
+apply (case_tac q, simp_all add: right_distrib)
+done
+
+lemma (in ring_1) pmult_by_x[simp]: "[0, 1] *** t = ((0)#t)"
+apply (induct "t", simp)
+apply (auto simp add: mult_zero_left poly_ident_mult padd_commut)
+apply (case_tac t, auto)
+done
+
+text{*properties of evaluation of polynomials.*}
+
+lemma (in semiring_0) poly_add: "poly (p1 +++ p2) x = poly p1 x + poly p2 x"
+proof(induct p1 arbitrary: p2)
+ case Nil thus ?case by simp
+next
+ case (Cons a as p2) thus ?case
+ by (cases p2, simp_all add: add_ac right_distrib)
+qed
+
+lemma (in comm_semiring_0) poly_cmult: "poly (c %* p) x = c * poly p x"
+apply (induct "p")
+apply (case_tac [2] "x=zero")
+apply (auto simp add: right_distrib mult_ac)
+done
+
+lemma (in comm_semiring_0) poly_cmult_map: "poly (map (op * c) p) x = c*poly p x"
+ by (induct p, auto simp add: right_distrib mult_ac)
+
+lemma (in comm_ring_1) poly_minus: "poly (-- p) x = - (poly p x)"
+apply (simp add: poly_minus_def)
+apply (auto simp add: poly_cmult minus_mult_left[symmetric])
+done
+
+lemma (in comm_semiring_0) poly_mult: "poly (p1 *** p2) x = poly p1 x * poly p2 x"
+proof(induct p1 arbitrary: p2)
+ case Nil thus ?case by simp
+next
+ case (Cons a as p2)
+ thus ?case by (cases as,
+ simp_all add: poly_cmult poly_add left_distrib right_distrib mult_ac)
+qed
+
+class recpower_semiring = semiring + recpower
+class recpower_semiring_1 = semiring_1 + recpower
+class recpower_semiring_0 = semiring_0 + recpower
+class recpower_ring = ring + recpower
+class recpower_ring_1 = ring_1 + recpower
+subclass (in recpower_ring_1) recpower_ring ..
+class recpower_comm_semiring_1 = recpower + comm_semiring_1
+class recpower_comm_ring_1 = recpower + comm_ring_1
+subclass (in recpower_comm_ring_1) recpower_comm_semiring_1 ..
+class recpower_idom = recpower + idom
+subclass (in recpower_idom) recpower_comm_ring_1 ..
+class idom_char_0 = idom + ring_char_0
+class recpower_idom_char_0 = recpower + idom_char_0
+subclass (in recpower_idom_char_0) recpower_idom ..
+
+lemma (in recpower_comm_ring_1) poly_exp: "poly (p %^ n) x = (poly p x) ^ n"
+apply (induct "n")
+apply (auto simp add: poly_cmult poly_mult power_Suc)
+done
+
+text{*More Polynomial Evaluation Lemmas*}
+
+lemma (in semiring_0) poly_add_rzero[simp]: "poly (a +++ []) x = poly a x"
+by simp
+
+lemma (in comm_semiring_0) poly_mult_assoc: "poly ((a *** b) *** c) x = poly (a *** (b *** c)) x"
+ by (simp add: poly_mult mult_assoc)
+
+lemma (in semiring_0) poly_mult_Nil2[simp]: "poly (p *** []) x = 0"
+by (induct "p", auto)
+
+lemma (in comm_semiring_1) poly_exp_add: "poly (p %^ (n + d)) x = poly( p %^ n *** p %^ d) x"
+apply (induct "n")
+apply (auto simp add: poly_mult mult_assoc)
+done
+
+subsection{*Key Property: if @{term "f(a) = 0"} then @{term "(x - a)"} divides
+ @{term "p(x)"} *}
+
+lemma (in comm_ring_1) lemma_poly_linear_rem: "\<forall>h. \<exists>q r. h#t = [r] +++ [-a, 1] *** q"
+proof(induct t)
+ case Nil
+ {fix h have "[h] = [h] +++ [- a, 1] *** []" by simp}
+ thus ?case by blast
+next
+ case (Cons x xs)
+ {fix h
+ from Cons.hyps[rule_format, of x]
+ obtain q r where qr: "x#xs = [r] +++ [- a, 1] *** q" by blast
+ have "h#x#xs = [a*r + h] +++ [-a, 1] *** (r#q)"
+ using qr by(cases q, simp_all add: ring_simps diff_def[symmetric]
+ minus_mult_left[symmetric] right_minus)
+ hence "\<exists>q r. h#x#xs = [r] +++ [-a, 1] *** q" by blast}
+ thus ?case by blast
+qed
+
+lemma (in comm_ring_1) poly_linear_rem: "\<exists>q r. h#t = [r] +++ [-a, 1] *** q"
+by (cut_tac t = t and a = a in lemma_poly_linear_rem, auto)
+
+
+lemma (in comm_ring_1) poly_linear_divides: "(poly p a = 0) = ((p = []) | (\<exists>q. p = [-a, 1] *** q))"
+proof-
+ {assume p: "p = []" hence ?thesis by simp}
+ moreover
+ {fix x xs assume p: "p = x#xs"
+ {fix q assume "p = [-a, 1] *** q" hence "poly p a = 0"
+ by (simp add: poly_add poly_cmult minus_mult_left[symmetric])}
+ moreover
+ {assume p0: "poly p a = 0"
+ from poly_linear_rem[of x xs a] obtain q r
+ where qr: "x#xs = [r] +++ [- a, 1] *** q" by blast
+ have "r = 0" using p0 by (simp only: p qr poly_mult poly_add) simp
+ hence "\<exists>q. p = [- a, 1] *** q" using p qr apply - apply (rule exI[where x=q])apply auto apply (cases q) apply auto done}
+ ultimately have ?thesis using p by blast}
+ ultimately show ?thesis by (cases p, auto)
+qed
+
+lemma (in semiring_0) lemma_poly_length_mult[simp]: "\<forall>h k a. length (k %* p +++ (h # (a %* p))) = Suc (length p)"
+by (induct "p", auto)
+
+lemma (in semiring_0) lemma_poly_length_mult2[simp]: "\<forall>h k. length (k %* p +++ (h # p)) = Suc (length p)"
+by (induct "p", auto)
+
+lemma (in ring_1) poly_length_mult[simp]: "length([-a,1] *** q) = Suc (length q)"
+by auto
+
+subsection{*Polynomial length*}
+
+lemma (in semiring_0) poly_cmult_length[simp]: "length (a %* p) = length p"
+by (induct "p", auto)
+
+lemma (in semiring_0) poly_add_length: "length (p1 +++ p2) = max (length p1) (length p2)"
+apply (induct p1 arbitrary: p2, simp_all)
+apply arith
+done
+
+lemma (in semiring_0) poly_root_mult_length[simp]: "length([a,b] *** p) = Suc (length p)"
+by (simp add: poly_add_length)
+
+lemma (in idom) poly_mult_not_eq_poly_Nil[simp]:
+ "poly (p *** q) x \<noteq> poly [] x \<longleftrightarrow> poly p x \<noteq> poly [] x \<and> poly q x \<noteq> poly [] x"
+by (auto simp add: poly_mult)
+
+lemma (in idom) poly_mult_eq_zero_disj: "poly (p *** q) x = 0 \<longleftrightarrow> poly p x = 0 \<or> poly q x = 0"
+by (auto simp add: poly_mult)
+
+text{*Normalisation Properties*}
+
+lemma (in semiring_0) poly_normalized_nil: "(pnormalize p = []) --> (poly p x = 0)"
+by (induct "p", auto)
+
+text{*A nontrivial polynomial of degree n has no more than n roots*}
+lemma (in idom) poly_roots_index_lemma:
+ assumes p: "poly p x \<noteq> poly [] x" and n: "length p = n"
+ shows "\<exists>i. \<forall>x. poly p x = 0 \<longrightarrow> (\<exists>m\<le>n. x = i m)"
+ using p n
+proof(induct n arbitrary: p x)
+ case 0 thus ?case by simp
+next
+ case (Suc n p x)
+ {assume C: "\<And>i. \<exists>x. poly p x = 0 \<and> (\<forall>m\<le>Suc n. x \<noteq> i m)"
+ from Suc.prems have p0: "poly p x \<noteq> 0" "p\<noteq> []" by auto
+ from p0(1)[unfolded poly_linear_divides[of p x]]
+ have "\<forall>q. p \<noteq> [- x, 1] *** q" by blast
+ from C obtain a where a: "poly p a = 0" by blast
+ from a[unfolded poly_linear_divides[of p a]] p0(2)
+ obtain q where q: "p = [-a, 1] *** q" by blast
+ have lg: "length q = n" using q Suc.prems(2) by simp
+ from q p0 have qx: "poly q x \<noteq> poly [] x"
+ by (auto simp add: poly_mult poly_add poly_cmult)
+ from Suc.hyps[OF qx lg] obtain i where
+ i: "\<forall>x. poly q x = 0 \<longrightarrow> (\<exists>m\<le>n. x = i m)" by blast
+ let ?i = "\<lambda>m. if m = Suc n then a else i m"
+ from C[of ?i] obtain y where y: "poly p y = 0" "\<forall>m\<le> Suc n. y \<noteq> ?i m"
+ by blast
+ from y have "y = a \<or> poly q y = 0"
+ by (simp only: q poly_mult_eq_zero_disj poly_add) (simp add: ring_simps)
+ with i[rule_format, of y] y(1) y(2) have False apply auto
+ apply (erule_tac x="m" in allE)
+ apply auto
+ done}
+ thus ?case by blast
+qed
+
+
+lemma (in idom) poly_roots_index_length: "poly p x \<noteq> poly [] x ==>
+ \<exists>i. \<forall>x. (poly p x = 0) --> (\<exists>n. n \<le> length p & x = i n)"
+by (blast intro: poly_roots_index_lemma)
+
+lemma (in idom) poly_roots_finite_lemma1: "poly p x \<noteq> poly [] x ==>
+ \<exists>N i. \<forall>x. (poly p x = 0) --> (\<exists>n. (n::nat) < N & x = i n)"
+apply (drule poly_roots_index_length, safe)
+apply (rule_tac x = "Suc (length p)" in exI)
+apply (rule_tac x = i in exI)
+apply (simp add: less_Suc_eq_le)
+done
+
+
+lemma (in idom) idom_finite_lemma:
+ assumes P: "\<forall>x. P x --> (\<exists>n. n < length j & x = j!n)"
+ shows "finite {x. P x}"
+proof-
+ let ?M = "{x. P x}"
+ let ?N = "set j"
+ have "?M \<subseteq> ?N" using P by auto
+ thus ?thesis using finite_subset by auto
+qed
+
+
+lemma (in idom) poly_roots_finite_lemma2: "poly p x \<noteq> poly [] x ==>
+ \<exists>i. \<forall>x. (poly p x = 0) --> x \<in> set i"
+apply (drule poly_roots_index_length, safe)
+apply (rule_tac x="map (\<lambda>n. i n) [0 ..< Suc (length p)]" in exI)
+apply (auto simp add: image_iff)
+apply (erule_tac x="x" in allE, clarsimp)
+by (case_tac "n=length p", auto simp add: order_le_less)
+
+lemma UNIV_nat_infinite: "\<not> finite (UNIV :: nat set)"
+ unfolding finite_conv_nat_seg_image
+proof(auto simp add: expand_set_eq image_iff)
+ fix n::nat and f:: "nat \<Rightarrow> nat"
+ let ?N = "{i. i < n}"
+ let ?fN = "f ` ?N"
+ let ?y = "Max ?fN + 1"
+ from nat_seg_image_imp_finite[of "?fN" "f" n]
+ have thfN: "finite ?fN" by simp
+ {assume "n =0" hence "\<exists>x. \<forall>xa<n. x \<noteq> f xa" by auto}
+ moreover
+ {assume nz: "n \<noteq> 0"
+ hence thne: "?fN \<noteq> {}" by (auto simp add: neq0_conv)
+ have "\<forall>x\<in> ?fN. Max ?fN \<ge> x" using nz Max_ge_iff[OF thfN thne] by auto
+ hence "\<forall>x\<in> ?fN. ?y > x" by auto
+ hence "?y \<notin> ?fN" by auto
+ hence "\<exists>x. \<forall>xa<n. x \<noteq> f xa" by auto }
+ ultimately show "\<exists>x. \<forall>xa<n. x \<noteq> f xa" by blast
+qed
+
+lemma (in ring_char_0) UNIV_ring_char_0_infinte:
+ "\<not> (finite (UNIV:: 'a set))"
+proof
+ assume F: "finite (UNIV :: 'a set)"
+ have "finite (UNIV :: nat set)"
+ proof (rule finite_imageD)
+ have "of_nat ` UNIV \<subseteq> UNIV" by simp
+ then show "finite (of_nat ` UNIV :: 'a set)" using F by (rule finite_subset)
+ show "inj (of_nat :: nat \<Rightarrow> 'a)" by (simp add: inj_on_def)
+ qed
+ with UNIV_nat_infinite show False ..
+qed
+
+lemma (in idom_char_0) poly_roots_finite: "(poly p \<noteq> poly []) =
+ finite {x. poly p x = 0}"
+proof
+ assume H: "poly p \<noteq> poly []"
+ show "finite {x. poly p x = (0::'a)}"
+ using H
+ apply -
+ apply (erule contrapos_np, rule ext)
+ apply (rule ccontr)
+ apply (clarify dest!: poly_roots_finite_lemma2)
+ using finite_subset
+ proof-
+ fix x i
+ assume F: "\<not> finite {x. poly p x = (0\<Colon>'a)}"
+ and P: "\<forall>x. poly p x = (0\<Colon>'a) \<longrightarrow> x \<in> set i"
+ let ?M= "{x. poly p x = (0\<Colon>'a)}"
+ from P have "?M \<subseteq> set i" by auto
+ with finite_subset F show False by auto
+ qed
+next
+ assume F: "finite {x. poly p x = (0\<Colon>'a)}"
+ show "poly p \<noteq> poly []" using F UNIV_ring_char_0_infinte by auto
+qed
+
+text{*Entirety and Cancellation for polynomials*}
+
+lemma (in idom_char_0) poly_entire_lemma2:
+ assumes p0: "poly p \<noteq> poly []" and q0: "poly q \<noteq> poly []"
+ shows "poly (p***q) \<noteq> poly []"
+proof-
+ let ?S = "\<lambda>p. {x. poly p x = 0}"
+ have "?S (p *** q) = ?S p \<union> ?S q" by (auto simp add: poly_mult)
+ with p0 q0 show ?thesis unfolding poly_roots_finite by auto
+qed
+
+lemma (in idom_char_0) poly_entire:
+ "poly (p *** q) = poly [] \<longleftrightarrow> poly p = poly [] \<or> poly q = poly []"
+using poly_entire_lemma2[of p q]
+by auto (rule ext, simp add: poly_mult)+
+
+lemma (in idom_char_0) poly_entire_neg: "(poly (p *** q) \<noteq> poly []) = ((poly p \<noteq> poly []) & (poly q \<noteq> poly []))"
+by (simp add: poly_entire)
+
+lemma fun_eq: " (f = g) = (\<forall>x. f x = g x)"
+by (auto intro!: ext)
+
+lemma (in comm_ring_1) poly_add_minus_zero_iff: "(poly (p +++ -- q) = poly []) = (poly p = poly q)"
+by (auto simp add: ring_simps poly_add poly_minus_def fun_eq poly_cmult minus_mult_left[symmetric])
+
+lemma (in comm_ring_1) poly_add_minus_mult_eq: "poly (p *** q +++ --(p *** r)) = poly (p *** (q +++ -- r))"
+by (auto simp add: poly_add poly_minus_def fun_eq poly_mult poly_cmult right_distrib minus_mult_left[symmetric] minus_mult_right[symmetric])
+
+subclass (in idom_char_0) comm_ring_1 ..
+lemma (in idom_char_0) poly_mult_left_cancel: "(poly (p *** q) = poly (p *** r)) = (poly p = poly [] | poly q = poly r)"
+proof-
+ have "poly (p *** q) = poly (p *** r) \<longleftrightarrow> poly (p *** q +++ -- (p *** r)) = poly []" by (simp only: poly_add_minus_zero_iff)
+ also have "\<dots> \<longleftrightarrow> poly p = poly [] | poly q = poly r"
+ by (auto intro: ext simp add: poly_add_minus_mult_eq poly_entire poly_add_minus_zero_iff)
+ finally show ?thesis .
+qed
+
+lemma (in recpower_idom) poly_exp_eq_zero[simp]:
+ "(poly (p %^ n) = poly []) = (poly p = poly [] & n \<noteq> 0)"
+apply (simp only: fun_eq add: all_simps [symmetric])
+apply (rule arg_cong [where f = All])
+apply (rule ext)
+apply (induct n)
+apply (auto simp add: poly_exp poly_mult)
+done
+
+lemma (in semiring_1) one_neq_zero[simp]: "1 \<noteq> 0" using zero_neq_one by blast
+lemma (in comm_ring_1) poly_prime_eq_zero[simp]: "poly [a,1] \<noteq> poly []"
+apply (simp add: fun_eq)
+apply (rule_tac x = "minus one a" in exI)
+apply (unfold diff_minus)
+apply (subst add_commute)
+apply (subst add_assoc)
+apply simp
+done
+
+lemma (in recpower_idom) poly_exp_prime_eq_zero: "(poly ([a, 1] %^ n) \<noteq> poly [])"
+by auto
+
+text{*A more constructive notion of polynomials being trivial*}
+
+lemma (in idom_char_0) poly_zero_lemma': "poly (h # t) = poly [] ==> h = 0 & poly t = poly []"
+apply(simp add: fun_eq)
+apply (case_tac "h = zero")
+apply (drule_tac [2] x = zero in spec, auto)
+apply (cases "poly t = poly []", simp)
+proof-
+ fix x
+ assume H: "\<forall>x. x = (0\<Colon>'a) \<or> poly t x = (0\<Colon>'a)" and pnz: "poly t \<noteq> poly []"
+ let ?S = "{x. poly t x = 0}"
+ from H have "\<forall>x. x \<noteq>0 \<longrightarrow> poly t x = 0" by blast
+ hence th: "?S \<supseteq> UNIV - {0}" by auto
+ from poly_roots_finite pnz have th': "finite ?S" by blast
+ from finite_subset[OF th th'] UNIV_ring_char_0_infinte
+ show "poly t x = (0\<Colon>'a)" by simp
+ qed
+
+lemma (in idom_char_0) poly_zero: "(poly p = poly []) = list_all (%c. c = 0) p"
+apply (induct "p", simp)
+apply (rule iffI)
+apply (drule poly_zero_lemma', auto)
+done
+
+lemma (in idom_char_0) poly_0: "list_all (\<lambda>c. c = 0) p \<Longrightarrow> poly p x = 0"
+ unfolding poly_zero[symmetric] by simp
+
+
+
+text{*Basics of divisibility.*}
+
+lemma (in idom) poly_primes: "([a, 1] divides (p *** q)) = ([a, 1] divides p | [a, 1] divides q)"
+apply (auto simp add: divides_def fun_eq poly_mult poly_add poly_cmult left_distrib [symmetric])
+apply (drule_tac x = "uminus a" in spec)
+apply (simp add: poly_linear_divides poly_add poly_cmult left_distrib [symmetric])
+apply (cases "p = []")
+apply (rule exI[where x="[]"])
+apply simp
+apply (cases "q = []")
+apply (erule allE[where x="[]"], simp)
+
+apply clarsimp
+apply (cases "\<exists>q\<Colon>'a list. p = a %* q +++ ((0\<Colon>'a) # q)")
+apply (clarsimp simp add: poly_add poly_cmult)
+apply (rule_tac x="qa" in exI)
+apply (simp add: left_distrib [symmetric])
+apply clarsimp
+
+apply (auto simp add: right_minus poly_linear_divides poly_add poly_cmult left_distrib [symmetric])
+apply (rule_tac x = "pmult qa q" in exI)
+apply (rule_tac [2] x = "pmult p qa" in exI)
+apply (auto simp add: poly_add poly_mult poly_cmult mult_ac)
+done
+
+lemma (in comm_semiring_1) poly_divides_refl[simp]: "p divides p"
+apply (simp add: divides_def)
+apply (rule_tac x = "[one]" in exI)
+apply (auto simp add: poly_mult fun_eq)
+done
+
+lemma (in comm_semiring_1) poly_divides_trans: "[| p divides q; q divides r |] ==> p divides r"
+apply (simp add: divides_def, safe)
+apply (rule_tac x = "pmult qa qaa" in exI)
+apply (auto simp add: poly_mult fun_eq mult_assoc)
+done
+
+
+lemma (in recpower_comm_semiring_1) poly_divides_exp: "m \<le> n ==> (p %^ m) divides (p %^ n)"
+apply (auto simp add: le_iff_add)
+apply (induct_tac k)
+apply (rule_tac [2] poly_divides_trans)
+apply (auto simp add: divides_def)
+apply (rule_tac x = p in exI)
+apply (auto simp add: poly_mult fun_eq mult_ac)
+done
+
+lemma (in recpower_comm_semiring_1) poly_exp_divides: "[| (p %^ n) divides q; m\<le>n |] ==> (p %^ m) divides q"
+by (blast intro: poly_divides_exp poly_divides_trans)
+
+lemma (in comm_semiring_0) poly_divides_add:
+ "[| p divides q; p divides r |] ==> p divides (q +++ r)"
+apply (simp add: divides_def, auto)
+apply (rule_tac x = "padd qa qaa" in exI)
+apply (auto simp add: poly_add fun_eq poly_mult right_distrib)
+done
+
+lemma (in comm_ring_1) poly_divides_diff:
+ "[| p divides q; p divides (q +++ r) |] ==> p divides r"
+apply (simp add: divides_def, auto)
+apply (rule_tac x = "padd qaa (poly_minus qa)" in exI)
+apply (auto simp add: poly_add fun_eq poly_mult poly_minus right_diff_distrib compare_rls add_ac)
+done
+
+lemma (in comm_ring_1) poly_divides_diff2: "[| p divides r; p divides (q +++ r) |] ==> p divides q"
+apply (erule poly_divides_diff)
+apply (auto simp add: poly_add fun_eq poly_mult divides_def add_ac)
+done
+
+lemma (in semiring_0) poly_divides_zero: "poly p = poly [] ==> q divides p"
+apply (simp add: divides_def)
+apply (rule exI[where x="[]"])
+apply (auto simp add: fun_eq poly_mult)
+done
+
+lemma (in semiring_0) poly_divides_zero2[simp]: "q divides []"
+apply (simp add: divides_def)
+apply (rule_tac x = "[]" in exI)
+apply (auto simp add: fun_eq)
+done
+
+text{*At last, we can consider the order of a root.*}
+
+lemma (in idom_char_0) poly_order_exists_lemma:
+ assumes lp: "length p = d" and p: "poly p \<noteq> poly []"
+ shows "\<exists>n q. p = mulexp n [-a, 1] q \<and> poly q a \<noteq> 0"
+using lp p
+proof(induct d arbitrary: p)
+ case 0 thus ?case by simp
+next
+ case (Suc n p)
+ {assume p0: "poly p a = 0"
+ from Suc.prems have h: "length p = Suc n" "poly p \<noteq> poly []" by auto
+ hence pN: "p \<noteq> []" by auto
+ from p0[unfolded poly_linear_divides] pN obtain q where
+ q: "p = [-a, 1] *** q" by blast
+ from q h p0 have qh: "length q = n" "poly q \<noteq> poly []"
+ apply -
+ apply simp
+ apply (simp only: fun_eq)
+ apply (rule ccontr)
+ apply (simp add: fun_eq poly_add poly_cmult minus_mult_left[symmetric])
+ done
+ from Suc.hyps[OF qh] obtain m r where
+ mr: "q = mulexp m [-a,1] r" "poly r a \<noteq> 0" by blast
+ from mr q have "p = mulexp (Suc m) [-a,1] r \<and> poly r a \<noteq> 0" by simp
+ hence ?case by blast}
+ moreover
+ {assume p0: "poly p a \<noteq> 0"
+ hence ?case using Suc.prems apply simp by (rule exI[where x="0::nat"], simp)}
+ ultimately show ?case by blast
+qed
+
+
+lemma (in recpower_comm_semiring_1) poly_mulexp: "poly (mulexp n p q) x = (poly p x) ^ n * poly q x"
+by(induct n, auto simp add: poly_mult power_Suc mult_ac)
+
+lemma (in comm_semiring_1) divides_left_mult:
+ assumes d:"(p***q) divides r" shows "p divides r \<and> q divides r"
+proof-
+ from d obtain t where r:"poly r = poly (p***q *** t)"
+ unfolding divides_def by blast
+ hence "poly r = poly (p *** (q *** t))"
+ "poly r = poly (q *** (p***t))" by(auto simp add: fun_eq poly_mult mult_ac)
+ thus ?thesis unfolding divides_def by blast
+qed
+
+
+
+(* FIXME: Tidy up *)
+
+lemma (in recpower_semiring_1)
+ zero_power_iff: "0 ^ n = (if n = 0 then 1 else 0)"
+ by (induct n, simp_all add: power_Suc)
+
+lemma (in recpower_idom_char_0) poly_order_exists:
+ assumes lp: "length p = d" and p0: "poly p \<noteq> poly []"
+ shows "\<exists>n. ([-a, 1] %^ n) divides p & ~(([-a, 1] %^ (Suc n)) divides p)"
+proof-
+let ?poly = poly
+let ?mulexp = mulexp
+let ?pexp = pexp
+from lp p0
+show ?thesis
+apply -
+apply (drule poly_order_exists_lemma [where a=a], assumption, clarify)
+apply (rule_tac x = n in exI, safe)
+apply (unfold divides_def)
+apply (rule_tac x = q in exI)
+apply (induct_tac "n", simp)
+apply (simp (no_asm_simp) add: poly_add poly_cmult poly_mult right_distrib mult_ac)
+apply safe
+apply (subgoal_tac "?poly (?mulexp n [uminus a, one] q) \<noteq> ?poly (pmult (?pexp [uminus a, one] (Suc n)) qa)")
+apply simp
+apply (induct_tac "n")
+apply (simp del: pmult_Cons pexp_Suc)
+apply (erule_tac Q = "?poly q a = zero" in contrapos_np)
+apply (simp add: poly_add poly_cmult minus_mult_left[symmetric])
+apply (rule pexp_Suc [THEN ssubst])
+apply (rule ccontr)
+apply (simp add: poly_mult_left_cancel poly_mult_assoc del: pmult_Cons pexp_Suc)
+done
+qed
+
+
+lemma (in semiring_1) poly_one_divides[simp]: "[1] divides p"
+by (simp add: divides_def, auto)
+
+lemma (in recpower_idom_char_0) poly_order: "poly p \<noteq> poly []
+ ==> EX! n. ([-a, 1] %^ n) divides p &
+ ~(([-a, 1] %^ (Suc n)) divides p)"
+apply (auto intro: poly_order_exists simp add: less_linear simp del: pmult_Cons pexp_Suc)
+apply (cut_tac x = y and y = n in less_linear)
+apply (drule_tac m = n in poly_exp_divides)
+apply (auto dest: Suc_le_eq [THEN iffD2, THEN [2] poly_exp_divides]
+ simp del: pmult_Cons pexp_Suc)
+done
+
+text{*Order*}
+
+lemma some1_equalityD: "[| n = (@n. P n); EX! n. P n |] ==> P n"
+by (blast intro: someI2)
+
+lemma (in recpower_idom_char_0) order:
+ "(([-a, 1] %^ n) divides p &
+ ~(([-a, 1] %^ (Suc n)) divides p)) =
+ ((n = order a p) & ~(poly p = poly []))"
+apply (unfold order_def)
+apply (rule iffI)
+apply (blast dest: poly_divides_zero intro!: some1_equality [symmetric] poly_order)
+apply (blast intro!: poly_order [THEN [2] some1_equalityD])
+done
+
+lemma (in recpower_idom_char_0) order2: "[| poly p \<noteq> poly [] |]
+ ==> ([-a, 1] %^ (order a p)) divides p &
+ ~(([-a, 1] %^ (Suc(order a p))) divides p)"
+by (simp add: order del: pexp_Suc)
+
+lemma (in recpower_idom_char_0) order_unique: "[| poly p \<noteq> poly []; ([-a, 1] %^ n) divides p;
+ ~(([-a, 1] %^ (Suc n)) divides p)
+ |] ==> (n = order a p)"
+by (insert order [of a n p], auto)
+
+lemma (in recpower_idom_char_0) order_unique_lemma: "(poly p \<noteq> poly [] & ([-a, 1] %^ n) divides p &
+ ~(([-a, 1] %^ (Suc n)) divides p))
+ ==> (n = order a p)"
+by (blast intro: order_unique)
+
+lemma (in ring_1) order_poly: "poly p = poly q ==> order a p = order a q"
+by (auto simp add: fun_eq divides_def poly_mult order_def)
+
+lemma (in semiring_1) pexp_one[simp]: "p %^ (Suc 0) = p"
+apply (induct "p")
+apply (auto simp add: numeral_1_eq_1)
+done
+
+lemma (in comm_ring_1) lemma_order_root:
+ " 0 < n & [- a, 1] %^ n divides p & ~ [- a, 1] %^ (Suc n) divides p
+ \<Longrightarrow> poly p a = 0"
+apply (induct n arbitrary: a p, blast)
+apply (auto simp add: divides_def poly_mult simp del: pmult_Cons)
+done
+
+lemma (in recpower_idom_char_0) order_root: "(poly p a = 0) = ((poly p = poly []) | order a p \<noteq> 0)"
+proof-
+ let ?poly = poly
+ show ?thesis
+apply (case_tac "?poly p = ?poly []", auto)
+apply (simp add: poly_linear_divides del: pmult_Cons, safe)
+apply (drule_tac [!] a = a in order2)
+apply (rule ccontr)
+apply (simp add: divides_def poly_mult fun_eq del: pmult_Cons, blast)
+using neq0_conv
+apply (blast intro: lemma_order_root)
+done
+qed
+
+lemma (in recpower_idom_char_0) order_divides: "(([-a, 1] %^ n) divides p) = ((poly p = poly []) | n \<le> order a p)"
+proof-
+ let ?poly = poly
+ show ?thesis
+apply (case_tac "?poly p = ?poly []", auto)
+apply (simp add: divides_def fun_eq poly_mult)
+apply (rule_tac x = "[]" in exI)
+apply (auto dest!: order2 [where a=a]
+ intro: poly_exp_divides simp del: pexp_Suc)
+done
+qed
+
+lemma (in recpower_idom_char_0) order_decomp:
+ "poly p \<noteq> poly []
+ ==> \<exists>q. (poly p = poly (([-a, 1] %^ (order a p)) *** q)) &
+ ~([-a, 1] divides q)"
+apply (unfold divides_def)
+apply (drule order2 [where a = a])
+apply (simp add: divides_def del: pexp_Suc pmult_Cons, safe)
+apply (rule_tac x = q in exI, safe)
+apply (drule_tac x = qa in spec)
+apply (auto simp add: poly_mult fun_eq poly_exp mult_ac simp del: pmult_Cons)
+done
+
+text{*Important composition properties of orders.*}
+lemma order_mult: "poly (p *** q) \<noteq> poly []
+ ==> order a (p *** q) = order a p + order (a::'a::{recpower_idom_char_0}) q"
+apply (cut_tac a = a and p = "p *** q" and n = "order a p + order a q" in order)
+apply (auto simp add: poly_entire simp del: pmult_Cons)
+apply (drule_tac a = a in order2)+
+apply safe
+apply (simp add: divides_def fun_eq poly_exp_add poly_mult del: pmult_Cons, safe)
+apply (rule_tac x = "qa *** qaa" in exI)
+apply (simp add: poly_mult mult_ac del: pmult_Cons)
+apply (drule_tac a = a in order_decomp)+
+apply safe
+apply (subgoal_tac "[-a,1] divides (qa *** qaa) ")
+apply (simp add: poly_primes del: pmult_Cons)
+apply (auto simp add: divides_def simp del: pmult_Cons)
+apply (rule_tac x = qb in exI)
+apply (subgoal_tac "poly ([-a, 1] %^ (order a p) *** (qa *** qaa)) = poly ([-a, 1] %^ (order a p) *** ([-a, 1] *** qb))")
+apply (drule poly_mult_left_cancel [THEN iffD1], force)
+apply (subgoal_tac "poly ([-a, 1] %^ (order a q) *** ([-a, 1] %^ (order a p) *** (qa *** qaa))) = poly ([-a, 1] %^ (order a q) *** ([-a, 1] %^ (order a p) *** ([-a, 1] *** qb))) ")
+apply (drule poly_mult_left_cancel [THEN iffD1], force)
+apply (simp add: fun_eq poly_exp_add poly_mult mult_ac del: pmult_Cons)
+done
+
+lemma (in recpower_idom_char_0) order_mult:
+ assumes pq0: "poly (p *** q) \<noteq> poly []"
+ shows "order a (p *** q) = order a p + order a q"
+proof-
+ let ?order = order
+ let ?divides = "op divides"
+ let ?poly = poly
+from pq0
+show ?thesis
+apply (cut_tac a = a and p = "pmult p q" and n = "?order a p + ?order a q" in order)
+apply (auto simp add: poly_entire simp del: pmult_Cons)
+apply (drule_tac a = a in order2)+
+apply safe
+apply (simp add: divides_def fun_eq poly_exp_add poly_mult del: pmult_Cons, safe)
+apply (rule_tac x = "pmult qa qaa" in exI)
+apply (simp add: poly_mult mult_ac del: pmult_Cons)
+apply (drule_tac a = a in order_decomp)+
+apply safe
+apply (subgoal_tac "?divides [uminus a,one ] (pmult qa qaa) ")
+apply (simp add: poly_primes del: pmult_Cons)
+apply (auto simp add: divides_def simp del: pmult_Cons)
+apply (rule_tac x = qb in exI)
+apply (subgoal_tac "?poly (pmult (pexp [uminus a, one] (?order a p)) (pmult qa qaa)) = ?poly (pmult (pexp [uminus a, one] (?order a p)) (pmult [uminus a, one] qb))")
+apply (drule poly_mult_left_cancel [THEN iffD1], force)
+apply (subgoal_tac "?poly (pmult (pexp [uminus a, one ] (order a q)) (pmult (pexp [uminus a, one] (order a p)) (pmult qa qaa))) = ?poly (pmult (pexp [uminus a, one] (order a q)) (pmult (pexp [uminus a, one] (order a p)) (pmult [uminus a, one] qb))) ")
+apply (drule poly_mult_left_cancel [THEN iffD1], force)
+apply (simp add: fun_eq poly_exp_add poly_mult mult_ac del: pmult_Cons)
+done
+qed
+
+lemma (in recpower_idom_char_0) order_root2: "poly p \<noteq> poly [] ==> (poly p a = 0) = (order a p \<noteq> 0)"
+by (rule order_root [THEN ssubst], auto)
+
+lemma (in semiring_1) pmult_one[simp]: "[1] *** p = p" by auto
+
+lemma (in semiring_0) poly_Nil_zero: "poly [] = poly [0]"
+by (simp add: fun_eq)
+
+lemma (in recpower_idom_char_0) rsquarefree_decomp:
+ "[| rsquarefree p; poly p a = 0 |]
+ ==> \<exists>q. (poly p = poly ([-a, 1] *** q)) & poly q a \<noteq> 0"
+apply (simp add: rsquarefree_def, safe)
+apply (frule_tac a = a in order_decomp)
+apply (drule_tac x = a in spec)
+apply (drule_tac a = a in order_root2 [symmetric])
+apply (auto simp del: pmult_Cons)
+apply (rule_tac x = q in exI, safe)
+apply (simp add: poly_mult fun_eq)
+apply (drule_tac p1 = q in poly_linear_divides [THEN iffD1])
+apply (simp add: divides_def del: pmult_Cons, safe)
+apply (drule_tac x = "[]" in spec)
+apply (auto simp add: fun_eq)
+done
+
+
+text{*Normalization of a polynomial.*}
+
+lemma (in semiring_0) poly_normalize[simp]: "poly (pnormalize p) = poly p"
+apply (induct "p")
+apply (auto simp add: fun_eq)
+done
+
+text{*The degree of a polynomial.*}
+
+lemma (in semiring_0) lemma_degree_zero:
+ "list_all (%c. c = 0) p \<longleftrightarrow> pnormalize p = []"
+by (induct "p", auto)
+
+lemma (in idom_char_0) degree_zero:
+ assumes pN: "poly p = poly []" shows"degree p = 0"
+proof-
+ let ?pn = pnormalize
+ from pN
+ show ?thesis
+ apply (simp add: degree_def)
+ apply (case_tac "?pn p = []")
+ apply (auto simp add: poly_zero lemma_degree_zero )
+ done
+qed
+
+lemma (in semiring_0) pnormalize_sing: "(pnormalize [x] = [x]) \<longleftrightarrow> x \<noteq> 0" by simp
+lemma (in semiring_0) pnormalize_pair: "y \<noteq> 0 \<longleftrightarrow> (pnormalize [x, y] = [x, y])" by simp
+lemma (in semiring_0) pnormal_cons: "pnormal p \<Longrightarrow> pnormal (c#p)"
+ unfolding pnormal_def by simp
+lemma (in semiring_0) pnormal_tail: "p\<noteq>[] \<Longrightarrow> pnormal (c#p) \<Longrightarrow> pnormal p"
+ unfolding pnormal_def
+ apply (cases "pnormalize p = []", auto)
+ by (cases "c = 0", auto)
+
+
+lemma (in semiring_0) pnormal_last_nonzero: "pnormal p ==> last p \<noteq> 0"
+proof(induct p)
+ case Nil thus ?case by (simp add: pnormal_def)
+next
+ case (Cons a as) thus ?case
+ apply (simp add: pnormal_def)
+ apply (cases "pnormalize as = []", simp_all)
+ apply (cases "as = []", simp_all)
+ apply (cases "a=0", simp_all)
+ apply (cases "a=0", simp_all)
+ done
+qed
+
+lemma (in semiring_0) pnormal_length: "pnormal p \<Longrightarrow> 0 < length p"
+ unfolding pnormal_def length_greater_0_conv by blast
+
+lemma (in semiring_0) pnormal_last_length: "\<lbrakk>0 < length p ; last p \<noteq> 0\<rbrakk> \<Longrightarrow> pnormal p"
+ apply (induct p, auto)
+ apply (case_tac "p = []", auto)
+ apply (simp add: pnormal_def)
+ by (rule pnormal_cons, auto)
+
+lemma (in semiring_0) pnormal_id: "pnormal p \<longleftrightarrow> (0 < length p \<and> last p \<noteq> 0)"
+ using pnormal_last_length pnormal_length pnormal_last_nonzero by blast
+
+lemma (in idom_char_0) poly_Cons_eq: "poly (c#cs) = poly (d#ds) \<longleftrightarrow> c=d \<and> poly cs = poly ds" (is "?lhs \<longleftrightarrow> ?rhs")
+proof
+ assume eq: ?lhs
+ hence "\<And>x. poly ((c#cs) +++ -- (d#ds)) x = 0"
+ by (simp only: poly_minus poly_add ring_simps) simp
+ hence "poly ((c#cs) +++ -- (d#ds)) = poly []" by - (rule ext, simp)
+ hence "c = d \<and> list_all (\<lambda>x. x=0) ((cs +++ -- ds))"
+ unfolding poly_zero by (simp add: poly_minus_def ring_simps minus_mult_left[symmetric])
+ hence "c = d \<and> (\<forall>x. poly (cs +++ -- ds) x = 0)"
+ unfolding poly_zero[symmetric] by simp
+ thus ?rhs apply (simp add: poly_minus poly_add ring_simps) apply (rule ext, simp) done
+next
+ assume ?rhs then show ?lhs by - (rule ext,simp)
+qed
+
+lemma (in idom_char_0) pnormalize_unique: "poly p = poly q \<Longrightarrow> pnormalize p = pnormalize q"
+proof(induct q arbitrary: p)
+ case Nil thus ?case by (simp only: poly_zero lemma_degree_zero) simp
+next
+ case (Cons c cs p)
+ thus ?case
+ proof(induct p)
+ case Nil
+ hence "poly [] = poly (c#cs)" by blast
+ then have "poly (c#cs) = poly [] " by simp
+ thus ?case by (simp only: poly_zero lemma_degree_zero) simp
+ next
+ case (Cons d ds)
+ hence eq: "poly (d # ds) = poly (c # cs)" by blast
+ hence eq': "\<And>x. poly (d # ds) x = poly (c # cs) x" by simp
+ hence "poly (d # ds) 0 = poly (c # cs) 0" by blast
+ hence dc: "d = c" by auto
+ with eq have "poly ds = poly cs"
+ unfolding poly_Cons_eq by simp
+ with Cons.prems have "pnormalize ds = pnormalize cs" by blast
+ with dc show ?case by simp
+ qed
+qed
+
+lemma (in idom_char_0) degree_unique: assumes pq: "poly p = poly q"
+ shows "degree p = degree q"
+using pnormalize_unique[OF pq] unfolding degree_def by simp
+
+lemma (in semiring_0) pnormalize_length: "length (pnormalize p) \<le> length p" by (induct p, auto)
+
+lemma (in semiring_0) last_linear_mul_lemma:
+ "last ((a %* p) +++ (x#(b %* p))) = (if p=[] then x else b*last p)"
+
+apply (induct p arbitrary: a x b, auto)
+apply (subgoal_tac "padd (cmult aa p) (times b a # cmult b p) \<noteq> []", simp)
+apply (induct_tac p, auto)
+done
+
+lemma (in semiring_1) last_linear_mul: assumes p:"p\<noteq>[]" shows "last ([a,1] *** p) = last p"
+proof-
+ from p obtain c cs where cs: "p = c#cs" by (cases p, auto)
+ from cs have eq:"[a,1] *** p = (a %* (c#cs)) +++ (0#(1 %* (c#cs)))"
+ by (simp add: poly_cmult_distr)
+ show ?thesis using cs
+ unfolding eq last_linear_mul_lemma by simp
+qed
+
+lemma (in semiring_0) pnormalize_eq: "last p \<noteq> 0 \<Longrightarrow> pnormalize p = p"
+ apply (induct p, auto)
+ apply (case_tac p, auto)+
+ done
+
+lemma (in semiring_0) last_pnormalize: "pnormalize p \<noteq> [] \<Longrightarrow> last (pnormalize p) \<noteq> 0"
+ by (induct p, auto)
+
+lemma (in semiring_0) pnormal_degree: "last p \<noteq> 0 \<Longrightarrow> degree p = length p - 1"
+ using pnormalize_eq[of p] unfolding degree_def by simp
+
+lemma (in semiring_0) poly_Nil_ext: "poly [] = (\<lambda>x. 0)" by (rule ext) simp
+
+lemma (in idom_char_0) linear_mul_degree: assumes p: "poly p \<noteq> poly []"
+ shows "degree ([a,1] *** p) = degree p + 1"
+proof-
+ from p have pnz: "pnormalize p \<noteq> []"
+ unfolding poly_zero lemma_degree_zero .
+
+ from last_linear_mul[OF pnz, of a] last_pnormalize[OF pnz]
+ have l0: "last ([a, 1] *** pnormalize p) \<noteq> 0" by simp
+ from last_pnormalize[OF pnz] last_linear_mul[OF pnz, of a]
+ pnormal_degree[OF l0] pnormal_degree[OF last_pnormalize[OF pnz]] pnz
+
+
+ have th: "degree ([a,1] *** pnormalize p) = degree (pnormalize p) + 1"
+ by (auto simp add: poly_length_mult)
+
+ have eqs: "poly ([a,1] *** pnormalize p) = poly ([a,1] *** p)"
+ by (rule ext) (simp add: poly_mult poly_add poly_cmult)
+ from degree_unique[OF eqs] th
+ show ?thesis by (simp add: degree_unique[OF poly_normalize])
+qed
+
+lemma (in idom_char_0) linear_pow_mul_degree:
+ "degree([a,1] %^n *** p) = (if poly p = poly [] then 0 else degree p + n)"
+proof(induct n arbitrary: a p)
+ case (0 a p)
+ {assume p: "poly p = poly []"
+ hence ?case using degree_unique[OF p] by (simp add: degree_def)}
+ moreover
+ {assume p: "poly p \<noteq> poly []" hence ?case by (auto simp add: poly_Nil_ext) }
+ ultimately show ?case by blast
+next
+ case (Suc n a p)
+ have eq: "poly ([a,1] %^(Suc n) *** p) = poly ([a,1] %^ n *** ([a,1] *** p))"
+ apply (rule ext, simp add: poly_mult poly_add poly_cmult)
+ by (simp add: mult_ac add_ac right_distrib)
+ note deq = degree_unique[OF eq]
+ {assume p: "poly p = poly []"
+ with eq have eq': "poly ([a,1] %^(Suc n) *** p) = poly []"
+ by - (rule ext,simp add: poly_mult poly_cmult poly_add)
+ from degree_unique[OF eq'] p have ?case by (simp add: degree_def)}
+ moreover
+ {assume p: "poly p \<noteq> poly []"
+ from p have ap: "poly ([a,1] *** p) \<noteq> poly []"
+ using poly_mult_not_eq_poly_Nil unfolding poly_entire by auto
+ have eq: "poly ([a,1] %^(Suc n) *** p) = poly ([a,1]%^n *** ([a,1] *** p))"
+ by (rule ext, simp add: poly_mult poly_add poly_exp poly_cmult mult_ac add_ac right_distrib)
+ from ap have ap': "(poly ([a,1] *** p) = poly []) = False" by blast
+ have th0: "degree ([a,1]%^n *** ([a,1] *** p)) = degree ([a,1] *** p) + n"
+ apply (simp only: Suc.hyps[of a "pmult [a,one] p"] ap')
+ by simp
+
+ from degree_unique[OF eq] ap p th0 linear_mul_degree[OF p, of a]
+ have ?case by (auto simp del: poly.simps)}
+ ultimately show ?case by blast
+qed
+
+lemma (in recpower_idom_char_0) order_degree:
+ assumes p0: "poly p \<noteq> poly []"
+ shows "order a p \<le> degree p"
+proof-
+ from order2[OF p0, unfolded divides_def]
+ obtain q where q: "poly p = poly ([- a, 1]%^ (order a p) *** q)" by blast
+ {assume "poly q = poly []"
+ with q p0 have False by (simp add: poly_mult poly_entire)}
+ with degree_unique[OF q, unfolded linear_pow_mul_degree]
+ show ?thesis by auto
+qed
+
+text{*Tidier versions of finiteness of roots.*}
+
+lemma (in idom_char_0) poly_roots_finite_set: "poly p \<noteq> poly [] ==> finite {x. poly p x = 0}"
+unfolding poly_roots_finite .
+
+text{*bound for polynomial.*}
+
+lemma poly_mono: "abs(x) \<le> k ==> abs(poly p (x::'a::{ordered_idom})) \<le> poly (map abs p) k"
+apply (induct "p", auto)
+apply (rule_tac y = "abs a + abs (x * poly p x)" in order_trans)
+apply (rule abs_triangle_ineq)
+apply (auto intro!: mult_mono simp add: abs_mult)
+done
+
+lemma (in semiring_0) poly_Sing: "poly [c] x = c" by simp
+
+end
--- a/src/HOL/List.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/List.thy Fri Jan 16 13:07:44 2009 -0800
@@ -547,9 +547,9 @@
lemma append_Nil2 [simp]: "xs @ [] = xs"
by (induct xs) auto
-class_interpretation semigroup_append: semigroup_add ["op @"]
+interpretation semigroup_append!: semigroup_add "op @"
proof qed simp
-class_interpretation monoid_append: monoid_add ["[]" "op @"]
+interpretation monoid_append!: monoid_add "[]" "op @"
proof qed simp+
lemma append_is_Nil_conv [iff]: "(xs @ ys = []) = (xs = [] \<and> ys = [])"
--- a/src/HOL/MetisExamples/BT.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/MetisExamples/BT.thy Fri Jan 16 13:07:44 2009 -0800
@@ -84,7 +84,7 @@
lemma depth_reflect: "depth (reflect t) = depth t"
apply (induct t)
apply (metis depth.simps(1) reflect.simps(1))
- apply (metis depth.simps(2) min_max.less_eq_less_sup.sup_commute reflect.simps(2))
+ apply (metis depth.simps(2) min_max.sup_commute reflect.simps(2))
done
text {*
--- a/src/HOL/MetisExamples/BigO.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/MetisExamples/BigO.thy Fri Jan 16 13:07:44 2009 -0800
@@ -1,5 +1,4 @@
(* Title: HOL/MetisExamples/BigO.thy
- ID: $Id$
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
Testing the metis method
@@ -13,9 +12,7 @@
subsection {* Definitions *}
-constdefs
-
- bigo :: "('a => 'b::ordered_idom) => ('a => 'b) set" ("(1O'(_'))")
+definition bigo :: "('a => 'b::ordered_idom) => ('a => 'b) set" ("(1O'(_'))") where
"O(f::('a => 'b)) == {h. EX c. ALL x. abs (h x) <= c * abs (f x)}"
ML_command{*AtpWrapper.problem_name := "BigO__bigo_pos_const"*}
@@ -362,7 +359,7 @@
apply (rule add_mono)
ML_command{*AtpWrapper.problem_name := "BigO__bigo_plus_eq_simpler"*}
(*Found by SPASS; SLOW*)
-apply (metis le_maxI2 linorder_linear linorder_not_le min_max.less_eq_less_sup.sup_absorb1 mult_le_cancel_right order_trans)
+apply (metis le_maxI2 linorder_linear linorder_not_le min_max.sup_absorb1 mult_le_cancel_right order_trans)
apply (metis le_maxI2 linorder_not_le mult_le_cancel_right order_trans)
done
@@ -1164,7 +1161,7 @@
(*sledgehammer*);
apply (case_tac "0 <= k x - g x")
prefer 2 (*re-order subgoals because I don't know what to put after a structured proof*)
- apply (metis abs_ge_zero abs_minus_commute linorder_linear min_max.less_eq_less_sup.sup_absorb1 min_max.less_eq_less_sup.sup_commute)
+ apply (metis abs_ge_zero abs_minus_commute linorder_linear min_max.sup_absorb1 min_max.sup_commute)
proof (neg_clausify)
fix x
assume 0: "\<And>A. k A \<le> f A"
@@ -1174,16 +1171,16 @@
have 3: "\<not> k x - g x < (0\<Colon>'b)"
by (metis 2 linorder_not_less)
have 4: "\<And>X1 X2. min X1 (k X2) \<le> f X2"
- by (metis min_max.less_eq_less_inf.inf_le2 min_max.less_eq_less_inf.le_inf_iff min_max.less_eq_less_inf.le_iff_inf 0)
+ by (metis min_max.inf_le2 min_max.le_inf_iff min_max.le_iff_inf 0)
have 5: "\<bar>g x - f x\<bar> = f x - g x"
- by (metis abs_minus_commute combine_common_factor mult_zero_right minus_add_cancel minus_zero abs_if diff_less_eq min_max.less_eq_less_inf.inf_commute 4 linorder_not_le min_max.less_eq_less_inf.le_iff_inf 3 diff_less_0_iff_less linorder_not_less)
+ by (metis abs_minus_commute combine_common_factor mult_zero_right minus_add_cancel minus_zero abs_if diff_less_eq min_max.inf_commute 4 linorder_not_le min_max.le_iff_inf 3 diff_less_0_iff_less linorder_not_less)
have 6: "max (0\<Colon>'b) (k x - g x) = k x - g x"
- by (metis min_max.less_eq_less_sup.le_iff_sup 2)
+ by (metis min_max.le_iff_sup 2)
assume 7: "\<not> max (k x - g x) (0\<Colon>'b) \<le> \<bar>f x - g x\<bar>"
have 8: "\<not> k x - g x \<le> f x - g x"
- by (metis 5 abs_minus_commute 7 min_max.less_eq_less_sup.sup_commute 6)
+ by (metis 5 abs_minus_commute 7 min_max.sup_commute 6)
show "False"
- by (metis min_max.less_eq_less_sup.sup_commute min_max.less_eq_less_inf.inf_commute min_max.less_eq_less_inf_sup.sup_inf_absorb min_max.less_eq_less_inf.le_iff_inf 0 max_diff_distrib_left 1 linorder_not_le 8)
+ by (metis min_max.sup_commute min_max.inf_commute min_max.sup_inf_absorb min_max.le_iff_inf 0 max_diff_distrib_left 1 linorder_not_le 8)
qed
ML_command{*AtpWrapper.problem_name := "BigO__bigo_lesso3"*}
@@ -1206,7 +1203,7 @@
ML_command{*AtpWrapper.problem_name := "BigO__bigo_lesso3_simpler"*}
apply (metis diff_less_0_iff_less linorder_not_le not_leE uminus_add_conv_diff xt1(12) xt1(6))
apply (metis add_minus_cancel diff_le_eq le_diff_eq uminus_add_conv_diff)
-apply (metis abs_ge_zero linorder_linear min_max.less_eq_less_sup.sup_absorb1 min_max.less_eq_less_sup.sup_commute)
+apply (metis abs_ge_zero linorder_linear min_max.sup_absorb1 min_max.sup_commute)
done
lemma bigo_lesso4: "f <o g =o O(k::'a=>'b::ordered_field) ==>
--- a/src/HOL/Statespace/StateSpaceEx.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/Statespace/StateSpaceEx.thy Fri Jan 16 13:07:44 2009 -0800
@@ -41,7 +41,7 @@
projection~/ injection functions that convert from abstract values to
@{typ "nat"} and @{text "bool"}. The logical content of the locale is: *}
-class_locale vars' =
+locale vars' =
fixes n::'name and b::'name
assumes "distinct [n, b]"
--- a/src/HOL/Univ_Poly.thy Thu Jan 15 14:33:38 2009 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1050 +0,0 @@
-(* Title: Univ_Poly.thy
- Author: Amine Chaieb
-*)
-
-header {* Univariate Polynomials *}
-
-theory Univ_Poly
-imports Plain List
-begin
-
-text{* Application of polynomial as a function. *}
-
-primrec (in semiring_0) poly :: "'a list => 'a => 'a" where
- poly_Nil: "poly [] x = 0"
-| poly_Cons: "poly (h#t) x = h + x * poly t x"
-
-
-subsection{*Arithmetic Operations on Polynomials*}
-
-text{*addition*}
-
-primrec (in semiring_0) padd :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" (infixl "+++" 65)
-where
- padd_Nil: "[] +++ l2 = l2"
-| padd_Cons: "(h#t) +++ l2 = (if l2 = [] then h#t
- else (h + hd l2)#(t +++ tl l2))"
-
-text{*Multiplication by a constant*}
-primrec (in semiring_0) cmult :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list" (infixl "%*" 70) where
- cmult_Nil: "c %* [] = []"
-| cmult_Cons: "c %* (h#t) = (c * h)#(c %* t)"
-
-text{*Multiplication by a polynomial*}
-primrec (in semiring_0) pmult :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" (infixl "***" 70)
-where
- pmult_Nil: "[] *** l2 = []"
-| pmult_Cons: "(h#t) *** l2 = (if t = [] then h %* l2
- else (h %* l2) +++ ((0) # (t *** l2)))"
-
-text{*Repeated multiplication by a polynomial*}
-primrec (in semiring_0) mulexp :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where
- mulexp_zero: "mulexp 0 p q = q"
-| mulexp_Suc: "mulexp (Suc n) p q = p *** mulexp n p q"
-
-text{*Exponential*}
-primrec (in semiring_1) pexp :: "'a list \<Rightarrow> nat \<Rightarrow> 'a list" (infixl "%^" 80) where
- pexp_0: "p %^ 0 = [1]"
-| pexp_Suc: "p %^ (Suc n) = p *** (p %^ n)"
-
-text{*Quotient related value of dividing a polynomial by x + a*}
-(* Useful for divisor properties in inductive proofs *)
-primrec (in field) "pquot" :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a list" where
- pquot_Nil: "pquot [] a= []"
-| pquot_Cons: "pquot (h#t) a = (if t = [] then [h]
- else (inverse(a) * (h - hd( pquot t a)))#(pquot t a))"
-
-text{*normalization of polynomials (remove extra 0 coeff)*}
-primrec (in semiring_0) pnormalize :: "'a list \<Rightarrow> 'a list" where
- pnormalize_Nil: "pnormalize [] = []"
-| pnormalize_Cons: "pnormalize (h#p) = (if ( (pnormalize p) = [])
- then (if (h = 0) then [] else [h])
- else (h#(pnormalize p)))"
-
-definition (in semiring_0) "pnormal p = ((pnormalize p = p) \<and> p \<noteq> [])"
-definition (in semiring_0) "nonconstant p = (pnormal p \<and> (\<forall>x. p \<noteq> [x]))"
-text{*Other definitions*}
-
-definition (in ring_1)
- poly_minus :: "'a list => 'a list" ("-- _" [80] 80) where
- "-- p = (- 1) %* p"
-
-definition (in semiring_0)
- divides :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infixl "divides" 70) where
- [code del]: "p1 divides p2 = (\<exists>q. poly p2 = poly(p1 *** q))"
-
- --{*order of a polynomial*}
-definition (in ring_1) order :: "'a => 'a list => nat" where
- "order a p = (SOME n. ([-a, 1] %^ n) divides p &
- ~ (([-a, 1] %^ (Suc n)) divides p))"
-
- --{*degree of a polynomial*}
-definition (in semiring_0) degree :: "'a list => nat" where
- "degree p = length (pnormalize p) - 1"
-
- --{*squarefree polynomials --- NB with respect to real roots only.*}
-definition (in ring_1)
- rsquarefree :: "'a list => bool" where
- "rsquarefree p = (poly p \<noteq> poly [] &
- (\<forall>a. (order a p = 0) | (order a p = 1)))"
-
-context semiring_0
-begin
-
-lemma padd_Nil2[simp]: "p +++ [] = p"
-by (induct p) auto
-
-lemma padd_Cons_Cons: "(h1 # p1) +++ (h2 # p2) = (h1 + h2) # (p1 +++ p2)"
-by auto
-
-lemma pminus_Nil[simp]: "-- [] = []"
-by (simp add: poly_minus_def)
-
-lemma pmult_singleton: "[h1] *** p1 = h1 %* p1" by simp
-end
-
-lemma (in semiring_1) poly_ident_mult[simp]: "1 %* t = t" by (induct "t", auto)
-
-lemma (in semiring_0) poly_simple_add_Cons[simp]: "[a] +++ ((0)#t) = (a#t)"
-by simp
-
-text{*Handy general properties*}
-
-lemma (in comm_semiring_0) padd_commut: "b +++ a = a +++ b"
-proof(induct b arbitrary: a)
- case Nil thus ?case by auto
-next
- case (Cons b bs a) thus ?case by (cases a, simp_all add: add_commute)
-qed
-
-lemma (in comm_semiring_0) padd_assoc: "\<forall>b c. (a +++ b) +++ c = a +++ (b +++ c)"
-apply (induct a arbitrary: b c)
-apply (simp, clarify)
-apply (case_tac b, simp_all add: add_ac)
-done
-
-lemma (in semiring_0) poly_cmult_distr: "a %* ( p +++ q) = (a %* p +++ a %* q)"
-apply (induct p arbitrary: q,simp)
-apply (case_tac q, simp_all add: right_distrib)
-done
-
-lemma (in ring_1) pmult_by_x[simp]: "[0, 1] *** t = ((0)#t)"
-apply (induct "t", simp)
-apply (auto simp add: mult_zero_left poly_ident_mult padd_commut)
-apply (case_tac t, auto)
-done
-
-text{*properties of evaluation of polynomials.*}
-
-lemma (in semiring_0) poly_add: "poly (p1 +++ p2) x = poly p1 x + poly p2 x"
-proof(induct p1 arbitrary: p2)
- case Nil thus ?case by simp
-next
- case (Cons a as p2) thus ?case
- by (cases p2, simp_all add: add_ac right_distrib)
-qed
-
-lemma (in comm_semiring_0) poly_cmult: "poly (c %* p) x = c * poly p x"
-apply (induct "p")
-apply (case_tac [2] "x=zero")
-apply (auto simp add: right_distrib mult_ac)
-done
-
-lemma (in comm_semiring_0) poly_cmult_map: "poly (map (op * c) p) x = c*poly p x"
- by (induct p, auto simp add: right_distrib mult_ac)
-
-lemma (in comm_ring_1) poly_minus: "poly (-- p) x = - (poly p x)"
-apply (simp add: poly_minus_def)
-apply (auto simp add: poly_cmult minus_mult_left[symmetric])
-done
-
-lemma (in comm_semiring_0) poly_mult: "poly (p1 *** p2) x = poly p1 x * poly p2 x"
-proof(induct p1 arbitrary: p2)
- case Nil thus ?case by simp
-next
- case (Cons a as p2)
- thus ?case by (cases as,
- simp_all add: poly_cmult poly_add left_distrib right_distrib mult_ac)
-qed
-
-class recpower_semiring = semiring + recpower
-class recpower_semiring_1 = semiring_1 + recpower
-class recpower_semiring_0 = semiring_0 + recpower
-class recpower_ring = ring + recpower
-class recpower_ring_1 = ring_1 + recpower
-subclass (in recpower_ring_1) recpower_ring ..
-class recpower_comm_semiring_1 = recpower + comm_semiring_1
-class recpower_comm_ring_1 = recpower + comm_ring_1
-subclass (in recpower_comm_ring_1) recpower_comm_semiring_1 ..
-class recpower_idom = recpower + idom
-subclass (in recpower_idom) recpower_comm_ring_1 ..
-class idom_char_0 = idom + ring_char_0
-class recpower_idom_char_0 = recpower + idom_char_0
-subclass (in recpower_idom_char_0) recpower_idom ..
-
-lemma (in recpower_comm_ring_1) poly_exp: "poly (p %^ n) x = (poly p x) ^ n"
-apply (induct "n")
-apply (auto simp add: poly_cmult poly_mult power_Suc)
-done
-
-text{*More Polynomial Evaluation Lemmas*}
-
-lemma (in semiring_0) poly_add_rzero[simp]: "poly (a +++ []) x = poly a x"
-by simp
-
-lemma (in comm_semiring_0) poly_mult_assoc: "poly ((a *** b) *** c) x = poly (a *** (b *** c)) x"
- by (simp add: poly_mult mult_assoc)
-
-lemma (in semiring_0) poly_mult_Nil2[simp]: "poly (p *** []) x = 0"
-by (induct "p", auto)
-
-lemma (in comm_semiring_1) poly_exp_add: "poly (p %^ (n + d)) x = poly( p %^ n *** p %^ d) x"
-apply (induct "n")
-apply (auto simp add: poly_mult mult_assoc)
-done
-
-subsection{*Key Property: if @{term "f(a) = 0"} then @{term "(x - a)"} divides
- @{term "p(x)"} *}
-
-lemma (in comm_ring_1) lemma_poly_linear_rem: "\<forall>h. \<exists>q r. h#t = [r] +++ [-a, 1] *** q"
-proof(induct t)
- case Nil
- {fix h have "[h] = [h] +++ [- a, 1] *** []" by simp}
- thus ?case by blast
-next
- case (Cons x xs)
- {fix h
- from Cons.hyps[rule_format, of x]
- obtain q r where qr: "x#xs = [r] +++ [- a, 1] *** q" by blast
- have "h#x#xs = [a*r + h] +++ [-a, 1] *** (r#q)"
- using qr by(cases q, simp_all add: ring_simps diff_def[symmetric]
- minus_mult_left[symmetric] right_minus)
- hence "\<exists>q r. h#x#xs = [r] +++ [-a, 1] *** q" by blast}
- thus ?case by blast
-qed
-
-lemma (in comm_ring_1) poly_linear_rem: "\<exists>q r. h#t = [r] +++ [-a, 1] *** q"
-by (cut_tac t = t and a = a in lemma_poly_linear_rem, auto)
-
-
-lemma (in comm_ring_1) poly_linear_divides: "(poly p a = 0) = ((p = []) | (\<exists>q. p = [-a, 1] *** q))"
-proof-
- {assume p: "p = []" hence ?thesis by simp}
- moreover
- {fix x xs assume p: "p = x#xs"
- {fix q assume "p = [-a, 1] *** q" hence "poly p a = 0"
- by (simp add: poly_add poly_cmult minus_mult_left[symmetric])}
- moreover
- {assume p0: "poly p a = 0"
- from poly_linear_rem[of x xs a] obtain q r
- where qr: "x#xs = [r] +++ [- a, 1] *** q" by blast
- have "r = 0" using p0 by (simp only: p qr poly_mult poly_add) simp
- hence "\<exists>q. p = [- a, 1] *** q" using p qr apply - apply (rule exI[where x=q])apply auto apply (cases q) apply auto done}
- ultimately have ?thesis using p by blast}
- ultimately show ?thesis by (cases p, auto)
-qed
-
-lemma (in semiring_0) lemma_poly_length_mult[simp]: "\<forall>h k a. length (k %* p +++ (h # (a %* p))) = Suc (length p)"
-by (induct "p", auto)
-
-lemma (in semiring_0) lemma_poly_length_mult2[simp]: "\<forall>h k. length (k %* p +++ (h # p)) = Suc (length p)"
-by (induct "p", auto)
-
-lemma (in ring_1) poly_length_mult[simp]: "length([-a,1] *** q) = Suc (length q)"
-by auto
-
-subsection{*Polynomial length*}
-
-lemma (in semiring_0) poly_cmult_length[simp]: "length (a %* p) = length p"
-by (induct "p", auto)
-
-lemma (in semiring_0) poly_add_length: "length (p1 +++ p2) = max (length p1) (length p2)"
-apply (induct p1 arbitrary: p2, simp_all)
-apply arith
-done
-
-lemma (in semiring_0) poly_root_mult_length[simp]: "length([a,b] *** p) = Suc (length p)"
-by (simp add: poly_add_length)
-
-lemma (in idom) poly_mult_not_eq_poly_Nil[simp]:
- "poly (p *** q) x \<noteq> poly [] x \<longleftrightarrow> poly p x \<noteq> poly [] x \<and> poly q x \<noteq> poly [] x"
-by (auto simp add: poly_mult)
-
-lemma (in idom) poly_mult_eq_zero_disj: "poly (p *** q) x = 0 \<longleftrightarrow> poly p x = 0 \<or> poly q x = 0"
-by (auto simp add: poly_mult)
-
-text{*Normalisation Properties*}
-
-lemma (in semiring_0) poly_normalized_nil: "(pnormalize p = []) --> (poly p x = 0)"
-by (induct "p", auto)
-
-text{*A nontrivial polynomial of degree n has no more than n roots*}
-lemma (in idom) poly_roots_index_lemma:
- assumes p: "poly p x \<noteq> poly [] x" and n: "length p = n"
- shows "\<exists>i. \<forall>x. poly p x = 0 \<longrightarrow> (\<exists>m\<le>n. x = i m)"
- using p n
-proof(induct n arbitrary: p x)
- case 0 thus ?case by simp
-next
- case (Suc n p x)
- {assume C: "\<And>i. \<exists>x. poly p x = 0 \<and> (\<forall>m\<le>Suc n. x \<noteq> i m)"
- from Suc.prems have p0: "poly p x \<noteq> 0" "p\<noteq> []" by auto
- from p0(1)[unfolded poly_linear_divides[of p x]]
- have "\<forall>q. p \<noteq> [- x, 1] *** q" by blast
- from C obtain a where a: "poly p a = 0" by blast
- from a[unfolded poly_linear_divides[of p a]] p0(2)
- obtain q where q: "p = [-a, 1] *** q" by blast
- have lg: "length q = n" using q Suc.prems(2) by simp
- from q p0 have qx: "poly q x \<noteq> poly [] x"
- by (auto simp add: poly_mult poly_add poly_cmult)
- from Suc.hyps[OF qx lg] obtain i where
- i: "\<forall>x. poly q x = 0 \<longrightarrow> (\<exists>m\<le>n. x = i m)" by blast
- let ?i = "\<lambda>m. if m = Suc n then a else i m"
- from C[of ?i] obtain y where y: "poly p y = 0" "\<forall>m\<le> Suc n. y \<noteq> ?i m"
- by blast
- from y have "y = a \<or> poly q y = 0"
- by (simp only: q poly_mult_eq_zero_disj poly_add) (simp add: ring_simps)
- with i[rule_format, of y] y(1) y(2) have False apply auto
- apply (erule_tac x="m" in allE)
- apply auto
- done}
- thus ?case by blast
-qed
-
-
-lemma (in idom) poly_roots_index_length: "poly p x \<noteq> poly [] x ==>
- \<exists>i. \<forall>x. (poly p x = 0) --> (\<exists>n. n \<le> length p & x = i n)"
-by (blast intro: poly_roots_index_lemma)
-
-lemma (in idom) poly_roots_finite_lemma1: "poly p x \<noteq> poly [] x ==>
- \<exists>N i. \<forall>x. (poly p x = 0) --> (\<exists>n. (n::nat) < N & x = i n)"
-apply (drule poly_roots_index_length, safe)
-apply (rule_tac x = "Suc (length p)" in exI)
-apply (rule_tac x = i in exI)
-apply (simp add: less_Suc_eq_le)
-done
-
-
-lemma (in idom) idom_finite_lemma:
- assumes P: "\<forall>x. P x --> (\<exists>n. n < length j & x = j!n)"
- shows "finite {x. P x}"
-proof-
- let ?M = "{x. P x}"
- let ?N = "set j"
- have "?M \<subseteq> ?N" using P by auto
- thus ?thesis using finite_subset by auto
-qed
-
-
-lemma (in idom) poly_roots_finite_lemma2: "poly p x \<noteq> poly [] x ==>
- \<exists>i. \<forall>x. (poly p x = 0) --> x \<in> set i"
-apply (drule poly_roots_index_length, safe)
-apply (rule_tac x="map (\<lambda>n. i n) [0 ..< Suc (length p)]" in exI)
-apply (auto simp add: image_iff)
-apply (erule_tac x="x" in allE, clarsimp)
-by (case_tac "n=length p", auto simp add: order_le_less)
-
-lemma UNIV_nat_infinite: "\<not> finite (UNIV :: nat set)"
- unfolding finite_conv_nat_seg_image
-proof(auto simp add: expand_set_eq image_iff)
- fix n::nat and f:: "nat \<Rightarrow> nat"
- let ?N = "{i. i < n}"
- let ?fN = "f ` ?N"
- let ?y = "Max ?fN + 1"
- from nat_seg_image_imp_finite[of "?fN" "f" n]
- have thfN: "finite ?fN" by simp
- {assume "n =0" hence "\<exists>x. \<forall>xa<n. x \<noteq> f xa" by auto}
- moreover
- {assume nz: "n \<noteq> 0"
- hence thne: "?fN \<noteq> {}" by (auto simp add: neq0_conv)
- have "\<forall>x\<in> ?fN. Max ?fN \<ge> x" using nz Max_ge_iff[OF thfN thne] by auto
- hence "\<forall>x\<in> ?fN. ?y > x" by auto
- hence "?y \<notin> ?fN" by auto
- hence "\<exists>x. \<forall>xa<n. x \<noteq> f xa" by auto }
- ultimately show "\<exists>x. \<forall>xa<n. x \<noteq> f xa" by blast
-qed
-
-lemma (in ring_char_0) UNIV_ring_char_0_infinte:
- "\<not> (finite (UNIV:: 'a set))"
-proof
- assume F: "finite (UNIV :: 'a set)"
- have "finite (UNIV :: nat set)"
- proof (rule finite_imageD)
- have "of_nat ` UNIV \<subseteq> UNIV" by simp
- then show "finite (of_nat ` UNIV :: 'a set)" using F by (rule finite_subset)
- show "inj (of_nat :: nat \<Rightarrow> 'a)" by (simp add: inj_on_def)
- qed
- with UNIV_nat_infinite show False ..
-qed
-
-lemma (in idom_char_0) poly_roots_finite: "(poly p \<noteq> poly []) =
- finite {x. poly p x = 0}"
-proof
- assume H: "poly p \<noteq> poly []"
- show "finite {x. poly p x = (0::'a)}"
- using H
- apply -
- apply (erule contrapos_np, rule ext)
- apply (rule ccontr)
- apply (clarify dest!: poly_roots_finite_lemma2)
- using finite_subset
- proof-
- fix x i
- assume F: "\<not> finite {x. poly p x = (0\<Colon>'a)}"
- and P: "\<forall>x. poly p x = (0\<Colon>'a) \<longrightarrow> x \<in> set i"
- let ?M= "{x. poly p x = (0\<Colon>'a)}"
- from P have "?M \<subseteq> set i" by auto
- with finite_subset F show False by auto
- qed
-next
- assume F: "finite {x. poly p x = (0\<Colon>'a)}"
- show "poly p \<noteq> poly []" using F UNIV_ring_char_0_infinte by auto
-qed
-
-text{*Entirety and Cancellation for polynomials*}
-
-lemma (in idom_char_0) poly_entire_lemma2:
- assumes p0: "poly p \<noteq> poly []" and q0: "poly q \<noteq> poly []"
- shows "poly (p***q) \<noteq> poly []"
-proof-
- let ?S = "\<lambda>p. {x. poly p x = 0}"
- have "?S (p *** q) = ?S p \<union> ?S q" by (auto simp add: poly_mult)
- with p0 q0 show ?thesis unfolding poly_roots_finite by auto
-qed
-
-lemma (in idom_char_0) poly_entire:
- "poly (p *** q) = poly [] \<longleftrightarrow> poly p = poly [] \<or> poly q = poly []"
-using poly_entire_lemma2[of p q]
-by auto (rule ext, simp add: poly_mult)+
-
-lemma (in idom_char_0) poly_entire_neg: "(poly (p *** q) \<noteq> poly []) = ((poly p \<noteq> poly []) & (poly q \<noteq> poly []))"
-by (simp add: poly_entire)
-
-lemma fun_eq: " (f = g) = (\<forall>x. f x = g x)"
-by (auto intro!: ext)
-
-lemma (in comm_ring_1) poly_add_minus_zero_iff: "(poly (p +++ -- q) = poly []) = (poly p = poly q)"
-by (auto simp add: ring_simps poly_add poly_minus_def fun_eq poly_cmult minus_mult_left[symmetric])
-
-lemma (in comm_ring_1) poly_add_minus_mult_eq: "poly (p *** q +++ --(p *** r)) = poly (p *** (q +++ -- r))"
-by (auto simp add: poly_add poly_minus_def fun_eq poly_mult poly_cmult right_distrib minus_mult_left[symmetric] minus_mult_right[symmetric])
-
-subclass (in idom_char_0) comm_ring_1 ..
-lemma (in idom_char_0) poly_mult_left_cancel: "(poly (p *** q) = poly (p *** r)) = (poly p = poly [] | poly q = poly r)"
-proof-
- have "poly (p *** q) = poly (p *** r) \<longleftrightarrow> poly (p *** q +++ -- (p *** r)) = poly []" by (simp only: poly_add_minus_zero_iff)
- also have "\<dots> \<longleftrightarrow> poly p = poly [] | poly q = poly r"
- by (auto intro: ext simp add: poly_add_minus_mult_eq poly_entire poly_add_minus_zero_iff)
- finally show ?thesis .
-qed
-
-lemma (in recpower_idom) poly_exp_eq_zero[simp]:
- "(poly (p %^ n) = poly []) = (poly p = poly [] & n \<noteq> 0)"
-apply (simp only: fun_eq add: all_simps [symmetric])
-apply (rule arg_cong [where f = All])
-apply (rule ext)
-apply (induct n)
-apply (auto simp add: poly_exp poly_mult)
-done
-
-lemma (in semiring_1) one_neq_zero[simp]: "1 \<noteq> 0" using zero_neq_one by blast
-lemma (in comm_ring_1) poly_prime_eq_zero[simp]: "poly [a,1] \<noteq> poly []"
-apply (simp add: fun_eq)
-apply (rule_tac x = "minus one a" in exI)
-apply (unfold diff_minus)
-apply (subst add_commute)
-apply (subst add_assoc)
-apply simp
-done
-
-lemma (in recpower_idom) poly_exp_prime_eq_zero: "(poly ([a, 1] %^ n) \<noteq> poly [])"
-by auto
-
-text{*A more constructive notion of polynomials being trivial*}
-
-lemma (in idom_char_0) poly_zero_lemma': "poly (h # t) = poly [] ==> h = 0 & poly t = poly []"
-apply(simp add: fun_eq)
-apply (case_tac "h = zero")
-apply (drule_tac [2] x = zero in spec, auto)
-apply (cases "poly t = poly []", simp)
-proof-
- fix x
- assume H: "\<forall>x. x = (0\<Colon>'a) \<or> poly t x = (0\<Colon>'a)" and pnz: "poly t \<noteq> poly []"
- let ?S = "{x. poly t x = 0}"
- from H have "\<forall>x. x \<noteq>0 \<longrightarrow> poly t x = 0" by blast
- hence th: "?S \<supseteq> UNIV - {0}" by auto
- from poly_roots_finite pnz have th': "finite ?S" by blast
- from finite_subset[OF th th'] UNIV_ring_char_0_infinte
- show "poly t x = (0\<Colon>'a)" by simp
- qed
-
-lemma (in idom_char_0) poly_zero: "(poly p = poly []) = list_all (%c. c = 0) p"
-apply (induct "p", simp)
-apply (rule iffI)
-apply (drule poly_zero_lemma', auto)
-done
-
-lemma (in idom_char_0) poly_0: "list_all (\<lambda>c. c = 0) p \<Longrightarrow> poly p x = 0"
- unfolding poly_zero[symmetric] by simp
-
-
-
-text{*Basics of divisibility.*}
-
-lemma (in idom) poly_primes: "([a, 1] divides (p *** q)) = ([a, 1] divides p | [a, 1] divides q)"
-apply (auto simp add: divides_def fun_eq poly_mult poly_add poly_cmult left_distrib [symmetric])
-apply (drule_tac x = "uminus a" in spec)
-apply (simp add: poly_linear_divides poly_add poly_cmult left_distrib [symmetric])
-apply (cases "p = []")
-apply (rule exI[where x="[]"])
-apply simp
-apply (cases "q = []")
-apply (erule allE[where x="[]"], simp)
-
-apply clarsimp
-apply (cases "\<exists>q\<Colon>'a list. p = a %* q +++ ((0\<Colon>'a) # q)")
-apply (clarsimp simp add: poly_add poly_cmult)
-apply (rule_tac x="qa" in exI)
-apply (simp add: left_distrib [symmetric])
-apply clarsimp
-
-apply (auto simp add: right_minus poly_linear_divides poly_add poly_cmult left_distrib [symmetric])
-apply (rule_tac x = "pmult qa q" in exI)
-apply (rule_tac [2] x = "pmult p qa" in exI)
-apply (auto simp add: poly_add poly_mult poly_cmult mult_ac)
-done
-
-lemma (in comm_semiring_1) poly_divides_refl[simp]: "p divides p"
-apply (simp add: divides_def)
-apply (rule_tac x = "[one]" in exI)
-apply (auto simp add: poly_mult fun_eq)
-done
-
-lemma (in comm_semiring_1) poly_divides_trans: "[| p divides q; q divides r |] ==> p divides r"
-apply (simp add: divides_def, safe)
-apply (rule_tac x = "pmult qa qaa" in exI)
-apply (auto simp add: poly_mult fun_eq mult_assoc)
-done
-
-
-lemma (in recpower_comm_semiring_1) poly_divides_exp: "m \<le> n ==> (p %^ m) divides (p %^ n)"
-apply (auto simp add: le_iff_add)
-apply (induct_tac k)
-apply (rule_tac [2] poly_divides_trans)
-apply (auto simp add: divides_def)
-apply (rule_tac x = p in exI)
-apply (auto simp add: poly_mult fun_eq mult_ac)
-done
-
-lemma (in recpower_comm_semiring_1) poly_exp_divides: "[| (p %^ n) divides q; m\<le>n |] ==> (p %^ m) divides q"
-by (blast intro: poly_divides_exp poly_divides_trans)
-
-lemma (in comm_semiring_0) poly_divides_add:
- "[| p divides q; p divides r |] ==> p divides (q +++ r)"
-apply (simp add: divides_def, auto)
-apply (rule_tac x = "padd qa qaa" in exI)
-apply (auto simp add: poly_add fun_eq poly_mult right_distrib)
-done
-
-lemma (in comm_ring_1) poly_divides_diff:
- "[| p divides q; p divides (q +++ r) |] ==> p divides r"
-apply (simp add: divides_def, auto)
-apply (rule_tac x = "padd qaa (poly_minus qa)" in exI)
-apply (auto simp add: poly_add fun_eq poly_mult poly_minus right_diff_distrib compare_rls add_ac)
-done
-
-lemma (in comm_ring_1) poly_divides_diff2: "[| p divides r; p divides (q +++ r) |] ==> p divides q"
-apply (erule poly_divides_diff)
-apply (auto simp add: poly_add fun_eq poly_mult divides_def add_ac)
-done
-
-lemma (in semiring_0) poly_divides_zero: "poly p = poly [] ==> q divides p"
-apply (simp add: divides_def)
-apply (rule exI[where x="[]"])
-apply (auto simp add: fun_eq poly_mult)
-done
-
-lemma (in semiring_0) poly_divides_zero2[simp]: "q divides []"
-apply (simp add: divides_def)
-apply (rule_tac x = "[]" in exI)
-apply (auto simp add: fun_eq)
-done
-
-text{*At last, we can consider the order of a root.*}
-
-lemma (in idom_char_0) poly_order_exists_lemma:
- assumes lp: "length p = d" and p: "poly p \<noteq> poly []"
- shows "\<exists>n q. p = mulexp n [-a, 1] q \<and> poly q a \<noteq> 0"
-using lp p
-proof(induct d arbitrary: p)
- case 0 thus ?case by simp
-next
- case (Suc n p)
- {assume p0: "poly p a = 0"
- from Suc.prems have h: "length p = Suc n" "poly p \<noteq> poly []" by auto
- hence pN: "p \<noteq> []" by auto
- from p0[unfolded poly_linear_divides] pN obtain q where
- q: "p = [-a, 1] *** q" by blast
- from q h p0 have qh: "length q = n" "poly q \<noteq> poly []"
- apply -
- apply simp
- apply (simp only: fun_eq)
- apply (rule ccontr)
- apply (simp add: fun_eq poly_add poly_cmult minus_mult_left[symmetric])
- done
- from Suc.hyps[OF qh] obtain m r where
- mr: "q = mulexp m [-a,1] r" "poly r a \<noteq> 0" by blast
- from mr q have "p = mulexp (Suc m) [-a,1] r \<and> poly r a \<noteq> 0" by simp
- hence ?case by blast}
- moreover
- {assume p0: "poly p a \<noteq> 0"
- hence ?case using Suc.prems apply simp by (rule exI[where x="0::nat"], simp)}
- ultimately show ?case by blast
-qed
-
-
-lemma (in recpower_comm_semiring_1) poly_mulexp: "poly (mulexp n p q) x = (poly p x) ^ n * poly q x"
-by(induct n, auto simp add: poly_mult power_Suc mult_ac)
-
-lemma (in comm_semiring_1) divides_left_mult:
- assumes d:"(p***q) divides r" shows "p divides r \<and> q divides r"
-proof-
- from d obtain t where r:"poly r = poly (p***q *** t)"
- unfolding divides_def by blast
- hence "poly r = poly (p *** (q *** t))"
- "poly r = poly (q *** (p***t))" by(auto simp add: fun_eq poly_mult mult_ac)
- thus ?thesis unfolding divides_def by blast
-qed
-
-
-
-(* FIXME: Tidy up *)
-
-lemma (in recpower_semiring_1)
- zero_power_iff: "0 ^ n = (if n = 0 then 1 else 0)"
- by (induct n, simp_all add: power_Suc)
-
-lemma (in recpower_idom_char_0) poly_order_exists:
- assumes lp: "length p = d" and p0: "poly p \<noteq> poly []"
- shows "\<exists>n. ([-a, 1] %^ n) divides p & ~(([-a, 1] %^ (Suc n)) divides p)"
-proof-
-let ?poly = poly
-let ?mulexp = mulexp
-let ?pexp = pexp
-from lp p0
-show ?thesis
-apply -
-apply (drule poly_order_exists_lemma [where a=a], assumption, clarify)
-apply (rule_tac x = n in exI, safe)
-apply (unfold divides_def)
-apply (rule_tac x = q in exI)
-apply (induct_tac "n", simp)
-apply (simp (no_asm_simp) add: poly_add poly_cmult poly_mult right_distrib mult_ac)
-apply safe
-apply (subgoal_tac "?poly (?mulexp n [uminus a, one] q) \<noteq> ?poly (pmult (?pexp [uminus a, one] (Suc n)) qa)")
-apply simp
-apply (induct_tac "n")
-apply (simp del: pmult_Cons pexp_Suc)
-apply (erule_tac Q = "?poly q a = zero" in contrapos_np)
-apply (simp add: poly_add poly_cmult minus_mult_left[symmetric])
-apply (rule pexp_Suc [THEN ssubst])
-apply (rule ccontr)
-apply (simp add: poly_mult_left_cancel poly_mult_assoc del: pmult_Cons pexp_Suc)
-done
-qed
-
-
-lemma (in semiring_1) poly_one_divides[simp]: "[1] divides p"
-by (simp add: divides_def, auto)
-
-lemma (in recpower_idom_char_0) poly_order: "poly p \<noteq> poly []
- ==> EX! n. ([-a, 1] %^ n) divides p &
- ~(([-a, 1] %^ (Suc n)) divides p)"
-apply (auto intro: poly_order_exists simp add: less_linear simp del: pmult_Cons pexp_Suc)
-apply (cut_tac x = y and y = n in less_linear)
-apply (drule_tac m = n in poly_exp_divides)
-apply (auto dest: Suc_le_eq [THEN iffD2, THEN [2] poly_exp_divides]
- simp del: pmult_Cons pexp_Suc)
-done
-
-text{*Order*}
-
-lemma some1_equalityD: "[| n = (@n. P n); EX! n. P n |] ==> P n"
-by (blast intro: someI2)
-
-lemma (in recpower_idom_char_0) order:
- "(([-a, 1] %^ n) divides p &
- ~(([-a, 1] %^ (Suc n)) divides p)) =
- ((n = order a p) & ~(poly p = poly []))"
-apply (unfold order_def)
-apply (rule iffI)
-apply (blast dest: poly_divides_zero intro!: some1_equality [symmetric] poly_order)
-apply (blast intro!: poly_order [THEN [2] some1_equalityD])
-done
-
-lemma (in recpower_idom_char_0) order2: "[| poly p \<noteq> poly [] |]
- ==> ([-a, 1] %^ (order a p)) divides p &
- ~(([-a, 1] %^ (Suc(order a p))) divides p)"
-by (simp add: order del: pexp_Suc)
-
-lemma (in recpower_idom_char_0) order_unique: "[| poly p \<noteq> poly []; ([-a, 1] %^ n) divides p;
- ~(([-a, 1] %^ (Suc n)) divides p)
- |] ==> (n = order a p)"
-by (insert order [of a n p], auto)
-
-lemma (in recpower_idom_char_0) order_unique_lemma: "(poly p \<noteq> poly [] & ([-a, 1] %^ n) divides p &
- ~(([-a, 1] %^ (Suc n)) divides p))
- ==> (n = order a p)"
-by (blast intro: order_unique)
-
-lemma (in ring_1) order_poly: "poly p = poly q ==> order a p = order a q"
-by (auto simp add: fun_eq divides_def poly_mult order_def)
-
-lemma (in semiring_1) pexp_one[simp]: "p %^ (Suc 0) = p"
-apply (induct "p")
-apply (auto simp add: numeral_1_eq_1)
-done
-
-lemma (in comm_ring_1) lemma_order_root:
- " 0 < n & [- a, 1] %^ n divides p & ~ [- a, 1] %^ (Suc n) divides p
- \<Longrightarrow> poly p a = 0"
-apply (induct n arbitrary: a p, blast)
-apply (auto simp add: divides_def poly_mult simp del: pmult_Cons)
-done
-
-lemma (in recpower_idom_char_0) order_root: "(poly p a = 0) = ((poly p = poly []) | order a p \<noteq> 0)"
-proof-
- let ?poly = poly
- show ?thesis
-apply (case_tac "?poly p = ?poly []", auto)
-apply (simp add: poly_linear_divides del: pmult_Cons, safe)
-apply (drule_tac [!] a = a in order2)
-apply (rule ccontr)
-apply (simp add: divides_def poly_mult fun_eq del: pmult_Cons, blast)
-using neq0_conv
-apply (blast intro: lemma_order_root)
-done
-qed
-
-lemma (in recpower_idom_char_0) order_divides: "(([-a, 1] %^ n) divides p) = ((poly p = poly []) | n \<le> order a p)"
-proof-
- let ?poly = poly
- show ?thesis
-apply (case_tac "?poly p = ?poly []", auto)
-apply (simp add: divides_def fun_eq poly_mult)
-apply (rule_tac x = "[]" in exI)
-apply (auto dest!: order2 [where a=a]
- intro: poly_exp_divides simp del: pexp_Suc)
-done
-qed
-
-lemma (in recpower_idom_char_0) order_decomp:
- "poly p \<noteq> poly []
- ==> \<exists>q. (poly p = poly (([-a, 1] %^ (order a p)) *** q)) &
- ~([-a, 1] divides q)"
-apply (unfold divides_def)
-apply (drule order2 [where a = a])
-apply (simp add: divides_def del: pexp_Suc pmult_Cons, safe)
-apply (rule_tac x = q in exI, safe)
-apply (drule_tac x = qa in spec)
-apply (auto simp add: poly_mult fun_eq poly_exp mult_ac simp del: pmult_Cons)
-done
-
-text{*Important composition properties of orders.*}
-lemma order_mult: "poly (p *** q) \<noteq> poly []
- ==> order a (p *** q) = order a p + order (a::'a::{recpower_idom_char_0}) q"
-apply (cut_tac a = a and p = "p *** q" and n = "order a p + order a q" in order)
-apply (auto simp add: poly_entire simp del: pmult_Cons)
-apply (drule_tac a = a in order2)+
-apply safe
-apply (simp add: divides_def fun_eq poly_exp_add poly_mult del: pmult_Cons, safe)
-apply (rule_tac x = "qa *** qaa" in exI)
-apply (simp add: poly_mult mult_ac del: pmult_Cons)
-apply (drule_tac a = a in order_decomp)+
-apply safe
-apply (subgoal_tac "[-a,1] divides (qa *** qaa) ")
-apply (simp add: poly_primes del: pmult_Cons)
-apply (auto simp add: divides_def simp del: pmult_Cons)
-apply (rule_tac x = qb in exI)
-apply (subgoal_tac "poly ([-a, 1] %^ (order a p) *** (qa *** qaa)) = poly ([-a, 1] %^ (order a p) *** ([-a, 1] *** qb))")
-apply (drule poly_mult_left_cancel [THEN iffD1], force)
-apply (subgoal_tac "poly ([-a, 1] %^ (order a q) *** ([-a, 1] %^ (order a p) *** (qa *** qaa))) = poly ([-a, 1] %^ (order a q) *** ([-a, 1] %^ (order a p) *** ([-a, 1] *** qb))) ")
-apply (drule poly_mult_left_cancel [THEN iffD1], force)
-apply (simp add: fun_eq poly_exp_add poly_mult mult_ac del: pmult_Cons)
-done
-
-lemma (in recpower_idom_char_0) order_mult:
- assumes pq0: "poly (p *** q) \<noteq> poly []"
- shows "order a (p *** q) = order a p + order a q"
-proof-
- let ?order = order
- let ?divides = "op divides"
- let ?poly = poly
-from pq0
-show ?thesis
-apply (cut_tac a = a and p = "pmult p q" and n = "?order a p + ?order a q" in order)
-apply (auto simp add: poly_entire simp del: pmult_Cons)
-apply (drule_tac a = a in order2)+
-apply safe
-apply (simp add: divides_def fun_eq poly_exp_add poly_mult del: pmult_Cons, safe)
-apply (rule_tac x = "pmult qa qaa" in exI)
-apply (simp add: poly_mult mult_ac del: pmult_Cons)
-apply (drule_tac a = a in order_decomp)+
-apply safe
-apply (subgoal_tac "?divides [uminus a,one ] (pmult qa qaa) ")
-apply (simp add: poly_primes del: pmult_Cons)
-apply (auto simp add: divides_def simp del: pmult_Cons)
-apply (rule_tac x = qb in exI)
-apply (subgoal_tac "?poly (pmult (pexp [uminus a, one] (?order a p)) (pmult qa qaa)) = ?poly (pmult (pexp [uminus a, one] (?order a p)) (pmult [uminus a, one] qb))")
-apply (drule poly_mult_left_cancel [THEN iffD1], force)
-apply (subgoal_tac "?poly (pmult (pexp [uminus a, one ] (order a q)) (pmult (pexp [uminus a, one] (order a p)) (pmult qa qaa))) = ?poly (pmult (pexp [uminus a, one] (order a q)) (pmult (pexp [uminus a, one] (order a p)) (pmult [uminus a, one] qb))) ")
-apply (drule poly_mult_left_cancel [THEN iffD1], force)
-apply (simp add: fun_eq poly_exp_add poly_mult mult_ac del: pmult_Cons)
-done
-qed
-
-lemma (in recpower_idom_char_0) order_root2: "poly p \<noteq> poly [] ==> (poly p a = 0) = (order a p \<noteq> 0)"
-by (rule order_root [THEN ssubst], auto)
-
-lemma (in semiring_1) pmult_one[simp]: "[1] *** p = p" by auto
-
-lemma (in semiring_0) poly_Nil_zero: "poly [] = poly [0]"
-by (simp add: fun_eq)
-
-lemma (in recpower_idom_char_0) rsquarefree_decomp:
- "[| rsquarefree p; poly p a = 0 |]
- ==> \<exists>q. (poly p = poly ([-a, 1] *** q)) & poly q a \<noteq> 0"
-apply (simp add: rsquarefree_def, safe)
-apply (frule_tac a = a in order_decomp)
-apply (drule_tac x = a in spec)
-apply (drule_tac a = a in order_root2 [symmetric])
-apply (auto simp del: pmult_Cons)
-apply (rule_tac x = q in exI, safe)
-apply (simp add: poly_mult fun_eq)
-apply (drule_tac p1 = q in poly_linear_divides [THEN iffD1])
-apply (simp add: divides_def del: pmult_Cons, safe)
-apply (drule_tac x = "[]" in spec)
-apply (auto simp add: fun_eq)
-done
-
-
-text{*Normalization of a polynomial.*}
-
-lemma (in semiring_0) poly_normalize[simp]: "poly (pnormalize p) = poly p"
-apply (induct "p")
-apply (auto simp add: fun_eq)
-done
-
-text{*The degree of a polynomial.*}
-
-lemma (in semiring_0) lemma_degree_zero:
- "list_all (%c. c = 0) p \<longleftrightarrow> pnormalize p = []"
-by (induct "p", auto)
-
-lemma (in idom_char_0) degree_zero:
- assumes pN: "poly p = poly []" shows"degree p = 0"
-proof-
- let ?pn = pnormalize
- from pN
- show ?thesis
- apply (simp add: degree_def)
- apply (case_tac "?pn p = []")
- apply (auto simp add: poly_zero lemma_degree_zero )
- done
-qed
-
-lemma (in semiring_0) pnormalize_sing: "(pnormalize [x] = [x]) \<longleftrightarrow> x \<noteq> 0" by simp
-lemma (in semiring_0) pnormalize_pair: "y \<noteq> 0 \<longleftrightarrow> (pnormalize [x, y] = [x, y])" by simp
-lemma (in semiring_0) pnormal_cons: "pnormal p \<Longrightarrow> pnormal (c#p)"
- unfolding pnormal_def by simp
-lemma (in semiring_0) pnormal_tail: "p\<noteq>[] \<Longrightarrow> pnormal (c#p) \<Longrightarrow> pnormal p"
- unfolding pnormal_def
- apply (cases "pnormalize p = []", auto)
- by (cases "c = 0", auto)
-
-
-lemma (in semiring_0) pnormal_last_nonzero: "pnormal p ==> last p \<noteq> 0"
-proof(induct p)
- case Nil thus ?case by (simp add: pnormal_def)
-next
- case (Cons a as) thus ?case
- apply (simp add: pnormal_def)
- apply (cases "pnormalize as = []", simp_all)
- apply (cases "as = []", simp_all)
- apply (cases "a=0", simp_all)
- apply (cases "a=0", simp_all)
- done
-qed
-
-lemma (in semiring_0) pnormal_length: "pnormal p \<Longrightarrow> 0 < length p"
- unfolding pnormal_def length_greater_0_conv by blast
-
-lemma (in semiring_0) pnormal_last_length: "\<lbrakk>0 < length p ; last p \<noteq> 0\<rbrakk> \<Longrightarrow> pnormal p"
- apply (induct p, auto)
- apply (case_tac "p = []", auto)
- apply (simp add: pnormal_def)
- by (rule pnormal_cons, auto)
-
-lemma (in semiring_0) pnormal_id: "pnormal p \<longleftrightarrow> (0 < length p \<and> last p \<noteq> 0)"
- using pnormal_last_length pnormal_length pnormal_last_nonzero by blast
-
-lemma (in idom_char_0) poly_Cons_eq: "poly (c#cs) = poly (d#ds) \<longleftrightarrow> c=d \<and> poly cs = poly ds" (is "?lhs \<longleftrightarrow> ?rhs")
-proof
- assume eq: ?lhs
- hence "\<And>x. poly ((c#cs) +++ -- (d#ds)) x = 0"
- by (simp only: poly_minus poly_add ring_simps) simp
- hence "poly ((c#cs) +++ -- (d#ds)) = poly []" by - (rule ext, simp)
- hence "c = d \<and> list_all (\<lambda>x. x=0) ((cs +++ -- ds))"
- unfolding poly_zero by (simp add: poly_minus_def ring_simps minus_mult_left[symmetric])
- hence "c = d \<and> (\<forall>x. poly (cs +++ -- ds) x = 0)"
- unfolding poly_zero[symmetric] by simp
- thus ?rhs apply (simp add: poly_minus poly_add ring_simps) apply (rule ext, simp) done
-next
- assume ?rhs then show ?lhs by - (rule ext,simp)
-qed
-
-lemma (in idom_char_0) pnormalize_unique: "poly p = poly q \<Longrightarrow> pnormalize p = pnormalize q"
-proof(induct q arbitrary: p)
- case Nil thus ?case by (simp only: poly_zero lemma_degree_zero) simp
-next
- case (Cons c cs p)
- thus ?case
- proof(induct p)
- case Nil
- hence "poly [] = poly (c#cs)" by blast
- then have "poly (c#cs) = poly [] " by simp
- thus ?case by (simp only: poly_zero lemma_degree_zero) simp
- next
- case (Cons d ds)
- hence eq: "poly (d # ds) = poly (c # cs)" by blast
- hence eq': "\<And>x. poly (d # ds) x = poly (c # cs) x" by simp
- hence "poly (d # ds) 0 = poly (c # cs) 0" by blast
- hence dc: "d = c" by auto
- with eq have "poly ds = poly cs"
- unfolding poly_Cons_eq by simp
- with Cons.prems have "pnormalize ds = pnormalize cs" by blast
- with dc show ?case by simp
- qed
-qed
-
-lemma (in idom_char_0) degree_unique: assumes pq: "poly p = poly q"
- shows "degree p = degree q"
-using pnormalize_unique[OF pq] unfolding degree_def by simp
-
-lemma (in semiring_0) pnormalize_length: "length (pnormalize p) \<le> length p" by (induct p, auto)
-
-lemma (in semiring_0) last_linear_mul_lemma:
- "last ((a %* p) +++ (x#(b %* p))) = (if p=[] then x else b*last p)"
-
-apply (induct p arbitrary: a x b, auto)
-apply (subgoal_tac "padd (cmult aa p) (times b a # cmult b p) \<noteq> []", simp)
-apply (induct_tac p, auto)
-done
-
-lemma (in semiring_1) last_linear_mul: assumes p:"p\<noteq>[]" shows "last ([a,1] *** p) = last p"
-proof-
- from p obtain c cs where cs: "p = c#cs" by (cases p, auto)
- from cs have eq:"[a,1] *** p = (a %* (c#cs)) +++ (0#(1 %* (c#cs)))"
- by (simp add: poly_cmult_distr)
- show ?thesis using cs
- unfolding eq last_linear_mul_lemma by simp
-qed
-
-lemma (in semiring_0) pnormalize_eq: "last p \<noteq> 0 \<Longrightarrow> pnormalize p = p"
- apply (induct p, auto)
- apply (case_tac p, auto)+
- done
-
-lemma (in semiring_0) last_pnormalize: "pnormalize p \<noteq> [] \<Longrightarrow> last (pnormalize p) \<noteq> 0"
- by (induct p, auto)
-
-lemma (in semiring_0) pnormal_degree: "last p \<noteq> 0 \<Longrightarrow> degree p = length p - 1"
- using pnormalize_eq[of p] unfolding degree_def by simp
-
-lemma (in semiring_0) poly_Nil_ext: "poly [] = (\<lambda>x. 0)" by (rule ext) simp
-
-lemma (in idom_char_0) linear_mul_degree: assumes p: "poly p \<noteq> poly []"
- shows "degree ([a,1] *** p) = degree p + 1"
-proof-
- from p have pnz: "pnormalize p \<noteq> []"
- unfolding poly_zero lemma_degree_zero .
-
- from last_linear_mul[OF pnz, of a] last_pnormalize[OF pnz]
- have l0: "last ([a, 1] *** pnormalize p) \<noteq> 0" by simp
- from last_pnormalize[OF pnz] last_linear_mul[OF pnz, of a]
- pnormal_degree[OF l0] pnormal_degree[OF last_pnormalize[OF pnz]] pnz
-
-
- have th: "degree ([a,1] *** pnormalize p) = degree (pnormalize p) + 1"
- by (auto simp add: poly_length_mult)
-
- have eqs: "poly ([a,1] *** pnormalize p) = poly ([a,1] *** p)"
- by (rule ext) (simp add: poly_mult poly_add poly_cmult)
- from degree_unique[OF eqs] th
- show ?thesis by (simp add: degree_unique[OF poly_normalize])
-qed
-
-lemma (in idom_char_0) linear_pow_mul_degree:
- "degree([a,1] %^n *** p) = (if poly p = poly [] then 0 else degree p + n)"
-proof(induct n arbitrary: a p)
- case (0 a p)
- {assume p: "poly p = poly []"
- hence ?case using degree_unique[OF p] by (simp add: degree_def)}
- moreover
- {assume p: "poly p \<noteq> poly []" hence ?case by (auto simp add: poly_Nil_ext) }
- ultimately show ?case by blast
-next
- case (Suc n a p)
- have eq: "poly ([a,1] %^(Suc n) *** p) = poly ([a,1] %^ n *** ([a,1] *** p))"
- apply (rule ext, simp add: poly_mult poly_add poly_cmult)
- by (simp add: mult_ac add_ac right_distrib)
- note deq = degree_unique[OF eq]
- {assume p: "poly p = poly []"
- with eq have eq': "poly ([a,1] %^(Suc n) *** p) = poly []"
- by - (rule ext,simp add: poly_mult poly_cmult poly_add)
- from degree_unique[OF eq'] p have ?case by (simp add: degree_def)}
- moreover
- {assume p: "poly p \<noteq> poly []"
- from p have ap: "poly ([a,1] *** p) \<noteq> poly []"
- using poly_mult_not_eq_poly_Nil unfolding poly_entire by auto
- have eq: "poly ([a,1] %^(Suc n) *** p) = poly ([a,1]%^n *** ([a,1] *** p))"
- by (rule ext, simp add: poly_mult poly_add poly_exp poly_cmult mult_ac add_ac right_distrib)
- from ap have ap': "(poly ([a,1] *** p) = poly []) = False" by blast
- have th0: "degree ([a,1]%^n *** ([a,1] *** p)) = degree ([a,1] *** p) + n"
- apply (simp only: Suc.hyps[of a "pmult [a,one] p"] ap')
- by simp
-
- from degree_unique[OF eq] ap p th0 linear_mul_degree[OF p, of a]
- have ?case by (auto simp del: poly.simps)}
- ultimately show ?case by blast
-qed
-
-lemma (in recpower_idom_char_0) order_degree:
- assumes p0: "poly p \<noteq> poly []"
- shows "order a p \<le> degree p"
-proof-
- from order2[OF p0, unfolded divides_def]
- obtain q where q: "poly p = poly ([- a, 1]%^ (order a p) *** q)" by blast
- {assume "poly q = poly []"
- with q p0 have False by (simp add: poly_mult poly_entire)}
- with degree_unique[OF q, unfolded linear_pow_mul_degree]
- show ?thesis by auto
-qed
-
-text{*Tidier versions of finiteness of roots.*}
-
-lemma (in idom_char_0) poly_roots_finite_set: "poly p \<noteq> poly [] ==> finite {x. poly p x = 0}"
-unfolding poly_roots_finite .
-
-text{*bound for polynomial.*}
-
-lemma poly_mono: "abs(x) \<le> k ==> abs(poly p (x::'a::{ordered_idom})) \<le> poly (map abs p) k"
-apply (induct "p", auto)
-apply (rule_tac y = "abs a + abs (x * poly p x)" in order_trans)
-apply (rule abs_triangle_ineq)
-apply (auto intro!: mult_mono simp add: abs_mult)
-done
-
-lemma (in semiring_0) poly_Sing: "poly [c] x = c" by simp
-
-end
--- a/src/HOL/Word/WordArith.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOL/Word/WordArith.thy Fri Jan 16 13:07:44 2009 -0800
@@ -22,7 +22,7 @@
proof
qed (unfold word_sle_def word_sless_def, auto)
-class_interpretation signed: linorder ["word_sle" "word_sless"]
+interpretation signed!: linorder "word_sle" "word_sless"
by (rule signed_linorder)
lemmas word_arith_wis =
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/HOL/base.ML Fri Jan 16 13:07:44 2009 -0800
@@ -0,0 +1,2 @@
+(*side-entry for HOL-Base*)
+use_thy "Code_Setup";
--- a/src/HOLCF/CompactBasis.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOLCF/CompactBasis.thy Fri Jan 16 13:07:44 2009 -0800
@@ -244,7 +244,7 @@
assumes "ab_semigroup_idem_mult f"
shows "fold_pd g f (PDPlus t u) = f (fold_pd g f t) (fold_pd g f u)"
proof -
- class_interpret ab_semigroup_idem_mult [f] by fact
+ interpret ab_semigroup_idem_mult f by fact
show ?thesis unfolding fold_pd_def Rep_PDPlus by (simp add: image_Un fold1_Un2)
qed
--- a/src/HOLCF/ConvexPD.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOLCF/ConvexPD.thy Fri Jan 16 13:07:44 2009 -0800
@@ -296,9 +296,8 @@
apply (simp add: PDPlus_absorb)
done
-class_interpretation aci_convex_plus: ab_semigroup_idem_mult ["op +\<natural>"]
- by unfold_locales
- (rule convex_plus_assoc convex_plus_commute convex_plus_absorb)+
+interpretation aci_convex_plus!: ab_semigroup_idem_mult "op +\<natural>"
+ proof qed (rule convex_plus_assoc convex_plus_commute convex_plus_absorb)+
lemma convex_plus_left_commute: "xs +\<natural> (ys +\<natural> zs) = ys +\<natural> (xs +\<natural> zs)"
by (rule aci_convex_plus.mult_left_commute)
--- a/src/HOLCF/HOLCF.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOLCF/HOLCF.thy Fri Jan 16 13:07:44 2009 -0800
@@ -17,7 +17,6 @@
"Tools/domain/domain_theorems.ML"
"Tools/domain/domain_extender.ML"
"Tools/adm_tac.ML"
-
begin
defaultsort pcpo
--- a/src/HOLCF/LowerPD.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOLCF/LowerPD.thy Fri Jan 16 13:07:44 2009 -0800
@@ -250,9 +250,8 @@
apply (simp add: PDPlus_absorb)
done
-class_interpretation aci_lower_plus: ab_semigroup_idem_mult ["op +\<flat>"]
- by unfold_locales
- (rule lower_plus_assoc lower_plus_commute lower_plus_absorb)+
+interpretation aci_lower_plus!: ab_semigroup_idem_mult "op +\<flat>"
+ proof qed (rule lower_plus_assoc lower_plus_commute lower_plus_absorb)+
lemma lower_plus_left_commute: "xs +\<flat> (ys +\<flat> zs) = ys +\<flat> (xs +\<flat> zs)"
by (rule aci_lower_plus.mult_left_commute)
--- a/src/HOLCF/UpperPD.thy Thu Jan 15 14:33:38 2009 -0800
+++ b/src/HOLCF/UpperPD.thy Fri Jan 16 13:07:44 2009 -0800
@@ -248,9 +248,8 @@
apply (simp add: PDPlus_absorb)
done
-class_interpretation aci_upper_plus: ab_semigroup_idem_mult ["op +\<sharp>"]
- by unfold_locales
- (rule upper_plus_assoc upper_plus_commute upper_plus_absorb)+
+interpretation aci_upper_plus!: ab_semigroup_idem_mult "op +\<sharp>"
+ proof qed (rule upper_plus_assoc upper_plus_commute upper_plus_absorb)+
lemma upper_plus_left_commute: "xs +\<sharp> (ys +\<sharp> zs) = ys +\<sharp> (xs +\<sharp> zs)"
by (rule aci_upper_plus.mult_left_commute)
--- a/src/Pure/Isar/class.ML Thu Jan 15 14:33:38 2009 -0800
+++ b/src/Pure/Isar/class.ML Fri Jan 16 13:07:44 2009 -0800
@@ -27,9 +27,9 @@
(** rule calculation **)
fun calculate_axiom thy sups base_sort assm_axiom param_map class =
- case Old_Locale.intros thy class
- of (_, []) => assm_axiom
- | (_, [intro]) =>
+ case Locale.intros_of thy class
+ of (_, NONE) => assm_axiom
+ | (_, SOME intro) =>
let
fun instantiate thy sort = Thm.instantiate ([pairself (Thm.ctyp_of thy o TVar o pair (Name.aT, 0))
(base_sort, sort)], map (fn (v, (c, ty)) => pairself (Thm.cterm_of thy)
@@ -45,23 +45,22 @@
|> SOME
end;
-fun raw_morphism thy class param_map some_axiom =
+fun raw_morphism thy class sups param_map some_axiom =
let
val ctxt = ProofContext.init thy;
- val some_wit = case some_axiom
- of SOME axiom => SOME (Element.prove_witness ctxt
- (Logic.unvarify (Thm.prop_of axiom))
- (ALLGOALS (ProofContext.fact_tac [axiom])))
- | NONE => NONE;
- val instT = Symtab.empty |> Symtab.update ("'a", TFree ("'a", [class]));
- val inst = Symtab.make ((map o apsnd) Const param_map);
- in case some_wit
- of SOME wit => Element.inst_morphism thy (instT, inst)
- $> Morphism.binding_morphism (Binding.add_prefix false (class_prefix class))
- $> Element.satisfy_morphism [wit]
- | NONE => Element.inst_morphism thy (instT, inst)
- $> Morphism.binding_morphism (Binding.add_prefix false (class_prefix class))
- end;
+ val (([props], [(_, morph1)], export_morph), _) = ctxt
+ |> Expression.cert_goal_expression ([(class, (("", false),
+ Expression.Named ((map o apsnd) Const param_map)))], []);
+ val morph2 = morph1
+ $> Morphism.binding_morphism (Binding.add_prefix false (class_prefix class));
+ val morph3 = case props
+ of [prop] => morph2
+ $> Element.satisfy_morphism [(Element.prove_witness ctxt prop
+ (ALLGOALS (ProofContext.fact_tac (the_list some_axiom))))]
+ | [] => morph2;
+ (*FIXME generic amend operation for classes*)
+ val morph4 = morph3 $> eq_morph thy (these_defs thy sups);
+ in (morph4, export_morph) end;
fun calculate_rules thy morph sups base_sort param_map axiom class =
let
@@ -70,19 +69,18 @@
(Var ((v, 0), map_atyps (fn _ => TVar ((Name.aT, 0), sort)) ty),
Const (c, map_atyps (fn _ => TVar ((Name.aT, 0), sort)) ty))) param_map);
val defs = these_defs thy sups;
- val assm_intro = Old_Locale.intros thy class
+ val assm_intro = Locale.intros_of thy class
|> fst
- |> map (instantiate thy base_sort)
- |> map (MetaSimplifier.rewrite_rule defs)
- |> map Thm.close_derivation
- |> try the_single;
+ |> Option.map (instantiate thy base_sort)
+ |> Option.map (MetaSimplifier.rewrite_rule defs)
+ |> Option.map Thm.close_derivation;
val fixate = Thm.instantiate
(map (pairself (Thm.ctyp_of thy)) [(TVar ((Name.aT, 0), []), TFree (Name.aT, base_sort)),
(TVar ((Name.aT, 0), base_sort), TFree (Name.aT, base_sort))], [])
val of_class_sups = if null sups
then map (fixate o Thm.class_triv thy) base_sort
else map (fixate o snd o rules thy) sups;
- val locale_dests = map Drule.standard' (Old_Locale.dests thy class);
+ val locale_dests = map Drule.standard' (Locale.axioms_of thy class);
val num_trivs = case length locale_dests
of 0 => if is_none axiom then 0 else 1
| n => n;
@@ -110,55 +108,54 @@
local
-fun gen_class_spec prep_class process_expr thy raw_supclasses raw_elems =
+fun gen_class_spec prep_class process_decl thy raw_supclasses raw_elems =
let
val supclasses = map (prep_class thy) raw_supclasses;
val supsort = Sign.minimize_sort thy supclasses;
val sups = filter (is_class thy) supsort;
- val supparam_names = map fst (these_params thy sups);
+ val base_sort = if null sups then supsort else
+ foldr1 (Sorts.inter_sort (Sign.classes_of thy))
+ (map (base_sort thy) sups);
+ val supparams = (map o apsnd) (snd o snd) (these_params thy sups);
+ val supparam_names = map fst supparams;
val _ = if has_duplicates (op =) supparam_names
then error ("Duplicate parameter(s) in superclasses: "
^ (commas o map quote o duplicates (op =)) supparam_names)
else ();
- val base_sort = if null sups then supsort else
- foldr1 (Sorts.inter_sort (Sign.classes_of thy))
- (map (base_sort thy) sups);
- val suplocales = map Old_Locale.Locale sups;
- val supexpr = Old_Locale.Merge suplocales;
- val supparams = (map fst o Old_Locale.parameters_of_expr thy) supexpr;
- val mergeexpr = Old_Locale.Merge suplocales;
+
+ val supexpr = (map (fn sup => (sup, (("", false), Expression.Positional [])))
+ sups, []);
val constrain = Element.Constrains ((map o apsnd o map_atyps)
(K (TFree (Name.aT, base_sort))) supparams);
+ (*FIXME perhaps better: control type variable by explicit
+ parameter instantiation of import expression*)
+ val begin_ctxt = begin sups base_sort
+ #> fold (Variable.declare_constraints o Free) ((map o apsnd o map_atyps)
+ (K (TFree (Name.aT, base_sort))) supparams) (*FIXME
+ should constraints be issued in begin?*)
+ val ((_, _, syntax_elems), _) = ProofContext.init thy
+ |> begin_ctxt
+ |> process_decl supexpr raw_elems;
fun fork_syn (Element.Fixes xs) =
fold_map (fn (c, ty, syn) => cons (Binding.base_name c, syn) #> pair (c, ty, NoSyn)) xs
#>> Element.Fixes
| fork_syn x = pair x;
- fun fork_syntax elems =
- let
- val (elems', global_syntax) = fold_map fork_syn elems [];
- in (constrain :: elems', global_syntax) end;
- val (elems, global_syntax) =
- ProofContext.init thy
- |> Old_Locale.cert_expr supexpr [constrain]
- |> snd
- |> begin sups base_sort
- |> process_expr Old_Locale.empty raw_elems
- |> fst
- |> fork_syntax
- in (((sups, supparams), (supsort, base_sort, mergeexpr)), (elems, global_syntax)) end;
+ val (elems, global_syntax) = fold_map fork_syn syntax_elems [];
+ in (((sups, supparam_names), (supsort, base_sort, supexpr)), (constrain :: elems, global_syntax)) end;
-val read_class_spec = gen_class_spec Sign.intern_class Old_Locale.read_expr;
-val check_class_spec = gen_class_spec (K I) Old_Locale.cert_expr;
+val cert_class_spec = gen_class_spec (K I) Expression.cert_declaration;
+val read_class_spec = gen_class_spec Sign.intern_class Expression.cert_read_declaration;
fun add_consts bname class base_sort sups supparams global_syntax thy =
let
- val supconsts = map fst supparams
+ val supconsts = supparams
|> AList.make (snd o the o AList.lookup (op =) (these_params thy sups))
|> (map o apsnd o apsnd o map_atyps o K o TFree) (Name.aT, [class]);
- val all_params = map fst (Old_Locale.parameters_of thy class);
+ val all_params = Locale.params_of thy class;
val raw_params = (snd o chop (length supparams)) all_params;
- fun add_const (v, raw_ty) thy =
+ fun add_const (b, SOME raw_ty, _) thy =
let
+ val v = Binding.base_name b;
val c = Sign.full_bname thy v;
val ty = map_atyps (K (TFree (Name.aT, base_sort))) raw_ty;
val ty0 = Type.strip_sorts ty;
@@ -183,9 +180,9 @@
fun globalize param_map = map_aterms
(fn Free (v, ty) => Const ((fst o the o AList.lookup (op =) param_map) v, ty)
| t => t);
- val raw_pred = Old_Locale.intros thy class
+ val raw_pred = Locale.intros_of thy class
|> fst
- |> map (Logic.unvarify o Logic.strip_imp_concl o Thm.prop_of);
+ |> Option.map (Logic.unvarify o Logic.strip_imp_concl o Thm.prop_of);
fun get_axiom thy = case (#axioms o AxClass.get_info thy) class
of [] => NONE
| [thm] => SOME thm;
@@ -194,7 +191,8 @@
|> add_consts bname class base_sort sups supparams global_syntax
|-> (fn (param_map, params) => AxClass.define_class (bname, supsort)
(map (fst o snd) params)
- [((Binding.name (bname ^ "_" ^ AxClass.axiomsN), []), map (globalize param_map) raw_pred)]
+ [(((*Binding.name (bname ^ "_" ^ AxClass.axiomsN*) Binding.empty, []),
+ Option.map (globalize param_map) raw_pred |> the_list)]
#> snd
#> `get_axiom
#-> (fn assm_axiom => fold (Sign.add_const_constraint o apsnd SOME o snd) params
@@ -204,35 +202,42 @@
fun gen_class prep_spec bname raw_supclasses raw_elems thy =
let
val class = Sign.full_bname thy bname;
- val (((sups, supparams), (supsort, base_sort, mergeexpr)), (elems, global_syntax)) =
+ val (((sups, supparams), (supsort, base_sort, supexpr)), (elems, global_syntax)) =
prep_spec thy raw_supclasses raw_elems;
- val supconsts = map (apsnd fst o snd) (these_params thy sups);
+ (*val export_morph = (*FIXME how canonical is this?*)
+ Morphism.morphism { binding = I, var = I,
+ typ = Logic.varifyT,
+ term = (*map_types Logic.varifyT*) I,
+ fact = map Thm.varifyT
+ } $> Morphism.morphism { binding = I, var = I,
+ typ = Logic.type_map TermSubst.zero_var_indexes,
+ term = TermSubst.zero_var_indexes,
+ fact = Drule.zero_var_indexes_list o map Thm.strip_shyps
+ };*)
in
thy
- |> Old_Locale.add_locale "" bname mergeexpr elems
- |> snd
- |> ProofContext.theory_of
+ |> Expression.add_locale bname "" supexpr elems
+ |> snd |> LocalTheory.exit_global
|> adjungate_axclass bname class base_sort sups supsort supparams global_syntax
|-> (fn (inst, param_map, params, assm_axiom) =>
- `(fn thy => calculate_axiom thy sups base_sort assm_axiom param_map class)
+ `(fn thy => calculate_axiom thy sups base_sort assm_axiom param_map class)
#-> (fn axiom =>
- prove_class_interpretation class inst
- (supconsts @ map (pair class o fst o snd) params) (the_list axiom) []
- #> `(fn thy => raw_morphism thy class param_map axiom)
- #-> (fn morph =>
- `(fn thy => calculate_rules thy morph sups base_sort param_map axiom class)
+ `(fn thy => raw_morphism thy class sups param_map axiom)
+ #-> (fn (morph, export_morph) => Locale.add_registration (class, (morph, export_morph))
+ #> Locale.activate_global_facts (class, morph $> export_morph)
+ #> `(fn thy => calculate_rules thy morph sups base_sort param_map axiom class)
#-> (fn (assm_intro, of_class) =>
register class sups params base_sort inst
morph axiom assm_intro of_class
- #> fold (note_assm_intro class) (the_list assm_intro)))))
+ (*#> fold (note_assm_intro class) (the_list assm_intro*)))))
|> TheoryTarget.init (SOME class)
|> pair class
end;
in
+val class = gen_class cert_class_spec;
val class_cmd = gen_class read_class_spec;
-val class = gen_class check_class_spec;
end; (*local*)
@@ -241,6 +246,12 @@
local
+fun prove_sublocale tac (sub, expr) =
+ Expression.sublocale sub expr
+ #> Proof.global_terminal_proof
+ (Method.Basic (K (Method.SIMPLE_METHOD tac), Position.none), NONE)
+ #> ProofContext.theory_of;
+
fun gen_subclass prep_class do_proof raw_sup lthy =
let
val thy = ProofContext.theory_of lthy;
@@ -258,16 +269,18 @@
val _ = if null err_params then [] else
error ("Class " ^ Syntax.string_of_sort lthy [sub] ^ " lacks parameter(s) " ^
commas_quote err_params ^ " of " ^ Syntax.string_of_sort lthy [sup]);
- val sublocale_prop =
- Old_Locale.global_asms_of thy sup
- |> maps snd
- |> try the_single
- |> Option.map (ObjectLogic.ensure_propT thy);
+
+ val expr = ([(sup, (("", false), Expression.Positional []))], []);
+ val (([props], _, _), goal_ctxt) =
+ Expression.cert_goal_expression expr lthy;
+ val some_prop = try the_single props; (*FIXME*)
fun after_qed some_thm =
- LocalTheory.theory (prove_subclass_relation (sub, sup) some_thm)
+ LocalTheory.theory (register_subclass (sub, sup) some_thm)
+ #> is_some some_thm ? LocalTheory.theory
+ (prove_sublocale (ALLGOALS (ProofContext.fact_tac (the_list some_thm))) (sub, expr))
#> (TheoryTarget.init (SOME sub) o ProofContext.theory_of);
in
- do_proof after_qed sublocale_prop lthy
+ do_proof after_qed some_prop lthy
end;
fun user_proof after_qed NONE =
--- a/src/Pure/Isar/class_target.ML Thu Jan 15 14:33:38 2009 -0800
+++ b/src/Pure/Isar/class_target.ML Fri Jan 16 13:07:44 2009 -0800
@@ -10,6 +10,8 @@
val register: class -> class list -> ((string * typ) * (string * typ)) list
-> sort -> term list -> morphism
-> thm option -> thm option -> thm -> theory -> theory
+ val register_subclass: class * class -> thm option
+ -> theory -> theory
val begin: class list -> sort -> Proof.context -> Proof.context
val init: class -> theory -> Proof.context
@@ -21,14 +23,12 @@
val intro_classes_tac: thm list -> tactic
val default_intro_tac: Proof.context -> thm list -> tactic
- val prove_class_interpretation: class -> term list -> (class * string) list
- -> thm list -> thm list -> theory -> theory
- val prove_subclass_relation: class * class -> thm option -> theory -> theory
val class_prefix: string -> string
val is_class: theory -> class -> bool
val these_params: theory -> sort -> (string * (class * (string * typ))) list
val these_defs: theory -> sort -> thm list
+ val eq_morph: theory -> thm list -> morphism
val base_sort: theory -> class -> sort
val rules: theory -> class -> thm option * thm
val print_classes: theory -> unit
@@ -64,36 +64,6 @@
structure Class_Target : CLASS_TARGET =
struct
-(*temporary adaption code to mediate between old and new locale code*)
-
-structure Locale_Layer =
-struct
-
-val init = Old_Locale.init;
-val parameters_of = Old_Locale.parameters_of;
-val intros = Old_Locale.intros;
-val dests = Old_Locale.dests;
-val get_interpret_morph = Old_Locale.get_interpret_morph;
-val Locale = Old_Locale.Locale;
-val extern = Old_Locale.extern;
-val intro_locales_tac = Old_Locale.intro_locales_tac;
-
-fun prove_interpretation tac prfx_atts expr inst =
- Old_Locale.interpretation I prfx_atts expr inst
- ##> Proof.global_terminal_proof
- (Method.Basic (fn ctxt => Method.SIMPLE_METHOD (tac ctxt), Position.none), NONE)
- ##> ProofContext.theory_of;
-
-fun prove_interpretation_in tac after_qed (name, expr) =
- Old_Locale.interpretation_in_locale
- (ProofContext.theory after_qed) (name, expr)
- #> Proof.global_terminal_proof
- (Method.Basic (K (Method.SIMPLE_METHOD tac), Position.none), NONE)
- #> ProofContext.theory_of;
-
-end;
-
-
(** primitive axclass and instance commands **)
fun axclass_cmd (class, raw_superclasses) raw_specs thy =
@@ -201,6 +171,8 @@
val ancestry = Graph.all_succs o ClassData.get;
+val heritage = Graph.all_preds o ClassData.get;
+
fun the_inst thy = #inst o the_class_data thy;
fun these_params thy =
@@ -235,14 +207,14 @@
fun class_binding_morph class =
Binding.map_prefix (K (Binding.add_prefix false (class_prefix class)));
+fun eq_morph thy thms = (*FIXME how general is this?*)
+ Morphism.term_morphism (MetaSimplifier.rewrite_term thy thms [])
+ $> Morphism.thm_morphism (MetaSimplifier.rewrite_rule thms);
+
fun morphism thy class =
let
val { base_morph, defs, ... } = the_class_data thy class;
- in
- base_morph
- $> Morphism.term_morphism (MetaSimplifier.rewrite_term thy defs [])
- $> Morphism.thm_morphism (MetaSimplifier.rewrite_rule defs)
- end;
+ in base_morph $> eq_morph thy defs end;
fun print_classes thy =
let
@@ -265,7 +237,7 @@
(SOME o Pretty.block) [Pretty.str "supersort: ",
(Syntax.pretty_sort ctxt o Sign.minimize_sort thy o Sign.super_classes thy) class],
if is_class thy class then (SOME o Pretty.str)
- ("locale: " ^ Locale_Layer.extern thy class) else NONE,
+ ("locale: " ^ Locale.extern thy class) else NONE,
((fn [] => NONE | ps => (SOME o Pretty.block o Pretty.fbreaks)
(Pretty.str "parameters:" :: ps)) o map mk_param
o these o Option.map #params o try (AxClass.get_info thy)) class,
@@ -312,39 +284,26 @@
(** tactics and methods **)
-fun prove_class_interpretation class inst consts hyp_facts def_facts thy =
- let
- val constraints = map (fn (class, c) => map_atyps (K (TFree (Name.aT,
- [class]))) (Sign.the_const_type thy c)) consts;
- val no_constraints = map (map_atyps (K (TFree (Name.aT, [])))) constraints;
- fun add_constraint c T = Sign.add_const_constraint (c, SOME T);
- fun tac ctxt = ALLGOALS (ProofContext.fact_tac (hyp_facts @ def_facts)
- ORELSE' (fn n => SELECT_GOAL (Locale_Layer.intro_locales_tac false ctxt []) n));
- val prfx = class_prefix class;
- in
- thy
- |> fold2 add_constraint (map snd consts) no_constraints
- |> Locale_Layer.prove_interpretation tac (class_binding_morph class) (Locale_Layer.Locale class)
- (map SOME inst, map (pair (Attrib.empty_binding) o Thm.prop_of) def_facts)
- |> snd
- |> fold2 add_constraint (map snd consts) constraints
- end;
-
-fun prove_subclass_relation (sub, sup) some_thm thy =
+fun register_subclass (sub, sup) thms thy =
let
val of_class = (snd o rules thy) sup;
- val intro = case some_thm
+ val intro = case thms
of SOME thm => Drule.standard' (of_class OF [Drule.standard' thm])
| NONE => Thm.instantiate ([pairself (Thm.ctyp_of thy o TVar o pair (Name.aT, 0))
([], [sub])], []) of_class;
val classrel = (intro OF (the_list o fst o rules thy) sub)
|> Thm.close_derivation;
+ (*FIXME generic amend operation for classes*)
+ val amendments = map (fn class => (class, morphism thy class))
+ (heritage thy [sub]);
+ val diff_sort = Sign.complete_sort thy [sup]
+ |> subtract (op =) (Sign.complete_sort thy [sub]);
+ val defs_morph = eq_morph thy (these_defs thy diff_sort);
in
thy
|> AxClass.add_classrel classrel
- |> Locale_Layer.prove_interpretation_in (ALLGOALS (ProofContext.fact_tac (the_list some_thm)))
- I (sub, Locale_Layer.Locale sup)
|> ClassData.map (Graph.add_edge (sub, sup))
+ |> fold (Locale.amend_registration defs_morph) amendments
end;
fun intro_classes_tac facts st =
@@ -428,7 +387,7 @@
fun init class thy =
thy
- |> Locale_Layer.init class
+ |> Locale.init class
|> begin [class] (base_sort thy class);
@@ -441,12 +400,18 @@
val morph = morphism thy' class;
val inst = the_inst thy' class;
val params = map (apsnd fst o snd) (these_params thy' [class]);
+ val amendments = map (fn class => (class, morphism thy' class))
+ (heritage thy' [class]);
val c' = Sign.full_bname thy' c;
val dict' = Morphism.term morph dict;
val ty' = Term.fastype_of dict';
val ty'' = Type.strip_sorts ty';
val def_eq = Logic.mk_equals (Const (c', ty'), dict');
+ (*FIXME a mess*)
+ fun amend def def' (class, morph) thy =
+ Locale.amend_registration (eq_morph thy [Thm.varifyT def])
+ (class, morph) thy;
fun get_axiom thy = ((Thm.varifyT o Thm.axiom thy) c', thy);
in
thy'
@@ -454,9 +419,9 @@
|> Thm.add_def false false (c, def_eq)
|>> Thm.symmetric
||>> get_axiom
- |-> (fn (def, def') => prove_class_interpretation class inst params [] [def]
- #> register_operation class (c', (dict', SOME (Thm.symmetric def')))
- #> PureThy.store_thm (c ^ "_raw", def')
+ |-> (fn (def, def') => register_operation class (c', (dict', SOME (Thm.symmetric def')))
+ #> fold (amend def def') amendments
+ #> PureThy.store_thm (c ^ "_raw", def') (*FIXME name*)
#> snd)
|> Sign.restore_naming thy
|> Sign.add_const_constraint (c', SOME ty')
--- a/src/Pure/Isar/expression.ML Thu Jan 15 14:33:38 2009 -0800
+++ b/src/Pure/Isar/expression.ML Fri Jan 16 13:07:44 2009 -0800
@@ -6,37 +6,47 @@
signature EXPRESSION =
sig
- datatype 'term map = Positional of 'term option list | Named of (string * 'term) list;
- type 'term expr = (string * ((string * bool) * 'term map)) list;
- type expression_i = term expr * (Binding.T * typ option * mixfix) list;
- type expression = string expr * (Binding.T * string option * mixfix) list;
+ (* Locale expressions *)
+ datatype 'term map = Positional of 'term option list | Named of (string * 'term) list
+ type 'term expr = (string * ((string * bool) * 'term map)) list
+ type expression_i = term expr * (Binding.T * typ option * mixfix) list
+ type expression = string expr * (Binding.T * string option * mixfix) list
(* Processing of context statements *)
val cert_statement: Element.context_i list -> (term * term list) list list ->
- Proof.context -> (term * term list) list list * Proof.context;
+ Proof.context -> (term * term list) list list * Proof.context
val read_statement: Element.context list -> (string * string list) list list ->
- Proof.context -> (term * term list) list list * Proof.context;
+ Proof.context -> (term * term list) list list * Proof.context
(* Declaring locales *)
+ val cert_declaration: expression_i -> Element.context_i list -> Proof.context ->
+ ((Binding.T * typ option * mixfix) list * (string * morphism) list
+ * Element.context_i list) * ((string * typ) list * Proof.context)
+ val cert_read_declaration: expression_i -> Element.context list -> Proof.context ->
+ ((Binding.T * typ option * mixfix) list * (string * morphism) list
+ * Element.context_i list) * ((string * typ) list * Proof.context)
+ (*FIXME*)
+ val read_declaration: expression -> Element.context list -> Proof.context ->
+ ((Binding.T * typ option * mixfix) list * (string * morphism) list
+ * Element.context_i list) * ((string * typ) list * Proof.context)
val add_locale: bstring -> bstring -> expression_i -> Element.context_i list ->
- theory -> string * local_theory;
+ theory -> string * local_theory
val add_locale_cmd: bstring -> bstring -> expression -> Element.context list ->
- theory -> string * local_theory;
+ theory -> string * local_theory
(* Interpretation *)
val cert_goal_expression: expression_i -> Proof.context ->
- (term list list * (string * morphism) list * morphism) * Proof.context;
+ (term list list * (string * morphism) list * morphism) * Proof.context
val read_goal_expression: expression -> Proof.context ->
- (term list list * (string * morphism) list * morphism) * Proof.context;
-
- val sublocale: string -> expression_i -> theory -> Proof.state;
- val sublocale_cmd: string -> expression -> theory -> Proof.state;
+ (term list list * (string * morphism) list * morphism) * Proof.context
+ val sublocale: string -> expression_i -> theory -> Proof.state
+ val sublocale_cmd: string -> expression -> theory -> Proof.state
val interpretation: expression_i -> (Attrib.binding * term) list ->
- theory -> Proof.state;
+ theory -> Proof.state
val interpretation_cmd: expression -> (Attrib.binding * string) list ->
- theory -> Proof.state;
- val interpret: expression_i -> bool -> Proof.state -> Proof.state;
- val interpret_cmd: expression -> bool -> Proof.state -> Proof.state;
+ theory -> Proof.state
+ val interpret: expression_i -> bool -> Proof.state -> Proof.state
+ val interpret_cmd: expression -> bool -> Proof.state -> Proof.state
end;
@@ -140,14 +150,14 @@
local
-fun prep_inst parse_term parms (Positional insts) ctxt =
+fun prep_inst parse_term ctxt parms (Positional insts) =
(insts ~~ parms) |> map (fn
- (NONE, p) => Syntax.parse_term ctxt p |
+ (NONE, p) => Free (p, the (Variable.default_type ctxt p)) |
(SOME t, _) => parse_term ctxt t)
- | prep_inst parse_term parms (Named insts) ctxt =
+ | prep_inst parse_term ctxt parms (Named insts) =
parms |> map (fn p => case AList.lookup (op =) insts p of
SOME t => parse_term ctxt t |
- NONE => Syntax.parse_term ctxt p);
+ NONE => Free (p, the (Variable.default_type ctxt p)));
in
@@ -315,7 +325,7 @@
let
val thy = ProofContext.theory_of ctxt;
val (parm_names, parm_types) = Locale.params_of thy loc |>
- map (fn (b, SOME T, _) => (Binding.base_name b, T)) |> split_list;
+ map_split (fn (b, SOME T, _) => (Binding.base_name b, T));
val (morph, _) = inst_morph (parm_names, parm_types) (prfx, inst) ctxt;
in (loc, morph) end;
@@ -337,7 +347,7 @@
local
-fun prep_full_context_statement parse_typ parse_prop parse_inst prep_vars prep_expr
+fun prep_full_context_statement parse_typ parse_prop prep_vars_elem parse_inst prep_vars_inst prep_expr
strict do_close raw_import raw_elems raw_concl ctxt1 =
let
val thy = ProofContext.theory_of ctxt1;
@@ -347,8 +357,9 @@
fun prep_inst (loc, (prfx, inst)) (i, insts, ctxt) =
let
val (parm_names, parm_types) = Locale.params_of thy loc |>
- map (fn (b, SOME T, _) => (Binding.base_name b, T)) |> split_list;
- val inst' = parse_inst parm_names inst ctxt;
+ map_split (fn (b, SOME T, _) => (Binding.base_name b, T))
+ (*FIXME return value of Locale.params_of has strange type*)
+ val inst' = parse_inst ctxt parm_names inst;
val parm_types' = map (TypeInfer.paramify_vars o
Term.map_type_tvar (fn ((x, _), S) => TVar ((x, i), S)) o Logic.varifyT) parm_types;
val inst'' = map2 TypeInfer.constrain parm_types' inst';
@@ -359,43 +370,47 @@
val ctxt'' = Locale.activate_declarations thy (loc, morph) ctxt;
in (i+1, insts', ctxt'') end;
- fun prep_elem raw_elem (insts, elems, ctxt) =
+ fun prep_elem insts raw_elem (elems, ctxt) =
let
- val ctxt' = declare_elem prep_vars raw_elem ctxt;
+ val ctxt' = declare_elem prep_vars_elem raw_elem ctxt;
val elems' = elems @ [parse_elem parse_typ parse_prop ctxt' raw_elem];
val (_, _, _, ctxt'') = check_autofix insts elems' [] ctxt';
- in (insts, elems', ctxt') end;
+ in (elems', ctxt') end;
fun prep_concl raw_concl (insts, elems, ctxt) =
let
val concl = parse_concl parse_prop ctxt raw_concl;
in check_autofix insts elems concl ctxt end;
- val fors = prep_vars fixed ctxt1 |> fst;
+ val fors = prep_vars_inst fixed ctxt1 |> fst;
val ctxt2 = ctxt1 |> ProofContext.add_fixes_i fors |> snd;
val (_, insts', ctxt3) = fold prep_inst raw_insts (0, [], ctxt2);
- val (_, elems'', ctxt4) = fold prep_elem raw_elems (insts', [], ctxt3);
- val (insts, elems, concl, ctxt5) =
- prep_concl raw_concl (insts', elems'', ctxt4);
+ val (elems, ctxt4) = fold (prep_elem insts') raw_elems ([], ctxt3);
+ val (insts, elems', concl, ctxt5) =
+ prep_concl raw_concl (insts', elems, ctxt4);
(* Retrieve parameter types *)
- val xs = fold (fn Fixes fixes => (fn ps => ps @ map (Binding.base_name o #1) fixes) |
- _ => fn ps => ps) (Fixes fors :: elems) [];
+ val xs = fold (fn Fixes fixes => (fn ps => ps @ map (Binding.base_name o #1) fixes)
+ | _ => fn ps => ps) (Fixes fors :: elems') [];
val (Ts, ctxt6) = fold_map ProofContext.inferred_param xs ctxt5;
val parms = xs ~~ Ts; (* params from expression and elements *)
val Fixes fors' = finish_primitive parms I (Fixes fors);
- val (deps, elems') = finish ctxt6 parms do_close insts elems;
+ val (deps, elems'') = finish ctxt6 parms do_close insts elems';
- in ((fors', deps, elems', concl), (parms, ctxt6)) end
+ in ((fors', deps, elems'', concl), (parms, ctxt6)) end
in
+fun cert_full_context_statement x =
+ prep_full_context_statement (K I) (K I) ProofContext.cert_vars
+ make_inst ProofContext.cert_vars (K I) x;
+fun cert_read_full_context_statement x =
+ prep_full_context_statement Syntax.parse_typ Syntax.parse_prop ProofContext.read_vars
+ make_inst ProofContext.cert_vars (K I) x;
fun read_full_context_statement x =
- prep_full_context_statement Syntax.parse_typ Syntax.parse_prop parse_inst
- ProofContext.read_vars intern x;
-fun cert_full_context_statement x =
- prep_full_context_statement (K I) (K I) make_inst ProofContext.cert_vars (K I) x;
+ prep_full_context_statement Syntax.parse_typ Syntax.parse_prop ProofContext.read_vars
+ parse_inst ProofContext.read_vars intern x;
end;
@@ -407,14 +422,16 @@
fun prep_statement prep activate raw_elems raw_concl context =
let
val ((_, _, elems, concl), _) =
- prep true false ([], []) raw_elems raw_concl context ;
- val (_, context') = activate elems (ProofContext.set_stmt true context);
+ prep true false ([], []) raw_elems raw_concl context;
+ val (_, context') = context |>
+ ProofContext.set_stmt true |>
+ activate elems;
in (concl, context') end;
in
+fun cert_statement x = prep_statement cert_full_context_statement Element.activate_i x;
fun read_statement x = prep_statement read_full_context_statement Element.activate x;
-fun cert_statement x = prep_statement cert_full_context_statement Element.activate_i x;
end;
@@ -431,13 +448,16 @@
val context' = context |>
ProofContext.add_fixes_i fixed |> snd |>
fold Locale.activate_local_facts deps;
- val (elems', _) = activate elems (ProofContext.set_stmt true context');
+ val (elems', _) = context' |>
+ ProofContext.set_stmt true |>
+ activate elems;
in ((fixed, deps, elems'), (parms, ctxt')) end;
in
+fun cert_declaration x = prep_declaration cert_full_context_statement Element.activate_i x;
+fun cert_read_declaration x = prep_declaration cert_read_full_context_statement Element.activate x;
fun read_declaration x = prep_declaration read_full_context_statement Element.activate x;
-fun cert_declaration x = prep_declaration cert_full_context_statement Element.activate_i x;
end;
@@ -476,8 +496,8 @@
in
+fun cert_goal_expression x = prep_goal_expression cert_full_context_statement x;
fun read_goal_expression x = prep_goal_expression read_full_context_statement x;
-fun cert_goal_expression x = prep_goal_expression cert_full_context_statement x;
end;
@@ -758,8 +778,8 @@
in
+val add_locale = gen_add_locale cert_declaration;
val add_locale_cmd = gen_add_locale read_declaration;
-val add_locale = gen_add_locale cert_declaration;
end;
@@ -804,8 +824,8 @@
in
+fun sublocale x = gen_sublocale cert_goal_expression (K I) x;
fun sublocale_cmd x = gen_sublocale read_goal_expression Locale.intern x;
-fun sublocale x = gen_sublocale cert_goal_expression (K I) x;
end;
@@ -873,9 +893,9 @@
in
+fun interpretation x = gen_interpretation cert_goal_expression (K I) (K I) x;
fun interpretation_cmd x = gen_interpretation read_goal_expression
Syntax.parse_prop Attrib.intern_src x;
-fun interpretation x = gen_interpretation cert_goal_expression (K I) (K I) x;
end;
@@ -910,8 +930,8 @@
in
+fun interpret x = gen_interpret cert_goal_expression x;
fun interpret_cmd x = gen_interpret read_goal_expression x;
-fun interpret x = gen_interpret cert_goal_expression x;
end;
--- a/src/Pure/Isar/isar_document.ML Thu Jan 15 14:33:38 2009 -0800
+++ b/src/Pure/Isar/isar_document.ML Fri Jan 16 13:07:44 2009 -0800
@@ -24,7 +24,7 @@
type command_id = string;
type document_id = string;
-fun new_id () = "isabelle:" ^ serial_string ();
+fun make_id () = "isabelle:" ^ serial_string ();
fun err_dup kind id = error ("Duplicate " ^ kind ^ ": " ^ quote id);
fun err_undef kind id = error ("Unknown " ^ kind ^ ": " ^ quote id);
@@ -53,7 +53,6 @@
fun set_entry_state (id, state_id) = put_entry_state id (SOME state_id);
-
(* document *)
datatype document = Document of
@@ -71,19 +70,21 @@
(* iterate entries *)
-fun fold_entries opt_id f (Document {start, entries, ...}) =
+fun fold_entries id0 f (Document {entries, ...}) =
let
fun apply NONE x = x
- | apply (SOME id) x = apply (#next (the_entry entries id)) (f id x);
- in if is_some opt_id then apply opt_id else apply (SOME start) end;
+ | apply (SOME id) x =
+ let val entry = the_entry entries id
+ in apply (#next entry) (f (id, entry) x) end;
+ in if Symtab.defined entries id0 then apply (SOME id0) else I end;
-fun find_entries P (Document {start, entries, ...}) =
+fun first_entry P (Document {start, entries, ...}) =
let
- fun find _ NONE = NONE
- | find prev (SOME id) =
- if P id then SOME (prev, id)
- else find (SOME id) (#next (the_entry entries id));
- in find NONE (SOME start) end;
+ fun first _ NONE = NONE
+ | first prev (SOME id) =
+ let val entry = the_entry entries id
+ in if P (id, entry) then SOME (prev, id, entry) else first (SOME id) (#next entry) end;
+ in first NONE (SOME start) end;
(* modify entries *)
@@ -133,16 +134,24 @@
end;
-fun define_state (id: state_id) state =
- change_states (Symtab.update_new (id, state))
+(* state *)
+
+val empty_state = Future.value (SOME Toplevel.toplevel);
+
+fun define_state (id: state_id) =
+ change_states (Symtab.update_new (id, empty_state))
handle Symtab.DUP dup => err_dup "state" dup;
+fun put_state (id: state_id) state = change_states (Symtab.update (id, state));
+
fun the_state (id: state_id) =
(case Symtab.lookup (get_states ()) id of
NONE => err_undef "state" id
| SOME state => state);
+(* command *)
+
fun define_command id tr =
change_commands (Symtab.update_new (id, Toplevel.put_id id tr))
handle Symtab.DUP dup => err_dup "command" dup;
@@ -153,6 +162,8 @@
| SOME tr => tr);
+(* document *)
+
fun define_document (id: document_id) document =
change_documents (Symtab.update_new (id, document))
handle Symtab.DUP dup => err_dup "document" dup;
@@ -160,60 +171,64 @@
fun the_document (id: document_id) =
(case Symtab.lookup (get_documents ()) id of
NONE => err_undef "document" id
- | SOME (Document doc) => doc);
+ | SOME document => document);
+
+(** main operations **)
+
(* begin/end document *)
fun begin_document (id: document_id) path =
let
val (dir, name) = ThyLoad.split_thy_path path;
val _ = define_command id Toplevel.empty;
- val _ = define_state id (Future.value (SOME Toplevel.toplevel));
+ val _ = define_state id;
val entries = Symtab.make [(id, make_entry NONE (SOME id))];
val _ = define_document id (make_document dir name id entries);
in () end;
-fun end_document (id: document_id) = error "FIXME";
+fun end_document (id: document_id) =
+ let
+ val document as Document {name, ...} = the_document id;
+ val end_state =
+ the_state (the (#state (#3 (the
+ (first_entry (fn (_, {next, ...}) => is_none next) document)))));
+ val _ =
+ Future.fork_deps [end_state] (fn () =>
+ (case Future.join end_state of
+ SOME st =>
+ (Toplevel.run_command name (Toplevel.put_id id (Toplevel.commit_exit Position.none)) st;
+ ThyInfo.touch_child_thys name;
+ ThyInfo.register_thy name)
+ | NONE => error ("Failed to finish theory " ^ quote name)));
+ in () end;
(* document editing *)
-fun update_state tr state = Future.fork_deps [state] (fn () =>
- (case Future.join state of NONE => NONE | SOME st => Toplevel.run_command tr st));
-
-fun update_states old_document new_document =
- let
- val Document {entries = old_entries, ...} = old_document;
- val Document {entries = new_entries, ...} = new_document;
+local
- fun is_changed id =
- (case try (the_entry new_entries) id of
- SOME {state = SOME _, ...} => false
- | _ => true);
-
- fun cancel_state id () =
- (case the_entry old_entries id of
- {state = SOME state_id, ...} => Future.cancel (the_state state_id)
- | _ => ());
+fun is_changed entries' (id, {next = _, state}) =
+ (case try (the_entry entries') id of
+ NONE => true
+ | SOME {next = _, state = state'} => state' <> state);
- fun new_state id (state_id, updates) =
+fun new_state name (id, _) (state_id, updates) =
+ let
+ val state_id' = make_id ();
+ val _ = define_state state_id';
+ val tr = Toplevel.put_id state_id' (the_command id);
+ fun make_state' () =
let
- val state_id' = new_id ();
- val state' = update_state (the_command id) (the_state state_id);
- val _ = define_state state_id' state';
- in (state_id', (id, state_id') :: updates) end;
- in
- (case find_entries is_changed old_document of
- NONE => ([], new_document)
- | SOME (prev, id) =>
- let
- val _ = fold_entries (SOME id) cancel_state old_document ();
- val prev_state_id = the (#state (the_entry new_entries (the prev)));
- val (_, updates) = fold_entries (SOME id) new_state new_document (prev_state_id, []);
- val new_document' = new_document |> map_entries (fold set_entry_state updates);
- in (updates, new_document') end)
- end;
+ val state = the_state state_id;
+ val state' =
+ Future.fork_deps [state] (fn () =>
+ (case Future.join state of
+ NONE => NONE
+ | SOME st => Toplevel.run_command name tr st));
+ in put_state state_id' state' end;
+ in (state_id', ((id, state_id'), make_state') :: updates) end;
fun report_updates _ [] = ()
| report_updates (document_id: document_id) updates =
@@ -221,17 +236,39 @@
|> Markup.markup (Markup.edits document_id)
|> Output.status;
-fun edit_document (id: document_id) (id': document_id) edits =
+in
+
+fun edit_document (old_id: document_id) (new_id: document_id) edits =
let
- val document = Document (the_document id);
- val (updates, document') =
- document
- |> fold (fn (id, SOME id2) => insert_after id id2 | (id, NONE) => delete_after id) edits
- |> update_states document;
- val _ = define_document id' document';
- val _ = report_updates id' updates;
+ val old_document as Document {name, entries = old_entries, ...} = the_document old_id;
+ val new_document as Document {entries = new_entries, ...} = old_document
+ |> fold (fn (id, SOME id2) => insert_after id id2 | (id, NONE) => delete_after id) edits;
+
+ fun cancel_old id = fold_entries id
+ (fn (_, {state = SOME state_id, ...}) => K (Future.cancel (the_state state_id)) | _ => K ())
+ old_document ();
+
+ val (updates, new_document') =
+ (case first_entry (is_changed old_entries) new_document of
+ NONE =>
+ (case first_entry (is_changed new_entries) old_document of
+ NONE => ([], new_document)
+ | SOME (_, id, _) => (cancel_old id; ([], new_document)))
+ | SOME (prev, id, _) =>
+ let
+ val _ = cancel_old id;
+ val prev_state_id = the (#state (the_entry new_entries (the prev)));
+ val (_, updates) = fold_entries id (new_state name) new_document (prev_state_id, []);
+ val new_document' = new_document |> map_entries (fold (set_entry_state o #1) updates);
+ in (rev updates, new_document') end);
+
+ val _ = define_document new_id new_document';
+ val _ = report_updates new_id (map #1 updates);
+ val _ = List.app (fn (_, run) => run ()) updates;
in () end;
+end;
+
(** concrete syntax **)
--- a/src/Pure/Isar/locale.ML Thu Jan 15 14:33:38 2009 -0800
+++ b/src/Pure/Isar/locale.ML Fri Jan 16 13:07:44 2009 -0800
@@ -58,7 +58,7 @@
val add_type_syntax: string -> declaration -> Proof.context -> Proof.context
val add_term_syntax: string -> declaration -> Proof.context -> Proof.context
val add_declaration: string -> declaration -> Proof.context -> Proof.context
- val add_dependency: string -> (string * Morphism.morphism) -> theory -> theory
+ val add_dependency: string -> string * Morphism.morphism -> theory -> theory
(* Activation *)
val activate_declarations: theory -> string * Morphism.morphism ->
@@ -74,9 +74,9 @@
val intro_locales_tac: bool -> Proof.context -> thm list -> tactic
(* Registrations *)
- val add_registration: (string * (Morphism.morphism * Morphism.morphism)) ->
+ val add_registration: string * (Morphism.morphism * Morphism.morphism) ->
theory -> theory
- val amend_registration: Morphism.morphism -> (string * Morphism.morphism) ->
+ val amend_registration: Morphism.morphism -> string * Morphism.morphism ->
theory -> theory
val get_registrations: theory -> (string * Morphism.morphism) list
@@ -356,23 +356,20 @@
in
fun activate_declarations thy dep ctxt =
- roundup thy activate_decls dep (get_local_idents ctxt, ctxt) |> uncurry put_local_idents;
+ roundup thy activate_decls dep (get_local_idents ctxt, ctxt) |-> put_local_idents;
fun activate_global_facts dep thy =
roundup thy (activate_notes init_global_elem Element.transfer_morphism)
- dep (get_global_idents thy, thy) |>
- uncurry put_global_idents;
+ dep (get_global_idents thy, thy) |-> put_global_idents;
fun activate_local_facts dep ctxt =
roundup (ProofContext.theory_of ctxt)
(activate_notes init_local_elem (Element.transfer_morphism o ProofContext.theory_of)) dep
- (get_local_idents ctxt, ctxt) |>
- uncurry put_local_idents;
+ (get_local_idents ctxt, ctxt) |-> put_local_idents;
fun init name thy =
activate_all name thy init_local_elem (Element.transfer_morphism o ProofContext.theory_of)
- (empty, ProofContext.init thy) |>
- uncurry put_local_idents;
+ (empty, ProofContext.init thy) |-> put_local_idents;
fun print_locale thy show_facts name =
let
@@ -408,8 +405,8 @@
fun add_registration (name, (base_morph, export)) thy =
roundup thy (fn _ => fn (name', morph') =>
(RegistrationsData.map o cons) ((name', (morph', export)), stamp ()))
- (name, base_morph) (get_global_idents thy, thy) |>
- snd (* FIXME ?? uncurry put_global_idents *);
+ (name, base_morph) (get_global_idents thy, thy) |> snd
+ (* FIXME |-> put_global_idents ?*);
fun amend_registration morph (name, base_morph) thy =
let
@@ -428,6 +425,7 @@
end;
+
(*** Storing results ***)
(* Theorems *)
--- a/src/Pure/Isar/toplevel.ML Thu Jan 15 14:33:38 2009 -0800
+++ b/src/Pure/Isar/toplevel.ML Fri Jan 16 13:07:44 2009 -0800
@@ -96,7 +96,7 @@
val transition: bool -> transition -> state -> (state * (exn * string) option) option
val commit_exit: Position.T -> transition
val command: transition -> state -> state
- val run_command: transition -> state -> state option
+ val run_command: string -> transition -> state -> state option
val excursion: (transition * transition list) list -> (transition * state) list lazy
end;
@@ -698,11 +698,17 @@
let val st' = command tr st
in (st', st') end;
-fun run_command tr st =
- (case transition true tr st of
- SOME (st', NONE) => (status tr Markup.finished; SOME st')
- | SOME (_, SOME exn_info) => (error_msg tr exn_info; status tr Markup.failed; NONE)
- | NONE => (error_msg tr (TERMINATE, at_command tr); status tr Markup.failed; NONE));
+fun run_command thy_name tr st =
+ (case
+ (case init_of tr of
+ SOME name => Exn.capture (fn () => ThyLoad.check_name thy_name name) ()
+ | NONE => Exn.Result ()) of
+ Exn.Result () =>
+ (case transition true tr st of
+ SOME (st', NONE) => (status tr Markup.finished; SOME st')
+ | SOME (_, SOME exn_info) => (error_msg tr exn_info; status tr Markup.failed; NONE)
+ | NONE => (error_msg tr (TERMINATE, at_command tr); status tr Markup.failed; NONE))
+ | Exn.Exn exn => (error_msg tr (exn, at_command tr); status tr Markup.failed; NONE));
(* excursion of units, consisting of commands with proof *)
--- a/src/Pure/Thy/thy_load.ML Thu Jan 15 14:33:38 2009 -0800
+++ b/src/Pure/Thy/thy_load.ML Fri Jan 16 13:07:44 2009 -0800
@@ -25,6 +25,7 @@
val check_file: Path.T -> Path.T -> (Path.T * File.ident) option
val check_ml: Path.T -> Path.T -> (Path.T * File.ident) option
val check_thy: Path.T -> string -> Path.T * File.ident
+ val check_name: string -> string -> unit
val deps_thy: Path.T -> string ->
{master: Path.T * File.ident, text: string list, imports: string list, uses: Path.T list}
val load_ml: Path.T -> Path.T -> Path.T * File.ident
@@ -95,6 +96,11 @@
| SOME thy_id => thy_id)
end;
+fun check_name name name' =
+ if name = name' then ()
+ else error ("Filename " ^ quote (Path.implode (thy_path name)) ^
+ " does not agree with theory name " ^ quote name');
+
(* theory deps *)
@@ -104,9 +110,7 @@
val text = explode (File.read path);
val (name', imports, uses) =
ThyHeader.read (Path.position path) (Source.of_list_limited 8000 text);
- val _ = name = name' orelse
- error ("Filename " ^ quote (Path.implode (Path.base path)) ^
- " does not agree with theory name " ^ quote name');
+ val _ = check_name name name';
val uses = map (Path.explode o #1) uses;
in {master = master, text = text, imports = imports, uses = uses} end;
--- a/src/Pure/Tools/isabelle_process.scala Thu Jan 15 14:33:38 2009 -0800
+++ b/src/Pure/Tools/isabelle_process.scala Fri Jan 16 13:07:44 2009 -0800
@@ -67,7 +67,8 @@
class Result(val kind: Kind.Value, val props: Properties, val result: String) {
override def toString = {
- val res = XML.content(YXML.parse_failsafe(result)).mkString
+ val tree = YXML.parse_failsafe(result)
+ val res = if (kind == Kind.STATUS) tree.toString else XML.content(tree).mkString
if (props == null) kind.toString + " [[" + res + "]]"
else kind.toString + " " + props.toString + " [[" + res + "]]"
}