Closed linus-md closed 4 months ago
I guess this relates to https://github.com/Nemocas/Nemo.jl/blob/79c9770d112d106c0d2911af095b929b0b7abf6f/docs/src/developer/topics.md?plain=1#L333 this somehow but how should I mitigate the issue?
http://nemocas.github.io/Nemo.jl/v0.6/matrix/ matrix space solve the problem!
You are trying to work with a Julia Matrix
containing Nemo elements, something we generally don't do and hence don't test for.
The Nemo resp. Oscar way of doing this would be this:
julia> A2 = matrix(R, A)
[A[1, 1] A[1, 2]]
[A[2, 1] A[2, 2]]
julia> A2 * transpose(A2)
[ A[1, 1]^2 + A[1, 2]^2 A[1, 1]*A[2, 1] + A[1, 2]*A[2, 2]]
[A[1, 1]*A[2, 1] + A[1, 2]*A[2, 2] A[2, 1]^2 + A[2, 2]^2]
That said, your code could be made to work by adding this definition:
Base.copy(x::Nemo.NCRingElem) = x
based on this method definition from the Julia stdlib:
copy(x::Number) = x # some code treats numbers as collection-like
With that added you'll get
julia> A * transpose(A)
2×2 Matrix{FqMPolyRingElem}:
A[1, 1]^2 + A[1, 2]^2 A[1, 1]*A[2, 1] + A[1, 2]*A[2, 2]
A[1, 1]*A[2, 1] + A[1, 2]*A[2, 2] A[2, 1]^2 + A[2, 2]^2
I am not sure such a copy
method would be safe in general, though... Seems we already have three and they either use deepcopy
or create a new ring element:
src/antic/nf_elem.jl:225:Base.copy(d::AbsSimpleNumFieldElem) = deepcopy(d)
src/flint/fmpq_poly.jl:76:Base.copy(f::QQPolyRingElem) = parent(f)(f)
src/flint/fmpz.jl:201:Base.copy(a::ZZRingElem) = deepcopy(a)
Thing is, the "documentation" for Base.copy
is really vague, and it does not really specify the expected semantics or what the result of it is used for :-/. In the specific case you encountered here, copy
is invoked by the LinearAlgebra
stdlib function matmul2x2!
on matrix entries... And unfortunately it says nothing about why it does that. Looking at the LinearAlgebra documentation suggests that perhaps this is for dealing with nested matrices (matrices with matrices as entries)... Anyway, for that particular caller of copy
, the method I suggested above should be fine. But there might be others were one really should be making an actual copy?
I guess we could add something like Base.copy(x::Nemo.NCRingElem) = deepcopy(x)
to Nemo to be on the safe side and still allow code like yours, but the result would be even more inefficient because of all the pointless copies being made.
You don't need matrix spaces to solve the issue -- and be careful to not really on the documentation for the truly ancient Nemo 0.6 (from 2017) while working with current 0.45 (from 2024). The current docs can be found at http://nemocas.github.io/Nemo.jl/stable/matrix/ (for the chapter you were referencing)
Thanks @fingolfin indeed matrix
is what I was really looking for! I don't know what you should do but as you said the copy error message is really not useful and given that A*A
and transpose(A)
can be computed seems strange.
Regarding the old documentation the message: "This documentation is not for the latest version. Go to the latest documentation." is shown but the link seems to be broken!
The link is fixed in https://github.com/Nemocas/Nemo.jl/pull/1822
Hello,
I want to compute A*A^T where a is a matrix of polynomial elements like that
which does not work, why is that?