| [[프로그래밍 언어|'''프로그래밍 언어 {{{#!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> ※ 나무위키에 등재된 프로그래밍 언어 목록 | |
| A | ActionScript · AdaT · AgdaTP · ALGOLT · ApexT · APL · awk · AssemblyT | |||||||
| B | BASIC | |||||||
| C | ||||||||
| D | ||||||||
| E | Elixir · | |||||||
| F | ||||||||
| G | GNU Octave · | |||||||
| H | ||||||||
| J | ||||||||
| K | ||||||||
| L | LeanTP · | |||||||
| M | MATLAB · MaxV · MojoT · Moonlight | |||||||
| N | ||||||||
| O | OberonT · Objective-CT · | |||||||
| P | PascalT · | |||||||
| Q | Q#T · QML | |||||||
| R | ||||||||
| S | SAS · | |||||||
| T | ||||||||
| U | UdonV · | |||||||
| V | Visual Basic · Visual Basic .NET · Visual Basic for Applications · vvvvV | |||||||
| X | XSharp | |||||||
| Z | ZenScript · | |||||||
| ㄴ | 누리 | |||||||
| ㅅ/ㅆ | 숨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 | }}}}}}}}}}}} | }}}}}}}}}}}} | |||
| 실행 방식 · 분류 · 언어 목록(분류:프로그래밍 언어 문법) · 언어별 예제 · 틀:프로그래밍 언어 문법 · 틀:난해한 프로그래밍 언어 | ||||||||
| 틀:난해한 프로그래밍 언어어와의 병합 토론이 진행 중입니다. | ||||||||
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. 외부 링크
- https://lean-lang.org/
- Lean Documentation Overview
- A Tour of Lean
- Lean4 Playground
- The Lean Language Reference
- Theorem Proving in Lean 4
- Natural Number Game
- 페아노 공리계를 구성하면서 진행되는 대화형 Lean 튜토리얼이다.
- vscode 확장
- Lean community
- Mathematics in Lean
- The Math Is Haunted