<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2007-2008 - INRIA
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="boolean">
    <refnamediv>
        <refname>boolean</refname>
        <refpurpose>Scilab Objects, boolean variables and operators &amp; | ~  </refpurpose>
    </refnamediv>
    <refsection>
        <title>Description</title>
        <para>
            A boolean variable is <constant>%T</constant> (for "true") or <constant>%F</constant> (for "false"). These variables can be used to define matrices of booleans, with the usual syntax. Boolean matrices can be manipulated as ordinary matrices for elements extraction/insertion and concatenation.
        </para>
        <para>
            <note>
                Note that other usual operations (<literal>+</literal>, <literal>*</literal>, <literal>-</literal>, <literal>^</literal>, etc) are undefined for boolean matrices. Three special operators are defined for boolean matrices:
            </note>
        </para>
        <variablelist>
            <varlistentry>
                <term>~b</term>
                <listitem>
                    <para>
                        is the element-wise negation of boolean <literal>b</literal> (matrix).
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>b1 &amp; b2</term>
                <listitem>
                    <para>
                        is the element-wise logical <literal>and</literal> of
                        <literal>b1</literal> and <literal>b2</literal>
                        (matrices).
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>b1 | b2</term>
                <listitem>
                    <para>
                        is the  element-wise logical
                        <literal>or</literal> of <literal>b1</literal>
                        and <literal>b2</literal> (matrices).
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
        <para>
            Boolean variables can be used for indexing matrices or vectors. For instance <code>a([%T,%F,%T],:)</code> returns the submatrix made of rows <literal>1</literal> and <literal>3</literal> of <literal>a</literal>. Boolean sparse matrices are supported.
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
[1,2]==[1,3]
[1,2]==1
a=1:5; a(a>2)
]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="matrices">matrices</link>
            </member>
            <member>
                <link linkend="or">or</link>
            </member>
            <member>
                <link linkend="and">and</link>
            </member>
            <member>
                <link linkend="not">not</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
