cnaOpt (version 0.1.0)

rreduce_ereduce: Eliminate redundancies from disjunctive normal forms (DNF)

Description

ereduce and rreduce implement different algorithmic approaches to eliminate redundancies from disjunctive normal forms (DNF), i.e. disjunctions of conjunctions of literals. If there are several minimal DNF, ereduce will return them all, while rreduce selects one at random.

Usage

ereduce(cond, x = full.tt(cond), full = !missing(x), simplify2constant = TRUE)
rreduce(cond, x = full.tt(cond), full = !missing(x), verbose = FALSE, maxiter = 1000)

Arguments

cond

A character string specifying a disjunctive normal form; can be either crisp-set or multi-value.

x

A truthTab or data.frame; can be either crisp-set or multi-value.

full

Logical; if TRUE (the default), redundancies are eliminated relative to full.tt(x), otherwise relative to x.

simplify2constant

Logical; if TRUE (the default), a tautologous or contradictory cond is reduced to a constant "1" or "0", respectively. If FALSE, a minimal tautology or contradiction, i.e. "A+a" or "A*a", will result.

verbose

Logical; if TRUE, the reduction process will be traced in the console.

maxiter

Maximal number of iterations.

Value

Redundancy-free disjunctive normal form (DNF).

Details

ereduce and rreduce eliminate conjuncts and disjuncts from a DNF cond as long as the consistency and coverage of cond in data x does not change, that is, as long as the result of condition(cond, x) remains the same. The only required argument is cond. If x is not provided, redundancies are eliminated relative to full.tt(cond). If x is provided and full = TRUE, redundancies are eliminated relative to full.tt(x). If x is provided and full = FALSE, redundancies are eliminated relative to x.

While ereduce generates all redundancy-free forms of cond, rreduce only returns one randomly chosen one. rreduce is faster than ereduce, but often incomplete. ereduce, in a nutshell, searches for minimal hitting sets in cond preventing cond from being false in data x.

See Also

full.tt, conCovOpt, DNFbuild.

Examples

Run this code
# NOT RUN {
# Logical redundancies.
cond1 <- "A*b + a*B + A*C + B*C"
ereduce(cond1)
rreduce(cond1)
cond2 <- "A*b + a*B + A*B + a*b"
ereduce(cond2)
ereduce(cond2, simplify2constant = FALSE)


# Redundancy elimination relative to simulated cs data.
dat1 <- data.frame(
  A = c(0, 0, 0, 0, 1, 1, 0, 1), 
  B = c(0, 1, 0, 1, 1, 0, 0, 0), 
  C = c(1, 1, 0, 1, 1, 0, 1, 1), 
  D = c(0, 0, 0, 0, 0, 1, 1, 1))
cco1 <- conCovOpt(dat1, "D")
best1 <- selectMax(cco1)
formula1 <- DNFbuild(best1, outcome = "D", reduce = FALSE)
# ereduce
ereduce(formula1, dat1, full = FALSE)
# rreduce
rreduce(formula1, dat1, full = FALSE)
rreduce(formula1, dat1, full = FALSE, verbose = TRUE)


# Redundancy elimination relative to simulated mv data.
dat2 <- data.frame(
  A = c(3,2,1,1,2,3,2,2,2,1,1,2,3,2,2,2,1,2,3,3,3,1,1,1,3,1,2,1,2,3,3,2,2,2,1,2,2,3,2,1,2,1,3,3),
  B = c(1,2,3,2,1,1,2,1,2,2,3,1,1,1,2,3,1,3,3,3,1,1,3,2,2,1,1,3,3,2,3,1,2,1,2,2,1,1,2,2,3,3,3,3),
  C = c(1,3,3,3,1,1,1,2,2,3,3,1,1,2,2,2,3,1,1,2,1,2,2,3,3,1,2,2,2,3,2,1,1,2,2,2,1,1,1,2,2,1,1,2),
  D = c(3,1,2,2,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,1,1,1,1,1,2,2,2,2,2,3,1,1,1,1,1,2,2,2,2,2,3,3,3),
  E = c(3,2,2,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3)
)
cco2 <- conCovOpt(dat2, "D=3", type="mv")
best2 <- selectMax(cco2)
formula2 <- DNFbuild(best2, outcome = "D=3", reduce = FALSE)
# ereduce
ereduce(formula2, mvtt(dat2), full = FALSE)
# rreduce
rreduce(formula2, mvtt(dat2), full = FALSE)


# Any Boolean expressions.
cond <- "!(A*B*C)*!(a*b*c)" # or "A + B*!(D + e) <-> C" 
x <- selectCases(cond) 
cond <- cna:::getCond(x) # Returns a DNF equivalent to cond, but with many redundancies.
ereduce(cond)
rreduce(cond)
# }

Run the code above in your browser using DataLab