@@ -147,6 +147,12 @@ let hoarecmp_opp cmp =
147147 | FHeq -> FHeq
148148 | FHge -> FHle
149149
150+ (* -------------------------------------------------------------------- *)
151+ let string_of_quant = function
152+ | Lforall -> " forall"
153+ | Lexists -> " exists"
154+ | Llambda -> " fun"
155+
150156(* -------------------------------------------------------------------- *)
151157let mk_form = EcAst. mk_form
152158let f_node { f_node = form } = form
@@ -601,41 +607,63 @@ exception DestrError of string
601607let destr_error e = raise (DestrError e)
602608
603609(* -------------------------------------------------------------------- *)
604- let destr_forall1 f =
605- match f.f_node with
606- | Fquant (Lforall,(x ,t )::bd ,p ) -> x,t,f_forall bd p
607- | _ -> destr_error " forall"
608-
609- let destr_forall f =
610+ let decompose_binder ?(bound : int option ) ~(quantif : quantif ) (f : form ) =
610611 match f.f_node with
611- | Fquant (Lforall,bd ,p ) -> bd, p
612- | _ -> destr_error " forall"
613-
614- let decompose_forall f =
615- match f.f_node with
616- | Fquant (Lforall,bd ,p ) -> bd, p
617- | _ -> [] , f
612+ | Fquant (q , bds , f ) when q = quantif -> begin
613+ match bound with
614+ | None ->
615+ bds, f
616+ | Some bound ->
617+ let bound = min bound (List. length bds) in
618+ let bd1, bd2 = List. takedrop bound bds in
619+ (bd1, f_quant quantif bd2 f)
620+ end
618621
619- let destr_lambda f =
620- match f.f_node with
621- | Fquant (Llambda,bd ,p ) -> bd, p
622- | _ -> destr_error " lambda"
622+ | _ ->
623+ ([] , f)
623624
624- let decompose_lambda f =
625- match f.f_node with
626- | Fquant (Llambda,bd ,p ) -> bd, p
627- | _ -> [] , f
625+ let decompose_forall ?(bound : int option ) (f : form ) =
626+ decompose_binder ?bound ~quantif: Lforall f
628627
629- let destr_exists1 f =
630- match f.f_node with
631- | Fquant (Lexists,(x ,t )::bd ,p ) -> x,t,f_exists bd p
632- | _ -> destr_error " exists"
628+ let decompose_exists ?(bound : int option ) (f : form ) =
629+ decompose_binder ?bound ~quantif: Lexists f
633630
634- let destr_exists f =
635- match f.f_node with
636- | Fquant (Lexists,bd ,p ) -> bd, p
637- | _ -> destr_error " exists"
631+ let decompose_lambda ?(bound : int option ) (f : form ) =
632+ decompose_binder ?bound ~quantif: Llambda f
633+
634+ (* -------------------------------------------------------------------- *)
635+ let destr_binder ?(bound : int option ) ~quantif :quantif (f : form ) =
636+ let bds, f = decompose_binder ?bound ~quantif f in
637+
638+ if 0 < Option. value ~default: 1 bound && List. is_empty bds then
639+ destr_error (string_of_quant quantif);
640+ bds, f
641+
642+ let destr_forall ?(bound : int option ) (f : form ) =
643+ destr_binder ?bound ~quantif: Lforall f
644+
645+ let destr_exists ?(bound : int option ) (f : form ) =
646+ destr_binder ?bound ~quantif: Lexists f
647+
648+ let destr_lambda ?(bound : int option ) (f : form ) =
649+ destr_binder ?bound ~quantif: Llambda f
638650
651+ (* -------------------------------------------------------------------- *)
652+ let destr_binder1 ~quantif :quantif (f : form ) =
653+ let (x, t), f =
654+ fst_map as_seq1 (destr_binder ~bound: 1 ~quantif f)
655+ in (x, t, f)
656+
657+ let destr_forall1 (f : form ) =
658+ destr_binder1 ~quantif: Lforall f
659+
660+ let destr_exists1 (f : form ) =
661+ destr_binder1 ~quantif: Lexists f
662+
663+ let destr_lambda1 (f : form ) =
664+ destr_binder1 ~quantif: Llambda f
665+
666+ (* -------------------------------------------------------------------- *)
639667let destr_let f =
640668 match f.f_node with
641669 | Flet (lp , e1 ,e2 ) -> lp,e1,e2
0 commit comments