diff --git a/CHANGES.md b/CHANGES.md
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -2,6 +2,33 @@
 
 ## NEXT
 
+## 0.9.6.3.8 (2026-12-01)
+
+- Avoid coercions between types with the same representation
+  [#848](https://github.com/ucsd-progsys/liquid-fixpoint/pull/864)
+- Remove unused parameter cmpFun of Language.Fixpoint.Parse.bops
+  [#850](https://github.com/ucsd-progsys/liquid-fixpoint/pull/850)
+- Support unicode syntax in operator names
+  [#853](https://github.com/ucsd-progsys/liquid-fixpoint/pull/853)
+- Add bv128/int conversions
+  [#856](https://github.com/ucsd-progsys/liquid-fixpoint/pull/856)
+- Expose `assert` mechanism to pass axioms on to SMT solver.
+  [#857](https://github.com/ucsd-progsys/liquid-fixpoint/pull/857)
+- Allow kvars with no arguments
+  [#860](https://github.com/ucsd-progsys/liquid-fixpoint/pull/860)
+- Keep unification predicative: instantiate FAbs before binding a  sort variable
+  [#861](https://github.com/ucsd-progsys/liquid-fixpoint/pull/861)
+- Sort-check qualifiers against the global environment
+  [#862](https://github.com/ucsd-progsys/liquid-fixpoint/pull/862)
+- Add lfMod/lfDiv desugaring and let frontends pick their division operators
+  [#863](https://github.com/ucsd-progsys/liquid-fixpoint/pull/863)
+- Add `--solver-path` to set the executable of the SMT solver instead of looking up its name in `PATH`
+  [#864](https://github.com/ucsd-progsys/liquid-fixpoint/pull/864)
+- Upgrade to rest-rewrite-0.5.0
+  [#865](https://github.com/ucsd-progsys/liquid-fixpoint/pull/865)
+- Rename `Language.Fixpoint.Solver.Rewrite.unify` to `matchExpr`
+  [#867](https://github.com/ucsd-progsys/liquid-fixpoint/pull/867)
+
 ## 0.9.6.3.7 (2026-06-04)
 
 - Migrate from cmdargs to base:System.Console.GetOpt
diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -315,6 +315,43 @@
   f @b : {v1:[b] | $k_##42[@a:=b][v:=v1] }
 ```
 
+* Additionally, the Horn format allows specifying kvars as follows
+
+```
+(var $k (Int Int Bool Int Int) :self 3)
+```
+
+This defines a `KVar` named `$k` over 5 "variables"  (in quotes because I'm making up the names)
+
+- "self" variables: `v1:Int`, `v2:Int`, `v3:Bool`
+- "other" variables: `x:Int`, `y:Int`
+
+The self/other distinction is relevant for qualifiers.
+
+We use the "self" variables only to match the _first_ parameter of a qualifier. So given a qualifier
+
+```
+qualif Q(v:a, z:a): v <= z
+```
+
+will "match" `v` with any of the _self_ variables  `v1`, `v2`, `v3` and match `z`
+with any of the _other_ variables, so the instantiations will be
+
+```
+┌─────────────────┬──────────────┬────────────────────┬─────────────────────────────────────────────┐
+│ First slot sort │ First slot x │ Later slot ys from │                   Results                   │
+├─────────────────┼──────────────┼────────────────────┼─────────────────────────────────────────────┤
+│ a := int        │ v1, v2       │ {x, y, v1, v2}     │ [v1,x] [v1,y] [v1,v2] [v2,x] [v2,y] [v2,v1] │
+├─────────────────┼──────────────┼────────────────────┼─────────────────────────────────────────────┤
+│ a := bool       │ v3           │ {v3}               │ none ([v3,v3] is removed by the guard)      │
+└─────────────────┴──────────────┴────────────────────┴─────────────────────────────────────────────┘
+```
+
+where the `v3` match is pruned because `v` and `z` must be distinct.
+
+NOTE: the "distinct" requirement and the special-casing of the "first" parameter is to minimize
+redundant or invalid instantiations of qualifiers.
+
 ### Global vs. Distinct Literals
 
 ```
diff --git a/liquid-fixpoint.cabal b/liquid-fixpoint.cabal
--- a/liquid-fixpoint.cabal
+++ b/liquid-fixpoint.cabal
@@ -1,6 +1,6 @@
 cabal-version:      2.4
 name:               liquid-fixpoint
-version:            0.9.6.3.7
+version:            0.9.6.3.8
 synopsis:           Predicate Abstraction-based Horn-Clause/Implication Constraint Solver
 description:
   This package implements an SMTLIB based Horn-Clause\/Logical Implication constraint
@@ -92,7 +92,6 @@
                     Language.Fixpoint.Solver.Solution
                     Language.Fixpoint.Solver.Solve
                     Language.Fixpoint.Solver.Stats
-                    Language.Fixpoint.Solver.TrivialSort
                     Language.Fixpoint.Solver.UniqifyBinds
                     Language.Fixpoint.Solver.UniqifyKVars
                     Language.Fixpoint.Solver.Worklist
@@ -150,7 +149,7 @@
                   , parser-combinators
                   , pretty               >= 1.1.3.1
                   , process
-                  , rest-rewrite >= 0.3.0
+                  , rest-rewrite ^>= 0.5
                   , smtlib-backends >= 0.3
                   , smtlib-backends-process >= 0.3
                   , stm
diff --git a/src/Language/Fixpoint/Defunctionalize.hs b/src/Language/Fixpoint/Defunctionalize.hs
--- a/src/Language/Fixpoint/Defunctionalize.hs
+++ b/src/Language/Fixpoint/Defunctionalize.hs
@@ -152,9 +152,8 @@
 
 instance Defunc (WfC a) where
   defunc wf@WfC{} = do
-    let (x, t, k) = wrft wf
-    t' <- defunc t
-    return $ wf { wrft = (x, t', k) }
+    vvs' <- mapM (traverse defunc) (wvvs wf)
+    return $ wf { wvvs = vvs' }
 
 instance Defunc SortedReft where
   defunc (RR s r) = RR s <$> defunc r
diff --git a/src/Language/Fixpoint/Horn/Info.hs b/src/Language/Fixpoint/Horn/Info.hs
--- a/src/Language/Fixpoint/Horn/Info.hs
+++ b/src/Language/Fixpoint/Horn/Info.hs
@@ -30,6 +30,7 @@
   , F.hoInfo    = F.cfgHoInfo cfg
   , F.defns     = F.MkDefinedFuns (H.qDefs q)
   , F.kuts      = F.KS (S.fromList (H.qKuts q))
+  , F.asserts   = H.qAxioms q
   }
   where
     be0         = F.emptyBindEnv
@@ -125,12 +126,13 @@
 kvInfo be k       = (be', KVInfo k (Misc.fst3 <$> xts) wfc)
   where
     -- make the WfC
-    wfc           = F.WfC wenv wrft (H.hvMeta k)
+    wfc           = F.WfC wenv vvs (F.KV (H.hvName k)) (H.hvMeta k)
     wenv          = F.fromListIBindEnv ids
-    wrft          = (x, t, F.KV (H.hvName k))
+    -- the self parameters are the value variables, and the rest are binders
+    vvs           = [ (x, t) | (x, t, _) <- selfs ]
+    (selfs, xts') = splitAt (H.hvSelf k) xts
     -- add the binders
     (be', ids)    = L.mapAccumL insertBE be xts'
-    ((x,t,_), xts') = Misc.safeUncons "Horn var with no args" xts
     -- make the parameters
     xts           = [ (hvarArg k i, t', a) | (t', i) <- zip (H.hvArgs k) [0..] ]
     a             = H.hvMeta k
@@ -215,7 +217,7 @@
 qualParams :: BindEnv -> F.Expr -> [(F.Symbol, F.Sort)]
 qualParams env e = [ (x, t) | (_, x, t) <- L.sortBy (comparing Down) ixts ]
   where
-    xs = Misc.nubOrd (F.syms e)
+    xs = S.toList (F.syms e)
     ixts = [ (i, x, t) | x <- xs, (t, i) <- Mb.maybeToList (lookupBindEnv x env) ]
 
 -------------------------------------------------------------------------------
diff --git a/src/Language/Fixpoint/Horn/Parse.hs b/src/Language/Fixpoint/Horn/Parse.hs
--- a/src/Language/Fixpoint/Horn/Parse.hs
+++ b/src/Language/Fixpoint/Horn/Parse.hs
@@ -19,6 +19,7 @@
 import qualified Data.HashMap.Strict            as M
 import qualified Data.Text as T
 import qualified Text.Megaparsec.Char.Lexer  as L
+import           Control.Monad                  (when)
 
 type FParser = FP.Parser
 
@@ -138,6 +139,7 @@
   , H.qOpts  =              [ o     | HOpt o   <- things ]
   , H.qNums  =              [ s     | HNum s   <- things ]
   , H.qKuts  =              [ k     | HKut k   <- things ]
+  , H.qAxioms =             [ a     | HAxm a   <- things ]
   }
 
 -- | A @HThing@ describes the kinds of things we may see, in no particular order
@@ -158,6 +160,7 @@
   | HOpt !String
   | HNum  F.Symbol
   | HKut  F.KVar
+  | HAxm  (F.Triggered F.Expr)
   deriving (Functor)
 
 hThingP :: FParser (HThing H.Tag)
@@ -175,7 +178,21 @@
         <|> HDat  <$> (reserved "datatype"   *> dataDeclP)
         <|> HNum  <$> (reserved "numeric"    *> numericDeclP)
         <|> HKut  <$> (reserved "cut"        *> FP.kvarP)
+        <|> HAxm  <$> (reserved "axiom"      *> axiomP)
 
+-- | An axiom is an expression that is sort-checked, elaborated and then
+--   asserted to the SMT solver. Quantified axioms may specify SMTLIB-style
+--   instantiation patterns:
+--
+--   > (axiom (forall ((x Int) (y Int)) (! (= (f x y) (+ x y)) :pattern ((f x y)))))
+axiomP :: FParser (F.Triggered F.Expr)
+axiomP =  try (parens (reserved "forall" *> (mkAxiom <$> bindsP <*> parens triggeredP)))
+      <|> F.noTrigger <$> exprP
+  where
+    triggeredP          = sym "!" *> ((,) <$> exprP <*> some patternP)
+    patternP            = sym ":pattern" *> parens (some exprP)
+    mkAxiom xts (e, ps) = F.TR (F.Patterns ps) (F.PAll xts e)
+
 numericDeclP :: FParser F.Symbol
 numericDeclP = do
   x <- F.val <$> locUpperIdP
@@ -202,7 +219,7 @@
 -------------------------------------------------------------------------------
 hPredP = parens body
   where
-    body =  H.Var  <$> kvSymP <*> some exprP
+    body =  H.Var  <$> kvSymP <*> many exprP
         <|> H.PAnd <$> (reserved "and" *> some hPredP)
         <|> H.Reft <$> exprP
 
@@ -230,7 +247,18 @@
 -------------------------------------------------------------------------------
 
 hVarP :: FParser (H.Var H.Tag)
-hVarP = H.HVar <$> kvSymP <*> parens (some sortP) <*> pure H.NoTag
+hVarP = do
+  k    <- kvSymP
+  ts   <- parens (many sortP)
+  self <- selfP (min 1 (length ts))
+  when (self < 0 || self > length ts) $
+    fail $ "variable $" ++ F.symbolString k ++ " has " ++ show (length ts)
+        ++ " parameters, so :self must be between 0 and " ++ show (length ts)
+  return $ H.HVar k ts self H.NoTag
+
+-- | Parses an optional @:self n@ annotation, returning the given default when absent.
+selfP :: Int -> FParser Int
+selfP def = option def (reserved ":self" *> fIntP)
 
 -------------------------------------------------------------------------------
 -- | Helpers
diff --git a/src/Language/Fixpoint/Horn/Transformations.hs b/src/Language/Fixpoint/Horn/Transformations.hs
--- a/src/Language/Fixpoint/Horn/Transformations.hs
+++ b/src/Language/Fixpoint/Horn/Transformations.hs
@@ -641,7 +641,7 @@
     thySyms = F.theorySymbols (F.solver cfg)
 
     isWellFormed :: F.Expr -> Bool
-    isWellFormed e = S.fromList (F.syms e) `S.isSubsetOf` argsAndPrims
+    isWellFormed e = S.fromList (HS.toList $ F.syms e) `S.isSubsetOf` argsAndPrims
 
     makeWellFormed :: Int -> [F.Expr] -> [F.Expr]
     makeWellFormed 0 exprs = filter isWellFormed exprs -- We solved it. Maybe.
@@ -649,7 +649,7 @@
       where
         go expr = if isWellFormed expr then [expr] else rewrite rewrites [expr]
           where
-            needSolving = S.fromList (F.syms expr) `S.difference` argsAndPrims
+            needSolving = S.fromList (HS.toList $ F.syms expr) `S.difference` argsAndPrims
             rewrites = (\x -> (x, filter (/= F.EVar x) $ sols x)) <$> S.toList needSolving
             rewrite [] es = es
             rewrite ((x, rewriteExprs):rewriteExprs') es = rewrite rewriteExprs' $ [F.subst (F.mkSubst [(x, e')]) e | e' <- rewriteExprs, e <- es]
diff --git a/src/Language/Fixpoint/Horn/Types.hs b/src/Language/Fixpoint/Horn/Types.hs
--- a/src/Language/Fixpoint/Horn/Types.hs
+++ b/src/Language/Fixpoint/Horn/Types.hs
@@ -43,10 +43,10 @@
 import qualified Data.Text               as T
 import           Data.Maybe (fromMaybe)
 import qualified Data.List               as L
-import qualified Language.Fixpoint.Misc  as Misc
 import qualified Language.Fixpoint.Types as F
 import qualified Text.PrettyPrint.HughesPJ.Compat as P
 import qualified Data.HashMap.Strict as M
+import qualified Data.HashSet as S
 import           Data.Aeson
 import           Data.Aeson.Types
 
@@ -55,7 +55,8 @@
 -------------------------------------------------------------------------------
 data Var a = HVar
   { hvName :: !F.Symbol                         -- ^ name of the variable $k1, $k2 etc.
-  , hvArgs :: ![F.Sort] {- len hvArgs > 0 -}    -- ^ sorts of its parameters i.e. of the relation defined by the @HVar@
+  , hvArgs :: ![F.Sort]                         -- ^ sorts of its parameters i.e. of the relation defined by the @HVar@
+  , hvSelf :: !Int {- 0 <= hvSelf <= len hvArgs -} -- ^ number of leading parameters that are self parameters
   , hvMeta :: a                                 -- ^ meta-data
   }
   deriving (Eq, Ord, Data, Typeable, Generic, Functor, ToJSON, FromJSON)
@@ -72,7 +73,7 @@
   deriving (Data, Typeable, Generic, Eq, ToJSON, FromJSON)
 
 instance F.ToHornSMT (Var a) where
-  toHornSMT (HVar k ts _) = P.parens ("var" P.<+> "$" P.<-> F.pprint k P.<+> F.toHornSMT ts)
+  toHornSMT (HVar k ts n _) = P.parens ("var" P.<+> "$" P.<-> F.pprint k P.<+> F.toHornSMT ts P.<+> ppSelf n)
 instance F.ToHornSMT Pred where
   toHornSMT (Reft p)   = P.parens (F.toHornSMT p)
   toHornSMT (Var k xs) = F.toHornMany (F.toHornSMT (F.KV k) : (F.toHornSMT <$> xs))
@@ -80,24 +81,12 @@
 
 instance F.Subable Pred where
   syms (Reft e)   = F.syms e
-  syms (Var _ xs) = concatMap F.syms xs
-  syms (PAnd ps)  = concatMap F.syms ps
-
-  substa f (Reft e)   = Reft  (F.substa f      e)
-  substa f (Var k xs) = Var k (F.substa f <$> xs)
-  substa f (PAnd ps)  = PAnd  (F.substa f <$> ps)
-
-  subst su (Reft  e)  = Reft  (F.subst su      e)
-  subst su (PAnd  ps) = PAnd  (F.subst su <$> ps)
-  subst su (Var k xs) = Var k (F.subst su <$> xs)
-
-  substf f (Reft  e)  = Reft  (F.substf f      e)
-  substf f (PAnd  ps) = PAnd  (F.substf f <$> ps)
-  substf f (Var k xs) = Var k (F.substf f <$> xs)
+  syms (Var _ xs) = F.syms xs
+  syms (PAnd ps)  = F.syms ps
 
-  subst1 (Reft  e)  su = Reft  (F.subst1 e su)
-  subst1 (PAnd  ps) su = PAnd  [F.subst1 p su | p <- ps]
-  subst1 (Var k xs) su = Var k [F.subst1 x su | x <- xs]
+  substr ns su (Reft  e)  = Reft  (F.substr ns su      e)
+  substr ns su (PAnd  ps) = PAnd  (F.substr ns su <$> ps)
+  substr ns su (Var k xs) = Var k (F.substr ns su <$> xs)
 
 -------------------------------------------------------------------------------
 quals :: Cstr a -> [F.Qualifier]
@@ -131,7 +120,7 @@
                    (_,so):xts -> F.mkQ "Auto" ((v, so) : xts) p junk
                    _          -> F.panic "impossible"
   where
-    xs         = L.delete v $ Misc.setNub (F.syms p)
+    xs         = S.toList $ S.delete v $ F.syms p
     junk       = F.dummyPos "mkQual"
 
 envSort :: F.SEnv F.Sort -> F.Symbol -> (F.Symbol, F.Sort)
@@ -163,11 +152,11 @@
   toHornSMT (Bind x t p _) = P.parens (F.toHornSMT (x, t) P.<+> F.toHornSMT p)
 
 instance F.Subable (Bind a) where
-    syms     (Bind x _ p _) = x : F.syms p
-    substa f (Bind v t p a) = Bind (f v) t (F.substa f p) a
-    substf f (Bind v t p a) = Bind v t (F.substf (F.substfExcept f [v]) p) a
-    subst su (Bind v t p a)  = Bind v t (F.subst (F.substExcept su [v]) p) a
-    subst1 (Bind v t p a) su = Bind v t (F.subst1Except [v] p su) a
+    syms     (Bind x _ p _) = S.insert x $ F.syms p
+    substr ns su (Bind v t p a) =
+      let (ns', v') = F.freshInNS v ns
+       in
+          Bind v t (F.substr ns' (F.extendSubstWithVar su v v') p) a
 
 -- Can we enforce the invariant that CAnd has len > 1?
 data Cstr a
@@ -218,6 +207,7 @@
   , qOpts  :: ![String]                  -- ^ list of fixpoint options
   , qNums  :: ![F.Symbol]                -- ^ list of numeric TyCon (?)
   , qKuts  :: ![F.KVar]                  -- ^ list of cut variables
+  , qAxioms :: ![F.Triggered F.Expr]     -- ^ list of axioms, to be asserted to the SMT solver
   }
   deriving (Data, Typeable, Generic, Functor, ToJSON, FromJSON)
 
@@ -283,9 +273,14 @@
     ppArg qp    = P.parens $ F.pprint (F.qpSym qp) P.<+> P.parens (F.pprint (F.qpSort qp))
 
 ppVar :: Var a -> P.Doc
-ppVar (HVar k ts _)  = P.parens ("var" P.<+> "$" P.<-> F.pprint k P.<+> ppBlanks (P.parens . F.pprint <$> ts))
+ppVar (HVar k ts n _)  = P.parens ("var" P.<+> "$" P.<-> F.pprint k P.<+> ppBlanks (P.parens . F.pprint <$> ts) P.<+> ppSelf n)
 
+-- | Prints the @:self@ annotation of a kvar, omitted when it is 1.
+ppSelf :: Int -> P.Doc
+ppSelf 1 = mempty
+ppSelf n = ":self" P.<+> P.int n
 
+
 ppBlanks :: [P.Doc] -> P.Doc
 ppBlanks ds = P.parens (P.hcat (L.intersperse " " ds))
 
@@ -296,7 +291,7 @@
 parens s = "(" ++ s ++ ")"
 
 instance Show (Var a) where
-  show (HVar k xs _) = show k ++ parens (unwords (show <$> xs))
+  show (HVar k xs _ _) = show k ++ parens (unwords (show <$> xs))
 
 instance Show Pred where
   show (Reft p)   = parens $ F.showpp p
@@ -340,9 +335,18 @@
     , P.vcat   (F.eqnToHornSMT "define_fun" <$> qDefs q)
     , P.vcat   (F.toHornSMT <$> qData q)
     , P.vcat   (F.toHornSMT <$> qMats q)
+    , P.vcat   (toHornAxiom <$> qAxioms q)
     , P.parens (P.vcat ["constraint", P.nest 1 (F.toHornSMT (qCstr q))])
     ]
     where
       toHornNum x   = F.toHornMany ["numeric", F.toHornSMT x]
       toHornOpt str = F.toHornMany ["fixpoint", P.text ("\"" ++ str ++ "\"")]
       toHornCon x t = F.toHornMany ["constant", F.toHornSMT x, F.toHornSMT t]
+
+toHornAxiom :: F.Triggered F.Expr -> P.Doc
+toHornAxiom (F.TR (F.Patterns ps@(_:_)) (F.PAll xts e))
+  = F.toHornMany ["axiom", F.toHornMany ["forall", F.toHornSMT xts, body]]
+  where
+    body = F.toHornMany ("!" : F.toHornSMT e : [":pattern" P.<+> F.toHornSMT p | p <- ps])
+toHornAxiom (F.TR _ e)
+  = F.toHornMany ["axiom", F.toHornSMT e]
diff --git a/src/Language/Fixpoint/Misc.hs b/src/Language/Fixpoint/Misc.hs
--- a/src/Language/Fixpoint/Misc.hs
+++ b/src/Language/Fixpoint/Misc.hs
@@ -18,7 +18,6 @@
 import           Control.Monad                    (when, forM_, filterM)
 import qualified Data.HashMap.Strict              as M
 import qualified Data.List                        as L
-import qualified Data.HashSet                     as S
 import qualified Data.Map                         as Map
 import qualified Data.Set                         as Set
 import           Data.Tuple                       (swap)
@@ -395,14 +394,6 @@
 
 powerset :: [a] -> [[a]]
 powerset xs = filterM (const [False, True]) xs
-
--- Null if first is a subset of second
-nubDiff :: (Eq a, Hashable a) => [a] -> [a] -> S.HashSet a
-nubDiff a b = a' `S.difference` b'
-  where
-    a' = S.fromList a
-    b' = S.fromList b
-
 
 fold1M :: (Monad m) => (a -> a -> m a) -> [a] -> m a
 fold1M _ []         = errorstar "fold1M with empty list"
diff --git a/src/Language/Fixpoint/Parse.hs b/src/Language/Fixpoint/Parse.hs
--- a/src/Language/Fixpoint/Parse.hs
+++ b/src/Language/Fixpoint/Parse.hs
@@ -103,6 +103,7 @@
   , isNotReserved
 
   , initPState, PState, PStateV (..)
+  , bops, fixpointOps
 
   , LayoutStack(..)
   , Fixity(..), Assoc(..), addOperatorP, addNumTyCon
@@ -434,7 +435,7 @@
 semi   = sym ";"
 comma  = sym ","
 colon  = sym ":" -- Note: not a reserved symbol; use with care
-dcolon = sym "::" -- Note: not a reserved symbol; use with care
+dcolon = sym "::"<|> maybe empty sym (unicodeAlias "::") -- Note: not a reserved symbol; use with care
 dot    = sym "." -- Note: not a reserved symbol; use with care
 
 -- | Parses a block via layout or explicit braces and semicolons.
@@ -546,6 +547,8 @@
   , "|-"
   , "::"
   , "."
+  -- unicode aliases
+  , "∷", "⇒", "→"
   ]
 
 {-
@@ -601,13 +604,24 @@
 -- list of reserved operators.
 --
 reservedOp :: String -> ParserV v ()
-reservedOp x =
-  void $ lexeme (try (string x <* notFollowedBy opLetter))
+reservedOp x = lexeme $ case unicodeAlias x of
+  Nothing -> reservedOpSingle x
+  Just y  -> reservedOpSingle x <|> reservedOpSingle y
 
+reservedOpSingle :: String -> ParserV v ()
+reservedOpSingle x = void $ try (string x <* notFollowedBy opLetter)
+
 reservedOp' :: Parser () -> String -> Parser ()
-reservedOp' spacesP x =
-  void $ lexeme' spacesP (try (string x <* notFollowedBy opLetter))
+reservedOp' spacesP x = lexeme' spacesP $ case unicodeAlias x of
+  Nothing -> reservedOpSingle x
+  Just y  -> reservedOpSingle x <|> reservedOpSingle y
 
+{-# INLINE unicodeAlias #-}
+unicodeAlias :: String -> Maybe String
+unicodeAlias "::" = Just "∷" -- U+2237
+unicodeAlias "=>" = Just "⇒" -- U+21D2
+unicodeAlias "->" = Just "→" -- U+2192
+unicodeAlias _   = Nothing
 
 -- | Parser that consumes the given symbol.
 --
@@ -933,19 +947,20 @@
 initOpTable :: OpTable v
 initOpTable = IM.empty
 
--- | Built-in operator table, parameterised over the composition function.
-bops :: forall v. ParseableV v => Maybe (Located String -> ExprV v) -> OpTable v
-bops cmpFun = List.foldl' (flip addOperator) initOpTable builtinOps
+-- | Built-in operator table, extended with the given extra operators.
+--
+-- The division-like operators differ between front-ends, so they are passed
+-- in: see 'fixpointOps' for the fixpoint CLI default.
+bops :: forall v. ParseableV v => [Fixity v] -> OpTable v
+bops extraOps = List.foldl' (flip addOperator) initOpTable (builtinOps ++ extraOps)
   where
     -- Built-in Haskell operators, see https://www.haskell.org/onlinereport/decls.html#fixity
     builtinOps :: [Fixity v]
     builtinOps = [ FPrefix (Just 9) "-"   (Just $ const ENeg)
                  , FInfix  (Just 7) "*"   (Just $ const $ EBin Times) AssocLeft
-                 , FInfix  (Just 7) "/"   (Just $ const $ EBin Div)   AssocLeft
                  , FInfix  (Just 6) "-"   (Just $ const $ EBin Minus) AssocLeft
                  , FInfix  (Just 6) "+"   (Just $ const $ EBin Plus)  AssocLeft
-                 , FInfix  (Just 5) "mod" (Just $ const $ EBin Mod)   AssocLeft -- Haskell gives mod 7
-                 , FInfix  (Just 9) "."   applyCompose        AssocRight
+                 , FInfix  (Just 9) "."   Nothing                     AssocRight
                 --  --
                  , FInfix  (Just 4) "=="  (Just $ const $ PAtom Eq)  AssocNone
                  , FInfix  (Just 4) "="   (Just $ const $ PAtom Eq)  AssocNone
@@ -966,8 +981,12 @@
                  , FPrefix (Just 9) "~"   (Just $ const PNot)
                  ]
 
-    applyCompose :: Maybe (Located String -> ExprV v -> ExprV v -> ExprV v)
-    applyCompose = (\f lop x y -> f lop `eApps` [x,y]) <$> cmpFun
+-- | Division-like operators used by the fixpoint front-end: infix @/@ is
+-- integer division and infix @mod@ is modulus.
+fixpointOps :: [Fixity v]
+fixpointOps = [ FInfix (Just 7) "/"   (Just $ const $ EBin Div) AssocLeft
+              , FInfix (Just 5) "mod" (Just $ const $ EBin Mod) AssocLeft -- Haskell gives mod 7
+              ]
 
 -- | Parser for function applications.
 funAppP :: ParseableV v => ParserV v (ExprV v)
@@ -1407,7 +1426,7 @@
     cm         = Misc.safeFromList
                    "defs-cm"        [(cid c, c)         | Cst c       <- defs]
     ws         = Misc.safeFromList
-                   "defs-ws"        [(i, w)              | Wfc w    <- defs, let i = Misc.thd3 (wrft w)]
+                   "defs-ws"        [(wkvar w, w)        | Wfc w    <- defs]
     bs         = bindEnvFromList    [(n,(x,r,a)) | IBind n x r a <- defs]
     lts        = fromListSEnv       [(x, t)             | Con x t     <- defs]
     dts        = fromListSEnv       [(x, t)             | Dis x t     <- defs]
@@ -1464,12 +1483,8 @@
 -- | Initial parser state.
 initPState
   :: ParseableV v
-  -- The expression to produce when the composition operator is parsed (@f . g@)
-  --
-  -- Receives the location of the composition operator.
-  => Maybe (Located String -> ExprV v)
-  -> PStateV v
-initPState cmpFun = PState { fixityTable = bops cmpFun
+  => PStateV v
+initPState = PState { fixityTable = bops fixpointOps
                            , empList     = Nothing
                            , singList    = Nothing
                            , fixityOps   = []
@@ -1489,7 +1504,7 @@
 
 doParse'' :: Bool -> Parser a -> SourceName -> String -> a
 doParse'' allowEx parser fileName input =
-  case runParser (evalStateT (spaces *> parser <* eof) ((initPState Nothing) { allowExists = allowEx})) fileName input of
+  case runParser (evalStateT (spaces *> parser <* eof) (initPState { allowExists = allowEx})) fileName input of
     Left peb@(ParseErrorBundle errors posState) -> -- parse errors; we extract the first error from the error bundle
       let
         ((_, pos) :| _, _) = attachSourcePos errorOffset errors posState
@@ -1504,7 +1519,7 @@
 -- | Function to test parsers interactively.
 parseTest' :: Show a => Parser a -> String -> IO ()
 parseTest' parser input =
-  parseTest (evalStateT parser (initPState Nothing)) input
+  parseTest (evalStateT parser initPState) input
 
 -- errorSpan :: ParseError -> SrcSpan
 -- errorSpan e = SS l l where l = errorPos e
diff --git a/src/Language/Fixpoint/Smt/Interface.hs b/src/Language/Fixpoint/Smt/Interface.hs
--- a/src/Language/Fixpoint/Smt/Interface.hs
+++ b/src/Language/Fixpoint/Smt/Interface.hs
@@ -65,7 +65,7 @@
     ) where
 
 import           Language.Fixpoint.Types.Config ( SMTSolver (..), solverFlags
-                                                , Config (solver, smtTimeout, noStringTheory, save, saveDir, allowHO))
+                                                , Config (solver, solverPath, smtTimeout, noStringTheory, save, saveDir, allowHO))
 import qualified Language.Fixpoint.Misc          as Misc
 import           Language.Fixpoint.Types.Errors
 import           Language.Fixpoint.Utils.Files
@@ -313,25 +313,27 @@
 makeContext' :: Config -> Maybe Handle -> IO Context
 makeContext' cfg ctxLog
   = do let slv = solver cfg
+           -- The solver's executable, by default its name looked up in PATH
+           exe name = fromMaybe name (solverPath cfg)
        (backend, closeIO) <- case slv of
          Z3      ->
            {- "z3 -smt2 -in"                   -}
            {- "z3 -smtc SOFT_TIMEOUT=1000 -in" -}
            {- "z3 -smtc -in MBQI=false"        -}
            makeProcess ctxLog $ Process.defaultConfig
-                             { Process.exe = "z3"
+                             { Process.exe = exe "z3"
                              , Process.args = ["-smt2", "-in"] }
          Z3mem   -> Conditional.Z3.makeZ3
          Mathsat -> makeProcess ctxLog $ Process.defaultConfig
-                             { Process.exe = "mathsat"
+                             { Process.exe = exe "mathsat"
                              , Process.args = ["-input=smt2"] }
          Cvc4    -> makeProcess ctxLog $
                       Process.defaultConfig
-                             { Process.exe = "cvc4"
+                             { Process.exe = exe "cvc4"
                              , Process.args = ["-L", "smtlib2"] }
          Cvc5    -> makeProcess ctxLog $
                       Process.defaultConfig
-                             { Process.exe = "cvc5"
+                             { Process.exe = exe "cvc5"
                              , Process.args = ["-L", "smtlib2", "--arrays-exp"] }
        solver <- SMTLIB.Backends.initSolver SMTLIB.Backends.Queuing backend
        loud <- isLoud
@@ -455,8 +457,10 @@
 
 -----------------------------------------------------------------
 
-smtAssertAxiom :: Triggered Expr -> SmtM ()
-smtAssertAxiom p  = interact' (AssertAx p)
+-- | Uses `interactDecl'` so that any `apply`, `coerce` and `lambda` symbols
+--   used by the axiom are declared before it is asserted.
+smtAssertAxiom :: HasCallStack => Triggered Expr -> SmtM ()
+smtAssertAxiom p  = interactDecl' (AssertAx p)
 
 smtDistinct :: [Expr] -> SmtM ()
 smtDistinct az = interact' (Distinct az)
diff --git a/src/Language/Fixpoint/Smt/Serialize.hs b/src/Language/Fixpoint/Smt/Serialize.hs
--- a/src/Language/Fixpoint/Smt/Serialize.hs
+++ b/src/Language/Fixpoint/Smt/Serialize.hs
@@ -270,11 +270,15 @@
     (f, es) = splitEApp' e
 
 smt2Coerc :: Sort -> Sort -> Expr -> SymM Builder
-smt2Coerc t1 t2 e
-  | t1 == t2  = smt2 e
-  | otherwise = do coerceFn <- symbolAtName coerceName (FFunc t1 t2)
-                   s <- smt2 e
-                   pure $ parenSeqs [Builder.fromText coerceFn , s]
+smt2Coerc t1 t2 e = do
+  env <- get
+  let s1 = Thy.sortSmtSort False (seData env) t1
+      s2 = Thy.sortSmtSort False (seData env) t2
+  if s1 == s2 then smt2 e
+  else do
+    coerceFn <- symbolAtName coerceName (FFunc t1 t2)
+    s <- smt2 e
+    pure $ parenSeqs [Builder.fromText coerceFn , s]
 
 splitEApp' :: Expr -> (Expr, [Expr])
 splitEApp'            = go []
@@ -335,7 +339,7 @@
   smt2     (Comment t)         = pure $ fromText ("; " <> t <> "\n")
 
 instance SMTLIB2 (Triggered Expr) where
-  smt2 (TR NoTrigger e)       = smt2 e
+  smt2 (TR (Patterns []) e)   = smt2 e
   smt2 (TR _ (PExist [] p))   = smt2 p
   smt2 t@(TR _ (PExist xs p)) = smtTr "exists" xs p t
   smt2 (TR _ (PAll   [] p))   = smt2 p
@@ -347,8 +351,8 @@
 smtTr q xs p t =
   do s <- smt2s xs
      s1 <- smt2 p
-     s2 <- smt2s (makeTriggers t)
-     pure $ key q (parens s <+> key "!" (s1 <+> ":pattern" <> parens s2))
+     s2 <- traverse smt2s (triggerPatterns t)
+     pure $ key q (parens s <+> key "!" (seqs (s1 : [":pattern" <> parens pat | pat <- s2])))
 
 {-# INLINE smt2s #-}
 smt2s :: SMTLIB2 a => [a] -> SymM Builder
diff --git a/src/Language/Fixpoint/Smt/Theories.hs b/src/Language/Fixpoint/Smt/Theories.hs
--- a/src/Language/Fixpoint/Smt/Theories.hs
+++ b/src/Language/Fixpoint/Smt/Theories.hs
@@ -531,8 +531,10 @@
 
   , interpSym intbv32Name   "(_ int2bv 32)" (FFunc intSort bv32)
   , interpSym intbv64Name   "(_ int2bv 64)" (FFunc intSort bv64)
+  , interpSym intbv128Name  "(_ int2bv 128)" (FFunc intSort bv128)
   , interpSym bv32intName   (bv2i cfg 32)   (FFunc bv32    intSort)
   , interpSym bv64intName   (bv2i cfg 64)   (FFunc bv64    intSort)
+  , interpSym bv128intName  (bv2i cfg 128)  (FFunc bv128   intSort)
 
   , interpSym intbv8Name    "(_ int2bv 8)"  (FFunc intSort bv8)
   , interpSym intbv16Name   "(_ int2bv 16)" (FFunc intSort bv16)
@@ -582,6 +584,7 @@
     bv16       = sizedBitVecSort "Size16"
     bv32       = sizedBitVecSort "Size32"
     bv64       = sizedBitVecSort "Size64"
+    bv128      = sizedBitVecSort "Size128"
     boolInt    = boolToIntName
 
     mapDefSort = FAbs 0 $ FAbs 1 $ FFunc (FVar 1)
diff --git a/src/Language/Fixpoint/Solver.hs b/src/Language/Fixpoint/Solver.hs
--- a/src/Language/Fixpoint/Solver.hs
+++ b/src/Language/Fixpoint/Solver.hs
@@ -26,7 +26,6 @@
 
 import           Control.Concurrent                 (setNumCapabilities)
 import qualified Data.HashMap.Strict              as HashMap
-import qualified Data.HashSet                     as HashSet
 import qualified Data.Store                       as S
 import           Data.Aeson                         (ToJSON, encode)
 import qualified Data.Text.Lazy.IO                as LT
@@ -42,7 +41,7 @@
 import           Language.Fixpoint.Solver.Sanitize  (symbolEnv, sanitize)
 import           Language.Fixpoint.Solver.UniqifyBinds (renameAll)
 import           Language.Fixpoint.Defunctionalize (defunctionalize)
-import           Language.Fixpoint.SortCheck            (ElabParam (..), Elaborate (..), unElab, unElabFSetBagZ3)
+import           Language.Fixpoint.SortCheck            (ElabParam (..), Elaborate (..), unElab, unElabFSetBagZ3, theoryEnv)
 import           Language.Fixpoint.Solver.Extensionality (expand)
 import           Language.Fixpoint.Solver.Prettify (savePrettifiedQuery)
 import           Language.Fixpoint.Solver.UniqifyKVars (wfcUniqify)
@@ -61,6 +60,7 @@
 import           Control.DeepSeq
 import           Data.Functor                        (void)
 import qualified Data.ByteString as B
+import qualified Data.HashSet as HS
 import Data.Maybe (catMaybes)
 import qualified Text.PrettyPrint.HughesPJ as PJ
 
@@ -285,8 +285,9 @@
 
 solveNative' !cfg !fi0 = do
   (elabParam, si6) <- simplifyFInfo cfg fi0
-  res0 <- {- SCC "Sol.solve" -} Sol.solve cfg elabParam $!! si6
-  let res = simplifyResult cfg res0
+  let scope = sInfoScope cfg si6
+  res0 <- {- SCC "Sol.solve" -} Sol.solve cfg elabParam scope $!! si6
+  let res = simplifyResult cfg scope res0
   -- rnf soln `seq` donePhase Loud "Solve2"
   --let stat = resStatus res
   -- saveSolution cfg res
@@ -296,6 +297,30 @@
   return res
 
 --------------------------------------------------------------------------------
+-- | Scope ---------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+-- | Computes the set of all symbols that may appear free in expressions
+-- within the constraint system.
+sInfoScope :: Config -> SInfo a -> HS.HashSet Symbol
+sInfoScope cfg si = let base = HS.unions
+                          [ HS.fromList [ sym | (_, (sym, _, _)) <- bindEnvToList (Types.bs si) ]
+                          , HS.fromList $ map fst $ toListSEnv (Types.gLits si)
+                          , HS.fromList $ map fst $ toListSEnv (Types.dLits si)
+                          , HS.fromList [ val (dcName dc) | dd <- Types.ddecls si, dc <- ddCtors dd ]
+                          , HS.fromList [ val (dfName df) | dd <- Types.ddecls si, dc <- ddCtors dd, df <- dcFields dc ]
+                          -- Reflected equation names
+                          , HS.fromList [ eqName eq | eq <- aenvEqs (Types.ae si) ]
+                          -- WF constraints: the value variables of kvars
+                          , HS.fromList [ v | w <- HashMap.elems (Types.ws si), (v, _) <- wvvs w ]
+                          -- Theory symbols (arr_store_m, set operations, etc.)
+                          , HS.fromList $ map fst $ toListSEnv (theoryEnv cfg si)
+                          -- Wired-in symbols used by elaboration
+                          , HS.fromList [toIntName, tyCastName, applyName]
+                          ]
+                    in base `HS.union` HS.map tidySymbol base
+
+--------------------------------------------------------------------------------
 -- | Parse External Qualifiers -------------------------------------------------
 --------------------------------------------------------------------------------
 parseFInfo :: [FilePath] -> IO (FInfo a)
@@ -310,14 +335,14 @@
                   , Types.gLits = Types.gLits  fi
                   , Types.dLits = Types.dLits  fi }
 
-simplifyResult :: Config -> Result a -> Result a
-simplifyResult cfg res =
+simplifyResult :: Config -> HS.HashSet Symbol -> Result a -> Result a
+simplifyResult cfg scope res =
     res
       { resSolution = HashMap.map simplifyKVar' (resSolution res)
       , resNonCutsSolution = HashMap.map (fmap simplifyKVar') (resNonCutsSolution res)
       }
   where
-    simplifyKVar' = unElabSets . unElab' . Sol.simplifyKVar HashSet.empty
+    simplifyKVar' e = unElabSets $ unElab' $ Sol.simplifyKVar scope e
     sets          = elabSetBag . solverFlags $ cfg
     unElabSets    = if sets then unElabFSetBagZ3 else id
     unElab'       = if sortedSolution cfg then id else unElab
diff --git a/src/Language/Fixpoint/Solver/EnvironmentReduction.hs b/src/Language/Fixpoint/Solver/EnvironmentReduction.hs
--- a/src/Language/Fixpoint/Solver/EnvironmentReduction.hs
+++ b/src/Language/Fixpoint/Solver/EnvironmentReduction.hs
@@ -91,9 +91,9 @@
   , reftBind
   , reftPred
   , sortedReftSymbols
-  , subst1
   , fromKVarSubst
   )
+import           Language.Fixpoint.Types.Substitutions (subst1)
 import           Language.Fixpoint.Types.Sorts (boolSort, sortSymbols)
 import           Language.Fixpoint.Types.Visitor (mapExprOnExpr)
 import Language.Fixpoint.Misc (snd3)
@@ -195,7 +195,7 @@
 
       wfBindsPlusSortSymbols =
         HashMap.unionWith HashSet.union kvarsBinds $
-        HashMap.map (sortSymbols . (\(_, b, _) -> b) . wrft) wfs
+        HashMap.map (HashSet.unions . map (sortSymbols . snd) . wvvs) wfs
 
       kvarsRelevantBinds =
         HashMap.unionWith HashSet.union wfBindsPlusSortSymbols kvarSubstSymbols
diff --git a/src/Language/Fixpoint/Solver/PLE.hs b/src/Language/Fixpoint/Solver/PLE.hs
--- a/src/Language/Fixpoint/Solver/PLE.hs
+++ b/src/Language/Fixpoint/Solver/PLE.hs
@@ -79,8 +79,8 @@
 -- unfoldings discovered by PLE on the constraints in @subcIds@ (or all
 -- constraints if @subcIds == Nothing@).
 {-# SCC instantiate #-}
-instantiate :: (Loc a) => Config -> SInfo a -> Maybe Solution -> Maybe [SubcId] -> SmtM (BindEnv a)
-instantiate cfg fi' mSol subcIds = do
+instantiate :: (Loc a) => Config -> S.HashSet Symbol -> SInfo a -> Maybe Solution -> Maybe [SubcId] -> SmtM (BindEnv a)
+instantiate cfg scope fi' mSol subcIds = do
     let cs = M.filterWithKey
                (\i c -> isPleCstr aEnv i c && maybe True (i `L.elem`) subcIds)
                (cm info)
@@ -88,7 +88,7 @@
     res   <- withRESTSolver $ \solver -> do
                ctx <- get
                (res, ctx') <- liftIO $ withProgressM (`runStateT` ctx) (1 + M.size cs) $ do
-                 env <- instEnv cfg info mSol cs solver
+                 env <- instEnv cfg scope info mSol cs solver
                  pleTrie t env                                              -- 2. TRAVERSE Trie to compute InstRes
                put ctx'
                return res
@@ -133,18 +133,21 @@
 instEnv
   :: Loc a
   => Config
+  -> S.HashSet Symbol
   -> SInfo a
   -> Maybe Solution
   -> CMap (SimpC a)
   -> Maybe SolverHandle
   -> SmtM (InstEnv a)
-instEnv cfg info s cs restSolver = do
+instEnv cfg scope info s cs restSolver = do
     ctx <- get
     refRESTCache <- liftIO $ newIORef mempty
     refRESTSatCache <- liftIO $ newIORef mempty
+    let restOrd = FC.restOC cfg
+    oc0 <- case restSolver of
+      Just h  -> liftIO $ ordConstraints restOrd h
+      Nothing -> liftIO $ ordConstraints (Rewrite.RESTFuel 0) (error "unused solver handle")
     let
-        restOrd = FC.restOC cfg
-        oc0 = ordConstraints restOrd $ Mb.fromJust restSolver
         oc :: OCAlgebra OCType RuntimeTerm IO
         oc = oc0
              { OC.isSat = cachedIsSat refRESTSatCache oc0
@@ -176,6 +179,7 @@
     return $ InstEnv
        { ieCfg = cfg
        , ieBEnv = bs info
+       , ieScope = scope
        , ieAenv = ae info
        , ieCstrs = cs
        , ieKnowl = knowledge cfg info
@@ -446,6 +450,7 @@
 data InstEnv a = InstEnv
   { ieCfg   :: !Config
   , ieBEnv  :: !(BindEnv a)
+  , ieScope :: !(S.HashSet Symbol)
   , ieAenv  :: !AxiomEnv
   , ieCstrs :: !(CMap (SimpC a))
   , ieKnowl :: !Knowledge
@@ -556,7 +561,7 @@
     es        = expr <$> bs
     eRhs      = maybe PTrue crhs subMb
 
-    (binds, existentialCounter) = renameExistentialsInSortedRefts binds0 (icFreshExistentialCounter ictx)
+    (binds, existentialCounter) = renameExistentialsInSortedRefts ieScope binds0 (icFreshExistentialCounter ictx)
 
     binds0    = [ maybeApplyKVarSolutions (x, y)
                 | i <- delta
@@ -589,6 +594,7 @@
         g = CEnv
           { ceCid = gCid
           , ceBEnv = ieBEnv
+          , ceInScope = ieScope
           , ceIEnv = ibinds
           , ceSpan = maybe dummySpan srcSpan $ gCid >>= (`M.lookup` ieCstrs)
           , ceBindingsInSmt = emptyIBindEnv
@@ -896,10 +902,16 @@
   evalRESTWithCache cacheRef γ ctx [] rp
 
 evalRESTWithCache
-  :: IORef (M.HashMap Expr Bool) -> Knowledge -> ICtx -> [Expr] -> RESTParams OCType -> EvalST [Expr]
+  :: IORef (M.HashMap Expr Bool)
+  -> Knowledge
+  -> ICtx
+  -> [Expr] -- ^ Rewrites of the last expression in the path of @rp@
+            -- that have been discovered so far
+  -> RESTParams OCType
+  -> EvalST [Expr]
 evalRESTWithCache cacheRef _ ctx acc rp
-  | pathExprs <- map fst (mytracepp "EVAL1: path" $ path rp)
-  , e         <- last pathExprs
+  | pathExprs <- path rp
+  , (e, _)    <- last pathExprs
   , Just v    <- M.lookup e (icSimpl ctx)
   = do
     smtCache <- liftIO $ readIORef cacheRef
@@ -909,57 +921,70 @@
       })
     return (v : acc)
 
-evalRESTWithCache cacheRef γ ctx acc rp =
-  do
+evalRESTWithCache cacheRef γ ctx acc rp = do
     mexploredTerms <- gets explored
     ebs <- gets evExScope
-    case mexploredTerms of
-      Nothing -> return acc
-      Just exploredTerms -> do
-        se <- liftIO (shouldExploreTerm ebs exploredTerms exprs)
-        if se then do
-          possibleRWs <- liftSMT (getRWs ebs)
-          rws <- notVisitedFirst exploredTerms <$> filterM (liftIO . allowed ebs) possibleRWs
-          oldEqualities <- gets evNewEqualities
-          modify $ \st -> st { evNewEqualities = mempty }
+    case mexploredTerms of { Nothing -> return acc; Just exploredTerms -> do
+      let (exprs, _) = last (path rp)
+      se <- liftIO (shouldExploreTerm ebs exploredTerms exprs)
+      if se then do
+        possibleRWs <- getRWs ebs rp
+        rws <- notVisitedFirst exploredTerms <$>
+                 filterM (liftIO . allowedRW ebs rp) possibleRWs
+        oldEqualities <- gets evNewEqualities
+        modify $ \st -> st { evNewEqualities = mempty }
 
-          -- liftIO $ putStrLn $ (show $ length possibleRWs) ++ " rewrites allowed at path length " ++ (show $ (map snd $ path rp))
-          e' <- do
-            ec <- eval γ ctx FuncNormal exprs
-            if ec /= exprs
-              then return ec
-              else eval γ ctx RWNormal exprs
+        e' <- do
+          ec <- eval γ ctx FuncNormal exprs
+          if ec /= exprs
+            then return ec
+            else eval γ ctx RWNormal exprs
 
-          let evalIsNewExpr = e' `L.notElem` pathExprs
-          let exprsToAdd    = [e' | evalIsNewExpr]  ++ map (\(_, e, _) -> e) rws
-              acc' = exprsToAdd ++ acc
-              eqnToAdd = [ (e1, simplify γ ctx e2) | ((e1, e2), _, _) <- rws ]
+        let evalIsNewExpr = not (exprInPath e' rp)
+            exprsToAdd    = [e' | evalIsNewExpr]  ++ map (\(_, e, _) -> e) rws
+            acc' = exprsToAdd ++ acc
+            eqnToAdd = [ (e1, simplify γ ctx e2) | ((e1, e2), _, _) <- rws ]
 
-          let explored' st =
-                if isExprRewritable e' && isExprRewritable exprs
-                  then Just $ ExploredTerms.insert (Rewrite.convert exprs) (c rp)
-                                                  (S.insert (Rewrite.convert e')
-                            $ S.fromList (map (Rewrite.convert . (\(_, e, _) -> e)) possibleRWs))
-                                        (Mb.fromJust $ explored st)
-                  else Nothing
+            explored' st =
+              if isExprRewritable e' && isExprRewritable exprs then
+                Just $
+                  ExploredTerms.insert
+                    (Rewrite.convert exprs)
+                    (c rp)
+                    (S.insert (Rewrite.convert e') $
+                       S.fromList
+                         (map (Rewrite.convert . (\(_, e, _) -> e)) possibleRWs)
+                    )
+                    (Mb.fromJust $ explored st)
+              else Nothing
 
-          newEqualities <- gets evNewEqualities
-          smtCache <- liftIO $ readIORef cacheRef
-          modify $ \st -> st
-            { evNewEqualities  = foldr S.insert (S.union newEqualities oldEqualities) eqnToAdd
-            , evSMTCache = smtCache
-            , explored = explored' st
-            }
+        newEqualities <- gets evNewEqualities
+        smtCache <- liftIO $ readIORef cacheRef
+        modify $ \st -> st
+          { evNewEqualities =
+              foldr S.insert (S.union newEqualities oldEqualities) eqnToAdd
+          , evSMTCache = smtCache
+          , explored = explored' st
+          }
 
-          acc'' <- if evalIsNewExpr
-            then if e' /= exprs && any isRW (path rp)
-              then (:[]) <$> eval γ (addConst (exprs, e')) NoRW e'
-              else evalRESTWithCache cacheRef γ (addConst (exprs, e')) acc' (rpEval newEqualities e')
-            else return acc'
+        acc'' <-
+          if evalIsNewExpr then
+            if e' /= exprs && any ((RW ==) . snd) (path rp) then
+              (:[]) <$> eval γ (addConst (exprs, e')) NoRW e'
+            else do
+              rp' <- updateRESTParamsPLE rp newEqualities e'
+              evalRESTWithCache cacheRef γ (addConst (exprs, e')) acc' rp'
+          else return acc'
 
-          foldM (\r rw -> evalRESTWithCache cacheRef γ ctx r (rpRW rw)) acc'' rws
-        else
-          return acc
+        foldM
+          (\r rw ->
+            evalRESTWithCache cacheRef γ ctx r (updateRESTParamsRW rw)
+          )
+          acc''
+          rws
+      else
+        return acc
+    }
   where
     shouldExploreTerm ebs exploredTerms e | Vis.isConc e =
       case rwTerminationOpts (rwArgs ebs) of
@@ -969,51 +994,72 @@
           ExploredTerms.shouldExplore (Rewrite.convert e) (c rp) exploredTerms
     shouldExploreTerm _ _ _ = return False
 
-    allowed _ebs (_, rwE, _) | rwE `elem` pathExprs = return False
-    allowed ebs (_, _, c)   = termCheck ebs c
-    termCheck ebs c = Rewrite.passesTerminationCheck (oc rp) (rwArgs ebs) c
+    exprInPath e rparams = any ((e ==) . fst) (path rparams)
 
+    allowedRW _ebs rparams (_, rwE, _) | exprInPath rwE rparams = return False
+    allowedRW ebs rparams (_, _, c) =
+      Rewrite.passesTerminationCheck (oc rparams) (rwArgs ebs) c
+
     notVisitedFirst exploredTerms rws =
       let
         (v, nv) = L.partition (\(_, e, _) -> ExploredTerms.visited (Rewrite.convert e) exploredTerms) rws
       in
         nv ++ v
 
-    rpEval newEqualities e' =
-      let
-        c' =
-          if any isRW (path rp)
-            then foldr (\(e1, e2) ctrs -> refine (oc rp) ctrs e1 e2) (c rp) (S.toList newEqualities)
-            else c rp
-
-      in
-        rp{path = path rp ++ [(e', PLE)], c = c'}
-
-    isRW (_, r) = r == RW
-
-    rpRW (_, e', c') = rp{path = path rp ++ [(e', RW)], c = c' }
+    updateRESTParamsPLE rparams newEqualities e' = do
+      c' <- if any ((RW ==) . snd) (path rparams) then
+              foldM
+                (\ctrs (e1, e2) -> liftIO $ refine (oc rparams) ctrs e1 e2)
+                (c rparams)
+                (S.toList newEqualities)
+            else
+              return (c rparams)
+      return $ rparams{path = path rparams ++ [(e', PLE)], c = c'}
 
-    pathExprs       = map fst (mytracepp "EVAL2: path" $ path rp)
-    exprs           = last pathExprs
-    autorws         = getAutoRws γ (icSubcId ctx)
+    updateRESTParamsRW (_, e', c') = rp{path = path rp ++ [(e', RW)], c = c' }
 
     rwArgs ebs = RWArgs (isValid cacheRef ebs γ) $ knRWTerminationOpts γ
 
-    getRWs ebs =
+    -- | @getRWs ebs rparams@ returns the list of rewritten expressions that can be
+    -- derived from @expr@, the last expression in the path of @rparams@.
+    --
+    -- For each rewrite yields:
+    -- * A pair of the rewritten subexpression before and after the rewrite.
+    -- * The expression resulting from applying the rewrite to @expr@.
+    -- * The ordering constraints after the rewrite.
+    getRWs
+      :: ExScope
+      -> RESTParams OCType
+      -> EvalST [((Expr, Expr), Expr, OCType)]
+    getRWs ebs rparams = liftSMT $
       do
+        let (lastExpr, termOrdering) = last (path rparams)
         -- Optimization: If we got here via rewriting, then the current constraints
         -- are satisfiable; otherwise double-check that rewriting is still allowed
         ok <-
-          if isRW $ last (path rp)
-            then return True
-            else liftIO $ termCheck ebs (c rp)
-        if ok
-          then
-            do
-              let getRW e ar = Rewrite.getRewrite (oc rp) (rwArgs ebs) (c rp) e ar
-              let getRWs' s  = Mb.catMaybes <$> mapM (runMaybeT . getRW s) autorws
-              concat <$> mapM getRWs' (subExprs exprs)
-          else return []
+          if termOrdering == RW then
+            return True
+          else
+            liftIO $
+              Rewrite.passesTerminationCheck
+                (oc rparams)
+                (rwArgs ebs)
+                (c rparams)
+        if ok then do
+          let autorws = getAutoRws γ (icSubcId ctx)
+              getRW (subE, toE) autorw = do
+                (subE', c') <-
+                  Rewrite.getRewrite
+                    (oc rparams)
+                    (rwArgs ebs)
+                    (c rparams)
+                    subE
+                    autorw
+                pure  ((subE, subE'), toE subE', c')
+          let getRWs' s  = Mb.catMaybes <$> mapM (runMaybeT . getRW s) autorws
+          concat <$> mapM getRWs' (subExprs lastExpr)
+        else
+          return []
 
     addConst (e,e') = if isConstant (knDCs γ) e'
                       then ctx { icSimpl = M.insert e e' $ icSimpl ctx} else ctx
@@ -1656,14 +1702,14 @@
 -- 4. We then look for unfoldings in each of the subexpressions. Whenever
 --    we find an unfolding, we record the scope in which it was found.
 --
---    @[v0, v1, v3] -> (f v0 v1 = v0 < v1) && (g v2 = v2 > v1)@
+--    @[v0, v1, v3] -> (f v0 v1 = v0 < v1) && (g v2 v1 = v2 > v1)@
 --
 -- 5. When PLE is finished, we create for every scope an existential
 --    quantification whose body contains all the corresponding unfoldings
 --    and the original subexpressions in the scope ('reconstructExistentials').
 --
 --    @exists v0 v1 v0.
---       (f v0 v 1 = v0 < v1) && (g v2 = v2 > v1) &&
+--       (f v0 v1 = v0 < v1) && (g v2 v1 = v2 > v1) &&
 --       (f v0 v1 || g v2 v1)@
 --
 --    This is the expression that PLE returns.
@@ -1678,23 +1724,24 @@
 -- These superficial existentials appear in conjunctions, disjunctions and in the
 -- body of other existentials only.
 renameExistentialsInSortedRefts
-  :: [(Symbol, SortedReft)]
+  :: S.HashSet Symbol
+  -> [(Symbol, SortedReft)]
   -> Int
   -> ([(Symbol, SortedReft)], Int)
-renameExistentialsInSortedRefts binds0 existentialCounter =
+renameExistentialsInSortedRefts scope binds0 existentialCounter =
     let
         binds = [ (x, sr { sr_reft = mapPredReft (const p) (sr_reft sr) }) | ((x, sr), p) <- zip binds0 preds ]
         (preds, existentialCounter') =
-          renameKVarExistentials (map (reftPred . sr_reft . snd) binds0) existentialCounter
+          renameKVarExistentials scope (map (reftPred . sr_reft . snd) binds0) existentialCounter
      in
         (binds, existentialCounter')
 
-renameKVarExistentials :: [Expr] -> Int -> ([Expr], Int)
-renameKVarExistentials = runState . mapM go
+renameKVarExistentials :: S.HashSet Symbol -> [Expr] -> Int -> ([Expr], Int)
+renameKVarExistentials scope0 = runState . mapM (go scope0)
   where
-    go (POr es) = POr <$> mapM go es
-    go (PAnd es) = PAnd <$> mapM go es
-    go (PExist bs e0) = do
+    go scope (POr es) = POr <$> mapM (go scope) es
+    go scope (PAnd es) = PAnd <$> mapM (go scope) es
+    go scope (PExist bs e0) = do
       i1 <- get
       let i2 = i1 + length bs
       put i2
@@ -1702,8 +1749,9 @@
           vs' = [ existSymbol v (fromIntegral i) | (v, i) <- zip vs [i1..] ]
           bs' = zip vs' (map snd bs)
           su = mkSubst $ zip vs (map EVar vs')
-      PExist bs' <$> go (rapierSubstExpr (S.fromList vs') su e0)
-    go e = pure e
+          scope' = S.fromList vs `S.union` S.fromList vs' `S.union` scope
+      PExist bs' <$> go scope' (substr scope' su e0)
+    go _ e = pure e
 
 -- ^ Scopes of existential binders identifying the location of sub-expressions
 type ExScope = [(Symbol, Sort)]
diff --git a/src/Language/Fixpoint/Solver/Prettify.hs b/src/Language/Fixpoint/Solver/Prettify.hs
--- a/src/Language/Fixpoint/Solver/Prettify.hs
+++ b/src/Language/Fixpoint/Solver/Prettify.hs
@@ -51,11 +51,10 @@
   , reftBind
   , reftPred
   , sortedReftSymbols
-  , substf
   , substSortInExpr
   )
 import           Language.Fixpoint.Types.Sorts (Sort(..), substSort)
-import           Language.Fixpoint.Types.Substitutions (exprSymbolsSet)
+import           Language.Fixpoint.Types.Substitutions (exprSymbolsSet, substf)
 import qualified Language.Fixpoint.Utils.Files as Files
 import           System.FilePath (addExtension)
 import           Text.PrettyPrint.HughesPJ.Compat
@@ -152,11 +151,14 @@
           | bId <- elemsIBindEnv $ wenv wfc
           , let (s, sr, _a) = lookupBindEnv bId bindEnv
           ]
-      (v, t, k) = wrft wfc
+      k = PKVar (wkvar wfc) M.empty mempty
+      prettyVVs = case wvvs wfc of
+        [(v, t)] -> text "reft" <+> toFix (RR t (Reft (v, k)))
+        vvs      -> hang (text "vvs:") 2 (vcat $ map prettyBind vvs) $+$ text "kvar" <+> toFix k
    in hang (text "\n\nwf:") 2 $
           hang (text "env:") 2
             (vcat $ map prettyBind prettyEnv)
-      $+$ text "reft" <+> toFix (RR t (Reft (v, PKVar k M.empty mempty)))
+      $+$ prettyVVs
       $+$ toFixMeta (text "wf") (toFix (winfo wfc))
   where
     prettyBind (s, srt) = toFix s <+> ":" <+> toFix srt
diff --git a/src/Language/Fixpoint/Solver/Rewrite.hs b/src/Language/Fixpoint/Solver/Rewrite.hs
--- a/src/Language/Fixpoint/Solver/Rewrite.hs
+++ b/src/Language/Fixpoint/Solver/Rewrite.hs
@@ -7,7 +7,7 @@
 module Language.Fixpoint.Solver.Rewrite
   ( getRewrite
   , subExprs
-  , unify
+  , matchExpr
   , ordConstraints
   , convert
   , passesTerminationCheck
@@ -20,6 +20,7 @@
   ) where
 
 import           Control.Monad (guard)
+import           Control.Monad.IO.Class
 import           Control.Monad.Trans.Maybe
 import           Data.Hashable
 import qualified Data.HashMap.Strict  as M
@@ -33,12 +34,9 @@
 import           Language.Fixpoint.Smt.Types (SmtM)
 import           Language.REST
 import           Language.REST.KBO (kbo)
-import           Language.REST.LPO (lpo)
 import           Language.REST.OCAlgebra as OC
-import           Language.REST.OCToAbstract (lift)
 import           Language.REST.Op
 import           Language.REST.SMT (SMTExpr)
-import           Language.REST.WQOConstraints.ADT (ConstraintsADT, adtOC)
 import qualified Language.REST.RuntimeTerm as RT
 
 -- | @(e, f)@ asserts that @e@ is a subexpression of @f e@
@@ -62,32 +60,36 @@
 -- Monomorphize ordering constraints so we don't litter PLE with type variables
 -- Also helps since GHC doesn't support impredicate polymorphism (yet)
 data OCType =
-    RPO (ConstraintsADT Op)
-  | LPO (ConstraintsADT Op)
-  | KBO (SMTExpr Bool)
-  | Fuel Int
+    RestOC (SMTExpr Bool)
+  | FuelOC Int
   deriving (Eq, Show, Generic, Hashable)
 
-ordConstraints :: RESTOrdering -> (Handle, Handle) -> OCAlgebra OCType RT.RuntimeTerm IO
-ordConstraints RESTRPO      solver = bimapConstraints RPO asRPO (adtRPO solver)
+ordConstraints :: RESTOrdering -> (Handle, Handle) -> IO (OCAlgebra OCType RT.RuntimeTerm IO)
+ordConstraints RESTRPO      solver = do
+  oca <- rpoOCA solver "$R_"
+  return (bimapConstraints RestOC asRestOC oca)
   where
-    asRPO (RPO t) = t
-    asRPO _       = undefined
+    asRestOC (RestOC e) = e
+    asRestOC _          = undefined
 
-ordConstraints RESTKBO      solver = bimapConstraints KBO asKBO (kbo solver)
+ordConstraints RESTKBO solver = do
+    oca <- kbo solver "$K_"
+    return (bimapConstraints RestOC asRestOC oca)
   where
-    asKBO (KBO t) = t
-    asKBO _       = undefined
+    asRestOC (RestOC e) = e
+    asRestOC _          = undefined
 
-ordConstraints RESTLPO      solver = bimapConstraints LPO asLPO (lift (adtOC solver) lpo)
+ordConstraints RESTLPO      solver = do
+  oca <- lpoOCA solver "$L_"
+  return (bimapConstraints RestOC asRestOC oca)
   where
-    asLPO (LPO t) = t
-    asLPO _       = undefined
+    asRestOC (RestOC e) = e
+    asRestOC _          = undefined
 
-ordConstraints (RESTFuel m) _      = bimapConstraints Fuel asFuel $ fuelOC m
+ordConstraints (RESTFuel m) _      = return (bimapConstraints FuelOC asFuelOC (fuelOC m))
   where
-    asFuel (Fuel n) = n
-    asFuel _        = undefined
+    asFuelOC (FuelOC n) = n
+    asFuelOC _          = undefined
 
 
 -- Note: if you change the domain of this function, you need to change
@@ -117,8 +119,11 @@
 
 -- | Yields the result of rewriting an expression with an autorewrite equation.
 --
+-- The result contains the rewritten expression and the ordering constraints.
+--
 -- Yields nothing if:
 --
+--  * The expression does not match the left-hand side of the autorewrite
 --  * The result of the rewrite is identical to the original expression
 --  * Any of the arguments of the autorewrite has a refinement type which is
 --    not satisfied in the current context.
@@ -127,43 +132,31 @@
      OCAlgebra oc Expr IO
   -> RewriteArgs
   -> oc
-  -> SubExpr
+  -> Expr
   -> AutoRewrite
-  -> MaybeT SmtM ((Expr, Expr), Expr, oc)
-getRewrite aoc rwArgs c (subE, toE) (AutoRewrite args lhs rhs) =
+  -> MaybeT SmtM (Expr, oc)
+getRewrite aoc rwArgs c subE (AutoRewrite args lhs rhs) =
   do
-    su <- MaybeT $ return $ unify freeVars lhs subE
+    su <- MaybeT $ return $ matchExpr freeVars lhs subE
     let subE' = subst su rhs
     guard $ subE /= subE'
-    let expr' = toE subE'
-        eqn = (subst su lhs, subE')
-    mapM_ (checkSubst su) exprs
-    return $ case rwTerminationOpts rwArgs of
-      RWTerminationCheckEnabled ->
-        let
-          c' = refine aoc c subE subE'
-        in
-          (eqn, expr', c')
-      RWTerminationCheckDisabled -> (eqn, expr', c)
+    mapM_ (checkArgValidity su) args
+    c' <- case rwTerminationOpts rwArgs of
+      RWTerminationCheckEnabled  -> liftIO $ refine aoc c subE subE'
+      RWTerminationCheckDisabled -> return c
+    return (subE', c')
   where
-    check :: Expr -> MaybeT SmtM ()
-    check e = do
-      valid <- MaybeT $ Just <$> isRWValid rwArgs e
-      guard valid
-
     freeVars = [s | RR _ (Reft (s, _)) <- args ]
-    exprs    = [(s, e) | RR _ (Reft (s, e)) <- args ]
 
-    checkSubst su (s, e) =
-      do
-        let su' = catSubst su $ mkSubst [("VV", subst su (EVar s))]
-        -- liftIO $ printf "Substitute %s in %s\n" (show su') (show e)
-        check $ subst (catSubst su su') e
-
+    checkArgValidity su (RR _ (Reft (_s, e))) = do
+      valid <- MaybeT $ Just <$> isRWValid rwArgs (subst su e)
+      guard valid
 
+-- | Produces all the subexpressions of an expression.
 subExprs :: Expr -> [SubExpr]
 subExprs e = (e,id):subExprs' e
 
+-- | Like 'subExprs', but does not include the expression itself.
 subExprs' :: Expr -> [SubExpr]
 subExprs' (EIte c lhs rhs)  = c''
   where
@@ -255,23 +248,23 @@
 unifyAll _ []     []               = Just (Su M.empty)
 unifyAll freeVars (template:xs) (seen:ys) =
   do
-    rs@(Su s1) <- unify freeVars template seen
+    rs@(Su s1) <- matchExpr freeVars template seen
     let xs' = map (subst rs) xs
     let ys' = map (subst rs) ys
     (Su s2) <- unifyAll (freeVars L.\\ M.keys s1) xs' ys'
     return $ Su (M.union s1 s2)
 unifyAll _ _ _ = undefined
 
--- | @unify vs template e = Just su@ yields a substitution @su@
+-- | @matchExpr vs template e = Just su@ yields a substitution @su@
 -- such that subst su template == e
 --
 -- Moreover, @su@ is constraint to only substitute variables in @vs@.
 --
 -- Yields @Nothing@ if no substitution exists.
 --
-unify :: [Symbol] -> Expr -> Expr -> Maybe Subst
-unify _ template seenExpr | template == seenExpr = Just (Su M.empty)
-unify freeVars template seenExpr = case (dropECst template, seenExpr) of
+matchExpr :: [Symbol] -> Expr -> Expr -> Maybe Subst
+matchExpr _ template seenExpr | template == seenExpr = Just (Su M.empty)
+matchExpr freeVars template seenExpr = case (dropECst template, seenExpr) of
   -- preserve seen casts if possible
   (EVar rwVar, _) | rwVar `elem` freeVars ->
     return $ Su (M.singleton rwVar seenExpr)
@@ -287,23 +280,23 @@
     (EApp templateF templateBody, EApp seenF seenBody) ->
       unifyAll freeVars [templateF, templateBody] [seenF, seenBody]
     (ENeg rw, ENeg seen) ->
-      unify freeVars rw seen
+      matchExpr freeVars rw seen
     (EBin op rwLeft rwRight, EBin op' seenLeft seenRight) | op == op' ->
       unifyAll freeVars [rwLeft, rwRight] [seenLeft, seenRight]
     (EIte cond rwLeft rwRight, EIte seenCond seenLeft seenRight) ->
       unifyAll freeVars [cond, rwLeft, rwRight] [seenCond, seenLeft, seenRight]
     (ECst rw _, seen) ->
-      unify freeVars rw seen
+      matchExpr freeVars rw seen
     (ETApp rw _, ETApp seen _) ->
-      unify freeVars rw seen
+      matchExpr freeVars rw seen
     (ETAbs rw _, ETAbs seen _) ->
-      unify freeVars rw seen
+      matchExpr freeVars rw seen
     (PAnd rw, PAnd seen ) ->
       unifyAll freeVars rw seen
     (POr rw, POr seen ) ->
       unifyAll freeVars rw seen
     (PNot rw, PNot seen) ->
-      unify freeVars rw seen
+      matchExpr freeVars rw seen
     (PImp templateF templateBody, PImp seenF seenBody) ->
       unifyAll freeVars [templateF, templateBody] [seenF, seenBody]
     (PIff templateF templateBody, PIff seenF seenBody) ->
@@ -311,11 +304,11 @@
     (PAtom rel templateF templateBody, PAtom rel' seenF seenBody) | rel == rel' ->
       unifyAll freeVars [templateF, templateBody] [seenF, seenBody]
     (PAll _ rw, PAll _ seen) ->
-      unify freeVars rw seen
+      matchExpr freeVars rw seen
     (PExist _ rw, PExist _ seen) ->
-      unify freeVars rw seen
+      matchExpr freeVars rw seen
     (ECoerc _ _ rw, ECoerc _ _ seen) ->
-      unify freeVars rw seen
+      matchExpr freeVars rw seen
     (ELet _ rw1 rw2, ELet _ seen1 seen2) ->
       unifyAll freeVars [rw1, rw2] [seen1, seen2]
     _ -> Nothing
diff --git a/src/Language/Fixpoint/Solver/Sanitize.hs b/src/Language/Fixpoint/Solver/Sanitize.hs
--- a/src/Language/Fixpoint/Solver/Sanitize.hs
+++ b/src/Language/Fixpoint/Solver/Sanitize.hs
@@ -301,9 +301,9 @@
     be   = F.bs fi
     ids  = F.elemsIBindEnv $ F.senv c
     cDom = [Misc.fst3 $ F.lookupBindEnv i be | i <- ids]
-    cRng = concat [S.toList . F.reftFreeVars . F.sr_reft . Misc.snd3 $ F.lookupBindEnv i be | i <- ids]
-        ++ F.syms (F.crhs c)
-    fv   = (`Misc.nubDiff` cDom) . filter (not . knownSym) $ cRng
+    cRng = S.unions $
+      F.syms (F.crhs c) : [F.syms . F.sr_reft . Misc.snd3 $ F.lookupBindEnv i be | i <- ids]
+    fv   = S.filter (not . knownSym) cRng `S.difference` S.fromList cDom
 
 badCs :: Misc.ListNE (F.SimpC a, [F.Symbol]) -> E.Error
 badCs = E.catErrors . map (E.errFreeVarInConstraint . Bifunctor.first F.subcId)
@@ -326,11 +326,11 @@
 --------------------------------------------------------------------------------
 banQualifFreeVars cfg fi = Misc.applyNonNull (Right fi) (Left . badQuals) bads
   where
-    bads    = [ (q, xs) | q <- F.quals fi, let xs = free q, not (null xs) ]
-    free q  = filter (not . isGlobal) (F.syms q)
+    bads    = [ (q, xs) | q <- F.quals fi, let xs = free q, not (S.null xs) ]
+    free q  = S.filter (not . isGlobal) (F.syms q)
     isGlobal x = F.memberSEnv x (SortCheck.globalEnv cfg fi)
 
-badQuals     :: Misc.ListNE (F.Qualifier, Misc.ListNE F.Symbol) -> E.Error
+badQuals     :: Misc.ListNE (F.Qualifier, S.HashSet F.Symbol) -> E.Error
 badQuals bqs = E.catErrors [ E.errFreeVarInQual q xs | (q, xs) <- bqs]
 
 
diff --git a/src/Language/Fixpoint/Solver/Solution.hs b/src/Language/Fixpoint/Solver/Solution.hs
--- a/src/Language/Fixpoint/Solver/Solution.hs
+++ b/src/Language/Fixpoint/Solver/Solution.hs
@@ -57,19 +57,24 @@
 init :: (F.Fixpoint a) => Config -> F.SInfo a -> S.HashSet F.KVar -> M.HashMap F.KVar Sol.QBind
 --------------------------------------------------------------------------------
 init cfg si ks =
-    runReader (traverse (refine si qcs genv) ws) (solverFlags cfg)
+    runReader (traverse (refine si qcs genv chkEnv) ws) (solverFlags cfg)
   where
     qcs = mkQCluster (F.quals si)
     ws = M.intersection (F.ws si) (S.toMap ks)
     genv = initQualifierEnv cfg si
+    chkEnv = initCheckEnv cfg si
 
 initQualifierEnv :: (F.Fixpoint a) => Config -> F.SInfo a -> F.SEnv F.Sort
 initQualifierEnv cfg si
-  | scraping  = So.globalEnv cfg si <> instConstants si
+  | scraping  = initCheckEnv cfg si
   | otherwise = instConstants si
   where
     scraping = scrape cfg /= No
 
+-- | Also includes theory symbols that are not instantiation candidates.
+initCheckEnv :: (F.Fixpoint a) => Config -> F.SInfo a -> F.SEnv F.Sort
+initCheckEnv cfg si = So.globalEnv cfg si <> instConstants si
+
 --------------------------------------------------------------------------------
 -- | [NOTE:qual-cluster] It is wasteful to perform instantiation *individually*
 --   on each qualifier, as many qualifiers have "equivalent" parameters, and
@@ -91,8 +96,8 @@
 
 --------------------------------------------------------------------------------
 
-refine :: F.SInfo a -> QCluster -> F.SEnv F.Sort -> F.WfC a -> ElabM Sol.QBind
-refine info qs genv w = refineK (allowHOquals info) env lits qs (F.wrft w)
+refine :: F.SInfo a -> QCluster -> F.SEnv F.Sort -> F.SEnv F.Sort -> F.WfC a -> ElabM Sol.QBind
+refine info qs genv chkEnv w = refineK (allowHOquals info) env (wenvSort <> chkEnv) lits qs (F.wvvs w)
   where
     env             = wenvSort <> genv
     wenvSort        = F.sr_sort <$> F.fromListSEnv (F.envCs (F.bs info) (F.wenv w))
@@ -104,25 +109,31 @@
     notLit    = not . F.isLitSymbol . fst
 
 
-refineK :: Bool -> F.SEnv F.Sort -> [F.Constant] -> QCluster -> (F.Symbol, F.Sort, F.KVar) -> ElabM Sol.QBind
-refineK ho env lits qs (v, t, _k) = Sol.qbFilterM (okInst env v t) eqs
+refineK :: Bool -> F.SEnv F.Sort -> F.SEnv F.Sort -> [F.Constant] -> QCluster -> [(F.Symbol, F.Sort)] -> ElabM Sol.QBind
+refineK ho candEnv chkEnv lits qs vvs = Sol.qbFilterM (okInst (withVVs chkEnv)) eqs
    where
-    eqs = instK ho env lits v t qs
+    eqs  = instK ho (withVVs candEnv) lits vvs qs
+    withVVs e = List.foldl' (\e' (v, t) -> F.insertSEnv v t e') e vvs
 
 --------------------------------------------------------------------------------
+-- | @instK ho env lits vvs qc@ instantiates the qualifiers in @qc@ for a kvar
+--   with value variables @vvs@. The first (non-literal) parameter of each
+--   qualifier is instantiated with a value variable, and the rest with any
+--   other symbol in @env@, which includes the value variables. A kvar without
+--   value variables only gets @false@ as a candidate.
 instK :: Bool
       -> F.SEnv F.Sort
       -> [F.Constant]
-      -> F.Symbol
-      -> F.Sort
+      -> [(F.Symbol, F.Sort)]
       -> QCluster
       -> Sol.QBind
 --------------------------------------------------------------------------------
-instK ho env lits v t qc = Sol.qb . unique $
+instK _  _   _    []  _  = Sol.qb [Sol.falseEqual]
+instK ho env lits vvs qc = Sol.qb . unique $
   [ Sol.eQual q xs ls
       | (sig, qs) <- M.toList qc
       , let (varSig, litSig) =  splitSig sig
-      , xs        <- instKSig ho env v t varSig
+      , xs        <- instKSig ho env vvs varSig
       , ls        <- instLitSig lits litSig
       , q         <- qs
   ]
@@ -144,19 +155,26 @@
 unique :: [Sol.EQual] -> [Sol.EQual]
 unique qs = M.elems $ M.fromList [ (Sol.eqPred q, q) | q <- qs ]
 
+-- | @instKSig ho env vvs sig@ instantiates the first parameter of @sig@ with a
+--   value variable in @vvs@, and the remaining parameters with symbols in @env@
+--   and value variables other than the one chosen for the first parameter. The
+--   name pattern of the first parameter is ignored.
 instKSig :: Bool
          -> F.SEnv F.Sort
-         -> F.Symbol
-         -> F.Sort
+         -> [(F.Symbol, F.Sort)]
          -> QCSig
          -> [[F.Symbol]]
-instKSig _  _   _ _ [] = error "Empty qsig in Solution.instKSig"
-instKSig ho env v sort' (qp:qps) = do
-  (su0, i0, qs0) <- candidatesP symToSrch [(0, sort', [v])] qp
-  ixs       <- matchP symToSrch tyss [(i0, qs0)] (applyQPP su0 <$> qps)
-  ys        <- instSymbol tyss (tail $ reverse ixs)
-  return (v:ys)
+instKSig _  _   _   [] = error "Empty qsig in Solution.instKSig"
+instKSig ho env vvs (qp:qps) = do
+  ixs    <- matchP symToSrch (vvQP : restQPs)
+  x : ys <- instSymbol (vvTyss ++ tyss) (reverse ixs)
+  guard (x `notElem` ys)
+  return (x : ys)
   where
+    vvQP       = (vvTyss, qp { F.qpPat = F.PatNone })
+    restQPs    = [ (tyss, qp') | qp' <- qps ]
+    -- value variables use negative indices to keep them apart from the env
+    vvTyss     = zipWith (\i (t, ys) -> (i, t, ys)) [-1, -2 ..] (Misc.groupList [ (t, x) | (x, t) <- vvs ])
     tyss       = zipWith (\i (t, ys) -> (i, t, ys)) [1..] (instCands ho env)
     symToSrch  = (`F.lookupSEnvWithDistance` env)
 
@@ -182,14 +200,16 @@
 
 type SortIdx = Int
 
-matchP :: So.Env -> [(SortIdx, F.Sort, a)] -> [(SortIdx, QualPattern)] -> [F.QualParam] ->
-          [[(SortIdx, QualPattern)]]
-matchP env tyss = go
+-- | @matchP env qps@ picks, for each parameter in @qps@, a sort index among the
+--   candidates paired with the parameter. Sort variables solved for one parameter
+--   are applied to the remaining ones. The result is in reverse order.
+matchP :: So.Env -> [([(SortIdx, F.Sort, a)], F.QualParam)] -> [[(SortIdx, QualPattern)]]
+matchP env = go []
   where
     go' !i !p !is !qps  = go ((i, p):is) qps
-    go is (qp : qps) = do (su, i, pat) <- candidatesP env tyss qp
-                          go' i pat is (applyQPP su <$> qps)
-    go is []         = return is
+    go is ((tyss, qp) : qps) = do (su, i, pat) <- candidatesP env tyss qp
+                                  go' i pat is [ (tyss', applyQPP su qp') | (tyss', qp') <- qps ]
+    go is []                 = return is
 
 applyQPP :: So.TVSubst -> F.QualParam -> F.QualParam
 applyQPP su qp = qp
@@ -259,15 +279,11 @@
   = p
 
 --------------------------------------------------------------------------------
-okInst :: F.SEnv F.Sort -> F.Symbol -> F.Sort -> Sol.EQual -> ElabM Bool
+okInst :: F.SEnv F.Sort -> Sol.EQual -> ElabM Bool
 --------------------------------------------------------------------------------
-okInst env v t eq =
-  do tc <- So.checkSorted (F.srcSpan eq) env sr
+okInst env eq =
+  do tc <- So.checkSorted (F.srcSpan eq) env (Sol.eqPred eq)
      pure $ isNothing tc
-  where
-    sr            = F.RR t (F.Reft (v, p))
-    p             = Sol.eqPred eq
-    -- _msg          = printf "okInst: t = %s, eq = %s" (F.showpp t) (F.showpp eq)
 
 
 --------------------------------------------------------------------------------
@@ -277,16 +293,17 @@
 lhsPred
   :: (F.Loc a)
   => Config
+  -> S.HashSet F.Symbol
   -> F.IBindEnv
   -> F.BindEnv a
   -> Sol.Solution
   -> F.SimpC a
   -> F.Expr
-lhsPred cfg bindingsInSmt be s c =
+lhsPred cfg scope bindingsInSmt be s c =
     let ap = apply cfg g s bs
      in F.notracepp _msg $ fst ap
   where
-    g          = CEnv ci be bs (F.srcSpan c) bindingsInSmt
+    g          = CEnv ci be scope bs (F.srcSpan c) bindingsInSmt
     bs         = F.senv c
     ci         = sid c
     _msg       = "LhsPred for id = " ++ show (sid c) ++ " with SOLUTION = " ++ F.showpp s
@@ -294,6 +311,7 @@
 data CombinedEnv a = CEnv
   { ceCid  :: !Cid
   , ceBEnv :: !(F.BindEnv a)
+  , ceInScope :: !(S.HashSet F.Symbol)
   , ceIEnv :: !F.IBindEnv
   , ceSpan :: !F.SrcSpan
     -- | These are the bindings that the smt solver knows about and can be
@@ -367,11 +385,10 @@
 mkNonCutsExpr :: Config -> CombinedEnv ann -> Sol.Sol Sol.QBind -> F.KVar -> Sol.Hyp -> F.Expr
 mkNonCutsExpr cfg ce s k cs = F.pOr (bareCubePred cfg ce s k <$> cs)
 
-nonCutsResult :: Config -> F.BindEnv ann -> Sol.Sol Sol.QBind -> FixDelayedSolution
-nonCutsResult cfg be s = M.mapWithKey (\k -> Delayed . mkNonCutsExpr cfg g s k) $ Sol.sHyp s
+nonCutsResult :: Config -> S.HashSet F.Symbol -> F.BindEnv ann -> Sol.Sol Sol.QBind -> FixDelayedSolution
+nonCutsResult cfg scope be s = M.mapWithKey (\k -> Delayed . mkNonCutsExpr cfg g s k) $ Sol.sHyp s
   where
-    g = CEnv Nothing be F.emptyIBindEnv F.dummySpan F.emptyIBindEnv
-
+    g = CEnv Nothing be scope F.emptyIBindEnv F.dummySpan F.emptyIBindEnv
 
 -- | Produces a predicate from a constraint defining a kvar.
 --
@@ -445,11 +462,8 @@
 cubePred :: Config -> CombinedEnv ann -> Sol.Sol Sol.QBind -> F.KVSub -> Sol.Cube -> ExprInfo
 cubePred cfg g s ksu c    =
     let (p, kI) = cubePredExc cfg g s c bs'
-        -- Free variables in p should not colide with those generated by
-        -- the rapier substitution. If that were the case, perhaps we would
-        -- need to include @combinedSEnv g@ in the scope set.
-        p' = F.rapierSubstExpr (F.substSymbolsSet su) su $
-             V.applyCoSub (F.ksuTySub ksu) p
+        p' = let pExpr = V.applyCoSub (F.ksuTySub ksu) p
+              in F.substr (ceInScope g) su pExpr
      in (p', kI)
   where
     bs' = F.diffIBindEnv bs (Misc.safeLookup "sScp" k (Sol.sScp s))
@@ -566,13 +580,14 @@
 -- start with the @subst$@ prefix.
 --
 simplifyKVar :: S.HashSet F.Symbol -> F.Expr -> F.Expr
-simplifyKVar s0 = F.conj . dedupByAlphaEq s0 . floatPExistConjuncts . go s0
+simplifyKVar s0 = F.conj . dedupByAlphaEq s0 . floatPExistConjuncts s0 . go s0
   where
-    go s (F.POr es) = disj $ map (F.conj . floatPExistConjuncts . go s) es
-    go s (F.PAnd es) = F.conj $ dedupByAlphaEq S.empty $ concatMap (floatPExistConjuncts . go s) es
+    go s (F.POr es) = disj $ map (F.conj . floatPExistConjuncts s . go s) es
+    go s (F.PAnd es) = F.conj $ dedupByAlphaEq s $ concatMap (floatPExistConjuncts s . go s) es
     go s (F.PExist bs e0) =
-      let es = concatMap (floatPExistConjuncts . go (S.union s $ S.fromList $ map fst bs)) (F.conjuncts e0)
-       in elimExistentialBinds (F.PExist bs (F.conj es))
+      let s' = S.union s $ S.fromList $ map fst bs
+          es = concatMap (floatPExistConjuncts s' . go s') (F.conjuncts e0)
+       in elimExistentialBinds s (F.PExist bs (F.conj es))
     go _ e = e
 
     dedupByAlphaEq :: S.HashSet F.Symbol -> [F.Expr] -> [F.Expr]
@@ -583,10 +598,10 @@
     disj [e] = e
     disj es = F.POr es
 
-    elimExistentialBinds (F.PExist bs0 (F.PExist bs1 p)) =
+    elimExistentialBinds s (F.PExist bs0 (F.PExist bs1 p)) =
       let bs0' = filter (\(x,_) -> x `notElem` map fst bs1) bs0
-       in elimExistentialBinds (F.PExist (bs0' ++ bs1) p)
-    elimExistentialBinds (F.PExist bs e0) =
+       in elimExistentialBinds s (F.PExist (bs0' ++ bs1) p)
+    elimExistentialBinds s (F.PExist bs e0) =
       let es = F.conjuncts e0
           esv = map (isVarEq (map fst bs)) es
           -- Eliminating multiple variables at once can be difficult if the
@@ -597,17 +612,18 @@
             let (xs, ys) = break (isJust . fst) esv
              in map snd (xs ++ drop 1 ys)
           su = F.mkSubst esvElim
-          e' = F.rapierSubstExpr (F.substSymbolsSet su) su $ F.conj esvKeep
+          esvKeepExpr = F.conj esvKeep
+          e' = F.substr (S.fromList (map fst bs) `S.union` s) su esvKeepExpr
           bs' = filter ((`S.member` F.exprSymbolsSet e') . fst) bs
           e'' = F.pExist bs' e'
        in
-          if null esvElim then e'' else elimExistentialBinds e''
-    elimExistentialBinds e = e
+          if null esvElim then e'' else elimExistentialBinds s e''
+    elimExistentialBinds _ e = e
 
     -- | Float out conjuncts from an existential expression that does not
     -- depend on the existentially bound variables.
-    floatPExistConjuncts :: F.Expr -> [F.Expr]
-    floatPExistConjuncts e0@(F.PExist bs es0) =
+    floatPExistConjuncts :: S.HashSet F.Symbol -> F.Expr -> [F.Expr]
+    floatPExistConjuncts s e0@(F.PExist bs es0) =
       let es = F.conjuncts es0
           (floatable, nonFloatable) =
            List.partition (isFloatableConjunct (S.fromList (map fst bs))) es
@@ -615,11 +631,11 @@
           if null floatable then
             [e0]
           else
-            elimExistentialBinds (F.pExist bs (F.conj nonFloatable)) : floatable
+            elimExistentialBinds s (F.pExist bs (F.conj nonFloatable)) : floatable
       where
         isFloatableConjunct :: S.HashSet F.Symbol -> F.Expr -> Bool
-        isFloatableConjunct s e = S.null $ S.intersection (F.exprSymbolsSet e) s
-    floatPExistConjuncts e = [e]
+        isFloatableConjunct ebs e = S.null $ S.intersection (F.exprSymbolsSet e) ebs
+    floatPExistConjuncts _ e = [e]
 
 -- | Determine if two expressions are alpha-equivalent.
 --
@@ -635,16 +651,20 @@
     go s su (F.PExist bs1 x1) (F.PExist bs2 x2) =
       let su' =
             List.foldl'
-              (\su1 (v1, v2) -> F.extendSubst su1 v1 (F.EVar v2))
+              (\su1 (v1, v2) -> F.extendSubstWithVar su1 v1 v2)
               su
               (zip (map fst bs1) (map fst bs2))
-       in go (S.union s (S.fromList $ map fst bs2)) su' x1 x2
+       in go
+             (S.unions [s, S.fromList (map fst bs1), S.fromList (map fst bs2)])
+             su'
+             x1
+             x2
     go s su (F.PAnd es1) (F.PAnd es2) =
       length es1 == length es2 && and (zipWith (go s su) es1 es2)
     go s su (F.POr es1) (F.POr es2) =
       length es1 == length es2 && and (zipWith (go s su) es1 es2)
     go s su e1 e2 =
-      F.rapierSubstExpr s su e1 == e2
+      F.substr s su e1 == e2
 
 -- | Determine if the expression is an equality that sets the value of
 -- a variable in the given set.
diff --git a/src/Language/Fixpoint/Solver/Solve.hs b/src/Language/Fixpoint/Solver/Solve.hs
--- a/src/Language/Fixpoint/Solver/Solve.hs
+++ b/src/Language/Fixpoint/Solver/Solve.hs
@@ -61,10 +61,10 @@
 --------------------------------------------------------------------------------
 solve
   :: forall a. (NFData a, F.Fixpoint a, Show a, F.Loc a)
-  => Config -> ElabParam -> F.SInfo a -> IO (F.Result (Integer, a))
+  => Config -> ElabParam -> S.HashSet F.Symbol -> F.SInfo a -> IO (F.Result (Integer, a))
 --------------------------------------------------------------------------------
 
-solve cfg elabParam fi = do
+solve cfg elabParam scope fi = do
     whenLoud $ donePhase Misc.Loud "Worklist Initialize"
     vb <- getVerbosity
     (res, stat) <- (if Quiet == vb then id else withProgressFI sI) $ runSolverM cfg sI elabParam act
@@ -77,7 +77,7 @@
       ctx <- getContext
       let sEnv = symbolEnv cfg fi
           s1 = s0{Sol.sMap = M.map (elabQBind ctx "solve" sEnv) (Sol.sMap s0)}
-      solve_ cfg fi s1 wkl
+      solve_ cfg scope fi s1 wkl
     -- solverInfo computes the set of cut and non-cut kvars, then initializes
     -- the solutions of the non-cut KVars (in the sHyp field)
     --
@@ -127,17 +127,18 @@
 {-# SCC solve_ #-}
 solve_ :: (NFData a, F.Fixpoint a, F.Loc a)
        => Config
+       -> S.HashSet F.Symbol
        -> F.SInfo a
        -> Sol.Solution
        -> W.Worklist a
        -> SolveM a (F.Result (Integer, a), Stats)
 --------------------------------------------------------------------------------
-solve_ cfg fi s2 wkl = do
+solve_ cfg scope fi s2 wkl = do
   liftSMT $ smtComment "solve: start"
   (s3, res0) <- sendConcreteBindingsToSMT F.emptyIBindEnv (F.bs fi) $ \bindingsInSmt -> do
     -- let s3   = solveEbinds fi s2
-    s3       <- {- SCC "sol-refine" -} refine bindingsInSmt (F.bs fi) s2 wkl
-    res0     <- {- SCC "sol-result" -} result bindingsInSmt cfg fi (W.unsatCandidates wkl) s3
+    s3       <- {- SCC "sol-refine" -} refine scope bindingsInSmt (F.bs fi) s2 wkl
+    res0     <- {- SCC "sol-result" -} result scope bindingsInSmt cfg fi (W.unsatCandidates wkl) s3
     return (s3, res0)
 
   (fi1, res1) <- case resStatus res0 of  {- first run the interpreter -}
@@ -148,7 +149,7 @@
           badCs = lookupCMap (F.cm fi) <$> map fst bads
       liftSMT $ smtComment "solve: pos-interpreter check"
       fmap (fi1,) $ sendConcreteBindingsToSMT F.emptyIBindEnv bs $ \bindingsInSmt ->
-        result bindingsInSmt cfg fi1 badCs s3
+        result scope bindingsInSmt cfg fi1 badCs s3
     _ -> return  (fi, mytrace "all checked before interpreter" res0)
 
   res2  <- case resStatus res1 of  {- then run normal PLE on remaining unsolved constraints -}
@@ -156,13 +157,13 @@
       when (save cfg) $
         liftIO $ S.saveSolution cfg ".pre-ple" res1
       liftSMT $ smtComment "solve: ple"
-      bs <- liftSMT $ PLE.instantiate cfg fi1 (Just s3) (Just $ map fst bads2)
+      bs <- liftSMT $ PLE.instantiate cfg scope fi1 (Just s3) (Just $ map fst bads2)
       -- Check the constraints one last time after PLE
       let fi2 = fi { F.bs = bs }
           badsCs2 = lookupCMap (F.cm fi) <$> map fst bads2
       liftSMT $ smtComment "solve: pos-ple check"
       sendConcreteBindingsToSMT F.emptyIBindEnv bs $ \bindingsInSmt ->
-        result bindingsInSmt cfg fi2 badsCs2 s3
+        result scope bindingsInSmt cfg fi2 badsCs2 s3
     _ -> return $ mytrace "all checked with interpreter" res1
 
   liftSMT $ smtComment "solve: finished"
@@ -220,19 +221,20 @@
 --
 refine
   :: forall a. F.Loc a
-  => F.IBindEnv
+  => S.HashSet F.Symbol
+  -> F.IBindEnv
   -> F.BindEnv a
   -> Sol.Solution
   -> W.Worklist a
   -> SolveM a Sol.Solution
 --------------------------------------------------------------------------------
-refine bindingsInSmt be0 s0 w0 = go be0 s0 w0
+refine scope bindingsInSmt be0 s0 w0 = go be0 s0 w0
   where
     go :: F.BindEnv a -> Sol.Solution -> W.Worklist a -> SolveM a Sol.Solution
     go be s w
       | Just (c, w', newScc, rnk) <- W.pop w = do
          i       <- tickIter newScc
-         (b, s') <- refineC bindingsInSmt be i s c
+         (b, s') <- refineC scope bindingsInSmt be i s c
          lift $ writeLoud $ refineMsg i c b rnk (showpp s')
          let w'' = if b then W.push c w' else w'
          go be s' w''
@@ -248,20 +250,21 @@
 {-# SCC refineC #-}
 refineC
   :: forall a. (F.Loc a)
-  => F.IBindEnv
+  => S.HashSet F.Symbol
+  -> F.IBindEnv
   -> F.BindEnv a
   -> Int
   -> Sol.Solution
   -> F.SimpC a
   -> SolveM a (Bool, Sol.Solution)
 ---------------------------------------------------------------------------
-refineC bindingsInSmt be _i s c =
+refineC scope bindingsInSmt be _i s c =
   do let krhs = rhsCands s
      cfg <- T.config <$> getContext
      if all (null . snd) krhs
         then return (False, s)
         else do
-          let lhs = S.lhsPred cfg bindingsInSmt be s c
+          let lhs = S.lhsPred cfg scope bindingsInSmt be s c
           kqs <- forM krhs $ \(k, rhs) ->
             (,) k . Sol.QB <$> filterValid (cstrSpan c) lhs rhs
           return $ S.update s kqs
@@ -284,20 +287,21 @@
 {-# SCC result #-}
 result
   :: (F.Fixpoint a, F.Loc a, NFData a)
-  => F.IBindEnv
+  => S.HashSet F.Symbol
+  -> F.IBindEnv
   -> Config
   -> F.SInfo a
   -> [F.SimpC a]
   -> Sol.Solution
   -> SolveM a (F.Result (Integer, a))
 --------------------------------------------------------------------------------
-result bindingsInSmt cfg fi cs s =
+result scope bindingsInSmt cfg fi cs s =
   sendConcreteBindingsToSMT bindingsInSmt be $ \bindingsInSmt2 -> do
     lift       $ writeLoud "Computing Result"
-    stat      <- result_ bindingsInSmt2 be cfg cs s
+    stat      <- result_ scope bindingsInSmt2 be cfg cs s
     lift       $ whenLoud $ putStrLn $ "RESULT: " ++ show (F.sid <$> stat)
     resCut    <- solResult cfg s
-    let resNonCut = S.nonCutsResult cfg be s
+    let resNonCut = S.nonCutsResult cfg scope be s
         resSorts = resultSorts fi (M.keys resCut ++ M.keys resNonCut) be
     return     $ F.Result (ci <$> stat) resCut resNonCut resSorts
   where
@@ -314,8 +318,7 @@
 kvarScope fi be k = do
   w <- M.lookup k (F.ws fi)
   let bs = F.wenv w
-  let (v, t, _) = F.wrft w
-  return $ (v, t) : [ bindInfo be i | i <- L.sort (F.elemsIBindEnv bs) ]
+  return $ F.wvvs w ++ [ bindInfo be i | i <- L.sort (F.elemsIBindEnv bs) ]
 
 bindInfo :: F.BindEnv a -> F.BindId -> (F.Symbol, F.Sort)
 bindInfo be i = (x, F.sr_sort sr)
@@ -327,14 +330,15 @@
 
 result_
   :: (F.Loc a, NFData a)
-  => F.IBindEnv
+  => S.HashSet F.Symbol
+  -> F.IBindEnv
   -> F.BindEnv a
   -> Config
   -> [F.SimpC a]
   -> Sol.Solution
   -> SolveM a (F.FixResult (F.SimpC a))
-result_ bindingsInSmt be cfg cs0 s = do
-  unsatisfiedConstraints <- filterM (isUnsat bindingsInSmt be s) cs
+result_ scope bindingsInSmt be cfg cs0 s = do
+  unsatisfiedConstraints <- filterM (isUnsat scope bindingsInSmt be s) cs
   sts      <- stats
   pure $ res sts unsatisfiedConstraints
   where
@@ -375,13 +379,13 @@
 
 --------------------------------------------------------------------------------
 isUnsat
-  :: (F.Loc a, NFData a) => F.IBindEnv -> F.BindEnv a -> Sol.Solution -> F.SimpC a -> SolveM a Bool
+  :: (F.Loc a, NFData a) => S.HashSet F.Symbol -> F.IBindEnv -> F.BindEnv a -> Sol.Solution -> F.SimpC a -> SolveM a Bool
 --------------------------------------------------------------------------------
-isUnsat bindingsInSmt be s c = do
+isUnsat scope bindingsInSmt be s c = do
   -- lift   $ printf "isUnsat %s" (show (F.subcId c))
   _     <- tickIter True -- newScc
   cfg <- T.config <$> getContext
-  let lp = S.lhsPred cfg bindingsInSmt be s c
+  let lp = S.lhsPred cfg scope bindingsInSmt be s c
       rp = rhsPred c
   res   <- not <$> isValid (cstrSpan c) lp rp
   lift   $ whenLoud $ showUnsat res (F.subcId c) lp rp
diff --git a/src/Language/Fixpoint/Solver/TrivialSort.hs b/src/Language/Fixpoint/Solver/TrivialSort.hs
deleted file mode 100644
--- a/src/Language/Fixpoint/Solver/TrivialSort.hs
+++ /dev/null
@@ -1,181 +0,0 @@
-{-# LANGUAGE CPP           #-}
-{-# LANGUAGE DeriveGeneric #-}
-
-{-# OPTIONS_GHC -Wno-name-shadowing #-}
-
-module Language.Fixpoint.Solver.TrivialSort (nontrivsorts) where
-
-import           GHC.Generics        (Generic)
-import           Language.Fixpoint.Types.PrettyPrint
-import           Language.Fixpoint.Types.Visitor
-import           Language.Fixpoint.Types.Config
-import           Language.Fixpoint.Types hiding (simplify)
-import           Language.Fixpoint.Utils.Files
-import           Language.Fixpoint.Misc
-import qualified Data.HashSet            as S
-import           Data.Hashable
-import qualified Data.HashMap.Strict     as M
-#if !MIN_VERSION_base(4,20,0)
-import           Data.List (foldl')
-#endif
-import qualified Data.Graph              as G
-import           Data.Maybe
-import           Text.Printf
-import           Debug.Trace
-
--------------------------------------------------------------------------
-nontrivsorts :: (Fixpoint a) => Config -> FInfo a -> IO (Result a)
--------------------------------------------------------------------------
-nontrivsorts cfg fi = do
-  let fi' = simplify' cfg fi
-  writeFInfo cfg fi' $ queryFile Out cfg
-  return mempty
-
-simplify' :: Config -> FInfo a -> FInfo a
-simplify' _ fi = simplifyFInfo (mkNonTrivSorts fi) fi
-
---------------------------------------------------------------------
--- | The main data types
---------------------------------------------------------------------
-type NonTrivSorts = S.HashSet Sort
-type KVarMap      = M.HashMap KVar [Sort]
-data Polarity     = Lhs | Rhs
-type TrivInfo     = (NonTrivSorts, KVarMap)
---------------------------------------------------------------------
-
---------------------------------------------------------------------
-mkNonTrivSorts :: FInfo a -> NonTrivSorts
---------------------------------------------------------------------
-mkNonTrivSorts = {- tracepp "mkNonTrivSorts: " . -}  nonTrivSorts . trivInfo
-
---------------------------------------------------------------------
-nonTrivSorts :: TrivInfo -> NonTrivSorts
---------------------------------------------------------------------
-nonTrivSorts ti = S.fromList [s | S s <- ntvs]
-  where
-    ntvs        = [fst3 (f v) | v <- G.reachable g root]
-    (g, f, fv)  = G.graphFromEdges $ ntGraph ti
-    root        = fromMaybe err    $ fv NTV
-    err         = errorstar "nonTrivSorts: cannot find root!"
-
-ntGraph :: TrivInfo -> NTG
-ntGraph ti = [(v,v,vs) | (v, vs) <- groupList $ ntEdges ti]
-
-ntEdges :: TrivInfo -> [(NTV, NTV)]
-ntEdges (nts, kvm) = es ++ [(v, u) | (u, v) <- es]
-  where
-    es = [(NTV, S s) | s       <- S.toList nts         ]
-      ++ [(K k, S s) | (k, ss) <- M.toList kvm, s <- ss]
-
-type NTG = [(NTV, NTV, [NTV])]
-
-data NTV = NTV
-         | K !KVar
-         | S !Sort
-         deriving (Eq, Ord, Show, Generic)
-
-instance Hashable NTV
-
---------------------------------------------------------------------
-trivInfo :: FInfo a -> TrivInfo
---------------------------------------------------------------------
-trivInfo fi = updTISubCs (M.elems $ cm fi)
-            . updTIBinds (bs fi)
-            $ (S.empty, M.empty)
-
-updTISubCs :: [SubC a] -> TrivInfo -> TrivInfo
-updTISubCs cs ti = foldl' (flip updTISubC) ti cs
-
-updTISubC :: SubC a -> TrivInfo -> TrivInfo
-updTISubC c = updTI Lhs (slhs c) . updTI Rhs (srhs c)
-
-updTIBinds :: BindEnv a -> TrivInfo -> TrivInfo
-updTIBinds be ti = foldl' (flip (updTI Lhs)) ti ts
-  where
-    ts           = [t | (_, (_,t,_)) <- bindEnvToList be]
-
---------------------------------------------------------------------
-updTI :: Polarity -> SortedReft -> TrivInfo -> TrivInfo
---------------------------------------------------------------------
-updTI p (RR t r) = addKVs t (kvarsExpr $ reftPred r) . addNTS p r t
-
-addNTS :: Polarity -> Reft -> Sort -> TrivInfo -> TrivInfo
-addNTS p r t ti
-  | isNTR p r = addSort t ti
-  | otherwise = ti
-
-addKVs :: Sort -> [KVar] -> TrivInfo -> TrivInfo
-addKVs t ks ti     = foldl' addK ti ks
-  where
-    addK (ts, m) k = (ts, inserts k t m)
-
-addSort :: Sort -> TrivInfo -> TrivInfo
-addSort t (ts, m) = (S.insert t ts, m)
-
---------------------------------------------------------------------
-isNTR :: Polarity -> Reft -> Bool
---------------------------------------------------------------------
-isNTR Rhs = not . trivR
-isNTR Lhs = not . trivOrSingR
-
-trivR :: Reft -> Bool
-trivR = all trivP . conjuncts . reftPred
-
-trivOrSingR :: Reft -> Bool
-trivOrSingR (Reft (v, p)) = all trivOrSingP $ conjuncts p
-  where
-    trivOrSingP p         = trivP p || singP v p
-
-trivP :: Expr -> Bool
-trivP PKVar {} = True
-trivP p        = isTautoPred p
-
-singP :: Symbol -> Expr -> Bool
-singP v (PAtom Eq (EVar x) _)
-  | v == x                    = True
-singP v (PAtom Eq _ (EVar x))
-  | v == x                    = True
-singP _ _                     = False
-
--------------------------------------------------------------------------
-simplifyFInfo :: NonTrivSorts -> FInfo a -> FInfo a
--------------------------------------------------------------------------
-simplifyFInfo tm fi = fi {
-     cm   = simplifySubCs   tm $ cm fi
-   , ws   = simplifyWfCs    tm $ ws fi
-   , bs   = simplifyBindEnv tm $ bs fi
-}
-
-simplifyBindEnv :: NonTrivSorts -> BindEnv a -> BindEnv a
-simplifyBindEnv tm = mapBindEnv (\_ (x, sr, a) -> (x, simplifySortedReft tm sr, a))
-
-simplifyWfCs :: NonTrivSorts -> M.HashMap KVar (WfC a) -> M.HashMap KVar (WfC a)
-simplifyWfCs tm = M.filter (isNonTrivialSort tm . snd3 . wrft)
-
-simplifySubCs :: (Eq k, Hashable k)
-              => NonTrivSorts -> M.HashMap k (SubC a) -> M.HashMap k (SubC a)
-simplifySubCs ti cm = trace msg cm'
-  where
-    cm' = tx cm
-    tx  = M.fromList . mapMaybe (simplifySubC ti) . M.toList
-    msg = printf "simplifySUBC: before = %d, after = %d \n" n n'
-    n   = M.size cm
-    n'  = M.size cm'
-
-simplifySubC :: NonTrivSorts -> (b, SubC a) -> Maybe (b, SubC a)
-simplifySubC tm (i, c)
- | isNonTrivial srhs' = Just (i, c { slhs = slhs' , srhs = srhs' })
- | otherwise          = Nothing
-  where
-    slhs'             = simplifySortedReft tm (slhs c)
-    srhs'             = simplifySortedReft tm (srhs c)
-
-simplifySortedReft :: NonTrivSorts -> SortedReft -> SortedReft
-simplifySortedReft tm sr
-  | nonTrivial = sr
-  | otherwise  = sr { sr_reft = trueReft }
-  where
-    nonTrivial = isNonTrivialSort tm (sr_sort sr)
-
-isNonTrivialSort :: NonTrivSorts -> Sort -> Bool
-isNonTrivialSort tm t = S.member t tm
diff --git a/src/Language/Fixpoint/Solver/UniqifyBinds.hs b/src/Language/Fixpoint/Solver/UniqifyBinds.hs
--- a/src/Language/Fixpoint/Solver/UniqifyBinds.hs
+++ b/src/Language/Fixpoint/Solver/UniqifyBinds.hs
@@ -81,14 +81,14 @@
     ids                 = elemsIBindEnv (senv s)
     nameMap             = M.fromList [(fst3 $ lookupBindEnv i be, i) | i <- ids]
     m'                  = foldl' (insertIdIdLinks be nameMap) m ids
-    symSet              = S.fromList $ syms $ crhs s
+    symSet              = syms $ crhs s
     refSet              = namesToIds symSet nameMap
 
 insertIdIdLinks :: BindEnv a -> M.HashMap Symbol BindId -> IdMap -> BindId -> IdMap
 insertIdIdLinks be nameMap m i = M.insertWith S.union (RB i) refSet m
   where
     sr     = snd3 $ lookupBindEnv i be
-    symSet = reftFreeVars $ sr_reft sr
+    symSet = syms $ sr_reft sr
     refSet = namesToIds symSet nameMap
 
 namesToIds :: S.HashSet Symbol -> M.HashMap Symbol BindId -> S.HashSet BindId
diff --git a/src/Language/Fixpoint/Solver/UniqifyKVars.hs b/src/Language/Fixpoint/Solver/UniqifyKVars.hs
--- a/src/Language/Fixpoint/Solver/UniqifyKVars.hs
+++ b/src/Language/Fixpoint/Solver/UniqifyKVars.hs
@@ -80,11 +80,11 @@
 updateWfc :: SInfo a -> WfC a -> SInfo a
 updateWfc fi w    = fi'' { ws = M.insert k w' (ws fi) }
   where
-    w'           = w { wenv = insertsIBindEnv newIds mempty, wrft = (v', t, k) }
-    (_, fi'')     = newTopBind v' (trueSortedReft t) a fi'
+    w'           = w { wenv = insertsIBindEnv newIds mempty, wvvs = vvs' }
+    fi''          = foldl' (\fi0 (v', t) -> snd (newTopBind v' (trueSortedReft t) a fi0)) fi' vvs'
     (fi', newIds) = foldl' (accumBindsIfValid k a) (fi, []) (L.sort $ elemsIBindEnv $ wenv w)
-    (v, t, k)     = wrft w
-    v'            = kArgSymbol v (kv k)
+    vvs'          = [ (kArgSymbol v (kv k), t) | (v, t) <- wvvs w ]
+    k             = wkvar w
     a             = winfo w
 
 accumBindsIfValid :: KVar -> a -> (SInfo a, [BindId]) -> BindId -> (SInfo a, [BindId])
diff --git a/src/Language/Fixpoint/SortCheck.hs b/src/Language/Fixpoint/SortCheck.hs
--- a/src/Language/Fixpoint/SortCheck.hs
+++ b/src/Language/Fixpoint/SortCheck.hs
@@ -3,7 +3,6 @@
 {-# LANGUAGE FlexibleContexts      #-}
 {-# LANGUAGE FlexibleInstances     #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE TupleSections         #-}
 {-# LANGUAGE OverloadedStrings     #-}
 {-# LANGUAGE PatternGuards         #-}
 {-# LANGUAGE BangPatterns          #-}
@@ -24,7 +23,6 @@
 
   -- * Checking Well-Formedness
   , checkSorted
-  , checkSortedReft
   , checkSortedReftFull
   , checkSortFull
   , pruneUnsortedReft
@@ -154,8 +152,15 @@
     }
 
 
-instance (Elaborate e) => (Elaborate (Triggered e)) where
-  elaborate ep t = elaborate ep <$> t
+instance Elaborate (Triggered Expr) where
+  elaborate ep (TR t e) = TR (elabTrigger t) (elaborate ep e)
+    where
+      -- explicit patterns mention the variables bound by the quantifier
+      elabTrigger (Patterns ps) = Patterns (fmap (elaborate ep') <$> ps)
+      ep'                       = ep { epEnv = insertsSymEnv (epEnv ep) (quantBinds e) }
+      quantBinds (PAll   xts _) = xts
+      quantBinds (PExist xts _) = xts
+      quantBinds _              = []
 
 instance (Elaborate a) => (Elaborate (Maybe a)) where
   elaborate ep t = elaborate ep <$> t
@@ -539,7 +544,7 @@
 subEnv :: (Subable e, Variable e ~ Symbol) => SEnv a -> e -> SEnv a
 subEnv g e = intersectWithSEnv const g g'
   where
-    g' = fromListSEnv $ (, ()) <$> syms e
+    g' = fromSetSEnv (syms e)
 
 
 --------------------------------------------------------------------------------
@@ -605,12 +610,6 @@
 --------------------------------------------------------------------------------
 -- | Checking Refinements ------------------------------------------------------
 --------------------------------------------------------------------------------
-checkSortedReft :: SEnv SortedReft -> [Symbol] -> SortedReft -> Maybe Doc
-checkSortedReft env xs sr = applyNonNull Nothing oops unknowns
-  where
-    oops                  = Just . (text "Unknown symbols:" <+>) . toFix
-    unknowns              = [ x | x <- syms sr, x `notElem` v : xs, not (x `memberSEnv` env)]
-    Reft (v,_)            = sr_reft sr
 
 checkSortedReftFull :: Checkable a => SrcSpan -> SEnv SortedReft -> a -> ElabM (Maybe Doc)
 checkSortedReftFull sp γ t =
@@ -1477,6 +1476,15 @@
   | otherwise               = throwErrorAt (errUnifyMany ts ts')
 
 unify1 :: Env -> Maybe Expr -> TVSubst -> Sort -> Sort -> CheckM TVSubst
+-- Polymorphic sorts are instantiated before the variable cases, so that a sort
+-- variable is never bound to an uninstantiated `FAbs`, whose bound variables
+-- could clash with the variables of the other sort.
+unify1 f e !θ t1@(FAbs _ _) !t2 = do
+  !t1' <- instantiate t1
+  unifyMany f e θ [t1'] [t2]
+unify1 f e !θ !t1 t2@(FAbs _ _) = do
+  !t2' <- instantiate t2
+  unifyMany f e θ [t1] [t2']
 unify1 f e !θ (FVar !i) !t
   = unifyVar f e θ i t
 unify1 f e !θ !t (FVar !i)
@@ -1486,12 +1494,6 @@
 unify1 _ _ !θ (FTC !l1) (FTC !l2)
   | isListTC l1 && isListTC l2
   = return θ
-unify1 f e !θ t1@(FAbs _ _) !t2 = do
-  !t1' <- instantiate t1
-  unifyMany f e θ [t1'] [t2]
-unify1 f e !θ !t1 t2@(FAbs _ _) = do
-  !t2' <- instantiate t2
-  unifyMany f e θ [t1] [t2']
 unify1 _ _ !θ !s1 !s2
   | isString s1, isString s2
   = return θ
diff --git a/src/Language/Fixpoint/Types/Config.hs b/src/Language/Fixpoint/Types/Config.hs
--- a/src/Language/Fixpoint/Types/Config.hs
+++ b/src/Language/Fixpoint/Types/Config.hs
@@ -68,6 +68,7 @@
   , minPartSize :: Int                 -- ^ Minimum size of a partition
   , maxPartSize :: Int                 -- ^ Maximum size of a partition. Overrides minPartSize
   , solver      :: SMTSolver           -- ^ which SMT solver to use
+  , solverPath  :: Maybe FilePath      -- ^ executable of the SMT solver (default: a name inferred from the value of the --solver flag)
   , linear      :: Bool                -- ^ not interpret div and mul in SMT
   , defunction  :: Bool                -- ^ defunctionalize (use 'apply' for all uninterpreted applications)
   , allowHO     :: Bool                -- ^ allow higher order binders in the logic environment
@@ -215,6 +216,7 @@
   { srcFile            = "out"
   , defunction         = False
   , solver             = if Conditional.Z3.builtWithZ3AsALibrary then Z3mem else Z3
+  , solverPath         = Nothing
   , linear             = False
   , noStringTheory     = False
   , allowHO            = False
@@ -302,7 +304,13 @@
         ]
       )
   , Option [] ["solver"]           (ReqArg setSolver "SOLVER")
-      ("SMT solver [" ++ L.intercalate " | " ["z3", "z3mem", "cvc4", "cvc5", "mathsat"] ++ "]")
+      (unlines
+        [ "Selects the configuration to use for a given solver [" ++ L.intercalate " | " ["z3", "z3mem", "cvc4", "cvc5", "mathsat"] ++ "]"
+        , "Determines initialization flags and the executable to search on the PATH."
+        ]
+      )
+  , Option [] ["solver-path"]      (ReqArg setSolverPath "FILE")
+      "Executable of the SMT solver selected with --solver (default: a name inferred from the value of the --solver flag, then looked up in the PATH)"
   , Option [] ["elimBound"]        (ReqArg (\s -> FxMod $ \c -> c { elimBound   = parseInt "elimBound" s }) "N")
       "(alpha) Maximum eliminate-chain depth"
   , Option [] ["smtTimeout"]       (ReqArg (\s -> FxMod $ \c -> c { smtTimeout  = parseInt "smtTimeout" s }) "N")
@@ -404,6 +412,7 @@
       error $ "Expected true/false, got: " ++ s ++ " (current default: " ++ show (getDef defConfig) ++ ")"
 
     setSolver s   = FxMod $ \c -> c { solver    = parseSolver s }
+    setSolverPath s = FxMod $ \c -> c { solverPath = Just s }
     setEliminate s = FxMod $ \c -> c { eliminate = parseEliminate s }
     setScrape s   = FxMod $ \c -> c { scrape    = parseScrape s }
     setSaveDir s = FxMod $ \c -> c { saveDir   = Just s }
diff --git a/src/Language/Fixpoint/Types/Constraints.hs b/src/Language/Fixpoint/Types/Constraints.hs
--- a/src/Language/Fixpoint/Types/Constraints.hs
+++ b/src/Language/Fixpoint/Types/Constraints.hs
@@ -36,6 +36,7 @@
 
   -- * Constraints
   , WfC (..)
+  , wrft
   , SubC, SubcId
   , mkSubC, subcId, sid, senv, updateSEnv, slhs, srhs, stag, subC, wfC
   , SimpC (..)
@@ -56,6 +57,7 @@
   , QualParam   (..)
   , QualPattern (..)
   , trueQual
+  , falseQual
   , qualifier
   , mkQual
   , remakeQual
@@ -122,7 +124,7 @@
 import           Language.Fixpoint.Types.Spans
 import           Language.Fixpoint.Types.Sorts
 import           Language.Fixpoint.Types.Refinements
-import           Language.Fixpoint.Types.Substitutions()
+import           Language.Fixpoint.Types.Substitutions
 import           Language.Fixpoint.Types.Environments
 import qualified Language.Fixpoint.Utils.Files as Files
 import qualified Language.Fixpoint.Solver.Stats as Solver
@@ -145,7 +147,13 @@
 type Tag           = [Int]
 
 data WfC a  =  WfC  { wenv  :: !IBindEnv
-                    , wrft  :: (Symbol, Sort, KVar)
+                      -- ^ The parameters of the kvar other than its value variables
+                    , wvvs  :: ![(Symbol, Sort)]
+                      -- ^ The value variables of the kvar. Qualifiers are only
+                      --   instantiated with candidates that bind their first
+                      --   parameter to a value variable, so a kvar without
+                      --   value variables can only be solved to @true@ or @false@.
+                    , wkvar :: !KVar
                     , winfo :: !a
                     }
               deriving (Eq, Generic, Functor)
@@ -393,10 +401,20 @@
 instance Fixpoint a => Fixpoint (WfC a) where
   toFix w     = hang (text "\n\nwf:") 2 bd
     where bd  =   toFix (wenv w)
+              $+$ warning
               -- NOTE: this next line is printed this way for compatability with the OCAML solver
-              $+$ text "reft" <+> toFix (RR t (Reft (v, PKVar k M.empty mempty)))
+              $+$ text "reft" <+> toFix (RR t (Reft (v, PKVar (wkvar w) M.empty mempty)))
               $+$ toFixMeta (text "wf") (toFix (winfo w))
-          (v, t, k) = wrft w
+          -- The .fq format has exactly one value variable per kvar, so other
+          -- wf constraints are printed lossily, with a warning.
+          ((v, t), warning) = case wvvs w of
+            [vt]   -> (vt, empty)
+            vt : _ -> (vt, lossy "only the first one is printed")
+            []     -> ((vv Nothing, intSort), lossy "a dummy one is printed")
+          -- rendered as a single line so that it stays a comment
+          lossy msg = text $ "// WARNING: the .fq format cannot express the value variables ["
+                      ++ L.intercalate ", " [ render (toFix x <+> colon <+> toFix t') | (x, t') <- wvvs w ]
+                      ++ "] of " ++ render (toFix (wkvar w)) ++ "; " ++ msg
 
 toFixMeta :: Doc -> Doc -> Doc
 toFixMeta k v = text "// META" <+> k <+> text ":" <+> v
@@ -446,7 +464,7 @@
 wfC be sr x = if all isEmptyKVarSubst sus -- ++ gsus)
                  -- NV TO RJ This tests fails with [LT:=GHC.Types.LT][EQ:=GHC.Types.EQ][GT:=GHC.Types.GT]]
                  -- NV TO RJ looks like a resolution issue
-                then [WfC be (v, sr_sort sr, k) x      | k         <- ks ]
+                then [WfC be [(v, sr_sort sr)] k x | k <- ks ]
                 else errorstar msg
   where
     msg             = "wfKvar: malformed wfC " ++ show sr ++ "\n" ++ show sus
@@ -457,7 +475,15 @@
     go (PAnd es)    = [(k, su) | PKVar k _ su <- es]
     go _            = []
 
+-- | The (first) value variable, its sort and the kvar of a wf constraint. Fails
+--   on a wf constraint without value variables.
+wrft :: WfC a -> (Symbol, Sort, KVar)
+wrft w = case wvvs w of
+  (v, t) : _ -> (v, t, wkvar w)
+  []         -> errorstar $ "wrft: wf constraint without value variables: " ++ showpp (wkvar w)
+{-# DEPRECATED wrft "A wf constraint can have zero or several value variables, use wvvs and wkvar" #-}
 
+
 mkSubC :: IBindEnv -> SortedReft -> SortedReft -> Maybe Integer -> Tag -> a -> SubC a
 mkSubC = SubC
 
@@ -539,6 +565,9 @@
 trueQual :: Qualifier
 trueQual = Q (symbol ("QTrue" :: String)) [] PTrue (dummyPos "trueQual")
 
+falseQual :: Qualifier
+falseQual = Q (symbol ("QFalse" :: String)) [] PFalse (dummyPos "falseQual")
+
 instance Loc Qualifier where
   srcSpan q = SS l l
     where
@@ -546,17 +575,17 @@
 
 instance Subable Qualifier where
   syms   = qualFreeSymbols
-  subst  = mapQualBody . subst
-  substf = mapQualBody . substf
-  substa = mapQualBody . substa
-
-mapQualBody :: (Expr -> Expr) -> Qualifier -> Qualifier
-mapQualBody f q = q { qBody = f (qBody q) }
+  substr ns su q =
+    let xs  = qpSym <$> qParams q
+        (ns', xs') = freshInNSL xs ns
+        su' = L.foldl' (\acc (x, x') -> extendSubstWithVar acc x x') su (zip xs xs')
+        ps' = zipWith (\qp x' -> qp { qpSym = x' }) (qParams q) xs'
+    in  q { qParams = ps', qBody = substr ns' su' (qBody q) }
 
-qualFreeSymbols :: Qualifier -> [Symbol]
-qualFreeSymbols q = filter (not . isPrim) xs
+qualFreeSymbols :: Qualifier -> S.HashSet Symbol
+qualFreeSymbols q = S.filter (not . isPrim) xs
   where
-    xs            = syms (qBody q) L.\\ syms (qpSym <$> qParams q)
+    xs            = syms (qBody q) `S.difference` S.fromList (qpSym <$> qParams q)
 
 instance Fixpoint QualParam where
   toFix (QP x _ t) = toFix (x, t)
@@ -589,8 +618,8 @@
 qualifier :: SEnv Sort -> SourcePos -> SEnv Sort -> Symbol -> Sort -> Expr -> Qualifier
 qualifier lEnv l γ v so p   = mkQ "Auto" ((v, so) : xts) p l
   where
-    xs  = L.delete v $ L.nub $ syms p
-    xts = catMaybes $ zipWith (envSort l lEnv γ) xs [0..]
+    xs  = S.delete v $ syms p
+    xts = catMaybes $ zipWith (envSort l lEnv γ) (S.toList xs) [0..]
 
 mkQ :: Symbol -> [(Symbol, Sort)] -> Expr -> SourcePos -> Qualifier
 mkQ n = Q n . qualParams
@@ -698,7 +727,7 @@
    -> GInfo SubC a
 fi cs ws binds ls ds ks qs bi aHO aHOq es axe adts
   = FI { cm       = M.fromList $ addIds cs
-       , ws       = M.fromListWith err [(k, w) | w <- ws, let (_, _, k) = wrft w]
+       , ws       = M.fromListWith err [(wkvar w, w) | w <- ws]
        , bs       = binds
        , gLits    = ls
        , dLits    = ds
@@ -831,7 +860,7 @@
     gConDoc       = sEnvDoc "constant"             . gLits
     dConDoc       = sEnvDoc "distinct"             . dLits
     csDoc         = vcat     . map (toFix . snd) . hashMapToAscList . cm
-    wsDoc         = vcat     . map toFix . L.sortOn (thd3 . wrft) . M.elems . ws
+    wsDoc         = vcat     . map toFix . L.sortOn wkvar . M.elems . ws
     kutsDoc       = toFix    . kuts
     -- packsDoc      = toFix    . packs
     declsDoc      = vcat     . map ((text "data" <+>) . toFix) . L.sort . ddecls
@@ -1041,12 +1070,11 @@
 
 instance Subable Equation where
   syms   a = syms (eqBody a) -- ++ F.syms (axiomEq a)
-  subst su = mapEqBody (subst su)
-  substf f = mapEqBody (substf f)
-  substa f = mapEqBody (substa f)
-
-mapEqBody :: (Expr -> Expr) -> Equation -> Equation
-mapEqBody f a = a { eqBody = f (eqBody a) }
+  substr ns su eq =
+    let (xs, sorts) = unzip (eqArgs eq)
+        (ns', xs')  = freshInNSL xs ns
+        su'  = L.foldl' (\acc (x, x') -> extendSubstWithVar acc x x') su (zip xs xs')
+    in  eq { eqArgs = zip xs' sorts, eqBody = substr ns' su' (eqBody eq) }
 
 instance PPrint Equation where
   pprintTidy _ = toFix
diff --git a/src/Language/Fixpoint/Types/Environments.hs b/src/Language/Fixpoint/Types/Environments.hs
--- a/src/Language/Fixpoint/Types/Environments.hs
+++ b/src/Language/Fixpoint/Types/Environments.hs
@@ -18,7 +18,7 @@
   , SEnvB(..)
   , SESearch
   , SESearchB(..)
-  , emptySEnv, toListSEnv, fromListSEnv, fromMapSEnv
+  , emptySEnv, toListSEnv, fromListSEnv, fromMapSEnv, fromSetSEnv
   , mapSEnvWithKey, mapSEnv, mapMSEnv
   , insertSEnv, deleteSEnv, memberSEnv, lookupSEnv, unionSEnv, unionSEnv'
   , intersectWithSEnv
@@ -128,6 +128,9 @@
 
 fromMapSEnv             ::  M.HashMap b a -> SEnvB b a
 fromMapSEnv             = SE
+
+fromSetSEnv             ::  S.HashSet b -> SEnvB b ()
+fromSetSEnv             = SE . S.toMap
 
 mapSEnv                 :: (a₁ -> a₂) -> SEnvB b a₁ -> SEnvB b a₂
 mapSEnv f (SE env)      = SE (fmap f env)
diff --git a/src/Language/Fixpoint/Types/Names.hs b/src/Language/Fixpoint/Types/Names.hs
--- a/src/Language/Fixpoint/Types/Names.hs
+++ b/src/Language/Fixpoint/Types/Names.hs
@@ -49,6 +49,7 @@
   , suffixOfSym
   , stripPrefix
   , stripSuffix
+  , unSuffixSymbol
   , consSym
   , unconsSym
   , dropSym
@@ -74,6 +75,7 @@
   , tempSymbol
   , appendSymbolText
   , hvarArgSymbol
+  , symSepName
 
   -- * Wrapping Symbols
   , litSymbol
@@ -110,6 +112,7 @@
   , sizeName
   , bitVecName
   , intbv32Name, intbv64Name, bv32intName, bv64intName
+  , intbv128Name, bv128intName
   , intbv8Name, intbv16Name, bv8intName, bv16intName
   , propConName
 
@@ -686,6 +689,10 @@
 intbv64Name = "int_to_bv64"
 bv32intName = "bv32_to_int"
 bv64intName = "bv64_to_int"
+
+intbv128Name, bv128intName :: Symbol
+intbv128Name = "int_to_bv128"
+bv128intName = "bv128_to_int"
 
 intbv8Name, intbv16Name, bv8intName, bv16intName :: Symbol
 intbv8Name  = "int_to_bv8"
diff --git a/src/Language/Fixpoint/Types/Refinements.hs b/src/Language/Fixpoint/Types/Refinements.hs
--- a/src/Language/Fixpoint/Types/Refinements.hs
+++ b/src/Language/Fixpoint/Types/Refinements.hs
@@ -58,7 +58,6 @@
   -- * Generalizing Embedding with Typeclasses
   , Expression (..)
   , Predicate (..)
-  , Subable (..)
 
   -- * Constructors
   , reft                    -- "smart
@@ -109,6 +108,7 @@
   , onEverySubexpr
   , mapBindExpr
   , pprintReft
+  , catKVarSubst
   , mapKVarSubst
   , mapBindKVarSubst
   , mapBindReft
@@ -128,7 +128,6 @@
 import           Data.HashSet              (HashSet)
 import qualified Data.HashSet              as HashSet
 import           GHC.Generics              (Generic)
-import           GHC.Stack                 (HasCallStack)
 #if MIN_VERSION_base(4,20,0)
 import           Data.List                 (partition)
 #else
@@ -195,7 +194,7 @@
 instance (B.Binary v, Hashable v) => B.Binary (SubstV v)
 instance (B.Binary b, B.Binary v) => B.Binary (KVarSubst b v)
 instance (B.Binary b, B.Binary v) => B.Binary (ExprBV b v)
-instance B.Binary v => B.Binary (ReftV v)
+instance (B.Binary b, B.Binary v) => B.Binary (ReftBV b v)
 
 
 reftConjuncts :: Reft -> [Reft]
@@ -237,7 +236,7 @@
 instance Hashable v => Hashable (SubstV v)
 instance (Hashable b, Hashable v) => Hashable (KVarSubst b v)
 instance (Hashable b, Hashable v) => Hashable (ExprBV b v)
-instance Hashable v => Hashable (ReftV v)
+instance (Hashable b, Hashable v) => Hashable (ReftBV b v)
 
 --------------------------------------------------------------------------------
 -- | Substitutions -------------------------------------------------------------
@@ -258,7 +257,8 @@
 instance (Ord v, Hashable v, Fixpoint v) => PPrint (SubstV v) where
   pprintTidy _ = toFix
 
-newtype KVarSubst b v = KSu [(b, ExprBV b v)]
+newtype KVarSubst b v =
+    KSu [(b, ExprBV b v)] -- ^ No duplicate entries are allowed in the list.
   deriving (Eq, Ord, Data, Typeable, Generic, Functor, Foldable, Traversable)
 
 fromKVarSubst :: Hashable b => KVarSubst b v -> M.HashMap b (ExprBV b v)
@@ -276,6 +276,14 @@
 isEmptyKVarSubst :: KVarSubst b v -> Bool
 isEmptyKVarSubst (KSu su) = null su
 
+-- | @t [catKVarSubst su kvs] = t [su, kvs]@
+--
+-- No substitions are made in expressions of @su@.
+catKVarSubst :: Eq b => KVarSubst b v -> [(b, ExprBV b v)] -> KVarSubst b v
+catKVarSubst (KSu su) kvs = KSu $ filter (not . inSu . fst) kvs ++ su
+  where
+    inSu b = any ((== b) . fst) su
+
 instance (Ord v, Fixpoint v, Ord b, Fixpoint b, Hashable b) => Show (KVarSubst b v) where
   show = showFix
 
@@ -1095,30 +1103,6 @@
 
 instance Falseable (ReftBV b v) where
   isFalse (Reft (_, ra)) = isFalse ra
-
--------------------------------------------------------------------------
--- | Class Predicates for Valid Refinements -----------------------------
--------------------------------------------------------------------------
-
-class (Eq (Variable a), Hashable (Variable a)) => Subable a where
-  type Variable a
-  type Variable a = Symbol
-
-  syms   :: a -> [Variable a]                   -- ^ free symbols of a
-  substa :: (Variable a -> Variable a) -> a -> a
-  -- substa f  = substf (EVar . f)
-
-  substf :: (Variable a -> ExprBV (Variable a) (Variable a)) -> a -> a
-  subst  :: HasCallStack => SubstV (Variable a) -> a -> a
-  subst1 :: a -> (Variable a, ExprBV (Variable a) (Variable a)) -> a
-  subst1 y (x, e) = subst (Su $ M.fromList [(x,e)]) y
-
-instance Subable a => Subable (Located a) where
-  type Variable (Located a) = Variable a
-  syms (Loc _ _ x)   = syms x
-  substa f (Loc l l' x) = Loc l l' (substa f x)
-  substf f (Loc l l' x) = Loc l l' (substf f x)
-  subst su (Loc l l' x) = Loc l l' (subst su x)
 
 instance Fixpoint Doc where
   toFix = id
diff --git a/src/Language/Fixpoint/Types/Solutions.hs b/src/Language/Fixpoint/Types/Solutions.hs
--- a/src/Language/Fixpoint/Types/Solutions.hs
+++ b/src/Language/Fixpoint/Types/Solutions.hs
@@ -32,6 +32,7 @@
   -- * Equal elements
   , eQual
   , trueEqual
+  , falseEqual
 
   , qbExprs
 
@@ -236,6 +237,9 @@
 
 trueEqual :: EQual
 trueEqual = EQL trueQual PTrue []
+
+falseEqual :: EQual
+falseEqual = EQL falseQual PFalse []
 
 instance PPrint EQual where
   pprintTidy k = pprintTidy k . eqPred
diff --git a/src/Language/Fixpoint/Types/Substitutions.hs b/src/Language/Fixpoint/Types/Substitutions.hs
--- a/src/Language/Fixpoint/Types/Substitutions.hs
+++ b/src/Language/Fixpoint/Types/Substitutions.hs
@@ -1,10 +1,11 @@
 {-# LANGUAGE CPP               #-}
+{-# LANGUAGE FlexibleContexts  #-}
 {-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE TypeFamilies      #-}
 {-# LANGUAGE TypeOperators     #-}
 
 {-# OPTIONS_GHC -Wno-orphans   #-}
-{-# LANGUAGE InstanceSigs #-}
 
 -- | This module contains the various instances for Subable,
 --   which (should) depend on the visitors, and hence cannot
@@ -19,36 +20,42 @@
   , substExcept
   , substfExcept
   , subst1Except
+  , subst1
+  , substa
+  , substf
   , substSymbolsSet
   , Refreshable(..)
+  , Subable(..)
+  , subst
   , rapierSubstExpr
-  , targetSubstSyms
   , filterSubst
   , catSubst
   , exprSymbolsSet
   , extendSubst
+  , extendSubstWithVar
+  , freshInNS
+  , freshInNSL
   , meetReft
   , pprReft
   ) where
 
 import           Data.List                 as List
-import           Data.Maybe
 import           Data.Hashable             (Hashable)
 import qualified Data.HashMap.Strict       as M
 import qualified Data.HashSet              as S
+import qualified Data.Text                 as T
+import           GHC.Stack                 (HasCallStack)
 import           Language.Fixpoint.Types.Binders
 import           Language.Fixpoint.Types.PrettyPrint
 import           Language.Fixpoint.Types.Names
-import           Language.Fixpoint.Types.Sorts
+import           Language.Fixpoint.Types.Spans
 import           Language.Fixpoint.Types.Refinements
-import           Language.Fixpoint.Misc
 import           Text.PrettyPrint.HughesPJ.Compat
-import           Text.Printf               (printf)
 
-instance (Eq v, Hashable v) => Semigroup (SubstV v) where
+instance (Eq v, Hashable v, Refreshable v) => Semigroup (SubstV v) where
   (<>) = catSubst
 
-instance (Eq v, Hashable v) => Monoid (SubstV v) where
+instance (Eq v, Hashable v, Refreshable v) => Monoid (SubstV v) where
   mempty  = emptySubst
   mappend = (<>)
 
@@ -74,7 +81,7 @@
 emptySubst :: SubstV v
 emptySubst = Su M.empty
 
-catSubst :: (Eq v, Hashable v) => SubstV v -> SubstV v -> SubstV v
+catSubst :: (Eq v, Hashable v, Refreshable v) => SubstV v -> SubstV v -> SubstV v
 catSubst (Su s1) θ2@(Su s2) = Su $ M.union s1' s2
   where
     s1'                     = subst θ2 <$> s1
@@ -91,47 +98,80 @@
 isEmptySubst :: SubstV v -> Bool
 isEmptySubst (Su xes) = M.null xes
 
-targetSubstSyms :: (Eq v, Hashable v) => SubstV v -> [v]
-targetSubstSyms (Su ms) = syms $ M.elems ms
-
 substSymbolsSet :: (Eq v, Hashable v) => SubstV v -> S.HashSet v
 substSymbolsSet (Su m) = S.unions $ map exprSymbolsSet (M.elems m)
 
+toListSubst :: SubstV v -> [(v, ExprBV v v)]
+toListSubst (Su m) = M.toList m
+
+-- | The Subable class provides overloaded names to compute the free symbols of
+-- a value, and to perform capture-avoiding substitution on it.
+class (Eq (Variable a), Hashable (Variable a)) => Subable a where
+  type Variable a
+  type Variable a = Symbol
+
+  -- | Free symbols of a value
+  syms   :: a -> S.HashSet (Variable a)
+
+  -- | Capture-avoiding substitution of a value, given a scope set of symbols
+  -- that are allowed to appear free in the result.
+  --
+  -- When a binder's name is in the scope set, it is renamed to a fresh name.
+  -- In this way, it cannot capture free variables in the range of the
+  -- substitution as these free variables need to be necessarily in scope.
+  --
+  -- The fresh name is chosen so it does not appear in the scope set, and
+  -- therefore the scope set must really contain all names in scope so the new
+  -- "fresh" name does not accidentally capture free variables in the term
+  -- on which the substitution is applied.
+  --
+  substr :: HasCallStack => S.HashSet (Variable a) -> SubstV (Variable a) -> a -> a
+
+subst :: (HasCallStack, Subable a) => SubstV (Variable a) -> a -> a
+subst su e = substr ns su e
+  where
+    ns = substSymbolsSet su `S.union` syms e
+
+instance Subable a => Subable (Located a) where
+  type Variable (Located a) = Variable a
+  syms (Loc _ _ x)   = syms x
+  substr ns m (Loc l l' x) = Loc l l' (substr ns m x)
+
 instance Subable () where
-  syms _      = []
-  subst _ ()  = ()
-  substf _ () = ()
-  substa _ () = ()
+  syms _         = S.empty
+  substr _ _ ()  = ()
 
 instance (Subable a, Subable b, Variable a ~ Variable b) => Subable (a,b) where
   type Variable (a, b) = Variable a
-  syms  (x, y)   = syms x ++ syms y
-  subst su (x,y) = (subst su x, subst su y)
-  substf f (x,y) = (substf f x, substf f y)
-  substa f (x,y) = (substa f x, substa f y)
 
+  syms  (x, y)      = S.union (syms x) (syms y)
+  substr ns su (x,y) = (substr ns su x, substr ns su y)
+
 instance Subable a => Subable [a] where
   type Variable [a] = Variable a
-  syms   = concatMap syms
-  subst  = fmap . subst
-  substf = fmap . substf
-  substa = fmap . substa
+  syms             = S.unions . map syms
+  substr ns su     = fmap (substr ns su)
 
 instance Subable a => Subable (Maybe a) where
   type Variable (Maybe a) = Variable a
-  syms   = concatMap syms . maybeToList
-  subst  = fmap . subst
-  substf = fmap . substf
-  substa = fmap . substa
+  syms             = maybe S.empty syms
+  substr ns m      = fmap (substr ns m)
 
 
 instance Subable a => Subable (M.HashMap k a) where
   type Variable (M.HashMap k a) = Variable a
-  syms   = syms . M.elems
-  subst  = M.map . subst
-  substf = M.map . substf
-  substa = M.map . substa
+  syms             = syms . M.elems
+  substr ns su     = M.map (substr ns su)
 
+subst1 :: Subable a => a -> (Variable a, ExprBV (Variable a) (Variable a)) -> a
+subst1 y (x, e) = subst (Su $ M.fromList [(x, e)]) y
+
+substa :: Subable a => (Variable a -> Variable a) -> a -> a
+substa f = substf (EVar . f)
+
+substf :: Subable a => (Variable a -> ExprBV (Variable a) (Variable a)) -> a -> a
+substf f e = subst (Su $ M.mapWithKey (const . f) $ S.toMap $ syms e) e
+
 subst1Except :: Subable a => [Variable a] -> a -> (Variable a, ExprBV (Variable a) (Variable a)) -> a
 subst1Except xs z su@(x, _)
   | x `elem` xs = z
@@ -144,217 +184,128 @@
 -- substExcept  (Su m) xs = Su (foldr M.delete m xs)
 substExcept (Su xes) xs = Su $ M.filterWithKey (const . not . (`elem` xs)) xes
 
-instance Subable Symbol where
-  substa f                 = f
-  substf f x               = subSymbol (Just (f x)) x
-  subst su x               = subSymbol (Just $ appSubst su x) x -- subSymbol (M.lookup x s) x
-  syms x                   = [x]
-
 appSubst :: (Eq v, Hashable v) => SubstV v -> v -> ExprBV v v
-appSubst (Su s) x = fromMaybe (EVar x) (M.lookup x s)
-
-subSymbol :: (Ord v, Hashable v, Fixpoint v) => Maybe (ExprBV v v) -> v -> v
-subSymbol (Just (EVar y)) _ = y
-subSymbol Nothing         x = x
-subSymbol a               b = errorstar (printf "Cannot substitute symbol %s with expression %s" (showFix b) (showFix a))
-
-captureAvoiding :: Eq v => v -> (v -> ExprBV b v) -> v -> ExprBV b v
-captureAvoiding x f y = if y == x then EVar x else f y
+appSubst (Su s) x = M.findWithDefault (EVar x) x s
 
-instance (Eq v, Hashable v) => Subable (ExprBV v v) where
+instance (Eq v, Hashable v, Refreshable v) => Subable (ExprBV v v) where
   type Variable (ExprBV v v) = v
-  syms                     = exprSymbols
-  substa f                 = substf (EVar . f)
-  substf :: (v -> ExprBV v v) -> ExprBV v v -> ExprBV v v
-  substf f (EApp s e)      = EApp (substf f s) (substf f e)
-  substf f (ELam (x,t) e)  = ELam (x, t) (substf (captureAvoiding x f) e)
-  substf f (ECoerc a t e)  = ECoerc a t (substf f e)
-  substf f (ENeg e)        = ENeg (substf f e)
-  substf f (EBin op e1 e2) = EBin op (substf f e1) (substf f e2)
-  substf f (ELet x e1 e2)  = ELet x (substf f e1) (substf (captureAvoiding x f) e2)
-  substf f (EIte p e1 e2)  = EIte (substf f p) (substf f e1) (substf f e2)
-  substf f (ECst e so)     = ECst (substf f e) so
-  substf f (EVar x)        = f x
-  substf f (PAnd ps)       = PAnd $ map (substf f) ps
-  substf f (POr  ps)       = POr  $ map (substf f) ps
-  substf f (PNot p)        = PNot $ substf f p
-  substf f (PImp p1 p2)    = PImp (substf f p1) (substf f p2)
-  substf f (PIff p1 p2)    = PIff (substf f p1) (substf f p2)
-  substf f (PAtom r e1 e2) = PAtom r (substf f e1) (substf f e2)
-  substf f (PKVar k tsu su)    = PKVar k tsu (mapKVarSubst (substf f) su)
-  substf _ (PAll _ _)      = errorstar "substf: FORALL"
-  substf f (PExist xts e)  = PExist xts (substf f e)
-  substf _  p              = p
-
-
-  subst = go
-    where
-      -- The auxiliary go function skips the HasCallStack constraint on every
-      -- recursive call. In case of error, the call stack only contains the
-      -- point at which subst was first called.
-      go su e0 = case e0 of
-        EApp f e ->
-          EApp (go su f) (go su e)
-        ELam x e ->
-          let su' = removeSubst su (fst x)
-           in ELam x (go su' e)
-        ELet x e1 e2 ->
-          let su' = removeSubst su x
-           in ELet x (go su e1) (go su' e2)
-        ECoerc a t e ->
-          ECoerc a t (go su e)
-        ENeg e ->
-          ENeg (go su e)
-        EBin op e1 e2 ->
-          EBin op (go su e1) (go su e2)
-        EIte p e1 e2 ->
-          EIte (go su p) (go su e1) (go su e2)
-        ECst e so ->
-          ECst (go su e) so
-        EVar x ->
-          appSubst su x
-        PAnd ps ->
-          PAnd $ map (go su) ps
-        POr  ps ->
-          POr  $ map (go su) ps
-        PNot p ->
-          PNot $ go su p
-        PImp p1 p2 ->
-          PImp (go su p1) (go su p2)
-        PIff p1 p2 ->
-          PIff (go su p1) (go su p2)
-        PAtom r e1 e2 ->
-          PAtom r (go su e1) (go su e2)
-        PKVar k tsu su' ->
-          PKVar k tsu (kSubstFromSubst $ substFromKSubst su' `catSubst` su)
-        PAll bs p
-          | disjointRange su' bs ->
-            PAll bs $ go su' p
-          | otherwise ->
-            errorstar "subst: PAll (without disjoint binds)"
-          where
-            su' = substExcept su (map fst bs)
-
-        PExist bs p
-          | disjointRange su' bs ->
-            PExist bs $ go su' p
-          | otherwise ->
-            errorstar "subst: EXISTS without disjoint binds"
-          where
-            su' = substExcept su (map fst bs)
-        p ->
-          p
-
-removeSubst :: (Eq v, Hashable v) => SubstV v -> v -> SubstV v
-removeSubst (Su su) x = Su $ M.delete x su
+  syms  = exprSymbolsSet
+  substr = rapierSubstExpr
 
--- | Variable names for which we can propose variations to avoid name captures
+--- | Variable names for which we can propose variations to avoid name captures
 class Refreshable v where
   -- | Variations of a variable name. They must contain at least a fresh name in
   -- the contexts where @candidates@ is used.
   candidates :: v -> [v]
 
 instance Refreshable Symbol where
-  candidates x = [ renameSubstSymbol x i | i <- [0..] ]
+  candidates x =
+     let (x', i) = splitIntSuffix x
+      in x : map (intSymbol x') [i..]
+    where
+      splitIntSuffix sx =
+        case T.breakOnEnd symSepName (symbolText sx) of
+          (pfx, sfx)
+            | T.null pfx -> (sx, 0 :: Int)
+            | otherwise  -> case reads (T.unpack sfx) of
+              ((i, []) : _) -> (unSuffixSymbol sx, i + 1 :: Int)
+              _ -> (sx, 0 :: Int)
 
 -- | Rapier style capture-avoiding substitution
 --
--- The scope set parameter must contain any symbols that are expected
--- to appear free in the result expression. Typically, this is the set of
--- symbols that are free in the range of the substitution, plus any symbols
--- that are already free in the input expression.
-rapierSubstExpr :: (Hashable v, Refreshable v) => S.HashSet v -> SubstV v -> ExprBV v v -> ExprBV v v
-rapierSubstExpr s su e0 =
-  let go = rapierSubstExpr
-   in case e0 of
-    EApp f e -> EApp (go s su f) (go s su e)
-    ELam (x, t) e ->
-      if x `S.member` s then
-        let x' = fresh x
-            su' = extendSubst su x (EVar x')
-         in ELam (x', t) (go (S.insert x' s) su' e)
-      else
-        ELam (x, t) (go (S.insert x s) (removeSubst su x) e)
-    ELet x e1 e2 ->
-      if x `S.member` s then
-        let x' = fresh x
-            su' = extendSubst su x (EVar x')
-         in ELet x' (go s su e1) (go (S.insert x' s) su' e2)
-      else
-        let su' = removeSubst su x
-         in ELet x (go s su e1) (go (S.insert x s) su' e2)
-
-    ECoerc a t e -> ECoerc a t (go s su e)
-    ENeg e -> ENeg (go s su e)
-    EBin op e1 e2 -> EBin op (go s su e1) (go s su e2)
-    EIte p e1 e2 -> EIte (go s su p) (go s su e1) (go s su e2)
-    ECst e so -> ECst (go s su e) so
-    EVar x -> appSubst su x
-    PAnd ps -> PAnd $ map (go s su) ps
-    POr ps -> POr $ map (go s su) ps
-    PNot p -> PNot $ go s su p
-    PImp p1 p2 -> PImp (go s su p1) (go s su p2)
-    PIff p1 p2 -> PIff (go s su p1) (go s su p2)
-    PAtom r e1 e2 -> PAtom r (go s su e1) (go s su e2)
-    PKVar k tsu su' -> PKVar k tsu (catSubstGo su' su)
-    PAll bs p ->
-      let mfs = map (maybeFresh . fst) bs
-          fs = map (either (\x -> (x, x)) id) mfs
-          su' = List.foldl' (\su1 (x, x') -> extendSubst su1 x (EVar x')) su fs
-          bs' = zip (map (either id snd) mfs) (map snd bs)
-          s' = foldr (S.insert . fst) s bs'
-       in
-          PAll bs' $ go s' su' p
-    PExist bs p ->
-      let mfs = map (maybeFresh . fst) bs
-          fs = map (either (\x -> (x, x)) id) mfs
-          su' = List.foldl' (\su1 (x, x') -> extendSubst su1 x (EVar x')) su fs
-          bs' = zip (map (either id snd) mfs) (map snd bs)
-          s' = foldr (S.insert . fst) s bs'
-       in
-          PExist bs' $ go s' su' p
-    p -> p
+-- See the documentation of 'Subable' for more details.
+rapierSubstExpr
+  :: (HasCallStack, Eq v, Hashable v, Refreshable v)
+  => S.HashSet v -> SubstV v -> ExprBV v v -> ExprBV v v
+rapierSubstExpr = go
   where
-    fresh x = head $ dropWhile (`S.member` s) (candidates x)
+    go s su e0 = case e0 of
+        EApp f e -> EApp (go s su f) (go s su e)
+        ELam (x, t) e ->
+          let (s', x') = freshInNS x s
+              su' = extendSubstWithVar su x x'
+           in ELam (x', t) (go s' su' e)
+        ELet x e1 e2 ->
+          let (s', x') = freshInNS x s
+              su' = extendSubstWithVar su x x'
+           in ELet x' (go s su e1) (go s' su' e2)
 
-    maybeFresh x =
-      if x `S.member` s then Right (x, fresh x) else Left x
+        ECoerc a t e -> ECoerc a t (go s su e)
+        ENeg e -> ENeg (go s su e)
+        EBin op e1 e2 -> EBin op (go s su e1) (go s su e2)
+        EIte p e1 e2 -> EIte (go s su p) (go s su e1) (go s su e2)
+        ECst e so -> ECst (go s su e) so
+        EVar x
+          | S.member x s -> appSubst su x
+          | otherwise -> error "rapierSubstExpr: variable not in scope set"
+        PAnd ps -> PAnd $ map (go s su) ps
+        POr ps -> POr $ map (go s su) ps
+        PNot p -> PNot $ go s su p
+        PImp p1 p2 -> PImp (go s su p1) (go s su p2)
+        PIff p1 p2 -> PIff (go s su p1) (go s su p2)
+        PAtom r e1 e2 -> PAtom r (go s su e1) (go s su e2)
+        PKVar k tsu su' -> PKVar k tsu (catSubstGo su' su s)
+        PAll bs p ->
+          let xs = map fst bs
+              (s', fs) = freshInNSL xs s
+              su' = List.foldl' (\su1 (x, x') -> extendSubstWithVar su1 x x') su (zip xs fs)
+              bs' = zip fs (map snd bs)
+           in
+              PAll bs' $ go s' su' p
+        PExist bs p ->
+          let xs = map fst bs
+              (s', fs) = freshInNSL xs s
+              su' = List.foldl' (\su1 (x, x') -> extendSubstWithVar su1 x x') su (zip xs fs)
+              bs' = zip fs (map snd bs)
+           in
+              PExist bs' $ go s' su' p
+        p -> p
 
-    catSubstGo su1 su2@(Su s2) = toKVarSubst $ M.union s1 s2
+    catSubstGo su1 su2 s = catKVarSubst su1' (toListSubst su2)
       where
-        s1 = rapierSubstExpr s su2 <$> fromKVarSubst su1
+        su1' = mapKVarSubst (rapierSubstExpr s su2) su1
 
 extendSubst :: Hashable v => SubstV v -> v -> ExprBV v v -> SubstV v
 extendSubst (Su m) x e = Su $ M.insert x e m
 
-disjointRange :: (Eq v, Hashable v) => SubstV v -> [(v, Sort)] -> Bool
-disjointRange (Su su) bs = S.null $ suSyms `S.intersection` bsSyms
-  where
-    suSyms = S.fromList $ syms (M.elems su)
-    bsSyms = S.fromList $ fst <$> bs
+-- | Like 'extendSubst', but a no-op when @x' == x@ and @x@ is not already in
+-- the substitution domain. Use when extending with a binder rename @x → EVar x'@
+-- that may be trivial.
+extendSubstWithVar :: (Eq v, Hashable v) => SubstV v -> v -> v -> SubstV v
+extendSubstWithVar su@(Su m) x x'
+  | x' == x && not (M.member x m) = su
+  | otherwise = extendSubst su x (EVar x')
 
-meetReft :: Binder v => ReftBV v v -> ReftBV v v -> ReftBV v v
+meetReft :: (Refreshable v, Binder v) => ReftBV v v -> ReftBV v v -> ReftBV v v
 meetReft (Reft (v, ra)) (Reft (v', ra'))
   | v == v'          = Reft (v , pAnd [ra, ra'])
   | v == wildcard    = Reft (v', pAnd [ra', ra `subst1`  (v , EVar v')])
   | otherwise        = Reft (v , pAnd [ra, ra' `subst1` (v', EVar v )])
 
+
+freshInNS :: (Refreshable v, Hashable v) => v -> S.HashSet v -> (S.HashSet v, v)
+freshInNS x s =
+    let x' = head $ filter (not . (`S.member` s)) (candidates x)
+    in (S.insert x' s, x')
+
+freshInNSL :: (Refreshable v, Hashable v) => [v] -> S.HashSet v -> (S.HashSet v, [v])
+freshInNSL xs s = mapAccumL (flip freshInNS) s xs
+
 instance (Eq v, Hashable v, Refreshable v) => Subable (ReftBV v v) where
   type Variable (ReftBV v v) = v
-  syms (Reft (v, ras))      = v : syms ras
-  substa f (Reft (v, ras))  = Reft (f v, substa f ras)
-  subst su (Reft (v, ras))  =
-    let su' = substExcept su [v]
-        s = S.union (substSymbolsSet su') (exprSymbolsSet ras)
-     in Reft (v, rapierSubstExpr s su' ras)
-  substf f (Reft (v, ras))  = Reft (v, substf (substfExcept f [v]) ras)
-  subst1 (Reft (v, ras)) su = Reft (v, subst1Except [v] ras su)
+  syms = reftSymbolsSet
+  substr ns su (Reft (v, ras)) =
+     let (ns', v') = freshInNS v ns
+         su' = extendSubstWithVar su v v'
+      in
+         Reft (v', substr ns' su' ras)
 
+reftSymbolsSet :: (Eq v, Hashable v) => ReftBV v v -> S.HashSet v
+reftSymbolsSet (Reft (v, ras)) = S.delete v $ exprSymbolsSet ras
+
 instance Subable SortedReft where
   syms               = syms . sr_reft
-  subst su (RR so r) = RR so $ subst su r
-  substf f (RR so r) = RR so $ substf f r
-  substa f (RR so r) = RR so $ substa f r
+  substr ns su (RR so r) = RR so $ substr ns su r
 
 pprReft :: Reft -> Doc -> Doc
 pprReft (Reft (v, p)) d
@@ -398,34 +349,6 @@
 
 ppRas :: [Expr] -> Doc
 ppRas = cat . punctuate comma . map toFix . flattenRefas
-
---------------------------------------------------------------------------------
--- | TODO: Rewrite using visitor -----------------------------------------------
---------------------------------------------------------------------------------
--- exprSymbols :: Expr -> [Symbol]
--- exprSymbols = go
-  -- where
-    -- go (EVar x)           = [x]
-    -- go (EApp f e)         = go f ++ go e
-    -- go (ELam (x,_) e)     = filter (/= x) (go e)
-    -- go (ECoerc _ _ e)     = go e
-    -- go (ENeg e)           = go e
-    -- go (EBin _ e1 e2)     = go e1 ++ go e2
-    -- go (EIte p e1 e2)     = exprSymbols p ++ go e1 ++ go e2
-    -- go (ECst e _)         = go e
-    -- go (PAnd ps)          = concatMap go ps
-    -- go (POr ps)           = concatMap go ps
-    -- go (PNot p)           = go p
-    -- go (PIff p1 p2)       = go p1 ++ go p2
-    -- go (PImp p1 p2)       = go p1 ++ go p2
-    -- go (PAtom _ e1 e2)    = exprSymbols e1 ++ exprSymbols e2
-    -- go (PKVar _ (Su su))  = syms (M.elems su)
-    -- go (PAll xts p)       = (fst <$> xts) ++ go p
-    -- go _                  = []
-
-
-exprSymbols :: (Eq v, Hashable v) => ExprBV v v -> [v]
-exprSymbols = S.toList . exprSymbolsSet
 
 instance Expression (Symbol, SortedReft) where
   expr (x, RR _ (Reft (v, r))) = subst1 (expr r) (v, EVar x)
diff --git a/src/Language/Fixpoint/Types/Triggers.hs b/src/Language/Fixpoint/Types/Triggers.hs
--- a/src/Language/Fixpoint/Types/Triggers.hs
+++ b/src/Language/Fixpoint/Types/Triggers.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE DeriveDataTypeable         #-}
 {-# LANGUAGE DeriveFunctor              #-}
 {-# LANGUAGE DeriveGeneric              #-}
 
@@ -5,12 +6,14 @@
 
     Triggered (..), Trigger(..),
 
-    noTrigger, defaultTrigger,
+    noTrigger,
 
-    makeTriggers
+    triggerPatterns
 
     ) where
 
+import           Data.Aeson                (FromJSON, ToJSON)
+import           Data.Data                 (Data)
 import qualified Data.Store as S
 import           Control.DeepSeq
 import           GHC.Generics              (Generic)
@@ -18,14 +21,15 @@
 
 import Language.Fixpoint.Types.Refinements
 import Language.Fixpoint.Types.PrettyPrint
-import Language.Fixpoint.Misc              (errorstar)
 
 
 data Triggered a = TR Trigger a
-  deriving (Eq, Show, Functor, Generic)
+  deriving (Eq, Show, Data, Functor, Generic)
 
-data Trigger = NoTrigger | LeftHandSide
-  deriving (Eq, Show, Generic)
+newtype Trigger
+  = Patterns [[Expr]]   -- ^ explicit (multi-)patterns, one list per SMTLIB @:pattern@;
+                        --   empty means the expression is asserted without patterns
+  deriving (Eq, Show, Data, Generic)
 
 instance PPrint Trigger where
   pprintTidy _ = text . show
@@ -34,37 +38,18 @@
   pprintTidy k (TR t x) = parens (pprintTidy k t <+> text ":" <+> pprintTidy k x)
 
 noTrigger :: e -> Triggered e
-noTrigger = TR NoTrigger
-
-defaultTrigger :: e -> Triggered e
-defaultTrigger = TR LeftHandSide
-
-makeTriggers :: Triggered Expr -> [Expr]
-makeTriggers (TR LeftHandSide e) = [getLeftHandSide e]
-makeTriggers (TR NoTrigger    _) = errorstar "makeTriggers on NoTrigger"
-
-
-getLeftHandSide :: Expr -> Expr
-getLeftHandSide (ECst e _)
-  = getLeftHandSide e
-getLeftHandSide (PAll _ e)
-  = getLeftHandSide e
-getLeftHandSide (PExist _ e)
-  = getLeftHandSide e
-getLeftHandSide (PAtom eq lhs _)
-  | eq == Eq || eq == Ueq
-  = lhs
-getLeftHandSide (PIff lhs _)
-  = lhs
-getLeftHandSide _
- = defaltPatter
+noTrigger = TR (Patterns [])
 
--- NV TODO find out a valid, default pattern that does not instantiate the axiom
-defaltPatter :: Expr
-defaltPatter = PFalse
+-- | The SMTLIB @:pattern@s of a triggered expression; each element is a multi-pattern.
+triggerPatterns :: Triggered Expr -> [[Expr]]
+triggerPatterns (TR (Patterns ps) _) = ps
 
 instance S.Store Trigger
 instance NFData   Trigger
+instance ToJSON   Trigger
+instance FromJSON Trigger
 
 instance (S.Store a) => S.Store (Triggered a)
 instance (NFData a)   => NFData   (Triggered a)
+instance (ToJSON a)   => ToJSON   (Triggered a)
+instance (FromJSON a) => FromJSON (Triggered a)
diff --git a/src/Language/Fixpoint/Types/Utils.hs b/src/Language/Fixpoint/Types/Utils.hs
--- a/src/Language/Fixpoint/Types/Utils.hs
+++ b/src/Language/Fixpoint/Types/Utils.hs
@@ -5,9 +5,6 @@
   -- * Domain of a kvar
     kvarDomain
 
-  -- * Free variables in a refinement
-  , reftFreeVars
-
   -- * Deconstruct a SortedReft
   , sortedReftConcKVars
 
@@ -20,9 +17,9 @@
 import qualified Data.HashMap.Strict                  as M
 import qualified Data.HashSet                         as S
 
-import           Language.Fixpoint.Misc
 import           Language.Fixpoint.Types.Names
 import           Language.Fixpoint.Types.Refinements
+import           Language.Fixpoint.Types.Substitutions
 import           Language.Fixpoint.Types.Environments
 import           Language.Fixpoint.Types.Constraints
 import           Language.Fixpoint.Types.Sorts
@@ -36,17 +33,10 @@
 kvarDomain si k = domain (bs si) (getWfC si k)
 
 domain :: BindEnv a -> WfC a -> [Symbol]
-domain be wfc = fst3 (wrft wfc) : map fst (envCs be $ wenv wfc)
+domain be wfc = map fst (wvvs wfc) ++ map fst (envCs be $ wenv wfc)
 
 getWfC :: GInfo c a -> KVar -> WfC a
 getWfC si k = ws si M.! k
-
---------------------------------------------------------------------------------
--- | Free variables of a refinement
---------------------------------------------------------------------------------
---TODO deduplicate (also in Solver/UniqifyBinds)
-reftFreeVars :: Reft -> S.HashSet Symbol
-reftFreeVars r@(Reft (v, _)) = S.delete v $ S.fromList $ syms r
 
 --------------------------------------------------------------------------------
 -- | Split a SortedReft into its concrete and KVar conjuncts
diff --git a/tests/pos/unicode.fq b/tests/pos/unicode.fq
new file mode 100644
--- /dev/null
+++ b/tests/pos/unicode.fq
@@ -0,0 +1,16 @@
+// Tests unicode operators
+
+fixpoint "--rewrite"
+fixpoint "--extensionality"
+fixpoint "--allowho"
+
+constant f : (func(0 , [int; int]))
+define f (x : int) : int = {(13)}
+
+expand [1 : True]
+
+constraint:
+  env []
+  lhs {VV1 : Tuple | true ⇒ true }
+  rhs {VV2 : Tuple | (f = \y : int → (13 ∷ int)) }
+  id 1 tag []
diff --git a/tests/tasty/ParserTests.hs b/tests/tasty/ParserTests.hs
--- a/tests/tasty/ParserTests.hs
+++ b/tests/tasty/ParserTests.hs
@@ -180,12 +180,24 @@
     , testCase "ELam" $
         show (doParse' expr0P "test" "\\ foo : Int -> true") @?= "ELam (\"foo\",FInt) (PAnd [])"
 
+    , testCase "ELam unicode arrow" $
+        show (doParse' expr0P "test" "\\ foo : Int → true") @?= "ELam (\"foo\",FInt) (PAnd [])"
+
+    , testCase "arrow unicode == ASCII" $
+        show (doParse' expr0P "test" "\\ foo : Int → true") @?= show (doParse' expr0P "test" "\\ foo : Int -> true")
+
     , testCase "Expr" $
         show (doParse' expr0P "test" "(1)") @?= "ECon (I 1)"
 
     , testCase "ECst dcolon" $
         show (doParse' expr0P "test" "(1 :: Int)") @?= "ECst (ECon (I 1)) FInt"
 
+    , testCase "ECst unicode dcolon" $
+        show (doParse' expr0P "test" "(1 ∷ Int)") @?= "ECst (ECon (I 1)) FInt"
+
+    , testCase "dcolon unicode == ASCII" $
+        show (doParse' expr0P "test" "(1 ∷ Int)") @?= show (doParse' expr0P "test" "(1 :: Int)")
+
     , testCase "ECst colon" $
         show (doParse' expr0P "test" "(1 : Int)") @?= "ECst (ECon (I 1)) FInt"
 
@@ -270,6 +282,16 @@
 
     , testCase "|| 2" $
         show (doParse' predP "test" "|| [x;y]") @?= "POr [EVar \"x\",EVar \"y\"]"
+
+    , testCase "=>" $
+        show (doParse' exprP "test" "true => false") @?= "PImp (PAnd []) (POr [])"
+
+    , testCase "=> unicode" $
+        show (doParse' exprP "test" "true ⇒ false") @?= "PImp (PAnd []) (POr [])"
+
+    , testCase "=> unicode == ASCII" $
+        show (doParse' exprP "test" "true ⇒ false") @?= show (doParse' exprP "test" "true => false")
+
     ]
 
 
diff --git a/tests/tasty/ghc-9.12.1/SimplifyKVarTests.hs b/tests/tasty/ghc-9.12.1/SimplifyKVarTests.hs
--- a/tests/tasty/ghc-9.12.1/SimplifyKVarTests.hs
+++ b/tests/tasty/ghc-9.12.1/SimplifyKVarTests.hs
@@ -3,7 +3,6 @@
 module SimplifyKVarTests (tests) where
 
 import Control.Monad (when)
-import qualified Data.HashSet as HashSet
 import Language.Fixpoint.Parse
 import qualified Language.Fixpoint.Types as F
 import qualified Language.Fixpoint.Solver.Solution as F
@@ -79,12 +78,12 @@
 simplificationTest :: SimplificationTest -> TestTree
 simplificationTest test =
   testCase (name test) $ do
-    let actual =
-          F.simplifyKVar
-            HashSet.empty
-            (doParse'' True predP (name test) (input test))
+    let actual0 = doParse'' True predP (name test) (input test)
+        scope = F.syms actual0
+        actual = F.simplifyKVar scope actual0
         expectedE = doParse'' True predP (name test) (expected test)
-    when (not (F.alphaEq HashSet.empty actual expectedE)) $ do
+        allScope = F.syms [actual, expectedE]
+    when (not $ F.alphaEq allScope actual expectedE) $ do
       assertFailure $ unlines
         [ "output is not as expected"
         , "Expected:"
