Learn R Programming

nlsr (version 2023.8.31)

newSimplification: newSimplification

Description

Define a new simplification expression

Usage

newSimplification(expr, test, simplification, do_eval = FALSE, 
                       simpEnv = sysSimplifications)

Value

If expr is missing, list all the functions with known simplifications.

If test is missing, list all the known simplifications for expr.

Otherwise, add the new simplification to the list of possible simplifications.

Arguments

expr

An expression to simplify.

test

An expression to evaluate whether the simplification should be applied to expr.

simplification

An equivalent but simpler version of the expression.

do_eval

Whether the simplification should be evaluated or stored as-is.

simpEnv

The environment in which the simplification is stored.

Examples

Run this code
# The unary + operation can always be safely removed:
newSimplification(+a, TRUE, a)

# The unary - operation can be absorbed into numeric values:
newSimplification(-a, is.numeric(a), -a, do_eval = TRUE)

# Adding zero to anything can be skipped:
newSimplification(a + b, isZERO(b), a)

Run the code above in your browser using DataLab