Skip to content

Add Z3 simplifiers via a context based option to Z3 ProverEnvironments - #747

Open
baierd wants to merge 4 commits into
masterfrom
669-z3-simplifiers-in-context
Open

baierd wants to merge 4 commits into
masterfrom
669-z3-simplifiers-in-context

Conversation

@baierd

@baierd baierd commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

This PR extends our Z3 wrapper with simplifiers. They are applied to all ProverEnvironments created from a context with a Configuration that specified a list of simplifiers via a newly added option. I have not added simplifier support to optimization proving for now.

Several tests were added as well. They showcase general workings, failures when configuring, and keep track of restrictions. Simplifiers can not be used with UNSAT-cores (neither in our version nor the current main branch of Z3), and also not with assumption solving, but this seems to be fixed in the current release.

(Simplifiers are a list instead of a set, as they may be applied multiple times and are applied in the order of the list.)

…and add some tests for them, as simplifiers can't be used with unsat-cores or assumption solving currently
@baierd baierd self-assigned this Nov 22, 2026
@baierd baierd added the Z3 label Nov 22, 2026
@baierd baierd linked an issue Nov 22, 2026 that may be closed by this pull request
@baierd baierd added this to the Release 7.1.0 milestone Nov 23, 2026
daniel-raffler
daniel-raffler previously approved these changes Nov 23, 2026

@daniel-raffler daniel-raffler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few TODOs about the unsat-core issue left in the code. Should we open a
Z3 issue for this?

Other than that, it looks fine to me

@Option(
secure = true,
description =
"List of Z3 simplifiers that are applied, in the given order, as incremental"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the "incremental" referring to here? Do we need to set a specific solver mode for simplifieres to work?

+ " pre-processing to the assertions of each ProverEnvironment created by this"
+ " context. This option has no effect on OptimizationProverEnvironments."
+ " Unsat-core generation and solving with assumptions are not supported together"
+ " with simplifiers due to issues."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we open a new Z3 issue for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name one of the 3 things ;D
Short answer: yes we need a issue for the unsat-core issue. The assumption solving issue is solved by updating Z3 (which i will do this week). I don't know whether optimization works or not, but i will only look into it if someone wants me to.

+ " with simplifiers due to issues."
+ " Example: \"simplify, propagate-values, solve-eqs\". Available simplifiers"
+ " can be found in the Z3 documentation online:"
+ " https://microsoft.github.io/z3guide/docs/strategies/simplifiers/")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a list of simplifiers on the website. It just say that they can be listed by running (help-simplifier)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point; either we support some API to get options and their values, or we need to add it here. I'll try adding it here and report back!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added all available simplifiers to the options text + what they do + a test that they do not go out of date.

Comment on lines +58 to +59
// TODO: unsat-cores with simplifiers fail with an exceptions.
// Tested in Z3 4.17.0-1009b13 and up to 5.4.1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the exception here? Did you make sure it's not an issue on our side? IIRC we use the same API call for both unsat-core and unsat-assumptions, so I'm a little surprised only one of them isn't working

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They actually don't fail with exceptions, but with wrong results. I updated the TODO. I even know why and will report in the issue. This is not caused by us.

Comment on lines 606 to 622
// TODO: do we allow tactic options currently?
@SuppressWarnings("unused")
String getTacticOptions() {
long tactic = Native.mkTactic(creator.getEnv(), "simplify");
Native.simplifierIncRef(creator.getEnv(), tactic);
String options = Native.tacticGetHelp(creator.getEnv(), tactic);
Native.simplifierDecRef(creator.getEnv(), tactic);
return options;
}

String getSimplifierOptions() {
long simplifier = Native.mkSimplifier(creator.getEnv(), "propagate-values");
Native.simplifierIncRef(creator.getEnv(), simplifier);
String options = Native.simplifierGetHelp(creator.getEnv(), simplifier);
Native.simplifierDecRef(creator.getEnv(), simplifier);
return options;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few unused functions down here. Can they be removed now, or do we still need them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now its used ;D

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

Add Support for Z3 Simplifiers

2 participants