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: expose that panic α = default #1614

Merged
merged 1 commit into from
Sep 19, 2022

Conversation

digama0
Copy link
Collaborator

@digama0 digama0 commented Sep 16, 2022

For reasoning about code that contains panic!, I think the least bad option (other than removing panic entirely) is to just make it visible to the kernel that panic evaluates to default (which is true if we ignore the side effect of tracing to stderr). This is similar to the dbgTrace function which has a side effect but is not opaque to the kernel and instead has a definition which just shows what happens after the side effect.

@leodemoura leodemoura added the dev meeting It will be discussed at the (next) dev meeting label Sep 16, 2022
@leodemoura
Copy link
Member

For reasoning about code that contains panic!,

Could you please provide some use-cases?

@digama0
Copy link
Collaborator Author

digama0 commented Sep 17, 2022

For example, a theorem I would like to prove is:

theorem head!_eq_head? [Inhabited α] : ∀ l : List α, head! l = (head? l).get!

but it's not true in the nil case, because the two sides reduce to

panicCore (mkPanicMessageWithDecl "Init.Data.List.BasicAux" "List.head!" 31 12 "empty list") =
panicCore (mkPanicMessageWithDecl "Init.Data.Option.BasicAux" "Option.get!" 16 14 "value is none")

and the two string expressions are not equal even after reduction.

On the other hand,

theorem get!_eq_get? [Inhabited α] (a : Array α) : a.get! n = (a.get? n).getD default

is provable, because the panic in this function is performed in a slightly different way which does not use an opaque.

@leodemoura leodemoura merged commit 61df1e5 into leanprover:master Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev meeting It will be discussed at the (next) dev meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants