What does the following expression evaluate to, given that a = 2 and b = 8?

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
Take them one at a time, and break them down into parts. Solve the parts one at a time, and combine them to get each answer.

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!

You should do your homework. If you would liste to your teacher or read your course note, it would not be that hard at least for some cases...

For case (i), you could you could distribute B || C to the rest of the equation and then you can simplify the equation as one part is included in the other.

Case (ii) is very trivial to solve.

Case (iii) is somewhat more difficult but you use rule like !X || !Y is equivalent to !(X && Y) a few times. Alternatively, you can draw a truth table, and find the solution.

A B C   !A   !C   (...)   C   !B   (...)   result
0 0 0    1    1     1     0    1     1        1
0 0 1    1    0     1     0    1     0        1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

Case (iv) has some trivial simplification...

You have to do other exercise all by yourself... So later cases seems to be incorrect either as code or mathematical expression. Also, for some of those cases, other information is required...

Add your solution here

 B   I   U   S  small BIG code var  <   >   &  link [^] encode untab case indent outdent

Preview 0

Existing Members

...or Join us

Download, Vote, Comment, Publish.

Your Email  

This email is in use. Do you need your password?

Optional Password  

When answering a question please:

  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

To evaluate an algebraic expression, you have to substitute a number for each variable and perform the arithmetic operations. In the example above, the variable x is equal to 6 since 6 + 6 = 12.

If we know the value of our variables, we can replace the variables with their values and then evaluate the expression.

There are two logical values in R, also called boolean values. They are TRUE and FALSE. In R you can construct logical expressions which will evaluate to either TRUE or FALSE.

Many of the questions in this lesson will involve evaluating logical expressions. It may be useful to open up a second R terminal where you can experiment with some of these expressions.

Creating logical expressions requires logical operators. You’re probably familiar with arithmetic operators like

6 == 7
3,
6 == 7
4,
6 == 7
5, and
6 == 7
6. The first logical operator we are going to discuss is the equality operator, represented by two equals signs
6 == 7
7. Use the equality operator below to find out if TRUE is equal to TRUE.
TRUE == TRUE
## [1] TRUE

Just like arithmetic, logical expressions can be grouped by parenthesis so that the entire expression (TRUE == TRUE) == TRUE evaluates to TRUE.

To test out this property, try evaluating (FALSE == TRUE) == FALSE .

(FALSE == TRUE) == FALSE
## [1] TRUE

The equality operator can also be used to compare numbers. Use

6 == 7
7 to see if 6 is equal to 7.
6 == 7
6 == 7
1

The previous expression evaluates to FALSE because 6 is less than 7. Thankfully, there are inequality operators that allow us to test if a value is less than or greater than another value.

The less than operator

6 == 7
9 tests whether the number on the left side of the operator (called the left operand) is less than the number on the right side of the operator (called the right operand). Write an expression to test whether 6 is less than 7.
6 == 7
3
## [1] TRUE

There is also a less-than-or-equal-to operator

6 == 7
10 which tests whether the left operand is less than or equal to the right operand. Write an expression to test whether 10 is less than or equal to 10.
6 == 7
6
## [1] TRUE

Keep in mind that there are the corresponding greater than

6 == 7
11 and greater-than-or-equal-to
6 == 7
12 operators.

Which of the following evaluates to FALSE?

9 >= 10

Which of the following evaluates to TRUE?

9 >= 10

The next operator we will discuss is the ‘not equals’ operator represented by

6 == 7
13. Not equals tests whether two values are unequal, so TRUE != FALSE evaluates to TRUE. Like the equality operator,
6 == 7
13 can also be used with numbers. Try writing an expression to see if 5 is not equal to 7.
## [1] TRUE
0
## [1] TRUE

In order to negate boolean expressions you can use the NOT operator. An exclamation point

6 == 7
15 will cause !TRUE (say: not true) to evaluate to FALSE and !FALSE (say: not false) to evaluate to TRUE. Try using the NOT operator and the equals operator to find the opposite of whether 5 is equal to 7.
## [1] TRUE
2
## [1] TRUE

Let’s take a moment to review. The equals operator

6 == 7
7 tests whether two boolean values or numbers are equal, the not equals operator
6 == 7
13 tests whether two boolean values or numbers are unequal, and the NOT operator
6 == 7
15 negates logical expressions so that TRUE expressions become FALSE and FALSE expressions become TRUE.

