Hideous Humpback FreakSoftware and Powerlifting
http://www.hideoushumpbackfreak.com/
http://www.rssboard.org/rss-specificationBlogEngine.NET 3.1.0.1en-UShttp://www.hideoushumpbackfreak.com/opml.axdhttp://www.dotnetblogengine.net/syndication.axdDale AlleshouseHideous Humpback Freak0.0000000.000000Gödel, Artificial Intelligence, and Confusion<div id="AdnTop"><div class="AdnTopLeft" style="float:left"></div><div class="AdnTopRight" style="float:right"></div><div style="clear:both"></div></div><p>Sentient software is the hot topic as of late. Speculative news about Artificial Intelligence (AI) systems such as Watson, Alexa, and even autonomous vehicles are dominating social media. It’s feasible that this impression is nothing more than Baader-Meinhof phenomenon (AKA frequency illusion). However, it seems that the populace has genuine interest in AI. Questions abound. Are there limits? Is it possible to create a factitious soul? Gödel’s incompleteness theorem is at the core of these questions; however, the conclusions are cryptic and often misunderstood.</p> <p>Gödel’s incompleteness theorem is frequently adduced as proof of antithetical concepts. For instance, Roger Penrose’s book <i>Shadows of the Mind</i> claims that the theorem disproves the possibility of sentient machines (Penrose, 1994, p. 65). Douglas Hofstadter asserts the opposite in his book, <i>I Am Strange Loop</i> (Hofstadter, 2007). This article aims to provide a cursory view of the theorem in laymen’s terms and elucidate its practical implications on AI. </p><h4>Context</h4> <p>Gödel’s Incompleteness Theorem is best understood within its historical context. This section covers requite concepts and notable events to provide the reader with adequate background knowledge. This is not meant to be comprehensive coverage of the material: rather it is stripped down to essentials. </p><h5>The Challenge</h5> <p>The mathematics community was never filled with more hope than at the turn of the twentieth century. On August 8<sup>th</sup>, 1900, David Hilbert gave his seminal address at the Second International Congress of Mathematics in which he declared, “in mathematics there is no ignorabimus” (Petzold, 2008, p. 40). Ignorabimus is a Latin word meaning “we shall not know”. Hilbert believed that, unlike some other branches of science, all things mathematical were knowable. Furthermore, he framed a plan to actualize a mathematical panacea. </p><p>In this address, Hilbert outlined ten open problems and challenged the mathematics community to solve them (this was a subset of twenty-three problems published by Hilbert). The problem of relevance for this article is the second which is entitled, <i>The Computability of Arithmetical Axioms</i>. Hilbert’s second problem called for the axiomatization of real numbers “to prove that there are no contradictory, this is, that a finite number of logical steps based upon them can never lead to contradictory results” (Petzold, 2008, p. 41). More concisely, Hilbert wished to axiomatize number theory. </p><p>The following sections delve into axiomatization. However, a pertinent idea here is the phrase “finite number of logical steps”. In modern nomenclature, this is known as <i>algorithmic</i>. Hilbert, along with his contemporaries, believed that every mathematical problem was solvable via an algorithmic process. (Petzold, 2008) This is a key concept that will be revisited after exploring axiomatization. </p><h5>Axiomatization</h5> <p>Stated concisely, axiomatization is a means of deriving a system’s theorems by logical inferences based on a set of axioms. Axioms are unprovable rules that are self-evidently true. The most well-known axiomatized system is Euclidean geometry; therefore, it serves as an archetype for understanding axiomatic systems. The whole of Euclidean geometry is based on five axioms. </p><ol> <li>A straight-line segment can be drawn joining any two points.</li> <li>Any straight-line segment can be extended indefinitely in a straight line.</li> <li>Given any straight-line segment, a circle can be drawn having the segment as radius and one endpoint as center.</li> <li>All right angles are congruent.</li> <li>If two lines are drawn which intersect a third in such a way that the sum of the inner angles on one side is less than two right angles, then the two lines inevitably must intersect each other on that side if extended far enough.</li></ol> <p>(Wolfram Research, Inc., 2017) </p><p>As a small aside, the fifth axiom is also known as the <i>parallel postulate</i>. This has the been the subject of mathematical quandary for centuries. It is highly recommended that the enthusiastic reader perform additional research on the subject. </p><p>These five axioms form the foundation of geometry. Pythagorean theorem, Pons Asinorum, Congruence of triangles, Thales' theorem, and countless others are derived via logical inferences based on the assumption that these self-evidentiary axioms are true. Axioms provide a solid foundation for a system, much like the cornerstone of a building. </p><p>Another key concept introduced in the previous paragraph is <i>logical inferences</i>. It’s not enough to have a firm foundation of axioms. Theorems derived from the axioms must be likewise sound and logical inference offers a guarantee of said soundness. </p><h5>Logical Inference</h5> <p>The process of connecting axioms to theorems cannot rely on intuition in any way. This is to say that they are definitive rules and constructs in which logical inference can be validated. This is important because the legitimacy of axioms is irrelevant if conclusions drawn from them are not completely consistent. A strong, stable, and trusted system must be composed of theorems that use valid logical inferences stemming from axioms. </p><p>It is beyond the scope of this blog post to give even a cursory explanation of logical systems of inference. However, it’s important for the reader to understand that formal logic has stringent rules and notations much like any mathematical system. Logic statements are written and manipulated like any other mathematical formulas. This allows for the creation of proofs that cement the validity from the bottom up. </p><p>Each theorem is analogous to a brick in a house. Because the theorem sits firmly on either an axiom or another theorem planted on an axiom, it’s validity is confirmed. This is commonly known as infinite regress. All the theorems taken together form a strong and stable system capable of being trusted. Formalism expands on the concept. </p><h5>Formalism</h5> <p>Recall the <i>Computability of Arithmetical Axioms</i> problem outlined in <i>The Challenge</i> section. Hilbert envisioned <i>Formalism</i> as the solution to this problem. Formalism, as conceived by Hilbert, is a “system comprised of definitions, axioms, and rules for constructing theorems from the axioms” (Petzold, 2008, p. 45). It is often described as a sort of <i>metamathematics</i>. Hilbert envisioned a formal logic language where axioms are represented as strings and theorems are derived by an algorithmic process. These concepts were introduced in the previous two chapters. A new concept to this section is the qualities that such a system must possess. </p><p>For a system, such as formalism, to truly axiomatize the whole of arithmetic, it must have four qualities which are outlined below. </p><ul> <li><i>Independence</i> – There are no superfluous axioms.</li> <li><i>Decidability</i> – A algorithmic process for deriving the validity of formulas.</li> <li><i>Consistency</i> – It is NOT possible to derive two theorems that contradict one another.</li> <li><i>Completeness</i> – Ability to derive ALL true formulas from the axioms.</li></ul> <p>(Petzold, 2008, p. 46) </p><p>As a small aside, there is a fair bit of legerdemain happening here. The concepts of truth, formulas, theorems, and proof are purposely glossed over to avoid minutia. Curious readers are encouraged to investigate further. </p><p>The two qualities that are particularly cogent to Gödel’s incompleteness theorem are consistency and completeness. Luckily, they are both self-explanatory. A system that is both complete and consistent will yield all possible true formulas, none of which are contradictory. </p><h5>Why? </h5> <p>The truth is that axiomatization is a fastidious process that can seem maddingly pedantic. One may be forced to question the very premise that it is a good thing. One can further postulate that simple human intuition is sufficient. However, recall the concept of infinite regress called out in the last paragraph of the <i>Logical Inference</i> section. New theorems are built upon existing theorems. Without stringent formal logic rules, systems become a “house of cards”. Mistakes found in foundational theorems can bring the entire system crashing down. </p><p>An archetypal example is Cantor’s set theory. The details of the theory are largely irrelevant to this line of inquiry, but the curious reader should refer to <a href="http://hideoushumpbackfreak.com/post/2017/02/05/Just-Enough-Set-Theory-Set-Theory-Defined-(Part-1-of-3)">this</a> set of blog posts for more information. In short, set theory took the mathematical world by storm. Countless mathematicians augmented it by building new abstractions on top of it. Bertrand Russel discovered a fatal flaw known as <i>Russel’s Paradox</i> which brought the system down like a proverbial “house of cards”. Formalism is meant to avoid similar debacles. </p><h5>Principia Mathematica</h5> <p>The <i>Principia Mathematica</i> is an infamous three-volume treatise by Alfred North Whitehead and Bertrand Russell published in 1910, 1912, and 1913. It is a truly herculean attempt to formalize the whole of arithmetic. The work is dense and inaccessible to even most mathematicians (Nagel & Newman, 2001). The system set forth sets the stage for Gödel’s incompleteness theorem. </p><h4>Incompleteness Theorem</h4> <p>In 1931, Kurt Gödel published a seminal, albeit recondite, paper entitled <i>On Formally Undecidable Propositions of Principia Mathematica and Related Systems</i>. The paper dismayed the whole of the mathematical community despite its esoteric content. It not only trampled the validity of <i>Principia Mathematica</i>, it proved that such a system isn’t achievable by any means. The implication being that Hilbert’s second problem, <i>The Computability of Arithmetical Axioms</i>, will never have a satisfactory solution. </p><p>In short, Gödel proved that any system complex enough to encompass simple arithmetic cannot be both complete and consistent as defined in the <i>Formalism</i> section. Through a clever method of converting logical expressions to numbers, the proof showed that any such system will enable the creation of a self-referential statement in the form of “this statement is false”. </p><p>The previous paragraph is a blatant over-simplification of Gödel’s incompleteness theorem. The intimate details of the proof are well beyond the scope of this humble article. As mentioned so many times throughout this work, the reader is encouraged to continue research independently. On a positive note, the arcane details are not requisite for comprehension of the implications. </p><h4>Implications</h4> <p>In short, the implications of Gödel’s Incompleteness Theorem are nothing more than that an axiomatic system of logic cannot be both complete and consistent. Expanding on that, it is not possible to derive an algorithm that will generate all possible proofs of a formalized system. One can then infer that it is not possible to write a computer program to generate said proofs. </p><p>There have been countless extrapolations based on the implications stated above. For instance, a commonly adduced argument is that there are more truths in the universe than there are proofs. Likewise, there are some things that are obviously true that cannot be formally proven. While these are both true, be careful not to fall into the enticing trap of applying the rule to anything outside of axiomatic systems of logic. </p><h4>Why the Confusion?</h4> <p>Although it’s a rather unsatisfying observation, the reality is that Gödel’s proofs are onerous to all but accomplished logicians. Despite this, the implications are far reaching. This situation creates a particularly fertile breeding ground for misconceptions. Many venerated experts within other disciplines attempt to apply the theorem by fallacious means. </p><p>A cursory Google search for “Gödel’s incompleteness theorem and God” will yield seemingly boundless results with varied interpretations. The fact of the matter is, the theorem strictly applies to formal axiomatic systems of logic. It does not apply to religious texts. Likewise, it has no implications on the validity of the afterlife or mystical intuition. (Tieszen, 2017, p. Kindle Loc. 1173) </p><p>As an example, Gödel’s ontological argument is often cited by theists because it formally proves the existence of God. Given the description, it is easy to see how someone ignorant of formal logical proofs could draw fallacious conclusions. As stated previously, Gödel’s proofs apply exclusively to formal axiomatic systems of logic. The concept of God is far from this. Gödel himself said that “it was undertaken as a purely logical investigation, to demonstrate that such a proof could be carried out on the basis of accepted principals of formal logic” (Tieszen, 2017, p. Kindle Loc. 2158). He also hesitated to publish “for fear that a belief in God might be ascribed to him” (Tieszen, 2017, p. Kindle Loc. 2158). </p><p>The cogent point is that it is easy to misinterpret the significance of Gödel’s work. It is difficult for anyone lacking a strong background in mathematical logic to draw valid conclusions based on the incompleteness theorem. Gödel’s work is best confined to scientific contexts. </p><h4>Implications for Artificial Intelligence</h4> <p>The thesis of this work is to define the implications of Gödel’s incompleteness theorem on AI. Unfortunately, a surfeit of background concepts is requisite to comprehension and the author humbly apologizes for the necessary discomfort. Possibly more disappointing is that the verdict is not as definitive as one may suppose as this section explains. </p><p>One thing is definite, it is not possible to use a computer to automatically derive proofs from an axiomatic system. Hilbert’s dream of automated formalization is inert. On the bright side, if it were many mathematicians would be out of work. Some claim, as does Roger Penrose, that this necessarily precludes any possibility of AI within the current computational model. Consider this, a human can necessarily comprehend some truths that a machine cannot. The insinuation is that humans are endowed with creativity that is not obtainable by a machine. Mr. Penrose postulates that this is a quantum effect that is beyond our current understanding. (Penrose, 1994) </p><p>Douglas Hofstadter passionately refutes Roger Penrose’s claims. He believes that the said limits stem from a fundamental misunderstanding of how the brain works and presents a compelling model of consciousness in his book, <i>I Am Strange Loop (Hofstadter, 2007)</i>. Theorem proving is by no means the only way to make a machine “think”. “The human mind is fundamentally not a logic engine but an analogy engine, a learning engine, a guessing engine, and esthetics-driven engine, a self-correcting engine” (Nagel & Newman, 2001, p. Kindle Loc. 146). From this frame of reference, Gödel’s incompleteness theorem doesn’t apply to AI. </p><p>Penrose and Hofstadter sit among varied experts with similar opinions. With the considerable amount of resources funneled into AI projects, the final verdict will be decided in due course of time. Not that this should sway the reader in any way, but the author tends to side with Mr. Hofstadter. The reader is encouraged to do their own research and form their own opinions. </p><h4>Conclusion</h4> <p>Gödel’s incompleteness theorem is inextricably associated with philosophy, religion, and the viability of Artificial Intelligence (AI). However, Gödel’s work is in a recondite field and its applicability beyond axiomatic systems of logic is perplexing and often misapplied. In the final analysis, the theorem’s only definitive assertion is that it is not possible for an axiomatic system of logic to be both consistent and complete. Many experts make conflicting ancillary claims and it’s difficult to draw any absolute conclusions. </p><p>This article presents a simplistic high-level view of Gödel’s incompleteness theorem aimed at the novice with limited exposure. It is highly recommended that readers use this as a starting point for much deeper exploration. The books listed in the bibliography are all excellent references for further research. </p><h4>Biography</h4> <p>Hofstadter, D. (2007). <i>I Am A Strange Loop.</i> Retrieved 8 27, 2017 </p><p>Nagel, E., & Newman, J. R. (2001). <i>Gödel's Proof: Edited and with a New Foreword by Douglas R. Hofstadter.</i> (D. Hofstadter, Ed.) New York University Press, NY. Retrieved 8 27, 2017 </p><p>Penrose, R. (1994). <i>Shadows of the Mind.</i> Oxford University Press p. 413. Retrieved 8 27, 2017 </p><p>Petzold, C. (2008). <i>The Annotated Turing.</i> Indianapolis: Wiley Publishing, Inc. </p><p>Tieszen, R. (2017). <i>Simply Gödel.</i> New York: Simply Charly. </p><p>Wolfram Research, Inc. (2017, October 30). <i>Euclid's Postulates</i>. Retrieved from Wolfram Math World: http://mathworld.wolfram.com/EuclidsPostulates.html</p><div id="AdnBottom"><div class="AdnBottomLeft" style="float:left"></div><div class="AdnBottomRight" style="float:right"></div><div style="clear:both"></div></div>
http://www.hideoushumpbackfreak.com/post/2017/11/21/Godels-Artificial-Intelligence-and-Confusion
dalealleshouse@gmail.comhttp://www.hideoushumpbackfreak.com/post/2017/11/21/Godels-Artificial-Intelligence-and-Confusion#commenthttp://www.hideoushumpbackfreak.com/post.aspx?id=2eb6530c-87a1-492d-a08d-156f433aa423Tue, 21 Nov 2017 21:49:00 +0000SoftwareComputerScienceMathGodeldalealleshousehttp://www.hideoushumpbackfreak.com/pingback.axdhttp://www.hideoushumpbackfreak.com/post.aspx?id=2eb6530c-87a1-492d-a08d-156f433aa4231http://www.hideoushumpbackfreak.com/trackback.axd?id=2eb6530c-87a1-492d-a08d-156f433aa423http://www.hideoushumpbackfreak.com/post/2017/11/21/Godels-Artificial-Intelligence-and-Confusion#commenthttp://www.hideoushumpbackfreak.com/syndication.axd?post=2eb6530c-87a1-492d-a08d-156f433aa423Diagonalization?<div id="AdnTop"><div class="AdnTopLeft" style="float:left"></div><div class="AdnTopRight" style="float:right"></div><div style="clear:both"></div></div><p>The goal of this article is to provide laymen with a conceptual understanding of diagonalization. Those interested in a deep dive full of mathematical jargon will be sorely disappointed. However, this piece is the perfect resource for a general understanding of the topic devoid of the more arcane details. Unlike the majority of my writing, this is not directly applicable to the daily responsibilities of software professionals. It is purely an endeavor to satisfy intellectual curiosity. </p><h4>Why?</h4> <p>The impetus for this writing comes from a colleague who contacted me after reading my blog series on Set Theory (<a href="http://hideoushumpbackfreak.com/post/2017/02/05/Just-Enough-Set-Theory-Set-Theory-Defined-(Part-1-of-3)">Set Theory Defined</a>, <a href="http://hideoushumpbackfreak.com/post/2017/02/19/Just-Enough-Set-Theory-Set-Operations-(Part-2-of-3)">Set Operations</a>, <a href="http://hideoushumpbackfreak.com/post/2017/02/22/Just-Enough-Set-Theory-When-Sets-Collide-(Part-3-of-3)">When Sets Collide</a>). The posts made pithy mention of Cantor’s diagonalization proof with implications on infinite cardinality. My friend’s search for a concise explanation proved to be unfruitful. The conversation naturally progressed toward Alan Turing’s seminal paper: <i>On Computable Numbers,</i> which also employs a diagonalization proof. Cantor and Turing both played a major part in shaping computer science. Therefore, although it is not likely that the majority of software professionals will ever employ diagonalization, it’s a crucial part of computing history. </p><h4>What Are We Trying to Prove?</h4> <p>Diagonalization is a mathematical proof demonstrating that there are certain numbers that cannot be enumerated. Stated differently, there are numbers that cannot be listed sequentially. Consider all the numbers on the number line as shown in <i>Figure One – Number Line</i>.</p> <p align="center"><a href="http://hideoushumpbackfreak.com/image.axd?picture=4-1.png"><img title="4-1" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="4-1" src="http://hideoushumpbackfreak.com/image.axd?picture=4-1_thumb.png" width="404" height="106"></a></p> <p>First consider the set of positive whole numbers including zero. These are known as <i>natural</i> or <i>counting</i> numbers and are denoted as `\mathbb{N}`. Most kindergarten curriculum teaches how to enumerate this set: starting with zero add one to the current number to get the next number ad infinitum. </p><p>Adding negative numbers to `\mathbb{N}` produces the set of integers denoted by `\mathbb{Z}`. Again, this set is also easy to enumerate by simply listing it as follows: `0, 1, -1, 2, -2, 3, -3, …`. </p><p>Now consider expanding on `\mathbb{Z}` by adding fractions to create the set of rational number denoted as `\mathbb{Q}`. The term rational signifies that a number can be expressed as a ratio such as `1/2` or `23/345`. These numbers fit between the whole number on the number line and there is an infinite amount of fractional numbers between each set of natural numbers. That is to say, regardless of the location of two rationals on the number line, it’s always possible to find another number between them. With some ingenuity, these numbers can also be enumerated in several different ways. Enumerating rational numbers, while fascinating, is beyond the scope of this post. The reader is encouraged to either just accept my word as fact or do research. <a href="http://www.cs.utexas.edu/users/sandip/acl2-09/presentations/rationals-talk.pdf">Here</a> is a good place to start. </p><p>Although it seems as if we’ve run out room on the number line, that isn’t actually the fact. There is another class of number that has been baffling mathematicians throughout the ages: irrational. It’s a bit perplexing, but irrationals fit between rationals on the number line (no matter how many times I think about that, it amazes me). Grade school curriculum typically introduces the concept with renowned numbers such as `\pi` or `e`. These are numbers that cannot be expressed as a ratio. The decimal representation consists of an infinite series of digits with no repeating pattern. Any calculations involving irrationals are approximations because it’s impossible to express them in a finite context. Adding these to `\mathbb{Q}` produces the set of real numbers denoted as `\mathbb{R}`. Irrational numbers are the target of our inquisition. </p><p>As a matter of note, the set of irrational numbers can be further divided into the sets of algebraic and transcendental numbers. Algebraic numbers can in fact be enumerated. However, this is a bit of minutia that isn’t really necessary for understanding diagonalization. Once again, the curious reader is encouraged to rely on Google for further inquiry. </p><p>The question is, how is it possible to prove that irrational numbers are not enumerable. With an understanding of the problem, we can turn our attention to the solution which is diagonalization. </p><h4>Reductio Ad Absurdum</h4> <p>Diagonalization is a type of proof known as reductio ad absurdum which is Latin for reduction to absurdity. It is common amongst mathematicians and philosophers alike. The premise is to first assume a proposition is true and then disprove it via deductive reasoning thus reducing it to an absurd conclusion. </p><p>One popular example of a reductio ad absurdum proof is that there is no smallest fractional number. Assume there is such a number: it can be divided by two to create a smaller number. Therefore, the original assumption is absurd. Another illustration is an alibi. First assume the suspect committed the crime. If the accused is known to be at a different location when the crime took place, it’s absurd to assume that they were also at the scene of the crime. </p><h4>Diagonalization</h4> <p>Having addressed all the introductory trivialities, it’s time to get to the point. The diagonalization proof is as follows. First assume that it is possible to enumerate all irrational numbers. If this is true, it should be impossible to devise a number that is not included in this list. Examine <i>Figure Two – Diagonalization</i> and stretch the mind to imagine that this is in fact the list of all irrational numbers: the list is infinitely long and each number expands on endlessly. Next, draw a diagonal line down the center of the list and write down the resulting infinite number. In this case, the number is `0.13579135…`. Next add 1 to each digit expect in the case of nine which becomes a zero. This results is the number `0.24680246…`. Is this number contained in the list? It’s obviously not the first number because the first digit does not match. The same holds true for the second number because the second digit has to be different. Continue this line of logic for every number and it’s obvious that the devised number is not in the list. The reader should take a few minutes to let that sink in.</p> <p align="center"><a href="http://hideoushumpbackfreak.com/image.axd?picture=4-2_2.png"><img title="4-2" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="4-2" src="http://hideoushumpbackfreak.com/image.axd?picture=4-2_thumb_2.png" width="404" height="410"></a></p> <p>Keep in mind, this is purely a thought experiment. Obviously, <i>Figure Two – Diagonalization</i> is not an infinite list and each number is not truly irrational. It’s impossible to construct such a list in a finite context. However, the line of logic holds true. </p><p>It is common to wonder why diagonalization does not apply to `\mathbb{Q}`. The concise answer is that those numbers have finite digits and irrationals do not. </p><h4>Implications</h4> <p>Accepting that the diagonalization proof is valid, it has some profound implications. At first glance, it’s difficult to understand how the fact that it’s impossible to enumerate irrational numbers has bearing on the world in any way. However, many people have derived some amazing conclusions. <a href="https://en.wikipedia.org/wiki/Cantor's_diagonal_argument">Cantor</a> showed that there are in fact multiple infinities. <a href="https://en.wikipedia.org/wiki/Turing's_proof">Turing</a> used diagonalization to prove the limits of computability. It’s even been employed by philosophers to prove that there are an insufficient number of proofs to prove all the truths in the universe. More concisely, some truths are unproveable. The implications lead down an exceedingly dark and deep rabbit hole. </p><h4>Conclusion</h4> <p>Diagonalization is a reductio ad absurdum proof that demonstrates the impossibility of enumerating irrational numbers. It is relatively easy for non-mathematicians to understand. While only tangentially related to software engineering, it’s a fascinating concept that sheds light on the foundations of computing and indeed the world. </p><p>As always, thank you for taking the time to read this article. Please feel free to contact me with any questions or concerns. </p><div id="AdnBottom"><div class="AdnBottomLeft" style="float:left"></div><div class="AdnBottomRight" style="float:right"></div><div style="clear:both"></div></div>
http://www.hideoushumpbackfreak.com/post/2017/02/24/Diagonalization
dalealleshouse@gmail.comhttp://www.hideoushumpbackfreak.com/post/2017/02/24/Diagonalization#commenthttp://www.hideoushumpbackfreak.com/post.aspx?id=96503e93-490e-4255-bdec-be949c9365b0Fri, 24 Feb 2017 18:49:00 +0000SoftwareMathSetTheoryComputerSciencedalealleshousehttp://www.hideoushumpbackfreak.com/pingback.axdhttp://www.hideoushumpbackfreak.com/post.aspx?id=96503e93-490e-4255-bdec-be949c9365b02http://www.hideoushumpbackfreak.com/trackback.axd?id=96503e93-490e-4255-bdec-be949c9365b0http://www.hideoushumpbackfreak.com/post/2017/02/24/Diagonalization#commenthttp://www.hideoushumpbackfreak.com/syndication.axd?post=96503e93-490e-4255-bdec-be949c9365b0Just Enough Set Theory – When Sets Collide (Part 3 of 3)<div id="AdnTop"><div class="AdnTopLeft" style="float:left"></div><div class="AdnTopRight" style="float:right"></div><div style="clear:both"></div></div><p>Welcome to the final installment of this three-part series on set theory. The first piece, <a href="http://hideoushumpbackfreak.com/post/2017/02/05/Just-Enough-Set-Theory-Set-Theory-Defined-(Part-1-of-3)">Set Theory Defined</a>, detailed requisite foundational knowledge. The second article, <a href="http://hideoushumpbackfreak.com/post/2017/02/19/Just-Enough-Set-Theory-Set-Operations-(Part-2-of-3)">Set Operations</a>, outlined some beneficial set algorithms. This post develops the concepts laid out in the first two; therefore, it is highly recommended that readers begin there. <p>Individual sets have many useful properties; however, preforming operations on multiple sets provides even greater utility. This piece outlines four such operations. Each operation provides a concise means for addressing common programming problems that virtually all software professionals encounter. There is a brief description of each from a mathematical perspective followed by JavaScript (ES6) code excerpts demonstrating how to apply theory to real world scenarios. <p><b>NOTE</b>: All code samples are written in ES6 and are therefore not likely to execute directly in a browser. The best option is to use Node or transpile the excerpts using either <a href="https://babeljs.io/">Babel</a> or <a href="https://www.typescriptlang.org/">TypeScript</a>. The working code is available on <a href="https://github.com/dalealleshouse/settheory">GitHub</a> along with execution instructions. <h4>Union</h4> <p>The union of two sets is a set containing the distinct elements from both sets. `\cup` is the mathematical symbol for a union and the union of sets `A` and `B` is denoted as `A \cup B`. An expanded way of representing the union relationship is `\{x| x \in A \vee x \in B\}`, which means every element contained in `A` OR (`\vee`) `B`. <i>Figure One – Union</i> depicts two sets with three elements each. The union is a set with five elements because one item, three, is shared and union returns distinct values. The Venn diagram shows the relationship graphically.</p> <p align="center"><a href="http://hideoushumpbackfreak.com/image.axd?picture=figure3-1.png"><img title="figure3-1" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="figure3-1" src="http://hideoushumpbackfreak.com/image.axd?picture=figure3-1_thumb.png" width="404" height="405"></a></p> <p>Generating the union of two sets is quite easy in ES6 as the code below illustrates.</p><pre class="brush: js;">const A = new Set([1, 2, 3]);
const B = new Set([3, 4, 5]);
const union = new Set([...A, ...B]);
// union = [1,2,3,4,5];</pre>
<p>The astute reader will notice that there’s some legerdemain afoot. The code above uses the ES6 Set data structure instead of standard JavaScript arrays. Set holds only unique elements by ignoring add operations for new values that match existing ones. The algorithm is as easy as concatenating the two sets without the concern of distinct elements. If the code was using standard arrays, there would have to be logic to remove duplicated items. Luckily, converting between sets and arrays is virtually effortless. </p><pre class="brush: js;">const setDataStructure = new Set([1, 2, 3]);
const arrayDataStrcture = Array.from(setDataStructure);</pre>
<p>The problem with the code above is that it’s a rare requirement to union sets containing primitive values. Software engineering is seldom that straightforward. A more realistic scenario is calculating the union between two sets of complex objects where equality becomes problematic. Unlike primitive variables, objects with identical values are not equal because they compare by reference. This abrogates the Set trick from earlier. Suppose the requirement is to compute all bug reports currently in process across two teams and it’s possible that both teams are working on the same bugs simultaneously. The code below demonstrates a solution by first concatenating the two sets and then removing duplicates using the filter method introduced in the last article. Notice the only equality check is via the Id. Obviously, this won’t work for every scenario and depending on the size of the sets and performance requirements it is possible to write generic deep equality methods (or use a library like underscore).</p><pre class="brush: js;">const teamABugs = [
{ id: 1, name: "Screen Explodes" },
{ id: 2, name: "Keyboard Burts into Flames" },
{ id: 3, name: "Submit button off by 1 pixel" }];
const teamBBugs = [
{ id: 5, name: "Randomly Dials Russian Hackers" },
{ id: 6, name: "Publishes CC info to the www" },
{ id: 3, name: "Submit button off by 1 pixel" }];
const union = [...teamABugs, ...teamBBugs]
.filter((x, index, array) => array.findIndex(y => y.id == x.id) == index);</pre>
<h4>Intersection</h4>
<p>The intersection of two sets is a set containing distinct shared elements. `A \cap B` is the mathematical representation of a union and the expanded notation is `\{x|x \in A \wedge x \in B \}`. Stated differently, the intersection of set `A` AND (`\wedge`) `B` is every element contained in `A` AND `B`. <i>Figure Two – Intersection</i> depicts the relationship showing the union of `A` and `B` to be a singleton set containing only the number three. Once again, the Venn diagram portrays the relationship.</p>
<p align="center"><a href="http://hideoushumpbackfreak.com/image.axd?picture=figure3-2.png"><img title="figure3-2" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="figure3-2" src="http://hideoushumpbackfreak.com/image.axd?picture=figure3-2_thumb.png" width="404" height="405"></a></p>
<p>Much like union, finding the intersection of two sets using the Set data structure and primitive types is easy. The code below shows how it’s a matter of using the filter method to check to see if an item is also stored in the other set.</p><pre class="brush: js;">const A = new Set([1, 2, 3]);
const B = new Set([3, 4, 5]);
const intersect = [...A].filter(x => B.has(x));
// intersect = [3];</pre>
<p>The code above is a bit fanciful. Consider instead a role protected resource. Possessing any one of many roles allows users to access said resource. Users each have a set of associated roles. There are a few different ways to achieve this, but finding the intersection between the user’s roles and the resource’s required roles is the most manageable. See the code below.</p><pre class="brush: js;">const resourceRoles = [
{ id: 1, name: "Administrator" },
{ id: 2, name: "Super User" }];
const user = { id: 314, name: "Edsger Dijkstra", roles: [
{ id: 1, name: "Administrator" },
{ id: 2, name: "User" }] }
const hasAccess = resourceRoles
.filter(x => user.roles.find(y => y.name == x.name)).length > 0;</pre>
<p>All of the caveats about equality described in the Union section also apply here. It’s something programmers need to be cognizant of.
<h4>Difference</h4>
<p>The difference of two sets is sometimes known as the relative complement; both nomenclatures are interchangeable. The concept is simple, the difference is a set made up of the items that are left over after removing the intersection of another set. Otherwise stated, all of the items in set `B` that do not exist in set `A`. Mathematically, this is represented as `\{x|x \in B \wedge x \notin A\}` or the shortened version which is `B\\A`. <i>Figure Three – Difference</i> shows the difference between `B` and `A` to be a set containing four and five. Just as above, there is a representative Venn diagram.</p>
<p align="center"><a href="http://hideoushumpbackfreak.com/image.axd?picture=figure3-3.png"><img title="figure3-3" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="figure3-3" src="http://hideoushumpbackfreak.com/image.axd?picture=figure3-3_thumb.png" width="404" height="405"></a></p>
<p>As an aside, there is also an absolute compliment which is somewhat similar; however, it is outside the scope of this article.
<p>Finding the difference of sets is almost identical to finding the intersection as the code below demonstrates. The only variation is that the predicate passed to the filter method is negated.</p><pre class="brush: js;">const A = new Set([1, 2, 3]);
const B = new Set([3, 4, 5]);
const difference = [...B].filter(x => !A.has(x));
// difference = [4,5];</pre>
<p>Again, a more realistic example is in order. Image that there is a set of actions that must be completed and a set of actions a user has completed. Finding the difference is an easy way to determine if all required actions are complete.</p><pre class="brush: js;">const requiredActions = [
{ id: 1, name: "Electronic Signing" },
{ id: 2, name: "Submission Form" },
{ id: 3, name: "Payment" }];
const userActions = [
{ id: 1, name: "Electronic Signing" },
{ id: 2, name: "Submission Form" }];
const complete = requiredActions
.filter(x => !userActions.find(y => y.name == x.name)).length === 0;
// complete = false
</pre>
<h4>Cartesian Product</h4>
<p>The Cartesian product of two sets is a set of ordered pairs that contain all possible combinations of elements in the two sets. The mathematical representation is `A \times B`. The expanded notation is `\{(a,b)|a \in A \wedge b \in B\}` which means an ordered pair consisting of every element in `A` AND (`\wedge`) every element in `B`. <i>Figure Four – Cartesian Product</i> demonstrates the concept. As a matter of importance, unlike standard products, the Cartesian product is not commutative. Stated mathematically, `A \times B \ne B \times A`. Switching the order of statement will change the order of the pairs.</p>
<p align="center"><a href="http://hideoushumpbackfreak.com/image.axd?picture=figure3-4.png"><img title="figure3-4" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="figure3-4" src="http://hideoushumpbackfreak.com/image.axd?picture=figure3-4_thumb.png" width="404" height="381"></a></p>
<p>The Cartesian product is useful for combinatorics problems. A common example is simulating a deck of cards. Instead of specifying all the cards explicitly in code, it’s easier to define the suits and values as two separate sets and then take the Cartesian product to get the entire deck. See the code below.</p><pre class="brush: js;">const suits = ['Diamond', 'Spade', 'Heart', 'Club'];
const values = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King'];
const cards = suits.reduce((acc, x) => [...acc, ...values.map(y => [x, y])], []);
// Alternatively, it’s possible to return the ordered pair as an object instead of an array
// const cards = suits.reduce((acc, x) => [...acc, ...values.map(y => { return { suit: x, value: y } })], []);</pre>
<p>This code should be starting to look familiar because all the samples make heavy use of the map, reduce, and filter methods. Using ES6, these methods have great utility for mimicking mathematical set operations. Because the code above is similar to previous examples, it doesn’t require further explanation.
<h4>Why Stop at Two?</h4>
<p>Up to this point, all the exhibited set operations employ two sets. However, this is for the sake of brevity. Each operations can act on as many sets as required. For instance, `A \cup B \cup C` is perfectly valid as is `A \times B \times C`. The enthused reader should solidify his/her learning by expanding each code sample to use additional sets.
<h4>Real World Applications</h4>
<p>This series demonstrated how set theory is applied to data structures and demonstrated some novel uses for set operations in order create efficient algorithms. However, this is only a meager representation of all the many and varied applications for software engineering. Relational databases make heavy use of set theory for defining data structure and constructing data queries. In fact, SQL is essentially a set notation. There are several instances in language theory and design where strings are realized as sets and set operations are performed on them. Another prolific use is in computer graphics where points on a plane are treated as sets. The list of applications is considerable. It’s a body of knowledge that no software professional should forsake.
<h4>Conclusion</h4>
<p>Thus concludes this three-part series on set theory. Hopefully, the reader has gained a high-level understanding as well as enough practical knowledge to apply the learning forthwith. The first article outlined the basics and introduced the concept of set mapping. Empty sets, cardinality, subsets, summation, and power sets were introduced in the second piece. Finally, this post presented operations involving more than one set including unions, intersections, differences, and Cartesian products. The method was to first introduce the ideas mathematically and then demonstrate how to apply them using ES6. These concepts should not be considered optional for software professionals because set theory is ubiquitous in computer science.
<p>As always, thank you for reading and please feel free to contact me with questions. I’m also happy to create more in depth posts upon request.</p><a style="display: none" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=608087" rel="tag">CodeProject</a><div id="AdnBottom"><div class="AdnBottomLeft" style="float:left"></div><div class="AdnBottomRight" style="float:right"></div><div style="clear:both"></div></div>
http://www.hideoushumpbackfreak.com/post/2017/02/22/Just-Enough-Set-Theory-When-Sets-Collide-(Part-3-of-3)
dalealleshouse@gmail.comhttp://www.hideoushumpbackfreak.com/post/2017/02/22/Just-Enough-Set-Theory-When-Sets-Collide-(Part-3-of-3)#commenthttp://www.hideoushumpbackfreak.com/post.aspx?id=fde79f15-1887-41db-9e70-d77b64aa7b18Wed, 22 Feb 2017 17:51:37 +0000SoftwareComputerScienceMathSetTheorydalealleshousehttp://www.hideoushumpbackfreak.com/pingback.axdhttp://www.hideoushumpbackfreak.com/post.aspx?id=fde79f15-1887-41db-9e70-d77b64aa7b182http://www.hideoushumpbackfreak.com/trackback.axd?id=fde79f15-1887-41db-9e70-d77b64aa7b18http://www.hideoushumpbackfreak.com/post/2017/02/22/Just-Enough-Set-Theory-When-Sets-Collide-(Part-3-of-3)#commenthttp://www.hideoushumpbackfreak.com/syndication.axd?post=fde79f15-1887-41db-9e70-d77b64aa7b18