# Question 17267: A State Invariant Covers Every Word, Not Just Test Cases

[Return to catalogue page 87](https://ocme.evemisslab.com/en/questions/page/87/)

[← Question derivation index](https://ocme.evemisslab.com/en/questions/) · [Original question batch](https://ocme.evemisslab.com/en/practice/batch-20261014-advance-20261102-r07-regular-language-foundations/#q-20261014-advance-20261102-r07-regular-language-0017)

This teaching derivation has second-context AI mathematical and bilingual semantic review, limited to the model and assumptions stated in this question. It has no human review or new Lean proof and does not promote the original question or MKO to Canonical truth.

R0033-17267 · q-20261014-advance-20261102-r07-regular-language-0017



## Original question and givens

Use alphabet=Fin(2)={0,…,1} and the language whose number of occurrences of target_symbol=1 is congruent to residue=0 modulo modulus=18. Construct the complete DFA on states 0 through modulus−1, start 0 and accepting subset [residue]. A target symbol increments the state modulo the modulus; every other symbol leaves it unchanged. The invariant is state equals target-symbol count modulo the modulus for every prefix of every finite word, not just selected tests. No regex, NFA, epsilon move, minimization or pumping-lemma result is added. Give (states,transition,start,accepting,regular?,state_equals_target_symbol_count_mod_modulus_for_all_prefixes). Rows follow state order and columns symbol order.


- G001 — Use alphabet=Fin(2)={0,…,1} and the language whose number of occurrences of target_symbol=1 is congruent to residue=0 modulo modulus=18. Construct the complete DFA on states 0 through modulus−1, start 0 and accepting subset [residue]. A target symbol increments the state modulo the modulus; every other symbol leaves it unchanged. The invariant is state equals target-symbol count modulo the modulus for every prefix of every finite word, not just selected tests. No regex, NFA, epsilon move, minimization or pumping-lemma result is added. Give (states,transition,start,accepting,regular?,state_equals_target_symbol_count_mod_modulus_for_all_prefixes). Rows follow state order and columns symbol order.





## Definition and scope

Use the original question domain, assumptions and cited MKO definitions. This item has second-context mathematical and bilingual review, with the model, answer and every arithmetic step independently recomputed from the original parameters; the source question remains a candidate.


- [mko-regular-language](https://ocme.evemisslab.com/en/mko/mko-regular-language/)





## Step-by-step derivation

S001 · impliesBefore

mod-count state=0;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(0+0) mod18=0

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001





S002 · impliesBefore

mod-count state=0;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(0+1) mod18=1

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S001





S003 · impliesBefore

mod-count state=1;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(1+0) mod18=1

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S002





S004 · impliesBefore

mod-count state=1;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(1+1) mod18=2

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S003





S005 · impliesBefore

mod-count state=2;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(2+0) mod18=2

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S004





S006 · impliesBefore

mod-count state=2;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(2+1) mod18=3

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S005





S007 · impliesBefore

mod-count state=3;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(3+0) mod18=3

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S006





S008 · impliesBefore

mod-count state=3;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(3+1) mod18=4

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S007





S009 · impliesBefore

mod-count state=4;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(4+0) mod18=4

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S008





S010 · impliesBefore

mod-count state=4;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(4+1) mod18=5

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S009





S011 · impliesBefore

mod-count state=5;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(5+0) mod18=5

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S010





S012 · impliesBefore

mod-count state=5;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(5+1) mod18=6

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S011





S013 · impliesBefore

mod-count state=6;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(6+0) mod18=6

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S012





S014 · impliesBefore

mod-count state=6;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(6+1) mod18=7

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S013





S015 · impliesBefore

mod-count state=7;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(7+0) mod18=7

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S014





S016 · impliesBefore

mod-count state=7;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(7+1) mod18=8

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S015





S017 · impliesBefore

mod-count state=8;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(8+0) mod18=8

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S016





S018 · impliesBefore

mod-count state=8;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(8+1) mod18=9

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S017





S019 · impliesBefore

mod-count state=9;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(9+0) mod18=9

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S018





S020 · impliesBefore

mod-count state=9;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(9+1) mod18=10

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S019





S021 · impliesBefore

mod-count state=10;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(10+0) mod18=10

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S020





S022 · impliesBefore

mod-count state=10;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(10+1) mod18=11

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S021





S023 · impliesBefore

mod-count state=11;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(11+0) mod18=11

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S022





S024 · impliesBefore

mod-count state=11;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(11+1) mod18=12

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S023





S025 · impliesBefore

mod-count state=12;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(12+0) mod18=12

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S024





S026 · impliesBefore

mod-count state=12;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(12+1) mod18=13

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S025





S027 · impliesBefore

mod-count state=13;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(13+0) mod18=13

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S026





S028 · impliesBefore

mod-count state=13;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(13+1) mod18=14

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S027





S029 · impliesBefore

mod-count state=14;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(14+0) mod18=14

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S028





S030 · impliesBefore

mod-count state=14;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(14+1) mod18=15

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S029





S031 · impliesBefore

mod-count state=15;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(15+0) mod18=15

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S030





S032 · impliesBefore

mod-count state=15;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(15+1) mod18=16

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S031





S033 · impliesBefore

mod-count state=16;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(16+0) mod18=16

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S032





S034 · impliesBefore

mod-count state=16;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(16+1) mod18=17

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S033





S035 · impliesBefore

mod-count state=17;original symbol=0;target symbol=1;indicator=0;modulus=18

After

next state=(17+0) mod18=17

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S034





S036 · impliesBefore

mod-count state=17;original symbol=1;target symbol=1;indicator=1;modulus=18

After

next state=(17+1) mod18=0

Conditions: none

Increment only for the target symbol,otherwise by0,and reduce modulo the same modulus.Check every state-symbol cell,including wraparound from the last residue to0.

Step identifiers and dependenciesRule: regular_mod_count_every_state_symbol_cell · Uses: G001, S035





S037 · impliesBefore

states Fin(18);complete typed table=[[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 0]];start0;accepting residue=0

After

empty prefix count=0 equals start;append any symbol adds exactly its target indicator to BOTH count and state modulo the modulus

Conditions: none

Both count and state start at0.Appending any symbol updates both by the same indicator,so induction preserves state equal to target-symbol count modulo m for every prefix of every word.

Step identifiers and dependenciesRule: regular_mod_count_all_prefix_induction_base_step · Uses: G001, S036





S038 · impliesBefore

for EVERY finite word,state equals target-symbol count mod18;accepting set=[0]

After

accepted iff count congruent to0;whole declared language has this complete DFA certificate

Conditions: none

Final-state membership in the specified residue characterizes the entire declared language.This uses the complete DFA and universal invariant,not finite tests,and adds no regex,epsilon moves,minimization or pumping lemma.

Step identifiers and dependenciesRule: regular_mod_count_language_characterized_not_test_suite · Uses: G001, S037









## Reverse checks


- S038 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S037 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S036 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S035 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S034 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S033 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S032 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S031 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S030 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S029 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S028 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S027 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S026 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S025 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S024 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S023 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S022 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S021 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S020 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S019 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S018 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S017 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S016 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S015 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S014 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S013 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S012 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S011 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S010 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S009 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S008 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S007 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S006 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S005 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S004 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S003 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S002 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.
- S001 · premise_and_result_audit — Check against the original data and this step's premises; a one-way implication is not an equivalence.





## Result

([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 0]], 0, [0], Yes, state_equals_target_symbol_count_mod_modulus_for_all_prefixes)

The full substitutions and premise checks give the original answer; source identity,format and status are unchanged.





## This question review and source binding

Review date: 2026-10-26

Original questions, answers, step expressions, numeric ASTs and historical records are retained. Source candidate labels remain historical and are not overwritten as formal proof.

Source hashes and review receipts
- input commit: 0f7be61e2c22317a4075561dc822c87d881a50db
- original question SHA-256: 28d37362bae9f85a13bac7fcab148c65c9729397448f9101f9dd5a321a3bb029
- candidate record SHA-256: 59554a015a9b35bc5bfe0160831255fd41b3466b754821c7b2ae881092b1338d
- semantic review receipt SHA-256: 4a0957a15bb33fbe5f663e37a8babf46ab5a291eb5d1dfa3bf9045204cd43ec3
- question-first witness SHA-256: 22a8506bcfa34c503216083d1a8e813d61aad22dbc81589c0d41089c528a7f93
- Lean: NOT_RUN · human review: NOT_PERFORMED

[Same-source full JSON](https://ocme.evemisslab.com/data/question-derivations/questions/q-20261014-advance-20261102-r07-regular-language-0017.json)




