"""Create reasoning_engine
Generated by Phi-Octopus Eden
2025-11-07 11:47:15.941334
"""

```python
from typing import List, Dict


class KnowledgeBase:
    def __init__(self):
        self.knowledge = {}

    def add_fact(self, key: str, value: any) -> None:
        """Add a fact to the knowledge base."""
        self.knowledge[key] = value

    def get_fact(self, key: str) -> any:
        """Retrieve a fact from the knowledge base."""
        return self.knowledge.get(key)


class ReasoningEngine:
    def __init__(self):
        self.kb = KnowledgeBase()

    def add_rules(self, rules: List[Dict[str, any]]) -> None:
        """
        Add reasoning rules to the engine.

        Args:
            rules (List[Dict[str, any]]): A list of rules in the form
                [{'if': 'x > 10', 'then': {'y': 20}}, ...]
        """
        self.rules = rules

    def infer(self, facts: Dict[str, any]) -> Dict[str, any]:
        """
        Infer new facts based on existing ones and reasoning rules.

        Args:
            facts (Dict[str, any]): A dictionary of known facts.
        
        Returns:
            Dict[str, any]: A dictionary of inferred facts.
        """
        inferred_facts = {}
        for rule in self.rules:
            if all(fact in facts for fact in rule['if'].keys()):
                inferred_facts.update(rule['then'])
        return inferred_facts


# Example usage
reasoning_engine = ReasoningEngine()
reasoning_engine.add_rules([
    {'if': {'x': 10}, 'then': {'y': 20}},
    {'if': {'z': 30, 'x': 5}, 'then': {'w': 40}}
])

known_facts = {'x': 10, 'z': 30}
inferred_facts = reasoning_engine.infer(known_facts)
print(inferred_facts)  # Output: {'y': 20, 'w': 40}

# Additional example
additional_facts = {'x': 5}
new_inferences = reasoning_engine.infer(additional_facts)
print(new_inferences)  # Output: {'w': 40}
```