What does 'predicate' mean in the context of computer science? [duplicate]
Specifically I've seen it used in the context of text filtering. As if "predicate" == "filter criteria".
Is this accurate?
A predicate ('PRED-i-cat') is the part of a sentence that contains the verb and tells you something about the subject.
For instance, in the sentence
"Mike is eating", we have the subject, 'Mike', and the predicate, 'is eating'.
In the context of computer science, we aren't interested in stating a fact, but rather, in testing a true/false condition for the purpose of deciding whether to do something.
Person mike;
if (!mike.isEating())
feedPerson(mike);
The isEating()
member of mike
(an instance of Person
) is a predicate. It returns true
or false
for the assertion that the person
(mike
in this case) is eating. The predicate is being used to decide whether or not to feed the person.
Predicates are often found in the form of callbacks, but in general we can use the term for any function that returns a bool based on evaluation of the truth of an assertion.
For sorting, might want have the member function
bool Fruit::ComesAfter(Fruit x) ...
as our predicate. If x
comes after us, our sorting algorithm will swap the two fruits.
There's also the term predicate (predi-KATE). In English we use it like this:
"Graduation is predicated upon attainment of passing grades."
It means one thing depends on another.
In computer science, we use this form of the word to describe conditional execution.
For instance, in CUDA programming, there are assembly instructions whose execution we can predicate (KATE) on a prior result. That is, you set a predicate (CAT) flag that, if true, causes the instruction to be executed, and if false, causes the instruction to be treated as a NOP. Thus the execution of the instruction is predicated upon the indicated predicate flag.
The uses are very similar.
Hope that helps.
It is a term most commonly used in the field of Mathematical Logic.
From wikipedia
In mathematics, a predicate is either a relation or the boolean-valued function that amounts to the characteristic function or the indicator function of such a relation.
A function P: X→ {true, false} is called a predicate on X. When P is a predicate on X, we sometimes say P is a property of X.
.
"predicate" == "filter criteria"