Predicate Logic Calculator online
Predicate logic · Free · No sign-up
Predicate logic calculator: rules of inference with quantifiers
Type your premises with quantifiers and the conclusion, and get the proof line by line: universal and existential instantiation and generalization, plus the usual rules (modus ponens, modus tollens, syllogisms). And if the argument is not valid, you get the counterexample: a concrete domain where the premises hold and the conclusion doesn’t.
Check whether your argument is valid
Use the buttons if you can’t type the symbolsWhat is predicate logic?
The classic example: “all men are mortal”, “Socrates is a man”, therefore “Socrates is mortal”. Anyone can see the reasoning is sound, but in propositional logic those are three unrelated letters, P, Q and R. And R does not follow from P and Q.
Predicate logic (also called first-order logic or predicate calculus) looks inside the sentences: it separates who we are talking about from what we say about them, and adds quantifiers to say how many elements the formula applies to. These are all the pieces, and there are no others:
The pieces: predicates, terms and quantifiers
| Piece | How it’s written | What it is | Example |
|---|---|---|---|
| Predicate | H(x)R(x,y) | The property or relation: what is said about the element. The number of slots is its arity. | H(x) is “x is a man”R(x,y) is “x knows y” |
| Constant | s, a, socrates | A specific element, someone with a name. | H(s) is “Socrates is a man” |
| Variable | x, y, z | A slot not filled in yet. The quantifier is what fills it. | In ∀x H(x), x is nobody in particular |
| Universal quantifier | ∀x | “For all x”, “every”, “any”. It says the formula holds for every element. | ∀x M(x) is “everyone is mortal” |
| Existential quantifier | ∃x | “There exists an x”, “some”, “at least one”. It doesn’t say which or how many: only that there is one. | ∃x M(x) is “someone is mortal” |
| Connectives | ¬ ∧ ∨ → ↔ | The same ones as in propositional logic: not, and, or, implies, if and only if. They work the same way. | H(x) → M(x) is “if x is a man, x is mortal” |
With those pieces, the Socrates argument is written ∀x (H(x) → M(x)), H(s) ⊢ M(s), and now it can be proved: the universal quantifier lets you bring the first premise down to the case of Socrates, and from there it’s a textbook modus ponens.
How to translate a sentence into a formula
This is where most marks are lost, and it has nothing to do with the rules: it’s just picking the right connective. “All A are B” takes an implication and “some A is B” takes a conjunction. They are not interchangeable.
| In English | Formula | Why that connective |
|---|---|---|
| All A are B | ∀x (A(x) → B(x)) | With implication: “if it is A, then it is B”. Things that aren’t A don’t matter. |
| Some A is B | ∃x (A(x) ∧ B(x)) | With conjunction: there is one that is A and also B. Both things at once. |
| No A is B | ∀x (A(x) → ¬B(x)) | It’s an “all”, but with the consequent negated: every A fails to be B. |
| Some A is not B | ∃x (A(x) ∧ ¬B(x)) | A normal “some” with the second part negated. |
| Not all A are B | ¬∀x (A(x) → B(x)) | Same as the row above: denying an “all” means there is an exception. |
| Only A are B | ∀x (B(x) → A(x)) | The implication reversed: to be B you have to be A. |
The trick to getting it right: if you wrote “all A are B” with a conjunction, ∀x (A(x) ∧ B(x)), you’d be saying that absolutely everything is A and B, which is far more than the sentence says. And if you wrote “some A is B” with an implication, ∃x (A(x) → B(x)), it would be enough for something that is not A to exist, because an implication with a false antecedent is true: you wouldn’t be saying anything.
The four rules of inference for quantified statements
The method is simple: quantifiers get in the way, so you remove them, reason with the familiar rules of propositional logic, and put them back at the end. Those four operations are the rules specific to predicate logic. In each pattern, above the line is what you have and below it (after ∴, “therefore”) what you can deduce:
| Rule | Pattern | What it says |
|---|---|---|
| Universal instantiation (UI) also called universal specification or universal elimination (∀E) | ∀x P(x)∴ P(a) | If a property holds for everyone, it holds for whichever element suits you. It’s the rule you start with almost every time: it brings the general premise down to the specific case you care about. |
| Universal generalization (UG) also called universal introduction (∀I) | P(a)∴ ∀x P(x) | If you have proved the property for an arbitrary element, without using anything specific to it, it holds for all. It closes the exercises whose conclusion starts with ∀, and it’s the one with the most conditions. |
| Existential instantiation (EI) also called existential specification or existential elimination (∃E) | ∃x P(x)∴ P(c) | If some element has the property, you give it a name and keep working with it. The name has to be new: you don’t know who it is, only that there is one. |
| Existential generalization (EG) also called existential introduction (∃I) | P(a)∴ ∃x P(x) | If the property holds for a specific element, then some element has it. It finishes the exercises whose conclusion starts with ∃, and it’s the only one of the four with no conditions. |
Depending on your textbook or lecture notes, these rules go by different names: instantiation, specification or elimination for the first and third, generalization or introduction for the second and fourth. They are exactly the same rules; here we use instantiation and generalization, the most common names in discrete math courses.
The two conditions that fail exams
Instantiating and generalizing look harmless, but without these two restrictions you can “prove” false things. These are the ones to memorize:
1 · The constant from an existential must be new. When you apply EI to ∃x P(x), the name you give it (c) cannot have appeared before. If you reuse one, you’re assuming the element that exists is exactly that one, and nobody told you that.
2 · You can only generalize over an arbitrary element. UG is valid if the constant came from a universal instantiation, that is, if it stands for “any one at all”. Never over the witness of an existential or over a constant from the exercise. Otherwise, from ∃x P(x) you would get P(c) and from there ∀x P(x): you’d go from “there is one” to “all”, which is the classic mistake.
The second condition has a practical consequence: instantiate the existentials first and the universals afterwards. If you do it the other way round, the universal leaves you with one constant and the existential forces you to introduce a different one, and then the rules don’t fit because they are talking about different elements. The calculator does it in that order, and next to each line it shows which constant it used and whether it was arbitrary.
The propositional rules are still there
Once the quantifiers are gone you have ordinary formulas, and from there you reason exactly as in propositional logic: modus ponens, modus tollens, hypothetical syllogism, disjunctive syllogism, simplification, conjunction, addition and resolution. The calculator applies all of them and names them the same way as the rules of inference calculator for propositional logic.
Equivalences with quantifiers
Besides the rules, there are rewrites that don’t deduce anything new: they say the same thing in a different way. The calculator applies them on its own when they’re needed and flags them in the proof. These four are the valid ones:
| Equivalence | Name | Read aloud |
|---|---|---|
¬∀x P(x) ≡ ∃x ¬P(x) | Quantifier negation (De Morgan’s laws for quantifiers) | “Not everyone passed” is the same as “someone didn’t pass”. Negating a ∀ turns it into ∃. |
¬∃x P(x) ≡ ∀x ¬P(x) | Quantifier negation | “Nobody passes” is the same as “everyone fails”. Negating an ∃ turns it into ∀. |
∀x (P(x) ∧ Q(x)) ≡ ∀x P(x) ∧ ∀x Q(x) | Distribution of ∀ over “and” | “Everyone is tall and blond” is the same as “everyone is tall and, also, everyone is blond”. |
∃x (P(x) ∨ Q(x)) ≡ ∃x P(x) ∨ ∃x Q(x) | Distribution of ∃ over “or” | “Someone is tall or blond” is the same as “someone is tall, or else someone is blond”. |
The first two chain together without trouble and are by far the most used. For example, ¬∃x (P(x) ∧ ¬Q(x)) becomes ∀x ¬(P(x) ∧ ¬Q(x)), then ∀x (¬P(x) ∨ Q(x)) by De Morgan, and ∀x (P(x) → Q(x)) by material implication.
And the three that DON’T work
Watch out for these, because they look a lot like the ones above and that’s where almost everyone slips. They are not equivalences: they only hold in one direction, and in the other they are false.
| What you CAN’T do | Why it’s false | What does work |
|---|---|---|
| ∀x (P(x) ∨ Q(x))does not imply∀x P(x) ∨ ∀x Q(x) | Every number is even or odd, and yet it isn’t true that all of them are even, nor that all of them are odd. | The other way round, yes: from ∀x P(x) ∨ ∀x Q(x) you can deduce ∀x (P(x) ∨ Q(x)). |
| ∃x P(x) ∧ ∃x Q(x)does not imply∃x (P(x) ∧ Q(x)) | There is someone tall and there is someone blond, but maybe nobody is tall and blond at the same time. They are two different people. | The other way round, yes: from ∃x (P(x) ∧ Q(x)) you can deduce ∃x P(x) ∧ ∃x Q(x). |
| ∀x ∃y R(x,y)does not imply∃y ∀x R(x,y) | Every number has a smaller one, and yet there is no number smaller than all of them. The y depends on the x. |
The other way round, yes: from ∃y ∀x R(x,y) you can deduce ∀x ∃y R(x,y). |
If you don’t believe one of them, paste it into the calculator above: it gives you the counterexample with a two-element domain and what each predicate holds for, which is the quickest way to see it.
How to solve an exercise step by step
The order is almost always the same, and it works for most exercises:
Step 1 · Translate and separate
Turn the statement into formulas with the translation table above, and decide what is a premise and what is the conclusion. If the exercise is already in formulas, you just need to identify the conclusion.
Step 2 · Remove the negations in front of quantifiers
If a premise starts with ¬∀ or ¬∃, apply quantifier negation before anything else. A premise that starts with a negation can’t be instantiated, and as soon as you rewrite it it becomes a normal ∀ or ∃ you can work with.
Step 3 · Instantiate: first the ∃, then the ∀
Apply EI to each existential, giving each one a new name. Then apply UI to the universals using those same constants, so that the formulas talk about the same element and the rules can fit. If no constant is involved, instantiate with an arbitrary element (a) and remember it’s the only one you’ll be able to generalize over later.
Step 4 · Reason as in propositional logic
With no quantifiers left, chain rules: modus ponens where you have the antecedent, modus tollens where you have the consequent negated, syllogisms to link implications and disjunctions, simplification to split conjunctions. This is the long part, and it’s identical to any propositional logic exercise.
Step 5 · Put the quantifier back
Look at how the conclusion starts. If it is ∃x …, it’s enough to have reached the formula for one specific element and apply EG. If it is ∀x …, you must have reached it for an arbitrary element and apply UG. And if the conclusion is a conjunction, get each part separately and join them.
Step 6 · If it doesn’t work, look for a counterexample
In propositional logic a truth table was enough. Here you have to build an interpretation: a domain with a few elements, deciding for each one whether it satisfies each predicate, so that every premise comes out true and the conclusion false. If you find one, the argument is not valid and no proof exists. The calculator searches for one automatically in domains of up to three elements and shows it to you in full.
Worked example, step by step
A typical exam exercise, with one universal and one existential:
“Every student in the class has read the book. Some student in the class has a scholarship. Prove that someone with a scholarship has read the book.”
- Step 1 — We translate.
WithS(x)“x is a student in the class”,R(x)“x has read the book” andH(x)“x has a scholarship”. Mind the connectives: “all S are R” with an implication, “some S is H” with a conjunction.We need to reach(1)∀x (S(x) → R(x))Premise(2)∃x (S(x) ∧ H(x))Premise∃x (H(x) ∧ R(x)). - Step 2 — We instantiate the existential first.
(2)says there is someone who is a student and has a scholarship. We don’t know who, so we give them a new name,a. And since it’s a conjunction, we split it.(3)S(a) ∧ H(a)Existential instantiation on (2) · we call that elementa(4)S(a)Simplification on (3)(5)H(a)Simplification on (3) - Step 3 — We instantiate the universal with that same constant.
This is the key:(1)holds for anyone, so we bring it down toa, exactly the element we know things about. If we had instantiated it earlier with another letter, it wouldn’t fit anything.(6)S(a) → R(a)Universal instantiation on (1) · witha(7)R(a)Modus ponens from (4) and (6) - Step 4 — We build the conclusion.
We haveH(a)andR(a): we join them and generalize. The conclusion starts with∃, so EG applies with no further conditions.We have reached the conclusion starting only from the premises, so the argument is valid.(8)H(a) ∧ R(a)Conjunction from (5) and (7)
Notice that here we could not have finished with a universal generalization: a is the witness of an existential, not an arbitrary element. ∀x R(x) does not follow from R(a), and the calculator won’t let you do it either.
What if there’s neither a proof nor a counterexample?
It can happen, and it’s worth knowing why. In propositional logic there is always an answer: with a handful of variables you evaluate every case and you’re done. In predicate logic there is no method that always decides whether an argument is valid: the domain can be infinite and there’s nothing to go through. It’s a classic result (the decision problem, Church and Turing), not a shortcoming of this calculator.
So there are three possible answers here, and each one means something different:
- Valid, with the proof in front of you. It’s certain: the proof itself is the evidence.
- Invalid, with the counterexample in front of you. Also certain: that specific model makes the premises true and the conclusion false, and one is enough.
- Inconclusive: it found neither a proof nor a counterexample in small domains. It usually means one of two things: the argument needs reasoning by cases or assuming the antecedent (moves that are not applying a rule from the table), or the counterexample needs a bigger domain than the one explored.
Related calculators
All logic calculators (index)
The page that brings together every tool on this topic.
Rules of Inference Calculator
The propositional version: modus ponens, tollens and syllogisms, without quantifiers.
Resolution Refutation Calculator
Negate the conclusion and search for the contradiction. A complete method.
Truth Table Generator
Check a propositional argument by evaluating every case.
Conjunctive Normal Form (CNF) converter
Rewrite a formula as clauses, the first step of the resolution method.
Frequently asked questions
Is this a proof solver or a proof checker?
A solver. You don’t need to write the proof yourself: you give it the premises and the conclusion, and it works as a predicate logic proof generator that writes the derivation line by line, with the rule used on each line. It isn’t a converter that only rewrites your formula into another form (for that, use the CNF converter). If you already have your own proof, compare it with the one it gives you: the lines where they differ are where to look.
How do I type the quantifiers?
With the ∀ and ∃ buttons, followed by the variable your exercise uses (x, y, z…). You can also type them directly, or write forall x and exists x, or the shortcuts \Ax and \Ex. The dot is optional: ∀x. P(x) and ∀x P(x) are the same. And for grouping, parentheses, square brackets [ ] and braces { } all work.
How far does a quantifier’s scope reach?
Only to the formula right after it. That is, ∀x P(x) → Q(x) reads as (∀x P(x)) → Q(x), not as ∀x (P(x) → Q(x)). If you want it to cover the whole formula, add parentheses. When we detect a quantified variable left outside the parentheses we warn you, because it’s almost always a typo.
Can I use square brackets, as in ∃x[A(x) ∧ C(x)]?
Yes. Square brackets [ ] and braces { } work exactly like parentheses, so you can copy the formula from your exercise as it is. Lecture notes often alternate them just to make it easier to see what closes what when there are several nested levels, but logically they mean nothing different: ∃x[A(x) ∧ C(x)] and ∃x (A(x) ∧ C(x)) are the same formula. The calculator always rewrites it with parentheses so every line of the proof looks the same.
What is the difference between a variable and a constant?
The quantifier decides: in ∀x (H(x) → M(x)), x is a variable because it is quantified. Any term that isn’t quantified is treated as a constant, that is, as a specific element: in H(s), s is Socrates. You don’t need to use upper or lower case in any particular way, although it’s usual to write predicates in upper case (P, Mortal) and terms in lower case (x, a, socrates).
Why can’t I generalize over the constant I got from an existential?
Because that constant doesn’t stand for “any one at all”, but for “the one we know exists”. From ∃x P(x) you get P(c), and if you could go from there to ∀x P(x) you would be proving that if something happens to one, it happens to everyone, which is false. Universal generalization only works on constants that come from instantiating a universal.
Does it support predicates with several arguments and nested quantifiers?
Yes. You can write R(x,y), Greater(x,y) or Between(x,y,z), and nest quantifiers as in ∀x ∃y R(x,y). Functions inside predicates (no P(f(x))) and the equality symbol are not supported.
Why does it sometimes say inconclusive?
Because in predicate logic there is no method that always decides whether an argument is valid: that’s a mathematical result, not a flaw in the tool. When it finds neither a proof nor a counterexample it tells you so plainly, instead of risking a false answer. It usually happens with arguments that need reasoning by cases.