Closed RobinHankin closed 5 years ago
But we can't do this:
> a <- rmvp(6)
> a
mvp object algebraically equal to
4 a b^5 c^6 e^4 + 2 a c^5 d^4 e^7 f^3 + a^2 b c d^5 e f^3 + 3 a^4 b^6 c^6 f^11 + 5 a^6 b^6 c^6 f^6 + 6 b d^6 e^5 f^6
> coeffs(a) <- pmax(coeffs(a),2)
Error in Ops.mvp_coeffs(mmm, each) :
operator '<' is not implemented for coeffs
and conceptually that should work: what we want to do is to replace each coefficient with the maximum of itself and 2. But of course <
is not (and cannot be) implemented because coeffs(a) < 2
is a Boolean vector, which is not allowed because it imposes a possibly incorrect ordering.
But now with the hashing system we can do this:
> linear(1:6)
mvp object algebraically equal to
a + 2 b + 3 c + 4 d + 5 e + 6 f
> x <- linear(1:8)
> coeffs(x)[coeffs(x)>3] <- 3
> x
mvp object algebraically equal to
a + 2 b + 3 c + 3 d + 3 e + 3 f + 3 g + 3 h
>
Note that coeffs(x)<3
(intentionally) returns an error.
The replacement method for coefficients requires that the replacement vector has length one. But look at this:
The idiom
coeffs(a) <- coeffs(a)+1
or indeed something likecoeffs(a) <- coeffs(a) %%2
is meaningful. It means "add one to each coefficient". Currently this does not work.Exactly the same issue happens in the
mvp
package:https://github.com/RobinHankin/freealg/issues/7
but I'll deal with them separately.