Learn R Programming

genscore (version 1.0.0)

get_postfix_rule: Changes a logical expression in infix notation to postfix notation using the shunting-yard algorithm.

Description

Changes a logical expression in infix notation to postfix notation using the shunting-yard algorithm.

Usage

get_postfix_rule(rule, num_eqs)

Arguments

rule

A string containing positive integers, parentheses, and "&" and "|" only. "&&" and "&" are not differentiated, and similarly for "||" and "|". Chained operations are only allowed for the same operation ("&" or "|"), so instead of "1 && 2 || 3" one should write either "(1 && 2) || 3" or "1 && (2 || 3)" to avoid ambiguity.

num_eqs

An integer, must be larger than or equal to the largest integer appearing in rule.

Value

rule in postfix notation.

Details

Applied to domain$rule if domain$type == "polynomial", and internally calls beautify_rule().

Examples

Run this code
# NOT RUN {
get_postfix_rule("1 & 2 && 3", 3)
get_postfix_rule("1 & (2 || 3)", 3)
get_postfix_rule("(1 & 2) || 3 | (4 & (5 || 6) && 7) | 8 | (9 && (10 || 11 | 12) & 13)", 13)
# }
# NOT RUN {
get_postfix_rule("1 && 2 & 3 && 4", 3) # Error, ineq number 4 appearing in \code{rule}.
# }
# NOT RUN {
# Error, ambigious rule. Change to either \code{"1 & (2 | 3)"} or \code{"(1 & 2) | 3"}.
get_postfix_rule("1 & 2 | 3", 3)
# }

Run the code above in your browser using DataLab