Table of contents
The logic was discovered by Greeks and formalized by Aristotle. Logic means thought or reason. Initially the logic was described only by philosophy. In time a new mathematical branch was developed. Logic is the science of truth. The purpose of logic is wisdom.
Importance of Logic
Despite common believe that you can learn logic by yourself by playing games like Chase is false. Logic is a precise science discovered and defined by Greeks and refined by mathematicians.
Logic is used in natural spoken languages. We use Logic to resolve problems. If you do not know anything about logic you can’t learn properly software development and cording.
Fundamental Concepts
Before you can understand logic we must define some words and rules that are well established and can’t be invented by yourself. Many software developers do not understand the definitions and therefore can’t have meaningful conversations and arguments. Read the entire article slowly to learn these things before you can say you know logic.
Logical inference: Using valid arguments into a sentence we can derive a logical conclusion. Sound arguments will produce the same conclusion no matter who makes the arguments or who derive the conclusion.
Logical inference is the most important concept in logic. It is also known as deduction or implication. This is a conclusion we reach after we study the arguments or premises into a sentence. Inference is a way of thinking and reasoning.
The inference and reason do not work the same in all cultures. For example a Christian will not reach the same conclusion from a religious sentence as another person that is Buddhist or Muslim. The words may be interpreted in different ways and lead to different conclusions.
Sentences: are enumerations of words that together express an idea, describe a situation or fact, give a command or inquiry about a fact, status or situation. Sentences can be classified in four categories:
Imperative sentences (orders)
Interrogative sentences ( questions)
Declarative sentences (statements)
Exclamative sentences (surprise)
Elements: A sentence can have 5 elements: { subject, verb, object, complement, and adjunct } (SVOCA). The subject is the performer of an action or the agent of the verb. It is usually at the beginning of a sentence, and it is generated by a noun or any of its equivalents, such as a pronoun, a noun phrase, or a noun clause. Sentences are studied by the grammar of a language.
Imperative sentence: is also a command from a superior entity or authority like Emperor, Queen, Führer, President or God. It is important to know that logic can’t create inference from imperative or interrogative sentences, but only from declarative sentences.
Info: By making inference from imperative sentences one culture can fall into irrational believes, wrong lows and social injustice. Logic can only work based on facts and solid arguments not on irrational commands.
Statements: are declarative sentences that express a fact, idea or opinion. Statements do not make requests, give commands or express a surprise. A statement usually end with dot (.)
Statements can be simple or composite. Composite statements can include arguments. A composite statement is made of simple statements. Most statements are true or false.
Some statements are neither true neither false but have an undetermined value that can be “maybe” or “probable”. There is a special logic for this kind of statements.
Propositions: are statements that can be true or false. A proposition has a single value, is either true, either false but not both in the same time. Propositions are used in propositional logic.
There are examples of declarative sentences that are not propositions. For example, “This sentence is false” is not a proposition, since it can’t be true. For instance, if we assign it the truth value True, then we are saying that “This sentence is false” is in fact true but the sentence is false by definition so it can’t be sometimes true.
Reasoning
Reasoning is the process of using logic and evidence to come to a conclusion. It is a fundamental skill that is essential for everyday life. We use reasoning to make decisions, solve problems, and understand the world around us.
How to reason
There are many different types of reasoning, but they all involve the following steps:
Identify the problem or question. What is the issue that you need to address?
Gather evidence. What information do you need to solve the problem or answer the question?
Form a hypothesis. What is your best guess at the answer?
Test your hypothesis. Use logic and evidence to see if your hypothesis is correct.
Draw a conclusion. Based on your evidence, what is the most likely answer to the problem or question?
Reasoning is a complex process, but it is essential for our everyday lives. By understanding how to reason, we can make better decisions, solve problems more effectively, and understand the world around us more deeply.
Kind of reasoning
Here are several kinds of reasoning:
Inductive reasoning is a type of reasoning that uses specific examples to make a general conclusion. For example, if you see that the sun has risen every day in your life, you might conclude that the sun will rise tomorrow.
Deductive reasoning is a type of reasoning that uses general principles to make specific conclusions. For example, if you know that all men are mortal and that Socrates is a man, you can use deductive reasoning to conclude that Socrates is mortal.
Abductive reasoning is a type of reasoning that uses evidence to infer the most likely explanation for an event. For example, if you find a footprint in the mud, you might use abductive reasoning to infer that someone was walking there recently.
Statistical reasoning is a type of reasoning that uses probability to make inferences about populations based on samples. For example, if you poll 1000 people and find that 60% of them support a certain candidate, you can use statistical reasoning to infer that about 60% of the entire population supports that candidate.
Dialectical reasoning is a type of reasoning that involves the use of argument and counterargument to reach a conclusion. For example, in a debate, each side will present its arguments and then the other side will respond with counterarguments. The goal of dialectical reasoning is to reach a conclusion that is supported by the best evidence, not just the evidence that supports one side's argument.
These are just a few of the many different types of reasoning. Each type of reasoning has its own strengths and weaknesses, and it is important to choose the right type of reasoning for the situation.
Propositional Logic
The propositional logic study the relation between arguments and sentences. Deductive arguments can be propositions or sentences that can have Boolean values: True or False. This logic do not deal with the content of propositions but only with the relation between propositions.
Logic Rules
Logic works with concepts like: propositions, arguments & premises. We understand these concepts better if we enumerate several rules of Logic science.
Identity rule: An argument is identical with itself and not something else;
Non-contradiction rule: An argument cannot be true and false in same sentence;
Validity rule: An argument is valid if the truth of premises lead to truth of the conclusion.
Law of excluded middle: An argument must be either true or false.
Law of sufficient reason: Everything has a reason for being the way it is.
Notation: To create rules and logic expressions we use capital symbols in range: {A -Z} to represent logical propositions. Part of propositional logic are relations like: { AND, OR, NOT } equivalent with {and, or, not}. This relations have very precise rules that makes propositional logic a reliable theory.
Validity and Soundness
A deductive argument is said to be valid if takes a form that makes it impossible for the premises to be true and the conclusion nevertheless to be false. Otherwise, a deductive argument is said to be invalid.
A deductive argument is sound if and only if it is both valid, and all of its premises are true. Otherwise, a deductive argument is unsound. Unsound arguments are invalid.
Symbols: are part of logic. We use symbols to write logic expressions. In computer science we have created ASCII symbols and Unicode symbols. Some of these symbols are useful to create programming languages or scientific papers.
Values: True and False are sometimes represented by symbols: {⊤, ⊥}. Language C has a convention for {⊤ = 1, ⊥ = 0 }. Most modern languages are using constants { True, False } or { true, false }. Fortran 77 use to have {.T. and .F.} but that was changed in Fortran 90.
Operators: Most languages these days are using ASCII symbols for logic operators. In logic algebra we use Unicode symbols. There are new languages that are supporting Unicode symbols: (Julia & Bee).
{ ¬ = NO, ∧ = AND, ∨ = OR, ⊕ = XOR, ↓ = NOR, ↑ = NAND }
NOR: ↓ q = ¬ (p ∨ q)
NAND: p ↑ q = ¬ (p ∧ q)
Implication: Implication is usually represented by symbol →, sometimes =>. This is a logic value created with deduction or inference. It can be derived from two propositions:
P → Q ≡ ¬ P ∨ Q
Equivalence: The equivalence is a relation between two propositions. These are equivalent if they have the same value of truth. The equivalence can be negated. We use symbols { \=, ≡ }. Expression P :⇔ Q means P is defined to be logically equivalent to Q. We sometimes use symbol “:” to define something.
Fundamental rules
There are several Logical rules that are universal and can’t be broken. Nobody can contradict them in any culture or language. If you understand propositional logic rules you have done your first step toward understanding computer science.
If A and B are true, then P = A and B, is true.
If A and B are false, then P = A and B, is false.
If A or B is false, then P = A and B, is false.
If A or B is true, then P = A or B, is true.
If A is true, then P = not A, is false.
If A is false, then P = not A, is true.
In addition operators {OR, AND} are commutative. That means:
A AND B B AND A
A OR B ≡ B OR A
Morgan’s laws
Sometimes you can transform one logical expression into another equivalent expression without knowing the value of the arguments. These rules are very useful in Computer Science to optimize Boolean expressions.
the negation of a disjunction is the conjunction of the negations;
the negation of a conjunction is the disjunction of the negations;
Let’s explain what it means in terms of expressions:
NOT ( NOT A) ≡ A
NOT (A OR B) ≡ (NOT A) AND (NOT B)
NOT (A OR B) ≡ (NOT A) or (NOT B)
Predicate Logic
Predicate logic is an extension of propositional logic. In propositional logic we look at propositions and arguments. That can be true or false but in reality there are many other things that are not true or false. In predicate logic we use terms and relations between terms to establish the value of truth of a proposition. Predicate logic is essential in programming, to deal with numbers and data sets.
Use case
Predicate logic define new terminology and notations. Understanding this terminology will help you read complex documentation used in programming. This may be a language specification or high level requirement that you can receive on the job. You can be invited to elaborate the requirements in detailed design that require logic.
Predicate
A predicate is a property or a relation between one or more terms. One term can be a variable or a constant. A predicate is not a logic entity but it can be evaluated to value True, False or invalid, depending on the range of predicate arguments.
Predicates with one argument, are called monadic. Predicates with more arguments are called dyadic, n-adic or polyadic. Some languages are using monadic predicates while other languages can accept polyadic predicates.
Arguments
The arguments are specific values, used to evaluate a predicate. Sometimes the arguments are called: predicate variables or parameters. In programming and mathematics a predicate is a function or an expression that can be evaluated to True or False depending on the arguments.
Expressions
Simplest predicates are the ones expressing properties of things. We use uppercase letters to express a predicate and lowercase letters to express arguments. Some examples of predicates:
A(x): x is tall
B(x,y): x owes money to y
C(x,y,z): x borrowed y from z
Domain
A variable used in a predicate can be bound to a specific domain. When a variable is not bound, is called “free variable”. This is not an argument but it can influence the result of predicate. In logic papers you may encounter the name “universe of discourse” (UD) that is actually a domain or range of values from a particular data set.
Data set
A data set is a range of values. It can be numeric or can represent symbols or objects. A data set can be empty, or can have one or more elements. Some data sets can have an infinite number of elements. In a dataset the elements are unique. The elements in a dataset are usually ordered. A data set is represented as an enumeration of symbols separated by comma and enclosed in brackets, like:
A = {a, b, c}
N = {1,2,3}
Relations
Elements in a dataset can be associated using a relation. A relation between two arguments is called binary relation. The elements of a binary relation is the Cartesian product (x). A relation R is a predicate with (at least) two arguments:
R = A x N = {(a,1), (a,2), (a,3), (b,1), (b,2), (b,3), (c,1), (c,2), (c,3)}
In logic, sometimes we use symbol “∼” to define relations: For example: x∼y means x is related to y. Also we can say that pair (x,y) belong to relation “∼”. Most of the time a relation is represented by a binary operator. For example we can use { =, <, > } to express the relation between numbers.
Quantifiers
In logic we use quantifiers to refer to a set of elements. The quantifier is a symbol that specify one or more elements we are referring to. So far I have not found programming languages that are using quantifiers. Usually a quantifier is implemented using one or more statements.
∀ = all (universal quantifier)
∃ = exist (existential quantifier)
Note: Qualifiers can be combined together to create meaningful predicate expressions. Most common we can use for all elements in domain there is or exist x that satisfy a relation R(x).
In programming, the exist "∃" can be implemented by searching for a particular element in a data set. If the element satisfy the relation the predicate is True, otherwise False.
Belonging
We can express if an element belong or does not belong to a particular domain or dataset. This is very helpful to establish meaningful logic expressions involving data sets.
∈ means: “belong”
∉ means: “does not belong”
Sometimes we factor out a qualifier to refer to more than one element. For example the expression: ∃(x,y,z) ∈ {0,1,2,3,4,5,6,7,8,9}, it means exist a pair of 3 single digit numbers.
Note: In programming we can refer to a range of numbers using square brackets. [x-y] or [x..y] or [x: y]. This convention is not the same in all languages. You must learn the specific syntax.
Identity
Identity is an equivalence relation. We have seen this symbol before, used for propositional logic: { “=” , “≡”}. This symbol is polymorphic. It can be used with any kind of elements not only propositions but also predicates or terms. It’s because identity relation is symmetric, transitive and reflexive.
Properties
Understanding relations, assume to know the symbol definition, and the properties of specific relations. Next 3 properties are very important:
relation ”∼” is symmetric: ∀(a,b) ∈ R*(a* ∼ b) \=> (b ∼ a)
relation ”∼” is transitive: ∀(a) ∈ R*(a* ∼ a)
relation ”∼” is reflexive: **∀(a, b, c) ∈ R((a∼b) ∧ (b∼c)) => (a ∼ c)
Conclusion
In this short article, I have just scratch the surface of Logic science. You like it so far? Encourage me to post other articles about Logic if you like this kind of knowledge.
Learning a programming language will explain the specifics. You will be able to create and optimize logic expressions using this basic knowledge. Now you can say you know Logic.
References
Predicate logic is used in first order logic and logic calculus. I hope I made you curious so you are prepared to study more. I advice you to study these articles:
Monadic predicate calculus :Wikipedia
Follow up: Sage-Code organization offers free training and premium services. Visit our homepage and start learning Software Engineering and Programming Languages. We have a friendly community for beginners. I hope you visit and join our group.
Hope this helps. Enjoy life, learn and prosper 🖖🏼