Nemocas / AbstractAlgebra.jl

Generic abstract algebra functionality in pure Julia (no C dependencies)
https://nemocas.github.io/AbstractAlgebra.jl/dev/index.html
Other
171 stars 63 forks source link

Use promote system for matrix operations #932

Closed thofma closed 2 years ago

thofma commented 3 years ago

I think it would be a good idea to use the promote system to also support the following:

julia> using AbstractAlgebra

julia> Qx, x = QQ["x"]
(Univariate Polynomial Ring in x over Rationals, x)

julia> A = zero_matrix(Qx, 2, 2)
[0   0]
[0   0]

julia> B = zero_matrix(QQ, 2, 2)
[0//1   0//1]
[0//1   0//1]

julia> A * B
ERROR: MethodError: [...]

A minor problem is that we cannot use the generic * fallback for ring elements since

  1. these are not ring elements and
  2. we don't want to create parents.

I guess the best idea is to use the promote system and use it to write a fallback * for matrices using change_base_ring.

I will take a stab at this if y'all think this is not a terrible idea.

wbhart commented 3 years ago

Sounds ok to me. It's still a simple coercion because the result is the same type as one of the two inputs.

I see no reason to not support this.

thofma commented 2 years ago

I think I fixed this.