reduce_sign_expr {lazy.symbolic} | R Documentation |
Simplify/Modify the Signs of an Expression
Description
Simplify/Modify the Signs of an Expression
Usage
reduce_sign_expr(expr, minus_as_sign = FALSE, expand = FALSE)
Arguments
expr |
an expression or a string |
minus_as_sign |
= TRUE to convert binary - to unary one |
expand |
= TRUE to remove parens |
Details
まず、++やなどを省略する。 minus_as_sign = TRUEなら、 A - B -> A + -Bにする。 make_minus_sign()代わり。 expand = TRUEなら、 A - (B -C ) -> A -B + Cにする。
@examples reduce_sign_expr("A-(B+C)") reduce_sign_expr("A-(B+C)", minus_as_sign=TRUE) reduce_sign_expr("A-(B+C)", minus_as_sign=TRUE, expand=TRUE) reduce_sign_expr("A-(B+C)", minus_as_sign=FALSE, expand=TRUE)
# Basic pattern c("A+B", "A-B", "-B", "+B", "A+(B+C)", "A+(B-C)", "A-(B+C)", "A-(B-C)", "+(B+C)", "+(B-C)", "-(B+C)", "-(B-C)", "++C", "+-C", "-+C", "C", "A++C", "A+-C", "A-+C", "AC") |> sapply(function(expr) list( nSE = reduce_sign_expr(expr), nSE_MS = reduce_sign_expr(expr, minus_as_sign=TRUE), nSE_EX = reduce_sign_expr(expr, expand=TRUE), nSE_MS_EX = reduce_sign_expr(expr, minus_as_sign=TRUE, expand=TRUE), rES = reduce_expr_sign(expr), mMS = make_minus_sign(expr) ) |> sapply(safe_deparse) ) |> t()
c("A+-++-+-+C", "A+(B+C)+(D-E)", "A-(B-C-(DE))", "A
"t(A-(B-C))-t(-A-C+B)"
) |> sapply(function(expr) list( nSE = reduce_sign_expr(expr), nSE_MS = reduce_sign_expr(expr, minus_as_sign=TRUE), nSE_EX = reduce_sign_expr(expr, expand=TRUE), nSE_MS_EX = reduce_sign_expr(expr, minus_as_sign=TRUE, expand=TRUE), rES = reduce_expr_sign(expr), mMS = make_minus_sign(expr) ) |> sapply(safe_deparse) ) |> t()
@return an expression
@export