Can clang be used as a problem solving assistant?

Spoiler: No

In this tweet Joe Groff links to this online compiler interface of a collatz conjecture implementation and clang/llvm optimizes it to return true. Its optimization is so aggressive, and perhaps arrogant, it treats the conjecture as settled and returns 1. The conjecture is of course unproven, and tested only up to about 2**68, a small fraction of the __int128_t parameter.

But it raises an interesting question. Could we glean insights to problems by writing solution checkers and observe clang/llvm's optimizer? Proposed workflow:

  1. write a solution checker
  2. compile the solution checker with optimization
  3. measure the complexity of the compiled checker (eg: cyclomatic complexity of the resulting CFG)
  4. propose bits of the solution by hardcoding them in the solution checker, goto 2

If the complexity of the compiled checker reduces, the partial solution is correct. Iterate this process to converge on a solution.

See ./tests.c for the tests and results.


generated from: clang-as-problem-solving-assistant/README.md