Skip to main content

Module isomorphic

Module isomorphic 

Source
Expand description

Schema isomorphism – ported from ~/dev/omnist/omnist/ops/isomorphic.py.

Two schemas are equivalent iff their minimized (normalized) forms are isomorphic. That gives a second, algorithm-independent decision procedure for equivalent, structurally unrelated to bidirectional subschema::compatible_with, so the two can be cross-checked against each other in tests (the “dual-algorithm oracle” – see tests.rs, the minimize/isomorphic triple-check strategy from the issue).

is_isomorphic is deliberately not part of the crate’s public surface commitment the way subschema::equivalent is – it exists purely as an independent oracle for tests, matching the Python reference’s choice to keep _isomorphic private.

Algorithm: parallel traversal from both roots, building a bijection name_a -> name_b (and its inverse) between env record names as the traversal discovers pairs. At each visited record pair, local_signature must match; since it sorts fields by label and ref/scalar shape is part of the key, fields on the two sides line up one-to-one by label once the signatures agree. For each ref-typed field, the two targets are recursively required to be isomorphic, with the bijection enforced consistently in both directions.

Both inputs are assumed already normalized (pruned + minimized) by the caller – this module does not call normalize itself.

Functions§

is_isomorphic
True iff normalized schemas a and b are isomorphic: there is a bijection between their env record names under which the two root records (and everything reachable from them) match exactly.