Which of the following evaluates to FALSE?

  1. !(0 >= -1)
  2. !FALSE
  3. 7 != 8
  4. 9 < 10

!(0 >= -1)

What do you think the following expression will evaluate to?: (TRUE != FALSE) == !(6 == 7)

  1. TRUE
  2. FALSE
  3. Can there be objective truth when programming?
  4. %>%

TRUE

At some point you may need to examine relationships between multiple logical expressions. This is where the AND operator and the OR operator come in.

Let’s look at how the AND operator works. There are two AND operators in R,

6 == 7
19 and
6 == 7
30. Both operators work similarly, if the right and left operands of AND are both TRUE the entire expression is TRUE, otherwise it is FALSE. For example, TRUE & TRUE evaluates to TRUE. Try typing FALSE & FALSE to how it is evaluated.
## [1] TRUE
4
6 == 7
1

You can use the

6 == 7
19 operator to evaluate AND across a vector. The
6 == 7
30 version of AND only evaluates the first member of a vector. Let’s test both for practice. Type the expression TRUE & c(TRUE, FALSE, FALSE).
## [1] TRUE
6
## [1] TRUE
7

What happens in this case is that the left operand

6 == 7
33 is recycled across every element in the vector of the right operand. This is the equivalent statement as c(TRUE, TRUE, TRUE) & c(TRUE, FALSE, FALSE).

Now we’ll type the same expression except we’ll use the

6 == 7
30 operator. Type the expression TRUE && c(TRUE, FALSE, FALSE).
## [1] TRUE
8
## [1] TRUE

In this case, the left operand is only evaluated with the first member of the right operand (the vector). The rest of the elements in the vector aren’t evaluated at all in this expression.

The OR operator follows a similar set of rules. The

6 == 7
35 version of OR evaluates OR across an entire vector, while the
6 == 7
36 version of OR only evaluates the first member of a vector.

An expression using the OR operator will evaluate to TRUE if the left operand or the right operand is TRUE. If both are TRUE, the expression will evaluate to TRUE, however if neither are TRUE, then the expression will be FALSE.

Let’s test out the vectorized version of the OR operator. Type the expression TRUE | c(TRUE, FALSE, FALSE).

(FALSE == TRUE) == FALSE
0
(FALSE == TRUE) == FALSE
1

Now let’s try out the non-vectorized version of the OR operator. Type the expression TRUE || c(TRUE, FALSE, FALSE).

(FALSE == TRUE) == FALSE
2
## [1] TRUE

Logical operators can be chained together just like arithmetic operators. The expressions:

6 == 7
37 or
6 == 7
38 are perfectly normal to see.

As you may recall, arithmetic has an order of operations and so do logical expressions. All AND operators are evaluated before OR operators. Let’s look at an example of an ambiguous case. Type: 5 > 8 || 6 != 8 && 4 > 3.9

(FALSE == TRUE) == FALSE
4
## [1] TRUE

Let’s walk through the order of operations in the above case. First the left and right operands of the AND operator are evaluated. 6 is not equal 8, 4 is greater than 3.9, therefore both operands are TRUE so the resulting expression

6 == 7
39 evaluates to TRUE. Then the left operand of the OR operator is evaluated: 5 is not greater than 8 so the entire expression is reduced to FALSE || TRUE. Since the right operand of this expression is TRUE the entire expression evaluates to TRUE.

Which one of the following expressions evaluates to TRUE?

  1. TRUE && FALSE || 9 >= 4 && 3 < 6
  2. TRUE && 62 < 62 && 44 >= 44
  3. 99.99 > 100 || 45 < 7.3 || 4 != 4.0
  4. FALSE || TRUE && FALSE

TRUE && FALSE || 9 >= 4 && 3 < 6

Which one of the following expressions evaluates to FALSE?

  1. FALSE && 6 >= 6 || 7 >= 8 || 50 <= 49.5
  2. FALSE || TRUE && 6 != 4 || 9 > 4
  3. !(8 > 4) || 5 == 5.0 && 7.8 >= 7.79
  4. 6 >= -9 && !(6 > 7) && !(!TRUE)

FALSE && 6 >= 6 || 7 >= 8 || 50 <= 49.5

Now that you’re familiar with R’s logical operators you can take advantage of a few functions that R provides for dealing with logical expressions.

The function isTRUE() takes one argument. If that argument evaluates to TRUE, the function will return TRUE. Otherwise, the function will return FALSE. Try using this function by typing: isTRUE(6 > 4)

