๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋นˆ ๊ตฌ๋ฉ ์ฑ„์šฐ๊ธฐ

[Programming] ๋ฉฑ๋“ฑ(ๅ†ช็ญ‰, idempotent)

ko.wikipedia.org/wiki/%EB%A9%B1%EB%93%B1%EB%B2%95%EC%B9%99

 

๋ฉฑ๋“ฑ๋ฒ•์น™ - ์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „

์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „. ๋ฉฑ๋“ฑ๋ฒ•์น™(ๅ†ช็ญ‰ๆณ•ๅ‰‡) ๋˜๋Š” ๋ฉฑ๋“ฑ์„ฑ(ๅ†ช็ญ‰ๆ€ง, ์˜์–ด: idempotent)์€ ์ˆ˜ํ•™์ด๋‚˜ ์ „์‚ฐํ•™์—์„œ ์—ฐ์‚ฐ์˜ ํ•œ ์„ฑ์งˆ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฒƒ์œผ๋กœ, ์—ฐ์‚ฐ์„ ์—ฌ๋Ÿฌ ๋ฒˆ ์ ์šฉํ•˜๋”๋ผ๋„ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ฌ๋ผ

ko.wikipedia.org

๋ฉฑ๋“ฑ๋ฒ•์น™, ๋ฉฑ๋“ฑ์„ฑ

์—ฐ์‚ฐ์„ ์—ฌ๋Ÿฌ๋ฒˆ ์ ์šฉํ•ด๋„ ๊ฒฐ๊ณผ๋Š” ๊ฐ™์€ ์„ฑ์งˆ

 

๋ฉฑ๋“ฑ์„ฑ์ด ์žˆ๋Š” ํ•จ์ˆ˜๋Š” ๋ฉฑ๋“ฑ ํ•จ์ˆ˜(idempotent function)๋ผ๊ณ  ๋ถ€๋ฆ„

 

๋‹จํ•ญ์—ฐ์‚ฐ

๋‹จํ•ญ์—ฐ์‚ฐ f, ์–ด๋–ค ์ง‘ํ•ฉ S์˜ ๋ชจ๋“  ์›์†Œ๋Š” x

f(f(x)) = f(x)

 

์ดํ•ญ์—ฐ์‚ฐ

์ดํ•ญ์—ฐ์‚ฐ โ˜…, ์–ด๋–ค ์ง‘ํ•ฉ S์˜ ๋ชจ๋“  ์›์†Œ x

xโ˜…x = x

 


ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ๋ฉฑ๋“ฑ์„ฑ

ํ•จ์ˆ˜๋ฅผ ์—ฌ๋Ÿฌ๋ฒˆ ํ˜ธ์ถœํ•ด๋„ ํ•œ ๋ฒˆ๋งŒ ํ˜ธ์ถœํ•œ ๊ฒƒ๊ณผ ๋™์ผํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋ฐ˜ํ™˜๋œ๋‹ค.

 

mortoray.com/2014/09/05/what-is-an-idempotent-function/

 

What is an idempotent function?

Idempotence is an essential tool in programming. It has many uses, from improving fault tolerance, clarifying code, to writing declarative deployment scripts. It’s important to understand wha…

mortoray.com

์˜ˆ์‹œ

import kotlin.math.floor

fun main() {
    val a = 10.3

    println(floor(a)) // 10.0
    println(floor(a)) // 10.0
    
}

 

import kotlin.math.floor

fun main() {
    val a = 10.3

    println(floor(a)) // 10.0
    println(floor(floor(a))) // 10.0
    
}