|
8 | 8 |
|
9 | 9 | from pydantic import Field, StrictInt, model_validator |
10 | 10 |
|
11 | | -from jacobian.canonical import canonicalize_json |
| 11 | +from jacobian.canonical import canonicalize_json, format_canonical_integer |
12 | 12 | from jacobian.contracts.exact import CanonicalInteger, CanonicalRational |
13 | 13 | from jacobian.contracts.graph_isomorphism import SimpleUndirectedGraph |
14 | 14 | from jacobian.contracts.results import ContractModel |
@@ -36,8 +36,8 @@ def _require_bounded_fraction( |
36 | 36 | label: str, |
37 | 37 | ) -> None: |
38 | 38 | if ( |
39 | | - len(str(abs(value.numerator))) > max_digits |
40 | | - or len(str(value.denominator)) > max_digits |
| 39 | + len(format_canonical_integer(abs(value.numerator))) > max_digits |
| 40 | + or len(format_canonical_integer(value.denominator)) > max_digits |
41 | 41 | ): |
42 | 42 | raise ValueError(f"{label} exceeds the {max_digits}-digit bound") |
43 | 43 |
|
@@ -324,13 +324,25 @@ def require_bounded_fully_weighted_graph(self) -> Self: |
324 | 324 | ) |
325 | 325 | probability_numerator_digits = sum( |
326 | 326 | max( |
327 | | - len(str(item.open_probability.as_fraction().numerator)), |
328 | | - len(str((1 - item.open_probability.as_fraction()).numerator)), |
| 327 | + len( |
| 328 | + format_canonical_integer( |
| 329 | + item.open_probability.as_fraction().numerator |
| 330 | + ) |
| 331 | + ), |
| 332 | + len( |
| 333 | + format_canonical_integer( |
| 334 | + (1 - item.open_probability.as_fraction()).numerator |
| 335 | + ) |
| 336 | + ), |
329 | 337 | ) |
330 | 338 | for item in self.edge_probabilities |
331 | 339 | ) |
332 | 340 | probability_denominator_digits = sum( |
333 | | - len(str(item.open_probability.as_fraction().denominator)) |
| 341 | + len( |
| 342 | + format_canonical_integer( |
| 343 | + item.open_probability.as_fraction().denominator |
| 344 | + ) |
| 345 | + ) |
334 | 346 | for item in self.edge_probabilities |
335 | 347 | ) |
336 | 348 | maximum_state = { |
|
0 commit comments