Being a hobbyist coder, I'm lacking some fundamental knowledge. For the last couple days I've been reading some stuff and the word "predicate" keeps reappearing. I'd very much appreciate an explanation on the subject.
-
4Here's my article on what *isn't* a predicate: http://blogs.msdn.com/ericlippert/archive/2008/08/19/tasty-beverages.aspx Enjoy! – Eric Lippert Sep 02 '09 at 19:28
-
Predicates are used as such, much more in the Relational Database arena, than in programming languages. – PerformanceDBA Apr 24 '15 at 17:09
-
1The example used in the definition at https://dictionary.cambridge.org/us/dictionary/english/predicated is "The sales forecast is predicated on the assumption that the economy will grow by four percent." In terms of programming, this may be represented in pseudo-code as `if (economy grows by 4%) then "sales forecast is valid" else "sales forecast is not valid"`. The "predicate" here is the test "economy grows by 4%", which would likely be implemented as a function which returns either true or false. Simplified, a predicate is the condition in an "if" statement (sometimes with side effects). – Casey May 13 '19 at 03:33
12 Answers
The definition of a predicate, which can be found online in various sources such as here, is:
A logical expression which evaluates to TRUE or FALSE, normally to direct the execution path in code.
Referencing: Software Testing. By Mathew Hayden (dead link / unknown origin)

- 15,225
- 5
- 36
- 45
-
3This answer is only partially true. A predicate is more specific that that. This definition of it is like saying the definition of "bibliophile" is someone who reads books. When the term bibliophile provides much more detail than that. – Ben Lesh Sep 02 '09 at 19:31
-
3
-
-
@PerformanceDBA At your karma level, you're free to edit my answer from six years ago. – aehlke May 02 '15 at 21:02
-
3I was going to make an edit, but not entirely sure how to phrase it. The google book reference in the answer no longer works. – Tiffany Feb 01 '18 at 13:56
-
@aehlke - The links for the book don't work. Moreover, google search does not show me any useful links matching "software testing by matthew hayden". There is one book by Ron Patton though. Is that the one you meant instead? Wayback machine does not have a copy of book either. Could you please fix the links ? – MasterJoe Feb 27 '20 at 23:04
-
@MasterJoe2 sorry, but I don't remember what article I was referencing 11 years ago. – aehlke Feb 29 '20 at 22:20
In programming, a predicate is a function which returns either true or false for some input.
Most commonly (I guess) used in the context of higher-order function. E.g. filter
is a function in many languages which takes a predicate and a list as arguments, and returns the items in the list for which the predicate is true.
Example in javascript:
function lessThanTen(x) { return x < 10; }
[1,7,15,22].filter(lessThanTen) --> [1,7]
The function lessThanTen
is the predicate here, which is applied to each item in the list.

