generated from PreTeXtBook/pretext-codespace
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a14101
commit e845069
Showing
37 changed files
with
2,240 additions
and
2,407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<chapter xml:id="ch-boolean-algebra" xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
<title>Boolean Algebra</title> | ||
|
||
<introduction> | ||
<p> | ||
This chapter completes the preceding one by explaining how to ask Sage to decide whether a given lattice is a Boolean algebra. | ||
We also illustrate basic operations with Boolean functions. | ||
</p> | ||
</introduction> | ||
<!-- include sections --> | ||
<xi:include href="sec-boolean-algebra.ptx" /> | ||
<xi:include href="sec-boolean-functions.ptx" /> | ||
</chapter> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<chapter xml:id="ch-boolean-algebra" xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
<title>Boolean Algebra</title> | ||
|
||
<introduction> | ||
<p> | ||
This chapter completes the preceding one by explaining how to ask Sage to decide whether a given lattice is a Boolean algebra. We also illustrate basic operations with Boolean functions. | ||
</p> | ||
</introduction> | ||
|
||
<!-- include sections --> | ||
<xi:include href="sec-boolean-algebra.ptx" /> | ||
<xi:include href="sec-boolean-functions.ptx" /> | ||
|
||
|
||
</chapter> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,98 @@ | ||
<section xml:id="sec-boolean-algebra" xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
<title>Boolean Algebra</title><idx><h>Boolean Algebra</h></idx> | ||
<aside> | ||
<p> | ||
In digital electronics, the principles of Boolean algebra guide the design of circuits such as multiplexers, demultiplexers, encoders, and decoders, essential components in telecommunications and signal processing. | ||
</p> | ||
</aside> | ||
<p> | ||
A Boolean algebra is a bounded lattice that is both complemented and distributive. Let's define the <c>is_boolean_algebra()</c> function to determine whether a given poset is a Boolean algebra. The function accepts a finite partially ordered set as input and returns a tuple containing a boolean value and a message explaining the result. Run the following cell to define the function and call it in other cells. | ||
</p> | ||
<sage> | ||
<input> | ||
def is_boolean_algebra(P): | ||
try: | ||
L = LatticePoset(P) | ||
except ValueError as e: | ||
return False, str(e) | ||
if not L.is_bounded(): | ||
return False, "The lattice is not bounded." | ||
if not L.is_distributive(): | ||
return False, "The lattice is not distributive." | ||
if not L.is_complemented(): | ||
return False, "The lattice is not complemented." | ||
return True, "The poset is a Boolean algebra." | ||
</input> | ||
</sage> | ||
<p> | ||
Let's check if the following poset is a Boolean algebra. | ||
</p> | ||
<sage> | ||
<input> | ||
S = Set([1, 2, 3, 4, 5, 6]) | ||
|
||
P = Poset((S, attrcall("divides"))) | ||
|
||
show(P) | ||
</input> | ||
</sage> | ||
<sage> | ||
<input> | ||
is_boolean_algebra(P) | ||
</input> | ||
</sage> | ||
<p> | ||
When we pass <c>P</c> to the <c>is_boolean_algebra()</c> function, <c>LatticePoset()</c> raises an error because <c>P</c> is not a lattice. The <c>ValueError</c> provides more information about the absence of a top element. Therefore, <c>P</c> is not a Boolean algebra. | ||
</p> | ||
<sage> | ||
<input> | ||
T = Subsets(['a', 'b', 'c']) | ||
|
||
Q = Poset((T, lambda x, y: x.issubset(y))) | ||
|
||
Q.plot(vertex_size=3500, border=True) | ||
</input> | ||
</sage> | ||
<sage> | ||
<input> | ||
is_boolean_algebra(Q) | ||
</input> | ||
</sage> | ||
<p> | ||
Let's examine the divisor lattice of 30: | ||
</p> | ||
<sage> | ||
<input> | ||
dl30 = Posets.DivisorLattice(30) | ||
show(dl30) | ||
is_boolean_algebra(dl30) | ||
</input> | ||
</sage> | ||
<p> | ||
Now for the divisor lattice of 20: | ||
</p> | ||
<sage> | ||
<input> | ||
dl20 = Posets.DivisorLattice(20) | ||
show(dl20) | ||
is_boolean_algebra(dl20) | ||
</input> | ||
</sage> | ||
<p> | ||
Here is a classic example in the field of computer science: | ||
</p> | ||
<sage> | ||
<input> | ||
B = posets.BooleanLattice(1) | ||
show(B) | ||
is_boolean_algebra(B) | ||
</input> | ||
</sage> | ||
<aside> | ||
<p> | ||
Software engineers use Boolean algebra to simplify conditions, refactor code, and optimize logic. These skills are crucial for identifying bottlenecks and improving efficiency in real-time systems and performance-critical applications. | ||
</p> | ||
</aside> | ||
</section> | ||
<section xml:id="sec-boolean-algebra" xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
<title>Boolean Algebra</title><idx><h>Boolean Algebra</h></idx> | ||
<aside> | ||
<p> | ||
In digital electronics, the principles of Boolean algebra guide the design of circuits such as multiplexers, demultiplexers, encoders, and decoders, essential components in telecommunications and signal processing. | ||
</p> | ||
</aside> | ||
<p> | ||
A Boolean algebra is a bounded lattice that is both complemented and distributive. Let's define the <c>is_boolean_algebra()</c> function to determine whether a given poset is a Boolean algebra. The function accepts a finite partially ordered set as input and returns a tuple containing a boolean value and a message explaining the result. Run the following cell to define the function and call it in other cells. | ||
</p> | ||
<sage> | ||
<input> | ||
def is_boolean_algebra(P): | ||
try: | ||
L = LatticePoset(P) | ||
except ValueError as e: | ||
return False, str(e) | ||
if not L.is_bounded(): | ||
return False, "The lattice is not bounded." | ||
if not L.is_distributive(): | ||
return False, "The lattice is not distributive." | ||
if not L.is_complemented(): | ||
return False, "The lattice is not complemented." | ||
return True, "The poset is a Boolean algebra." | ||
</input> | ||
</sage> | ||
<p> | ||
Let's check if the following poset is a Boolean algebra. | ||
</p> | ||
<sage> | ||
<input> | ||
P = [1, 2, 3, 4, 5, 6] | ||
|
||
divisibility_poset = Poset((P, attrcall("divides"))) | ||
|
||
show(divisibility_poset) | ||
</input> | ||
</sage> | ||
<sage> | ||
<input> | ||
is_boolean_algebra(divisibility_poset) | ||
</input> | ||
</sage> | ||
<p> | ||
When we pass <m>P</m> to the <c>is_boolean_algebra()</c> function, <c>LatticePoset()</c> raises an error because <m>P</m> is not a lattice. The <c>ValueError</c> provides more information about the absence of a top element. Therefore, <c>divisibility_poset</c> is not a Boolean algebra. | ||
</p> | ||
<sage> | ||
<input> | ||
S = {'a', 'b', 'c'} | ||
|
||
power_set = Subsets(S) | ||
|
||
P = Poset((power_set, lambda x, y: x.issubset(y))) | ||
|
||
P.plot(vertex_size=1000,vertex_shape="") | ||
</input> | ||
</sage> | ||
<sage> | ||
<input> | ||
is_boolean_algebra(P) | ||
</input> | ||
</sage> | ||
<p> | ||
Let's examine the divisor lattice of 30: | ||
</p> | ||
<sage> | ||
<input> | ||
dl30 = Posets.DivisorLattice(30) | ||
show(dl30) | ||
is_boolean_algebra(dl30) | ||
</input> | ||
</sage> | ||
<p> | ||
Now for the divisor lattice of 20: | ||
</p> | ||
<sage> | ||
<input> | ||
dl20 = Posets.DivisorLattice(20) | ||
show(dl20) | ||
is_boolean_algebra(dl20) | ||
</input> | ||
</sage> | ||
<p> | ||
Here is a classic example in the field of computer science: | ||
</p> | ||
<sage> | ||
<input> | ||
B = posets.BooleanLattice(1) | ||
show(B) | ||
is_boolean_algebra(B) | ||
</input> | ||
</sage> | ||
<aside> | ||
<p> | ||
Software engineers use Boolean algebra to simplify conditions, refactor code, and optimize logic. These skills are crucial for identifying bottlenecks and improving efficiency in real-time systems and performance-critical applications. | ||
</p> | ||
</aside> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,61 @@ | ||
<section xml:id="sec-boolean-definition" xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
<title>Definition</title> | ||
<p> | ||
Boolean algebra is a branch of algebra that deals with variables that can take two values: true or false. This form of algebra is foundational in fields such as digital electronics and computer science where binary systems are prevalent. | ||
</p> | ||
<p> | ||
In SageMath, Boolean algebra can be manipulated through various built-in functions designed for handling Boolean variables and expressions. | ||
</p> | ||
<aside> | ||
<title>Notes</title> | ||
<p> | ||
Boolean algebra is crucial in digital circuit design. For example, simplifying the expression of a digital circuit can minimize the number of gates used, which reduces cost and power consumption. Techniques such as Karnaugh maps and Boolean simplification are common in the industry. | ||
</p> | ||
</aside> | ||
<sage> | ||
<input> | ||
B = BooleanPolynomialRing(3, 'x') | ||
f = B('x0 + x1 * x2') | ||
show(f) | ||
</input> | ||
<output> | ||
# Outputs the Boolean expression in polynomial form | ||
</output> | ||
</sage> | ||
<p> | ||
A common structure analyzed in Boolean algebra is the lattice. Below, we show how to work with a divisor lattice, which is a specific type of lattice useful in various mathematical computations. | ||
</p> | ||
<sage> | ||
<input> | ||
p = Posets.DivisorLattice(20) | ||
p.show() | ||
</input> | ||
<output> | ||
# This will display the lattice structure for divisors of the number 20. | ||
</output> | ||
</sage> | ||
<p> | ||
The following Sage cell checks whether the divisor lattice is distributive. A distributive lattice is one where the operations of join and meet distribute over each other. | ||
</p> | ||
<sage> | ||
<input> | ||
p = Posets.DivisorLattice(20) | ||
p.is_distributive(certificate='True') | ||
</input> | ||
<output> | ||
# Returns True if the lattice is distributive, along with a certificate if applicable. | ||
</output> | ||
</sage> | ||
<p> | ||
Another important property in Boolean algebra is the complemented lattice. A complemented lattice is one where every element has a complement in the lattice. | ||
</p> | ||
<sage> | ||
<input> | ||
p = Posets.DivisorLattice(20) | ||
p.is_complemented(certificate='True') | ||
</input> | ||
<output> | ||
# Returns True if the lattice is complemented, along with a certificate if applicable. | ||
</output> | ||
</sage> | ||
</section> | ||
<section xml:id="sec-boolean-definition" xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
<title>Definition</title> | ||
<p> | ||
Boolean algebra is a branch of algebra that deals with variables that can take two values: true or false. This form of algebra is foundational in fields such as digital electronics and computer science where binary systems are prevalent. | ||
</p> | ||
<p> | ||
In SageMath, Boolean algebra can be manipulated through various built-in functions designed for handling Boolean variables and expressions. | ||
</p> | ||
<aside> | ||
<title>Notes</title> | ||
<p> | ||
Boolean algebra is crucial in digital circuit design. For example, simplifying the expression of a digital circuit can minimize the number of gates used, which reduces cost and power consumption. Techniques such as Karnaugh maps and Boolean simplification are common in the industry. | ||
</p> | ||
</aside> | ||
<sage> | ||
<input> | ||
B = BooleanPolynomialRing(3, 'x') | ||
f = B('x0 + x1 * x2') | ||
show(f) | ||
</input> | ||
<output> | ||
# Outputs the Boolean expression in polynomial form | ||
</output> | ||
</sage> | ||
<p> | ||
A common structure analyzed in Boolean algebra is the lattice. Below, we show how to work with a divisor lattice, which is a specific type of lattice useful in various mathematical computations. | ||
</p> | ||
<sage> | ||
<input> | ||
p = Posets.DivisorLattice(20) | ||
p.show() | ||
</input> | ||
<output> | ||
# This will display the lattice structure for divisors of the number 20. | ||
</output> | ||
</sage> | ||
<p> | ||
The following Sage cell checks whether the divisor lattice is distributive. A distributive lattice is one where the operations of join and meet distribute over each other. | ||
</p> | ||
<sage> | ||
<input> | ||
p = Posets.DivisorLattice(20) | ||
p.is_distributive(certificate='True') | ||
</input> | ||
<output> | ||
# Returns True if the lattice is distributive, along with a certificate if applicable. | ||
</output> | ||
</sage> | ||
<p> | ||
Another important property in Boolean algebra is the complemented lattice. A complemented lattice is one where every element has a complement in the lattice. | ||
</p> | ||
<sage> | ||
<input> | ||
p = Posets.DivisorLattice(20) | ||
p.is_complemented(certificate='True') | ||
</input> | ||
<output> | ||
# Returns True if the lattice is complemented, along with a certificate if applicable. | ||
</output> | ||
</sage> | ||
</section> |
Oops, something went wrong.