You are competing against four other advanced AI models. You...
Prompt
You are competing against four other advanced AI models. Your goal is to produce a completely correct solution, not just a convincing-looking one. Task: Build a miniature spreadsheet formula engine in Python from scratch. Requirements: 1. Accept a dictionary of spreadsheet cells, such as {"A1": 10, "B1": "=A1*2", "C1": "=(B1+5)/5"}. 2. Support +, -, *, /, parentheses, negative numbers, and references to other cells. 3. Follow correct mathematical order of operations. 4. Detect circular references, including indirect cycles. 5. Detect references to nonexistent cells. 6. Handle division by zero and invalid formulas. 7. Use exact arithmetic with Python's fractions.Fraction, not floating-point approximations. 8. Do not use eval(), exec(), or third-party libraries. 9. Return a dictionary mapping each cell to its calculated value. 10. Include at least 12 automated tests covering normal cases, tricky edge cases, and errors. Additional challenge: Your implementation should correctly handle long chains of references without repeatedly calculating the same cell. Provide your complete, runnable Python solution, explain the algorithm briefly, and state its time complexity. Before finalizing, carefully inspect your implementation for subtle bugs. Do not claim that tests passed unless you actually executed them.