Project Euler Lab - Problem 674

#674 - Solving $\mathcal{I}$-equations

● ResearchOfficial difficulty: 89%PolynomialsTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

We define the \(\mathcal{I}\) operator as the function \[\mathcal{I}(x,y) = (1+x+y)^2+y-x\] and \(\mathcal{I}\)-expressions as arithmetic expressions built only from variable names and applications of \(\mathcal{I}\). A variable name may consist of one or more letters. For example, the three expressions \(x\), \(\mathcal{I}(x,y)\), and \(\mathcal{I}(\mathcal{I}(x,ab),x)\) are all \(\mathcal{I}\)-expressions.

For two \(\mathcal{I}\)-expressions \(e_1\) and \(e_2\) such that the equation \(e_1=e_2\) has a solution in non-negative integers, we define the least simultaneous value of \(e_1\) and \(e_2\) to be the minimum value taken by \(e_1\) and \(e_2\) on such a solution. If the equation \(e_1=e_2\) has no solution in non-negative integers, we define the least simultaneous value of \(e_1\) and \(e_2\) to be \(0\). For example, consider the following three \(\mathcal{I}\)-expressions: \[\begin{array}{l}A = \mathcal{I}(x,\mathcal{I}(z,t))\\ B = \mathcal{I}(\mathcal{I}(y,z),y)\\ C = \mathcal{I}(\mathcal{I}(x,z),y)\end{array}\] The least simultaneous value of \(A\) and \(B\) is \(23\), attained for \(x=3,y=1,z=t=0\). On the other hand, \(A=C\) has no solutions in non-negative integers, so the least simultaneous value of \(A\) and \(C\) is \(0\). The total sum of least simultaneous pairs made of \(\mathcal{I}\)-expressions from \(\{A,B,C\}\) is \(26\).

Find the sum of least simultaneous values of all \(\mathcal{I}\)-expressions pairs made of distinct expressions from file I-expressions.txt (pairs \((e_1,e_2)\) and \((e_2,e_1)\) are considered to be identical). Give the last nine digits of the result as the answer.

This problem is taken from Project Euler, Problem 674.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=674. Published Sunday, 9th June 2019, 10:00 am. Solved by 206 members at time of mirroring.

Why this is useful

Optimization. A genuine objective is optimised over a choice set - the same shape as calibration and optimal-execution problems (Phases 10, 16).

We classify relevance honestly - not every Euler problem is a trading application.

Learning mode

Pick how much scaffolding you want. Your choice is remembered per problem.

Scratchpad

Mathematical notes, formulas, pseudocode, hypotheses, complexity notes. Saved automatically with your progress.

Python workbench

Tier C - reduced scale in browser; full scale in notebook
Browser runs a reduced, clearly-labelled educational scale; the original scale is provided in a local notebook.

Real Python (Pyodide) in a sandboxed Web Worker - no network, no filesystem, no DOM access. Ctrl/Cmd+Enter runs. Escape leaves the editor. Stop terminates the worker.

Python runtime not loaded (it boots on first run - a one-time local load).

Check your answer

Answers are checked against a salted hash held in a separate file - not printed in this page. This prevents accidental spoilers; it is not cryptographic protection (see the build notes).

Progressive hints

Confidence

Low confidence schedules this problem for spaced review, even if you solved it.

Reference solution

Spoiler
The complete original explanation (interpretation, naive approach, insight, proof, complexity, Python implementation, tests, common mistakes, alternatives) is hidden and lazy-loaded. Reveal it only after a meaningful attempt - the struggle is where the learning happens.