- 41,662
- 13
- 71
- 86
-
-
3yeah, but since the predicate may rely on variables it it probably more natural to think of it as a function. – JacquesB Aug 27 '09 at 22:18
-
A proposition is a (true or false) statement. A predicate is a mapping/function from a tuple to a proposition or to the truth of a proposition. – philipxy Jan 11 '20 at 07:20
A predicate isn't simply an expression that evaluates to true or false, there's more to it. The term "predicate" is used to refer to an expression that determines whether something is true or false. Or in other words, it makes an assertion and returns true or false based on that.
For example (in C#):
/*this is a predicate, as it's sole purpose is to make some
assertion about something.*/
bool IsNameBob(string name)
{
return name == "Bob";
}
/*Whereas this is not a predicate, as it's performing an action
then evaluating to true if it succeeds. */
bool DoSomethingCool() {
try
{
ImDoingSomethingCool();
}
catch
{
return false;
}
return true;
}
I understand what I've put here is purely a difference in semantics, but that's what this question was about right? Semantics?

- 107,825
- 47
- 247
- 232
-
+1... All of this is easy in C++. A predicate is a function whose parameters are all either by value or `const` references, and whose return type is a `bool`. – isekaijin Sep 07 '09 at 15:24
-
1My answer already covered this nuance by using the word "expression." Also, a method definition is not a predicate - it's not even an expression. Your answer is rather confused and misleading. – aehlke Jan 07 '10 at 09:16
In non programing terms; a question. Typically a general question with place holders (like it and them) that can be asked of many things.
- Is it red?
- Is it a dog?
- Is it owned by them?

- 75,627
- 68
- 187
- 294
-
2
-
I’m not very firm in grammar but still, my impression until now was that a predicate is the *answer* to the above questions, not the question itself (so “This **is red**.”, “This **is a dog**.”, “This **is owned by them**.”) Can you clarify? Is both correct? – Konrad Rudolph Aug 30 '09 at 07:48
-
1I know from my logic class that in formal logic, predicates are the function analog. So in that context it is the question, not the answer. I'm not so sure in normal English. – BCS Aug 31 '09 at 04:28
A basic evaluation that results in a boolean1 value. It often refers to a function or object that represents an evaluation of this type.
1: boolean used loosely, not necessarily referring to variables declared bool
or boolean
.

- 31,137
- 42
- 147
- 238
-
I used boolean in the sense of boolean logic. http://en.wikipedia.org/wiki/Boolean_logic. Boolean logic is not language dependent. – C. Ross Aug 28 '09 at 12:28
First let's take a look at a regular dictionary and see what it says about what a predicate is:
Oxford American Dictionary(1980):
n. a part of a sentence that says something about the grammatical subject, as "is short" in "life is short"
Here is another sentence: "John is tall." the predicate is "is tall". As you can see it modifies or describes the subject, another term that is similar to predicate
is adjective
. In essence it's a modifier.
IBM's technology glossary provides several definitions but, the one fits best is this one:
An expression used as part of a filter, consisting of a data item, an operator, and a value
Here is an example using SQL:
SELECT name
FROM tableA
WHERE name = "john";
The predicate in this code would be name = "john"
. It has all the components of the IBM definition and also fits with the regular definition of predicate. The subject being name
and the predicate being name = "john"
.

- 10,126
- 19
- 78
- 130
A function that returns a boolean. Predicates are used a lot in functional and OO programming to select subsets of values from data structures, especially lists and other collections. You'll find plenty of examples in the standard libraries for Haskell and Smalltalk.

- 198,648
- 61
- 360
- 533
It is probably useful to consider the grammatical meaning of the concept to extrapolate the programming concept.
In traditional grammar, a predicate is one of the two main parts of a sentence (the other being the subject, which the predicate modifies). For the simple sentence "John [is yellow]," John acts as the subject, and is yellow acts as the predicate, a subsequent description of the subject headed with a verb.
In current linguistic semantics, a predicate is an expression that can be true of something. Thus, the expressions "is yellow" or "is like broccoli" are true of those things that are yellow or like broccoli, respectively. This notion is closely related to the notion of a predicate in formal logic, which includes more expressions than the former one, like, for example, nouns and some kinds of adjectives.
In logic terms:
An operator in logic which returns either true or false.
from MathWorld

- 5,802
- 9
- 42
- 60
I don't know if I'm speaking in the correct context, but there is a Predicate
class in C# which is essentially a delegate which, given an item, determines whether or not the object meets a set of criteria.
For example, the following method, which is of type Predicate<int>
, could be used to select all integers greater than 5:
public bool MyPredicate(int x)
{
return x > 5;
}
I'm not sure how this translates into the more general case, but it's a start. For more info, click here.

- 4,658
- 2
- 29
- 38
-
I don't know whether it's possible to create a function that alters an object (instance of a `ref` type) and returns a bool, and assign it to a `Predicate` delegate. If it's possible, then the `Predicate` delegate doesn't make much sense. – isekaijin Sep 07 '09 at 15:26
From C++ Primer 5th (§10.3.1):
A predicate is an expression that can be called and that returns a value that can be used as a condition.
Also from chapter Defined Terms section:
predicate : Function that returns a type that can be converted to
bool
.

- 7,007
- 2
- 49
- 79
The best S.O. answer around predicates, that I have found, is on a duplicate question.
To summarize, in natural languages a predicate is the part of the sentence that describes a subject.
Jane is tall
Jane is the subject and is tall
is the predicate.
In computer science we are not interested in asserting a fact about a subject but rather testing if something is true or false.
jane.isTall();
Here jane is some object with a predicate method that will return either true or false.

- 8,666
- 9
- 48
- 69