PocketChange 1.02

documentation notebook

Eric Rowland
https://ericrowland.github.io/packages.html

Introduction

PocketChange is a package for analyzing the long-term behavior of the set of coins in one’s pocket.
This introduction gets you started with a few features of the package; the next section provides a complete list of package symbols along with their usage messages and further examples.

To use PocketChange, first you will need to load the package by evaluating the following cell. (If you need help, see loading a package.)

<<PocketChange`

Overview

In a cash transaction, the spender hands coins to the cashier to pay for the purchase, and the cashier hands coins back to the spender for the change.

Cashiers use the greedy algorithm to decide what coins to return, and they effectively have an infinite supply.  GreedyPartition gives the greedy partition of an integer in a given currency.

GreedyPartition[30,{1,5,10,25}]

Spenders, on the other hand, are assumed to
• spend no coins if they do not have sufficient change,
• overpay as little as possible if they do have sufficient change, and
• break ties among the possible ways to pay by favoring bigger coins to spend over smaller coins.
Such a spender is called a big spender, and the set of coins a big spender has after a transaction is computed by BigSpenderTransaction.

BigSpenderTransaction[{25,25,5},99]

BigSpenderTransaction[{25,25,5},28]

The set of all reasonable pocket partitions for a given currency is given by PartitionList.

PartitionList[{10,25}]

Many examples of computing limiting distributions of coins appear in the computation notebook accompanying the paper “What's in YOUR wallet?” by Lara Pudwell and Eric Rowland:
https://ericrowland.github.io/computations/What’s_in_YOUR_wallet.nb

Package symbols

BigSpenderBestPartition

?BigSpenderBestPartition

BigSpenderBestPartition[{{5,5,5},{10,5}}]

BigSpenderTransaction

?BigSpenderTransaction

BigSpenderTransaction[{25,10,5,5,1,1},13]

BigSpenderTransaction[{25,10,5,5,5,1,1},13]

BigSpenderTransaction[{25,1,1,1},13]

BigSpenderTransaction[{1,1,1,1},99]

DistinctSubsets

?DistinctSubsets

DistinctSubsets[{10,5,1,1}]

When there are no repeated elements, the DistinctSubsets are the same as the Subsets:

DistinctSubsets[{1,2,3}]==Subsets[{1,2,3}]

Union[Sort/@Subsets[{a,a,b,c,c,b}]]==Sort[DistinctSubsets[{a,a,b,c,c,b}]]

GreedyPartition

?GreedyPartition

GreedyPartition[98]

If the integer is not representable in the currency, GreedyPartition returns unevaluated:

GreedyPartition[98,{5,10}]

PartitionList

?PartitionList

PartitionList[{20,25}]

Total/@%

Short[PartitionList[]]

PenniesFirstBigSpenderTransaction

?PenniesFirstBigSpenderTransaction

PenniesFirstBigSpenderTransaction[{25,10,5,5,1,1},13]

PenniesFirstBigSpenderTransaction[{25,10,5,5,5,1,1},13]

PenniesFirstBigSpenderTransaction[{25,1,1,1},13]

PenniesFirstBigSpenderTransaction[{1,1,1,1},99]