lean4-htt/src/library
Leonardo de Moura 0a2d121e45
fix: modify projection instance binder info (#5376)
closes #5333

This PR tries to address issue #5333.

My conjecture is that the binder annotations for `C.toB` and
`Algebra.toSMul` are not ideal. `Algebra.toSMul` is one of declarations
where the new command `set_synth_order` was used. Both classes, `C` and
`Algebra`, are parametric over instances, and in both cases, the issue
arises due to projection instances: `C.toB` and `Algebra.toSMul`. Let's
focus on the binder annotations for `C.toB`. They are as follows:

```
C.toB [inst : A 20000] [self : @C inst] : @B ...
```

As a projection, it seems odd that `inst` is an instance-implicit
argument instead of an implicit one, given that its value is fixed by
`self`. We observe the same issue in `Algebra.toSMul`:

```
Algebra.toSMul {R : Type u} {A : Type v} [inst1 : CommSemiring R] [inst2 : Semiring A]
   [self : @Algebra R A inst1 inst2] : SMul R A
```

The PR changes the binder annotations as follows:

```
C.toB {inst : A 20000} [self : @C inst] : @B ...
```

and

```
Algebra.toSMul {R : Type u} {A : Type v} {inst1 : CommSemiring R} {inst2 : Semiring A}
    [self : @Algebra R A inst1 inst2] : SMul R A
```

In both cases, the `set_synth_order` is used to force `self` to be
processed first.

In the MWE, there is no instance for `C ...`, and `C.toB` is quickly
discarded. I suspect a similar issue occurs when trying to use
`Algebra.toSMul`, where there is no `@Algebra R A ... ...`, but Lean
spends unnecessary time trying to synthesize `CommSemiring R` and
`Semiring A` instances. I believe the new binder annotations make sense,
as if there is a way to synthesize `Algebra R A ... ...`, it will tell
us how to retrieve the instance-implicit arguments.

TODO: 
- Impact on Mathlib.
- Document changes.

---------

Co-authored-by: Kim Morrison <scott.morrison@gmail.com>
Co-authored-by: Johan Commelin <johan@commelin.net>
2024-09-20 06:03:59 +00:00
..
compiler chore: rename Array.data to Array.toList 2024-09-10 15:24:23 +10:00
constructions fix: modify projection instance binder info (#5376) 2024-09-20 06:03:59 +00:00
annotation.cpp chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
annotation.h chore: fix more typos in comments 2023-10-08 14:37:34 -07:00
aux_recursors.cpp refactor: constructions: modify environment in lean world (#4474) 2024-06-19 08:58:53 +00:00
aux_recursors.h refactor: constructions: modify environment in lean world (#4474) 2024-06-19 08:58:53 +00:00
bin_app.cpp
bin_app.h
class.cpp
class.h
CMakeLists.txt refactor: constructions: modify environment in lean world (#4474) 2024-06-19 08:58:53 +00:00
constants.cpp chore: rename Array.data to Array.toList 2024-09-10 15:24:23 +10:00
constants.h chore: rename Array.data to Array.toList 2024-09-10 15:24:23 +10:00
constants.txt chore: rename Array.data to Array.toList 2024-09-10 15:24:23 +10:00
expr_lt.cpp fix: dllexport functions not already annotated in header 2021-09-20 18:41:46 +02:00
expr_lt.h
expr_pair.h chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
expr_pair_maps.h
expr_unsigned_map.h
formatter.cpp
formatter.h
init_module.cpp fix: Windows needs more LEAN_EXPORTs 2024-08-12 14:14:42 +02:00
init_module.h fix: Windows needs more LEAN_EXPORTs 2024-08-12 14:14:42 +02:00
max_sharing.cpp chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
max_sharing.h
module.cpp feat: embed and check githash in .olean (#2766) 2023-11-27 10:24:43 +00:00
module.h fix: Windows needs more LEAN_EXPORTs 2024-08-12 14:14:42 +02:00
num.cpp
num.h chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
print.cpp fix: pp projection indices starting at 1 2023-10-15 14:25:00 -07:00
print.h fix: Windows needs more LEAN_EXPORTs 2024-08-12 14:14:42 +02:00
profiling.cpp fix: profiler threshold in C++ 2023-04-10 16:57:54 +02:00
profiling.h fix: Windows needs more LEAN_EXPORTs 2024-08-12 14:14:42 +02:00
projection.cpp refactor: move is_structure_like to inductive.cpp 2021-11-25 11:31:00 -08:00
projection.h perf: fix implementation of move constructors and move assignment ope… (#4700) 2024-08-02 17:55:03 +00:00
reducible.cpp
reducible.h
replace_visitor.cpp chore: reduce src/include/lean 2021-09-07 08:24:54 -07:00
replace_visitor.h
suffixes.h refactor: port recOn construction to Lean (#4516) 2024-06-23 07:36:27 +00:00
time_task.cpp chore: move trace.cpp to kernel (#4014) 2024-04-28 17:24:48 +00:00
time_task.h fix: Windows needs more LEAN_EXPORTs 2024-08-12 14:14:42 +02:00
util.cpp refactor: constructions: modify environment in lean world (#4474) 2024-06-19 08:58:53 +00:00
util.h fix: Windows needs more LEAN_EXPORTs 2024-08-12 14:14:42 +02:00