-
Notifications
You must be signed in to change notification settings - Fork 1
fix(4780): address review comments on Residuated lattice tests #4821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
52fe48d
feat(B-0711): add FsCheck property-based tests for Residuated lattice…
AceHack 788468c
fix(tests): address review comments on Residuated lattice tests
AceHack fc379a7
fix(tests): address review comments on Residuated lattice tests
fbf4833
fix(4780,4821): revert Galois `None`-branch from `not lhs` to `false`
claude dcb32bc
fix(4821): assert mid-stream prefix equivalence in retraction property
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| module Zeta.Tests.Algebra.ResiduatedTests | ||
| #nowarn "0893" | ||
|
|
||
| open System | ||
| open System.Collections.Generic | ||
| open FsUnit.Xunit | ||
| open FsCheck | ||
| open FsCheck.FSharp | ||
| open global.Xunit | ||
| open Zeta.Core | ||
|
|
||
|
|
||
| // ═══════════════════════════════════════════════════════════════════ | ||
| // Residuated-Lattice IVM Property Tests (B-0711) | ||
| // ═══════════════════════════════════════════════════════════════════ | ||
|
|
||
| // 1. Galois connection: a · x ≤ b ⇔ x ≤ a \ b | ||
| // where · = max and the residual is partial over a totally-ordered key | ||
| // set with no bottom element: a \ b = Some b when a ≤ b, otherwise None. | ||
| // The None branch represents the empty/bottom residual — no x satisfies | ||
| // max(a, x) ≤ b when a > b, so x ≤ (a \ b) must be false everywhere. | ||
| // | ||
| // NOTE (B-NNNN follow-up): this property encodes the residual definition | ||
| // locally; a stronger test would exercise the production ResidualMaxOp's | ||
| // residual semantics directly. Tracked as a known limitation; see the | ||
| // PR thread P2 finding. | ||
| [<FsCheck.Xunit.Property>] | ||
| let ``Galois connection holds for ResidualMax under natural order`` (a: int) (x: int) (b: int) = | ||
| let residualMax a b = if a <= b then Some b else None | ||
|
|
||
| let lhs = (max a x) <= b | ||
| let rhs = | ||
| match residualMax a b with | ||
| | Some bound -> x <= bound | ||
| // None ⇒ a > b ⇒ max(a, x) ≥ a > b, so lhs is always false. The | ||
| // residual is "bottom" / empty: no x satisfies the inequality, | ||
| // so rhs must also be false for the equivalence to hold. | ||
| | None -> false | ||
|
|
||
| lhs = rhs | ||
|
AceHack marked this conversation as resolved.
|
||
|
|
||
| // 2. Residual under max: a \ b = Some b if a ≤ b else None | ||
| [<FsCheck.Xunit.Property>] | ||
| let ``Residual under max has expected behavior`` (a: int) (b: int) = | ||
| let residualMax a b = if a <= b then Some b else None | ||
|
|
||
| if a <= b then | ||
| residualMax a b = Some b | ||
|
AceHack marked this conversation as resolved.
|
||
| else | ||
| residualMax a b = None | ||
|
|
||
| // 3. Retraction equivalence: ResidualMax(insert + retract trace) = max(positive-only trace) | ||
| // Oracle for max over active set | ||
| let private oracle (ops: (int * int64) list) = | ||
| let keyWeight = Dictionary<int, int64>() | ||
|
|
||
| for (k, w) in ops do | ||
| let existing = | ||
| match keyWeight.TryGetValue k with | ||
| | true, v -> v | ||
| | false, _ -> 0L | ||
| let updated = existing + w | ||
|
|
||
| if updated = 0L then keyWeight.Remove k |> ignore | ||
| else keyWeight.[k] <- updated | ||
|
|
||
| let activeKeys = keyWeight |> Seq.filter (fun kvp -> kvp.Value > 0L) |> Seq.map (fun kvp -> kvp.Key) | ||
|
|
||
| if Seq.isEmpty activeKeys then ValueNone | ||
| else ValueSome (Seq.max activeKeys) | ||
|
|
||
| [<FsCheck.Xunit.Property>] | ||
| let ``ResidualMax retraction equivalence`` (ops: (int * int) list) = | ||
| // Limit weight changes to reasonable bounds to simulate typical active/retract traces | ||
| let opsMapped = ops |> List.map (fun (k, w) -> (k, int64 (w % 10))) | ||
|
|
||
| let c = Circuit() | ||
| let input = c.ZSetInput<int>() | ||
| let m = c.ResidualMax(input.Stream, Func<_, _>(id)) | ||
| let out = OutputHandle m.Op | ||
| c.Build() | ||
|
|
||
| // Assert mid-stream after each Send/Step that out.Current matches the oracle | ||
| // over the prefix processed so far. Catches state bugs that occur mid-stream | ||
| // but "self-heal" by the end of the trace (Copilot PR #4821 P1 finding). | ||
| let mutable ok = true | ||
| let mutable prefix : (int * int64) list = [] | ||
| for op in opsMapped do | ||
| input.Send (ZSet.singleton (fst op) (snd op)) | ||
| c.Step() | ||
| prefix <- prefix @ [op] | ||
| ok <- ok && (out.Current = oracle prefix) | ||
| ok | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update this coverage note to avoid stating that all residuated laws now have property-based coverage, because the newly added tests still encode
residualMaxlocally (tests/Tests.FSharp/Algebra/Residuated.Tests.fs, lines 23-26 and 44-50) instead of checking the production residual semantics directly. As written, this line overstates verification status and can mislead future reviewers/research writeups about what regressions the suite can actually catch.Useful? React with 👍 / 👎.