Zulip Chat Archive

Stream: mathlib4

Topic: upstreaming simps to Std


Scott Morrison (Nov 03 2023 at 02:41):

@Floris van Doorn, I would really like to make simps available to everyone, outside Mathlib. I've verified that it is easy to extract: #8140 does a slight import cleanup result from checking this.

Would you have any objection if I did this? (Anyone else?)

Floris van Doorn (Nov 03 2023 at 07:45):

That sounds good to me!

Johan Commelin (Nov 03 2023 at 07:47):

@Scott Morrison I don't know what I'm talking about, but I noticed that you are removing a use of q. I thought we generally tried to use Qq whenever possible?

But I guess Std can't depend on Qq, because Qq already depends on Std?

Eric Wieser (Nov 03 2023 at 07:55):

Qq doesn't depend on Std

Eric Wieser (Nov 03 2023 at 07:56):

Also, I think there's an open PR that fixes a bug in simps; it would be nice to get that merged before upstreaming

Johan Commelin (Nov 03 2023 at 07:57):

Do you mean

WIP: try to fix simps not failing when reaching a term is not a constructor #2936

Eric Wieser (Nov 03 2023 at 07:57):

Last time the Qq thing came up I think we were stalled by Gabriel having no time; I think now that the repo ownership has transferred, that's slightly less of a concern

Eric Wieser (Nov 03 2023 at 07:58):

#7707 is the one I had in mind

Mario Carneiro (Nov 03 2023 at 08:02):

Speaking of which, I've been thinking about upstreaming Qq to Std

Johan Commelin (Nov 03 2023 at 08:03):

In that case, this change to simps should maybe not be made?

Eric Wieser (Nov 03 2023 at 08:15):

Mario Carneiro said:

Speaking of which, I've been thinking about upstreaming Qq to Std

This sounds like a much better option than de-Qqing mathlib tactics; though I think we should:

  • merge the open Qq PRs first
  • make sure to merge the histories git merge --allow-unrelated to ensure Gabriel keeps all the credit / commit logs

Johan Commelin (Nov 03 2023 at 08:21):

@Mario Carneiro How concrete are you Qq-upstreaming plans?
@Scott Morrison How urgent is upstreaming simps to Std for you/FRO?

Mario Carneiro (Nov 03 2023 at 08:21):

I was thinking about bringing it up for discussion, not much more concrete than that

Mario Carneiro (Nov 03 2023 at 08:22):

it's definitely appropriate for Std, and it's going to be a bigger problem the more mathlib tactics we upstream because many of them use Qq

Johan Commelin (Nov 03 2023 at 08:23):

For now, could Std just start depending on Qq? Or is that too weird?

Mario Carneiro (Nov 03 2023 at 08:23):

It would most likely take the form of making Qq live in some new module like Std.Tactic.Qq, copying the contents in

Mario Carneiro (Nov 03 2023 at 08:24):

Std doesn't have any dependencies and the plan is to keep it that way, although we can consider alternatives

Eric Wieser (Nov 03 2023 at 08:45):

What's the issue with adding dependencies to Std? If the plan is to eventually merge the packages anyway, that doesn't sound too bad in the meantime.

Mario Carneiro (Nov 03 2023 at 08:46):

I was talking long term

Mario Carneiro (Nov 03 2023 at 08:47):

Sure, we could do it as a temporary measure but I don't really see the point since inlining is also fairly easy

Mario Carneiro (Nov 03 2023 at 08:47):

I don't see any forthcoming technical solutions to being able to automatically inline Qq in Std

Eric Wieser (Nov 03 2023 at 08:48):

We should probably check @Gabriel Ebner is happy with that outcome

Mario Carneiro (Nov 03 2023 at 08:48):

The main reason I want to avoid dependencies is because it means fewer moving parts for all downstream packages

Scott Morrison (Nov 04 2023 at 04:34):

I think this whole discussion is a bit off-track. :-)

