-
Notifications
You must be signed in to change notification settings - Fork 37
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
Refactor of Reduce / Fold operators #38
Conversation
modules/FiniteSetsExt.tla
Outdated
(* where `x` s the current value of the iterator. *) | ||
(* *) | ||
(* Example: *) | ||
(* FoldSet(LAMBA x,y : x + y, 0 .. 10, 0) = 55 *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mismatch: Example mentions FoldSet
but operator name is MapThenFoldSet
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this in the definition of FoldSet by MapThenFoldSet ?
08a128e
to
fc824da
Compare
f6f0342
to
1dc1c47
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order of base
and set
in calls to FoldSet
is inconsistent. I have added comments to fix that.
modules/FiniteSetsExt.tla
Outdated
(* Fold op over the elements of set using base as starting value. *) | ||
(* *) | ||
(* Example: *) | ||
(* FoldSet(LAMBA x,y : x + y, 0 .. 10, 0) = 55 *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(* FoldSet(LAMBA x,y : x + y, 0 .. 10, 0) = 55 *) | |
(* FoldSet(LAMBA x,y : x + y, 0, 0 .. 10) = 55 *) |
(* An alias for FoldSet. ReduceSet was used instead of FoldSet in *) | ||
(* earlier versions of the community modules. *) | ||
(*************************************************************************) | ||
FoldSet(op, set, acc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FoldSet(op, set, acc) | |
FoldSet(op, acc, set) |
(* Example: *) | ||
(* Product(1 .. 3) = 6 *) | ||
(*************************************************************************) | ||
FoldSet(LAMBDA x, y: x * y, set, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FoldSet(LAMBDA x, y: x * y, set, 1) | |
FoldSet(LAMBDA x, y: x * y, 1, set) |
(* Example: *) | ||
(* Sum(0 .. 10) = 55 *) | ||
(*************************************************************************) | ||
FoldSet(LAMBDA x, y: x + y, set, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FoldSet(LAMBDA x, y: x + y, set, 0) | |
FoldSet(LAMBDA x, y: x + y, 0, set) |
FlattenSet(S) == | ||
(******************************************************************************) | ||
(* Starting from base, apply op to f(x), for all x \in S, in an arbitrary *) | ||
(* order. It is assumed that op is associative and commutative. *) | ||
(* *) | ||
(* Example: *) | ||
(* *) | ||
(* FlattenSet({{1},{2}}) = {1,2} *) | ||
(******************************************************************************) | ||
FoldSet(LAMBDA x,y: x \cup y, {}, S) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is not it exactly UNION S
?
(***************************************************************************) | ||
ReduceSet(LAMBDA i, a: op(seq[i], a), DOMAIN seq, acc) | ||
MapThenFoldSet(op, base, LAMBDA i : seq[i], LAMBDA x,y: TRUE, DOMAIN seq) | ||
FoldLeft(op(_, _), base, seq) == |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FoldLeft(op(_, _), base, seq) == | |
FoldSeqLeft(op(_, _), base, seq) == |
modules/SequencesExt.tla
Outdated
(* FoldSeq folds op on all elements of seq from left to right. *) | ||
(***************************************************************************) | ||
MapThenFoldSet(op, base, LAMBDA i : seq[i], LAMBDA x,y: x < y, DOMAIN seq) | ||
FoldRight(op(_, _), base, seq) == |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FoldRight(op(_, _), base, seq) == | |
FoldSeqRight(op(_, _), base, seq) == |
…to appropriate modules (Functions, FiniteSequencesEx)
75790aa
to
6a3dd90
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
@quicquid Can you please add a note to https://github.com/tlaplus/CommunityModules/blob/master/README.md#contributing about the line-number business in tests? |
Merged with (squashed) commit 0b5fcd4 |
CommunityModules/modules/SequencesExt.tla Line 180 in fa811ce
{ f[x] : x \in DOMAIN f } that is even part of Functions!Range(s) .
|
No description provided.