find_factors {lazy.symbolic}R Documentation

Decompose a Term into Multiplicative Factors separated by *, / or %*%.

Description

Decompose a Term into Multiplicative Factors separated by *, / or %*%.

Usage

find_factors(exp, markso = 1, sort = 0, debug = 0)

Arguments

exp

An expression vector or matrix
Each element of exp must not contain multiple terms.

markso

= 0 not to mark the special opeartors

sort

= 1 to sort the factors according to their names

debug

= 1 to print the intermediate result

Details

It is assumed that there is just one character in between % and %.
The i-th factor with the preceding operator of exp is substr( exp0, fromto[i,1], fromto[i,2] ) where exp0 is the blank compressed exp.
The prefix operator associated with the i-th factor is oper[i].

The original expression can be recovered as:

res <- find_factors( exp )
expr <- paste( mapply( paste, res$oper, res$factor, sep="" ), collapse="" )

or

expr <- paste( paste( res$oper, res$factor, sep="" ), collapse="" )


The unbalanced parens, if any, will be neglected.

The factors can be sorted according to their names as follows:

res <- find_factors("A*d/a/c", sort=1)
exps <- paste( paste( res$oper, res$factor, sep="" ), collapse="" )

res <- find_factors("A*c/(x+y)/d", sort=1)
exps <- paste( paste( res$oper, res$factor, sep="" ), collapse="" )

Value

A list consisting of # of factors (nfactors), a vector of operators (oper) , a vector of factors (factor), location of each term+oper (fromto) , and ok flag.

Examples

find_factors( "a*b/c*(d-e)*f(n)" )
find_factors( c("a*b/c*(d-e)*f(n)", "-2.13*a") )
find_factors( "a%*%b/c%*%(d-e)%*%f(n)" )
find_factors( "ab%*%cd*(b%p%q+a%m%c)/c*d/a%T%b" )
# error
find_factors( "a+b" )


[Package lazy.symbolic version 0.1.3 Index]