+ ]
+ | reflexivity
+ ]
+ | elim (g n1)
+ [ left.
+ reflexivity
+ | right.
+ reflexivity
+ ]
+ ]
+]
+qed.
+
+(* I introduce an equivalence in the form map_iter_i in order to use
+ * the existing result about permutation in that part of the library.
+ *)
+
+theorem eq_map_iter_i_sigma_p_alwaysTrue: \forall n:nat.\forall g:nat \to nat.
+map_iter_i n g plus O = sigma_p (S n) (\lambda c:nat.true) g.
+intros.
+elim n
+[ simplify.
+ rewrite < plus_n_O.
+ reflexivity
+| rewrite > true_to_sigma_p_Sn
+ [ simplify in \vdash (? ? % ?).
+ rewrite < plus_n_O.
+ apply eq_f.
+ assumption
+ | reflexivity
+ ]
+]
+qed.
+
+theorem sigma_p_plus_1: \forall n:nat. \forall f,g:nat \to nat.
+\forall p.
+sigma_p n p (\lambda a:nat.(f a) + (g a)) =
+sigma_p n p f + sigma_p n p g.
+intros.
+elim n
+[ simplify.
+ reflexivity
+| apply (bool_elim ? (p n1)); intro;
+ [ rewrite > true_to_sigma_p_Sn
+ [ rewrite > (true_to_sigma_p_Sn n1 p f)
+ [ rewrite > (true_to_sigma_p_Sn n1 p g)
+ [ rewrite > assoc_plus in \vdash (? ? ? %).
+ rewrite < assoc_plus in \vdash (? ? ? (? ? %)).
+ rewrite < sym_plus in \vdash (? ? ? (? ? (? % ?))).
+ rewrite > assoc_plus in \vdash (? ? ? (? ? %)).
+ rewrite < assoc_plus in \vdash (? ? ? %).
+ apply eq_f.
+ assumption]]]
+ assumption
+ | rewrite > false_to_sigma_p_Sn
+ [ rewrite > (false_to_sigma_p_Sn n1 p f)
+ [ rewrite > (false_to_sigma_p_Sn n1 p g)
+ [assumption]]]
+ assumption
+]]
+qed.
+
+theorem eq_sigma_p_sigma_p_times1 : \forall n,m:nat.\forall f:nat \to nat.
+sigma_p (n*m) (\lambda x:nat.true) f =
+sigma_p m (\lambda x:nat.true)
+ (\lambda a.(sigma_p n (\lambda x:nat.true) (\lambda b.f (b*m + a)))).
+intro.
+elim n
+[ simplify.
+ elim m
+ [ simplify.
+ reflexivity
+ | rewrite > true_to_sigma_p_Sn
+ [ rewrite < H.
+ reflexivity
+ | reflexivity
+ ]
+ ]
+| change in \vdash (? ? ? (? ? ? (\lambda a:?.%))) with ((f ((n1*m)+a)) +
+ (sigma_p n1 (\lambda x:nat.true) (\lambda b:nat.f (b*m +a)))).
+ rewrite > sigma_p_plus_1 in \vdash (? ? ? %).
+ rewrite > (sym_times (S n1) m).
+ rewrite < (times_n_Sm m n1).
+ rewrite > sigma_p_plus in \vdash (? ? % ?).
+ apply eq_f2
+ [ rewrite < (sym_times m n1).
+ apply eq_sigma_p
+ [ intros.
+ reflexivity
+ | intros.
+ rewrite < (sym_plus ? (m * n1)).
+ reflexivity
+ ]
+ | rewrite > (sym_times m n1).
+ apply H
+ ]
+]
+qed.
+
+theorem eq_sigma_p_sigma_p_times2 : \forall n,m:nat.\forall f:nat \to nat.
+sigma_p (n *m) (\lambda c:nat.true) f =
+sigma_p n (\lambda c:nat.true)
+ (\lambda a.(sigma_p m (\lambda c:nat.true) (\lambda b:nat.f (b* n + a)))).
+intros.
+rewrite > sym_times.
+apply eq_sigma_p_sigma_p_times1.
+qed.
+
+theorem sigma_p_times:\forall n,m:nat.
+\forall f,f1,f2:nat \to bool.
+\forall g:nat \to nat \to nat.
+\forall g1,g2: nat \to nat.
+(\forall a,b:nat. a < (S n) \to b < (S m) \to (g b a) < (S n)*(S m)) \to
+(\forall a,b:nat. a < (S n) \to b < (S m) \to (g1 (g b a)) = a) \to
+(\forall a,b:nat. a < (S n) \to b < (S m) \to (g2 (g b a)) = b) \to
+(\forall a,b:nat. a < (S n) \to b < (S m) \to f (g b a) = andb (f2 b) (f1 a)) \to
+(sigma_p ((S n) * (S m)) f (\lambda c:nat.(S O))) =
+sigma_p (S n) f1 (\lambda c:nat.(S O)) * sigma_p (S m) f2 (\lambda c:nat.(S O)).
+intros.
+
+rewrite > (sigma_P_SO_to_sigma_p_true ).
+rewrite > (S_pred ((S n)*(S m))) in \vdash (? ? (? % ? ?) ?)
+[ rewrite < (eq_map_iter_i_sigma_p_alwaysTrue (pred ((S n)* (S m)))).
+ rewrite > (permut_to_eq_map_iter_i plus assoc_plus sym_plus ? ? ?
+ (\lambda i.g (div i (S n)) (mod i (S n))))
+ [ rewrite > eq_map_iter_i_sigma_p_alwaysTrue.
+ rewrite < S_pred
+ [ rewrite > eq_sigma_p_sigma_p_times2.
+ apply (trans_eq ? ? (sigma_p (S n) (\lambda c:nat.true)
+ (\lambda a. sigma_p (S m) (\lambda c:nat.true)
+ (\lambda b.(bool_to_nat (f2 b))*(bool_to_nat (f1 a))))))
+ [ apply eq_sigma_p;intros
+ [ reflexivity
+ | apply eq_sigma_p;intros
+ [ reflexivity
+ |
+ rewrite > (div_mod_spec_to_eq (x1*(S n) + x) (S n) ((x1*(S n) + x)/(S n))
+ ((x1*(S n) + x) \mod (S n)) x1 x)
+ [ rewrite > (div_mod_spec_to_eq2 (x1*(S n) + x) (S n) ((x1*(S n) + x)/(S n))
+ ((x1*(S n) + x) \mod (S n)) x1 x)
+ [ rewrite > H3
+ [ apply bool_to_nat_andb
+ | assumption
+ | assumption
+ ]
+ | apply div_mod_spec_div_mod.
+ apply lt_O_S
+ | constructor 1
+ [ assumption
+ | reflexivity
+ ]
+ ]
+ | apply div_mod_spec_div_mod.
+ apply lt_O_S
+ | constructor 1
+ [ assumption
+ | reflexivity
+ ]
+ ]