swh:1:snp:81eadaa089e8253d8469bcef66aa332632c6c669
Tip revision: 138099729fa36cb6c4eaacac3037ea9105d6700a authored by Hans W. Borchers on 28 November 2013, 00:00:00 UTC
version 1.5.8
version 1.5.8
Tip revision: 1380997
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)
}