-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Algebraic properties of amounts #557
Comments
In writing the issue, I realized that it is already wrong. The relationship between
and add a new column for multisets (or bags), which are equivalent to @katelynsills maps from set elements to naturals. On multisets, On sets with The reason our purses and payments still work when It is clear that the difference between exclusive and shared erights will not be in the |
Looked at #523 . Bottoms out in But the interesting thing is that |
I'm wrong. @katelynsills 's lists of naturals is doing something else. We don't yet have multiset amountMath. |
Because From this we can conclude that |
This all sounds very good to me. I had previously been thinking that the AmountMath should intentionally handle duplicates. For example, even if the situation would never come up in |
Following up on @katelynsills last comment above. We discussed further and decided that indeed, the right semantics for most uses is sets, not multisets, where |
@katelynsills @Chris-Hibbert @tyg I think this needs to be settled and carefully written down. Given the refactorings we're in the midst of, this is a good time to at least refamiliarize ourselves with it. So assigning the four of us. |
Searching, the closest math concept I found is the Commutative Monoid https://en.wikipedia.org/wiki/Monoid#Commutative_monoid . The monoid's add operator implies its ordering operator. The properties of all these seem to match. |
hey @erights, I've spent some time looking into this issue this week and have a quick question. Is the end goal for this issue to express that |
Correct. Reusing the table from the top (which is still accurate for amountMath) a use we make of each is:
|
refs #557 CommutativeMonoid specification
@erights writes Aug 5, 2021:
I learned enough TLA+ to specify CommutativeMonoid: https://github.com/Agoric/agoric-sdk/blob/dc-ertp-spec/packages/ERTP/spec/Amount.tla
TLA+ Crash CourseThese are the materials I learned from: |
refs #557 CommutativeMonoid specification
since AmountMath is stateless, property testing is about the same thing as model checking with TLA+: |
Hi @Tyrosine22 and @dckc , I just removed Tom and added you two. It would be cool to get this written down in a coherent and clear manner, and to put into into the appropriate findable place. Where would that be? |
In ERTP docs, after basics of fungible amounts, when we give details about nfts, SET, and COPY_BAG. |
An amount is a group defined by the following abstract operators (represented by methods of
AmountMath
. The two most common abstract examples of amounts are natural numbers and sets.These operators must always be pure deterministic predicates and functions, up to equivalence regarding these operators.
We need to define the algebraic properties that these operators have in relationship to each other. All amount implementations, and therefore all extent implementations, must be verified (initially by hand) to have these algebraic properties. Our own generically parametrizable code, such as Zoe and most of our contracts, must not count on any algebraic properties not guaranteed by the amount specification. This issue is a start on gathering such algebraic properties. Note I am not a formalist and this should be taken up by someone who is.
forall
x
,y
,z
which are amounts from the same amount group, where0
is the empty of that group:x >= y
is a total predicate, i.e., always gives true or false, never an error.x >= 0
, all amounts include the empty amount. Thus, no negatives.>=
is a partial orderx == y
iff x and y are indistinguishable by these operators.==
is a total predicate.x + y
is total and closed, meaning it is defined for allx
andy
and always produces a new amount from the same group.x + y == y + x
, so+
is commutative(x + y) + z == x + (y + z)
, so+
is associativex + y >= x
(thereforex + y >= y
), so+
is monotonicx + 0 == x
(therefore0 + x == x
), so empty is the identity elementx - y
is not total. It is defined iffx >= y
. It is closed, i.e., where it is defined, its result is another amount of the same group.x + y == z
iffz - x == y
(thereforez - y == x
). Since the left equation impliesz >= x
andz >= y
, the subtraction is defined everywhere that the left equation holds.(question: are any of the above bullets implied by the others, and can therefore be dropped as definitional?)
Given only the above guarantees, we should be able to prove that, with purses and payments of a well behaved issuer ( Agoric/documentation#663 ) , but without access to that issuer's mint, one cannot violate conservation of currency. This should follow from the mapping of
deposit
to+
, ofwithdraw
to-
(including the>=
check), the associative, commutative nature of+
and the relationship of+
to-
. We should be able to generalize the other proofs in https://research.google/pubs/pub44272/ in the same manner.Design
nat
and otherAssetKind
sThe text was updated successfully, but these errors were encountered: