Skip to content

Commit 2fded43

Browse files
committed
feat(fibonacci): add Plutarch 1.10.1 submission by SeungheonOh
Cherry-picked Plutarch fibonacci submission from PR #28: - CPU units: 159,193,455,218 - Memory units: 583,897,822 - Script size: 50 bytes - Implements fibonacci using fix point combinators
1 parent 472e62f commit 2fded43

7 files changed

Lines changed: 156 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Benchmark Implementation Notes
2+
3+
**Scenario**: `fibonacci`
4+
5+
**Submission ID**: `Plutarch_1.10.1_SeungheonOh`
6+
7+
## Implementation Details
8+
9+
- **Compiler**: `Plutarch v1.10.1`
10+
- **Implementation Approach**: `recursive`
11+
- **Compilation Flags**: N/A
12+
13+
## Performance Results
14+
15+
- See [metrics.json](metrics.json) for detailed performance measurements
16+
17+
## Reproducibility
18+
19+
- **Source Available**: true
20+
- **Source Repository**: N/A
21+
- **Compilation Config**: describe any non-default parameters
22+
23+
## Notes
24+
25+
I provided two different fix point combinator: `pfix'` and `pfix''`. They have different performance trade offs. `pfix'` will generate smaller script with bigger CPU and Memory cost while `pfix''` will generate bigger script(in terms of size) with smaller CPU and Memory cost.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"comment": "Optional: Include compilation parameters that affect UPLC output",
3+
"optimization_flags": [],
4+
"compiler_settings": {},
5+
"build_environment": {}
6+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(program
2+
1.1.0
3+
[
4+
[
5+
(lam i-0 [ i-0 i-0 ])
6+
(lam
7+
i-1
8+
(lam
9+
i-2
10+
(force
11+
(case
12+
(constr
13+
0
14+
[ [ (builtin lessThanEqualsInteger) i-2 ] (con integer 1) ]
15+
(delay i-2)
16+
(delay
17+
[
18+
[
19+
(builtin addInteger)
20+
[
21+
[ i-1 i-1 ]
22+
[ [ (builtin subtractInteger) i-2 ] (con integer 1) ]
23+
]
24+
]
25+
[
26+
[ i-1 i-1 ]
27+
[ [ (builtin subtractInteger) i-2 ] (con integer 2) ]
28+
]
29+
]
30+
)
31+
)
32+
(force (builtin ifThenElse))
33+
)
34+
)
35+
)
36+
)
37+
]
38+
(con integer 25)
39+
]
40+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"compiler": {
3+
"name": "Plutarch",
4+
"version": "1.10.1",
5+
"commit_hash": "75c06ef1e77742916574414975f76ddac59cce4a"
6+
},
7+
"compilation_config": {
8+
"optimization_level": "Plutarch",
9+
"target": "uplc",
10+
"flags": ["Plutarch"],
11+
"environment": {
12+
"dependencies": {
13+
"plutarch": "1.10.1"
14+
}
15+
}
16+
},
17+
"contributor": {
18+
"name": "Seungheon Oh",
19+
"organization": "IOG",
20+
"contact": "seungheon.oh@iohk.io"
21+
},
22+
"submission": {
23+
"date": "2025-08-19T00:00:00Z",
24+
"source_available": true,
25+
"implementation_notes": "Plutarch"
26+
}
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"execution_environment": {
3+
"evaluator": "PlutusTx.Eval-unknown"
4+
},
5+
"measurements": {
6+
"cpu_units": 159193455218,
7+
"memory_units": 583897822,
8+
"script_size_bytes": 50,
9+
"term_size": 43
10+
},
11+
"notes": "<optional notes>",
12+
"scenario": "fibonacci",
13+
"timestamp": "2025-08-20T05:56:42Z",
14+
"version": "1.0.0"
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Optional: Place your source code files here
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module Main where
2+
3+
import Control.Lens (traverseOf)
4+
import Plutarch.Internal.Term (compile, punsafeCoerce)
5+
import Plutarch.Prelude
6+
import Plutarch.Script
7+
import PlutusCore (FreeVariableError, runQuoteT)
8+
import PlutusCore.Pretty
9+
import UntypedPlutusCore (
10+
fakeNameDeBruijn,
11+
progTerm,
12+
programMapNames,
13+
unDeBruijnTerm,
14+
)
15+
16+
-- this is faster than `Plutarch.Internal.Fix.pfix`.
17+
pfix' :: (Term s (a :--> b) -> Term s (a :--> b)) -> Term s (a :--> b)
18+
pfix' f =
19+
(plam $ \r -> (punsafeCoerce r) # r)
20+
# (plam $ \r -> f ((punsafeCoerce r) # r))
21+
22+
-- this is faster than `pfix'` but generates more bloat uplc.
23+
pfix'' :: (Term s (a :--> b) -> Term s (a :--> b)) -> Term s (a :--> b)
24+
pfix'' f =
25+
(plam $ \r -> f ((punsafeCoerce r) # r))
26+
# (plam $ \r -> f ((punsafeCoerce r) # r))
27+
28+
pfibo :: Term s (PInteger :--> PInteger)
29+
pfibo =
30+
pfix' $ \r -> plam $ \x ->
31+
pif (x #<= 1) x (r # (x - 1) + r # (x - 2))
32+
33+
main :: IO ()
34+
main =
35+
case compile mempty $ pfibo # 25 of
36+
Left _ -> error "compiliation failed"
37+
Right (Script s) ->
38+
case runQuoteT $
39+
traverseOf progTerm unDeBruijnTerm $
40+
programMapNames fakeNameDeBruijn s of
41+
Left (_ :: FreeVariableError) -> error "debruijn conversion failed"
42+
Right s' -> print $ prettyPlcClassic s'

0 commit comments

Comments
 (0)