http://www.categories.acsl.org/wiki/api.php?action=feedcontributions&user=Jerry&feedformat=atomACSL Category Descriptions - User contributions [en]2024-03-29T10:34:37ZUser contributionsMediaWiki 1.37.1http://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&diff=882Bit-String Flicking2024-01-30T16:51:08Z<p>Jerry: </p>
<hr />
<div><br />
Bit strings (strings of binary digits) are frequently manipulated bit-by-bit using the logical operators '''NOT''', '''AND''', '''OR''', and '''XOR'''. Bits strings are manipulated as a unit using '''SHIFT''' and '''CIRCULATE''' operators. The bits on the left are called the ''most significant bits'' and those on the right are the ''least significant bits''.<br />
<br />
Most high-level languages (e.g., Python, Java, C++), support bit-string operations. Programmers typically use bit strings to maintain a set of flags. Suppose that a program supports 8 options, each of which can be either “on” or “off”. One could maintain this information using an array of size 8, or one could use a single variable (if it is internally stored using at least 8 bits or 1 byte, which is usually the case) and represent each option with a single bit. In addition to saving space, the program is often cleaner if a single variable is involved rather than an array. Bits strings are often used to maintain a set where values are either in the set or not. Shifting of bits is also used to multiply or divide by powers of 2.<br />
<br />
Mastering this topic is essential for systems programming, programming in assembly language, optimizing code, and hardware design.<br />
<br />
== Operators==<br />
<br />
=== Bitwise Operators ===<br />
<br />
The logical operators are '''NOT''' (~ or $\neg$), '''AND''' (&), '''OR''' (|), and '''XOR''' ($\oplus$). These operators should be familiar to ACSL students from the [[Boolean Algebra]] and [[Digital Electronics]] categories.<br />
<br />
* '''NOT''' is a unary operator that performs logical negation on each bit. Bits that are 0 become 1, and those that are 1 become 0. For example: ~101110 has a value of 010001.<br />
<br />
* '''AND''' is a binary operator that performs the logical '''AND''' of each bit in each of its operands. The '''AND''' of two values is 1 only if both values are 1. For example, '''1011011 and 0011001''' has a value of '''0011001'''. The '''AND''' function is often used to isolate the value of a bit in a bit-string or to clear the value of a bit in a bit-string.<br />
<br />
* '''OR''' is a binary operator that performs the logical '''OR''' of each bit in each of its operands. The '''OR''' of two values is 1 only if one or both values are 1. For example, '''1011011 or 0011001''' has a value of '''1011011'''. The '''OR''' function is often use to force the value of a bit in a bit-string to be 1, if it isn't already.<br />
<br />
* '''XOR''' is a binary operator that performs the logical '''XOR''' of each bit in each of its operands. The '''XOR''' of two values is 1 if the values are different and 0 if they are the same. For example, '''1011011 xor 011001 = 110010'''. The '''XOR''' function is often used to change the value of a particular bit.<br />
<br />
All binary operators (AND, OR, or XOR) must operate on bit-strings that are of the same length. If the operands are not the same length, the shorter one is padded with 0's on the left as needed. For example, '''11010 and 1110''' would have value of '''11010 and 01110 = 01010'''.<br />
<br />
The following table summarizes the operators:<br />
<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
! '''not''' <math>x</math><br />
!<math>x</math> '''and''' <math>y</math><br />
!<math>x</math> '''or''' <math>y</math><br />
!<math>x</math> '''xor''' <math>y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
| 0 <br />
| 0 <br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
| 0 <br />
| 1 <br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
| 0 <br />
| 1 <br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0 <br />
| 1 <br />
| 1 <br />
| 0<br />
|}<br />
<br />
=== Shift Operators ===<br />
<br />
Logical shifts (LSHIFT-x and RSHIFT-x) “ripple” the bit-string x positions in the indicated direction, either to the left or to the right. Bits shifted out are lost; zeros are shifted in at the other end. <br />
<br />
Circulates (RCIRC-x and LCIRC-x) “ripple” the bit string x positions in the indicated direction. As each bit is shifted out one end, it is shifted in at the other end. The effect of this is that the bits remain in the same order on the other side of the string.<br />
<br />
The size of a bit-string does not change with shifts, or circulates. If any bit strings are initially of different lengths, all shorter ones are padded with zeros in the left bits until all strings are of the same length. <br />
<br />
The following table gives some examples of these operations:<br />
<br />
::{| class="wikitable" style="text-align: right"<br />
|-<br />
!x<br />
!(LSHIFT-2 x)<br />
!(RSHIFT-3 x)<br />
!(LCIRC-3 x)<br />
!(RCIRC-1 x)<br />
|-<br />
!01101<br />
| 10100<br />
| 00001<br />
| 01011<br />
| 10110<br />
|-<br />
!10<br />
| 00<br />
| 00<br />
| 01<br />
| 01<br />
|-<br />
!1110<br />
| 1000<br />
| 0001<br />
| 0111<br />
| 0111<br />
|-<br />
!1011011<br />
| 1101100<br />
| 0001011<br />
| 1011101<br />
| 1101101<br />
|}<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of precedence (from highest to lowest) is: NOT; SHIFT and CIRC; AND; XOR; and finally, OR. In other words, all unary operators are performed on a single operator first. Operators with equal precedence are evaluated left to right; all unary operators bind from right to left.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
Evaluate the following expression: <br />
:(101110 AND NOT 110110 OR (LSHIFT-3 101010))<br />
<br />
'''Solution:'''<br />
The expression evaluates as follows:<br />
:(101110 AND '''001001''' OR (LSHIFT-3 101010))<br />
:('''001000''' OR (LSHIFT-3 101010))<br />
:(001000 OR '''010000''')<br />
:'''011000'''<br />
<br />
=== Problem 2 ===<br />
<br />
Evaluate the following expression: <br />
:(RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) <br />
<br />
'''Solution:'''<br />
The expression evaluates as follows, starting at the innermost parentheses:<br />
:(RCIRC-2 01101) => 01011<br />
:(LCIRC-4 01011) => 10101<br />
:(RSHIFT-1 10101) = 01010<br />
<br />
=== Problem 3 ===<br />
<br />
List all possible values of x (5 bits long) that solve the following equation.<br />
:(LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100<br />
<br />
'''Solution:'''<br />
Since x is a string 5 bits long, represent it by abcde.<br />
:(RCIRC-3 abcde) => cdeab<br />
:(cdeab AND 11011) => cd0ab<br />
:(10110 XOR cd0ab) => Cd1Ab (the capital letter is the NOT of its lower case)<br />
:(LSHIFT-1 Cd1Ab) => d1Ab0<br />
<br />
So, d1Ab0 = 01100.<br />
<br />
Meaning, we must have d=0, A=1 (hence a=0), b=0. Thus, the solution must be in the form 00*0*, where * is an “I-don’t-care”. <br />
<br />
The four possible values of x are: 00000, 00001, 00100 and 00101.<br />
<br />
=== Problem 4 ===<br />
<br />
Evaluate the following expression:<br />
: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) & (RSHIFT-2 10111))<br />
<br />
'''Solution:'''<br />
The problem can be rewritten as <br />
: A | B & C<br />
The AND has higher precedence than the OR. <br />
<br />
The evaluation of expression A can be done in a straightforward way: (LCIRC-23 01101) is the same as (LCIRC-3 01101) which has a value of 01011, and (RCIRC-14 01011) is the same as (RCIRC-4 01011) which has a value of 10110. Another strategy is to offset the left and right circulates. So, ((RCIRC-14 (LCIRC-23 01101)) has the same value as (LCIRC-9 01101), which has the same value as (LCIRC-4 01101) which is also 11010.<br />
<br />
Expressions B and C are pretty easy to evaluate:<br />
:B = (LSHIFT-1 10011) = 00110<br />
:C = (RSHIFT-2 10111) = 00101<br />
<br />
The expression becomes<br />
: A | B & C = 10110 | 00110 & 00101 = 10110 | 00100 = 10110<br />
<br />
== Video Resources ==<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/0U6ogoQ5Hkk</youtube><br />
| [https://youtu.be/0U6ogoQ5Hkk "ACSL Math: Bit String Flicking" (Quick Coding Bytes)]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/IeMsD3harrE</youtube><br />
| [https://youtu.be/IeMsD3harrE ''Bit String Flicking (Intro)'' ('''CalculusNguyenify''')]<br />
<br />
A great two-part tutorial on this ACSL category. Part 1 covers bitwise operations AND, OR, NOT, and XOR. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jbKw8oYJPs4</youtube><br />
| [https://youtu.be/jbKw8oYJPs4 ''Bit String Flicking Shifts and Circs'' ('''CalculusNguyenify''')]<br />
<br />
Part 2 covers logical shifts and circulate operations.<br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/XNBcO25mgCw</youtube><br />
| [https://youtu.be/XNBcO25mgCw ''Bit String Flicking'' ('''Tangerine Code''')]<br />
<br />
Shows the solution to the problem: (RSHIFT-3 (LCIRC-2 (NOT 10110)))<br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aa_lQ8gft60</youtube><br />
| [https://youtu.be/aa_lQ8gft60 ''ACSL BitString Flicking Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Solves a handful of problems given in previous years at the Intermediate Division level.<br />
<br />
|}<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&diff=881Bit-String Flicking2024-01-30T16:48:30Z<p>Jerry: </p>
<hr />
<div><br />
Bit strings (strings of binary digits) are frequently manipulated bit-by-bit using the logical operators '''NOT''', '''AND''', '''OR''', and '''XOR'''. Bits strings are manipulated as a unit using '''SHIFT''' and '''CIRCULATE''' operators. The bits on the left are called the ''most significant bits'' and those on the right are the ''least significant bits''.<br />
<br />
Most high-level languages (e.g., Python, Java, C++), support bit-string operations. Programmers typically use bit strings to maintain a set of flags. Suppose that a program supports 8 options, each of which can be either “on” or “off”. One could maintain this information using an array of size 8, or one could use a single variable (if it is internally stored using at least 8 bits or 1 byte, which is usually the case) and represent each option with a single bit. In addition to saving space, the program is often cleaner if a single variable is involved rather than an array. Bits strings are often used to maintain a set where values are either in the set or not. Shifting of bits is also used to multiply or divide by powers of 2.<br />
<br />
Mastering this topic is essential for systems programming, programming in assembly language, optimizing code, and hardware design.<br />
<br />
== Operators==<br />
<br />
=== Bitwise Operators ===<br />
<br />
The logical operators are '''NOT''' (~ or $\neg$), '''AND''' (&), '''OR''' (|), and '''XOR''' ($\oplus$). These operators should be familiar to ACSL students from the [[Boolean Algebra]] and [[Digital Electronics]] categories.<br />
<br />
* '''NOT''' is a unary operator that performs logical negation on each bit. Bits that are 0 become 1, and those that are 1 become 0. For example: ~101110 has a value of 010001.<br />
<br />
* '''AND''' is a binary operator that performs the logical '''AND''' of each bit in each of its operands. The '''AND''' of two values is 1 only if both values are 1. For example, '''1011011 and 0011001''' has a value of '''1011011'''. The '''AND''' function is often used to isolate the value of a bit in a bit-string or to clear the value of a bit in a bit-string.<br />
<br />
* '''OR''' is a binary operator that performs the logical '''OR''' of each bit in each of its operands. The '''OR''' of two values is 1 only if one or both values are 1. For example, '''1011011 or 0011001''' has a value of '''1011011'''. The '''OR''' function is often use to force the value of a bit in a bit-string to be 1, if it isn't already.<br />
<br />
* '''XOR''' is a binary operator that performs the logical '''XOR''' of each bit in each of its operands. The '''XOR''' of two values is 1 if the values are different and 0 if they are the same. For example, '''1011011 xor 011001 = 110010'''. The '''XOR''' function is often used to change the value of a particular bit.<br />
<br />
All binary operators (AND, OR, or XOR) must operate on bit-strings that are of the same length. If the operands are not the same length, the shorter one is padded with 0's on the left as needed. For example, '''11010 and 1110''' would have value of '''11010 and 01110 = 01010'''.<br />
<br />
The following table summarizes the operators:<br />
<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
! '''not''' <math>x</math><br />
!<math>x</math> '''and''' <math>y</math><br />
!<math>x</math> '''or''' <math>y</math><br />
!<math>x</math> '''xor''' <math>y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
| 0 <br />
| 0 <br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
| 0 <br />
| 1 <br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
| 0 <br />
| 1 <br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0 <br />
| 1 <br />
| 1 <br />
| 0<br />
|}<br />
<br />
=== Shift Operators ===<br />
<br />
Logical shifts (LSHIFT-x and RSHIFT-x) “ripple” the bit-string x positions in the indicated direction, either to the left or to the right. Bits shifted out are lost; zeros are shifted in at the other end. <br />
<br />
Circulates (RCIRC-x and LCIRC-x) “ripple” the bit string x positions in the indicated direction. As each bit is shifted out one end, it is shifted in at the other end. The effect of this is that the bits remain in the same order on the other side of the string.<br />
<br />
The size of a bit-string does not change with shifts, or circulates. If any bit strings are initially of different lengths, all shorter ones are padded with zeros in the left bits until all strings are of the same length. <br />
<br />
The following table gives some examples of these operations:<br />
<br />
::{| class="wikitable" style="text-align: right"<br />
|-<br />
!x<br />
!(LSHIFT-2 x)<br />
!(RSHIFT-3 x)<br />
!(LCIRC-3 x)<br />
!(RCIRC-1 x)<br />
|-<br />
!01101<br />
| 10100<br />
| 00001<br />
| 01011<br />
| 10110<br />
|-<br />
!10<br />
| 00<br />
| 00<br />
| 01<br />
| 01<br />
|-<br />
!1110<br />
| 1000<br />
| 0001<br />
| 0111<br />
| 0111<br />
|-<br />
!1011011<br />
| 1101100<br />
| 0001011<br />
| 1011101<br />
| 1101101<br />
|}<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of precedence (from highest to lowest) is: NOT; SHIFT and CIRC; AND; XOR; and finally, OR. In other words, all unary operators are performed on a single operator first. Operators with equal precedence are evaluated left to right; all unary operators bind from right to left.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
Evaluate the following expression: <br />
:(101110 AND NOT 110110 OR (LSHIFT-3 101010))<br />
<br />
'''Solution:'''<br />
The expression evaluates as follows:<br />
:(101110 AND '''001001''' OR (LSHIFT-3 101010))<br />
:('''001000''' OR (LSHIFT-3 101010))<br />
:(001000 OR '''010000''')<br />
:'''011000'''<br />
<br />
=== Problem 2 ===<br />
<br />
Evaluate the following expression: <br />
:(RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) <br />
<br />
'''Solution:'''<br />
The expression evaluates as follows, starting at the innermost parentheses:<br />
:(RCIRC-2 01101) => 01011<br />
:(LCIRC-4 01011) => 10101<br />
:(RSHIFT-1 10101) = 01010<br />
<br />
=== Problem 3 ===<br />
<br />
List all possible values of x (5 bits long) that solve the following equation.<br />
:(LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100<br />
<br />
'''Solution:'''<br />
Since x is a string 5 bits long, represent it by abcde.<br />
:(RCIRC-3 abcde) => cdeab<br />
:(cdeab AND 11011) => cd0ab<br />
:(10110 XOR cd0ab) => Cd1Ab (the capital letter is the NOT of its lower case)<br />
:(LSHIFT-1 Cd1Ab) => d1Ab0<br />
<br />
So, d1Ab0 = 01100.<br />
<br />
Meaning, we must have d=0, A=1 (hence a=0), b=0. Thus, the solution must be in the form 00*0*, where * is an “I-don’t-care”. <br />
<br />
The four possible values of x are: 00000, 00001, 00100 and 00101.<br />
<br />
=== Problem 4 ===<br />
<br />
Evaluate the following expression:<br />
: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) & (RSHIFT-2 10111))<br />
<br />
'''Solution:'''<br />
The problem can be rewritten as <br />
: A | B & C<br />
The AND has higher precedence than the OR. <br />
<br />
The evaluation of expression A can be done in a straightforward way: (LCIRC-23 01101) is the same as (LCIRC-3 01101) which has a value of 01011, and (RCIRC-14 01011) is the same as (RCIRC-4 01011) which has a value of 10110. Another strategy is to offset the left and right circulates. So, ((RCIRC-14 (LCIRC-23 01101)) has the same value as (LCIRC-9 01101), which has the same value as (LCIRC-4 01101) which is also 11010.<br />
<br />
Expressions B and C are pretty easy to evaluate:<br />
:B = (LSHIFT-1 10011) = 00110<br />
:C = (RSHIFT-2 10111) = 00101<br />
<br />
The expression becomes<br />
: A | B & C = 10110 | 00110 & 00101 = 10110 | 00100 = 10110<br />
<br />
== Video Resources ==<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/0U6ogoQ5Hkk</youtube><br />
| [https://youtu.be/0U6ogoQ5Hkk "ACSL Math: Bit String Flicking" (Quick Coding Bytes)]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/IeMsD3harrE</youtube><br />
| [https://youtu.be/IeMsD3harrE ''Bit String Flicking (Intro)'' ('''CalculusNguyenify''')]<br />
<br />
A great two-part tutorial on this ACSL category. Part 1 covers bitwise operations AND, OR, NOT, and XOR. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jbKw8oYJPs4</youtube><br />
| [https://youtu.be/jbKw8oYJPs4 ''Bit String Flicking Shifts and Circs'' ('''CalculusNguyenify''')]<br />
<br />
Part 2 covers logical shifts and circulate operations.<br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/XNBcO25mgCw</youtube><br />
| [https://youtu.be/XNBcO25mgCw ''Bit String Flicking'' ('''Tangerine Code''')]<br />
<br />
Shows the solution to the problem: (RSHIFT-3 (LCIRC-2 (NOT 10110)))<br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aa_lQ8gft60</youtube><br />
| [https://youtu.be/aa_lQ8gft60 ''ACSL BitString Flicking Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Solves a handful of problems given in previous years at the Intermediate Division level.<br />
<br />
|}<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&diff=880Bit-String Flicking2024-01-30T16:44:56Z<p>Jerry: </p>
<hr />
<div><br />
Bit strings (strings of binary digits) are frequently manipulated bit-by-bit using the logical operators '''NOT''', '''AND''', '''OR''', and '''XOR'''. Bits strings are manipulated as a unit using '''SHIFT''' and '''CIRCULATE''' operators. The bits on the left are called the ''most significant bits'' and those on the right are the ''least significant bits''.<br />
<br />
Most high-level languages (e.g., Python, Java, C++), support bit-string operations. Programmers typically use bit strings to maintain a set of flags. Suppose that a program supports 8 options, each of which can be either “on” or “off”. One could maintain this information using an array of size 8, or one could use a single variable (if it is internally stored using at least 8 bits or 1 byte, which is usually the case) and represent each option with a single bit. In addition to saving space, the program is often cleaner if a single variable is involved rather than an array. Bits strings are often used to maintain a set where values are either in the set or not. Shifting of bits is also used to multiply or divide by powers of 2.<br />
<br />
Mastering this topic is essential for systems programming, programming in assembly language, optimizing code, and hardware design.<br />
<br />
== Operators==<br />
<br />
=== Bitwise Operators ===<br />
<br />
The logical operators are '''NOT''' (~ or $\neg$), '''AND''' (&), '''OR''' (|), and '''XOR''' ($\oplus$). These operators should be familiar to ACSL students from the [[Boolean Algebra]] and [[Digital Electronics]] categories.<br />
<br />
* '''NOT''' is a unary operator that performs logical negation on each bit. Bits that are 0 become 1, and those that are 1 become 0. For example: ~101110 has a value of 010001.<br />
<br />
* '''AND''' is a binary operator that performs the logical '''AND''' of each bit in each of its operands. The '''AND''' of two values is 1 only if both values are 1. For example, '''1011011 and 011001''' has a value of '''1011011'''. The '''AND''' function is often used to isolate the value of a bit in a bit-string or to clear the value of a bit in a bit-string.<br />
<br />
* '''OR''' is a binary operator that performs the logical '''OR''' of each bit in each of its operands. The '''OR''' of two values is 1 only if one or both values are 1. For example, '''1011011 or 0011001''' has a value of '''1011011'''. The '''OR''' function is often use to force the value of a bit in a bit-string to be 1, if it isn't already.<br />
<br />
* '''XOR''' is a binary operator that performs the logical '''XOR''' of each bit in each of its operands. The '''XOR''' of two values is 1 if the values are different and 0 if they are the same. For example, '''1011011 xor 011001 = 110010'''. The '''XOR''' function is often used to change the value of a particular bit.<br />
<br />
All binary operators (AND, OR, or XOR) must operate on bit-strings that are of the same length. If the operands are not the same length, the shorter one is padded with 0's on the left as needed. For example, '''11010 and 1110''' would have value of '''11010 and 01110 = 01010'''.<br />
<br />
The following table summarizes the operators:<br />
<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
! '''not''' <math>x</math><br />
!<math>x</math> '''and''' <math>y</math><br />
!<math>x</math> '''or''' <math>y</math><br />
!<math>x</math> '''xor''' <math>y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
| 0 <br />
| 0 <br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
| 0 <br />
| 1 <br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
| 0 <br />
| 1 <br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0 <br />
| 1 <br />
| 1 <br />
| 0<br />
|}<br />
<br />
=== Shift Operators ===<br />
<br />
Logical shifts (LSHIFT-x and RSHIFT-x) “ripple” the bit-string x positions in the indicated direction, either to the left or to the right. Bits shifted out are lost; zeros are shifted in at the other end. <br />
<br />
Circulates (RCIRC-x and LCIRC-x) “ripple” the bit string x positions in the indicated direction. As each bit is shifted out one end, it is shifted in at the other end. The effect of this is that the bits remain in the same order on the other side of the string.<br />
<br />
The size of a bit-string does not change with shifts, or circulates. If any bit strings are initially of different lengths, all shorter ones are padded with zeros in the left bits until all strings are of the same length. <br />
<br />
The following table gives some examples of these operations:<br />
<br />
::{| class="wikitable" style="text-align: right"<br />
|-<br />
!x<br />
!(LSHIFT-2 x)<br />
!(RSHIFT-3 x)<br />
!(LCIRC-3 x)<br />
!(RCIRC-1 x)<br />
|-<br />
!01101<br />
| 10100<br />
| 00001<br />
| 01011<br />
| 10110<br />
|-<br />
!10<br />
| 00<br />
| 00<br />
| 01<br />
| 01<br />
|-<br />
!1110<br />
| 1000<br />
| 0001<br />
| 0111<br />
| 0111<br />
|-<br />
!1011011<br />
| 1101100<br />
| 0001011<br />
| 1011101<br />
| 1101101<br />
|}<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of precedence (from highest to lowest) is: NOT; SHIFT and CIRC; AND; XOR; and finally, OR. In other words, all unary operators are performed on a single operator first. Operators with equal precedence are evaluated left to right; all unary operators bind from right to left.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
Evaluate the following expression: <br />
:(101110 AND NOT 110110 OR (LSHIFT-3 101010))<br />
<br />
'''Solution:'''<br />
The expression evaluates as follows:<br />
:(101110 AND '''001001''' OR (LSHIFT-3 101010))<br />
:('''001000''' OR (LSHIFT-3 101010))<br />
:(001000 OR '''010000''')<br />
:'''011000'''<br />
<br />
=== Problem 2 ===<br />
<br />
Evaluate the following expression: <br />
:(RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) <br />
<br />
'''Solution:'''<br />
The expression evaluates as follows, starting at the innermost parentheses:<br />
:(RCIRC-2 01101) => 01011<br />
:(LCIRC-4 01011) => 10101<br />
:(RSHIFT-1 10101) = 01010<br />
<br />
=== Problem 3 ===<br />
<br />
List all possible values of x (5 bits long) that solve the following equation.<br />
:(LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100<br />
<br />
'''Solution:'''<br />
Since x is a string 5 bits long, represent it by abcde.<br />
:(RCIRC-3 abcde) => cdeab<br />
:(cdeab AND 11011) => cd0ab<br />
:(10110 XOR cd0ab) => Cd1Ab (the capital letter is the NOT of its lower case)<br />
:(LSHIFT-1 Cd1Ab) => d1Ab0<br />
<br />
So, d1Ab0 = 01100.<br />
<br />
Meaning, we must have d=0, A=1 (hence a=0), b=0. Thus, the solution must be in the form 00*0*, where * is an “I-don’t-care”. <br />
<br />
The four possible values of x are: 00000, 00001, 00100 and 00101.<br />
<br />
=== Problem 4 ===<br />
<br />
Evaluate the following expression:<br />
: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) & (RSHIFT-2 10111))<br />
<br />
'''Solution:'''<br />
The problem can be rewritten as <br />
: A | B & C<br />
The AND has higher precedence than the OR. <br />
<br />
The evaluation of expression A can be done in a straightforward way: (LCIRC-23 01101) is the same as (LCIRC-3 01101) which has a value of 01011, and (RCIRC-14 01011) is the same as (RCIRC-4 01011) which has a value of 10110. Another strategy is to offset the left and right circulates. So, ((RCIRC-14 (LCIRC-23 01101)) has the same value as (LCIRC-9 01101), which has the same value as (LCIRC-4 01101) which is also 11010.<br />
<br />
Expressions B and C are pretty easy to evaluate:<br />
:B = (LSHIFT-1 10011) = 00110<br />
:C = (RSHIFT-2 10111) = 00101<br />
<br />
The expression becomes<br />
: A | B & C = 10110 | 00110 & 00101 = 10110 | 00100 = 10110<br />
<br />
== Video Resources ==<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/0U6ogoQ5Hkk</youtube><br />
| [https://youtu.be/0U6ogoQ5Hkk "ACSL Math: Bit String Flicking" (Quick Coding Bytes)]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/IeMsD3harrE</youtube><br />
| [https://youtu.be/IeMsD3harrE ''Bit String Flicking (Intro)'' ('''CalculusNguyenify''')]<br />
<br />
A great two-part tutorial on this ACSL category. Part 1 covers bitwise operations AND, OR, NOT, and XOR. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jbKw8oYJPs4</youtube><br />
| [https://youtu.be/jbKw8oYJPs4 ''Bit String Flicking Shifts and Circs'' ('''CalculusNguyenify''')]<br />
<br />
Part 2 covers logical shifts and circulate operations.<br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/XNBcO25mgCw</youtube><br />
| [https://youtu.be/XNBcO25mgCw ''Bit String Flicking'' ('''Tangerine Code''')]<br />
<br />
Shows the solution to the problem: (RSHIFT-3 (LCIRC-2 (NOT 10110)))<br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aa_lQ8gft60</youtube><br />
| [https://youtu.be/aa_lQ8gft60 ''ACSL BitString Flicking Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Solves a handful of problems given in previous years at the Intermediate Division level.<br />
<br />
|}<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=LISP&diff=879LISP2023-02-11T13:45:01Z<p>Jerry: </p>
<hr />
<div>LISP is one of the simplest computer languages in terms of syntax and semantics, and also one of the most powerful. It was developed in the mid-1950's by John McCarthy at M.I.T. as a "LISt Processing language." It has been historically used for virtually all Artificial Intelligence programs and is often the environment of choice for applications which require a powerful interactive working environment. LISP presents a very different way to think about programming from the "algorithmic" languages, such as Python, C++, and Java.<br />
<br />
== Syntax ==<br />
<br />
As its name implies, the basis of LISP is a list. One constructs a list by enumerating elements inside a pair of parentheses. For example, here is a list with four elements (the second element is also a list):<br />
<br />
:<code>(23 (this is easy) hello 821)</code><br />
<br />
The elements in the list, which are not lists, are called "atoms." For example, the atoms in the list above are: 23, 'this, 'hello, 821, 'easy, and 'is. Literals are identified with a single leading quote. Everything in LISP is either an atom or a list (but not both). The only exception is "NIL," which is both an atom and a list. It can also be written as "()" – a pair of parentheses with nothing inside.<br />
<br />
All statements in LISP are function calls with the following syntax: (function arg1 arg2 arg3 … argn). To evaluate a LISP statement, each of the arguments (possibly functions themselves) are evaluated, and then the function is invoked with the arguments. For example, (MULT (ADD 2 3) (ADD 1 4 2)) has a value of 35, since (ADD 2 3) has a value of 5, (ADD 1 4 2) has a value of 7, and (MULT 5 7) has a value of 35. Some functions have an arbitrary number of arguments; others require a fixed number. All statements return a value, which is either an atom or a list.<br />
<br />
== Basic Functions (SET, SETQ, EVAL, ATOM) ==<br />
<br />
We may assign values to variables using the function SET. For example, the statement (SET 'test 6) would have a value of a 6, and (more importantly, however) would also cause the atom 'test to be bound to the atom 6. The function SETQ is the same as SET, but it causes LISP to act as if the first argument was quoted. <br />
Observe the following examples:<br />
<br />
:{| class="wikitable" style="text-align: left"<br />
!Statement || Value || Comment <br />
|-<br />
|(SET 'a (MULT 2 3))<br />
|6<br />
|a is an atom with a value of 6<br />
|-<br />
|(SET 'a '(MULT 2 3))<br />
|(MULT 2 3)<br />
|a is a list with 3 elements<br />
|-<br />
|(SET 'b 'a)<br />
|a<br />
|b is an atom with a value of the character a<br />
|-<br />
|(SET 'c a)<br />
|(MULT 2 3)<br />
|c is a list with 3 elements<br />
|-<br />
|(SETQ EX (ADD 3 (MULT 2 5)))<br />
|13<br />
|The variable EX has a value of 13<br />
|-<br />
|(SETQ VOWELS '(A E I O U))<br />
|(A E I O U)<br />
|VOWELS is a list of 5 elements<br />
|}<br />
<br />
The function EVAL returns the value of its argument, after it has been evaluated. For example, (SETQ z '(ADD 2 3)) has a value of the list (ADD 2 3); the function (EVAL 'z) has a value of (ADD 2 3); the function (EVAL z) has a value of 5 (but the binding of the atom z has not changed). In this last example, you can think of z being "resolved" twice: once because it is an argument to a function and LISP evaluates all arguments to functions before the function is invoked, and once when the function EVAL is invoked to resolve arguments. The function ATOM can be used to determine whether an item is an atom or a list. It returns either "true", or "NIL" for false. Consider the following examples:<br />
<br />
:{| class="wikitable" style="text-align: left"<br />
!Statement || Value || Comment <br />
|-<br />
|(SETQ p '(ADD 1 2 3 4))<br />
|(ADD 1 2 3 4)<br />
|p is a list with 5 elements<br />
|-<br />
|(ATOM 'p)<br />
|true<br />
|The argument to ATOM is the atom p<br />
|-<br />
|(ATOM p)<br />
|NIL<br />
|Because p is not quoted, it is evaluated to the 5-element list.<br />
|-<br />
|(EVAL p)<br />
|10<br />
|The argument to EVAL is the value of p; the value of p is 10. <br />
|}<br />
<br />
== List Functions (CAR, CDR, CONS, REVERSE)==<br />
<br />
The two most famous LISP functions are CAR and CDR (pronounced: could-er), named after registers of a now long-forgotten IBM machine on which LISP was first developed. The function (CAR x) returns the first item of the list x (and x must be a list or an error will occur); (CDR x) returns the list without its first element (again, x must be a list). The function CONS takes two arguments, of which the second must be a list. It returns a list which is composed by placing the first argument as the first element in the second argument's list. The function REVERSE returns a list which is its arguments in reverse order. <br />
<br />
The CAR and CDR functions are used extensively to grab specific elements of a list or sublist, that there's a shorthand for this: (CADR x) is the same as (CAR (CDR x)), which retrieves the second element of the list x; (CAADDAR x) is a shorthand for (CAR (CAR (CDR (CDR (CAR x))))), and so on.<br />
<br />
The following examples illustrate the use of CAR, CDR, CONS, and REVERSE: <br />
<br />
:{| class="wikitable" style="text-align: left"<br />
!Statement || Value<br />
|-<br />
|(CAR '(This is a list))<br />
|This<br />
|-<br />
|(CDR '(This is a list))<br />
|(is a list)<br />
|-<br />
|(CONS 'red '(white blue))<br />
|(red white blue)<br />
|-<br />
|(SETQ z (CONS '(red white blue) (CDR '(This is a list))))<br />
|((red white blue) is a list)<br />
|-<br />
|(REVERSE z)<br />
|(list a is (red white blue))<br />
|-<br />
|(CDDAR z)<br />
|(blue)<br />
|}<br />
<br />
== Arithmetic Functions (ADD, MULT, ...)==<br />
<br />
As you have probably already figured out, the function ADD simply summed its arguments. We'll also be using the following arithmetic functions:<br />
<br />
:{| class="wikitable" style="text-align: left"<br />
!'''Function''' || '''Result'''<br />
|-<br />
|(ADD x1 x2 …)<br />
|sum of all arguments<br />
|-<br />
|(SUB a b)<br />
|a-b<br />
|-<br />
|(MULT x1 x2 …)<br />
|product of all arguments<br />
|-<br />
|(DIV a b)<br />
|a/b<br />
|-<br />
|(SQUARE a)<br />
|a*a<br />
|-<br />
|(EXP a n)<br />
|a<sup>n</sup><br />
|-<br />
|(EQ a b)<br />
|true if a and b are equal, NIL otherwise<br />
|-<br />
|(POS a)<br />
|true if a is positive, NIL otherwise<br />
|-<br />
|(NEG a)<br />
|true if a is negative, NIL otherwise<br />
|-<br />
|}<br />
<br />
Functions ADD, SUB, MULT, and DIV can be written as their common mathematical symbols, +, -, *, and /. Here are some examples of these functions:<br />
<br />
:{| class="wikitable"<br />
!'''Statement''' || '''Value'''<br />
|-<br />
|(ADD (EXP 2 3) (SUB 4 1) (DIV 54 4))<br />
|24.5<br />
|-<br />
|(- (* 3 2) (- 12 (+ 1 2 1)))<br />
| -2<br />
|-<br />
|(ADD (SQUARE 3) (SQUARE 4))<br />
|25<br />
|}<br />
<br />
== User-defined Functions ==<br />
<br />
LISP also allows us to create our own functions using the DEF function. (We will sometimes use DEFUN rather than DEF, as it is a bit more standard terminology.) For example,<br />
(DEF SECOND (args) (CAR (CDR args)))<br />
defines a new function called SECOND which operates on a single parameter named "args". SECOND will take the CDR of the parameter and then the CAR of that result. So, for example:<br />
(SECOND '(a b c d e))<br />
would first CDR the list to give (b c d e), and then CAR that value returning the single character "b". Consider the following program fragment:<br />
(SETQ X '(a c s l))<br />
(DEF WHAT(args) (CONS args (REVERSE (CDR args))))<br />
(DEF SECOND(args) (CONS (CAR (CDR args)) NIL))<br />
<br />
The following chart illustrates the use of the user-defined functions WHAT and SECOND:<br />
<br />
:{| class="wikitable"<br />
!Statement || Value<br />
|-<br />
|(WHAT X) || ((a c s l) l s c)<br />
|-<br />
|(SECOND X) || (c)<br />
|-<br />
|(SECOND (WHAT X)) || (l)<br />
|-<br />
|(WHAT (SECOND X)) || ((c))<br />
|}<br />
<br />
== Online Interpreters ==<br />
<br />
There are many online LISP interpreters available on the Internet. The one that ACSL uses for testing its programs is CLISP that is accessible from [https://www.jdoodle.com/execute-clisp-online JDoodle]. This interpreter is nice because it is quite peppy in running programs, and functions are not case sensitive. So, <code>(CAR (CDR x))</code> is legal as is <code>(car (cdr x))</code> One drawback of this interpreter is the print function changes lowercase input into uppercase. <br />
<br />
== Sample Problems ==<br />
<br />
Questions from this topic will typically present a line of LISP code or a short sequence of statements and ask what is the value of the (final) statement.<br />
<br />
=== Problem 1 ===<br />
<br />
Evaluate the following expression. <code>(MULT (ADD 6 5 0) (MULT 5 1 2 2) (DIV 6 (SUB 2 5)))</code><br />
<br />
'''Solution:'''<br />
(MULT (ADD 6 5 0) (MULT 5 1 2 2) (DIV 6 (SUB 2 5)))<br />
(MULT 11 20 (DIV 6 -3))<br />
(MULT 11 20 -2)<br />
-440<br />
<br />
=== Problem 2 ===<br />
<br />
Evaluate the following expression: <code>(CDR '((2 (3))(4 (5 6) 7)))</code><br />
<br />
'''Solution:'''<br />
The CDR function takes the first element of its parameter (which is assumed to be a list) and returns the list with the first element removed. The first element of the list is (2 (3)) and the list without this element is<br />
((4 (5 6) 7)), a list with one element.<br />
<br />
=== Problem 3 ===<br />
<br />
Consider the following program fragment:<br />
(SETQ X '(RI VA FL CA TX))<br />
(CAR (CDR (REVERSE X)))<br />
What is the value of the CAR expression? <br />
<br />
'''Solution:'''<br />
The first statement binds variable X to the list '(RI VA FL CA TX).<br />
The REVERSE of this list is '(TX CA FL VA RI)<br />
whose CDR is '(CA FL VA RI). The CAR of this list is just the atom CA (without the quote).<br />
<br />
<!-- <br />
<br />
Too scary of a sample problem! --marc 9/3/2018<br />
<br />
=== Problem 4 ===<br />
<br />
Given the function definitions for HY and FY as follows:<br />
(DEFUN HY(PARM) (REVERSE (CDR PARM)))<br />
(DEFUN FY(PARM) (CAR (HY (CDR PARM))))<br />
What is the value of the following?<br />
(FY '(DO RE (MI FA) SO))<br />
<br />
'''Solution:'''<br />
To evaluate (FY '(DO RE (MI FA) SO)), we must evaluate<br />
(CAR (HY (CDR '(DO RE (MI FA) SO)))).<br />
Thus, HY is invoked with <br />
PARM = '(RE (MI FA) SO), and we evaluate<br />
(REVERSE (CDR '(RE (MI FA) SO)))<br />
This has a value of (SO (MI FA)) which is returned to FY. FY now takes the CAR of this which is SO (without the quotes).<br />
--><br />
<br />
== Video Resources ==<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--><br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jWFgmE279eQ</youtube><br />
| [https://youtu.be/jWFgmE279eQ ''LISP very gentle intro'' ('''CalculusNguyenify''')]<br />
<br />
A very gentle introduction to the LISP category, covering the LISP syntax and the basic operators, SETQ, ADD, SUB, MULT, and DIV.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/mRpbbss48sw</youtube><br />
| [https://youtu.be/mRpbbss48sw ''LISP Basics (for ACSL)'' ('''Tangerine Code''')]<br />
<br />
Explains the LISP operators CAR, CDR, and REVERSE, in the context of solving an ACSL All-Star Contest problem.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/50wj_f51kBM</youtube><br />
| [https://youtu.be/50wj_f51kBM ''LISP Basics (for ACSL)'' ('''Tangerine Code''')]<br />
<br />
Completes the problem that was started in the above video. <br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=864Boolean Algebra2021-03-17T18:33:38Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator ]. This link that has ads also simplifies and uses ! for NOT [https://www.boolean-algebra.com/ calculator].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=863Boolean Algebra2021-03-17T18:30:27Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator ]. This link also simplifies and uses ! for NOT [https://www.boolean-algebra.com/ calculator].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=862Boolean Algebra2021-03-17T18:14:13Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator ].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=861Boolean Algebra2021-03-17T18:13:35Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator ]. this one also simplifies [https://www.dcode.fr/boolean-expressions-calculator/ calculator].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=860Boolean Algebra2021-03-17T17:41:47Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator ].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=859Boolean Algebra2021-03-17T17:40:24Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator ]. This one also simplifies [https://www.wolframalpha.com/widgets/view.jsp?id=a52797be9f91295a27b14cb751198ae3/ calculator]<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=858Boolean Algebra2021-03-17T17:31:30Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator ].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=857Boolean Algebra2021-03-17T17:30:21Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator 2].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=856Boolean Algebra2021-03-17T17:28:17Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one does simplification [http://tma.main.jp/logic/index_en.html/ calculator 1]. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator 2].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=855Boolean Algebra2021-03-17T17:26:44Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one does simplification [http://tma.main.jp/logic/logic.php?lang=en&type=eq&eq=%7Ea%28a%2Bb%29/ calculator 1]. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator 2].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=854Boolean Algebra2021-03-17T17:18:38Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one does simplification [https://www.dcode.fr/boolean-expressions-calculator/ calculator 1]. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator 2].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=853Boolean Algebra2021-03-17T17:17:28Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one does simplification [https://www.dcode.fr/boolean-expressions-calculator/calculator 1]. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator 2].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=852Boolean Algebra2021-03-17T17:15:52Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one does simplification [https://www.dcode.fr/boolean-expressions-calculator/ calculator 1]. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/ calculator 2].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=851Boolean Algebra2021-03-17T17:14:51Z<p>Jerry: /* Online Resources */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one does simplification [https://www.dcode.fr/boolean-expressions-calculator/ calculator 1]. This one gives Truth Tables [https://sheabunge.github.io/boolcalc//calculator 2].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=850Boolean Algebra2021-03-17T17:14:06Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one does simplification [https://www.dcode.fr/boolean-expressions-calculator/ calculator 1]. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/calculator 2].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=849Boolean Algebra2021-03-17T17:11:42Z<p>Jerry: /* Websites */</p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
== Operators ==<br />
<br />
The basic operators in Boolean algebra are '''AND''', '''OR''', and '''NOT'''. The secondary operators are ''eXclusive OR'' (often called '''XOR''') and ''eXclusive NOR'' ('''XNOR''', sometimes called '''equivalence'''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
<br />
*The '''AND''' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''OR''' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x + y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The '''NOT''' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ \overline{x}\ \ \ \ </math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The '''XOR''' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \oplus y\ </math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The '''XNOR''' of two values is true whenever the values are the same. It is the '''NOT''' of the '''XOR''' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>\ \ \ \ x\ \ \ \ </math><br />
!<math>\ \ \ \ y\ \ \ \ </math><br />
!<math>\ x \odot y\ </math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
== Why is Boolean Algebra Important for ACSL Students? ==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression ''jaguar speed -car'' is parsed by the search engine as the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as if it were written $x \cdot \overline{(y + z)}.$<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
=== Fundamental Identities ===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials]. There are many online Boolean Calculators. This one does simplification [https://www.dcode.fr/boolean-expressions-calculator]. This one gives Truth Tables [https://sheabunge.github.io/boolcalc/].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&diff=842Bit-String Flicking2021-01-20T18:57:58Z<p>Jerry: /* Bitwise Operators */</p>
<hr />
<div><br />
Bit strings (strings of binary digits) are frequently manipulated bit-by-bit using the logical operators '''NOT''', '''AND''', '''OR''', and '''XOR'''. Bits strings are manipulated as a unit using '''SHIFT''' and '''CIRCULATE''' operators. The bits on the left are called the ''most significant bits'' and those on the right are the ''least significant bits''.<br />
<br />
Most high-level languages (e.g., Python, Java, C++), support bit-string operations. Programmers typically use bit strings to maintain a set of flags. Suppose that a program supports 8 options, each of which can be either “on” or “off”. One could maintain this information using an array of size 8, or one could use a single variable (if it is internally stored using at least 8 bits or 1 byte, which is usually the case) and represent each option with a single bit. In addition to saving space, the program is often cleaner if a single variable is involved rather than an array. Bits strings are often used to maintain a set where values are either in the set or not. Shifting of bits is also used to multiply or divide by powers of 2.<br />
<br />
Mastering this topic is essential for systems programming, programming in assembly language, optimizing code, and hardware design.<br />
<br />
== Operators==<br />
<br />
=== Bitwise Operators ===<br />
<br />
The logical operators are '''NOT''' (~ or $\neg$), '''AND''' (&), '''OR''' (|), and '''XOR''' ($\oplus$). These operators should be familiar to ACSL students from the [[Boolean Algebra]] and [[Digital Electronics]] categories.<br />
<br />
* '''NOT''' is a unary operator that performs logical negation on each bit. Bits that are 0 become 1, and those that are 1 become 0. For example: ~101110 has a value of 010001.<br />
<br />
* '''AND''' is a binary operator that performs the logical '''AND''' of each bit in each of its operands. The '''AND''' of two values is 1 only if both values are 1. For example, '''1011011 and 011001''' has a value of '''001001'''. The '''AND''' function is often used to isolate the value of a bit in a bit-string or to clear the value of a bit in a bit-string.<br />
<br />
* '''OR''' is a binary operator that performs the logical '''OR''' of each bit in each of its operands. The '''OR''' of two values is 1 only if one or both values are 1. For example, '''1011011 or 0011001''' has a value of '''1011011'''. The '''OR''' function is often use to force the value of a bit in a bit-string to be 1, if it isn't already.<br />
<br />
* '''XOR''' is a binary operator that performs the logical '''XOR''' of each bit in each of its operands. The '''XOR''' of two values is 1 if the values are different and 0 if they are the same. For example, '''1011011 xor 011001 = 110010'''. The '''XOR''' function is often used to change the value of a particular bit.<br />
<br />
All binary operators (AND, OR, or XOR) must operate on bit-strings that are of the same length. If the operands are not the same length, the shorter one is padded with 0's on the left as needed. For example, '''11010 and 1110''' would have value of '''11010 and 01110 = 01010'''.<br />
<br />
The following table summarizes the operators:<br />
<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
! '''not''' <math>x</math><br />
!<math>x</math> '''and''' <math>y</math><br />
!<math>x</math> '''or''' <math>y</math><br />
!<math>x</math> '''xor''' <math>y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
| 0 <br />
| 0 <br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
| 0 <br />
| 1 <br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
| 0 <br />
| 1 <br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0 <br />
| 1 <br />
| 1 <br />
| 0<br />
|}<br />
<br />
=== Shift Operators ===<br />
<br />
Logical shifts (LSHIFT-x and RSHIFT-x) “ripple” the bit-string x positions in the indicated direction, either to the left or to the right. Bits shifted out are lost; zeros are shifted in at the other end. <br />
<br />
Circulates (RCIRC-x and LCIRC-x) “ripple” the bit string x positions in the indicated direction. As each bit is shifted out one end, it is shifted in at the other end. The effect of this is that the bits remain in the same order on the other side of the string.<br />
<br />
The size of a bit-string does not change with shifts, or circulates. If any bit strings are initially of different lengths, all shorter ones are padded with zeros in the left bits until all strings are of the same length. <br />
<br />
The following table gives some examples of these operations:<br />
<br />
::{| class="wikitable" style="text-align: right"<br />
|-<br />
!x<br />
!(LSHIFT-2 x)<br />
!(RSHIFT-3 x)<br />
!(LCIRC-3 x)<br />
!(RCIRC-1 x)<br />
|-<br />
!01101<br />
| 10100<br />
| 00001<br />
| 01011<br />
| 10110<br />
|-<br />
!10<br />
| 00<br />
| 00<br />
| 01<br />
| 01<br />
|-<br />
!1110<br />
| 1000<br />
| 0001<br />
| 0111<br />
| 0111<br />
|-<br />
!1011011<br />
| 1101100<br />
| 0001011<br />
| 1011101<br />
| 1101101<br />
|}<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of precedence (from highest to lowest) is: NOT; SHIFT and CIRC; AND; XOR; and finally, OR. In other words, all unary operators are performed on a single operator first. Operators with equal precedence are evaluated left to right; all unary operators bind from right to left.<br />
<br />
== Sample Problems ==<br />
<br />
=== Problem 1 ===<br />
<br />
Evaluate the following expression: <br />
:(101110 AND NOT 110110 OR (LSHIFT-3 101010))<br />
<br />
'''Solution:'''<br />
The expression evaluates as follows:<br />
:(101110 AND '''001001''' OR (LSHIFT-3 101010))<br />
:('''001000''' OR (LSHIFT-3 101010))<br />
:(001000 OR '''010000''')<br />
:'''011000'''<br />
<br />
=== Problem 2 ===<br />
<br />
Evaluate the following expression: <br />
:(RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) <br />
<br />
'''Solution:'''<br />
The expression evaluates as follows, starting at the innermost parentheses:<br />
:(RCIRC-2 01101) => 01011<br />
:(LCIRC-4 01011) => 10101<br />
:(RSHIFT-1 10101) = 01010<br />
<br />
=== Problem 3 ===<br />
<br />
List all possible values of x (5 bits long) that solve the following equation.<br />
:(LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100<br />
<br />
'''Solution:'''<br />
Since x is a string 5 bits long, represent it by abcde.<br />
:(RCIRC-3 abcde) => cdeab<br />
:(cdeab AND 11011) => cd0ab<br />
:(10110 XOR cd0ab) => Cd1Ab (the capital letter is the NOT of its lower case)<br />
:(LSHIFT-1 Cd1Ab) => d1Ab0<br />
<br />
So, d1Ab0 = 01100.<br />
<br />
Meaning, we must have d=0, A=1 (hence a=0), b=0. Thus, the solution must be in the form 00*0*, where * is an “I-don’t-care”. <br />
<br />
The four possible values of x are: 00000, 00001, 00100 and 00101.<br />
<br />
=== Problem 4 ===<br />
<br />
Evaluate the following expression:<br />
: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) & (RSHIFT-2 10111))<br />
<br />
'''Solution:'''<br />
The problem can be rewritten as <br />
: A | B & C<br />
The AND has higher precedence than the OR. <br />
<br />
The evaluation of expression A can be done in a straightforward way: (LCIRC-23 01101) is the same as (LCIRC-3 01101) which has a value of 01011, and (RCIRC-14 01011) is the same as (RCIRC-4 01011) which has a value of 10110. Another strategy is to offset the left and right circulates. So, ((RCIRC-14 (LCIRC-23 01101)) has the same value as (LCIRC-9 01101), which has the same value as (LCIRC-4 01101) which is also 11010.<br />
<br />
Expressions B and C are pretty easy to evaluate:<br />
:B = (LSHIFT-1 10011) = 00110<br />
:C = (RSHIFT-2 10111) = 00101<br />
<br />
The expression becomes<br />
: A | B & C = 10110 | 00110 & 00101 = 10110 | 00100 = 10110<br />
<br />
== Video Resources ==<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/0U6ogoQ5Hkk</youtube><br />
| [https://youtu.be/0U6ogoQ5Hkk "ACSL Math: Bit String Flicking" (Quick Coding Bytes)]<br />
<br />
This video introduces the topic, then using an example problem, explains the methodology to solve problems that appear on ACSL contests.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/IeMsD3harrE</youtube><br />
| [https://youtu.be/IeMsD3harrE ''Bit String Flicking (Intro)'' ('''CalculusNguyenify''')]<br />
<br />
A great two-part tutorial on this ACSL category. Part 1 covers bitwise operations AND, OR, NOT, and XOR. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jbKw8oYJPs4</youtube><br />
| [https://youtu.be/jbKw8oYJPs4 ''Bit String Flicking Shifts and Circs'' ('''CalculusNguyenify''')]<br />
<br />
Part 2 covers logical shifts and circulate operations.<br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/XNBcO25mgCw</youtube><br />
| [https://youtu.be/XNBcO25mgCw ''Bit String Flicking'' ('''Tangerine Code''')]<br />
<br />
Shows the solution to the problem: (RSHIFT-3 (LCIRC-2 (NOT 10110)))<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/8J9AdxU5CW8</youtube><br />
| [https://youtu.be/8J9AdxU5CW8 ''Bit String Flicking by Ravi Yeluru'' ('''hemsra''')]<br />
<br />
Walks through two problems from the Junior Division.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aa_lQ8gft60</youtube><br />
| [https://youtu.be/aa_lQ8gft60 ''ACSL BitString Flicking Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Solves a handful of problems given in previous years at the Intermediate Division level.<br />
<br />
|}<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=595What Does This Program Do?2018-09-23T15:28:21Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, and documentation is, unfortunately,<br />
not always available or sufficient, it is essential to be able to read and understand an arbitrary program. <br />
<br />
This category presents a program and asks the student to determine that the program does. The programs are written using a pseudocode that<br />
should be readily understandable by all programmers familiar with a high-level programming language, such as Python, Java, or C.<br />
<br />
= Description of the ACSL Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ or ↑(exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Functions<br />
|abs(x) - absolute value, sqrt(x) - square root, int(x) - greatest integer <= x<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimensional arrays use a single subscript such as A(5). 2 dimensional arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimensional arrays and location (0,0) for 2 dimensional arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|Strings can contain 0 or more characters and the indexed position starts with 0 at the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total number of characters. Strings are identified with surrounding double quotes. Use [ ] for identifying the characters in a substring of a given string as follows: <br />
S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)<br />
<br />
S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
<br />
S[5:] = “WDTPD” (take the last 5 characters starting on the right) <br />
<br />
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)<br />
<br />
S[0] = “A” (position 0 only). <br />
<br />
String concatenation is accomplished using the + symbol<br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4.<br />
<br />
= Sample Problems =<br />
<br />
== Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
<syntaxhighlight><br />
input H, R<br />
B = 0<br />
if H>48 then<br />
B = B + (H - 48) * 2 * R<br />
H = 48<br />
end if<br />
if H>40 then<br />
B = B + (H - 40) * (3/2) * R<br />
H = 40<br />
end if<br />
B = B + H * R<br />
output B<br />
</syntaxhighlight><br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! | B || H<br />
|-<br />
| | 0 || 50<br />
|-<br />
| | 40 || 48<br />
|-<br />
| | 160 || 40<br />
|-<br />
| | 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
<syntaxhighlight><br />
A = “BANANAS”<br />
NUM = 0: T = “”<br />
for J = len(A) - 1 to 0 step –1<br />
T = T + A[j]<br />
next <br />
for J = 0 to len(A) - 1<br />
if A[J] == T[J] then NUM = NUM + 1<br />
next<br />
</syntaxhighlight><br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
Variable NUM is incremented each time a character at position x of A is the same as the character in position x of string T. There are 5 such positions: 1, 2, 3, 4, and 5.<br />
<br />
== Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
<syntaxhighlight><br />
A(0) = 12: A(1) = 41: A(2) = 52<br />
A(3) = 57: A(4) = 77: A(5) = -100<br />
B(0) = 17: B(1) = 34: B(20 = 81<br />
J = 0: K = 0: N = 0<br />
while A(J) > 0<br />
while B(K) <= A(J)<br />
C(N) = B(K)<br />
N = N + 1<br />
k = k + 1<br />
end while<br />
C(N) = A(J): N = N + 1: J = J + 1<br />
end while<br />
C(N) = B(K)<br />
</syntaxhighlight><br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
<!--<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&diff=588FSAs and Regular Expressions2018-09-12T13:28:53Z<p>Jerry: </p>
<hr />
<div>A Finite State Automaton (FSA) is a mathematical model of computation comprising: a finite number of ''states'', of which exactly one is ''active'' at any given time; ''transition rules'' to change<br />
the active state; an ''initial state''; and one more ''final states''. We can draw an FSA by representing each state as a circle; the final state as a double circle; the start state as the only state with an incoming arrow; and the transition rules as labeled-edges connecting the states. When labels are assigned to states, they appear inside the circle representing the state. <br />
<br />
In this category, FSAs will be limited to parsing strings. That is, determining if a string is valid or not. <br />
<br />
= Basics =<br />
<br />
Here is a drawing of an FSA that is used to parse strings consisting of x's and y's:<br />
<br />
<center><br />
[[File:fsa.svg|250px]]<br />
</center><br />
<br />
In the above FSA, there are three states: A, B, and C. The initial state is A; the final state is C. The only way to go from state A to B is by ''seeing'' the letter x. Once in state B, there are two transition rules: Seeing the letter y will cause the FSA to make C the active state, and seeing an x will keep B as the active state. State C is a final state, so if the string being parsed is completed and the FSA is in State C, the input string is said to be ''accepted'' by the FSA. In State C, seeing any additional letter y will keep the machine in state C. The FSA above will accept strings composed of one or more x’s followed by one or more y’s (e.g., xy, xxy, xxxyy, xyyy, xxyyyy). <br />
<br />
Just like [[Boolean Algebra]] there is a convenient algebraic representation of [[Digital Electronics]] Circuits. A Regular Expression (RE) is an algebraic representation of an FSA. For example, the regular expression corresponding to the first FSA given above is xx*yy*. <br />
<br />
The rules for forming a Regular Expression (RE) are as follows:<br />
:1. The null string (λ) is a RE.<br />
:2. If the string a is in the input alphabet, then it is a RE.<br />
:3. if the strings a and b are both REs, then so are the strings built up using the following rules:<br />
::a. CONCATENATION. “ab” (a followed by b).<br />
::b. UNION. “aUb” (a or b). <br />
::c. CLOSURE. “a*” (a repeated zero or more times). This is known as the Kleene Star.<br />
<br />
Identities for Regular Expressions appear in the next section. The order of precedence for Regular Expression operators is: Kleene Star, concatenation, and then union. <br />
<br />
If we have a Regular Expression, then we can mechanically build an FSA to accept the strings which are generated by the Regular Expression. Conversely, if we have an FSA, we can mechanically develop a Regular Expression which will describe the strings which can be parsed by the FSA. For a given FSA or Regular Expression, there are many others which are equivalent to it. A “most simplified” Regular Expression or FSA is not always well defined. <br />
<!--<br />
Most programming languages today have a package to handle Regular Expressions in order to do pattern matching algorithms more easily. Visual BASIC has the LIKE operator that is very easy to use. We will use these “basic” symbols in our category description.<br />
<br />
{| class="wikitable" style="text-align: left"|<br />
|-<br />
!Pattern<br />
!Description<br />
|-<br />
|?<br />
|Any single character<br />
|-<br />
|*<br />
|Zero or more of the preceding character<br />
|-<br />
|#<br />
|Any single digit<br />
|-<br />
|[ char-char,char,…]<br />
|Any inclusive range or list of characters<br />
|-<br />
|{![charlist]}<br />
|Any character not in a given range or list<br />
|}<br />
<br />
For example, the following strings either match or don’t match the pattern “[A-M][o-z][!a,e,I,o,u]?#.*”:<br />
<br />
{| class="wikitable" style="text-align: left"|<br />
|-<br />
!YES<br />
!NO<br />
!Why not?<br />
|-<br />
|App$5.java<br />
|Help1.<br />
| E is not in the range [o-z].<br />
|-<br />
|Dog&2.py<br />
|IoU$5<br />
|There is no . at the end.<br />
|-<br />
|LzyG3.txt<br />
|move6.py<br />
|The m is not in the range [A-M].<br />
|-<br />
|Hot90.<br />
|MaX7A.txt<br />
|The A is not a digit from 0 to 9.<br />
|}<br />
--><br />
<br />
Typical problems in the category will include: translate an FSA to a Regular Expression; simplify a Regular Expression; determine which Regular Expressions or FSAs are equivalent; and determine which strings are accepted by either an FSA or a Regular Expression.<br />
<br />
= Regular Expression Identities =<br />
<br />
{| Class="wikitable"<br />
|-<br />
|1. (a*)* = a*<br />
|-<br />
|2. aa* = a*a<br />
|-<br />
|3. aa* U λ = a*<br />
|-<br />
|4. a(b U c) = ab U ac<br />
|-<br />
|5. a(ba)* = (ab)*a<br />
|-<br />
|6. (a U b)* = (a* U b*)*<br />
|-<br />
|7. (a U b)* = (a*b*)*<br />
|-<br />
|8. (a U b)* = a*(ba*)*<br />
|}<br />
<br />
= Sample Problems =<br />
<br />
== Problem 1 ==<br />
<br />
Find a simplified Regular Expression for the following FSA:<br />
<br />
[[File:fsa_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
The expression 01*01 is read directly from the FSA. It is in its most simplified form.<br />
<br />
== Problem 2 ==<br />
<br />
Which of the following strings are accepted by the following Regular Expression "00*1*1U11*0*0" ?<br />
<br />
::A. 0000001111111<br />
::B. 1010101010<br />
::C. 1111111<br />
::D. 0110<br />
::E. 10 <br />
<br />
'''Solution:'''<br />
<br />
This Regular Expression parses strings described by the union of 00*1*1 and 11*0*0. The RE 00*1*1 are strings starting with oe or more 0s followed by one or more 1s: 01, 001, 0001111, and so on. The RE 11*0*0 are strings with one or more 1s followed by one or more 0s: 10, 1110, 1111100, and so on. In other words, strings of the form: 0s followed by some 1s; or 1s <br />
followed by some 0s. Choice A and E following this pattern.<br />
<br />
== Problem 3 ==<br />
<br />
Which, if any, of the following Regular Expressions are equivalent?<br />
::A. (aUb)(ab*)(b*Ua)<br />
::B. (aab*Ubab*)a<br />
::C. aab*Ubab*UaabaUbab*a<br />
::D. aab*Ubab*Uaab*aUbab*a<br />
::E. a*Ub* <br />
<br />
'''Solution:'''<br />
<br />
Choice B can be discarded because it is the only RE whose strings '''must''' end with an a. Choice E can be discarded since it is the only RE that can accept a null string. Choices C and D are not equal. After expanding choice A, we must compare it to choices C and D. It is equal to choice D, but not to choice C. The only REs that are equivalent are choices A and D.<br />
<br />
<!--<br />
== Problem 3 ==<br />
<br />
Which of the following strings match the regular expression pattern "?[A-D]*[a-d]*#" ?<br />
<br />
::A. 8AAAabd4<br />
::B. MM5<br />
::C. AAAAAAAA7<br />
::D. Abcd9<br />
::E. &dd88<br />
::F. >BAD0<br />
<br />
'''Solution:'''<br />
<br />
The answer is A, C, D, and F. In B the character M is not in the range A-D or a-d. In E, there cannot be more than 1 digit at the end of the string. Remember that an asterisk represents 0 or more of that character or rangle of characters.<br />
--><br />
<br />
= Video Resources =<br />
<br />
Nice two-part video showing the relationship between FSAs and REs. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/GwsU2LPs85U</youtube><br />
| [https://youtu.be/GwsU2LPs85U ''1 - Convert Regular Expression to Finite-State Automaton'' ('''Barry Brown''')]<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/shN_kHBFOUE</youtube><br />
| [https://youtu.be/shN_kHBFOUE ''2 - Convert Regular Expression to Finite-State Automaton'' ('''Barry Brown''')]<br />
<br />
This video uses the symbol "+" to mean "1 or more matches of the previous term". For example, "ab+" is the same as "abb*". <br />
|}<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&diff=587FSAs and Regular Expressions2018-09-12T13:27:01Z<p>Jerry: </p>
<hr />
<div>A Finite State Automaton (FSA) is a mathematical model of computation comprising: a finite number of ''states'', of which exactly one is ''active'' at any given time; ''transition rules'' to change<br />
the active state; an ''initial state''; and one more ''final states''. We can draw an FSA by representing each state as a circle; the final state as a double circle; the start state as the only state with an incoming arrow; and the transition rules as labeled-edges connecting the states. When labels are assigned to states, they appear inside the circle representing the state. <br />
<br />
In this category, FSAs will be limited to parsing strings. That is, determining if a string is valid or not. <br />
<br />
= Basics =<br />
<br />
Here is a drawing of an FSA that is used to parse strings consisting of x's and y's:<br />
<br />
<center><br />
[[File:fsa.svg|250px]]<br />
</center><br />
<br />
In the above FSA, there are three states: A, B, and C. The initial state is A; the final state is C. The only way to go from state A to B is by ''seeing'' the letter x. Once in state B, there are two transition rules: Seeing the letter y will cause the FSA to make C the active state, and seeing an x will keep B as the active state. State C is a final state, so if the string being parsed is completed and the FSA is in State C, the input string is said to be ''accepted'' by the FSA. In State C, seeing any additional letter y will keep the machine in state C. The FSA above will accept strings composed of one or more x’s followed by one or more y’s (e.g., xy, xxy, xxxyy, xyyy, xxyyyy). <br />
<br />
Just like [[Boolean Algebra]] there is a convenient algebraic representation of [[Digital Electronics]] Circuits. A Regular Expression (RE) is an algebraic representation of an FSA. For example, the regular expression corresponding to the first FSA given above is xx*yy*. <br />
<br />
The rules for forming a Regular Expression (RE) are as follows:<br />
:1. The null string (λ) is a RE.<br />
:2. If the string a is in the input alphabet, then it is a RE.<br />
:3. if the strings a and b are both REs, then so are the strings built up using the following rules:<br />
::a. CONCATENATION. “ab” (a followed by b).<br />
::b. UNION. “aUb” (a or b). <br />
::c. CLOSURE. “a*” (a repeated zero or more times). This is known as the Kleene Star.<br />
<br />
Identities for Regular Expressions appear in the next section. The order of precedence for Regular Expression operators is: Kleene Star, concatenation, and then union. <br />
<br />
If we have a Regular Expression, then we can mechanically build an FSA to accept the strings which are generated by the Regular Expression. Conversely, if we have an FSA, we can mechanically develop a Regular Expression which will describe the strings which can be parsed by the FSA. For a given FSA or Regular Expression, there are many others which are equivalent to it. A “most simplified” Regular Expression or FSA is not always well defined. <br />
<!--<br />
Most programming languages today have a package to handle Regular Expressions in order to do pattern matching algorithms more easily. Visual BASIC has the LIKE operator that is very easy to use. We will use these “basic” symbols in our category description.<br />
<br />
{| class="wikitable" style="text-align: left"|<br />
|-<br />
!Pattern<br />
!Description<br />
|-<br />
|?<br />
|Any single character<br />
|-<br />
|*<br />
|Zero or more of the preceding character<br />
|-<br />
|#<br />
|Any single digit<br />
|-<br />
|[ char-char,char,…]<br />
|Any inclusive range or list of characters<br />
|-<br />
|{![charlist]}<br />
|Any character not in a given range or list<br />
|}<br />
<br />
For example, the following strings either match or don’t match the pattern “[A-M][o-z][!a,e,I,o,u]?#.*”:<br />
<br />
{| class="wikitable" style="text-align: left"|<br />
|-<br />
!YES<br />
!NO<br />
!Why not?<br />
|-<br />
|App$5.java<br />
|Help1.<br />
| E is not in the range [o-z].<br />
|-<br />
|Dog&2.py<br />
|IoU$5<br />
|There is no . at the end.<br />
|-<br />
|LzyG3.txt<br />
|move6.py<br />
|The m is not in the range [A-M].<br />
|-<br />
|Hot90.<br />
|MaX7A.txt<br />
|The A is not a digit from 0 to 9.<br />
|}<br />
--><br />
<br />
Typical problems in the category will include: translate an FSA to a Regular Expression; simplify a Regular Expression; determine which Regular Expressions or FSAs are equivalent; and determine which strings are accepted by either an FSA or a Regular Expression.<br />
<br />
= Regular Expression Identities =<br />
<br />
{| Class="wikitable"<br />
|-<br />
|1. (a*)* = a*<br />
|-<br />
|2. aa* = a*a<br />
|-<br />
|3. aa* U λ = a*<br />
|-<br />
|4. a(b U c) = ab U ac<br />
|-<br />
|5. a(ba)* = (ab)*a<br />
|-<br />
|6. (a U b)* = (a* U b*)*<br />
|-<br />
|7. (a U b)* = (a*b*)*<br />
|-<br />
|8. (a U b)* = a*(ba*)*<br />
|}<br />
<br />
= Sample Problems =<br />
<br />
== Problem 1 ==<br />
<br />
Find a simplified Regular Expression for the following FSA:<br />
<br />
[[File:fsa_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
The expression 01*01 is read directly from the FSA. It is in its most simplified form.<br />
<br />
== Problem 2 ==<br />
<br />
Which of the following strings are accepted by the following Regular Expression "00*1*1U11*0*0" ?<br />
<br />
::A. 0000001111111<br />
::B. 1010101010<br />
::C. 1111111<br />
::D. 0110<br />
::E. 10 <br />
<br />
'''Solution:'''<br />
<br />
This Regular Expression parses strings described by the union of 00*1*1 and 11*0*0. The RE 00*1*1 are strings starting with oe or more 0s followed by one or more 1s: 01, 001, 0001111, and so on. The RE 11*0*0 are strings with one or more 1s followed by one or more 0s: 10, 1110, 1111100, and so on. In other words, strings of the form: 0s followed by some 1s; or 1s <br />
followed by some 0s. Choice A and E following this pattern.<br />
<br />
== Problem 3 ==<br />
<br />
Which, if any, of the following Regular Expressions are equivalent?<br />
::A. (aUb)(ab*)(b*Ua)<br />
::B. (aab*Ubab*)a<br />
::C. aab*Ubab*UaabaUbab*a<br />
::D. aab*Ubab*Uaab*aUbab*a<br />
::E. a*Ub* <br />
<br />
'''Solution:'''<br />
<br />
Choice B can be discarded because it is the only RE whose strings '''must''' end with an a. Choice E can be discarded since it is the only RE that can accept a null string. Choices C and D are not equal. After expanding choice A, we must compare it to choices C and D. It is equal to choice D, but not to choice C. The only REs that are equivalent are choices A and D.<br />
<br />
<!--<br />
== Problem 3 ==<br />
<br />
Which of the following strings match the regular expression pattern "?[A-D]*[a-d]*#" ?<br />
<br />
::A. 8AAAabd4<br />
::B. MM5<br />
::C. AAAAAAAA7<br />
::D. Abcd9<br />
::E. &dd88<br />
::F. >BAD0<br />
<br />
'''Solution:'''<br />
<br />
The answer is A, C, D, and F. In B the character M is not in the range A-D or a-d. In E, there cannot be more than 1 digit at the end of the string. Remember that an asterisk represents 0 or more of that character or rangle of characters.<br />
--><br />
<br />
= Video Resources =<br />
<br />
Nice two-part video showing the relationship between FSAs and REs. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/GwsU2LPs85U</youtube><br />
| [https://youtu.be/GwsU2LPs85U ''1 - Convert Regular Expression to Finite-State Automaton'' ('''Barry Brown''')]<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/shN_kHBFOUE</youtube><br />
| [https://youtu.be/shN_kHBFOUE ''2 - Convert Regular Expression to Finite-State Automaton'' ('''Barry Brown''')]<br />
<br />
This video uses the symbol "+" to mean "1 or more matches of the previous term". For example, "ab+" is the same as "abb*". <br />
|}<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&diff=586FSAs and Regular Expressions2018-09-12T13:26:31Z<p>Jerry: </p>
<hr />
<div>A Finite State Automaton (FSA) is a mathematical model of computation comprising: a finite number of ''states'', of which exactly one is ''active'' at any given time; ''transition rules'' to change<br />
the active state; an ''initial state''; and one more ''final states''. We can draw an FSA by representing each state as a circle; the final state as a double circle; the start state as the only state with an incoming arrow; and the transition rules as labeled-edges connecting the states. When labels are assigned to states, they appear inside the circle representing the state. <br />
<br />
In this category, FSAs will be limited to parsing strings. That is, determining if a string is valid or not. <br />
<br />
= Basics =<br />
<br />
Here is a drawing of an FSA that is used to parse strings consisting of x's and y's:<br />
<br />
<center><br />
[[File:fsa.svg|250px]]<br />
</center><br />
<br />
In the above FSA, there are three states: A, B, and C. The initial state is A; the final state is C. The only way to go from state A to B is by ''seeing'' the letter x. Once in state B, there are two transition rules: Seeing the letter y will cause the FSA to make C the active state, and seeing an x will keep B as the active state. State C is a final state, so if the string being parsed is completed and the FSA is in State C, the input string is said to be ''accepted'' by the FSA. In State C, seeing any additional letter y will keep the machine in state C. The FSA above will accept strings composed of one or more x’s followed by one or more y’s (e.g., xy, xxy, xxxyy, xyyy, xxyyyy). <br />
<br />
Just like [[Boolean Algebra]] there is a convenient algebraic representation of [[Digital Electronics]] Circuits. A Regular Expression (RE) is an algebraic representation of an FSA. For example, the regular expression corresponding to the first FSA given above is xx*yy*. <br />
<br />
The rules for forming a Regular Expression (RE) are as follows:<br />
:1. The null string (λ) is a RE.<br />
:2. If the string a is in the input alphabet, then it is a RE.<br />
:3. if the strings a and b are both REs, then so are the strings built up using the following rules:<br />
::a. CONCATENATION. “ab” (a followed by b).<br />
::b. UNION. “aUb” (a or b). <br />
::c. CLOSURE. “a*” (a repeated zero or more times). This is known as the Kleene Star.<br />
<br />
Identities for Regular Expressions appear in the next section. The order of precedence for Regular Expression operators is: Kleene Star, concatenation, and then union. <br />
<br />
If we have a Regular Expression, then we can mechanically build an FSA to accept the strings which are generated by the Regular Expression. Conversely, if we have an FSA, we can mechanically develop a Regular Expression which will describe the strings which can be parsed by the FSA. For a given FSA or Regular Expression, there are many others which are equivalent to it. A “most simplified” Regular Expression or FSA is not always well defined. <br />
<!--<br />
Most programming languages today have a package to handle Regular Expressions in order to do pattern matching algorithms more easily. Visual BASIC has the LIKE operator that is very easy to use. We will use these “basic” symbols in our category description.<br />
<br />
{| class="wikitable" style="text-align: left"|<br />
|-<br />
!Pattern<br />
!Description<br />
|-<br />
|?<br />
|Any single character<br />
|-<br />
|*<br />
|Zero or more of the preceding character<br />
|-<br />
|#<br />
|Any single digit<br />
|-<br />
|[ char-char,char,…]<br />
|Any inclusive range or list of characters<br />
|-<br />
|{![charlist]}<br />
|Any character not in a given range or list<br />
|}<br />
<br />
For example, the following strings either match or don’t match the pattern “[A-M][o-z][!a,e,I,o,u]?#.*”:<br />
<br />
{| class="wikitable" style="text-align: left"|<br />
|-<br />
!YES<br />
!NO<br />
!Why not?<br />
|-<br />
|App$5.java<br />
|Help1.<br />
| E is not in the range [o-z].<br />
|-<br />
|Dog&2.py<br />
|IoU$5<br />
|There is no . at the end.<br />
|-<br />
|LzyG3.txt<br />
|move6.py<br />
|The m is not in the range [A-M].<br />
|-<br />
|Hot90.<br />
|MaX7A.txt<br />
|The A is not a digit from 0 to 9.<br />
|}<br />
--><br />
<br />
Typical problems in the category will include: translate an FSA to a Regular Expression; simplify a Regular Expression; determine which Regular Expressions or FSAs are equivalent; and determine which strings are accepted by either an FSA or a Regular Expression.<br />
<br />
= Regular Expression Identities =<br />
<br />
{| Class="wikitable"<br />
|-<br />
|1. (a*)* = a*<br />
|-<br />
|2. aa* = a*a<br />
|-<br />
|3. aa* U λ = a*<br />
|-<br />
|4. a(b U c) = ab U ac<br />
|-<br />
|5. a(ba)* = (ab)*a<br />
|-<br />
|6. (a U b)* = (a* U b*)*<br />
|-<br />
|7. (a U b)* = (a*b*)*<br />
|-<br />
|8. (a U b)* = a*(ba*)*<br />
|}<br />
<br />
= Sample Problems =<br />
<br />
== Problem 1 ==<br />
<br />
Find a simplified Regular Expression for the following FSA:<br />
<br />
[[File:fsa_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
The expression 01*01 is read directly from the FSA. It is in its most simplified form.<br />
<br />
== Problem 2 ==<br />
<br />
Which of the following strings are accepted by the following Regular Expression "00*1*1U11*0*0" ?<br />
<br />
::A. 0000001111111<br />
::B. 1010101010<br />
::C. 1111111<br />
::D. 0110<br />
::E. 10 <br />
<br />
'''Solution:'''<br />
<br />
This Regular Expression parses strings described by the union of 00*1*1 and 11*0*0. The RE 00*1*1 are strings starting with oe or more 0s followed by one or more 1s: 01, 001, 0001111, and so on. The RE 11*0*0 are strings with one or more 1s followed by one or more 0s: 10, 1110, 1111100, and so on. In other words, strings of the form: 0s followed by some 1s; or 1s <br />
followed by some 0s. Choice A and E following this pattern.<br />
<br />
== Problem 3 ==<br />
<br />
Which, if any, of the following Regular Expressions are equivalent?<br />
::A. (aUb)(ab*)(b*Ua)<br />
::B. (aab*Ubab*)a<br />
::C. aab*Ubab*UaabaUbab*a<br />
::D. aab*Ubab*Uaab*aUbab*a<br />
::E. a*Ub* <br />
<br />
'''Solution:'''<br />
<br />
Choice B can be discarded because it is the only RE whose strings '''must''' end with an a. Choice E can be discarded since it is the only RE that can accept a null string. Choices C and D are not equal. After expanding choice A, we must compare it to choices C and D. It is equal to choice D, but not to choice C. The only REs that are equivalent are choices A and D.<br />
<br />
<!--<br />
== Problem 3 ==<br />
<br />
Which of the following strings match the regular expression pattern "?[A-D]*[a-d]*#" ?<br />
<br />
::A. 8AAAabd4<br />
::B. MM5<br />
::C. AAAAAAAA7<br />
::D. Abcd9<br />
::E. &dd88<br />
::F. >BAD0<br />
<br />
'''Solution:'''<br />
<br />
The answer is A, C, D, and F. In B the character M is not in the range A-D or a-d. In E, there cannot be more than 1 digit at the end of the string. Remember that an asterisk represents 0 or more of that character or rangle of characters.<br />
--><br />
<br />
= Video Resources =<br />
<br />
Nice two-part video showing the relationship between FSAs and REs. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/GwsU2LPs85U</youtube><br />
| [https://youtu.be/GwsU2LPs85U ''1 - Convert Regular Expression to Finite-State Automaton'' ('''Barry Brown''')]<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/shN_kHBFOUE</youtube><br />
| [https://youtu.be/shN_kHBFOUE ''2 - Convert Regular Expression to Finite-State Automaton'' ('''Barry Brown''')]<br />
<br />
This video uses the symbol "+" to mean "1 or more matches of the previous term". For example, "ab+" is the same as "abb*". <br />
|}<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=FSAs_and_Regular_Expressions&diff=585FSAs and Regular Expressions2018-09-12T13:25:35Z<p>Jerry: </p>
<hr />
<div>A Finite State Automaton (FSA) is a mathematical model of computation comprising: a finite number of ''states'', of which exactly one is ''active'' at any given time; ''transition rules'' to change<br />
the active state; an ''initial state''; and one more ''final states''. We can draw an FSA by representing each state as a circle; the final state as a double circle; the start state as the only state with an incoming arrow; and the transition rules as labeled-edges connecting the states. When labels are assigned to states, they appear inside the circle representing the state. <br />
<br />
In this category, FSAs will be limited to parsing strings. That is, determining if a string is valid or not. <br />
<br />
= Basics =<br />
<br />
Here is a drawing of an FSA that is used to parse strings consisting of x's and y's:<br />
<br />
<center><br />
[[File:fsa.svg|250px]]<br />
</center><br />
<br />
In the above FSA, there are three states: A, B, and C. The initial state is A; the final state is C. The only way to go from state A to B is by ''seeing'' the letter x. Once in state B, there are two transition rules: Seeing the letter y will cause the FSA to make C the active state, and seeing an x will keep B as the active state. State C is a final state, so if the string being parsed is completed and the FSA is in State C, the input string is said to be ''accepted'' by the FSA. In State C, seeing any additional letter y will keep the machine in state C. The FSA above will accept strings composed of one or more x’s followed by one or more y’s (e.g., xy, xxy, xxxyy, xyyy, xxyyyy). <br />
<br />
AJust like [[Boolean Algebra]] there is a convenient algebraic representation of [[Digital Electronics]] Circuits. A Regular Expression (RE) is an algebraic representation of an FSA. For example, the regular expression corresponding to the first FSA given above is xx*yy*. <br />
<br />
The rules for forming a Regular Expression (RE) are as follows:<br />
:1. The null string (λ) is a RE.<br />
:2. If the string a is in the input alphabet, then it is a RE.<br />
:3. if the strings a and b are both REs, then so are the strings built up using the following rules:<br />
::a. CONCATENATION. “ab” (a followed by b).<br />
::b. UNION. “aUb” (a or b). <br />
::c. CLOSURE. “a*” (a repeated zero or more times). This is known as the Kleene Star.<br />
<br />
Identities for Regular Expressions appear in the next section. The order of precedence for Regular Expression operators is: Kleene Star, concatenation, and then union. <br />
<br />
If we have a Regular Expression, then we can mechanically build an FSA to accept the strings which are generated by the Regular Expression. Conversely, if we have an FSA, we can mechanically develop a Regular Expression which will describe the strings which can be parsed by the FSA. For a given FSA or Regular Expression, there are many others which are equivalent to it. A “most simplified” Regular Expression or FSA is not always well defined. <br />
<!--<br />
Most programming languages today have a package to handle Regular Expressions in order to do pattern matching algorithms more easily. Visual BASIC has the LIKE operator that is very easy to use. We will use these “basic” symbols in our category description.<br />
<br />
{| class="wikitable" style="text-align: left"|<br />
|-<br />
!Pattern<br />
!Description<br />
|-<br />
|?<br />
|Any single character<br />
|-<br />
|*<br />
|Zero or more of the preceding character<br />
|-<br />
|#<br />
|Any single digit<br />
|-<br />
|[ char-char,char,…]<br />
|Any inclusive range or list of characters<br />
|-<br />
|{![charlist]}<br />
|Any character not in a given range or list<br />
|}<br />
<br />
For example, the following strings either match or don’t match the pattern “[A-M][o-z][!a,e,I,o,u]?#.*”:<br />
<br />
{| class="wikitable" style="text-align: left"|<br />
|-<br />
!YES<br />
!NO<br />
!Why not?<br />
|-<br />
|App$5.java<br />
|Help1.<br />
| E is not in the range [o-z].<br />
|-<br />
|Dog&2.py<br />
|IoU$5<br />
|There is no . at the end.<br />
|-<br />
|LzyG3.txt<br />
|move6.py<br />
|The m is not in the range [A-M].<br />
|-<br />
|Hot90.<br />
|MaX7A.txt<br />
|The A is not a digit from 0 to 9.<br />
|}<br />
--><br />
<br />
Typical problems in the category will include: translate an FSA to a Regular Expression; simplify a Regular Expression; determine which Regular Expressions or FSAs are equivalent; and determine which strings are accepted by either an FSA or a Regular Expression.<br />
<br />
= Regular Expression Identities =<br />
<br />
{| Class="wikitable"<br />
|-<br />
|1. (a*)* = a*<br />
|-<br />
|2. aa* = a*a<br />
|-<br />
|3. aa* U λ = a*<br />
|-<br />
|4. a(b U c) = ab U ac<br />
|-<br />
|5. a(ba)* = (ab)*a<br />
|-<br />
|6. (a U b)* = (a* U b*)*<br />
|-<br />
|7. (a U b)* = (a*b*)*<br />
|-<br />
|8. (a U b)* = a*(ba*)*<br />
|}<br />
<br />
= Sample Problems =<br />
<br />
== Problem 1 ==<br />
<br />
Find a simplified Regular Expression for the following FSA:<br />
<br />
[[File:fsa_s1.png]]<br />
<br />
'''Solution:'''<br />
<br />
The expression 01*01 is read directly from the FSA. It is in its most simplified form.<br />
<br />
== Problem 2 ==<br />
<br />
Which of the following strings are accepted by the following Regular Expression "00*1*1U11*0*0" ?<br />
<br />
::A. 0000001111111<br />
::B. 1010101010<br />
::C. 1111111<br />
::D. 0110<br />
::E. 10 <br />
<br />
'''Solution:'''<br />
<br />
This Regular Expression parses strings described by the union of 00*1*1 and 11*0*0. The RE 00*1*1 are strings starting with oe or more 0s followed by one or more 1s: 01, 001, 0001111, and so on. The RE 11*0*0 are strings with one or more 1s followed by one or more 0s: 10, 1110, 1111100, and so on. In other words, strings of the form: 0s followed by some 1s; or 1s <br />
followed by some 0s. Choice A and E following this pattern.<br />
<br />
== Problem 3 ==<br />
<br />
Which, if any, of the following Regular Expressions are equivalent?<br />
::A. (aUb)(ab*)(b*Ua)<br />
::B. (aab*Ubab*)a<br />
::C. aab*Ubab*UaabaUbab*a<br />
::D. aab*Ubab*Uaab*aUbab*a<br />
::E. a*Ub* <br />
<br />
'''Solution:'''<br />
<br />
Choice B can be discarded because it is the only RE whose strings '''must''' end with an a. Choice E can be discarded since it is the only RE that can accept a null string. Choices C and D are not equal. After expanding choice A, we must compare it to choices C and D. It is equal to choice D, but not to choice C. The only REs that are equivalent are choices A and D.<br />
<br />
<!--<br />
== Problem 3 ==<br />
<br />
Which of the following strings match the regular expression pattern "?[A-D]*[a-d]*#" ?<br />
<br />
::A. 8AAAabd4<br />
::B. MM5<br />
::C. AAAAAAAA7<br />
::D. Abcd9<br />
::E. &dd88<br />
::F. >BAD0<br />
<br />
'''Solution:'''<br />
<br />
The answer is A, C, D, and F. In B the character M is not in the range A-D or a-d. In E, there cannot be more than 1 digit at the end of the string. Remember that an asterisk represents 0 or more of that character or rangle of characters.<br />
--><br />
<br />
= Video Resources =<br />
<br />
Nice two-part video showing the relationship between FSAs and REs. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/GwsU2LPs85U</youtube><br />
| [https://youtu.be/GwsU2LPs85U ''1 - Convert Regular Expression to Finite-State Automaton'' ('''Barry Brown''')]<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/shN_kHBFOUE</youtube><br />
| [https://youtu.be/shN_kHBFOUE ''2 - Convert Regular Expression to Finite-State Automaton'' ('''Barry Brown''')]<br />
<br />
This video uses the symbol "+" to mean "1 or more matches of the previous term". For example, "ab+" is the same as "abb*". <br />
|}<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Assembly_Language_Programming&diff=457Assembly Language Programming2018-08-29T17:51:23Z<p>Jerry: </p>
<hr />
<div>Programs written in high-level languages are traditionally converted by compilers into assembly language, which is turned into machine language programs – sequences of 1’s and 0’s – by an assembler. Even today, with very good quality compilers available, there is the need for programmers to understand assembly language. First, it provides programmers with a better understanding of the compiler and its constraints. Second, on occasion, programmers find themselves needing to program directly in assembly language in order to meet constraints in execution speed or space. <br />
<br />
ACSL chose to define its own assembly language rather than use a “real” one in order to eliminate the many sticky details associated with real languages. The basic concepts of our ACSL topic description are common to all assembly languages. <br />
<br />
== Reference Manual ==<br />
<br />
Execution starts at the first line of the program and continues sequentially, except for branch instructions (BG, BE, BL, BU), until the end instruction (END) is encountered. The result of each operation is stored in a special word of memory, called the “accumulator” (ACC). Each line of an assembly language program has the following fields (lower-case indicates optional components):<br />
<br />
label OPCODE LOC comments<br />
<br />
The ''label'' is a character string beginning in the first column. Valid OPCODE’s are listed in the chart below. The LOC field is either a reference to a label or ''immediate data''. For example, “LOAD A” would put the contents referenced by the label “A” into the ACC; “LOAD =123” would store the value 123 in the ACC. Only those instructions that do not modify the LOC field can use the “immediate data” format. In the following chart, they are indicated by an asterisk in the first column.<br />
<br />
{| class="wikitable" style="text-align: left"|<br />
|-<br />
!OP CODE<br />
!DESCRIPTION<br />
<br />
|-<br />
!*LOAD<br />
|The contents of LOC are placed in the ACC. LOC is unchanged.<br />
<br />
|-<br />
!STORE<br />
|The contents of LOC are placed in the LOC. ACC is unchanged.<br />
<br />
|-<br />
!*ADD<br />
|The contents of LOC are added to the contents of the ACC. The sum is stored in the ACC. LOC is unchanged. Addition is modulo 1,000,000.<br />
<br />
|-<br />
!*SUB<br />
|The contents of LOC are subtracted from the contents of the ACC. The difference is stored in the ACC. LOC is unchanged. Subtraction is modulo 1,000,000.<br />
<br />
|-<br />
!*MULT<br />
|The contents of LOC are multiplied by the contents of the ACC. The product is stored in the ACC. LOC is unchanged. Multiplication is modulo 1,000,000.<br />
<br />
|-<br />
!*DIV<br />
|The contents of LOC are divided into the contents of the ACC. The signed integer part of the quotient is stored in the ACC. LOC is unchanged.<br />
.<br />
|-<br />
!BG<br />
|<br />
Branch to the instruction labeled with LOC if ACC>0.<br />
<br />
|-<br />
!BE<br />
|<br />
Branch to the instruction labeled with LOC if ACC=0.<br />
<br />
|-<br />
!BL<br />
|<br />
Branch to the instruction labeled with LOC if ACC<0.<br />
<br />
|-<br />
!BU<br />
|Branch to the instruction labeled with LOC.<br />
<br />
|-<br />
!READ<br />
|<br />
Read a signed integer (modulo 1,000,000) into LOC.<br />
<br />
|-<br />
!PRINT<br />
|<br />
Print the contents of LOC.<br />
<br />
|-<br />
!DC<br />
|<br />
The value of the memory word defined by the LABEL field is defined to contain the specified constant. The LABEL field is mandatory for this opcode. The ACC is not modified.<br />
<br />
|-<br />
!END<br />
| <br />
Program terminates. LOC field is ignored.<br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
=== Sample Problem 1 ===<br />
<br />
After the following program is executed, <br />
what value is in location TEMP?<br />
<br />
{|class="wikitable" style="text-align: left"<br />
|TEMP || DC || 0<br />
|-<br />
|A||DC||8<br />
|-<br />
|B||DC||-2<br />
|-<br />
|C||DC||3<br />
|-<br />
| ||LOAD||B<br />
|-<br />
| ||MULT||C<br />
|-<br />
| ||ADD||A<br />
|-<br />
| ||DIV||B<br />
|-<br />
| ||SUB||A<br />
|-<br />
| ||STORE||TEMP<br />
|-<br />
| ||END||<br />
|}<br />
<br />
'''Solution:''' The ACC takes on values -2, -6, 2, -1, and -9 in that order. The last value, -9, is stored in location TEMP.<br />
<br />
=== Sample Problem 2 ===<br />
<br />
If the following program has an input value<br />
of N, what is the final value of X which is<br />
computed? Express X as an algebraic<br />
expression in terms of N. <br />
<br />
{|class="wikitable" style="text-align: left"<br />
| || READ || X<br />
|-<br />
| || LOAD || X<br />
|-<br />
|TOP || SUB || =1<br />
|-<br />
| || BE || DONE<br />
|-<br />
| || STORE || A<br />
|-<br />
| || MULT || X<br />
|-<br />
| || STORE || X<br />
|-<br />
| || LOAD || A<br />
|-<br />
| || BU || TOP<br />
|-<br />
|DONE || END || <br />
|}<br />
<br />
'''Solution:''' This program loops between labels TOP and<br />
DONE for A times. A has an initial value of X and subsequent terms of N,<br />
then values of A-1, A-2, …, 1. Each time through the loop,<br />
X is multiplied by the the current value of A.<br />
Thus, X = A * (A-1) * (A-2) * … * 1 or X=A! or A factorial.<br />
For example, 5! = 5 * 4 * 3 * 2 * 1 = 120. Since the<br />
initial value of A is the number input (i.e. N),<br />
the algebraic expression is X = N!.<br />
<br />
== Video Resources ==<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/RUm3iHsbO3I</youtube><br />
| [https://youtu.be/RUm3iHsbO3I ''Intro to Assembly Language'' ('''CalculusNguyenify''')]<br />
<br />
A general introduction into assembly language. In particular, it covers how it fits into the source code to an executable image pipeline.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/i_JYT398O64</youtube><br />
| [https://youtu.be/i_JYT398O64 ''Syntax of ACSL Assembly Language'' ('''CalculusNguyenify''')]<br />
<br />
A very nice introduction to this ACSL category.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/NEQASUsZ0g4</youtube><br />
| [https://youtu.be/NEQASUsZ0g4 ''Examples'' ('''CalculusNguyenify''')]<br />
<br />
Walks through a couple of ACSL Assembly language programs that have been used in previous contests.<br />
<br />
|}<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=456What Does This Program Do?2018-08-24T15:05:51Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ or ↑(exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|Strings can contain 0 or more characters and the indexed position starts with 0 at the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [ ] for identifying the characters in a substring of a given string as follows: <br />
S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)<br />
<br />
S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
<br />
S[5:] = “WDTPD” (take the last 5 characters starting on the right) <br />
<br />
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)<br />
<br />
S[0] = “A” (position 0 only). <br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! | B || H<br />
|-<br />
| | 0 || 50<br />
|-<br />
| | 40 || 48<br />
|-<br />
| | 160 || 40<br />
|-<br />
| | 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=455What Does This Program Do?2018-08-24T15:04:25Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ or ↑(exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|Strings can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [ ] for identifying the characters in a substring of a given string as follows: <br />
S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)<br />
<br />
S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
<br />
S[5:] = “WDTPD” (take the last 5 characters starting on the right) <br />
<br />
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)<br />
<br />
S[0] = “A” (position 0 only). <br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! | B || H<br />
|-<br />
| | 0 || 50<br />
|-<br />
| | 40 || 48<br />
|-<br />
| | 160 || 40<br />
|-<br />
| | 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=454What Does This Program Do?2018-08-24T15:02:31Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ or ↑(exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [ ] for identifying the characters in a substring of a given string as follows: <br />
S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)<br />
<br />
S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
<br />
S[5:] = “WDTPD” (take the last 5 characters starting on the right) <br />
<br />
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)<br />
<br />
S[0] = “A” (position 0 only). <br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! | B || H<br />
|-<br />
| | 0 || 50<br />
|-<br />
| | 40 || 48<br />
|-<br />
| | 160 || 40<br />
|-<br />
| | 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=453What Does This Program Do?2018-08-24T14:56:20Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [ ] for identifying the characters in a substring of a given string as follows: <br />
S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)<br />
<br />
S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
<br />
S[5:] = “WDTPD” (take the last 5 characters starting on the right) <br />
<br />
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)<br />
<br />
S[0] = “A” (position 0 only). <br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! | B || H<br />
|-<br />
| | 0 || 50<br />
|-<br />
| | 40 || 48<br />
|-<br />
| | 160 || 40<br />
|-<br />
| | 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=452What Does This Program Do?2018-08-24T14:53:05Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: <br />
S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)<br />
<br />
S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
<br />
S[5:] = “WDTPD” (take the last 5 characters starting on the right) <br />
<br />
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)<br />
<br />
S[0] = “A” (position 0 only). <br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! | B || H<br />
|-<br />
| | 0 || 50<br />
|-<br />
| | 40 || 48<br />
|-<br />
| | 160 || 40<br />
|-<br />
| | 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=451What Does This Program Do?2018-08-24T14:50:35Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: <br />
S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)<br />
<br />
S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
<br />
S[5:] = “WDTPD” (take the last 5 characters starting on the right) <br />
<br />
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)<br />
<br />
S[0] = “A” (position 0 only). <br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! || B || H<br />
|-<br />
| || 0 || 50<br />
|-<br />
| || 40 || 48<br />
|-<br />
| || 160 || 40<br />
|-<br />
| || 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=450What Does This Program Do?2018-08-24T14:49:48Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: <br />
S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)<br />
S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
<br />
S[5:] = “WDTPD” (take the last 5 characters starting on the right) <br />
<br />
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)<br />
<br />
S[0] = “A” (position 0 only). <br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! || B || H<br />
|-<br />
| || 0 || 50<br />
|-<br />
| || 40 || 48<br />
|-<br />
| || 160 || 40<br />
|-<br />
| || 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=449What Does This Program Do?2018-08-24T14:48:53Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: <br />
S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)<br />
S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
S[5:] = “WDTPD” (take the last 5 characters starting on the right) <br />
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)<br />
S[0] = “A” (position 0 only). <br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! || B || H<br />
|-<br />
| || 0 || 50<br />
|-<br />
| || 40 || 48<br />
|-<br />
| || 160 || 40<br />
|-<br />
| || 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=448What Does This Program Do?2018-08-24T14:45:59Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: <br />
|S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)<br />
|S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
|S[5:] = “WDTPD” (take the last 5 characters starting on the right) <br />
|S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)<br />
|S[0] = “A” (position 0 only). <br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! || B || H<br />
|-<br />
| || 0 || 50<br />
|-<br />
| || 40 || 48<br />
|-<br />
| || 160 || 40<br />
|-<br />
| || 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=447What Does This Program Do?2018-08-24T14:44:37Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: <br />
S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)<br />
S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
S[5:] = “WDTPD” (take the last 5 characters starting on the right) <br />
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)<br />
S[0] = “A” (position 0 only). <br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! || B || H<br />
|-<br />
| || 0 || 50<br />
|-<br />
| || 40 || 48<br />
|-<br />
| || 160 || 40<br />
|-<br />
| || 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=446What Does This Program Do?2018-08-24T13:36:43Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: <br />
If S = “ACSL WDTPD”, then S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
S[5:] = “WDTPD” (take the last 5 characters starting on the right) <br />
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6), and S[0] = “A” (position 0 only). <br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! || B || H<br />
|-<br />
| || 0 || 50<br />
|-<br />
| || 40 || 48<br />
|-<br />
| || 160 || 40<br />
|-<br />
| || 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=445What Does This Program Do?2018-08-24T13:33:49Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: If S = “ACSL WDTPD”, then S[:3] = “ACS” (take the first 3 characters starting on the left) <br />
S[5:] = “WDTPD” (take the last 5 characters starting on the right), S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6), and S[0] = “A” (position 0 only). The value of len(A) is 10.<br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! || B || H<br />
|-<br />
| || 0 || 50<br />
|-<br />
| || 40 || 48<br />
|-<br />
| || 160 || 40<br />
|-<br />
| || 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=444What Does This Program Do?2018-08-24T13:31:36Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: If S = “ACSL WDTPD”, then S[:3] = “ACS” (take the first 3 characters starting on the left), S[5:] = “WDTPD” (take the last 5 characters starting on the right), S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6), and S[0] = “A” (position 0 only). The value of len(A) is 10.<br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
! || B || H<br />
|-<br />
| || 0 || 50<br />
|-<br />
| || 40 || 48<br />
|-<br />
| || 160 || 40<br />
|-<br />
| || 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
:: A = “BANANAS”<br />
:: NUM = 0: T = “”<br />
:: for J = len(A) - 1 to 0 step –1<br />
:: T = T + A[j]<br />
:: next <br />
:: for J = 0 to len(A) - 1<br />
:: if A[J] == T[J] then NUM = NUM + 1<br />
:: next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
:: A(0) = 12: A(1) = 41: A(2) = 52<br />
:: A(3) = 57: A(4) = 77: A(5) = -100<br />
:: B(0) = 17: B(1) = 34: B(20 = 81<br />
:: J = 0: K = 0: N = 0<br />
:: while A(J) > 0<br />
:: while B(K) <= A(J)<br />
:: C(N) = B(K)<br />
:: N = N + 1<br />
:: k = k + 1<br />
:: end while<br />
:: C(N) = A(J): N = N + 1: J = J + 1<br />
:: end while<br />
:: C(N) = B(K)<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A(J)<br />
!B(K)<br />
!C(N)<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C(4) is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=443What Does This Program Do?2018-08-24T13:24:03Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: If S = “ACSL WDTPD”, then S[:3] = “ACS” (take the first 3 characters starting on the left), S[5:] = “WDTPD” (take the last 5 characters starting on the right), S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6), and S[0] = “A” (position 0 only). The value of len(A) is 10.<br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
:: B = 0<br />
:: if H>48 then<br />
:: B = B + (H - 48) * 2 * R<br />
:: H = 48<br />
:: end if<br />
:: if H>40 then<br />
:: B = B + (H - 40) * (3/2) * R<br />
:: H = 40<br />
:: end if<br />
:: B = B + H * R<br />
:: output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
!LINE || B || H<br />
|-<br />
|20 || 0 || 50<br />
|-<br />
|50 || 40 || 48<br />
|-<br />
|90 || 160 || 40<br />
|-<br />
|110 || 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
::10 A = “BANANAS”<br />
::20 NUM = 0: T = “”<br />
::30 for J = len(A) - 1 to 0 step –1<br />
::40 T = T + A[j]<br />
::50 next <br />
::60 for J = 0 to len(A) - 1<br />
::70 if A[J] == T[J] then NUM = NUM + 1<br />
::80 next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
::10 A[0] = 12: A[1] = 41: A[2] = 52<br />
::20 A[3] = 57: A[4] = 77: A[5] = -100<br />
::30 B[0] = 17: B[1] = 34: B[2] = 81<br />
::40 J = 0: K = 0: N = 0<br />
::50 while A[J] > 0<br />
::60 while B[K] <= A[J]<br />
::70 C[N] = B[K]<br />
::80 N = N + 1<br />
::90 k = k + 1<br />
::100 end while<br />
::110 C[N] = A[J]: N = N + 1: J = J + 1<br />
::120 end while<br />
::130 C[N] = B[K]<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A[J]<br />
!B[K]<br />
!C[N]<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C[4] is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=442What Does This Program Do?2018-08-24T13:22:36Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: If S = “ACSL WDTPD”, then S[:3] = “ACS” (take the first 3 characters starting on the left), S[5:] = “WDTPD” (take the last 5 characters starting on the right), S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6), and S[0] = “A” (position 0 only). The value of len(A) is 10.<br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
:: input H, R<br />
::20 B = 0<br />
::30 if H>48 then<br />
::40 B = B + (H - 48) * 2 * R<br />
::50 H = 48<br />
::60 end if<br />
::70 if H>40 then<br />
::80 B = B + (H - 40) * (3/2) * R<br />
::90 H = 40<br />
::100 end if<br />
::110 B = B + H * R<br />
::120 output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
!LINE || B || H<br />
|-<br />
|20 || 0 || 50<br />
|-<br />
|50 || 40 || 48<br />
|-<br />
|90 || 160 || 40<br />
|-<br />
|110 || 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
::10 A = “BANANAS”<br />
::20 NUM = 0: T = “”<br />
::30 for J = len(A) - 1 to 0 step –1<br />
::40 T = T + A[j]<br />
::50 next <br />
::60 for J = 0 to len(A) - 1<br />
::70 if A[J] == T[J] then NUM = NUM + 1<br />
::80 next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
::10 A[0] = 12: A[1] = 41: A[2] = 52<br />
::20 A[3] = 57: A[4] = 77: A[5] = -100<br />
::30 B[0] = 17: B[1] = 34: B[2] = 81<br />
::40 J = 0: K = 0: N = 0<br />
::50 while A[J] > 0<br />
::60 while B[K] <= A[J]<br />
::70 C[N] = B[K]<br />
::80 N = N + 1<br />
::90 k = k + 1<br />
::100 end while<br />
::110 C[N] = A[J]: N = N + 1: J = J + 1<br />
::120 end while<br />
::130 C[N] = B[K]<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A[J]<br />
!B[K]<br />
!C[N]<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C[4] is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=441What Does This Program Do?2018-08-24T13:21:30Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: If S = “ACSL WDTPD”, then S[:3] = “ACS” (take the first 3 characters starting on the left), S[5:] = “WDTPD” (take the last 5 characters starting on the right), S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6), and S[0] = “A” (position 0 only). The value of len(A) is 10.<br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
10 input H, R<br />
::20 B = 0<br />
::30 if H>48 then<br />
::40 B = B + (H - 48) * 2 * R<br />
::50 H = 48<br />
::60 end if<br />
::70 if H>40 then<br />
::80 B = B + (H - 40) * (3/2) * R<br />
::90 H = 40<br />
::100 end if<br />
::110 B = B + H * R<br />
::120 output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
!LINE || B || H<br />
|-<br />
|20 || 0 || 50<br />
|-<br />
|50 || 40 || 48<br />
|-<br />
|90 || 160 || 40<br />
|-<br />
|110 || 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
::10 A = “BANANAS”<br />
::20 NUM = 0: T = “”<br />
::30 for J = len(A) - 1 to 0 step –1<br />
::40 T = T + A[j]<br />
::50 next <br />
::60 for J = 0 to len(A) - 1<br />
::70 if A[J] == T[J] then NUM = NUM + 1<br />
::80 next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
::10 A[0] = 12: A[1] = 41: A[2] = 52<br />
::20 A[3] = 57: A[4] = 77: A[5] = -100<br />
::30 B[0] = 17: B[1] = 34: B[2] = 81<br />
::40 J = 0: K = 0: N = 0<br />
::50 while A[J] > 0<br />
::60 while B[K] <= A[J]<br />
::70 C[N] = B[K]<br />
::80 N = N + 1<br />
::90 k = k + 1<br />
::100 end while<br />
::110 C[N] = A[J]: N = N + 1: J = J + 1<br />
::120 end while<br />
::130 C[N] = B[K]<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A[J]<br />
!B[K]<br />
!C[N]<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C[4] is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=What_Does_This_Program_Do%3F&diff=440What Does This Program Do?2018-08-24T13:17:06Z<p>Jerry: </p>
<hr />
<div>Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, it is essential to be able to read and understand an arbitrary program. This category has been rewritten using pseudocode similar to the design of the AP CS Principles course. Pseudo-code is English-like, language independent algorithmic code and should be able to be traced by students regardless of whether they are familiar with BASIC, C++, Java, Python, or any other high level language.<br />
<br />
= Description of Pseudo-code =<br />
<br />
We will use the following constructs in writing this code for this topic in ACSL:<br />
<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
!'''Construct'''<br />
!'''Code Segment'''<br />
|-<br />
|Operators<br />
|! (not) , ^ (exponent), *, / (real division), % (modulus), +, -, >, <, >=, <=, !=, ==, && (and), <math>||</math> (or) in that order of precedence<br />
|-<br />
|Variables<br />
|Start with a letter, only letters and digits<br />
|-<br />
|Sequential statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|INPUT variable<br />
|-<br />
|variable = expression (assignment)<br />
|-<br />
|OUTPUT variable<br />
|}<br />
|-<br />
|Decision statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|IF boolean expression THEN<br />
|-<br />
|Statement(s)<br />
|-<br />
|ELSE (optional)<br />
|-<br />
|Statement(s)<br />
|-<br />
|END IF<br />
|}<br />
|-<br />
|Indefinite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|WHILE Boolean expression<br />
|-<br />
| Statement(s)<br />
|-<br />
|END WHILE<br />
|}<br />
|-<br />
|Definite Loop statements<br />
|<br />
{| class="wikitable" style="text-align: left"<br />
|-<br />
|FOR variable = start TO end STEP increment<br />
|-<br />
| Statement(s)<br />
|-<br />
|NEXT<br />
|}<br />
|-<br />
|Arrays:<br />
|1 dimension arrays use a single subscript such as A(5). 2 dimension arrays use (row, col) order such as A(2,3). Arrays can start at location 0 for 1 dimension arrays and location (0,0) for 2 dimension arrays. Most ACSL past problems start with either A(1) or A(1,1). The size of the array will usually be specified in the problem statement.<br />
|-<br />
|Strings:<br />
|They can contain 0 or more characters and the indexed position starts with 0 as the first character. An empty string has a length of 0. Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger. The len(A) function will find the length of the string which is the total characters. Strings are identified with surrounding double quotes. Use [] for identifying the characters in a substring of a given string as follows: If S = “ACSL WDTPD”, then S[:3] = “ACS” (take the first 3 characters starting on the left), S[5:] = “WDTPD” (take the last 5 characters starting on the right), S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6), and S[0] = “A” (position 0 only). The value of len(A) is 10.<br />
|}<br />
<br />
The questions in this topic will cover any of the above constructs in the Intermediate and Senior Division. In the Junior Division, loops will not be included in contest 1; loops will be used in contest 2; strings will be used in contest 3; and arrays will be included in contest 4. <br />
= Sample Problems =<br />
<br />
== Sample Problem 1 ==<br />
<br />
After this program is executed, what is the value of B that is printed if the input values are 50 and 10?<br />
::10 input H, R<br />
::20 B = 0<br />
::30 if H>48 then<br />
::40 B = B + (H - 48) * 2 * R<br />
::50 H = 48<br />
::60 end if<br />
::70 if H>40 then<br />
::80 B = B + (H - 40) * (3/2) * R<br />
::90 H = 40<br />
::100 end if<br />
::110 B = B + H * R<br />
::120 output B<br />
<br />
'''Solution:'''<br />
<br />
This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid an hourly rate for the number of hours worked, up to 40, time and a half for the overtime hours, up to 48 hours, and double for all hours over 48. The table monitors variables B and H:<br />
{| class="wikitable"<br />
|-<br />
!LINE || B || H<br />
|-<br />
|20 || 0 || 50<br />
|-<br />
|50 || 40 || 48<br />
|-<br />
|90 || 160 || 40<br />
|-<br />
|110 || 560 || 40<br />
|}<br />
<br />
Therefore, the final value of B is 2*2*10 + 8*3/2*10 + 40*10 = 40 + 120 + 400 = 560.<br />
<br />
== Sample Problem 2 ==<br />
<br />
After the following program is executed, what is the final value of NUM?<br />
::10 A = “BANANAS”<br />
::20 NUM = 0: T = “”<br />
::30 for J = len(A) - 1 to 0 step –1<br />
::40 T = T + A[j]<br />
::50 next <br />
::60 for J = 0 to len(A) - 1<br />
::70 if A[J] == T[J] then NUM = NUM + 1<br />
::80 next<br />
<br />
'''Solution:'''<br />
<br />
The program first stores the reverse of variable A into variable T and then counts the number of letters that are in the same position in both strings.<br />
A B A N A N A S<br />
T S A N A N A B<br />
* * * * * <br />
Those positions marked with an asterisk contribute one to the value of NUM. There are 5 such positions. <br />
<br />
== Sample Problem 3 ==<br />
<br />
After the following program is executed, what is the final value of C[4]?<br />
::10 A[0] = 12: A[1] = 41: A[2] = 52<br />
::20 A[3] = 57: A[4] = 77: A[5] = -100<br />
::30 B[0] = 17: B[1] = 34: B[2] = 81<br />
::40 J = 0: K = 0: N = 0<br />
::50 while A[J] > 0<br />
::60 while B[K] <= A[J]<br />
::70 C[N] = B[K]<br />
::80 N = N + 1<br />
::90 k = k + 1<br />
::100 end while<br />
::110 C[N] = A[J]: N = N + 1: J = J + 1<br />
::120 end while<br />
::130 C[N] = B[K]<br />
<br />
'''Solution:'''<br />
<br />
The following table traces the variables through the execution of the program. <br />
<br />
{| class="wikitable" <br />
|-<br />
!J<br />
!K<br />
!N<br />
!A[J]<br />
!B[K]<br />
!C[N]<br />
|-<br />
|0 || 0 || 0 || 12 || 17 || 12<br />
|-<br />
|1 || 0 || 1 || 41 || 17 || 17<br />
|-<br />
|1 || 1 || 2 || 41 || 34 || 34<br />
|-<br />
|1 || 2 || 3 || 41 || 81 || 41<br />
|-<br />
|2 || 2 || 4 || 52 || 81 || 52<br />
|-<br />
|3 || 2 || 5 || 57 || 81 || 57<br />
|-<br />
|4 || 2 || 6 || 77 || 81 || 77<br />
|-<br />
|5 || 2 || 7 || -100 || 81 || 81<br />
|}<br />
<br />
Thus, the value of C[4] is 52. Note that this program merges two arrays in increasing order into one array until a negative number is input.<br />
<br />
= Video Resources =<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=248Boolean Algebra2018-08-16T17:04:03Z<p>Jerry: </p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
The basic operators in Boolean algebra are ''and'', ''or'', and ''not''. The secondary operators are ''exclusive or'' (often called ''xor'') and ''exclusive nor'' (sometimes called ''equivalence''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
*The ''and'' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The ''or'' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x + y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The ''not'' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>\overline{x}</math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The ''xor'' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \oplus y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The ''xnor'' of two values is true whenever the values are the same. It is the ''not'' of the ''xor'' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \odot y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
==Why is Boolean Algebra Important for ACSL Students?==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression "jaguar speed -car is the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as is it were written $x \cdot \overline{(y + z)}.$<br />
<br />
===Order of Precedence===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
===Fundamental Identities===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify means writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Sample Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Sample Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Computer_Number_Systems&diff=247Computer Number Systems2018-08-16T14:05:10Z<p>Jerry: </p>
<hr />
<div>All digital computers – from supercomputers to your smartphone – ultimately can do one thing: detect whether an electrical signal is on or off. <br />
That basic information, called a ''bit'' ('''bi'''nary digi'''t'''), has two values: a 1 (or ''true'') when the signal is on, and a 0 (of ''false'') when the signal is off. Larger values can be stored by a group of bits. For example, 3 bits together can take on 8 different values. <br />
<br />
Computer scientists use the [https://en.wikipedia.org/wiki/Binary_number binary number system] (that is, base 2) to represent the values of bits. Proficiency in the binary number system is essential to understanding how numbers and information are represented in a computer. Since binary numbers representing moderate values quickly become rather lengthy, bases eight ([https://en.wikipedia.org/wiki/Octal octal]) and sixteen ([https://en.wikipedia.org/wiki/Hexadecimal hexadecimal]) are frequently used as shorthand. In octal, groups of 3 bits form a single octal digit; in hexadecimal, groups of 4 bits form a single hex digit.<br />
<br />
In this category, we will focus on conversion between binary, octal, decimal, and hexadecimal numbers. There may be some arithmetic in these bases, and occasionally, a number with a fractional part. We will not cover how negative numbers or floating point numbers are represented in binary.<br />
<br />
== Resources ==<br />
<br />
[https://ryanstutorials.net/ Ryan's Tutorials] covers this topic beautifully. Rather than trying to duplicate that work, we'll point you to the different sections:<br />
<br />
:[https://ryanstutorials.net/binary-tutorial/ 1. Number Systems] - An introduction to what numbers systems are all about, with emphasis on decimal, binary, octal, and hexadecimal. ACSL will typically identify the base of a number using a subscript. For example, $123_8$ is an octal number, whereas $123_{16}$ is a hexadecimal number. <br />
<br />
:[https://ryanstutorials.net/binary-tutorial/binary-conversions.php 2. Binary Conversions] - This section shows how to convert between binary, decimal, hexadecimal and octal numbers. In the [https://ryanstutorials.net/binary-tutorial/binary-conversions.php#activities ''Activities''] section, you can practice converting numbers. <br />
<br />
:[https://ryanstutorials.net/binary-tutorial/binary-arithmetic.php 3. Binary Arithmetic] - Describes how to perform various arithmetic operations (addition, subtraction, multiplication, and division) with binary numbers. ACSL problems will also cover basic arithmetic in other bases, such as adding and subtracting together 2 hexadecimal numbers. ACSL problems will not cover division in other bases.<br />
<br />
:[https://ryanstutorials.net/binary-tutorial/binary-negative-numbers.php 4. Negative Numbers] - ACSL problems will not cover how negative numbers are represented in binary. <br />
<br />
:[https://ryanstutorials.net/binary-tutorial/binary-floating-point.php 5. Binary Fractions and Floating Point] - The first part of this section is relevant to ACSL: fractions in other bases. ACSL will not cover floating point numbers in other basis. So, focus on the section [https://ryanstutorials.net/binary-tutorial/binary-floating-point.php#convertfraction Converting to a Binary Fraction], but keep in mind that ACSL problems may also cover octal and hexadecimal fractions.<br />
<br />
The [https://coolconversion.com/math/binary-octal-hexa-decimal/ CoolConversion.com online calculator] is another online app for practicing conversion from/to decimal, hexadecimal, octal and binary; this tool shows the steps that one goes through in the conversion.<br />
<br />
== Format of ACSL Problems ==<br />
<br />
The problems in this category will focus on converting between binary, octal, decimal, and hexadecimal, basic arithmetic of numbers in those bases, and, occasionally, fractions in those bases.<br />
<br />
To be successful in this category, you must know the following facts cold:<br />
<br />
# The decimal value of each hex digit A, B, C, D, E, F <br />
# The binary value of each hex digit A, B, C, D, E, F<br />
# Powers of 2, up to 4096<br />
# Powers of 8, up to 4096<br />
# Powers of 16, up to 65,536<br />
<br />
== Sample Problems ==<br />
<br />
=== Sample Problem 1 ===<br />
<br />
Solve for $x$ where $x_{16}=3676_8$.<br />
<br />
'''Solution:''' One method of solution is to convert $3676_8$ into base 10, and then convert that number into base 16 to yield the value of $x$.<br />
<br />
An easier solution, less prone to arithmetic mistakes, is to convert from octal (base 8) to hexadecimal (base 16) through the binary (base 2) representation of the number:<br />
<br />
$$\begin{align}<br />
3676_8 &= 011 ~ 110 ~ 111 ~ 110_2 & \text{convert each octal digit into base 2}\hfill\cr <br />
&= 0111 ~ 1011 ~ 1110_2 & \text{group by 4 bits, from right-to-left}\hfill\cr<br />
&= 7 ~ \text{B} ~ \text{E}_{16} & \text{convert each group of 4 bits into a hex digit}\cr<br />
\end{align}$$<br />
<br />
=== Sample Problem 2 ===<br />
<br />
Solve for $x$ in the following hexadecimal equation: $ x= \text{F5AD}_{16} - \text{69EB}_{16}$<br />
<br />
'''Solution:''' One could convert the hex numbers into base 10, perform the subtraction, and then convert the answer back to base 16. However, <br />
working directly in base 16 isn't too hard. <br />
As in conventional decimal arithmetic, one works from right-to-left, from the least significant digits to the most. <br />
<br />
:The rightmost digit becomes 2, because D-B=2. <br />
:The next column is A-E. We need to ''borrow'' a one from the 5 column, and 1A-E=C <br />
:In the next column, 4-9=B, again, borrowing a 1 from the next column.<br />
:Finally, the leftmost column, E-6=8<br />
<br />
Combining these results of each column, we get a final answer of $8BC2_{16}$.<br />
<br />
=== Sample Problem 3 ===<br />
<br />
How many numbers from 100 to 200 in base 10 consist of distinct<br />
ascending digits and also have distinct ascending hex digits when<br />
converted to base 16? <br />
<br />
'''Solution:''' There are 13 numbers that have ascending digits in both bases from 100<br />
to 200. They are (in base 10):<br />
123 (7B), 124, 125, 126, 127 (7F), 137 (89), 138, 139 (8B), 156 (9C), 157, 158, 159 (9F), 189 (BD)<br />
<br />
== Video Resources ==<br />
<br />
There are many YouTube videos about computer number systems. Here are a handful that cover the topic nicely, without too many ads:<br />
<br />
{|<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aW3qCcH6Dao</youtube><br />
| [https://youtu.be/aW3qCcH6Dao ''Number Systems - Converting Decimal, Binary and Hexadecimal'' ('''Joe James''')]<br />
<br />
An introduction to number systems, and how to convert between decimal, binary and hexadecimal numbers. <br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/m1JtWKuTLR0</youtube><br />
| [https://youtu.be/m1JtWKuTLR0 ''Lesson 2.3 : Hexadecimal Tutorial'' ('''Carl Herold''')]<br />
<br />
The video focuses on hexadecimal numbers: their relationship to binary numbers and how to convert to decimal numbers. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jvx-NrILgpE</youtube><br />
| [https://youtu.be/jvx-NrILgpE ''Collins Lab: Binary & Hex'' ('''Adafruit Industries''')]<br />
<br />
A professionally produced video that explains the number systems, how and why binary numbers are fundamental to computer science, and why hexadecimal is important to computer programmers. <br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Computer_Number_Systems&diff=246Computer Number Systems2018-08-16T14:00:34Z<p>Jerry: </p>
<hr />
<div>All digital computers – from supercomputers to your smartphone – ultimately can do one thing: detect whether an electrical signal is on or off. <br />
That basic information, called a ''bit'' ('''bi'''nary digi'''t'''), has two values: a 1 (or ''true'') when the signal is on, and a 0 (of ''false'') when the signal is off. Larger values can be stored by a group of bits. For example, 3 bits together can take on 8 different values. <br />
<br />
Computer scientists use the [https://en.wikipedia.org/wiki/Binary_number binary number system] (that is, base 2) to represent the values of bits. Proficiency in the binary number system is essential to understanding how numbers and information are represented in a computer. Since binary numbers representing moderate values quickly become rather lengthy, bases eight ([https://en.wikipedia.org/wiki/Octal octal]) and sixteen ([https://en.wikipedia.org/wiki/Hexadecimal hexadecimal]) are frequently used as shorthand. In octal, groups of 3 bits form a single octal digit; in hexadecimal, groups of 4 bits form a single hex digit.<br />
<br />
In this category, we will focus on conversion between binary, octal, decimal, and hexadecimal numbers. There may be some arithmetic in these bases, and occasionally, a number with a fractional part. We will not cover how negative numbers or floating point numbers are represented in binary.<br />
<br />
== Resources ==<br />
<br />
[https://ryanstutorials.net/ Ryan's Tutorials] covers this topic beautifully. Rather than trying to duplicate that work, we'll point you to the different sections:<br />
<br />
:[https://ryanstutorials.net/binary-tutorial/ 1. Number Systems] - An introduction to what numbers systems are all about, with emphasis on decimal, binary, octal, and hexadecimal. ACSL will typically identify the base of a number using a subscript. For example, $123_8$ is an octal number, whereas $123_{16}$ is a hexadecimal number. <br />
<br />
:[https://ryanstutorials.net/binary-tutorial/binary-conversions.php 2. Binary Conversions] - This section shows how to convert between binary, decimal, hexadecimal and octal numbers. In the [https://ryanstutorials.net/binary-tutorial/binary-conversions.php#activities ''Activities''] section, you can practice converting numbers. <br />
<br />
:[https://ryanstutorials.net/binary-tutorial/binary-arithmetic.php 3. Binary Arithmetic] - Describes how to perform various arithmetic operations (addition, subtraction, multiplication, and division) with binary numbers. ACSL problems will also cover basic arithmetic in other bases, such as adding and subtracting together 2 hexadecimal numbers. ACSL problems will not cover division in other bases.<br />
<br />
:[https://ryanstutorials.net/binary-tutorial/binary-negative-numbers.php 4. Negative Numbers] - ACSL problems will not cover how negative numbers are represented in binary. <br />
<br />
:[https://ryanstutorials.net/binary-tutorial/binary-floating-point.php 5. Binary Fractions and Floating Point] - The first part of this section is relevant to ACSL: fractions in other bases. ACSL will not cover floating point numbers in other basis. So, focus on the section [https://ryanstutorials.net/binary-tutorial/binary-floating-point.php#convertfraction Converting to a Binary Fraction], but keep in mind that ACSL problems may also cover octal and hexadecimal fractions.<br />
<br />
The [https://coolconversion.com/math/binary-octal-hexa-decimal/ CoolConversion.com online calculator] is another online app for practicing conversion from/to decimal, hexadecimal, octal and binary; this tool shows the steps that one goes through in the conversion.<br />
<br />
== Format of ACSL Problems ==<br />
<br />
The problems in this category will focus on converting between binary, octal, decimal, and hexadecimal, basic arithmetic of numbers in those bases, and, occasionally, fractions in those bases.<br />
<br />
To be successful in this category, you must know the following fact cold:<br />
<br />
# The decimal value of each hex digit A, B, C, D, E, F <br />
# The binary value of each hex digit A, B, C, D, E, F<br />
# Powers of 2, up to 4096<br />
# Powers of 8, up to 4096<br />
# Powers of 16, up to 65,536<br />
<br />
== Sample Problems ==<br />
<br />
=== Sample Problem 1 ===<br />
<br />
Solve for $x$ where $x_{16}=3676_8$.<br />
<br />
'''Solution:''' One method of solution is to convert $3676_8$ into base 10, and then convert that number into base 16 to yield the value of $x$.<br />
<br />
An easier solution, less prone to arithmetic mistakes, is to convert from octal (base 8) to hexadecimal (base 16) through the binary (base 2) representation of the number:<br />
<br />
$$\begin{align}<br />
3676_8 &= 011 ~ 110 ~ 111 ~ 110_2 & \text{convert each octal digit into base 2}\hfill\cr <br />
&= 0111 ~ 1011 ~ 1110_2 & \text{group by 4 bits, from right-to-left}\hfill\cr<br />
&= 7 ~ \text{B} ~ \text{E}_{16} & \text{convert each group of 4 bits into a hex digit}\cr<br />
\end{align}$$<br />
<br />
=== Sample Problem 2 ===<br />
<br />
Solve for $x$ in the following hexadecimal equation: $ x= \text{F5AD}_{16} - \text{69EB}_{16}$<br />
<br />
'''Solution:''' One could convert the hex numbers into base 10, perform the subtraction, and then convert the answer back to base 16. However, <br />
working directly in base 16 isn't too hard. <br />
As in conventional decimal arithmetic, one works from right-to-left, from the least significant digits to the most. <br />
<br />
:The rightmost digit becomes 2, because D-B=2. <br />
:The next column is A-E. We need to ''borrow'' a one from the 5 column, and 1A-E=C <br />
:In the next column, 4-9=B, again, borrowing a 1 from the next column.<br />
:Finally, the leftmost column, E-6=8<br />
<br />
Combining these results of each column, we get a final answer of $8BC2_{16}$.<br />
<br />
=== Sample Problem 3 ===<br />
<br />
How many numbers from 100 to 200 in base 10 consist of distinct<br />
ascending digits and also have distinct ascending hex digits when<br />
converted to base 16? <br />
<br />
'''Solution:''' There are 13 numbers that have ascending digits in both bases from 100<br />
to 200. They are (in base 10):<br />
123 (7B), 124, 125, 126, 127 (7F), 137 (89), 138, 139 (8B), 156 (9C), 157, 158, 159 (9F), 189 (BD)<br />
<br />
== Video Resources ==<br />
<br />
There are many YouTube videos about computer number systems. Here are a handful that cover the topic nicely, without too many ads:<br />
<br />
{|<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aW3qCcH6Dao</youtube><br />
| [https://youtu.be/aW3qCcH6Dao ''Number Systems - Converting Decimal, Binary and Hexadecimal'' ('''Joe James''')]<br />
<br />
An introduction to number systems, and how to convert between decimal, binary and hexadecimal numbers. <br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/m1JtWKuTLR0</youtube><br />
| [https://youtu.be/m1JtWKuTLR0 ''Lesson 2.3 : Hexadecimal Tutorial'' ('''Carl Herold''')]<br />
<br />
The video focuses on hexadecimal numbers: their relationship to binary numbers and how to convert to decimal numbers. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jvx-NrILgpE</youtube><br />
| [https://youtu.be/jvx-NrILgpE ''Collins Lab: Binary & Hex'' ('''Adafruit Industries''')]<br />
<br />
A professionally produced video that explains the number systems, how and why binary numbers are fundamental to computer science, and why hexadecimal is important to computer programmers. <br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Boolean_Algebra&diff=245Boolean Algebra2018-08-16T13:57:03Z<p>Jerry: </p>
<hr />
<div>''Boolean algebra'' is the branch of algebra in which the values of the variables and constants have exactly two values: ''true'' and ''false'', usually denoted 1 and 0 respectively. <br />
<br />
The basic operators in Boolean algebra are ''and'', ''or'', and ''not''. The secondary operators are ''exclusive or'' (often called ''xor'') and ''exclusive nor'' (sometimes called ''equivalence''). They are secondary in the sense that they <br />
can be composed from the basic operators.<br />
*The ''and'' of two values is true only whenever both values are true. It is written as $xy$ or $x \cdot y$. The values of ''and'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 0 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The ''or'' of two values is true whenever either or both values are true. It is written as $x+y$. The values of ''or'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x + y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 1 <br />
|} <br />
<br />
* The ''not'' of a value is its opposite; that is, the ''not'' of a true value is false whereas the ''not'' of a false value is true. It is written as $\overline{x}$ or $\neg{x}$. The values of ''not'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>\overline{x}</math><br />
|-<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
| 0 <br />
|} <br />
<br />
* The ''xor'' of two values is true whenever the values are different. It uses the $\oplus$ operator, and can be built from the basic operators: $x \oplus y = x \overline{y} + \overline{x} y$ The values of ''xor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \oplus y</math><br />
|-<br />
!0<br />
!0<br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 1 <br />
|-<br />
!1<br />
!1<br />
| 0<br />
|} <br />
<br />
*The ''xnor'' of two values is true whenever the values are the same. It is the ''not'' of the ''xor'' function. It uses the $\odot$ operator: $x \odot y = \overline{x \oplus y}$. The ''xnor'' can be built from basic operators: $x \odot y = x y + \overline{x} \overline{y}$ The values of ''xnor'' for all possible inputs is shown in the following truth table:<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
!<math>x \odot y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
|-<br />
!0<br />
!1<br />
| 0<br />
|-<br />
!1<br />
!0<br />
| 0<br />
|-<br />
!1<br />
!1<br />
| 1<br />
|} <br />
<br />
Just as algebra has basic rules for simplifying and evaluating expressions, so does Boolean algebra.<br />
<br />
==Why is Boolean Algebra Important for ACSL Students?==<br />
<br />
Boolean algebra is important to programmers, computer scientists, and the general population. <br />
<br />
*For programmers, Boolean expressions are used for conditionals and loops. For example, the following snippet of code sums the even numbers that are not also multiples of 3, stopping when the sum hits 100:<br />
<br />
<dl><br />
<dd><br />
<syntaxhighlight lang="python"><br />
s = 0<br />
x = 1<br />
while (s < 100):<br />
if (x % 2 == 0) and (x % 3 != 0)<br />
then s = s + x<br />
x = x + 1<br />
</syntaxhighlight><br />
Both the conditional statement <br />
<syntaxhighlight lang="python" inline>s < 100</syntaxhighlight><br />
and the Boolean expression with 2 conditional statements <br />
<syntaxhighlight lang="python" inline>(x % 2 == 0) and (x % 3 != 0)</syntaxhighlight><br />
evaluate to ''true'' or ''false''. <br />
</dd><br />
</dl><br />
<br />
*For computer scientists, Boolean algebra is the basis for digital circuits that make up a computer's hardware. The [[Digital Electronics]] category concerns a graphical representation of a circuit. That circuit is typically easiest to understand and evaluate by converting it to its Boolean algebra representation. <br />
<br />
* The general population uses Boolean algebra, probably without knowing that they are doing so, when they enter search terms in Internet search engines. For example, the search expression "jaguar speed -car is the Boolean expression <syntaxhighlight lang="python" inline>"jaguar" and "car" and not "speed"</syntaxhighlight>; it returns pages about the speed of the jaguar animal, not the Jaguar car.<br />
<br />
==Laws==<br />
A '''law''' of Boolean algebra is an identity such as <math>x + (y + z) = (x + y) + z</math><br />
between two Boolean terms, where a '''Boolean term''' is defined as an expression built up from variables, the constants 0 and 1, and operations ''and'', ''or'', ''not'', ''xor'', and ''xnor''. <br />
<br />
Like ordinary algebra, parentheses are used to group terms. When a ''not'' is represented with an overhead horizontal line, there is an implicit grouping of the terms under the line. That is, $x \cdot \overline{y + z}$ is evaluated as is it were written $x \cdot \overline{(y + z)}.$<br />
<br />
===Order of Precedence===<br />
<br />
The order of operator precedence is ''not''; then ''and''; then ''xor'' and ''xnor''; and finally ''or''. Operators with the same level of precedence are evaluated from left-to-right. <br />
<br />
===Fundamental Identities===<br />
<br />
{| class="wikitable" style="text-align: center"<br />
|- <br />
| style="text-align: left" | Commutative Law – The order of application of two separate terms is not important. || $x+y = y+x$ || $x \cdot y = y \cdot x$ <br />
|- <br />
| style="text-align: left" | Associative Law – Regrouping of the terms in an expression doesn't change the value of the expression. ||$(x + y) + z$ = $x + (y + z)$ || $x \cdot (y \cdot z) = (x \cdot y) \cdot z$ <br />
|-<br />
| style="text-align: left" | Idempotent Law – A term that is ''or'''´ed or ''and''´ed with itself is equal to that term. || $ x +x = x $ || $x \cdot x = x$<br />
|-<br />
| style="text-align: left" | Annihilator Law – A term that is ''or'''´ed with 1 is 1; a term ''and''´ed with 0 is 0. || $x + 1 = 1$ || $ x \cdot 0 = 0 $ <br />
|-<br />
| style="text-align: left" | Identity Law – A term ''or''´ed 0 or ''and''´ed with a 1 will always equal that term. || $x + 0 = x$ || $x \cdot 1 = x$<br />
|-<br />
| style="text-align: left" | Complement Law – A term ''or''´ed with its complement equals 1 and a term ''and''´ed with its complement equals 0. || $x + \overline{x} = 1 $ || $x \cdot \overline{x} = 0$<br />
|-<br />
| style="text-align: left" | Absorptive Law – Complex expressions can be reduced to a simpler ones by absorbing like terms. ||colspan=2|<br />
$x+x y = x$<br />
<br />
$ x +\overline{x}y = x + y $<br />
<br />
$x (x+y) = x$<br />
<br />
|-<br />
| style="text-align: left" | Distributive Law – It's OK to multiply or factor-out an expression.||colspan=2|<br />
<br />
$x \cdot (y + z) = xy + xz$<br />
<br />
$(x+y) \cdot (p + q) = xp + xq +yp + yq$<br />
<br />
$(x+y)(x+z)=x + yz $<br />
<br />
|-<br />
| style="text-align: left" | DeMorgan's Law – An ''or'' (''and'') expression that is negated is equal to the ''and'' (''or'') of the negation of each term.|| $\overline{x+y} = \overline{x} \cdot \overline{y}$||$\overline{x \cdot y} = \overline{x} + \overline{y}$<br />
|- <br />
| style="text-align: left" | Double Negation – A term that is inverted twice is equal to the original term.||colspan=2| $\overline{\overline{x}} = x $ <br />
|- <br />
| style="text-align: left" | Relationship between XOR and XNOR|| colspan=2 | $ x\odot y = \overline{x\oplus y} = x \oplus \overline{y} =\overline{x} \oplus {y}$ <br />
|}<br />
<br />
== Sample Problems ==<br />
<br />
Problems in this category are typically of the form "Given a Boolean expression, simplify it as much as possible" or "Given a Boolean expression,<br />
find the values of all possible inputs that make the expression ''true''." Simplify implies writing an equivalent expression using the fewest number of operators.<br />
<br />
=== Sample Problem 1: Simplify the Expression ===<br />
<br />
'''Problem:''' Simplify the following expression as much as possible:<br />
$ \overline{ \overline{A(A+B)} + B\overline{A}}$<br />
<br />
'''Solution:'''<br />
<br />
The simplification proceeds as follows:<br />
<br />
:$\overline{ \overline{A(A+B)} + B\overline{A}}$<br />
::{| <br />
<br />
|-<br />
| <math>= \left(\overline{ \overline{A(A+B)}}\right) \cdot \left(\overline{ B\overline{A}}\right)</math> ||<br />
| (DeMorgan's Law)<br />
<br />
|-<br />
| <math>= \left(A(A+B)\right) \cdot \left( \overline{B}+\overline{\overline{A}}\right)</math> ||<br />
| (Double Negation; DeMorgan's Law)<br />
<br />
|-<br />
| <math>= A \cdot \left( \overline{B}+A\right)</math> ||<br />
| (Absorption; Double Negation)<br />
<br />
|-<br />
| <math>=A</math> || <br />
| (Absorption)<br />
| <br />
<br />
|}<br />
<br />
=== Sample Problem 2: Find Solutions ===<br />
<br />
'''Problem:''' Find all orderd pairs $(A,B)$ that make the following expression ''true'':<br />
$ \overline{ \overline{(A+B)} + \overline{A}B }$<br />
<br />
'''Solution:'''<br />
<br />
There are typically two approaches to solving this type of problem. One approach is to simplify the expression as much as possible, until<br />
it's obvious what the solutions are. The other approach is to create a truth table of all possible inputs, with columns for each subexpression.<br />
<br />
The simplification approach is as following:<br />
:$ \overline{\overline{(A+B)} + \overline{A}B}$<br />
::$= \overline{\overline{A+B}} \cdot \overline{\overline{A}B}$ <br />
::$= (A+B) \cdot (\overline{\overline{A}}+\overline{B} ) $ <br />
::$= (A+B) \cdot (A+\overline{B}) $ <br />
::$= AA + A\overline{B} + BA + B\overline{B} $ <br />
::$= A + A(\overline{B} + B) + 0 $ <br />
::$= A + A(1)$ <br />
::$= A + A$ <br />
::$=A$<br />
This means that all inputs are valid whenever $A$ is ''true'': $(1,0)$ and $(1,1)$<br />
<br />
The truth table approach is as following. Each column is the result of a basic operation on two other columns. <br />
:{| class="wikitable" style="text-align: center"<br />
|-<br />
!style="background-color: #cceeff; font-size: x-small" |#1<br />
!style="background-color: #cceeff; font-size: x-small" |#2<br />
!style="background-color: #cceeff; font-size: x-small" |#3 <br />
!style="background-color: #cceeff; font-size: x-small" |#4<br />
!style="background-color: #cceeff; font-size: x-small" |#5<br />
!style="background-color: #cceeff; font-size: x-small" |#6<br />
!style="background-color: #cceeff; font-size: x-small" |#7<br />
!style="background-color: #cceeff; font-size: x-small" |#8<br />
<br />
|-<br />
|style="background-color: #cceeff"|<br />
|style="background-color: #cceeff"|<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#3<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#1<br />
!style="background-color: #cceeff; font-size: x-small" |ADD of Col#1, Col#2<br />
!style="background-color: #cceeff; font-size: x-small" |OR of Col#4, Col#6<br />
!style="background-color: #cceeff; font-size: x-small" |NOT of Col#7 <br />
<br />
|-<br />
!<math>A</math><br />
!<math>B</math><br />
!<math>A+B</math><br />
!<math>\overline{A+B}</math><br />
!<math>\overline{A}</math><br />
!<math>\overline{A}B</math><br />
!<math>\overline{A+B} + \overline{A}B</math><br />
!<math>\overline{\overline{A+B} + \overline{A}B}</math><br />
<br />
|-<br />
!0<br />
!0<br />
|0<br />
|1<br />
|1<br />
|0<br />
|1<br />
!0<br />
<br />
|-<br />
!0<br />
!1<br />
<br />
|1<br />
|0<br />
|1<br />
|1<br />
|1<br />
!0<br />
<br />
|-<br />
!1<br />
!0<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
<br />
|-<br />
!1<br />
!1<br />
<br />
|1<br />
|0<br />
|0<br />
|0<br />
|0<br />
!1<br />
|}<br />
<br />
The rightmost column is the expression we are solving; it is ''true'' for the 3rd and 4th rows, where the inputs are $(1,0)$ and $(1,1)$.<br />
<br />
== Online Resources ==<br />
<br />
===Websites===<br />
A great online tutorial on Boolean Algebra is part of [https://ryanstutorials.net/boolean-algebra-tutorial/ Ryan's Tutorials].<br />
<br />
===Videos===<br />
The following YouTube videos show ACSL students and advisors working out some previous problems. To access the YouTube page with the video, click on the title of the video in the icon. (You can also play the video directly by clicking on the arrow in the center of the image; however, you'll <br />
probably want to have a larger viewing of the video since it contains writing on a whiteboard.) Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/1cwO-FtybNw</youtube><br />
| [https://youtu.be/1cwO-FtybNw ''ACSL Prep - Mrs. Gupta - Boolean Algebra'' ('''MegaChristian5555''')]<br />
<br />
Christian is a student participating in ACSL. This video shows how to solve a half-dozen or so Boolean Algebra problems that have appeared in ACSL contests in recent years in the Intermediate and Senior divisions.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/HJdhEjpVYsY</youtube><br />
| [https://youtu.be/HJdhEjpVYsY ''ACSL Boolean Algebra Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/4io6xgz8Zwk</youtube><br />
| [https://youtu.be/4io6xgz8Zwk ''ACSL Boolean Algebra Contest 2 Worksheet 2'' ('''misterminich''') ]<br />
<br />
Mr. Minich is an ACSL advisor. This video was one of two he created to help prepare his students for the ACSL Boolean algebra category. It shows solutions to 5 different problems that have<br />
appeared in recent years. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/6vI1mO1XOjQ</youtube><br />
| [https://youtu.be/6vI1mO1XOjQ ''ACSL 3 13-14 #1 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the solution to finding all ordered triples that make the following<br />
Boolean expression ''true'':<br />
:<math><br />
(AB+\overline{C})(\overline{A}+BC)(A+\overline{B}+C)<br />
</math><br />
This problem appeared in 2013-2014 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/KRKTbAZYlLM</youtube><br />
| [https://youtu.be/KRKTbAZYlLM ''ACSL 3 #1 14-15 - AM'' ('''Gordon Campbell''')]<br />
<br />
This video walks through the simplification of the expression:<br />
:<math><br />
\overline{(\overline{A}+B)}(B+C)\overline{(A+\overline{C})}(A\overline{B}+BC)<br />
</math><br />
This problem appeared in 2014-2015 in the Senior Division, Contest #3.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jDnni-zm2g8</youtube><br />
| [https://youtu.be/jDnni-zm2g8 ''A general tutorial on boolean algebra that can be used for American Computer Science League.'' ('''Tangerine Code''')]<br />
<br />
Walks through the simplification of the following Boolean expression:<br />
:<math><br />
\overline{ (\overline{A + \overline{B}})(AB)} +<br />
\overline{ (A+B)(\overline{\overline{A}B})}<br />
</math><br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aGJALO57X7o</youtube><br />
| [https://youtu.be/aGJALO57X7o ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving a handful of ACSL problems.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/-Iagy51n5bQ</youtube><br />
| [https://youtu.be/-Iagy51n5bQ ''Boolean Algebra by Ravi Yeluru'' ]<br />
<br />
Walks through solving 4 ACSL problems.<br />
<br />
|}</div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&diff=244Bit-String Flicking2018-08-16T13:43:19Z<p>Jerry: </p>
<hr />
<div><br />
Bit strings (strings of binary digits) are frequently manipulated bit-by-bit using the logical operators '''not''', '''and''', '''or''', and '''xor'''. Bits strings are manipulated as a unit using '''shift''' and '''circulate''' operators. The bits on the left are called the ''most significant bits'' and those on the right are the ''least significant bits''. <br />
<br />
Most high-level languages (e.g., Python, Java, C++), support bit-string operations. Programmers typically use bit string to maintain a set of flags. Suppose that a program supports 8 options, each of which can be either “on” or “off”. One could maintain this information using an array of size 8, or one could use a single variable (if it is internally stored using at least 8 bits or 1 byte, which is usually the case) and use 8 bits to record each option. In addition to saving space, the program is often cleaner if a single variable is involved rather than an array. Bits strings are often used to maintain a set where values are either in the set or not. <br />
<br />
Mastering this topic is essential for systems programming, programming in assembly language, optimizing code and hardware design.<br />
<br />
== Operators==<br />
<br />
=== Bitwise Operators ===<br />
<br />
The logical operators are '''not''' (~ or $\neg$), '''and''' (&), '''or''' (|), and '''xor''' ($\oplus$). These operators should be familiar to ACSL students from the [[Boolean Algebra]] and [[Digital Electronics]] categories.<br />
<br />
* '''not''' is a unary operator that performs logical negation on each bit. Bits that are 0 become 1, and those that are 1 become 0. For example: ~101110 has a value of 010001.<br />
<br />
* '''and''' is a binary operator that performs the logical '''and''' of each bit in each of its operands. The '''and''' of two values is 1 only whenever both values are 1. For example, '''1011011 and 011001''' has a value of '''001001'''. The and function is often use to isolate the value of a bit in a bit-string, or to clear the value of a bit in a bit-string.<br />
<br />
* '''or''' is a binary operator that performs the logical '''or''' of each bit in each of its operands. The '''or''' of two values is 1 only when one or both values are 1. For example, '''1011011 or 011001''' has a value of '''111011'''. The and function is often use to force the value of a bit in a bit-string to be 1, if it isn't already.<br />
<br />
* '''xor''' is a binary operator that performs the logical '''xor''' of each bit in each of its operands. The '''xor''' of two values is 1 whenever the values are different. For example, 1011011 xor 011001 = 110010. The xor function is often use to change the value of a particular bit.<br />
<br />
The operands to binary operators (and, or, or xor) must operate on bit-strings that are of<br />
the same length. If the operands are not the same<br />
length, the shorter one is padded with 0's on the left as needed. For <br />
example, '''11010 and 1110''' would have value of 01010.<br />
<br />
The following table summarizes the operators:<br />
<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
! '''not''' <math>x</math><br />
!<math>x</math> '''and''' <math>y</math><br />
!<math>x</math> '''or''' <math>y</math><br />
!<math>x</math> '''xor''' <math>y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
| 0 <br />
| 0 <br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
| 0 <br />
| 1 <br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
| 0 <br />
| 1 <br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 0 <br />
| 1 <br />
| 1 <br />
| 1 <br />
|}<br />
<br />
=== Shift Operators ===<br />
<br />
Logical shifts (LSHIFT-x and RSHIFT-x) “ripple” the bit-string x positions in the indicated direction, either to the left or to the right. Bits shifted out are lost; zeros are shifted in at the other end. <br />
<br />
Circulates (RCIRC-x and LCIRC-x) “ripple” the bit string x positions in the indicated direction. As each bit is shifted out one end, it is shifted in at the other end. <br />
<br />
The size of a bit-string does not change with shifts, or circulates. If any bit strings are initially of different lengths, all shorter ones are padded with zeros in the left bits until all strings are of the same length. <br />
<br />
The following table gives some examples of these operations:<br />
<br />
::{| class="wikitable" style="text-align: right"<br />
|-<br />
!x<br />
!(LSHIFT-2 x)<br />
!(RSHIFT-3 x)<br />
!(LCIRC-3 x)<br />
!(RCIRC-1 x)<br />
|-<br />
!01101<br />
| 10100<br />
| 00001<br />
| 01011<br />
| 10110<br />
|-<br />
!10<br />
| 00<br />
| 00<br />
| 01<br />
| 01<br />
|-<br />
!1110<br />
| 1000<br />
| 0001<br />
| 0111<br />
| 0111<br />
|-<br />
!1011011<br />
| 1101100<br />
| 0001011<br />
| 1011101<br />
| 1101101<br />
|}<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of precedence (from highest to lowest) is: NOT; SHIFT and CIRC; AND; XOR; and finally, OR. In other words, all unary operators are performed on a single operator first. Operators with equal precedence are evaluated left to right; all operators bind from right to left.<br />
<br />
== Sample Problems ==<br />
<br />
=== Sample Problem 1 ===<br />
<br />
Evaluate the following expression: <br />
:(0101110 AND NOT 110110 OR (LSHIFT-2 101010))<br />
<br />
'''Solution:'''<br />
The expression evaluates as follows:<br />
:(0101110 AND '''001001''' OR (LSHIFT-2 101010))<br />
:('''001000''' OR (LSHIFT-3 101010))<br />
:(001000 OR '''010000''')<br />
:'''011000'''<br />
<br />
=== Sample Problem 2 ===<br />
<br />
Evaluate the following expression: <br />
:(RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) <br />
<br />
'''Solution:'''<br />
The expression evaluates as follows, starting at the innermost parentheses:<br />
:(RCIRC-2 01101) => 01011<br />
:(LCIRC-4 01011) => 10101<br />
:(RSHIFT-1 10101) = 01010<br />
<br />
=== Sample Problem 3 ===<br />
<br />
List all possible values of x (5 bits long) that solve the following equation.<br />
:(LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100<br />
<br />
'''Solution:'''<br />
Since x is a string 5 bits long, represent it by abcde. (RCIRC-3 x) is cdeab which, when ANDed with 11011 gives cd0ab. This is XORed to 10110 to yield Cd1Ab (the capital letter is the NOT of its lower case).<br />
Now, (LSHIFT-1 Cd1Ab) = d1Ab0 which has a value of 01100, we must have d=0, A=1 (hence a=0), b=0. Thus, the solution must be in the form 00*0*, where * is an “I-don’t-care”. The four possible values of x are: 00000, 00001, 00100 and 00101.<br />
<br />
=== Sample Problem 4 ===<br />
<br />
Evaluate the following expression:<br />
: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) & (RSHIFT-2 10111))<br />
<br />
'''Solution:'''<br />
The problem can be rewritten as <br />
: A | B & C<br />
The AND has higher precedence than the OR. <br />
<br />
The evaluation of expression A can be done in a straightforward way: LCIRC-23 011101) has a value of 01011, and RCIRC-14 01011) has a value of 10110. However, if the value of 23 and 14 were much larger, a more clever strategy is to offset the left and right circulates. For example, (RCIRC-7 (LCIRC-3 x)) would have the same results as (RCIRC-4 x). So, ((RCIRC-14 (LCIRC-23 01101)) has the same value as (LCIRC-9 01101), which has the same value as (LCIRC-4 01101). This is an easy expression to evaluate.<br />
<br />
Expressions B and C are pretty easy to evaluate:<br />
:B = (LSHIFT-1 10011) = 00110<br />
:C = (RSHIFT-2 10111) = 00101<br />
<br />
The expression becomes<br />
: A | B & C = 10110 | 00110 & 00101 = 10110 | 00100 = 10110<br />
<br />
== Video Resources ==<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/IeMsD3harrE</youtube><br />
| [https://youtu.be/IeMsD3harrE ''Bit String Flicking (Intro)'' ('''CalculusNguyenify''')]<br />
<br />
A great two-part tutorial on this ACSL category. Part 1 covers bitwise operations AND, OR, NOT, and XOR. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jbKw8oYJPs4</youtube><br />
| [https://youtu.be/jbKw8oYJPs4 ''Bit String Flicking Shifts and Circs'' ('''CalculusNguyenify''')]<br />
<br />
Part 2 covers logical shifts and circulate operations.<br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/XNBcO25mgCw</youtube><br />
| [https://youtu.be/XNBcO25mgCw ''Bit String Flicking'' ('''Tangerine Code''')]<br />
<br />
Shows the solution to the problem: (RSHIFT-3 (LCIRC-2 (NOT 10110)))<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/8J9AdxU5CW8</youtube><br />
| [https://youtu.be/8J9AdxU5CW8 ''Bit String Flicking by Ravi Yeluru'' ('''hemsra''')]<br />
<br />
Walks through two problems from the Junior Division.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aa_lQ8gft60</youtube><br />
| [https://youtu.be/aa_lQ8gft60 ''ACSL BitString Flicking Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Solves a handful of problems given in previous years at the Intermediate Division level.<br />
<br />
|}<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerryhttp://www.categories.acsl.org/wiki/index.php?title=Bit-String_Flicking&diff=243Bit-String Flicking2018-08-16T13:40:08Z<p>Jerry: </p>
<hr />
<div><br />
Bit strings (strings of binary digits) are frequently manipulated bit-by-bit using the logical operators '''not''', '''and''', '''or''', and '''xor'''. Bits strings are manipulated as a unit using '''shift''' and '''circulate''' operators. The bits on the left are called the ''most significant bits'' and those on the right are the ''least significant bits''. <br />
<br />
Most high-level languages (e.g., Python, Java, C++), support bit-string operations. Programmers typically use bit string to maintain a set of flags. Suppose that a program supports 8 options, each of which can be either “on” or “off”. One could maintain this information using an array of size 8, or one could use a single variable (if it is internally stored using at least 8 bits or 1 byte, which is usually the case) and use 8 bits to record each option. In addition to saving space, the program is often cleaner if a single variable is involved rather than an array. Bits strings are often used to maintain a set where values are either in the set or not. <br />
<br />
Mastering this topic is essential for systems programming, programming in assembly language, optimizing code and hardware design.<br />
<br />
== Operators==<br />
<br />
=== Bitwise Operators ===<br />
<br />
The logical operators are '''not''' (~ or $\neg$), '''and''' (&), '''or''' (|), and '''xor''' ($\oplus$). These operators should be familiar to ACSL students from the [[Boolean Algebra]] and [[Digital Electronics]] categories.<br />
<br />
* '''not''' is a unary operator that performs logical negation on each bit. Bits that are 0 become 1, and those that are 1 become 0. For example: ~101110 has a value of 010001.<br />
<br />
* '''and''' is a binary operator that performs the logical '''and''' of each bit in each of its operands. The '''and''' of two values is 1 only whenever both values are 1. For example, '''1011011 and 011001''' has a value of '''001001'''. The and function is often use to isolate the value of a bit in a bit-string, or to clear the value of a bit in a bit-string.<br />
<br />
* '''or''' is a binary operator that performs the logical '''or''' of each bit in each of its operands. The '''or''' of two values is 1 only when one or both values are 1. For example, '''1011011 or 011001''' has a value of '''111011'''. The and function is often use to force the value of a bit in a bit-string to be 1, if it isn't already.<br />
<br />
* '''xor''' is a binary operator that performs the logical '''xor''' of each bit in each of its operands. The '''xor''' of two values is 1 whenever the values are different. For example, 1011011 xor 011001 = 110010. The xor function is often use to change the value of a particular bit.<br />
<br />
The operands to binary operators (and, or, or xor) must operate on bit-strings that are of<br />
the same length. If the operands are not the same<br />
length, the shorter one is padded with 0's on the left as needed. For <br />
example, '''11010 and 1110''' would have value of 01010.<br />
<br />
The following table summarizes the operators:<br />
<br />
::{| class="wikitable" style="text-align: center"<br />
|-<br />
!<math>x</math><br />
!<math>y</math><br />
! '''not''' <math>x</math><br />
!<math>x</math> '''and''' <math>y</math><br />
!<math>x</math> '''or''' <math>y</math><br />
!<math>x</math> '''xor''' <math>y</math><br />
|-<br />
!0<br />
!0<br />
| 1 <br />
| 0 <br />
| 0 <br />
| 0 <br />
|-<br />
!0<br />
!1<br />
| 1 <br />
| 0 <br />
| 1 <br />
| 1 <br />
|-<br />
!1<br />
!0<br />
| 0 <br />
| 0 <br />
| 1 <br />
| 0 <br />
|-<br />
!1<br />
!1<br />
| 0 <br />
| 1 <br />
| 1 <br />
| 1 <br />
|}<br />
<br />
=== Shift Operators ===<br />
<br />
Logical shifts (LSHIFT-x and RSHIFT-x) “ripple” the bit-string x positions in the indicated direction, either to the left or to the right. Bits shifted out are lost; zeros are shifted in at the other end. <br />
<br />
Circulates (RCIRC-x and LCIRC-x) “ripple” the bit string x positions in the specified direction. As each bit is shifted out one end, it is shifted in at the other end. <br />
<br />
The size of a bit-string does not change with shifts, or circulates. If any bit strings are initially of different lengths, all shorter ones are padded with zeros in the left bits until all strings are of the same length. <br />
<br />
The following table gives some examples of these operations:<br />
<br />
::{| class="wikitable" style="text-align: right"<br />
|-<br />
!x<br />
!(LSHIFT-2 x)<br />
!(RSHIFT-3 x)<br />
!(LCIRC-3 x)<br />
!(RCIRC-1 x)<br />
|-<br />
!01101<br />
| 10100<br />
| 00001<br />
| 01011<br />
| 10110<br />
|-<br />
!10<br />
| 00<br />
| 00<br />
| 01<br />
| 01<br />
|-<br />
!1110<br />
| 1000<br />
| 0001<br />
| 0111<br />
| 0111<br />
|-<br />
!1011011<br />
| 1101100<br />
| 0001011<br />
| 1011101<br />
| 1101101<br />
|}<br />
<br />
=== Order of Precedence ===<br />
<br />
The order of precedence (from highest to lowest) is: NOT; SHIFT and CIRC; AND; XOR; and finally, OR. In other words, all unary operators are performed on a single operator first. Operators with equal precedence are evaluated left to right; all operators bind from right to left.<br />
<br />
== Sample Problems ==<br />
<br />
=== Sample Problem 1 ===<br />
<br />
Evaluate the following expression: <br />
:(0101110 AND NOT 110110 OR (LSHIFT-2 101010))<br />
<br />
'''Solution:'''<br />
The expression evaluates as follows:<br />
:(0101110 AND '''001001''' OR (LSHIFT-2 101010))<br />
:('''001000''' OR (LSHIFT-3 101010))<br />
:(001000 OR '''010000''')<br />
:'''011000'''<br />
<br />
=== Sample Problem 2 ===<br />
<br />
Evaluate the following expression: <br />
:(RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) <br />
<br />
'''Solution:'''<br />
The expression evaluates as follows, starting at the innermost parentheses:<br />
:(RCIRC-2 01101) => 01011<br />
:(LCIRC-4 01011) => 10101<br />
:(RSHIFT-1 10101) = 01010<br />
<br />
=== Sample Problem 3 ===<br />
<br />
List all possible values of x (5 bits long) that solve the following equation.<br />
:(LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100<br />
<br />
'''Solution:'''<br />
Since x is a string 5 bits long, represent it by abcde. (RCIRC-3 x) is cdeab which, when ANDed with 11011 gives cd0ab. This is XORed to 10110 to yield Cd1Ab (the capital letter is the NOT of its lower case).<br />
Now, (LSHIFT-1 Cd1Ab) = d1Ab0 which has a value of 01100, we must have d=0, A=1 (hence a=0), b=0. Thus, the solution must be in the form 00*0*, where * is an “I-don’t-care”. The four possible values of x are: 00000, 00001, 00100 and 00101.<br />
<br />
=== Sample Problem 4 ===<br />
<br />
Evaluate the following expression:<br />
: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) & (RSHIFT-2 10111))<br />
<br />
'''Solution:'''<br />
The problem can be rewritten as <br />
: A | B & C<br />
The AND has higher precedence than the OR. <br />
<br />
The evaluation of expression A can be done in a straightforward way: LCIRC-23 011101) has a value of 01011, and RCIRC-14 01011) has a value of 10110. However, if the value of 23 and 14 were much larger, a more clever strategy is to offset the left and right circulates. For example, (RCIRC-7 (LCIRC-3 x)) would have the same results as (RCIRC-4 x). So, ((RCIRC-14 (LCIRC-23 01101)) has the same value as (LCIRC-9 01101), which has the same value as (LCIRC-4 01101). This is an easy expression to evaluate.<br />
<br />
Expressions B and C are pretty easy to evaluate:<br />
:B = (LSHIFT-1 10011) = 00110<br />
:C = (RSHIFT-2 10111) = 00101<br />
<br />
The expression becomes<br />
: A | B & C = 10110 | 00110 & 00101 = 10110 | 00100 = 10110<br />
<br />
== Video Resources ==<br />
<br />
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads. <br />
<br />
{|<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/IeMsD3harrE</youtube><br />
| [https://youtu.be/IeMsD3harrE ''Bit String Flicking (Intro)'' ('''CalculusNguyenify''')]<br />
<br />
A great two-part tutorial on this ACSL category. Part 1 covers bitwise operations AND, OR, NOT, and XOR. <br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/jbKw8oYJPs4</youtube><br />
| [https://youtu.be/jbKw8oYJPs4 ''Bit String Flicking Shifts and Circs'' ('''CalculusNguyenify''')]<br />
<br />
Part 2 covers logical shifts and circulate operations.<br />
<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/XNBcO25mgCw</youtube><br />
| [https://youtu.be/XNBcO25mgCw ''Bit String Flicking'' ('''Tangerine Code''')]<br />
<br />
Shows the solution to the problem: (RSHIFT-3 (LCIRC-2 (NOT 10110)))<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/8J9AdxU5CW8</youtube><br />
| [https://youtu.be/8J9AdxU5CW8 ''Bit String Flicking by Ravi Yeluru'' ('''hemsra''')]<br />
<br />
Walks through two problems from the Junior Division.<br />
<br />
|-<br />
| <youtube width="300" height="180">https://youtu.be/aa_lQ8gft60</youtube><br />
| [https://youtu.be/aa_lQ8gft60 ''ACSL BitString Flicking Contest 2 Worksheet 1'' ('''misterminich''')]<br />
<br />
Solves a handful of problems given in previous years at the Intermediate Division level.<br />
<br />
|}<br />
<br />
<br />
<br />
<!--<br />
{|<br />
|-<br />
| <youtube width="300" height="180">URL</youtube><br />
| [URL ''TITLE'' ('''AUTHOR''')]<br />
<br />
DESCRIPTION<br />
|}<br />
--></div>Jerry