-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docs/user): produce a simple Factorial example
I extracted a Factorial example in Rust to Lean. Signed-off-by: Ryan Lahfa <[email protected]>
- Loading branch information
Ryan Lahfa
committed
Aug 20, 2024
1 parent
746b6d9
commit e340a84
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Base | ||
|
||
/-! | ||
# Computing factorial | ||
-/ | ||
|
||
open Primitives | ||
set_option linter.dupNamespace false | ||
set_option linter.hashCommand false | ||
set_option linter.unusedVariables false | ||
|
||
namespace factorial | ||
|
||
/- [factorial::factorial]: | ||
Source: 'src/factorial.rs', lines 1:0-1:27 -/ | ||
divergent def factorial (n : U64) : Result U64 := | ||
if n = 0#u64 | ||
then Result.ok 1#u64 | ||
else do | ||
let i ← n - 1#u64 | ||
let i1 ← factorial i | ||
n * i1 | ||
|
||
end factorial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{#include factorial.lean}} |