버튼 수집상

[CS] predicate란 본문

TIL - CS

[CS] predicate란

cocokaribou 2023. 6. 26. 17:10

https://en.wikipedia.org/wiki/Functional_predicate

 

Functional predicate - Wikipedia

From Wikipedia, the free encyclopedia In formal logic and related branches of mathematics, a functional predicate, or function symbol, is a logical symbol that may be applied to an object term to produce another object term. Functional predicates are also

en.wikipedia.org

functional predicate, 혹은 function symbol
즉, 논리 연산자

 

 

https://www.baeldung.com/cs/predicates

predicate란 여러 인자를 받아서 boolean을 리턴하는 함수를 말한다.
boolean predicate(set_of_parameters)

 

 

https://stackoverflow.com/questions/3230944/what-does-predicate-mean-in-the-context-of-computer-science

 

What does 'predicate' mean in the context of computer science?

Specifically I've seen it used in the context of text filtering. As if "predicate" == "filter criteria". Is this accurate?

stackoverflow.com

predicate란 문장에서 동사를 포함하면서 주어에 대해 서술하는 부분이다. 예를 들어 Mike is eating 마이크는 먹는 중이다 에서 주어는 마이크, 술어는 먹는 중이다, 이다. 하지만 컴퓨터공학의 관점에서 predicate란 어떤 작업을 수행할지 말지 알기 위해 true / false 조건을 체크하는 것이다.
Person mike;

if (!mike.isEating())
    feedPerson(mike);
Person의 인스턴스 mike의 멤버함수인 isEating()은 predicate이다. 이 함수는 person 인스턴스 (이 경우엔 mike)가 먹는 중인지 여부에 따라 true 혹은 false를 리턴한다.
predicate은 주로 콜백의 형태로 쓰이지만 일반적으로 참거짓을 판별해서 boolean을 리턴하는 함수라면 모두 predicate라고 부를 수 있다.

 

 

함수 명세를 보다가 predicate란 단어가 직관적으로 이해되지 않아서 용례를 찾아봤다.

fun main(){
    val listOfNumbers = listOf(10,3,45,90,1,22,1000)
    
    val filtered = listOfNumbers.filter{ x -> x < 50 }
    print(filtered)
}

예시의 경우, filter 블럭의 람다 함수를 predicate이라고 부를 수 있다.

728x90

'TIL - CS' 카테고리의 다른 글

[CS] mounting이란  (0) 2024.01.30
[CS] 정규표현식 Basic Regex  (1) 2024.01.11
[CS] payload란  (0) 2023.07.13
[CS] heuristic이란  (0) 2023.07.11