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

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

[ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ] ์—ํƒ€ ๋ณ€ํ™˜ eta conversion

์ถœ์ฒ˜

ChatGPT

https://sookocheff.com/post/fp/eta-conversion/

 

Eta Reduction

The purpose of eta reduction (also written \(\eta\)-reduction) is to drop an abstraction over a function to simplify it. This is possible when there is nothing more that a function can do to its argument. For example, imagine that we have a simple function

sookocheff.com

https://library.fiveable.me/key-terms/programming-languages-iii/eta-conversion

 

Eta conversion - (Programming Techniques III) - Vocab, Definition, Explanations | Fiveable

Eta conversion is a process in lambda calculus where a function is considered equivalent to another function if they behave identically when applied to an argument. This concept reflects the principle that a function that takes an argument and returns anot

library.fiveable.me

 


์—ํƒ€ ๋ณ€ํ™˜ Eta Conversion

ํ•จ์ˆ˜์˜ ํ˜•ํƒœ๋ฅผ ์•ฝ๊ฐ„ ๋ณ€ํ˜•ํ•ด๋„ ๊ทธ ํ•จ์ˆ˜์˜ ์˜๋ฏธ๊ฐ€ ๋ณ€ํ•˜์ง€ ์•Š์Œ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐœ๋….

eta๋Š” ๊ทธ๋ฆฌ์Šค ์•ŒํŒŒ๋ฒณ η์ด๋‹ค.

์—ํƒ€ ๋ณ€ํ™˜์€ ํ™•์žฅ๊ณผ ์ถ•์•ฝ ๋‘ ๊ฐ€์ง€๋กœ ๋‚˜๋‰œ๋‹ค.

1. ์—ํƒ€ ํ™•์žฅ  eta expansion

์ฃผ์–ด์ง„ ํ•จ์ˆ˜ f์— ๋Œ€ํ•ด ํ•จ์ˆ˜์˜ ์ •์˜๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ํ™•์žฅํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. 

2. ์—ํƒ€ ์ถ•์•ฝ eta reduction

์—ํƒ€ ํ™•์žฅ์˜ ๋ฐ˜๋Œ€ ๊ฐœ๋…์œผ๋กœ, ํ•จ์ˆ˜ ํ‘œํ˜„์—์„œ ๋ถˆํ•„์š”ํ•œ ์ธ์ž ์ ์šฉ์„ ์ œ๊ฑฐํ•˜๋Š” ๋ณ€ํ™˜์ด๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, ๊ฐ„๋‹จํ•œ ํ•จ์ˆ˜ f x = g x ๋ฅผ ์ƒ๊ฐํ•ด๋ณด์ž. f์™€ g๋Š” ๊ฐ™์€ ์ธ์ˆ˜ x๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , ์ด ํ•จ์ˆ˜์˜ ๊ฒฐ๊ณผ ๊ฐ’์€ ๊ฐ™๋‹ค. f์™€  g๊ฐ€ ๊ฐ™์€ ์ธ์ˆ˜๋ฅผ ๊ฐ€์ง€๊ณ  ๊ฐ™์€ ๊ฐ’์„ ์ƒ์„ฑํ•˜๊ธฐ ๋Œ€๋ฌธ์—, ์šฐ๋ฆฌ๋Š” ๋ฐฉ์ •์‹์„ f = g ๋ผ๊ณ  ๋‹จ์ˆœํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค. 

 

์—ํƒ€ ๋ณ€ํ™˜์˜ ํ•ต์‹ฌ

์—ํƒ€ ๋ณ€ํ™˜์€ ๋‘ ํ•จ์ˆ˜๊ฐ€ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ๋งŒ๋“ค์–ด ๋‚ด๋Š” ํ•œ, ๋™์ผํ•œ ํ•จ์ˆ˜๋กœ ์ทจ๊ธ‰๋  ์ˆ˜ ์žˆ์Œ์„ ๋ณด์žฅํ•œ๋‹ค. 

 

์ด ๋ณ€ํ™˜์€ ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ์ค‘์š”ํ•œ ์ด๋ก ์  ๊ธฐ๋ฐ˜์ด ๋œ๋‹ค. ํŠนํžˆ ํ•จ์ˆ˜์˜ ์ •์˜์™€ ์‚ฌ์šฉ์„ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋‹ค๋ฃจ๊ธฐ ์œ„ํ•œ ์ตœ์ ํ™” ๋ฐ ํ•จ์ˆ˜ ํ•ฉ์„ฑ์—์„œ ์ž์ฃผ ์‚ฌ์šฉ๋œ๋‹ค.

 

์˜ˆ์‹œ

val f: (Int) -> Int = { x -> x + 1 }

// ์—ํƒ€ ํ™•์žฅ: f๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ํ™•์žฅ
val g: (Int) -> Int = { x -> f(x) }

// ์—ํƒ€ ์ถ•์•ฝ: g๋Š” ๊ฒฐ๊ตญ f์™€ ๋™์ผํ•จ
val h: (Int) -> Int = f