(FALSE == TRUE) == FALSE
6
## [1] TRUE

Which of the following evaluates to TRUE?

  1. isTRUE(!TRUE)
  2. isTRUE(3)
  3. isTRUE(NA)
  4. !isTRUE(4 < 3)
  5. !isTRUE(8 != 5)

!isTRUE(4 < 3)

The function identical() will return TRUE if the two R objects passed to it as arguments are identical. Try out the identical() function by typing: identical(‘twins’, ‘twins’)

(FALSE == TRUE) == FALSE
8
## [1] TRUE

Which of the following evaluates to TRUE?

  1. identical(5 > 4, 3 < 3.1)
  2. identical(4, 3.1)
  3. identical(‘hello’, ‘Hello’)
  4. !identical(7, 7)

identical(5 > 4, 3 < 3.1)

You should also be aware of the xor() function, which takes two arguments. The xor() function stands for exclusive OR. If one argument evaluates to TRUE and one argument evaluates to FALSE, then this function will return TRUE, otherwise it will return FALSE. Try out the xor() function by typing: xor(5 == 6, !FALSE)

## [1] TRUE
0
## [1] TRUE

5 == 6 evaluates to FALSE, !FALSE evaluates to TRUE, so xor(FALSE, TRUE) evaluates to TRUE. On the other hand if the first argument was changed to 5 == 5 and the second argument was unchanged then both arguments would have been TRUE, so xor(TRUE, TRUE) would have evaluated to FALSE.

Which of the following evaluates to FALSE?

  1. xor(4 >= 9, 8 != 8.0)
  2. xor(!isTRUE(TRUE), 6 > -1)
  3. xor(identical(xor, ‘xor’), 7 == 7.0)
  4. xor(!!TRUE, !!FALSE)

xor(4 >= 9, 8 != 8.0)

For the next few questions, we’re going to need to create a vector of integers called ints. Create this vector by typing: ints <- sample(10)

## [1] TRUE
2

Now simply display the contents of ints.

## [1] TRUE
3
## [1] TRUE
4

The vector

## [1] TRUE
0 is a random sampling of integers from 1 to 10 without replacement. Let’s say we wanted to ask some logical questions about contents of ints. If we type ints > 5, we will get a logical vector corresponding to whether each element of ints is greater than 5. Try typing: ints > 5
## [1] TRUE
5
## [1] TRUE
6

We can use the resulting logical vector to ask other questions about ints. The which() function takes a logical vector as an argument and returns the indices of the vector that are TRUE. For example which(c(TRUE, FALSE, TRUE)) would return the vector c(1, 3).

Use the which() function to find the indices of ints that are greater than 7.

## [1] TRUE
7
## [1] TRUE
8

Which of the following commands would produce the indices of the elements in ints that are less than or equal to 2?

  1. ints < 2
  2. ints <= 2
  3. which(ints < 2)
  4. which(ints <= 2)

which(ints <= 2)

Like the which() function, the functions any() and all() take logical vectors as their argument. The any() function will return TRUE if one or more of the elements in the logical vector is TRUE. The all() function will return TRUE if every element in the logical vector is TRUE.

Use the any() function to see if any of the elements of ints are less than zero.

## [1] TRUE
9
6 == 7
1

Use the all() function to see if all of the elements of ints are greater than zero.

6 == 7
1
## [1] TRUE

Which of the following evaluates to TRUE?

  1. any(ints == 10)
  2. all(ints == 10)
  3. all(c(TRUE, FALSE, TRUE))
  4. any(ints == 2.5)

any(ints == 10)

That’s all for this introduction to logic in R. If you really want to see what you can do with logic, check out the control flow lesson!

Please submit the log of this lesson to Google Forms so that Simon (well, ok, Andrew) may evaluate your progress.

What is a evaluate in math example?

To calculate the value of. Example: Evaluate the cost of each pie when 3 pies cost $6. Answer: $2 each.

What is the value and the type of the result obtained by evaluating expression 13 4?

13/4 is 3 rather than 3.25. Since 13/4 is a single mode arithmetic expression and since all of its operands are of INTEGER type, the result must also be of INTEGER type. The computer will truncate the mathematical result (3.25) making it an integer. Therefore, the result is 3.

What does evaluate mean in math?

To determine or calculate the value of.

What is the value of the expression?

The value of the expression is the result of the calculation described by this expression when the variables and constants in it are assigned values. Letters can be used to represent numbers in an algebraic expression.