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

[Merged by Bors] - feat(logic/nontrivial): a tactic to summon nontrivial instances #4374

Closed
wants to merge 9 commits into from

Conversation

semorrison
Copy link
Collaborator

Given a goal `a = b` or `a ≤ b` in a type `α`, generates an additional hypothesis `nontrivial α`
(as otherwise `α` is a subsingleton and the goal is trivial).

Alternatively, given a hypothesis `a ≠ b` or `a < b` in a type `α`, tries to generate a `nontrivial α`
hypothesis from existing hypotheses using `nontrivial_of_ne` and `nontrivial_of_lt`.

@semorrison
Copy link
Collaborator Author

@robertylewis I really struggled to come up with meaningful context-free examples to put in the doc-string. In order for this tactic to be useful, you need a "consumer" of the nontrivial instance available, and these are all a bit too interesting to put in a small example.

I added a test file, and used the tactic in an additional place in the library, in the hope that these are helpful for understanding the tactic.

I could just add the examples from the test file to the doc-string, but they are pretty lame.

@semorrison semorrison added the awaiting-review The author would like community review of the PR label Oct 3, 2020
Comment on lines 160 to 161
t ← (do `(%%a ≠ %%b) ← target, infer_type a) <|> (do `(%%a < %%b) ← target, infer_type a) <|>
fail "Goal is not `_ ≠ _` or `_ < _`",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On the previous branch Gabriel had suggested deleting these two lines.

If I do this, we don't know which type to look for an instance of nontrivial for. It would be plausible to just look for any, by using a placeholder, but I'd worry about finding the wrong one.

Copy link
Member

Choose a reason for hiding this comment

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

Well, this failure message will never display in notriviality. Not sure if that's what Gabriel was pointing out.

You can get t more cleanly with `(@ne %%t _ _) ← target

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is there a way to get t without using infer_type when I need to consider two possibilities and <? I can't get around using <|>.

Is (do `(@ne %%t _ _) ← target, return t) any better than (do `(%%a ≠ %%b) ← target, infer_type a)?

Copy link
Member

Choose a reason for hiding this comment

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

You can do something like

guardb $ e.is_app_of `ne || e.is_app_of `has_le.le,
return $ e.get_app_args.head

but looking at this again, would it be better to unify with ne or lt instead of checking syntactically, to capture ¬ a = b, >, etc?

Is (do `(@ne %%t _ _) ← target, return t) any better than (do `(%%a ≠ %%b) ← target, infer_type a)?

It's not a particularly big deal but it seems better to avoid a call to infer_type when the type info is already in the term.

Copy link
Member

Choose a reason for hiding this comment

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

For the record, what I wanted to say is that the tactic shouldn't be limited to = and goals. Maybe it should take an optional argument, like the inhabit tactic? That is, nontriviality α?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, I've switched to using unify.

I'm not entirely sure what the behaviour should be for other goals (besides = and ). Are we going to branch into cases and create a goal with a subsingleton hypothesis as well?

Copy link
Member

Choose a reason for hiding this comment

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

There's nothing special about the goal in the ne/lt case, is there? It just uses the goal to pick a type and then tries to prove nontriviality using hypotheses. nontriviality_by_assumption wouldn't need to be restricted to certain goals if it knew what type to look for.

I agree with Gabriel that the optional argument makes sense. If it's provided and the goal is eq/le and the types match, ignore it. If it's provided otherwise, do nontriviality_by_assumption except skip the first line. Otherwise do what you do now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, I've revised the tactic, so it now takes an optional type argument.

Copy link
Member

@robertylewis robertylewis left a comment

Choose a reason for hiding this comment

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

I'd still like to see an example in the doc, even a dumb one from the tests. You can add a comment showing how the context changes after the tactic call. Lots of people seem to learn tactics by example, not by reading the descriptions.

Comment on lines 160 to 161
t ← (do `(%%a ≠ %%b) ← target, infer_type a) <|> (do `(%%a < %%b) ← target, infer_type a) <|>
fail "Goal is not `_ ≠ _` or `_ < _`",
Copy link
Member

Choose a reason for hiding this comment

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

Well, this failure message will never display in notriviality. Not sure if that's what Gabriel was pointing out.

You can get t more cleanly with `(@ne %%t _ _) ← target

@robertylewis robertylewis added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Oct 3, 2020
@semorrison
Copy link
Collaborator Author

I've added the examples to the doc-string.

@semorrison semorrison added awaiting-review The author would like community review of the PR and removed awaiting-author A reviewer has asked the author a question or requested changes labels Oct 4, 2020
@robertylewis robertylewis added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Oct 5, 2020
@semorrison semorrison added awaiting-review The author would like community review of the PR and removed awaiting-author A reviewer has asked the author a question or requested changes labels Oct 6, 2020
@robertylewis robertylewis added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Oct 6, 2020
@semorrison semorrison added awaiting-review The author would like community review of the PR and removed awaiting-author A reviewer has asked the author a question or requested changes labels Oct 8, 2020
@robertylewis
Copy link
Member

Thanks! LGTM if you're okay with the example I added.

bors d+

@bors
Copy link

bors bot commented Oct 8, 2020

✌️ semorrison can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@robertylewis robertylewis added delegated The PR author may merge after reviewing final suggestions. and removed awaiting-review The author would like community review of the PR labels Oct 8, 2020
@semorrison
Copy link
Collaborator Author

bors merge

@github-actions github-actions bot added the ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) label Oct 8, 2020
bors bot pushed a commit that referenced this pull request Oct 8, 2020
```
Given a goal `a = b` or `a ≤ b` in a type `α`, generates an additional hypothesis `nontrivial α`
(as otherwise `α` is a subsingleton and the goal is trivial).

Alternatively, given a hypothesis `a ≠ b` or `a < b` in a type `α`, tries to generate a `nontrivial α`
hypothesis from existing hypotheses using `nontrivial_of_ne` and `nontrivial_of_lt`.
```



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
Co-authored-by: Rob Lewis <rob.y.lewis@gmail.com>
@bors
Copy link

bors bot commented Oct 8, 2020

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(logic/nontrivial): a tactic to summon nontrivial instances [Merged by Bors] - feat(logic/nontrivial): a tactic to summon nontrivial instances Oct 8, 2020
@bors bors bot closed this Oct 8, 2020
@bors bors bot deleted the nontriviality branch October 8, 2020 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
delegated The PR author may merge after reviewing final suggestions. ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants