Question

I am working on a lemma that shows that the degree of a sum of monomials is always less or equal to n if the exponent of each monomial is less or equal to n.

lemma degree_poly_smaller:
  fixes a :: "('a::comm_ring_1 poly)" and n::nat
  shows "degree (∑x∷nat | x ≤ n . monom (coeff a x) x) ≤ n"
sorry

What I have to so far is the following (please mind that I am a beginner in Isabelle):

lemma degree_smaller:
  fixes a :: "('a::comm_ring_1 poly)" and n::nat
  shows "degree (∑x∷nat | x ≤ n . monom (coeff a x) x) ≤ n"
proof-

 have th01: "⋀k. k ≤ n ⟹ 
             degree (setsum (λ x . monom (coeff a x) k) {x∷nat. x ≤ n})  ≤ n" 
                    by (metis degree_monom_le monom_setsum order_trans)

 have min_lemma1: "k∈{x∷nat. x ≤ n} ⟹ k ≤ n" by simp

 from this th01 have th02: 
     "⋀k. k∈{x∷nat. x ≤ n} ⟹ 
     degree (setsum (λ x . monom (coeff a x) k) {x∷nat. x ≤ n})  ≤ n" 
                                             by (metis mem_Collect_eq)

 have min_lemma2: "(SOME y . y ≤ n) ≤ n" by (metis (full_types) le0 some_eq_ex)

 from this have th03: 
     "degree (∑x∷nat | x ≤ n . monom (coeff a x) (SOME y . y ≤ n)) ≤ n" 
                                                         by (metis th01)

 from min_lemma1 min_lemma2 have min_lemma3: 
     "(SOME y . y∈{x∷nat. x ≤ n}) ≤ n" by (metis (full_types) mem_Collect_eq some_eq_ex)

 from this th01 th02 th03 have th04: 
     "degree (∑x∷nat | x ≤ n . monom (coeff a x) (SOME y . y∈{x∷nat. x ≤ n}) ) ≤ n" 
                                                                      by presburger

Here is the problem, I don't understand why the following lemma is not sufficient to finish the proof. In particular, I would expect the last part (where the sorry is) to be simple enough for sledgehammer to find a proof:

 from this th01 th02 th03 th04  have th05: 
 "degree 
  (setsum (λ i . monom (coeff a i) (SOME y . y∈{x∷nat. x ≤ n})) {x∷nat. x ≤ n})
   ≤ n"
        by linarith

  (* how can I prove this last step ? *)
  from this have 
    "degree (setsum (λ i . monom (coeff a i) i) {x∷nat. x ≤ n}) ≤ n" sorry 

  from this show ?thesis by auto
qed

.
SOLUTION from Brian Huffman's excellent answer:
.

lemma degree_setsum_smaller:
  "finite A ⟹ ∀x∈A. degree (f x) ≤ n ⟹ degree (∑x∈A. f x) ≤ n"
apply(induct rule: finite_induct)
apply(auto)
by (metis degree_add_le)

lemma finiteSetSmallerThanNumber: 
   "finite {x∷nat. x ≤ n}" 
by (metis finite_Collect_le_nat)

lemma degree_smaller:
  fixes a :: "('a::comm_ring_1 poly)" and n::nat
  shows "degree (∑x∷nat | x ≤ n . monom (coeff a x) x) ≤ n"
apply (rule degree_setsum_smaller)
apply(simp add: finiteSetSmallerThanNumber)
by (metis degree_0 degree_monom_eq le0 mem_Collect_eq monom_eq_0_iff) (* from sledgehammer *)
Was it helpful?

Solution

The last step does not follow from your th05. The problem is that you seem to want to unify (SOME y. y∈{x∷nat. x ≤ n}) with the bound variable i. However, in HOL (SOME y. y∈{x∷nat. x ≤ n}) has a single value that depends only on n and not on i. Furthermore, you don't get to choose the value; a theorem using SOME is not the same as a theorem with a universally quantified variable.

My advice is to avoid using SOME altogether, and instead try to prove a generalization of your theorem first:

lemma degree_setsum_smaller:
  "finite A ⟹ ∀x∈A. degree (f x) ≤ n ⟹ degree (∑x∈A. f x) ≤ n"

You should be able to prove degree_setsum_smaller by induction over A (use induct rule: finite_induct), and then use it to prove degree_poly_smaller. Lemma degree_add_le from the polynomial library should be useful.

OTHER TIPS

It is generally considered bad style to use auto as anything other than the last method in an apply script, because such proofs tend to be quite fragile. I would eliminate the "finiteSetSmallerThanNumber" lemma completely, it is a needlessly specific special case of Collect_le_nat. Also, camel case names for theorems are usually not used in Isabelle.

At any rate, this is my suggestion of how to make the proofs nicer:

lemma degree_setsum_smaller:
  "finite A ⟹ ∀x∈A. degree (f x) ≤ n ⟹ degree (∑x∈A. f x) ≤ n"
by (induct rule: finite_induct, simp_all add: degree_add_le)

lemma degree_smaller:
  fixes a :: "('a::comm_ring_1 poly)" and n::nat
  shows "degree (∑x∷nat | x ≤ n . monom (coeff a x) x) ≤ n"
proof (rule degree_setsum_smaller)
  show "finite {x. x ≤ n}" using finite_Collect_le_nat .
  {
    fix x assume "x ≤ n"
    hence "degree (monom (coeff a x) x) ≤ n"
        by (cases "coeff a x = 0", simp_all add: degree_monom_eq)
  }
  thus "∀x∈{x. x≤ n}. degree (monom (coeff a x) x) ≤ n" by simp
qed
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top