# Factorize Boolean expressions

## Usage

    factorize(expression, snames = "", noflevels, pos = FALSE, tilde, ...)

## Arguments

expression
  A string containing the DNF expression, or an object of class `"qca"`.
snames
  A string containing the sets' names, separated by commas.
noflevels
  Numerical vector containing the number of levels for each set.
pos
  Logical, if possible factorize using product(s) of sums.
tilde
  Logical, use a tilde to negate the expression.
...
  Other arguments (mainly for backwards compatibility).

## Description

This function finds all combinations of common factors in a Boolean expression written in DNF - disjunctive normal form.

## Details

Factorization is a process of finding common factors in a Boolean expression, written in DNF - disjunctive normal form, or in a sum of products (SOP) form. The factorization is also possible using products of sums (POS) form, whenever possible.

Starting with version 2.1 of the package, a number of arguments have been deprecated. For example, `prod.split`, because intersections (products) are indicated by the standard `*` sign, and sometimes products are not indicated by anything (for example when the set names are single letters.

The argument `snames` is only needed when products are not indicated by any sign at all, and the set names have more than one letter each (see function `translate()` for more details).

The number of levels in `noflevels` is needed only when negating multivalue conditions, and it should complement the `snames` argument.

If `expression` is an object of class `"qca"` (the result of the `eqmcc()` minimization function), this function performs a factorization for each of the minimized solutions.

## Value

A list with two components:

initial |  | The input expression.
factored |  | All possible factorizations of the input expression.

## References

Ragin, C.C. (1987) The Comparative Method. Moving beyond qualitative and quantitative strategies, Berkeley: University of California Press

## Examples

    # results presented in alphabetical order
    factorize("one*TWO*four + one*THREE + THREE*four")

    M1: one*TWO*four + one*THREE + THREE*four

    F1: four*(THREE + one*TWO) + one*THREE
    F2: four*THREE + one*(THREE + four*TWO)
    F3: four*one*TWO + THREE*(four + one)

    # to preserve a certain order of the set names
    factorize("one*TWO*four + one*THREE + THREE*four",
              snames = "ONE, TWO, THREE, FOUR")

    M1: one*TWO*four + one*THREE + THREE*four

    F1: one*(THREE + TWO*four) + THREE*four
    F2: one*TWO*four + THREE*(one + four)
    F3: four*(THREE + one*TWO) + one*THREE

    factorize("~ONE*TWO*~FOUR + ~ONE*THREE + THREE*~FOUR",
              snames = "ONE, TWO, THREE, FOUR")

    M1: ~ONE*TWO*~FOUR + ~ONE*THREE + THREE*~FOUR

    F1: ~ONE*(THREE + TWO*~FOUR) + THREE*~FOUR
    F2: ~ONE*TWO*~FOUR + THREE*(~ONE + ~FOUR)
    F3: ~FOUR*(THREE + ~ONE*TWO) + ~ONE*THREE

    # using pos - products of sums
    factorize("a*c + a*D + b*c + b*D", pos = TRUE)

    M1: a*c + a*D + b*c + b*D

    F1: (a + b)*(c + D)

    # using an object of class "qca" produced with eqmcc()
    data(CVF)
    pCVF <- eqmcc(CVF, outcome = "PROTEST", incl.cut = 0.8,
                  include = "?", use.letters = TRUE)

    factorize(pCVF)

    M1: e + ACD + ABC + aBD

    F1: AC(B + D) + e + aBD
    F2: B(AC + aD) + e + ACD
    F3: D(AC + aB) + e + ABC

    M2: e + ACD + ABC + BCD

    F1: AC(B + D) + e + BCD
    F2: BC(A + D) + e + ACD
    F3: C(AD + AB + BD) + e
    F4: CD(A + B) + e + ABC

    M3: e + ACD + aBD + ABd

    F1: A(CD + Bd) + e + aBD
    F2: B(aD + Ad) + e + ACD
    F3: D(AC + aB) + e + ABd

    M4: e + ACD + ABd + BCD

    F1: A(CD + Bd) + e + BCD
    F2: B(Ad + CD) + e + ACD
    F3: CD(A + B) + e + ABd

    # using an object of class "deMorgan" produced with deMorgan()
    factorize(deMorgan(pCVF))

    M1: abE + adE + bcE + AcE + cdE + bdE

    F01: E(ab + ad + bc + Ac + cd + bd)
    F02: aE(b + d) + E(bc + Ac + cd + bd)
    F03: aE(b + d) + bE(c + d) + cE(A + d)
    F04: aE(b + d) + bdE + cE(A + b + d)
    F05: aE(b + d) + cE(A + b) + dE(b + c)
    F06: bE(a + c + d) + E(ad + Ac + cd)
    F07: adE + bE(a + c + d) + cE(A + d)
    F08: AcE + bE(a + c + d) + dE(a + c)
    F09: cE(A + b + d) + E(ab + ad + bd)
    F10: adE + bE(a + d) + cE(A + b + d)
    F11: abE + cE(A + b + d) + dE(a + b)
    F12: dE(a + b + c) + E(ab + bc + Ac)
    F13: AcE + bE(a + c) + dE(a + b + c)
    F14: abE + cE(A + b) + dE(a + b + c)

    M2: abE + adE + cE + bdE

    F1: E(c + ab + ad + bd)
    F2: aE(b + d) + E(c + bd)
    F3: bE(a + d) + E(c + ad)
    F4: dE(a + b) + E(c + ab)

    M3: abE + adE + AcDE + bcE + bdE

    F01: E(ab + ad + AcD + bc + bd)
    F02: aE(b + d) + E(AcD + bc + bd)
    F03: AcDE + aE(b + d) + bE(c + d)
    F04: aE(b + d) + bdE + cE(b + AD)
    F05: bE(a + c + d) + E(ad + AcD)
    F06: cE(b + AD) + E(ab + ad + bd)
    F07: adE + bE(a + d) + cE(b + AD)
    F08: abE + cE(b + AD) + dE(a + b)
    F09: dE(a + b) + E(ab + AcD + bc)
    F10: AcDE + bE(a + c) + dE(a + b)

    M4: abE + acE + adE + bcE + cDE + bdE

    F01: E(ab + ac + ad + bc + cD + bd)
    F02: aE(b + c + d) + E(bc + cD + bd)
    F03: aE(b + c + d) + bE(c + d) + cDE
    F04: aE(b + c + d) + bdE + cE(b + D)
    F05: bE(a + c + d) + E(ac + ad + cD)
    F06: aE(c + d) + bE(a + c + d) + cDE
    F07: adE + bE(a + c + d) + cE(a + D)
    F08: cE(a + b + D) + E(ab + ad + bd)
    F09: aE(b + d) + bdE + cE(a + b + D)
    F10: adE + bE(a + d) + cE(a + b + D)
    F11: abE + cE(a + b + D) + dE(a + b)
    F12: dE(a + b) + E(ab + ac + bc + cD)
    F13: aE(b + c) + cE(b + D) + dE(a + b)
    F14: bE(a + c) + cE(a + D) + dE(a + b)

## See also

`translate`

## Author

Adrian Dusa