1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
doc ///
Key
tally
(tally, VisibleList)
(tally, String)
Headline
tally the elements of a list, sequence, array, or string
Usage
y = tally x
Inputs
x:{VisibleList,String}
Outputs
y:Tally
Description
Text
It produces a hash table (multiset) @TT "y"@ which tallies the frequencies
of the occurrences of items in the list or string @TT "x"@, i.e.,
@TT "y_i"@ is the number of times @TT "i"@ appears in @TT "x"@, or is
@TT "0"@ if @TT "i"@ doesn't appear in the list or string.
Example
y = tally {1,2,3,a,b,1,2,a,1,2,{a,b},{a,b},a}
y_2
y_5
y_{a,b}
tally "Hello, world!"
SeeAlso
Tally
///
document {
Key => Tally,
Headline => "the class of all tally results",
TT "Tally", " -- a class designed to hold tally results, i.e., multisets.",
SeeAlso => { Set },
Subnodes => {
TO (symbol +, Tally, Tally),
TO (symbol -, Tally, Tally),
}
}
document {
Key => VirtualTally,
"The only difference between this class and ", TO "Tally", " is that this class allows negative numbers.",
EXAMPLE lines ///
x = tally {a,b,b,c,c,c}
y = tally {a,a,a,b,b,c}
x' = new VirtualTally from x
y' = new VirtualTally from y
x-y
x'-y'
///,
Subnodes => {
TO Tally,
TO BettiTally,
TO (symbol **, VirtualTally, VirtualTally),
TO (symbol ^**, VirtualTally, ZZ),
TO (symbol +, VirtualTally, VirtualTally),
TO (symbol -, VirtualTally, VirtualTally),
TO (symbol -, VirtualTally),
TO (symbol _, VirtualTally, Thing),
TO (product, VirtualTally),
TO (sum, VirtualTally),
}
}
document {
Key => (symbol **, VirtualTally, VirtualTally),
Headline => "Cartesian product of tallies",
TT "x ** y", " -- produces the Cartesian product of two tallies.",
PARA{},
"One of the arguments may be a ", TO "Set", ".",
PARA{},
EXAMPLE {
"x = tally {a,a,b}",
"y = tally {1,2,2,2}",
"x ** y",
},
SeeAlso => {"Tally", "tally"}
}
-- TODO
document {
Key => (symbol -, VirtualTally, VirtualTally),
}
document {
Key => (symbol +, VirtualTally, VirtualTally),
Headline => "union of tallies",
TT "x + y", " -- produces the union of two tallies.",
PARA{},
"One of the arguments may be a ", TO "Set", ".",
PARA{},
EXAMPLE {
"x = tally {a,b,b,c,c,c,d,d,d}",
"y = tally {a,a,a,b,b,c,d}",
"x' = new VirtualTally from x",
"y' = new VirtualTally from y",
"z' = y' - x'",
"z' + x'",
"z' + y'",
},
}
document {
Key => (symbol -, VirtualTally),
Headline => "negation of a virtual tally",
TT "-x", " -- the negation of ", TT "x",
PARA{},
EXAMPLE {
"x = tally {a,b,b,c,c,d,d,d}",
"x' = new VirtualTally from x",
"- x'",
},
}
document {
Key => (symbol +, Tally, Tally),
Headline => "union of tallies",
TT "x + y", " -- produces the union of two tallies.",
PARA{},
"One of the arguments may be a ", TO "Set", ".",
PARA{},
EXAMPLE {
"x = tally {a,a,a,b,b,c}",
"y = tally {b,c,c,d,d,d}",
"x + y",
},
SeeAlso => {"Tally", "tally"}
}
document {
Key => (symbol -, Tally, Tally),
Headline => "difference of tallies",
Usage => "x - y",
Inputs => { "x", "y" },
Outputs => { { "the difference of the two tallies" } },
"The count associated to an item ", TT "i", " in the result is the difference of the counts in
", TT "x", " and in ", TT "y", " if it's positive, otherwise, zero.",
EXAMPLE "tally {a,a,b,c} - tally {c,d,d}",
SeeAlso => "Tally"
}
document {
Key => (symbol ^**, VirtualTally, ZZ),
Headline => "Cartesian power of sets and tallies",
Usage => "B = A^**n",
Inputs => { "A", "n" },
Outputs => {"B" => { "the tally of ", TT "n", "-tuples of elements from ", TT "A" }},
"If ", TT "A", " is ", ofClass Set, ", then so is ", TT "B", ".",
EXAMPLE lines ///
A = set {1,2}
A^**3
A = tally {1,1,2}
A^**3
///,
SeeAlso => {Set, (symbol**,Set,Set)}
}
document {
Key => (symbol _, VirtualTally, Thing),
Headline => "get a count from a tally",
Usage => "t_x",
Inputs => {
"t","x"
},
Outputs => {
ZZ => {"the number of times ", TT "x", " is counted by ", TT "t"}
},
EXAMPLE lines ///
t = tally apply(1..10000, i -> # factor i)
t_5
t_6
///,
SeeAlso => {Tally}
}
|