`setindex!` for `Fac`
I'm a bit confused by the behavior of setindex! for Fac. Currently I see no advantage over mulpow!. I'd expect to be able to change the exponents of factors already included, especially considering the docstring:
If $b$ is a factor of $a$, the corresponding entry is set to $c$.
What's also a bit weird, is that with setindex! non-positive exponents can be set. Resulting in interesting outputs:
julia> fac=factor(q^2-1)
1 * (q - 1) * (q + 1)
julia> setindex!(fac, 0, q);
julia> fac
1 * (q - 1) * q^0 * (q + 1)
julia> setindex!(fac, -1, q-2);
julia> fac
1 * (q - 1) * (q - 2)^-1 * q^0 * (q + 1)
julia> evaluate(fac)
ERROR: DomainError with -1:
Exponent must be non-negative
Stacktrace:
[1] ^(x::QQPolyRingElem, y::Int64)
@ Nemo ~/.julia/packages/Nemo/y7UoI/src/flint/fmpq_poly.jl:166
[2] evaluate(a::Fac{QQPolyRingElem})
@ AbstractAlgebra ~/.julia/packages/AbstractAlgebra/HxIHB/src/Factor.jl:56
[3] top-level scope
@ REPL[67]:1
In Hecke:
julia> factor(ZZ, QQ(1//100))
1 * 5^-2 * 2^-2
Regarding the setindex! and mulpow!. Yes, there is some overlapping functionality, but it is quite "natural" to have it given the other functionality for Fac.
Ok, but zero as exponent should never be useful, except setting zero removes the factor all together. And why is redefining of exponents not allowed?
Because someone thought it was a good idea when it was implemented. But I guess we could change it, if there is some interest.
the way it was used orignally: redefining an exponent meant a logic flaw in the code...
I understand this desire to prevent accidental changes to a Fac struct, but in that case wouldn't it make even more sense to disallow setindex! completely? To stop users from accidentally modifying the Fac at all?