File tree Expand file tree Collapse file tree
src/jacobian/math/impartial_games
tests/math/impartial_games Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -221,3 +221,19 @@ class DisjunctiveSumResult(StrictModel):
221221 component_grundy_values : tuple [int , ...]
222222 is_p_position : bool
223223 component_count : int = Field (ge = 1 )
224+
225+ @model_validator (mode = "after" )
226+ def require_exact_disjunctive_invariants (self ) -> Self :
227+ if self .component_count != len (self .component_grundy_values ):
228+ raise ValueError ("component_count must match component_grundy_values length" )
229+ if any (value < 0 for value in self .component_grundy_values ):
230+ raise ValueError ("component Grundy values must be nonnegative" )
231+ from functools import reduce
232+ from operator import xor
233+
234+ expected = reduce (xor , self .component_grundy_values , 0 )
235+ if self .grundy_value != expected :
236+ raise ValueError ("grundy_value must be XOR of component_grundy_values" )
237+ if self .is_p_position != (expected == 0 ):
238+ raise ValueError ("is_p_position must agree with grundy_value == 0" )
239+ return self
Original file line number Diff line number Diff line change 11"""Wire adapters for exact bounded impartial-game operations."""
22
33from jacobian .math .impartial_games ._models import (
4- DisjunctiveSumRequest ,
5- DisjunctiveSumResult ,
64 BirthdayRequest ,
75 BirthdayResult ,
6+ DisjunctiveSumRequest ,
7+ DisjunctiveSumResult ,
88 GrundyEntry ,
99 GrundyTableRequest ,
1010 GrundyTableResult ,
@@ -67,8 +67,8 @@ def compute_subtraction_grundy_prefix(
6767
6868
6969__all__ = [
70- "compute_disjunctive_sum" ,
7170 "compute_birthday" ,
71+ "compute_disjunctive_sum" ,
7272 "compute_grundy_table" ,
7373 "compute_subtraction_grundy_prefix" ,
7474]
Original file line number Diff line number Diff line change 55
66from jacobian .math .impartial_games ._models import (
77 DisjunctiveSumRequest ,
8- DisjunctiveSumResult ,
98)
109from jacobian .math .impartial_games ._operations import compute_disjunctive_sum
1110from jacobian .math .impartial_games ._tools import TOOLS
1211
13-
1412# -- helpers -----------------------------------------------------------------
1513
1614_TERMINAL = {"positions" : ["start" ], "moves" : []}
You can’t perform that action at this time.
0 commit comments