The word 'logic' originates from the Greek word 'logos', which has a variety of translations such as reason, discourse, or language. In general, logic refers to reasoning conducted or assessed according to strict principles of validity. In computer science (CS), it instead refers to a system or set of principles underlying the arrangements of elements in a computer or electronic device so as to perform a specified task.
The branch symbolic logic uses symbolic notation to represent propositions (statements) and arguments. It formalizes logical relationships using symbols. Compared to natural languages, symbolic logic prioritizes the structure of arguments rather than their real-world meaning. Due to this, it is described as the 'simplest kind of logic' because it abstracts arguments into basic symbols and rules, avoiding ambiguity.
Natural human language is flowery and ambiguous thanks to factors of equivocation, amphiboly, accent, vagueness, and confusion in emotive significances. A formal language — using minimal characters and represented it with a high degree of clarity and simplicity — had to be made to substitute it. Otherwise, there will be potential ambiguity and errors for our computers to interpret.
The goals of formal language are to design the elements of this formal language, translate natural language grammar into symbolic notation, and represent arguments in the formal language.
We will cover the basics and subcategories of symbolic logic using Wumpus World, a logical environment where an agent must navigate safely while avoiding dangerous and searching for gold. The world follows a set of rules that dictate the relationships between pits, breezes, the Wumpus, stenches, and the agent's actions, which AIs will work to uncover.
The Wumpus World environment can be solved with several branches of logic in computer science:
Propositional logic: Studies how entire statements or propositions are combined and modified using logical operators to form more complex statements, focusing on the relationships between those statements.
Example: Scenario of raining and condition of wet ground.
Weaknesses: Struggles with quantifiers ('all', 'some'), cannot represent the meaning of words or concepts, and assumes propositions are either true or false, ignoring uncertainty.
First-order logic: Used to represent and reason about knowledge, allowing for the use of quantified variables over non-logical objects and sentences containing variables, predicates, and quantifiers.
Example: Status of student and condition of enrollment in a university.
Weaknesses: Has difficulty in expressing certain relationships, inefficiency compared to other AI methods, and potential comprehension challenges
Logical inference: the process of deriving conclusions from given statements (premises) using formal rules of logic, moving from what is known to what can be logically deduced. Several key rules of inference used in classical logic are:
Modus Ponens: Direct inference using conditional statements. Allows users to conclude the consequent Q of an implication P → Q, given that the antecedent P is true.
Modus Tollens: Reasoning using negation of the conclusion. Allows users to conclude the negation of the antecedent ¬P if the consequent Q in an implication P → Q is false.
Syllogism: Connecting multiple premises to draw a final conclusion. (reminder: photoshop later)
In logic, a free variable is a variable within a formula that is not bound by a quantifier, meaning its value is not explicitly defined and can vary.
Imagine that you have system of equations (see below). When solved, you will find that z is a free variable. You can assign any value to z, and then determine corresponding values for x and y.
Meanwhile, a sentence (or closed formula) is a formula that contains no free variables, essentially expressing a complete proposition with a definite truth value that can be determined without assigning values to any variables.
Take an example of illustrating Tom from Tom and Jerry's correlated status as a cat, mammal, and animal:
Mammal(Tom): Since Tom is a cat, and all cats are mammals.
Animal(Tom): Since Tom is a mammal, and all mammals are animals.
A satisfaction relation is a concept in formal logic that determines if a structure satisfies a formula or statement. It connects the syntax of expressions with their semantics.
Example
Training a neural network involves adjusting the weights to minimize the difference between its predictions and the correct answers. Some key training steps are:
Forward Propagation: Input passes through layers, generating an output.
Loss Calculation: Difference between the predicted output and actual value is measured using a loss function.
Backpropagation: Network adjusts weights by computing gradients to reduce errors.
Optimization using Gradient Descent: Network updates weights step-by-step to improve accuracy.
Neural networks classify images by categories over three minimum steps:
Input Layer: the raw image is converted into pixel values (e.g., RGB values).
Hidden Layers: the network extracts features such as edges, fur patterns, and eyes. Each layer learns more complex features (e.g., early layers detect edges, then deeper layers detect shapes like ears).
Output Layer: the network assigns a probability to each class (e.g., 20 % dog, 80% cat → Predicted label: cat).
Keep in mind that neural networks only detect patterns, not reason symbolically like their human creators could.
While a powerhouse of analytical power in its own right, traditional neural networks are not exempt from possessing numerous limitations:
Black-box problem: Neural networks are powerful but lack explainability.
Data dependency: Neural networks require huge amounts of labeled data.
Lack of logical reasoning: Neural networks struggle with rule-based inference.
Error sensitivity: Confident but incorrect predictions can occur within neural networks.
For example, a neural network trained on medical images can predict diseases, but it cannot explain why a particular image suggests cancer. Doctors need an explanation, not just a prediction. Adding logic to neural networks helps them:
Add explainability: Rules and constraints provide transparent reasoning.
Reduce data dependency: Knowledge-based reasoning reduces the need for big data.
Improve consistency: Logical constraints prevent contradictory outputs.
Soft product-sum logic is a type of fuzzy logic that extends the traditional concept of Boolean logic by allowing degrees of truth. Instead of strict binary values (i.e., true or false), soft logic allows for values between 0 and 1, representing the degree to which a proposition is true.
Take the example of a hospital using a soft logic-based AI system to determine the likelihood of a patient having a serious infection. The AI assigns probability scores to different symptoms. (photoshop later)
Logical neural networks (LNNs) are neuro-symbolic systems that integrate neural networks with formal logic, enabling logic inference on propositional and first-order logic. Unlike traditional neural networks, LNNs explicitly incorporate logical constraints to ensure consistent predictions.
A logical neuron in LNNs is assigned to each node of a syntax tree that represents logical operations. This network structure follows logical inference rules. Each logical neuron maintains a lower bound (L) and an upper bound (U) for the probability of its corresponding sub-formula, allowing the model itself to handle uncertainty and partial truth values.
The image below is an example of an LNN workflow. To break it down into digestible pieces:
First rule: (Whiskers ⊗ Tail ⊗ (Laser pointer → Chases)) → Cat = If an entity has Whiskers and Tail, and if Laser pointer is what it chases, then it is a Cat.
⊗: Multiplication operation that represents an AND-like operation where all conditions must be satisfied.
→: Implication that represents logical entailment. If left-hand conditions hold, then right-hand conclusion follows.
Second rule: (Cat ⊕ Dog) → Pet = If an entity is either a Cat or a Dog, then it is classified as a Pet.
⊕: Addition operation that represents an OR-like operation, meaning at least one of the inputs must be true.
LNNs represent truth values as bounds L and U, combinedly called truth bounds, where 0 ≤ L ≤ U ≤ 1. Different bounds represent different logical interpretations, as seen below:
For example, if a neuron has truth bounds L = 0.3 and U = 0.7, while the threshold is α = 0.5, this indicates that the neuron’s truth value is uncertain.
In mathematics and philosophy, Polish logician Jan Łukasiewicz's Łukasiewicz logic is a non-classical, many-valued logic. It extends classical Boolean logic by allowing for degrees of truth beyond simple true or false. Instead of binary values (0 for false and 1 for true), Łukasiewicz logic uses values within the continuous range of [0, 1] — just like soft logic, which Łukasiewicz logic predates much earlier in the 1920s.
In an LNN, Łukasiewicz logic provides a basic activation function that ensures output remains within [0, 1] range, which helps maintain differentiability for logic-based neural networks.
Next, Łukasiewicz logic's logical AND operation ensures truth value is high only when all inputs are high.
Finally, for Łukasiewicz logic, its logical OR operation ensures that the truth value is high if at least one input is high.
Inference and convergence of LNN performs bidirectional message passing to update neuron truth bounds until convergence. The process involves three key steps:
Read inputs from data: Map input data, typically axioms and facts, to initial neuron truth bounds.
Bidirectional message passing until convergence: Repeatedly perform bidirectional message passing until a stable state is achieved.
Upward Pass (Forward Propagation): Compute derived truth bounds from input neurons.
Downward Pass (Backward Propagation): Constrain lower-level neuron bounds based on logical rules.
Inspect target neuron bounds: Determine final neuron truth bounds upon convergence for reasoning and decision-making.