Skip to content

Commit 87200ea

Browse files
committed
refactor: simplify Value builtin cost models with improved documentation
Simplify the R model definitions for Value-related builtins by replacing custom linear model implementation with standard linearInY wrapper for valueContains. This maintains the same statistical behavior while improving code maintainability. Add inline comments documenting the parameter wrapping strategy used for each model (Logarithmic wrapping for lookupCoin/valueContains, ValueTotalSize for contains operand, unwrapped for valueData/unValueData). Clean up formatting inconsistencies in model definitions.
1 parent 7eebe28 commit 87200ea

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

plutus-core/cost-model/data/models.R

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -806,29 +806,25 @@ modelFun <- function(path) {
806806
mk.result(m, "exp_mod_cost")
807807
}
808808

809-
dropListModel <- linearInX ("DropList")
809+
dropListModel <- linearInX ("DropList")
810810

811811
## Arrays
812812
lengthOfArrayModel <- constantModel ("LengthOfArray")
813813
listToArrayModel <- linearInX ("ListToArray")
814814
indexArrayModel <- constantModel ("IndexArray")
815815

816816
## Values
817-
lookupCoinModel <- linearInZ ("LookupCoin")
818817

819-
## ValueContains is O(n₂ × log max(m₁, k₁)) where n₂ is the total size of the second Value
820-
## We model this as linear in the sum of sizes, which is conservative
821-
valueContainsModel <- {
822-
fname <- "ValueContains"
823-
filtered <- data %>%
824-
filter.and.check.nonempty(fname) %>%
825-
discard.upper.outliers()
826-
m <- lm(t ~ I(x_mem + y_mem), filtered)
827-
mk.result(m, "added_sizes")
828-
}
818+
# Z wrapped with `Logarithmic . ValueOuterOrMaxInner`
819+
lookupCoinModel <- linearInZ ("LookupCoin")
820+
821+
# X wrapped with `Logarithmic . ValueOuterOrMaxInner`
822+
# Y wrapped with `ValueTotalSize`
823+
valueContainsModel <- linearInY("ValueContains")
829824

830-
valueDataModel <- constantModel ("ValueData")
831-
unValueDataModel <- linearInX ("UnValueData")
825+
# Sizes of parameters are used as is (unwrapped):
826+
valueDataModel <- constantModel ("ValueData")
827+
unValueDataModel <- linearInX ("UnValueData")
832828

833829
##### Models to be returned to Haskell #####
834830

0 commit comments

Comments
 (0)