Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 4183461[1X20 [33X[0;0YBooleans[133X[101X23[33X[0;0YThe two main [13Xboolean[113X values are [9Xtrue[109X and [9Xfalse[109X. They stand for the [13Xlogical[113X4values of the same name. They appear as values of the conditions in5[9Xif[109X-statements and [9Xwhile[109X-loops. Booleans are also important as return values6of [13Xfilters[113X (see [14X13.2[114X) such as [2XIsFinite[102X ([14X30.4-2[114X) and [2XIsBool[102X ([14X20.1-1[114X). Note7that it is a convention that the name of a function that returns [9Xtrue[109X or8[9Xfalse[109X according to the outcome, starts with [10XIs[110X.[133X910[33X[0;0YFor technical reasons, also the value [9Xfail[109X (see [14X20.2[114X) is regarded as a11boolean.[133X121314[1X20.1 [33X[0;0YIsBool (Filter)[133X[101X1516[1X20.1-1 IsBool[101X1718[33X[1;0Y[29X[2XIsBool[102X( [3Xobj[103X ) [32X Category[133X1920[33X[0;0Ytests whether [3Xobj[103X is [9Xtrue[109X, [9Xfalse[109X or [9Xfail[109X.[133X2122[4X[32X Example [32X[104X23[4X[25Xgap>[125X [27XIsBool( true ); IsBool( false ); IsBool( 17 );[127X[104X24[4X[28Xtrue[128X[104X25[4X[28Xtrue[128X[104X26[4X[28Xfalse[128X[104X27[4X[32X[104X282930[1X20.2 [33X[0;0YFail (Variable)[133X[101X3132[1X20.2-1 fail[101X3334[33X[1;0Y[29X[2Xfail[102X[32X global variable[133X3536[33X[0;0YThe value [9Xfail[109X is used to indicate situations when an operation could not be37performed for the given arguments, either because of shortcomings of the38arguments or because of restrictions in the implementation or computability.39So for example [2XPosition[102X ([14X21.16-1[114X) will return [9Xfail[109X if the point searched for40is not in the list.[133X4142[33X[0;0Y[9Xfail[109X is simply an object that is different from every other object than43itself.[133X4445[33X[0;0YFor technical reasons, [9Xfail[109X is a boolean value. But note that [9Xfail[109X cannot be46used to form boolean expressions with [9Xand[109X, [9Xor[109X, and [9Xnot[109X (see [14X20.4[114X below), and47[9Xfail[109X cannot appear in boolean lists (see Chapter [14X22[114X).[133X484950[1X20.3 [33X[0;0YComparisons of Booleans[133X[101X515253[1X20.3-1 [33X[0;0YEquality and inequality of Booleans[133X[101X5455[33X[0;0Y[10X[3Xbool1[103X[10X = [3Xbool2[103X[10X[110X[133X5657[33X[0;0Y[10X[3Xbool1[103X[10X <> [3Xbool2[103X[10X[110X[133X5859[33X[0;0YThe equality operator [10X=[110X evaluates to [9Xtrue[109X if the two boolean values [3Xbool1[103X60and [3Xbool2[103X are equal, i.e., both are [9Xtrue[109X or both are [9Xfalse[109X or both [9Xfail[109X, and61[9Xfalse[109X otherwise. The inequality operator [10X<>[110X evaluates to [9Xtrue[109X if the two62boolean values [3Xbool1[103X, [3Xbool2[103X are different, and [9Xfalse[109X otherwise. This63operation is also called the [13Xexclusive or[113X, because its value is [9Xtrue[109X if64exactly one of [3Xbool1[103X or [3Xbool2[103X is [9Xtrue[109X.[133X6566[33X[0;0YYou can compare boolean values with objects of other types. Of course they67are never equal.[133X6869[4X[32X Example [32X[104X70[4X[25Xgap>[125X [27Xtrue = false;[127X[104X71[4X[28Xfalse[128X[104X72[4X[25Xgap>[125X [27Xfalse = (true = fail);[127X[104X73[4X[28Xtrue[128X[104X74[4X[25Xgap>[125X [27Xtrue <> 17;[127X[104X75[4X[28Xtrue[128X[104X76[4X[32X[104X777879[1X20.3-2 [33X[0;0YOrdering of Booleans[133X[101X8081[33X[0;0Y[3Xbool1[103X [10X<[110X [3Xbool2[103X[133X8283[33X[0;0YThe ordering of boolean values is defined by [9Xtrue[109X [10X<[110X [9Xfalse[109X [10X<[110X [9Xfail[109X. For the84comparison of booleans with other [5XGAP[105X objects, see Section [14X4.12[114X.[133X8586[4X[32X Example [32X[104X87[4X[25Xgap>[125X [27Xtrue < false; fail >= false;[127X[104X88[4X[28Xtrue[128X[104X89[4X[28Xtrue[128X[104X90[4X[32X[104X919293[1X20.4 [33X[0;0YOperations for Booleans[133X[101X9495[33X[0;0YThe following boolean operations are only applicable to [9Xtrue[109X and [9Xfalse[109X.[133X969798[1X20.4-1 [33X[0;0YLogical disjunction[133X[101X99100[33X[0;0Y[3Xbool1[103X [9Xor[109X [3Xbool2[103X[133X101102[33X[0;0YThe logical operator [9Xor[109X evaluates to [9Xtrue[109X if at least one of the two boolean103operands [3Xbool1[103X and [3Xbool2[103X is [9Xtrue[109X, and to [9Xfalse[109X otherwise.[133X104105[33X[0;0Y[9Xor[109X first evaluates [3Xbool1[103X. If the value is neither [9Xtrue[109X nor [9Xfalse[109X an error is106signalled. If the value is [9Xtrue[109X, then [9Xor[109X returns [9Xtrue[109X [13Xwithout[113X evaluating107[3Xbool2[103X. If the value is [9Xfalse[109X, then [9Xor[109X evaluates [3Xbool2[103X. Again, if the value108is neither [9Xtrue[109X nor [9Xfalse[109X an error is signalled. Otherwise [9Xor[109X returns the109value of [3Xbool2[103X. This [13Xshort-circuited[113X evaluation is important if the value of110[3Xbool1[103X is [9Xtrue[109X and evaluation of [3Xbool2[103X would take much time or cause an111error.[133X112113[33X[0;0Y[9Xor[109X is associative, i.e., it is allowed to write [3Xb1[103X [9Xor[109X [3Xb2[103X [9Xor[109X [3Xb3[103X, which is114interpreted as ([3Xb1[103X [9Xor[109X [3Xb2[103X) [9Xor[109X [3Xb3[103X. [9Xor[109X has the lowest precedence of the logical115operators. All logical operators have lower precedence than the comparison116operators [10X=[110X, [10X<[110X, [9Xin[109X, etc.[133X117118[4X[32X Example [32X[104X119[4X[25Xgap>[125X [27Xtrue or false;[127X[104X120[4X[28Xtrue[128X[104X121[4X[25Xgap>[125X [27Xfalse or false;[127X[104X122[4X[28Xfalse[128X[104X123[4X[25Xgap>[125X [27Xi := -1;; l := [1,2,3];;[127X[104X124[4X[25Xgap>[125X [27Xif i <= 0 or l[i] = false then # this does not cause an error,[127X[104X125[4X[25X>[125X [27X Print("aha\n"); fi; # because `l[i]' is not evaluated[127X[104X126[4X[28Xaha[128X[104X127[4X[32X[104X128129130[1X20.4-2 [33X[0;0YLogical conjunction[133X[101X131132[33X[0;0Y[3Xbool1[103X [9Xand[109X [3Xbool2[103X[133X133134[33X[0;0Y[3Xfil1[103X [9Xand[109X [3Xfil2[103X[133X135136[33X[0;0YThe logical operator [9Xand[109X evaluates to [9Xtrue[109X if both boolean operands [3Xbool1[103X,137[3Xbool2[103X are [9Xtrue[109X, and to [9Xfalse[109X otherwise.[133X138139[33X[0;0Y[9Xand[109X first evaluates [3Xbool1[103X. If the value is neither [9Xtrue[109X nor [9Xfalse[109X an error140is signalled. If the value is [9Xfalse[109X, then [9Xand[109X returns [9Xfalse[109X [13Xwithout[113X141evaluating [3Xbool2[103X. If the value is [9Xtrue[109X, then [9Xand[109X evaluates [3Xbool2[103X. Again, if142the value is neither [9Xtrue[109X nor [9Xfalse[109X an error is signalled. Otherwise [9Xand[109X143returns the value of [3Xbool2[103X. This [13Xshort-circuited[113X evaluation is important if144the value of [3Xbool1[103X is [9Xfalse[109X and evaluation of [3Xbool2[103X would take much time or145cause an error.[133X146147[33X[0;0Y[9Xand[109X is associative, i.e., it is allowed to write [3Xb1[103X [9Xand[109X [3Xb2[103X [9Xand[109X [3Xb3[103X, which is148interpreted as ([3Xb1[103X [9Xand[109X [3Xb2[103X) [9Xand[109X [3Xb3[103X. [9Xand[109X has higher precedence than the149logical [9Xor[109X operator, but lower than the unary logical [9Xnot[109X operator. All150logical operators have lower precedence than the comparison operators [10X=[110X, [10X<[110X,151[9Xin[109X, etc.[133X152153[4X[32X Example [32X[104X154[4X[25Xgap>[125X [27Xtrue and false;[127X[104X155[4X[28Xfalse[128X[104X156[4X[25Xgap>[125X [27Xtrue and true;[127X[104X157[4X[28Xtrue[128X[104X158[4X[25Xgap>[125X [27Xfalse and 17; # does not cause error, because 17 is never looked at[127X[104X159[4X[28Xfalse[128X[104X160[4X[32X[104X161162[33X[0;0Y[9Xand[109X can also be applied to filters. It returns a filter that when applied to163some argument [3Xx[103X, tests [3Xfil1[103X[22X(x)[122X [9Xand[109X [3Xfil2[103X[22X(x)[122X.[133X164165[4X[32X Example [32X[104X166[4X[25Xgap>[125X [27Xandfilt:= IsPosRat and IsInt;;[127X[104X167[4X[25Xgap>[125X [27Xandfilt( 17 ); andfilt( 1/2 );[127X[104X168[4X[28Xtrue[128X[104X169[4X[28Xfalse[128X[104X170[4X[32X[104X171172173[1X20.4-3 [33X[0;0YLogical negation[133X[101X174175[33X[0;0Y[9Xnot[109X [3Xbool[103X[133X176177[33X[0;0YThe logical operator [9Xnot[109X returns [9Xtrue[109X if the boolean value [3Xbool[103X is [9Xfalse[109X,178and [9Xtrue[109X otherwise. An error is signalled if [3Xbool[103X does not evaluate to [9Xtrue[109X179or [9Xfalse[109X.[133X180181[33X[0;0Y[9Xnot[109X has higher precedence than the other logical operators, [9Xor[109X and [9Xand[109X. All182logical operators have lower precedence than the comparison operators [10X=[110X, [10X<[110X,183[9Xin[109X, etc.[133X184185[4X[32X Example [32X[104X186[4X[25Xgap>[125X [27Xtrue and false;[127X[104X187[4X[28Xfalse[128X[104X188[4X[25Xgap>[125X [27Xnot true;[127X[104X189[4X[28Xfalse[128X[104X190[4X[25Xgap>[125X [27Xnot false;[127X[104X191[4X[28Xtrue[128X[104X192[4X[32X[104X193194195196