ReplaceOptim(query, value) is an optimization that replaces the
subexpressions matching query by value, as SymPy's ReplaceOptim.
sym_optimize(expr, optimizations) applies optimizations in order of
decreasing priority, keeping the cheaper expression when an
optimization has a cost function (SymPy's optimize()).
FuncMinusOneOptim(func, func_m_1) rewrites sums such as exp(x) - 1 as
expm1(x), and create_expand_pow_optimization(limit) writes small
integer powers as repeated products.
Usage
ReplaceOptim(query, value, cost_function = NULL, priority = 1)
sym_optimize(expr, optimizations)
exp2_opt(expr)
sinc_opt1(expr)
sinc_opt2(expr)
sinc_opts
log2_opt(expr)
log2const_opt(expr)
logsumexp_2terms_opt(expr)
FuncMinusOneOptim(func, func_m_1, opportunistic = TRUE)
expm1_opt(expr)
cosm1_opt(expr)
powm1_opt(expr)
log1p_opt(expr)
create_expand_pow_optimization(limit, base_req = NULL)
matinv_opt(expr)
logaddexp_opt(expr)
logaddexp2_opt(expr)
optims_c99
optims_numpy
optims_scipyArguments
- query
A pattern with wild symbols, the name of a function or node type, or an R predicate of a node.
- value
The replacement: an expression (using the wild symbols of a pattern), or an R function of the matched wild symbols (for a pattern), of the arguments (for a name) or of the node (for a predicate).
- cost_function
NULL, or an R function giving the cost of an expression.- priority
Optimizations of higher priority are applied first.
- expr
An expression.
- optimizations
A list of optimizations.
- func, func_m_1
R functions building
f(x)andf(x) - 1(such asexpandsym_expm1), or their names.- opportunistic
Whether to rewrite whenever the constant term gets smaller, rather than only when it cancels.
- limit
The largest exponent to expand.
- base_req
An R predicate on the base of a power; the default accepts symbols.
Details
The predefined optimizations are exp2_opt, sinc_opt1, sinc_opt2,
log2_opt, log2const_opt, logsumexp_2terms_opt, expm1_opt,
cosm1_opt, powm1_opt, log1p_opt, matinv_opt, logaddexp_opt and
logaddexp2_opt, with the collections sinc_opts, optims_c99,
optims_numpy and optims_scipy. matinv_opt rewrites
the product of Inverse(A) and a column x as MatrixSolve(A, x) when
the assumptions context holds Q$fullrank(A) for the matrix symbol A
(see assuming() and global_assumptions).