최근 수정 시각 : 2026-11-24 14:05:26

Lean


[[프로그래밍 언어|'''프로그래밍 언어
{{{#!wiki style="font-family: Times New Roman, serif; display: inline;"
]]
{{{#!wiki style="min-height: calc(1.5em + 5px); margin: 0 -10px -5px"
{{{#!wiki style="display: inline-table; min-width: 40%; min-height: calc(1.5em + 5px)"
{{{#!folding [ 목록 ]
{{{#!wiki style="margin: -5px -1px"
<colbgcolor=royalblue><colcolor=#fff> ※ 나무위키에 등재된 프로그래밍 언어 목록
AActionScript · AdaT · AgdaTP · ALGOLT · ApexT · APL · awk · AssemblyT
BBASIC
C파일:C언어 로고.svg CT · 파일:C C#T · 파일:C++ 로고.svg C++T · CarbonT · 파일:Clojure 로고.svg ClojureS · COBOLT · CoffeeScript · Common LispS · CrystalT
D파일:D(프로그래밍 언어) 로고.svg DT · 파일:Dart 심볼.svg DartT
EElixir · 파일:Elm 로고.svg elmT · 파일:Erlang 로고.svg Erlang
F파일:F F#T · Factor · 파일:fennel-logo.svg FennelS · 파일:forth.png Forth · FortranT
GGNU Octave · 파일:Go 로고.svg GoT · 파일:Groovy 로고.svg GroovyT
H파일:Haskell 로고 심볼.svg HaskellT · HolyCT · HaxeT
J파일:Java 로고.svg JavaT · 파일:JavaScript 로고.svg JavaScript · 파일:julia-dots.svg Julia
K파일:Kotlin 심볼.svg KotlinT
LLeanTP · 파일:LISP_logo.svg LISPS · 파일:Lua 로고.svg Lua
MMATLAB · MaxV · MojoT · Moonlight
N파일:Nim 왕관 로고.svg NimT · 파일:Nix 로고.svg Nix
OOberonT · Objective-CT · 파일:ocaml.svg OCamlT
PPascalT · 파일:Perl 로고.svg Perl · 파일:PHP 로고.svg PHP · Processing · Prolog · PureScriptT · 파일:Python 심볼.svg Python
QQ#T · QML
R파일:R 로고.svg R · 파일:racket-logo.svg RacketS · Raku · ReasonMLT · 파일:Rocq 로고.svg RocqTP · 파일:Ruby 로고.svg Ruby · 파일:Rust 로고.svg파일:Rust 로고 화이트.svg RustT
SSAS · 파일:Scala 심볼.svg ScalaT · SchemeS · 파일:스크래치(교육 플랫폼) 로고.svg ScratchV · sed · Shell Script · Smalltalk · 파일:Swift 심볼 배경.svg SwiftT
T파일:Typescript_logo_2020.svg TypeScriptT
UUdonV · 파일:uiua-logo.png Uiua
VVisual Basic · Visual Basic .NET · Visual Basic for Applications · vvvvV
XXSharp
ZZenScript · 파일:Zig 로고마크.svg ZigT
ㄴ누리
ㅅ/ㅆ숨V · 씨앗
ㅇ약속 · 파일:엔트리 아이콘.svg 엔트리V
ㅊ창조
T: 정적 타입 프로그래밍 언어 · P: 증명 보조 언어 · S: LISP 방언 및 S-표현식 기반 언어 · V: 시각적 프로그래밍 언어 }}}}}}}}}{{{#!wiki style="display: inline-table; min-width: 40%; min-height: calc(1.5em + 5px)"
{{{#!folding [ 순위 ]
{{{#!wiki style="margin: -5px -1px -10px"
{{{#!wiki style="min-height: calc(1.5em + 5px); margin: 0 -10px -5px"
{{{#!wiki style="display: inline-table; min-width: 25%; min-height: calc(1.5em + 5px)"
{{{#!folding [ IEEE Spectrum 2025 ]
{{{#!wiki style="margin: -5px -1px"
<tablewidth=100%><tablebgcolor=transparent><colbgcolor=#11a500><colcolor=#fff> 스펙트럼 부문 상위 10개 프로그래밍 언어 <colbgcolor=#ff1100><colcolor=#fff> 직업 부문 상위 10개 프로그래밍 언어
1 Python 1 Python
2 Java 2 SQL
3 C++ 3 Java
4 SQL 4 JavaScript
5 C# 5 TypeScript
6 JavaScript 6 C#
7 TypeScript 7 C++
8 C 8 HTML
9 Shell 9 Go
10 Go 10 Shell }}}}}}}}}{{{#!wiki style="display: inline-table; min-width: 25%; min-height: calc(1.5em + 5px)"
{{{#!folding [ Stack Overflow 2025 ]
{{{#!wiki style="margin: -5px -1px"
<colbgcolor=#ffa500><colcolor=#fff> 2025년 Stackoverflow 설문조사 상위 25개 프로그래밍 언어
1 JavaScript <colbgcolor=#ffa500><colcolor=#fff> 14 Rust
2 HTML & CSS 15 Kotlin
3 SQL 16 Lua
4 Python 17 어셈블리어
5 Bash/Shell 18 Ruby
6 TypeScript 19 Dart
7 Java 20 Swift
8 C# 21 R
9 C++ 22 Groovy
10 PowerShell 23 Visual Basic
11 C 24 VBA
12 PHP 25 MATLAB
13 Go }}}}}}}}}{{{#!wiki style="display: inline-table; min-width: 25%; min-height: calc(1.5em + 5px)"
{{{#!folding [ TIOBE 2025 ]
{{{#!wiki style="margin: -5px -1px"
<colbgcolor=#2777c2><colcolor=#fff> 2025년 10월 TIOBE 검색어 점유율 상위 20개 프로그래밍 언어
1 Python <colbgcolor=#2777c2><colcolor=#fff> 11 Fortran
2 C 12 Perl
3 C++ 13 R
4 Java 14 PHP
5 C# 15 Assembly language
6 JavaScript 16 Rust
7 Visual Basic 17 MATLAB
8 Go 18 Scratch
9 Delphi / Object Pascal 19 Ada
10 SQL 20 Kotlin }}}}}}}}}{{{#!wiki style="display: inline-table; min-width: 25%; min-height: calc(1.5em + 5px)"
{{{#!folding [ PYPL 2025 ]
{{{#!wiki style="margin: -5px -1px -10px"
<colbgcolor=green><colcolor=#fff> 2025년 11월 PYPL 검색어 점유율 상위 20개 프로그래밍 언어
1 Python <colbgcolor=green><colcolor=#fff> 11 Ada
2 Java 12 TypeScript
3 C++ 13 MATLAB
4 Objective-C 14 Kotlin
5 R 15 PowerShell
6 JavaScript 16 Go
7 C# 17 Dart
8 Swift 18 Ruby
9 PHP 19 Lua
10 Rust 20 VBA }}}}}}}}}}}} }}}}}}}}}}}}
실행 방식 · 분류 · 언어 목록(분류:프로그래밍 언어 문법) · 언어별 예제 · 틀:프로그래밍 언어 문법 · 틀:난해한 프로그래밍 언어
틀:난해한 프로그래밍 언어어와의 병합 토론이 진행 중입니다.

[[Microsoft|
파일:Microsoft 아이콘.svg
Microsoft
마이크로소프트
]]
{{{#!wiki style="margin: 0 -10px -5px; min-height:calc(1lh + 5px)"
{{{#!folding [ 펼치기ㆍ접기 ]
{{{#!wiki style="margin: -5px -1px -11px"
<colbgcolor=#393939,#737373><colcolor=#fff>제품군
하드​웨어Surface · XBOX · HoloLens · PixelSense · Zune · Pluton · IVAS · Azure Cobalt · Azure MAIA
소프트​웨어Windows(주요 내장 프로그램) · Office · Edge · Media Player · Hyper-V · Defender · Visual Studio Code · Visual Studio · Windows Terminal · Microsoft Store · Xbox App · PowerToys · Internet Explorer · MS-DOS · Windows Movie Maker · Autoruns · Clipchamp · Family Safety · Windows Essentials
서비스Microsoft Azure · OneDrive · Microsoft Copilot · Bing · LinkedIn · Microsoft Docs · Skype · MSN · 정품인증 · Xbox Game Pass · Xbox Cloud Gaming · Xbox network · SwiftKey
관련 기술ASF · ASP · Blazor · COM · DCOM · Debug Adapter Protocol · DirectX · 파일 시스템(FAT · NTFS · ReFS) · 언어 서버 프로토콜 · MFC · .NET(.NET Core · .NET Standard · C# · F# · Visual Basic .NET · Q#) · 라이브러리(Windows Forms · WPF · UWP · Xamarin · .NET MAUI · ASP.NET · ML.NET · XNA) · OLE · Silverlight · Visual Basic · Visual Basic for Applications · WASAPI · Windows 커널 · Windows 디자인 · Windows API · Windows Runtime(UWP · WinUI) · WMA · WMV · 하복 엔진 · SAMI · PowerShell · Windows Modern Standby · Nearby Sharing
산하 계열사 및 사업부GitHub · .NET Foundation · Xbox · LinkedIn
관련 인물빌 게이츠(은퇴) · 폴 앨런(은퇴) · 스티브 발머(퇴사) · 게이브 뉴웰(퇴사) · 마이크 이바라(퇴사) · 사티아 나델라 · 필 스펜서(은퇴)[1] · 아샤 사르마[2] · 로드 퍼거슨(퇴사)
기타제니맥스 미디어 인수 · 액티비전 블리자드 인수 · 시작 메뉴 · 빌 게이츠의 굴욕 · Microsoft Campus
관련 틀365 제품군 · 하드웨어 제품군 · Surface 제품군 · Windows 제품군
[각주 펼치기ㆍ접기]

[1] Microsoft Gaming의 초대 CEO[2] XBOX 게이밍 부서의 2대 CEO
}}}}}}}}} ||
1. 개요2. 재귀 처리 관련3. 기타4. 외부 링크

1. 개요

def main := IO.println "Hello, World!"

Lean은 마이크로소프트 리서치에서 개발한 프로그래밍 언어이자 증명보조기이다.

mathlib 등 수학 이론 및 증명들을 형식화하는 데 사용되는 것이 대표적이며, lean4 이후로는 일반적인 프로그래밍 용도로도 사용할 수 있다. 처음 Lean 프로젝트가 시작된 곳이 마이크로소프트 리서치이지만,[1] 2023년부터는 비영리단체인 Lean FRO[2]가 개발을 담당하고 있다.

2. 재귀 처리 관련

기본적으로 lean에서 재귀 처리가 까다로운 이유는 일반 프로그래밍 언어와 달리 consistency 때문에 기본적으로 모든 재귀함수가 반드시 정지(terminate)한다는 것을 증명해야 하기 때문인데, 정지 문제로 인해 실제로는 유한 시간 내에 정지하는 구현이더라도 lean이 이걸 항상 자동으로 추론하는 것은 수학적으로 불가능하기에 다소 귀찮은 면이 있다.

terminate하지 않는 경우부터 생각해 보자. 계산 이론 시간에 배웠던 걸 떠올리면 non-halting term 예시 중 하나로 [math(\Omega = \omega \omega)] combinator가 떠오를 것이다. 물론 λ x => x x 같은 람다 표현식은 ill-typed이니 type checker 수준에서 걸러질 거고, inductive type을 사용해 보자.
inductive D where
  | mk : (D → D) → D
이 경우 다음과 같이 커널 수준에서 컴파일에 실패한다.
(kernel) arg #1 of 'D.mk' has a non positive occurrence of the datatypes being declared
이를 strict positivity check이라고 하는데 여기선 쉽게 말해 constructor argument의 화살표(D → D) 왼쪽 위치에 정의중인 타입을 놓았기 때문이다.

좀더 현실적인, terminate하지 않는 예시를 보자.
def loop (n : Nat) : Nat := loop n
다음과 같이 컴파일에 실패한다.
fail to show termination for
  loop
with errors
failed to infer structural recursion:
Not considering parameter n of loop:
  it is unchanged in the recursive calls
no parameters suitable for structural recursion

well-founded recursion cannot be used, `loop` does not take any (non-fixed) arguments

위 에러 메세지에 structural recursion과 well-founded recursion이라는 말이 나오는데, 기본적으로 structural recursion은 parameter의 subterm에 대한 재귀로 syntactic한 수준에서 따질 수 있는 패턴을 말하며, well-founded recursion은 semantic한 경우를 말한다. 잘 모르겠다면 집합론에 나오는 그 well-foundedness를 생각하면 편하며, 여전히 잘 이해가 안 된다면 무한강하법을 떠올려도 도움이 될 수 있다. 에러 메세지에도 구분해서 나오고 해당 개념을 잘 구분하지 않으면 간혹 recursion 구현 시 문제를 볼 때가 있다. 가령 함수형 프로그래밍에서 자주 나오는 zip 구현을 생각해 보자. List가 inductive type이기 때문에 naive하게 다음과 같은 구현을 생각해볼 수 있다.
def zip (l : List α × List β) :=
  match (l.1, l.2) with
  | (a :: as, b :: bs) => (a, b) :: zip (as, bs)
  | _ => []
잘 돌아갈 것 같지만 실제로는 다음과 같이 컴파일에 실패한다.
fail to show termination for
  zip
with errors
failed to infer structural recursion:
Not considering parameter α of zip:
  it is unchanged in the recursive calls
Not considering parameter β of zip:
  it is unchanged in the recursive calls
Cannot use parameter l:
  the type List α × List β does not have a `.brecOn` recursor


failed to prove termination, possible solutions:
  - Use `have`-expressions to prove the remaining goals
  - Use `termination_by` to specify a different well-founded relation
  - Use `decreasing_by` to specify your own tactic for discharging this kind of goal
α : Type u_1
β : Type u_2
l : List α × List β
as : List α
bs : List β
⊢ 1 + sizeOf as + sizeOf bs < sizeOf l

해당 오류가 복잡해 보이지만 윗 부분의 the type List α × List β does not have a `.brecOn` recursor가 핵심인데, Prod가 recursive type이 아니라는 뜻이고, 때문에 structural recursion이 될 수 없다는 소리다. 때문에 well-founded recursion으로 추론했다가 termination의 증명에도 실패(failed to prove termination)했다는 소리가 아래 메세지다. 위 예시에서는 기본적으로 discriminant가 변수가 아니라서 그런데, 아래와 같이 direct parameter를 그대로 쓰도록 바꾸면 parameter와 pattern의 관계를 lean이 자동으로 추론할 수 있기에 well-founded recursion의 증명이 성공해서 컴파일이 성공한다. 참고로 편의상 parameter name까지 생략했으나 생략 문법을 쓰지 않아도 결과는 똑같다.
def zip : List α × List β → List (α × β)
  | (a :: as, b :: bs) => (a, b) :: zip (as, bs)
  | _ => []

위 방법 외에도 상황에 따라 적절한 경우, simultaneous match를 쓰면 처음부터 structural recursion을 만들 수 있다.
def zip : List α → List β → List (α × β)
  | a :: as, b :: bs => (a, b) :: zip as bs
  | _, _ => []

물론 유한 시간 내에 정지(terminate)하는 재귀함수임을 손으로 증명해야 하는 케이스도 많다. 다소 억지스러운 예시지만 다음을 생각해 보자. 물론 패턴 자체는 재귀 렉서(lexer) 구현 등 현실적인 경우에서 자주 볼 수 있는 패턴이다.
def dropRec (input : String.Slice) :=
  if input.isEmpty then 0
  else 1 + dropRec (input.drop 1)
이 경우 다음과 같이 컴파일에 실패한다.
fail to show termination for
  dropRec
with errors
failed to infer structural recursion:
Cannot use parameter input:
  the type String.Slice does not have a `.brecOn` recursor


failed to prove termination, possible solutions:
  - Use `have`-expressions to prove the remaining goals
  - Use `termination_by` to specify a different well-founded relation
  - Use `decreasing_by` to specify your own tactic for discharging this kind of goal
input : String.Slice
h✝ : ¬input.isEmpty = true
⊢ sizeOf (input.drop 1) < sizeOf input
이는 기본적으로 기본 measure가 메세지와 같이 sizeOf이기 때문이다. 물론 measure를 길이로 바꿔도 그대로인데, String.Slice.drop이 slice 길이에 어떤 영향을 주는지 lean이 알 도리가 없기 때문. 이 경우 lean 입장에서는 drop이 문자열 길이를 매번 감소시킨다는 증명이 없으면 dropRec이 영원히 정지하지 않을 가능성이 있기 때문이다. 이제 밑에 나오는 조건을 보이는 보조정리를 하나 증명해 보자.
theorem String.Slice.length_drop_one_lt {s : String.Slice} (h : ¬s.isEmpty) :
    (s.drop 1).copy.toList.length < s.copy.toList.length := by
  cases h' : s.copy.toList <;> simp_all [String.Slice.toList_copy_drop, String.toList_eq_nil_iff]
simp_all 딸깍기본적으로 이미 빌트인인 String.Slice.toList_copy_drop 보조정리에 기대는 증명이며, cases 부분은 []인 경우 가정 h : ¬s.isEmpty에 모순되니 toList가 c :: cs 꼴이라는 간단한 disjunctive syllogism이다.

이제 필요한 증명이 있으니 다음과 같이 termination_by를 적어주고 decreasing_by로 앞서 쓴 증명 데이터를 넘겨주면 컴파일이 성공한다.
def dropRec (input : String.Slice) :=
  if h : input.isEmpty then 0
  else 1 + dropRec (input.drop 1)
termination_by input.copy.toList.length
decreasing_by exact input.length_drop_one_lt h

이런 모든 경우에도 불구하고 lean에서 정지 여부를 증명하기 매우 까다롭거나, IO랑 엮인 경우처럼 실용적으로 불필요한 경우들이 있을 것이다. 이럴 땐 그냥 포기하고 partial def를 쓰는 방법이 있으나, 이 경우 상술한 consistency 원칙에 위배되기 때문에 증명에 사용할 수 없다는 단점이 있다.

3. 기타

  • 내장 정규 표현식 지원은 없다. 진짜 string regex가 필요하다면 lean-regex 등을 사용하자. 형식 언어론적으로 다룰 거라면 mathlib에 Mathlib.Computability.RegularExpressions에 있으나 현재 몇몇 이슈에 TODO가 붙어있는 상황이니 직접 PR이나 Zulip을 보고 판단하자.
  • 버전 관리자로 elan이 있는데, Nix를 쓰고 있다면 lean4를 바로 설치해도 된다. 단, 둘을 동시에 설치하면 elan toolchain을 nixpkgs 버전이 덮어버릴 수 있으니 하나만 쓰는 것이 좋다. flake 관리를 잘 할 자신이 있다면 lean4-nix 등의 overlay를 사용해도 무방한 편. 기본적으로 빌드 툴로 lake를 쓰고 있다면 lean-toolchain이랑 lakefile.toml 버전을 맞춰줘야 한다.
  • 생성형 인공지능이 나오기 10년도 전부터 쓰이던 기술이고 증명보조기 자체도 수많은 구현이 있으나, 생성형 인공지능의 발전 및 대중화 이후 가장 대표적으로 쓰이는 증명보조기 중 하나가 되었고, 주요 연구 성과 및 형식화가 상당수 Lean4로 이루어지는 추세이다. 이 때문에 증명보조기 지식이 부족한 대중이 반대로 AI만 쓰는 것이나 AI 전용 기술이라고 오해하기도 하나 주객전도인 셈.

4. 외부 링크


[1] 첫 리포지터리(repository)가 만들어진 것이 2013년인데, 리포지터리가 나오자마자 바로 사용 가능한 0.1 버젼이 완성된 것으로 보아 실제 개발은 그보다 일찍 시작된 것으로 보인다.[2] FRO는 Focused Research Organization (집중 연구 기관)의 약자이고, 현재 Lean FRO에 개발 자금을 대주고 있는 곳은 에릭 슈미트 등이 2021년에 설립한 자선 벤처 기업 육성 기관인 Convergent Research이다.