# Factorize Boolean expressions

## Description

This function finds all combinations of common factors in a Boolean expression written in SOP - Sum Of Products form.

## Usage

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

## Arguments

`expression` |  |  |  | A string containing the SOP 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 sets.
`...` |  |  |  | Other arguments (mainly for backwards compatibility).

## Details

Factorization is a process of finding common factors in a Boolean expression, written in a SOP - sum of products (or DNF - disjunctive normal form). Whenever possible, the factorization can also be performed in a POS - product of sums form.

Conjunctions should preferably be indicated with a star `*` sign, but this is not necessary when conditions have single letters or when the expression is expressed in multi-value notation.

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

If `input` is an object of class `"qca"` (the result of the `minimize()` function), a factorization is performed 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

    # typical example with redundant conditions
    factorize("AbcD + AbCd + AbCD + ABCd")

    M1: AbcD + AbCd + AbCD + ABCd

    F1: A(bcD + bCd + bCD + BCd)
    F2: Ab(cD + Cd + CD) + ABCd
    F3: AbcD + AC(bd + bD + Bd)
    F4: AbD + ACd
    F5: A(bcD + BCd) + AbC

    # 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("ac + aD + bc + bD", pos = TRUE)

    M1: ac + aD + bc + bD

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

    # using an object of class "qca" produced with minimize()
    data(CVF)
    pCVF <- minimize(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 negate()
    factorize(negate(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)

## Author

Adrian Dusa

## See also

`translate`