In short.
C/C++ to Lean4 Translator is an assistant skill for developers moving C or C++ code to Lean 4, but its examples need correction and verification before equivalent behavior can be claimed. It covers types, recursion, state, arrays, structures and input/output. Concrete concerns include changed array-processing boundaries, an incorrect string-comparison substitution and incompatible summation formulas. No code was compiled or run, and no performance measurements or equivalence proofs are supplied.
Researched and written by an AI model and checked by a second AI model. How it works
Coverage includes both supplied files in skills/c-cpp-to-lean4-translator: SKILL.md and references/translation_patterns.md, plus the repository-level LICENSE above the folder, all at revision 4f38503747e0617504bce5329283ef837d375c09. Other repository content and the external documentation linked by the skill are outside this coverage. Both skill files should be retained with their relative directory structure for use. No code was executed; installation behavior, compiler acceptance, runtime results, performance and formal equivalence remain unassessed.
The overview
Resource identity
The resource is the c-cpp-to-lean4-translator skill folder in ArabelaTso/Skills-4-SE. Its two supplied files are SKILL.md and references/translation_patterns.md. They provide instructions and examples for an assistant translating C/C++ programs into Lean 4; the selected folder contains no executable translator.
The original source folder is [https://github.com/ArabelaTso/Skills-4-SE/tree/main/skills/c-cpp-to-lean4-translator]. The supplied files are pinned to revision 4f38503747e0617504bce5329283ef837d375c09.
Practical assessment
This is a useful starting checklist for an assisted port, particularly for small algorithms whose inputs and expected outputs are well understood. It encourages analysis before translation, explicit type choices, boundary-case checks and comparison with the original program.
Its promise of preserving semantics is stronger than the supplied examples establish. Static inspection shows substitutions that change interfaces or results. Treat generated code as a draft requiring review by someone who understands both languages. Successful compilation and faithful behavior remain unassessed.
Who it suits
Developers learning Lean 4 can use the side-by-side examples to understand how familiar functions, structs and mutable operations might become functional code. Experienced developers can use the workflow to identify assumptions before porting a self-contained algorithm.
Beginners will need additional help with integer behavior, shared mutable data, termination and proof obligations. The files acknowledge challenges involving threading, pointer arithmetic, macros, templates and external libraries, but do not provide complete migration strategies for those areas.
Documented coverage
The main instructions cover function signatures, conditionals, loop-to-recursion translation, arrays, structures, output parameters, input/output and mutable state using IO.Ref or ST. They also discuss optional results, bounds checks, explicit conversions and standard-library folds.
The companion reference adds examples for constants, floating-point values, strings, switch statements, dynamic arrays, constructors and basic library calls. These are documented patterns rather than demonstrated automatic translation capabilities. No parser, command-line interface, project migration engine or proof generator is supplied.
Using it
Requirements
Using the material as a skill requires an assistant that can read its instructions and companion reference. The files do not name a supported assistant, model, editor integration or installation location.
Following the proposed validation steps requires a Lean 4 project with Lake and a working build environment for the original C/C++ program. Its dependencies and representative inputs must also be available for output comparisons. No Lean toolchain version, operating-system support matrix, hardware requirement or complete project configuration is specified.
How it works
The skill guides an assistant through six stages: analyze the original program, design the Lean structure, translate it, address type issues, check results and refine the implementation. It asks the assistant to identify side effects, memory usage, invariants and preconditions before choosing a representation.
Common substitutions include structures for C/C++ records, recursion for loops, function parameters for changing state, tuples for output parameters and IO for side effects. These substitutions require decisions about observable behavior; the text does not supply an automated method for proving that those decisions preserve the original program.
Getting started
Obtain both files from the original source folder. Keep SKILL.md at the skill root and translation_patterns.md under references/ so the relative reference remains usable. The files provide no host-specific installation command; loading them depends on the chosen assistant's documented skill mechanism.
Configure the Lean project separately and supply the original program with its input assumptions. The skill proposes lake build, small #eval expressions and comparisons with the C/C++ program. These are suggested checks, and no results from performing them are supplied.
An example and its implications
The findMax example illustrates both the value and the risk of the approach. The C function accepts an array and a size. The Lean version accepts only an Array Int and returns Option Int, meaning either a maximum value or no value when the array is empty.
The new empty-array result is explicit, but dropping size changes which elements are processed. By inspection, an array containing 3 and 9 with size equal to 1 makes the C code return 3, while the supplied Lean expression processes the whole array and would produce some 9. This is a predicted difference from reading the code, not an execution result.
Assessment & evidence
Correctness limits
The suggested numeric mappings need explicit assumptions. Mapping unsigned integers to Nat does not model finite-width wraparound. Mapping signed integers to arbitrary-precision Int does not preserve all machine-integer behavior. Several examples also replace signed inputs with Nat, removing negative inputs. The reference maps both float and double to a type it describes as double precision, leaving single-precision rounding behavior unresolved.
Two substitutions are visibly problematic. The reference replaces strcmp(s1, s2) with s1 == s2, changing an ordering operation into Boolean equality. The main file's loop sums values from 0 through n minus 1, but its later closed formula n * (n + 1) / 2 sums values from 1 through n.
Replacing pointers with values or returned tuples requires analysis of shared references and mutation. Recursive examples do not explain how their termination obligations are discharged. Compilation acceptance, performance and behavior involving concurrency or external libraries remain unassessed.
Why these limits matter
A Lean program can be well typed while computing a different result from its C/C++ source. Changing integer domains, array lengths, error handling or mutation can alter behavior even when the translated function looks simpler.
The skill's advice to document assumptions and compare outputs is therefore central to its usefulness. Compilation would establish acceptance by a particular toolchain; matching selected outputs would provide evidence for those inputs. Neither alone establishes equivalence across every permitted input, and the files supply no equivalence specification or proof.
Other approaches
For learning the target language, the skill links to Lean documentation [https://lean-lang.org/documentation/] and the Lean standard-library source [https://github.com/leanprover/lean4/tree/master/src/Init]. Those linked contents were not supplied, so their current coverage and compatibility are not assessed.
A manual port driven by an explicit description of the required behavior is another approach for code with strict compatibility requirements. The supplied files name no competing translator and provide no comparison of translation quality, speed or cost.
Source evidence
The main workflow and examples are in the captured SKILL.md [https://raw.githubusercontent.com/ArabelaTso/Skills-4-SE/4f38503747e0617504bce5329283ef837d375c09/skills/c-cpp-to-lean4-translator/SKILL.md].
The additional pattern catalog is references/translation_patterns.md [https://raw.githubusercontent.com/ArabelaTso/Skills-4-SE/4f38503747e0617504bce5329283ef837d375c09/skills/c-cpp-to-lean4-translator/references/translation_patterns.md]. The licence text is the repository LICENSE [https://raw.githubusercontent.com/ArabelaTso/Skills-4-SE/4f38503747e0617504bce5329283ef837d375c09/LICENSE].
These sources establish the instructions, example code and licence terms. They contain no compiler receipts, completed comparison results, performance measurements or formal equivalence proofs. Comments stating expected outputs are examples rather than observed results.
Access & freshness
Costs
The supplied Apache License 2.0 grants copyright permissions without licence royalties. That does not establish the total cost of using an assistant to perform a port.
The files provide no assistant subscription or API pricing, token usage, compute measurements or estimate of engineering review time. Those costs depend on the chosen setup and remain unknown.
Licence and reuse
The supplied repository-level LICENSE contains Apache License 2.0. It permits reproduction, modification and redistribution subject to its conditions, including supplying the licence, marking changed files and retaining applicable notices. If a distribution contains a NOTICE file, its relevant attribution notices must also be preserved as required by the licence.
The licence includes a contributor patent grant with conditions, does not grant general trademark rights and provides the work without warranties. No separate licence terms appear in the two supplied skill files.
Version and freshness
The supplied snapshot was captured on 17 November 2026 at 09:27:26.644 UTC and identifies revision 4f38503747e0617504bce5329283ef837d375c09. That identifies the source examined, rather than a release number or a last-maintained date.
Neither skill file pins a Lean 4 toolchain version. Compatibility with a particular installed version and changes to the repository after the captured snapshot are unknown.
Practical next steps
Begin with a small function and write down its allowed inputs and required outputs. Decide how integer ranges, overflow, negative values, array lengths, empty inputs and shared mutable data should behave. Correct the string-comparison and summation substitutions before applying them.
Pin the actual Lean toolchain, compile the complete translation and compare its outputs with the original on representative and boundary inputs. Record intentional behavior changes. If formal guarantees are required, define the relationship between the source and target programs and prove the relevant properties; the supplied skill provides no such proof.
