c-cpp-to-lean4-translator

Solid

Translate C or C++ programs into equivalent Lean4 code, preserving program semantics and ensuring the generated code is well-typed, executable, and can run successfully. Use when the user asks to convert C/C++ code to Lean4, port C/C++ programs to Lean4, translate imperative code to functional Lean4, or create Lean4 versions of C/C++ algorithms.

Data & Documents 160 stars 17 forks Updated today Apache-2.0

Install

View on GitHub

Quality Score: 87/100

Stars 20%
73
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# C/C++ to Lean4 Translator ## Overview Transform C or C++ programs into equivalent Lean4 code that preserves the original semantics while leveraging Lean4's functional programming paradigm, strong type system, and proof capabilities. ## Translation Workflow ### Step 1: Analyze Input Code Understand the C/C++ program structure and semantics: 1. **Identify program components:** - Functions and their signatures - Data structures (structs, classes, arrays) - Control flow patterns (loops, conditionals) - Memory management (allocation, pointers) - I/O operations - Dependencies and includes 2. **Understand semantics:** - What does the program compute? - What are the inputs and outputs? - Are there side effects? - What are the invariants and preconditions? 3. **Note translation challenges:** - Pointer arithmetic - Mutable state - Imperative loops - Manual memory management - Undefined behavior ### Step 2: Design Lean4 Structure Plan the Lean4 equivalent before writing code: 1. **Choose appropriate types:** - `Int` for signed integers - `Nat` for unsigned integers and array indices - `Float` for floating-point numbers - `Array` for dynamic arrays - `List` for linked lists - Custom `structure` types for structs/classes 2. **Determine purity:** - Pure functions: return values directly - Side effects: use `IO` monad - Mutable state: use `IO.Ref` or `ST` monad 3. **Plan control flow translation:** - L...

Details

Author
ArabelaTso
Repository
ArabelaTso/Skills-4-SE
Created
6 months ago
Last Updated
today
Language
Python
License
Apache-2.0

Similar Skills

Semantically similar based on skill content — not just same category