Yes, you're right, you want to pop
(remove) the last assertion. To do this, you first need to save the current set of assertions with push
. This is how Z3 supports scope.
By add some part of the formula, I'm going to assume you mean to define a variable containing an additional chunk of some original large formula you're doing the incremental checking on. I'll also assume the original formula is a large conjunction of sub-formulas. This new formula will remain defined between pushes and pops (assuming you keep a variable referencing it).
Here is a link to an example of roughly the following pseudo-code in z3py, except in the z3py script I also assume the formula and the constraint are actually the same thing, but maybe you want to create some different constraint based on that piece of the subformula: http://rise4fun.com/Z3Py/LIxW
I haven't used Scala^Z3, but roughly you want to do the following:
formula // list containing parts (sub-formulas) of original large formula
while (formulaPart = formula.removeFirst()) // remove first element of list
Z3Context.push() // save current set of assertions
assertion = makeConstraint( formulaPart ) // assertion based on sub-formula
Z3Context.assertCnstr( assertion ) // add new assertion
if !Z3Context.check() // check if assertions cannot be satisfied
Z3Context.pop() // remove most recent assertion
Here is an example using pop/push from the .NET API: http://research.microsoft.com/en-us/um/redmond/projects/z3/test__managed_8cs_source.html#l00637
You'd also be interested in this: Soft/Hard constraints in Z3