Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Mathlib/Computability/Ackermann): Ackermann function is computable #22457

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Komyyy
Copy link
Collaborator

@Komyyy Komyyy commented Mar 2, 2025

It had been proved that Ackermann function is not primitive recursive, but not been proved that it's computable.
I proved that.


Open in Gitpod

@Komyyy Komyyy added the t-computability Computability theory (TMs, DFAs, languages, grammars, etc) label Mar 2, 2025
@Komyyy Komyyy requested a review from vihdzp March 2, 2025 06:10
Copy link

github-actions bot commented Mar 2, 2025

PR summary b73698b1d3

Import changes for modified files

Dependency changes

File Base Count Head Count Change
Mathlib.Computability.Ackermann 710 716 +6 (+0.85%)
Import changes for all files
Files Import difference
Mathlib.Computability.Ackermann 6

Declarations diff

+ _root_.computable₂_ack
+ eval_pappAck
+ eval_pappAck_step_succ
+ eval_pappAck_step_zero
+ pappAck
+ pappAck_prim
+ pappAck_step_prim

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@Komyyy Komyyy force-pushed the Komyyy/computable_ack branch from 16438ae to 04e9308 Compare March 2, 2025 06:16
@vihdzp
Copy link
Collaborator

vihdzp commented Mar 2, 2025

Awesome! I'm not very familiar with the computability API, but I'll try to review this anyways.

@Komyyy Komyyy force-pushed the Komyyy/computable_ack branch from 04e9308 to b73698b Compare March 2, 2025 11:38
@Komyyy Komyyy requested a review from vihdzp March 2, 2025 12:01

/-- The code for the partial applied Ackermann function.
This is used to prove that the Ackermann function is computable. -/
def pappAck : ℕ → Code
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes do make the code look nicer, though that's not quite what I meant. I was expecting something like

theorem primrec_ack_apply (n : ℕ) : Primrec (ack n) := sorry

This should then (hopefully) give you a simple proof of computability.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question!
Indeed, we can get a function of ℕ → Code from the primrec_ack_apply lemma by using choose tactic, but there are no warranty that the function is computable, this fact is used to the proof.
So, we should give an explicit code function which is computable.

Copy link
Collaborator Author

@Komyyy Komyyy Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, there are uncountable noncomputable many code functions which evaluated to ack n.

@Komyyy Komyyy added WIP Work in progress and removed WIP Work in progress labels Mar 3, 2025
@Komyyy
Copy link
Collaborator Author

Komyyy commented Mar 6, 2025

@vihdzp If the review is done, please approve.

step (c : Code) : Code :=
.curry (.prec (.comp c (.const 1)) (.comp c (.comp .right .right))) 0

lemma pappAck_step_prim : Primrec pappAck.step := by
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is prim a standard abbreviation for Primrec in these files? I would've expected a name primrec_pappAck_step instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the consistency with lemmas like Code.prec_prim.

(pappAck.step c).eval (n + 1) = ((pappAck.step c).eval n).bind c.eval := by
simp [pappAck.step, Code.eval]

lemma pappAck_prim : Primrec pappAck := by
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be used to prove the primrec_ack_apply theorem I mentioned earlier, right? Can you add that too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lemma can prove Computable (ack n) but not Primrec (ack n).
This is clearly weaker than Computable₂ ack so it's not worth to prove.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t-computability Computability theory (TMs, DFAs, languages, grammars, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants