Inductive plusP :
list (Term A n) -> list (Term A n) -> list (Term A n) -> Prop :=
  | nillu1 : forall l1, plusP (pO A n) l1 l1
  | nillu2 : forall l1, plusP l1 (pO A n) l1
  | mainu1 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a2 a1 ->
      plusP l1 (pX a2 l2) l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a1 l3)
  | mainu2a :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2) l3
  | mainu2b :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      ~ zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2)
        (pX (plusTerm (A:=A) plusA (n:=n) a1 a2) l3)
  | mainu3 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a1 a2 ->
      plusP (pX a1 l1) l2 l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a2 l3).Inductive plusP :
list (Term A n) -> list (Term A n) -> list (Term A n) -> Prop :=
  | nillu1 : forall l1, plusP (pO A n) l1 l1
  | nillu2 : forall l1, plusP l1 (pO A n) l1
  | mainu1 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a2 a1 ->
      plusP l1 (pX a2 l2) l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a1 l3)
  | mainu2a :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2) l3
  | mainu2b :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      ~ zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2)
        (pX (plusTerm (A:=A) plusA (n:=n) a1 a2) l3)
  | mainu3 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a1 a2 ->
      plusP (pX a1 l1) l2 l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a2 l3).Inductive plusP :
list (Term A n) -> list (Term A n) -> list (Term A n) -> Prop :=
  | nillu1 : forall l1, plusP (pO A n) l1 l1
  | nillu2 : forall l1, plusP l1 (pO A n) l1
  | mainu1 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a2 a1 ->
      plusP l1 (pX a2 l2) l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a1 l3)
  | mainu2a :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2) l3
  | mainu2b :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      ~ zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2)
        (pX (plusTerm (A:=A) plusA (n:=n) a1 a2) l3)
  | mainu3 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a1 a2 ->
      plusP (pX a1 l1) l2 l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a2 l3).Inductive plusP :
list (Term A n) -> list (Term A n) -> list (Term A n) -> Prop :=
  | nillu1 : forall l1, plusP (pO A n) l1 l1
  | nillu2 : forall l1, plusP l1 (pO A n) l1
  | mainu1 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a2 a1 ->
      plusP l1 (pX a2 l2) l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a1 l3)
  | mainu2a :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2) l3
  | mainu2b :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      ~ zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2)
        (pX (plusTerm (A:=A) plusA (n:=n) a1 a2) l3)
  | mainu3 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a1 a2 ->
      plusP (pX a1 l1) l2 l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a2 l3).Inductive plusP :
list (Term A n) -> list (Term A n) -> list (Term A n) -> Prop :=
  | nillu1 : forall l1, plusP (pO A n) l1 l1
  | nillu2 : forall l1, plusP l1 (pO A n) l1
  | mainu1 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a2 a1 ->
      plusP l1 (pX a2 l2) l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a1 l3)
  | mainu2a :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2) l3
  | mainu2b :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      ~ zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2)
        (pX (plusTerm (A:=A) plusA (n:=n) a1 a2) l3)
  | mainu3 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a1 a2 ->
      plusP (pX a1 l1) l2 l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a2 l3).Inductive plusP :
list (Term A n) -> list (Term A n) -> list (Term A n) -> Prop :=
  | nillu1 : forall l1, plusP (pO A n) l1 l1
  | nillu2 : forall l1, plusP l1 (pO A n) l1
  | mainu1 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a2 a1 ->
      plusP l1 (pX a2 l2) l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a1 l3)
  | mainu2a :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2) l3
  | mainu2b :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      ~ zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2)
        (pX (plusTerm (A:=A) plusA (n:=n) a1 a2) l3)
  | mainu3 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a1 a2 ->
      plusP (pX a1 l1) l2 l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a2 l3).Inductive plusP :
list (Term A n) -> list (Term A n) -> list (Term A n) -> Prop :=
  | nillu1 : forall l1, plusP (pO A n) l1 l1
  | nillu2 : forall l1, plusP l1 (pO A n) l1
  | mainu1 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a2 a1 ->
      plusP l1 (pX a2 l2) l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a1 l3)
  | mainu2a :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2) l3
  | mainu2b :
      forall a1 a2 l1 l2 l3,
      plusP l1 l2 l3 ->
      eqT a1 a2 ->
      ~ zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a1 a2) ->
      plusP (pX a1 l1) (pX a2 l2)
        (pX (plusTerm (A:=A) plusA (n:=n) a1 a2) l3)
  | mainu3 :
      forall a1 a2 l1 l2 l3,
      ltT ltM a1 a2 ->
      plusP (pX a1 l1) l2 l3 -> plusP (pX a1 l1) (pX a2 l2) (pX a2 l3).Definition projsig1 (A : Set) (P : A -> Prop) (H : sig P) :=
  let (a, _) return A := H in a.Definition plusp : forall l, {a : _ | plusP (fst l) (snd l) a}.Definition pluspf l1 l2 := projsig1 _ _ (plusp (l1, l2)).

(* Specifications: *)
Lemma plusP_inv : forall p q l (a b : Term A n), plusP (pX a p) (pX b q) l -> exists l1 : _, ltT ltM b a /\ plusP p (pX b q) l1 /\ l = pX a l1 \/ ltT ltM a b /\ plusP (pX a p) q l1 /\ l = pX b l1 \/ eqT a b /\ (zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a b) /\ plusP p q l \/ ~ zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a b) /\ plusP p q l1 /\ l = pX (plusTerm (A:=A) plusA (n:=n) a b) l1).
Theorem uniq_plusp : forall l l3 l4, plusP (fst l) (snd l) l3 -> plusP (fst l) (snd l) l4 -> l3 = l4.
Theorem pluspf_is_plusP : forall l1 l2, plusP l1 l2 (pluspf l1 l2).
Theorem order_plusP : forall l1 l2 l3 a, plusP l1 l2 l3 -> canonical A0 eqA ltM (pX a l1) -> canonical A0 eqA ltM (pX a l2) -> canonical A0 eqA ltM l3 -> canonical A0 eqA ltM (pX a l3).
Theorem canonical_plusP : forall l1 l2 l3, plusP l1 l2 l3 -> canonical A0 eqA ltM l1 -> canonical A0 eqA ltM l2 -> canonical A0 eqA ltM l3.
Theorem canonical_pluspf : forall l1 l2, canonical A0 eqA ltM l1 -> canonical A0 eqA ltM l2 -> canonical A0 eqA ltM (pluspf l1 l2).
Theorem pO_plusP_inv1 : forall p q, plusP (pO A n) p q -> p = q.
Theorem pO_plusP_inv2 : forall p q, plusP p (pO A n) q -> p = q.
Theorem plusP_decomp : forall a p, canonical A0 eqA ltM (pX a p) -> plusP (pX a (pO A n)) p (pX a p).
Theorem plusP_inv1 : forall a b p q s, plusP (pX a p) (pX b q) s -> ltT ltM b a -> s = pX a (pluspf p (pX b q)).
Theorem plusP_inv2 : forall a b p q s, plusP (pX a p) (pX b q) s -> ltT ltM a b -> s = pX b (pluspf (pX a p) q).
Theorem plusP_inv3a : forall a b p q s, eqT a b -> zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a b) -> plusP (pX a p) (pX b q) s -> s = pluspf p q.
Theorem plusP_inv3b : forall a b p q s, eqT a b -> ~ zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a b) -> plusP (pX a p) (pX b q) s -> s = pX (plusTerm (A:=A) plusA (n:=n) a b) (pluspf p q).
Theorem pluspf_inv1 : forall a b p q, ltT ltM b a -> eqP A eqA n (pX a (pluspf p (pX b q))) (pluspf (pX a p) (pX b q)).
Theorem pluspf_inv2 : forall a b p q, ltT ltM a b -> eqP A eqA n (pX b (pluspf (pX a p) q)) (pluspf (pX a p) (pX b q)).
Theorem pluspf_inv3a : forall a b p q, eqT a b -> zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a b) -> eqP A eqA n (pluspf p q) (pluspf (pX a p) (pX b q)).
Theorem pluspf_inv3b : forall a b p q, eqT a b -> ~ zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a b) -> eqP A eqA n (pX (plusTerm (A:=A) plusA (n:=n) a b) (pluspf p q)) (pluspf (pX a p) (pX b q)).
Theorem plusP_com : forall p q r s, plusP p q r -> plusP q p s -> eqP A eqA n r s.
Theorem pluspf_com : forall p q, eqP A eqA n (pluspf p q) (pluspf q p).
Theorem plusP_zero_pOl : forall p q, plusP (pO A n) p q -> eqP A eqA n p q.
Theorem plusP_zero_pOr : forall p q, plusP p (pO A n) q -> eqP A eqA n p q.
Theorem plusP_uniq_eqP : forall p q r s, plusP p q r -> plusP p q s -> eqP A eqA n r s.
Theorem pO_pluspf_inv1 : forall p, p = pluspf (pO A n) p.
Theorem pO_pluspf_inv2 : forall p, p = pluspf p (pO A n).
Theorem pluspf_inv1_eq : forall a b p q, ltT ltM b a -> pX a (pluspf p (pX b q)) = pluspf (pX a p) (pX b q).
Theorem pluspf_inv2_eq : forall a b p q, ltT ltM a b -> pX b (pluspf (pX a p) q) = pluspf (pX a p) (pX b q).
Theorem pluspf_inv3a_eq : forall a b p q, eqT a b -> zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a b) -> pluspf p q = pluspf (pX a p) (pX b q).
Theorem pluspf_inv3b_eq : forall a b p q, eqT a b -> ~ zeroP (A:=A) A0 eqA (n:=n) (plusTerm (A:=A) plusA (n:=n) a b) -> pX (plusTerm (A:=A) plusA (n:=n) a b) (pluspf p q) = pluspf (pX a p) (pX b q).
Theorem order_pluspf : forall l1 l2 a, canonical A0 eqA ltM (pX a l1) -> canonical A0 eqA ltM (pX a l2) -> canonical A0 eqA ltM (pX a (pluspf l1 l2)).
Theorem pluspf_inv1_eqa : forall a p q, canonical A0 eqA ltM (pX a p) -> canonical A0 eqA ltM (pX a q) -> pX a (pluspf p q) = pluspf (pX a p) q.
Theorem pluspf_inv2_eqa : forall a p q, canonical A0 eqA ltM (pX a p) -> canonical A0 eqA ltM (pX a q) -> pX a (pluspf p q) = pluspf p (pX a q).
Theorem p0_pluspf_l : forall p, eqP A eqA n (pluspf (pO A n) p) p.
Theorem p0_pluspf_r : forall p, eqP A eqA n (pluspf p (pO A n)) p.
Theorem plusTerm_is_pX : forall (a : Term A n) (p : list (Term A n)), canonical A0 eqA ltM (pX a p) -> eqP A eqA n (pluspf (pX a (pO A n)) p) (pX a p).
Theorem pluspf3_assoc : forall l, canonical A0 eqA ltM (fst l) -> canonical A0 eqA ltM (fst (snd l)) -> canonical A0 eqA ltM (snd (snd l)) -> eqP A eqA n (pluspf (pluspf (fst l) (fst (snd l))) (snd (snd l))) (pluspf (fst l) (pluspf (fst (snd l)) (snd (snd l)))).
Theorem pluspf_assoc : forall p q r, canonical A0 eqA ltM p -> canonical A0 eqA ltM q -> canonical A0 eqA ltM r -> eqP A eqA n (pluspf (pluspf p q) r) (pluspf p (pluspf q r)).
Theorem eqp_pluspf_com_l : forall p q r, eqP A eqA n p q -> canonical A0 eqA ltM p -> canonical A0 eqA ltM q -> canonical A0 eqA ltM r -> eqP A eqA n (pluspf p r) (pluspf q r).
Theorem eqp_pluspf_com_r : forall p q r, eqP A eqA n p q -> canonical A0 eqA ltM p -> canonical A0 eqA ltM q -> canonical A0 eqA ltM r -> eqP A eqA n (pluspf r p) (pluspf r q).
Theorem eqp_pluspf_com : forall p q r t, canonical A0 eqA ltM p -> canonical A0 eqA ltM q -> canonical A0 eqA ltM r -> canonical A0 eqA ltM t -> eqP A eqA n p r -> eqP A eqA n q t -> eqP A eqA n (pluspf p q) (pluspf r t).