Skip to content

Feature request: Parameters in termination_by #879

Closed

Description

@digama0

The default behavior of the termination checker is to tuple together all the arguments of the function, including variables (which cannot possibly change in recursive arguments). This can be problematic when it comes to supplying the relevant WellFoundedRelation, if this relation depends on some of the parameters. (For example, mathlib4 has a relation for doing upward recursion:

def Up (ub a i : ℕ) := i < a ∧ i < ub

but ub is a dependency of the relation, and it is difficult to use this on a function def foo (ub : nat) (i : nat) because the two arguments get tupled together.)

It is possible to work around this with a variation on lex that is dependent and skips some of the arguments, but I think a nicer default behavior is to check the recursive arguments to find out which ones change in recursive calls, and only tuple these up and leave the rest as parameters. That is, a function like this:

variable (a : Nat)
def foo (b c : Nat) := if b = 0 then a + c else foo (b - 1) c 
termination_by ...

would get a goal of a c : Nat |- WellFoundedRelation Nat, because only b changes in recursive calls.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions