find_terms {lazy.symbolic}R Documentation

Decompose an Expression into Additive Terms separated by + or -

Description

Decompose an Expression into Additive Terms separated by + or -

Usage

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

Arguments

exp

An expression vector or matrix

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

The i-th term 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 term is oper[i].

The original expression can be recovered as:

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

or
expr <- paste( paste( res$oper, res$term, sep="" ), collapse="" )
The unbalanced parens, if any, will be neglected.

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

res <- find_terms("c-a+d-b", sort=1)
exps <- paste( paste( res$oper, res$factor, sep="" ), collapse="" )

Value

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

Examples

find_terms( "-((a)) - c + ((a)+(b)) + (a-b) + 1 - (x-y)*(((z+1)))" )
find_terms("-a")
find_terms("x*a/(1-y)")
find_terms("-a+b-0")
find_terms("(A%p%B)%*%C-D%*%diag(X) %m% E")
find_terms(Simplify("-a+b-0"))

find_terms("(((b)+c")
find_terms(")*c+5")



[Package lazy.symbolic version 0.1.3 Index]