-
Notifications
You must be signed in to change notification settings - Fork 1
feat(B-0711): add FsCheck property-based tests for Residuated lattice IVM laws #4780
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
Closed
Closed
Changes from all commits
Commits
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
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,76 @@ | ||
| 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 · is max, and a \ b = (if a <= b then b else a) | ||
| [<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 -> false | ||
|
|
||
| lhs = rhs | ||
|
|
||
| // 2. Residual under max: a \ b = Some b if a ≤ b else None | ||
| [<FsCheck.Xunit.Property>] | ||
| let ``Residual under max properties`` (a: int) (b: int) = | ||
| let residualMax a b = if a <= b then Some b else None | ||
| residualMax a b = (if a <= b then Some b else 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>() | ||
| let active = SortedSet<int>() | ||
|
|
||
| for (k, w) in ops do | ||
| let existing = | ||
| match keyWeight.TryGetValue k with | ||
| | true, v -> v | ||
| | false, _ -> 0L | ||
| let updated = existing + w | ||
| let wasActive = existing > 0L | ||
| let isActive = updated > 0L | ||
|
|
||
| if wasActive && not isActive then active.Remove k |> ignore | ||
| elif not wasActive && isActive then active.Add k |> ignore | ||
|
|
||
| if updated = 0L then keyWeight.Remove k |> ignore | ||
| else keyWeight.[k] <- updated | ||
|
Comment on lines
+40
to
+56
|
||
|
|
||
| if active.Count = 0 then ValueNone | ||
| else ValueSome (active.Max) | ||
|
|
||
| [<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() | ||
|
|
||
| for (k, w) in opsMapped do | ||
| input.Send (ZSet.singleton k w) | ||
| c.Step() | ||
|
|
||
| out.Current = (oracle opsMapped) | ||
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.
The
oraclehere mirrors the same state-transition rules used byResidualMaxOp.StepAsync(updated > 0drives active membership with the same add/remove branching), so a defect in that transition logic can still pass if it exists in both places. In that scenario this property reports success while the production behavior is wrong, which undermines the new claim of law coverage; compute expectations from a different spec path (e.g., rebuild max from accumulated counts) rather than duplicating operator internals.Useful? React with 👍 / 👎.