"""Independent formal-tree and certificate rejection checks.""" from copy import deepcopy from math import prod import unittest from theory.code import existence_product_closure as engine class ProductClosureTests(unittest.TestCase): def test_independent_counts_recurrence_and_full_tree_partitions(self): exponents,plans=engine.exponent_catalogue(64) c=engine.caterpillar_exponents(64) for count in range(1,65): self.assertEqual(exponents[count],engine.count_enumeration(count)['exponent']) self.assertEqual(exponents[count],c[count]+2) def test_twelve_rule_improves_declared_old_grammar(self): old,_=engine.exponent_catalogue(12,{2:3,4:4}) new,_=engine.exponent_catalogue(12) self.assertEqual((old[12],new[12]),(10,9)) self.assertEqual((new[1],new[2],new[4]),(2,3,4)) def test_every_input_used_once_and_exact_output(self): exponents,plans=engine.exponent_catalogue(32) for count in range(1,33): inputs=[4*(i+1)for i in range(count)] value=2**exponents[count]*prod(n//4 for n in inputs) self.assertTrue(engine.verify_certificate(engine.proof_tree(count,plans),inputs,value)) def test_corrupt_certificates_are_rejected(self): self.assertEqual(len(engine.tamper_controls()),6) def test_uniform_source_specialization_matches_closed_form(self): qs=[5,9,13,25];rs=[0,2,1,0] record=engine.specialize_uniform(qs,rs) self.assertEqual(record['target_order'],631**4*prod((q+1)*q**r for q,r in zip(qs,rs))) self.assertEqual([h['order']for h in record['input_existence_hypotheses']],record['input_orders']) self.assertIn('search/docs/EXTENDED_SPENCE_FAMILIES.md',record['input_source_theorem_provenance']['proof_paths']) record=engine.specialize_uniform([5]*12,[0]*12) self.assertEqual(record['target_order'],512*(631*3)**12) def test_invalid_uniform_source_hypotheses_rejected(self): for qs,rs in[([1],[0]),([21],[0]),([7],[0]),([5],[-1]),([5],[True]),([5],[])]: with self.assertRaises(ValueError):engine.specialize_uniform(qs,rs) if __name__=='__main__':unittest.main(verbosity=2)