Skip to content

Conversation

@stevenraphael
Copy link
Contributor

@stevenraphael stevenraphael commented Nov 24, 2025

Following substantial discussion with Andrew Adams and Alex Reinking, I have implemented a first draft of their idea of inductively defined functions. A full description is in src/Inductive.h. This pull includes correctness and error tests. Please suggest any additional changes I need to make. The basic idea is to have pure functions that are defined with self-references, e.g. f(x) = select(x <= 0, input(0), input(x) + f(x - 1)), which allows for optimizations that are currently impossible to do with reduction domains.

@stevenraphael stevenraphael changed the title Inductive2 Inductive functions Nov 24, 2025
@stevenraphael stevenraphael changed the title Inductive functions Add support for inductively defined functions Nov 24, 2025
@zvookin
Copy link
Member

zvookin commented Nov 24, 2025

Given the constraints on the definition, I'm wondering if this should be its own syntax. E.g. f(x) = inductive(cond, expr1, expr2) Could also try to put it all in the construction, similar to how RDom is done, but given the arguments need to be specified, function definition syntax seems better.

Main goal is to avoid confusion around the lack of generality in the definition. If it is envisioned that this will become more general, the current design might be the right way to go. (And by confusion, I mean that this makes it look like normal programming language recursion expectations are supported.)

@abadams
Copy link
Member

abadams commented Nov 24, 2025

The goal is definitely to become more general over time. The thinking was that if we fail to solve for a base case, we could tell the user to write things in a particular form that is known to work, but first we'd try to handle any recursive RHS.

@alexreinking
Copy link
Member

We are likely to merge #8877 before this, so consider using the new APIs to simplify visitors/mutators here. I see two here: RecursiveHelper in is_inductive, and maybe BaseCaseSolver as it has just one visit overload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants