convert/boolean_function - Maple Programming Help

Home : Support : Online Help : Programming : Data Types : Conversion : convert/boolean_function

convert/boolean_function

convert boolean statements involving {and,or,xor,implies,not} into equivalent boolean functions using {And,Or,Not}

 Calling Sequence convert(expr, boolean_function) convert(expr, boolean_function, or, and, ...)

Parameters

 expr - Maple expression possibly containing boolean statements constructed using the operators and, or, xor, implies, not

Description

 • The convert(expr, boolean_function) command converts, in a given expression, all boolean statements constructed using the operators {and, or, xor, implies, not} into equivalent boolean function constructions using the functions {And, Or, Not}. If the given expression contains no such boolean operators, it is returned unchanged. To perform the opposite conversion, that is, from the functions {And, Or, Xor, Implies, Not} to the corresponding boolean operators {and, or, xor, implies, not}, see convert,boolean_operator.
 • To restrict the application of the conversion to boolean operators of only certain type, for instance only to and operators, give the name of these operators, surrounded by  after the keyword boolean_function - see the Examples.
 • The conversion of boolean statements constructed with operators into boolean statements constructed with functions is of use, among others things, for:
 - avoiding the automatic simplification which happens with boolean operators;
 - allowing the read of the boolean statement with the ordering of execution and precedence of the operations made explicit with parenthesis.

Examples

 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b$
 ${a}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{b}$ (1)
 > $\mathrm{convert}\left(,\mathrm{boolean_function}\right)$
 ${\mathrm{And}}{}\left({a}{,}{b}\right)$ (2)
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{or}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b$
 ${a}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{or}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{b}$ (3)
 > $\mathrm{convert}\left(,\mathrm{boolean_function}\right)$
 ${\mathrm{Or}}{}\left({a}{,}{b}\right)$ (4)
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{or}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}c$
 ${a}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{or}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{b}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{c}$ (5)
 > $\mathrm{convert}\left(,\mathrm{boolean_function}\right)$
 ${\mathrm{Or}}{}\left({a}{,}{\mathrm{And}}{}\left({b}{,}{c}\right)\right)$ (6)

To reverse these conversions use convert, boolean_operator

 > $\mathrm{convert}\left(,\mathrm{boolean_operator}\right)$
 ${a}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{or}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{b}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{c}$ (7)

To restrict the application of the conversion only to one (or some) type of boolean operators use for instance

 > $\mathrm{convert}\left(,\mathrm{boolean_function},\mathrm{and}\right)$
 ${a}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{or}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{And}}{}\left({b}{,}{c}\right)$ (8)
 > $\mathrm{convert}\left(,\mathrm{boolean_function},\mathrm{or}\right)$
 ${\mathrm{Or}}{}\left({a}{,}{b}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{c}\right)$ (9)

Note that, convert, boolean_function returns using only {And,Or,Not}, so statements using {xor, implies} will not result in statements with {Xor, Implies} in the output (even when convert, boolean_operator knows about them)

 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{xor}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b$
 ${a}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{xor}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{b}$ (10)
 > $\mathrm{convert}\left(,\mathrm{boolean_function}\right)$
 ${\mathrm{Or}}{}\left({\mathrm{And}}{}\left({a}{,}{\mathrm{Not}}{}\left({b}\right)\right){,}{\mathrm{And}}{}\left({\mathrm{Not}}{}\left({a}\right){,}{b}\right)\right)$ (11)
 > $a⇒b$
 ${a}{⇒}{b}$ (12)
 > $\mathrm{convert}\left(,\mathrm{boolean_function}\right)$
 ${\mathrm{Or}}{}\left({\mathrm{Not}}{}\left({a}\right){,}{b}\right)$ (13)

Boolean statements constructed with operators have some simplifications performed automatically.

 > $z\ne 0\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left(b-2a-2=0\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{or}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b-2a=0\right)$
 ${\mathrm{false}}$ (14)

The equivalent boolean function statement is not automatically simplified (quotes around the boolean operator statement are required).

 > $\mathrm{convert}\left('z\ne 0\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left(b-2a-2=0\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{or}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b-2a=0\right)',\mathrm{boolean_function}\right)$
 ${\mathrm{And}}{}\left({z}{\ne }{0}{,}{\mathrm{Or}}{}\left({b}{-}{2}{}{a}{-}{2}{=}{0}{,}{b}{-}{2}{}{a}{=}{0}\right)\right)$ (15)

The function representation above permits further manipulations of the boolean statement without having it simplified to 'false'.

The order and precedence of the operations becomes explicit:

 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{or}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}c\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}d\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{or}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}e$
 ${a}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{b}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{or}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{c}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{d}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{or}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{e}$ (16)
 > $\mathrm{convert}\left(,\mathrm{boolean_function}\right)$
 ${\mathrm{Or}}{}\left({\mathrm{And}}{}\left({a}{,}{b}\right){,}{\mathrm{And}}{}\left({c}{,}{d}\right){,}{e}\right)$ (17)
 > $a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{xor}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b⇒c\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}d$
 ${a}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{xor}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{b}{⇒}{c}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{d}$ (18)
 > $\mathrm{convert}\left(,\mathrm{boolean_function}\right)$
 ${\mathrm{Or}}{}\left({\mathrm{Not}}{}\left({\mathrm{Or}}{}\left({\mathrm{And}}{}\left({a}{,}{\mathrm{Not}}{}\left({b}\right)\right){,}{\mathrm{And}}{}\left({\mathrm{Not}}{}\left({a}\right){,}{b}\right)\right)\right){,}{\mathrm{And}}{}\left({c}{,}{d}\right)\right)$ (19)

To reverse this conversion use

 > $\mathrm{convert}\left(,\mathrm{boolean_operator}\right)$
 ${\mathbf{not}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left({a}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{not}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{b}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{or}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{not}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{a}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{b}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{or}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{c}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{d}$ (20)

For information on manipulating and simplifying these expressions, see the Logic package.