"try" should suppress error processing
Nobody has claimed this yet.
- Dominant language
- Macaulay2
- Stars
- 435
- Forks
- 297
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 11
Description
Here's a bizarre observation: I tried to profile @pzinn's examples [here](https://github.com/Macaulay2/M2/issues/3843#issuecomment-2906328204), and got this:
```m2
o5 = #run %time position
5 233.8 ../linuxbrew/.linuxbrew/share/Macaulay2/LieTypes.m2:531:8-533:27
4 233.8 ../linuxbrew/.linuxbrew/share/Macaulay2/LieTypes.m2:533:13-533:27
3103 95.37 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/lists.m2:164:5-168:12
3146 72.18 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/matrix.m2:179:10-205:25
4 64.35 ../linuxbrew/.linuxbrew/share/Macaulay2/LieTypes.m2:1190:4-1190:49
4 63.63 ../linuxbrew/.linuxbrew/share/Macaulay2/LieTypes.m2:1058:4-1060:29
44 63.55 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/lists.m2:190:5-194:12
44 60.8 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/lists.m2:193:10-193:46
3146 60.19 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/matrix.m2:182:15-0:0
3103 56.61 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/lists.m2:167:10-167:46
4720 56.57 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/modules.m2:41:5-41:21
1573 41.14 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/methods.m2:27:65-28:88
3103 37.99 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/lists.m2:166:10-166:20
7865 35.71 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/robust.m2:9:32-9:40
6292 34.35 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/robust.m2:39:131-39:136
1573 33.95 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/robust.m2:48:5-48:93
4 32.41 ../linuxbrew/.linuxbrew/share/Macaulay2/LieTypes.m2:1191:4-1191:23
1 32.36 ../linuxbrew/.linuxbrew/share/Macaulay2/LieTypes.m2:1028:90-1028:142
1 32.35 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/methods.m2:669:4-679:107
4 32.35 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/methods.m2:670:12-670:100
1 24.17s elapsed total
```
There was no error being printed, so what is going on here?
```m2
7865 35.71 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/robust.m2:9:32-9:40
6292 34.35 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/robust.m2:39:131-39:136
1573 33.95 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/robust.m2:48:5-48:93
```
This should not be called once, let alone 7865 times!
https://github.com/Macaulay2/M2/blob/00b89ec877f93f5fc8f741eb0c3e657314cb57db/M2/Macaulay2/m2/robust.m2#L9
The answer lies in this line:
```m2
3146 60.19 ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.25.05/share/Macaulay2/Core/matrix.m2:182:15-0:0
```
This is inside `Matrix * Matrix`
https://github.com/Macaulay2/M2/blob/00b89ec877f93f5fc8f741eb0c3e657314cb57db/M2/Macaulay2/m2/matrix.m2#L182
Tracking a little bit, it's coming from here, where some integer and rational matrices are multiplied:
https://github.com/Macaulay2/M2/blob/00b89ec877f93f5fc8f741eb0c3e657314cb57db/M2/Macaulay2/packages/LieTypes.m2#L704-L709
This is of course easy to fix, e.g. just using `matrix(QQ, {...})` in the package, but I think two things should be fixed in Macaulay2:
1. `try ...` should not even begin to process error printing, and we should have tests to ensure this doesn't happen in future changes by accident;
2. there should be a better way to handle operations over potentially different rings, without the need to try promoting either way. This is basically #3638.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with M2/Macaulay2/m2/robust.m2 and the Matrix * Matrix implementation in M2/Macaulay2/m2/matrix.m2, then trace the calls from LieTypes.m2 lines 704-709. Reproduce the behavior with the profiling example and inspect how try handles error processing. Done means try avoids unnecessary error-printing work and regression tests cover that behavior; ring-promotion remains the separate #3638 concern.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100