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

compose(f,g) is inconsistent #690

Closed
fingolfin opened this issue Sep 20, 2021 · 14 comments
Closed

compose(f,g) is inconsistent #690

fingolfin opened this issue Sep 20, 2021 · 14 comments

Comments

@fingolfin
Copy link
Member

fingolfin commented Sep 20, 2021

We need to settle what that means, ensure it is implemented consistently everywhere, and documented clearly.

There are two choices how to interpret it, both are natural in some settings but not in others:

  • compose(f,g)(x) = f(g(x)) is compatible with left application of functions and matches Julia's \circ operator, which satisfies (f ∘ g)(x) = f(g(x)); this is what textbooks use nowadays
  • compose(f,g)(x) = g(f(x)) is compatible with right application of functions (so f(x) = x^f and then x^{compose(f,g)} = (x^f)^g); for this composition I have often seen the convention to denote it by f g (juxtaposition), sometimes alsof \cdot g or f * g) -- this is by the way historically the older notation, and e.g. group theorists still use it a lot

But in Oscar, what compose does differs by type, which is bad. We need to settle on one and implement it uniformly. I'll try to sum up the state below; I only looked at the written documentation for this, though; what is actually implemented might differ yet again...

Places that say compose(f,g) = g(f(x) = (x^f)^g:

Places that say compose(f,g) = f(g(x) = (x^g)^f:

Since the AA documentation is quite explicit on this, I tend to say we should follow it; what worries me is that some docstrings in AA claim to do it the other way around; but perhaps the doc strings are wrong?

Besides settling this, I think it'd be a great thing to have a conformance test for, though I am not sure how to best to arrange for it.

CC @wbhart @thofma @fieker

@fingolfin
Copy link
Member Author

Discussed with @fieker and I think we agree that compose should do what it claims in the AA docs; so now we need to fix everything that does it wrong.

@thofma

This comment has been minimized.

@fingolfin

This comment has been minimized.

@thofma

This comment has been minimized.

@fingolfin

This comment has been minimized.

@fingolfin

This comment has been minimized.

@thofma

This comment has been minimized.

@fingolfin

This comment has been minimized.

fingolfin pushed a commit that referenced this issue Feb 2, 2022
... such that `compose(f, g)` maps `x` to `g(f(x))`.
As is stated in the discussion of issue #690,
the definition from [the AbstractAlgebra manual section for the Map interface](https://oscar-system.github.io/Oscar.jl/dev/AbstractAlgebra/map_interface/#Composition-of-maps) should be used consistently.
@fingolfin
Copy link
Member Author

This is now fixed for (GAP) groups, by PR #1038.

bschroter pushed a commit to bschroter/oscar-matroids that referenced this issue Feb 20, 2022
... such that `compose(f, g)` maps `x` to `g(f(x))`.
As is stated in the discussion of issue oscar-system#690,
the definition from [the AbstractAlgebra manual section for the Map interface](https://oscar-system.github.io/Oscar.jl/dev/AbstractAlgebra/map_interface/#Composition-of-maps) should be used consistently.
@lgoettgens
Copy link
Member

citing @fieker from slack:

I'm not sure how much of an issue it is. For all Map-types compose(a,b) is b(a(x))
for non-map types, I'd never use compose... I'd be in favour of droppnig compse for non-maps amd use evaluare instead. or even f(a). THis is non-ambigous

@lgoettgens
Copy link
Member

Nemocas/Nemo.jl#1521 implements the changes proposed here for all remaining Nemo types. But it still has the same seriousness of breaking a lot of stuff as Nemocas/AbstractAlgebra.jl#1025 for PolyElem and RelSeriesElem.

How to proceed here?

  1. Breaking change in AA and Nemo
  2. Remove compose for all non-map types (as suggested by @fieker)
  3. ?

@thofma
Copy link
Collaborator

thofma commented Aug 15, 2023

Since it is called polynomial composition, I would prefer to keep compose for polynomials for the sake of discoverability.

One option to go forward would be to

  1. remove all of our uses of compose for non-map types and make new releases.
  2. introduce a warning in the compose for non-map types, that the order will change in the next version.
  3. make a breaking release, where we change the order of compose for non-map types.

This is the only thing I could come up with.

@thofma
Copy link
Collaborator

thofma commented Dec 30, 2023

After the discussions we had a while ago, the following is the best I can come up with:

  1. Turn compose(f::PolyElem, g::PolyElem) into compose(f::PolyElem, g::PolyElem; side) with a mandatory keyword argument. Similar for the other problematic method. Maybe we could also introduce a _compose with the right behaviour that we can use internally (or whatever name we settle on. I don't care too much).
  2. Wait a few years.
  3. Add the default keyword.
  4. Profit.

We have dallied over this quite a bit, so unfortunately 2. would not finish before 1.0. On ther other hand, we can also just promote f(g) resp. g(f) over compose both in our code as well as in the documentation.

Any comments @fingolfin @fieker?

@fieker
Copy link
Contributor

fieker commented Jan 2, 2024 via email

thofma added a commit to Nemocas/AbstractAlgebra.jl that referenced this issue Feb 13, 2024
- First step at resolving oscar-system/Oscar.jl#690
- Introduce a mandatory keyword argument for compose(f, g)
  and add a hint for f(g)/g(f) syntax.

[breaking]
thofma added a commit to Nemocas/AbstractAlgebra.jl that referenced this issue Feb 13, 2024
- First step at resolving oscar-system/Oscar.jl#690
- Introduce a mandatory keyword argument for compose(f, g)
  and add a hint for f(g)/g(f) syntax.

[breaking]
thofma added a commit to Nemocas/AbstractAlgebra.jl that referenced this issue Feb 13, 2024
- First step at resolving oscar-system/Oscar.jl#690
- Introduce a mandatory keyword `inner = :first/:second` argument for
  compose(f, g) and add a hint for f(g)/g(f) syntax.

[breaking]
thofma added a commit to Nemocas/AbstractAlgebra.jl that referenced this issue Feb 13, 2024
- First step at resolving oscar-system/Oscar.jl#690
- Introduce a mandatory keyword `inner = :first/:second` argument for
  compose(f, g) and add a hint for f(g)/g(f) syntax.

[breaking]
thofma added a commit to Nemocas/AbstractAlgebra.jl that referenced this issue Feb 13, 2024
* fix: make compose do what it says

- First step at resolving oscar-system/Oscar.jl#690
- Introduce a mandatory keyword `inner = :first/:second` argument for
  compose(f, g) and add a hint for f(g)/g(f) syntax.

[breaking]

* chore: bump to 0.39.0
ooinaruhugh pushed a commit to ooinaruhugh/AbstractAlgebra.jl that referenced this issue Feb 15, 2024
* fix: make compose do what it says

- First step at resolving oscar-system/Oscar.jl#690
- Introduce a mandatory keyword `inner = :first/:second` argument for
  compose(f, g) and add a hint for f(g)/g(f) syntax.

[breaking]

* chore: bump to 0.39.0
@lgoettgens lgoettgens removed the triage label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants