gen_random_expr {lazy.symbolic} | R Documentation |
Generate Random Expression
Description
Japanese help file: gen_random_expr_JPH
Usage
gen_random_expr(
natom = 2,
nparen = 0,
nparen2 = 0,
random = 0,
maxlena = 1,
maxlennum = 0,
oper = c("+", "-", "*"),
alpha = c(letters, LETTERS),
num = 1:2,
func = NULL,
pfunc = 0.2,
print = 0,
debug = 0
)
Arguments
natom |
# of atmic elements in an expression |
nparen |
# of parentheses in an expression |
nparen2 |
# of higher level parentheses in an expression |
random |
= 1 to randomize the roots of the atomic elements |
maxlena |
# of alphabets in the root |
maxlennum |
# of numerics in the root |
oper |
a vector consisting of the binary operators to be used |
alpha |
a vector of characters to be used as the root |
num |
a vector of the numbers to be postfixed when random=1 |
func |
a vector of the function names to be used |
pfunc |
probability for the functions to appear |
print |
= 1 to print the result |
debug |
= 1 to print intermediate results |
Details
This function generates a valid expression according to the specification given by the input parameters
Note that, the name of the function to be used cannot have the characters
specified by alpha argument.
For example, if alpha=LETTERS[1:5]
,
function names cannot contain LETTERS[1:5].
In this case, func="Diag"
is NG.
Value
an expression as a character vector of length one
Examples
set.seed(1701)
gen_random_expr( )
gen_random_expr( natom=9, random=1, nparen=3 )
set.seed(1701)
gen_random_expr( natom=9, random=0, nparen=3 )
set.seed(1701)
gen_random_expr( natom=9, random=0, nparen=3, nparen2=3 )
set.seed(1701)
expr <- gen_random_expr( natom=4, random=0, nparen=3, nparen2=1
, oper=c("%*%","+","-"), alpha=c("AX",LETTERS[-9])
, func=c("t","diag"), pfunc=.8 )
expre <- Expand(expr, all=1)
temp <- mat2sum(expre) |> print() |> sumDisplay()