The use of Qq in simps was completely trivial: I replaced it with literally a single call to mkConst.

Scott Morrison (Nov 04 2023 at 04:35):

If #7707 is going to happen soon it is fine to wait for it. But if it's more than a couple of days I'd prefer that we just continue with the upstreaming, and move #7707 over afterwards.

Scott Morrison (Nov 04 2023 at 04:37):

Entirely separately from upstreaming simps, we can talk about Qq in Std. :-)

Leo has previously expressed opposition to moving Qq into Std, or indeed having too many tactics relying on it. So I think this question is a complicated one that may not be resolvable quickly.

Scott Morrison (Nov 04 2023 at 06:56):

Okay, std#347 is the upstreaming of @[simps]. It can happen before or after #7707, either way will just patch up the second PR.

Mario Carneiro (Nov 04 2023 at 07:06):

Scott Morrison said:

Entirely separately from upstreaming simps, we can talk about Qq in Std. :-)

Leo has previously expressed opposition to moving Qq into Std, or indeed having too many tactics relying on it. So I think this question is a complicated one that may not be resolvable quickly.

Okay, I will hold off and also bring this up with him. Qq is definitely not the most bullet-proof implementation, but I think the ideas are sound and I really would not want to do any serious expr building over known types without it or an equivalent.

Scott Morrison (Nov 04 2023 at 07:09):

My only real complaint is that there are sometimes weird hard-to-diagnose errors binding universe levels.

I think (don't quote me?) Leo was concerned in part that it might be too easy for users to write non-performant Expr matching code, when a few getAppFnArgs would suffice?

For Expr building, quote4 is indispensable, I agree!

Mario Carneiro (Nov 04 2023 at 07:10):

yeah the expr match stuff is pretty expensive

Mario Carneiro (Nov 04 2023 at 07:11):

obviously the goal is to have expr match syntax which elaborates to calls to getAppFnArgs and friends

Mario Carneiro (Nov 04 2023 at 07:18):

I think we could have a Std.Experimental folder and put Qq.Match in it. This folder would not be included in import Std but it would be useful for allowing more things to be upstreamed faster before we are ready to commit to the API

Eric Wieser (Nov 04 2023 at 08:37):

Scott Morrison said:

I think (don't quote me?) Leo was concerned in part that it might be too easy for users to write non-performant Expr matching code, when a few getAppFnArgs would suffice?

The flip side of this is that code that doesn't use Qq can end up behaving incorrectly around reducible definitions, as it can end up performing exact rather than reducible matches.

Jannis Limperg (Nov 04 2023 at 09:30):

Does QQ do matching up to reducible computation by default? Can you get it to do syntactic matching as well?

Eric Wieser (Nov 04 2023 at 10:12):

My understanding was that it only did reducible matching (and that that's in some sense a feature; you don't ever want to match things like instances syntactically)

Jannis Limperg (Nov 04 2023 at 10:14):

Makes sense; reducible matching should certainly be the default.

Gabriel Ebner (Nov 10 2023 at 01:50):

Scott Morrison said:

I think (don't quote me?) Leo was concerned in part that it might be too easy for users to write non-performant Expr matching code, when a few getAppFnArgs would suffice?

Indeed, the matching part of quote4 is not great. It does its job as a tech demo amazingly, but I completely agree that there's massive performance issues. My plan was to automatically generate matching code using whnfR+getAppArgs+isDefEq (without unification), roughly approximating what the discrimination tree module does. But I never found the time to implement it.

Gabriel Ebner (Nov 10 2023 at 01:53):

There's two other big issues with the match syntax. First, there's no way to distinguish pattern variables from antiquotations. For example, in let x : Q(Nat) := 42; match y with | ~q($x + $y) => .... Should $x bind a fresh variable, or should it check that the lhs is defeq to 42?

Gabriel Ebner (Nov 10 2023 at 01:55):

Second, the macros in that file are wild. :smile:


Last updated: Dec 20 2023 at 11:08 UTC