let rec p_has_var xs = function
  | Papp(_,ts) -> List.exists (e_has_var xs) ts
  | Ptrue | Pfalse -> false
  | Pimplies(p,q) | Pand(p,q) | Por(p,q) | Piff(p,q) ->
      p_has_var xs p || p_has_var xs q
  | Pif(t,p,q) ->
      e_has_var xs t || p_has_var xs p || p_has_var xs q
  | Pnot p | Pnamed(_,p) -> p_has_var xs p
  | Pforall(x,p) | Pexists(x,p) ->
      let xs = List.filter (fun y -> not (Var.equal x y)) xs in
      xs <> [] && p_has_var xs p
  | Plet(x,a,p) ->
      e_has_var xs a ||
        (let xs = List.filter (fun y -> not (Var.equal x y)) xs in
         xs <> [] && p_has_var xs p)