# Negate Boolean expressions

## Usage

    deMorgan(expression, snames = "", noflevels, use.tilde = FALSE)

## Arguments

expression
  A string representing an expression written in SOP, 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.
use.tilde
  Logical, use tilde for negation with bivalent variables.

## Description

This function negates an boolean expression written in Disjunctive Normal Form.

## Details

In Boolean algebra, there are two transformation rules named after the British mathematician Augustus De Morgan. These rules state that:

1. The complement of the union of two sets is the intersection of their complements.

2. The complement of the intersection of two sets is the union of their complements.

In "normal" language, these would be written as:

1. `"not (A and B)" = "(not A) or (not B)"`

2. `"not (A or B)" = "(not A) and (not B)"`

Based on these two laws, any Boolean expression written in disjunctive normal form can be transformed into its negation.

It is also possible to negate all models and solutions from the result of a Boolean minimization from function `eqmcc()`. The resulting object, of class `"qca"`, is automatically recognised by this function (provided the minimization is Boolean).

The products should normally be split by using a star `*` sign, otherwise the sets' names will be considered the individual letters in alphabetical order, unless they are specified via `snames`.

To negate multilevel expressions, the arguent `noflevels` is required.

## Value

A list with the following two components:

initial
The initial expression.
negated
The negation of the initial expression.

If `x` is an object of type `"qca"`, the result is a list of solutions.

## References

Ragin, Charles C. 1987. The Comparative Method: Moving beyond Qualitative and Quantitative Strategies. Berkeley: University of California Press.

## Examples

    # example from Ragin (1987, p.99)
    deMorgan("AC + B~C")

    S1: AC + B~C
    N1: ~A*~B + ~A*C + ~B*~C

    # with different intersection operators
    deMorgan("AB*EF + ~CD*EF")

    S1: AB*EF + ~CD*EF
    N1: ~AB*CD + ~EF

    # using an object of class "qca" produced with eqmcc()
    data(LC)
    cLC <- eqmcc(LC, "SURV", include = "?")

    deMorgan(cLC)

    S1: DEV*STB
    N1: dev + stb

    # parsimonious solution
    pLC <- eqmcc(LC, "SURV", include = "?")

    deMorgan(pLC)

    S1: DEV*STB
    N1: dev + stb

## See also

`eqmcc`

## Author

Adrian Dusa