modify_math_operators {lazy.symbolic}R Documentation

Modify Mathematical Operators for Symbolic Math

Description

Japanese help file: modify_math_operators_JPH

Usage

modify_math_operators(where = "parent", print = 1)

Arguments

where

The environment name. (parent or global)

print

= 0 to skip the message

Details

The following native mathematical operators will be modified so that they can handle symbolic objects.

 +     Addition
 -     Subtraction
 *     Scalar Multiplication
 /     Scalar Division
 %*%   Matrix Multiplication
 t   transposition

These operators will be available in the environment specified by where. The default is parent.frame(), the calling environment.

To remove these operators, submit the following code:
rm( '+', '-', '*', '%*%', '/' , t ) .

In addition, we have

%@%   Kronecker product

Examples

# in global environment
# remove all
rm(list=ls())

# Create symbolic matrices
A=demomat(3,2,root="a")
B=demomat(3,2,root="b")

# Below causes error.
# A+B

# Load modified operators
modify_math_operators()
ls()

# This works!
A+B

# Remove operators
rm(`+`, `-`, `*`, `%*%`,  `/`, t)


# In a function environment
func1 <- function(){
 printm("in function before call", ls())
 modify_math_operators()
 printm("in function after call", ls())
 printm(A+B)
}

printm("in the calling environment before call", ls())
func1()
printm("in the calling environment after", ls())



[Package lazy.symbolic version 1.0.0.20250316 ]