Require Export Coq.Sorting.Permutation.
Local Open Scope logic.
Inductive localdef : Type :=
| temp: ident -> val -> localdef
| lvar: ident -> type -> val -> localdef   (* local variable *)
| gvars: globals -> localdef.              (* global variables *)
Arguments temp i%positive v.
Definition lvar_denote (i: ident) (t: type) (v: val) rho :=
match Map.get (ve_of rho) i with
| Some (b, ty') => t=ty' /\ v = Vptr b Ptrofs.zero
| None => False
end.
Definition gvars_denote (gv: globals) rho :=
gv = (fun i => match Map.get (ge_of rho) i with Some b => Vptr b Ptrofs.zero | None => Vundef end).
Definition locald_denote (d: localdef) : environ -> Prop :=
match d with
| temp i v => `and (`(eq v) (eval_id i)) `(v <> Vundef)
| lvar i t v => lvar_denote i t v
| gvars gv => gvars_denote gv
end.
Fixpoint fold_right_andp rho (l: list (environ -> Prop)) : Prop :=
match l with
| nil => True
| b::nil => b rho
| b::r => b rho /\ fold_right_andp rho r
end.
Definition PROPx (P: list Prop): forall (Q: environ->mpred), environ->mpred :=
andp (prop (fold_right and True P)).
Notation "'PROP' ( x ; .. ; y )   z" := (PROPx (cons x%type .. (cons y%type nil) ..) z) (at level 10).
Notation "'PROP' ()   z" :=   (PROPx nil z) (at level 10).
Notation "'PROP' ( )   z" :=   (PROPx nil z) (at level 10).
Definition LOCALx (Q: list localdef) : forall (R: environ->mpred), environ->mpred :=
andp (local (fold_right (`and) (`True) (map locald_denote Q))).
Notation " 'LOCAL' ( )   z" := (LOCALx nil z)  (at level 9).
Notation " 'LOCAL' ()   z" := (LOCALx nil z)  (at level 9).
Notation " 'LOCAL' ( x ; .. ; y )   z" := (LOCALx (cons x%type .. (cons y%type nil) ..) z)
(at level 9).
Definition SEPx (R: list mpred) : environ->mpred :=
fun _ => (fold_right_sepcon R).
Arguments SEPx R _ : simpl never.
Notation " 'SEP' ( x ; .. ; y )" := (SEPx (cons x%logic .. (cons y%logic nil) ..))
(at level 8).
Notation " 'SEP' ( ) " := (SEPx nil) (at level 8).
Notation " 'SEP' () " := (SEPx nil) (at level 8).
Delimit Scope assert with assert.

Lemma LOCALx_Permutation: forall P Q,
Permutation P Q ->
LOCALx P = LOCALx Q.