What does 'predicate' mean in the context of computer science?
Computer ScienceComputer Science Problem Overview
Specifically I've seen it used in the context of text filtering. As if "predicate" == "filter criteria".
Is this accurate?
Computer Science Solutions
Solution 1 - Computer Science
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.
Solution 2 - Computer Science
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"
Solution 3 - Computer Science
The word comes from logic.
A predicate is an "is" boolean question about the inputs.
"IsNull" is a predicate question.
Also, wikipedia link about Predicates in Math.
Solution 4 - Computer Science
A predicate is a statement about something that is either true or false.
Solution 5 - Computer Science
Just to simplify things . predicate is a function that return a true or false value based on some condition.
it's used as a "filter criteria" meaning lets consider an array of numbers and a predicate that returns true if number > 0 , false other wise .
function predicate(number){
return number > 0
}
// array of numbers
var numbers = [-2 , -1 , 0 , 1 , 2];
var newNumbers = numbers.filter(predicate);
// newNumbers => [1 , 2] ;
filter is a function that returns a new array based on a predicate ( or a "filter criteria". )
it has filtered the array based on the value of predicate
- true : include value
- false : don't include it
Solution 6 - Computer Science
Proposition:
- either definitely set to true or false
- not dependent on values of the parameters
- e.g.
- "x+2=2x, when x = -2" => true
- "2*2=5" => false
Predicate:
- truth value depends on the parameter's value
- e.g.
- "x+2=2x" => truth value is unknown and is dependent on the value of x
Use quantifiers to transform predicate to proposition:
- ∃x∈Z (x+2=2x) "There exists a x in the set of integers such that x+2=2x"
Solution 7 - Computer Science
Predicate is a function that takes one element as input parameter and return either true or false. Predicates are used in higher order functions, applied to a given function(a.k.a transformer) element-wise to a list of elements and returns a list of results. Transformer is a function applies to each element and will produce one or more new elements.