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