proposition: Lemma refine_Iterate_Count_For_UnConstrQuery_In_QueryResultComp {m : nat} {qs_schema : RawQueryStructureSchema} {ResultT} (schemaIdx : Fin.t _) (body : @RawTuple _ -> Comp (list ResultT)) (attrIdx : Fin.t _) (a : Vector.t Type m) (a_proj_index : Vector.nth (AttrList (GetNRelSchemaHeading (qschemaSchemas qs_schema) schemaIdx)) attrIdx -> Fin.t m) (a_proj : forall (attr : Vector.nth _ attrIdx), a[@a_proj_index attr]) (a_inj : forall idx, Vector.nth a idx -> Vector.nth (AttrList (GetNRelSchemaHeading (qschemaSchemas qs_schema) schemaIdx)) attrIdx) (r_n : UnConstrQueryStructure qs_schema * UnConstrQueryStructure (DecomposeRawQueryStructureSchema qs_schema schemaIdx attrIdx a)) : refine (Count (For (Iterate_Equiv_QueryResultComp_body _ _ (GetUnConstrRelation (snd r_n)) (Tuple_DecomposeRawQueryStructure_inj' _ _ a a_inj) body))) (Iterate_Equiv_Count_For_UnConstrQuery_In_body schemaIdx body attrIdx a a_proj_index a_proj a_inj (snd r_n)).
proof: Proof. intros. unfold Iterate_Equiv_Count_For_UnConstrQuery_In_body. destruct r_n as [ r_n' r_n]. unfold UnConstrQuery_In. simpl. generalize (GetUnConstrRelation r_n). unfold DecomposeRawQueryStructureSchema; simpl. generalize ((Tuple_DecomposeRawQueryStructure_inj' schemaIdx attrIdx a a_inj)). simpl; clear. generalize (DecomposeSchema (qschemaSchemas qs_schema)[@schemaIdx] attrIdx a); clear. induction m; simpl; intros. - rewrite refine_For_List; rewrite refine_Count; simplify with monad laws; reflexivity. - revert i i0 IHm. pattern m, t; apply Vector.caseS; simpl; clear t; intros. setoid_rewrite <- (IHm t (fun idx => i (Fin.FS idx)) (fun idx => i0 (Fin.FS idx))). Local Transparent Query_For. Local Transparent Count. unfold Query_For. unfold Count. autorewrite with monad laws. clear; intros ? ?; computes_to_inv; subst. repeat computes_to_econstructor; eauto using Permutation_app. rewrite app_length. erewrite (Permutation_length H''''), Permutation_length; eauto using Permutation_app. Local Opaque Query_For. Local Opaque Count. Qed.
imports: Fiat.Common.Coq__8_4__8_5__Compat Coq.Vectors.Vector Coq.Strings.Ascii Coq.Bool.Bool Coq.Lists.List Fiat.Common.SumType Fiat.Computation.ListComputations Fiat.QueryStructure.Automation.AutoDB Bedrock.Word Bedrock.Memory