swh:1:snp:81eadaa089e8253d8469bcef66aa332632c6c669
Tip revision: 26e049d70b4a1c237987e260cba68f6a9413736c authored by Hans W. Borchers on 09 April 2019, 04:10:07 UTC
version 2.2.5
version 2.2.5
Tip revision: 26e049d
polymul.R
##
## p ol y m u l .R Polynomial Multiplication
##
polymul <- function(p, q){
if ( (!is.vector(p, mode="numeric") && !is.vector(p, mode="complex")) ||
(!is.vector(q, mode="numeric") && !is.vector(q, mode="complex")) )
stop("Arguments 'p' and 'q' must be real or complex vectors.")
n <- length(p); m <- length(q)
if (n <= 1 || m <= 1) return(p*q)
r <- rep(0, n+m-1)
for (i in seq(along=q)) {
r <- r + c(rep(0, i-1), p * q[i], rep(0, m-i))
}
while (r[1] == 0 && length(r) > 1)
r <- r[2:length(r)]
return(r)
}