plutus
plutus copied to clipboard
refactor(cost-model): use linear costing for valueContains
Summary
- Change
valueContainscosting frommultiplied_sizestoconst_above_diagonalwithlinear_in_x_and_yinner model - Add
LinearInXAndYconstructor to SimpleJSON.hs for JSON parsing - Update cost model visualization to support new model types
Motivation
The true complexity of valueContains is O(m*log(n/m+1)) where n is the container size and m is the contained size. Kenneth MacKenzie showed that this is bounded above by a linear function (m+n)/k for some constant k.
The new model better reflects this:
- Above diagonal (y > x): constant cost (early exit, returns False immediately)
- Below diagonal (x >= y):
intercept + slope1*x + slope2*y
Changes
| File | Change |
|---|---|
models.R |
Update valueContainsModel to use const_above_diagonal with linear_in_x_and_y |
SimpleJSON.hs |
Add LinearInXAndY constructor for JSON parsing |
utils.js |
Add evaluators for linear_in_x_and_y and const_above_diagonal |
builtinCostModel{A,B,C}.json |
Regenerated with new model type |
New Cost Model Structure
"valueContains": {
"cpu": {
"arguments": {
"constant": 284518,
"model": {
"arguments": {
"intercept": 1000,
"slope1": 158792,
"slope2": 24659
},
"type": "linear_in_x_and_y"
}
},
"type": "const_above_diagonal"
},
"memory": {
"arguments": 32,
"type": "constant_cost"
}
}
Test plan
- [x] Build passes
- [x] Conformance tests pass (will need budget expectation updates)
- [x] Cost model visualization works with new model type
Closes https://github.com/IntersectMBO/plutus-private/issues/1984
PR Preview Action v1.6.2 :---: |
:rocket: View preview athttps://IntersectMBO.github.io/plutus/pr-preview/cost-models/pr-7476/
|
Built to branch gh-pages at 2025-12-04 16:06 UTC.
Preview will be ready when the GitHub Pages deployment is complete.
This PR replaces https://github.com/IntersectMBO/plutus/pull/7476