Skip to content

Conversation

@shigoel
Copy link
Contributor

@shigoel shigoel commented Jan 3, 2026

Description of changes:

Make the detection of relevant axioms for a given function more precise. See test in irrelevantAxiomsTestPgm2 in Strata/StrataTest/Languages/Boogie/Examples/RemoveIrrelevantAxioms.lean for details.

There are three modes to choose from for detecting and removing irrelevant axioms:

  • Off: do not remove any axioms.

  • Aggressive: Only the functions in the consequent Q of a goal P ==> Q will be taken into account for relevant axiom analysis. This means that axioms relevant to some function in P may be removed. This is sound, but may yield unknown results from the solver.

  • Precise: Functions in both P and Q of a goal P ==> Q will be considered for relevant axiom analysis. A caveat is that only the antecedents that appear after a marker called __end_of_prelude_marker will be considered as the real assumptions here.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@shigoel shigoel marked this pull request as ready for review January 3, 2026 04:08
@shigoel shigoel requested review from a team, MikaelMayer and atomb as code owners January 3, 2026 04:08
@aqjune-aws
Copy link
Contributor

Hi, while reviewing this PR I became to want to assure the natures of properties Strata want to reason about.

If we want to detect malformed API calls whose inputs cannot be right, would aggressively removing axioms affect the result?
For example, let's assume that f_x_must_be_negative(x) is an API call that must have x a negative number. And if we have a code:

if x in [1, 2, 3]:
  f_x_must_be_negative(x)

If the axioms about List membership is correctly encoded, Strata will correctly indicate that f_x_must_be_negative(x) can never be right.
However, if it this membership axiom was (eagerly) eliminated for some reason, the if branch being taken won't give additional information stating that x is positive.

@shigoel
Copy link
Contributor Author

shigoel commented Jan 8, 2026

If the axioms about List membership is correctly encoded, Strata will correctly indicate that f_x_must_be_negative(x) can never be right. However, if it this membership axiom was (eagerly) eliminated for some reason, the if branch being taken won't give additional information stating that x is positive.

Axiom removal is sound, as long as we're relying on an unsat result from an SMT solver. As you noted, at worst we may not be able to prove something we need, but then axiom removal is also optional. Indeed, there are three modes: off (which should avoid the problem you brought up), aggressive (which can eliminate necessary axioms but it'd still be sound), and precise (if the relevant axioms are properly computed, we should avoid this situation).

Does this address your concern?

@shigoel shigoel requested a review from joehendrix as a code owner January 8, 2026 15:30
(fun (k, v) => f!"{k}: [{Std.Format.joinSep (v.map Std.format) ", "}]")
f!"{Std.Format.joinSep entries ", \n"}"
/-- Fixed-point computation for axiom relevance. -/
private partial def computeRelevantAxioms (prog : Program) (cg : CallGraph) (fmap : FuncAxMap)
Copy link
Contributor

Choose a reason for hiding this comment

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

In principle this could be proved terminating by looking at number axioms in prog - |discoveredAxioms| but maybe that is not necessary for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed -- I shied away from that proof for now. I expect we won't be using axiom removal too much after datatypes are in. This is mostly for a rainy day.

assume [assume_maybe_except_none]: (ExceptOrNone_tag(maybe_except) == EN_NONE_TAG);
};

axiom [__end_of_prelude_marker]: (true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Somewhere, it should probably be documented that this must occur at the end of the prelude. And what happens if there are multiple preludes/libraries being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally geared towards a single prelude for now. It's a stopgap, which I acknowledge in Strata/Languages/Boogie/Verifier.lean.

@aqjune-aws
Copy link
Contributor

aqjune-aws commented Jan 8, 2026

If the axioms about List membership is correctly encoded, Strata will correctly indicate that f_x_must_be_negative(x) can never be right. However, if it this membership axiom was (eagerly) eliminated for some reason, the if branch being taken won't give additional information stating that x is positive.

Axiom removal is sound, as long as we're relying on an unsat result from an SMT solver. As you noted, at worst we may not be able to prove something we need, but then axiom removal is also optional. Indeed, there are three modes: off (which should avoid the problem you brought up), aggressive (which can eliminate necessary axioms but it'd still be sound), and precise (if the relevant axioms are properly computed, we should avoid this situation).

Does this address your concern?

To record - we had a separate chat about this and I recommended that the codebase explicitly mentions the Aggressive mode may change unsat to sat.

@joscoh
Copy link
Contributor

joscoh commented Jan 8, 2026

If the axioms about List membership is correctly encoded, Strata will correctly indicate that f_x_must_be_negative(x) can never be right. However, if it this membership axiom was (eagerly) eliminated for some reason, the if branch being taken won't give additional information stating that x is positive.

Axiom removal is sound, as long as we're relying on an unsat result from an SMT solver. As you noted, at worst we may not be able to prove something we need, but then axiom removal is also optional. Indeed, there are three modes: off (which should avoid the problem you brought up), aggressive (which can eliminate necessary axioms but it'd still be sound), and precise (if the relevant axioms are properly computed, we should avoid this situation).
Does this address your concern?

To record - we had a separate chat about this and I recommened to explicitly mention in the codebase that Aggressive mode may change unsat to sat.

If the axioms about List membership is correctly encoded, Strata will correctly indicate that f_x_must_be_negative(x) can never be right. However, if it this membership axiom was (eagerly) eliminated for some reason, the if branch being taken won't give additional information stating that x is positive.

Axiom removal is sound, as long as we're relying on an unsat result from an SMT solver. As you noted, at worst we may not be able to prove something we need, but then axiom removal is also optional. Indeed, there are three modes: off (which should avoid the problem you brought up), aggressive (which can eliminate necessary axioms but it'd still be sound), and precise (if the relevant axioms are properly computed, we should avoid this situation).
Does this address your concern?

To record - we had a separate chat about this and I recommened to explicitly mention in the codebase that Aggressive mode may change unsat to sat.

I think Precise can also change unsat to sat. E.g. if you have axiom: false and it is removed.

@aqjune-aws
Copy link
Contributor

Ah, right. I was implicitly assuming that existing axioms were not false.

@jimgrundy
Copy link

Axiom removal is sound, as long as we're relying on an unsat result from an SMT solver.

Just checking. Yes, so you can do this when you are proving assertions. But not if you are checking coverage/reachability.

@shigoel
Copy link
Contributor Author

shigoel commented Jan 8, 2026

Axiom removal is sound, as long as we're relying on an unsat result from an SMT solver.

Just checking. Yes, so you can do this when you are proving assertions. But not if you are checking coverage/reachability.

Indeed, and that was June's point too. We don't have coverage checking in Strata yet (imminent), but when we do, we won't run this axiom removal bit on it.

@shigoel shigoel marked this pull request as draft January 12, 2026 14:15
auto-merge was automatically disabled January 12, 2026 14:15

Pull request was converted to draft

@shigoel
Copy link
Contributor Author

shigoel commented Jan 12, 2026

I'll re-open this PR after #314 is merged.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants