Professional > Interview scripting > Writing interview scripts > Logical expressions > Reversing the meaning of an expression
 
Reversing the meaning of an expression
The Not operator reverses the meaning of the expression that it precedes. When the expression starts with a simple question name you should enclose the expression in parentheses to ensure that the statement is evaluated correctly.
Not(expression)
For example:
Not (Gender = {Male})
means the same as:
Gender <> {Male}
and the expressions:
(Not Tried > {ProductA, ProductB})
Not Tried.ContainsAll({ProductA, ProductB}, false)
are both True if the answer to Tried does not contain Product A, Product B and at least one other response.
In the second example, notice that the first expression is enclosed in parentheses so that it is clear that the question name belongs with the product names. This is not necessary in the second expression because the question name is followed by a function name.
If the expression contains a number of subexpressions linked with And, Or, or Xor, Not refers only to the first subexpression. To reverse the meaning of more than one subexpression or a group of subexpressions either place Not in front of each subexpression or group the subexpressions using parentheses so that Not reverses the meaning of the parenthesized expression as a whole. Which method you use will depend on the purpose of the test. Take, for example, the expression:
Region = {North} And Age <= 24
This is True for people who live in the north and are aged 24 or younger. There are four ways of using Not in this expression: with Region, with Age, with Region and Age separately, and with Region and Age grouped inside parentheses. Each possibility generates a different result, so it is important that you are clear about which respondents you will be accepting and rejecting before your project goes live.
Not (Region = {North}) And Age <= 24
In this expression only the test for region is reversed. The expression is True for anyone who does not live in the north and who is younger than 25 years of age, and includes anyone who lives in the south, east, or west as long as they are of the right age. The expression is False for everyone who lives in the north regardless of their age, and for anyone aged 25 or older regardless of where they live.
Region = {North} And Not (Age <= 24)
In this expression only the test for age is reversed. The expression is True for anyone who lives in the north and who is not aged 24 or younger. It is False for anyone who lives in the south, east, or west regardless of their age, and for all northerners aged 24 or younger.
Not (Region = {North}) And Not (Age <= 24)
In this expression both tests are reversed separately. The region subexpression is True for anyone who does not live in the north; the age subexpression is True for anyone who is not aged 24 or younger. The And operator indicates that both subexpressions must be True, so the expression as a whole is True for people who do not live in the north and who are not under 25 years of age.
Not (Region = {North} And Age <= 24)
In this variation the two expressions are grouped and the meaning of the combined expression is reversed. The expression in parentheses is True for people who live in the north and are aged 24 or younger. It is False for people of any age who live in the south, east, or west, as well as for northerners aged 25 or older. Not switches this round so that the expression is False for people who live in the north and are aged 24 or younger, and True for people of any age who live in the south, east, or west, as well as for northerners aged 25 or older.
Here is a table that brings these results together for easy comparison:
 
North aged <=24
Elsewhere aged <=24
North aged >24
Elsewhere aged >24
region And age
True
False
False
False
Not region And age
False
True
False
False
region And Not age
False
False
True
False
Not region And Not age
False
False
False
True
Not (region And age)
False
True
True
True
Similar rules apply when the operator is Or or Xor, and when the expression contains more than two subexpressions.
See also
Logical expressions