"""Create reasoning_engine
Generated by Phi-Octopus Eden
2025-11-07 04:52:43.385899
"""

```python
from typing import Dict, List


class ReasoningEngine:
    """
    A simple reasoning engine that attempts to solve problems by chaining rules.

    This class is designed to handle limited reasoning sophistication,
    meaning it can only follow predefined rules and cannot reason beyond them.
    """

    def __init__(self):
        self.rules = []

    def add_rule(self, rule: str) -> None:
        """
        Add a new rule to the engine.

        Args:
            rule (str): A string representing a reasoning step in the format "IF condition THEN action".

        Raises:
            ValueError: If the rule is not properly formatted.
        """
        if "IF" not in rule or "THEN" not in rule:
            raise ValueError("Rule must be in 'IF condition THEN action' format.")
        self.rules.append(rule)

    def infer(self, initial_state: Dict[str, bool]) -> List[Dict[str, bool]]:
        """
        Perform inference based on the current rules and initial state.

        Args:
            initial_state (Dict[str, bool]): A dictionary representing the initial state with keys as variable names
                                              and values as boolean states of these variables.

        Returns:
            List[Dict[str, bool]]: A list of dictionaries representing the intermediate and final states.
        """
        current_state = [initial_state]
        for rule in self.rules:
            new_states = []
            for state in current_state:
                if "IF" in rule:
                    condition, action = rule.split(" THEN ", 1)
                    condition_true = all(state[var] == bool(eval(cond))
                                         for cond in condition.replace(" IF ", "").split(" AND "))
                    if condition_true:
                        new_state = {**state}
                        for act in action.split():
                            var, value = act.split("=")
                            new_state[var] = value == "True"
                        new_states.append(new_state)
            current_state.extend(new_states)
        return current_state


# Example usage
if __name__ == "__main__":
    reasoning_engine = ReasoningEngine()
    reasoning_engine.add_rule("IF A=True AND B=False THEN C=True")
    reasoning_engine.add_rule("IF C=True THEN D=False")

    initial_state = {"A": True, "B": False}
    states = reasoning_engine.infer(initial_state)

    for state in states:
        print(state)
```

This code defines a `ReasoningEngine` class that can add rules and perform inference based on those rules. The example usage at the bottom demonstrates how to create an instance of this engine, add some rules, and infer new states from an initial state.