plutus-core-1.70.0.0: Language library for Plutus Core
Safe HaskellSafe-Inferred
LanguageHaskell2010

Evaluation.Builtins.Costing

Synopsis

Documentation

eqCostStream ∷ CostStream → CostStream → Bool Source #

Direct equality of two CostStreams. Same as deriving stock Eq. We don't want to do the latter, because the semantics of a CostStream are those of the sum of its elements and the derived Eq instance would conflict with that.

magnitudes ∷ [(SatInt, SatInt)] Source #

A list of ranges: (0, 0), (1, 10) : (11, 100) : (101, 1000) : ... : [(10^18, maxBound)].

toRange ∷ SatInt → (SatInt, SatInt) Source #

Return the range (in the sense of magnitudes) in which the given SatInt belongs. E.g.

>>> toRange 42
(11,100)
>>> toRange 1234
(1001,10000) 

chooseSatInt ∷ (SatInt, SatInt) → Gen SatInt Source #

Generate a SatInt in the given range.

checkEqualsVia ∷ Show a ⇒ (a → a → Bool) → a → a → Property Source #

Same as (===) except accepts a custom equality checking function.

bottom ∷ a Source #

A value to use in tests to make sure what's not supposed to be forced isn't forced.

test_magnitudes ∷ TestTree Source #

Test that magnitudes has the correct bounds.

test_CostStreamDistribution ∷ TestTree Source #

Show the distribution of generated CostStreams as a diagnostic.

test_toCostListRoundtrip ∷ TestTree Source #

Test that fromCostList . toCostList is identity.

test_fromCostListRoundtrip ∷ TestTree Source #

Test that toCostList . fromCostList is identity.

test_unconsCostRoundtrip ∷ TestTree Source #

Test that uncurry reconsCost . unconsCost is identity.

test_sumCostStreamIsSum ∷ TestTree Source #

Test that sumCostStream returns the sum of the elements of a CostStream.

test_mapCostStreamIsMap ∷ TestTree Source #

Test that mapCostStream applies a function to each element of a CostStream.

test_addCostStreamIsAdd ∷ TestTree Source #

Test that the sum of a stream returned by addCostStream equals the sum of the sums of its two arguments.

test_minCostStreamIsMin ∷ TestTree Source #

Test that the sum of a stream returned by minCostStream equals the minimum of the sums of its two arguments.

test_zipCostStreamIsZip ∷ TestTree Source #

Test that the sum of a stream returned by zipCostStream equals an ExBudget containing the sums of its two arguments.

test_mapCostStreamReasonableLength ∷ TestTree Source #

Test that mapCostStream preserves the length of the stream.

test_addCostStreamReasonableLength ∷ TestTree Source #

Test that the length of the stream returned by addCostStream equals the sum of the lengths of its two arguments.

test_minCostStreamReasonableLength ∷ TestTree Source #

Test that the length of the stream returned by addCostStream is

  1. greater than or equal to the minimum of the lengths of its two arguments
  2. smaller than or equal to the sum of the lengths of its two arguments.

test_zipCostStreamReasonableLength ∷ TestTree Source #

Test that the length of the stream returned by zipCostStream equals the maximum of the lengths of its two arguments.

test_mapCostStreamHandlesBottom ∷ TestTree Source #

Test that mapCostStream preserves the laziness of its argument.

test_addCostStreamHandlesBottom ∷ TestTree Source #

Test that mapCostStream preserves the laziness of its two arguments.

test_minCostStreamHandlesBottom ∷ TestTree Source #

Test that minCostStream preserves the laziness of its two arguments.

postAlignWith ∷ a → [a] → [a] → ([a], [a]) Source #

Pad the shortest of the given lists by appending the given element to it until the length of the result matches the length of the other list.

>>> postAlignWith 'a' "bcd" "e"
("bcd","eaa")
>>> postAlignWith 'a' "b" "cdef"
("baaa","cdef") 

test_zipCostStreamHandlesBottom ∷ TestTree Source #

Test that zipCostStream preserves the laziness of its two arguments.

sierpinskiSize ∷ Int → Int Source #

The size sierpinskiRose of the given depth.

sierpinskiRose ∷ Int → CostRose Source #

Return a finite balanced tree with each node (apart from the leaves) having exactly 3 children. The parameter is the depth of the tree. Named after https://en.wikipedia.org/wiki/Sierpi%C5%84ski_triangle

test_flattenCostRoseIsLinearForSierpinskiRose ∷ Int → TestTree Source #

Traverse a sierpinskiRose of the given depth and display the total amount of elements processed. See test_flattenCostRoseIsLinear for why we do this.

test_flattenCostRoseIsLinear ∷ TestTree Source #

Test that traversing a larger CostRose takes _linearly_ more time. The actual test can only be done with eyes unfortunately, because the tests are way too noisy for evaluation times to be reported even remotely accurately.

genCostRose ∷ NonEmptyList SatInt → Gen CostRose Source #

Generate a CostRose from the given list by splitting the list into sublists and generating a CostRose for each of them recursively.

collectListLengths ∷ CostRose → [Int] Source #

Return the lengths of all the forests in a CostRose.

test_CostRoseListLengthsDistribution ∷ TestTree Source #

Show the distribution of forest lengths in generated CostRose values as a diagnostic.

test_genCostRoseSound ∷ TestTree Source #

Test that genCostRose only takes costs from its argument when generating a CostRose.

test_flattenCostRoseSound ∷ TestTree Source #

Test that flattenCostRose returns the elements of its argument.

test_costsAreNeverNegative ∷ TestTree Source #

Test that memoryUsage called over a value of a built-in type never returns a stream containing a negative cost.

Orphan instances

Arbitrary CostStream Source # 
Instance details

Arbitrary CostRose Source # 
Instance details

Arbitrary SatInt Source #

Generate asymptotically bigger SatInts with exponentially lower chance. This is in order to make the generator of CostStream produce streams whose sums are more or less evenly distributed across magnitudes.

Instance details

Methods

arbitrary ∷ Gen SatInt #

shrink ∷ SatInt → [SatInt] #

CoArbitrary SatInt Source # 
Instance details

Methods

coarbitrary ∷ SatInt → Gen b → Gen b #

Function SatInt Source # 
Instance details

Methods

function ∷ (SatInt → b) → SatInt :-> b #

Foldable NonEmptyList Source # 
Instance details

Methods

fold ∷ Monoid m ⇒ NonEmptyList m → m Source #

foldMap ∷ Monoid m ⇒ (a → m) → NonEmptyList a → m Source #

foldMap' ∷ Monoid m ⇒ (a → m) → NonEmptyList a → m Source #

foldr ∷ (a → b → b) → b → NonEmptyList a → b Source #

foldr' ∷ (a → b → b) → b → NonEmptyList a → b Source #

foldl ∷ (b → a → b) → b → NonEmptyList a → b Source #

foldl' ∷ (b → a → b) → b → NonEmptyList a → b Source #

foldr1 ∷ (a → a → a) → NonEmptyList a → a Source #

foldl1 ∷ (a → a → a) → NonEmptyList a → a Source #

toList ∷ NonEmptyList a → [a] Source #

null ∷ NonEmptyList a → Bool Source #

length ∷ NonEmptyList a → Int Source #

elem ∷ Eq a ⇒ a → NonEmptyList a → Bool Source #

maximum ∷ Ord a ⇒ NonEmptyList a → a Source #

minimum ∷ Ord a ⇒ NonEmptyList a → a Source #

sum ∷ Num a ⇒ NonEmptyList a → a Source #

product ∷ Num a ⇒ NonEmptyList a → a Source #