File: doc_tables.m2

package info (click to toggle)
macaulay2 1.24.11%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 171,648 kB
  • sloc: cpp: 107,850; ansic: 16,307; javascript: 4,188; makefile: 3,947; lisp: 682; yacc: 604; sh: 476; xml: 177; perl: 114; lex: 65; python: 33
file content (703 lines) | stat: -rw-r--r-- 15,500 bytes parent folder | download
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
--authors: Dan Grayson, Lily Silverstein

doc///
 Key
  table
 Headline
  make a table from a binary function
 Usage
  table(a, b, f)
  table(m, n, f)
 Inputs
  a:List
  b:List
  m:ZZ
  n:ZZ
  f:
   a function {\tt f(i,j)} of two variables
 Outputs
  T:
   a table, or list of lists, where $T_{ij}$ is the value
   of $f(a_i, b_j)$, OR, if using integer arguments $m$ and $n$, 
   $T_{ij}=f(i,j)$ for $0\le i < m, 0\le j < n$
 Description
  Text
   The command {\tt table(m, n, f)} is equivalent to 
   {\tt table(0..(m-1), 0..(n-1), f)}.
  Example
   t1 = table({1,3,5,7}, {0,1,2,4}, (i,j) -> i^j)
   t2 = table(5, 5, (i,j) -> i+j)
  Text
   Tables can be displayed nicely using @TO netList@.
  Example
   netList t1
 SeeAlso
  applyTable
  isTable
  subtable
  "lists and sequences"
///

doc///
 Key
  applyTable
 Headline
  apply a function to each element of a table
 Usage
  applyTable(T, f)
 Inputs
  T:List
   a table (list of lists of the same length)
  f:Function
 Outputs
  A:List
   a table of the same shape as $T$, where the function
   $f$ has been applied elementwise
 Description
  Example
   t = table({1,3,5,7}, {0,1,2,4}, (i,j) -> i^j);
   netList t
   netList applyTable(t, i -> 2*i)
   netList applyTable(t, isPrime)
 SeeAlso
  isTable
  subtable
  table
  "lists and sequences"
///

doc ///
 Key
  subtable
 Headline
  extract a subtable from a table
 Usage
  subtable(a, b, T)
 Inputs
  a:List
   of rows to extract
  b:List
   of columns to extract
 Outputs
  S:
   the subtable of $T$ defined by restricting to rows in the list $a$
   and columns in the list $b$
 Description
  Example
   t = table({1,3,5,7}, {0,1,2,4}, (i,j) -> i^j);
   netList t
   s1 = subtable({0,2}, {1,3}, t);
   netList s1
   s2 = subtable(toList(0..3), {1}, t);
   netList s2
 SeeAlso
  applyTable
  isTable
  positions
  table
  select
  "lists and sequences"
///

doc///
 Key
  isTable
 Headline
  whether something is a list of lists of equal length
 Usage
  isTable t
 Inputs
  t:Thing
 Outputs
  b:Boolean
   whether or not $t$ is a table
 Description
  Example
   isTable {{1,2,3},{4,5,6}}
   isTable {{1,2,3},{4,5}}
 Caveat
  It is intrinsically impossible to represent a $0\times k$ matrix
  as a list of lists.
 SeeAlso
  applyTable
  table
  subtable
  "lists and sequences"
///
 

doc///
 Key
  HashTable
 Headline
  the class of all hash tables
 Description
  Text
   A hash table consists of: a class type, a parent type, and a
   set of key-value pairs.  The keys and values can be anything.
   The access functions below accept a key and return the
   corresponding value.  For details of the mechanism
   underlying this, see @TO "hashing"@.
   
   One important feature of hash tables that when the keys
   are consecutive integers starting at 0, the keys are scanned
   in the natural order.

   There is a subclass of HashTable called @TO MutableHashTable@
   which consists of those hash tables whose entries can be changed.
   
   This node is currently in progress!!!
 SeeAlso
  "#"
  "."
  "#?"
  ".?"
///


doc///
 Key
   keys
  (keys, Database)
  (keys, Dictionary)
  (keys, HashTable)
 Headline
  keys used in a hash table, dictionary, or database
 Usage
  keys t
 Inputs
  t:{HashTable,Dictionary,Database}
 Outputs
  :List
   the keys occurring in the hash table {\tt t}
 Description
  Example
   x = new HashTable from {a => 1, b => 2}
   keys x
 SeeAlso
  "hash tables"
  applyKeys
  pairs
  scanKeys
  values
  "#"
  "#?"
///

doc ///
 Key
  isMutable
  (isMutable, Thing)
 Headline
  whether something may be modified
 Usage
  isMutable x
 Inputs
  x:Thing
 Outputs
  :Boolean
   whether {\tt x} is mutable
 Description
  Text
   If {\tt x} is a hash table, list, dictionary, or database, then 
   it is mutable if its contents can be destructively altered.
   
   If {\tt x} is a symbol, then it's mutable if a value can be 
   assigned to it; i.e., if it is not @TO protect@ed.
   
   If {\tt x} is anything else, {\tt isMutable x} will return {\bf false}.
  Example
   T = new MutableList from (a, b, c)
   isMutable T
   V = new List from (a, b, c)
   isMutable V
   isMutable join(T, V)
   isMutable a
   isMutable "a"  
  Text
   This function may also be called using the synonym @TT "mutable"@.
 Caveat
  The (changeable) contents of a mutable hash table or list 
  do not participate in strong comparison with @TO "==="@
  or in @TO "hashing"@.
 SeeAlso
  MutableHashTable
  MutableList
  "hash tables"
  "lists and sequences"
///

doc ///
 Key
  pairs
  (pairs, HashTable)
  (pairs, Dictionary)
  (pairs, BasicList)
 Headline
  list the pairs in a hash table, dictionary, or basic list
 Usage
  pairs x
 Inputs
  x:HashTable
   or @TO Dictionary@ or @TO BasicList@
 Outputs
  L:List
   of all pairs {\tt (k, x#k)}
 Description
  Text
   If {\tt x} is a hash table or dictionary, the pairs consist of
   each key along with its associated value.
  Example
   x = new HashTable from {a => 1, b => 2, c => 3}
   pairs x
  Text
   A dictionary is a special hash table whose keys are strings, 
   and whose values are the corresponding symbols.
  Example
   d = new Dictionary
   getGlobalSymbol (d, "foo")
   getGlobalSymbol (d, "bar")
   pairs d
   first oo
   class \ oo
  Text
   If {\tt x} is a basic list, the pairs consist of each index 
   along with the element at that index in the list.
  Example
   L = {3, 5, 7};
   pairs L
   pairs {apple, banana, carrot}
 Caveat
  As the first example illustrates, pairs are not necessarily listed in
  any particular order.
 SeeAlso
  "hash tables"
  applyPairs
  keys
  scanPairs
  values
  "#"
  "#?"
///

doc ///
 Key
  remove
  (remove, HashTable, Thing)
  (remove, MutableList, ZZ)
  (remove, Database, String)
 Headline
  remove an entry from a mutable hash table, list, or database
 Usage
  remove(T, k)
 Inputs
  T:{HashTable, MutableList, Database}
  k:
    the key to remove (must be @ofClass ZZ@ if @TT "T"@ is a mutable list or
    @ofClass String@ if it is a database)
 Outputs
  :Thing -- the removed value
 Description
  Text
   {\tt remove(T, k)} removes and returns the entry of {\tt T} stored under
   the key {\tt k}.
  Example
   T = new MutableHashTable from {a => 1, b => 2, c => 3}; peek T
   remove(T, a)
   peek T
  Text
   If {\tt T} is not a mutable hash table, an error is thrown.
   One way to remove an entry from an immutable hash table is
   with the function @TO applyPairs@:
  Example
   T = new HashTable from {a => 1, b => 2, c => 3}
   T = applyPairs(T, (k, v) -> if k =!= a then (k, v))
  Text
   @TT "remove"@ works similarly when @TT "T"@ is a database.  See @TO Database@
   for more information.
  Text
    If @TT "T"@ is a mutable list, then @TT "k"@ gives the index of the element
    to be removed.
  Example
    T = new MutableList from {1, 2, 3, 4}; peek T
    remove(T, 0)
    peek T
  Text
    If @TT "k"@ is negative, then the index is determined by counting backwards
    from the end of @TT "T"@.
  Example
    remove(T, -1)
    peek T
 SeeAlso
  applyKeys
  applyPairs
  applyValues
  delete
  drop
  keys
  mutable
  scanKeys
  "hash tables"
///

doc ///
 Key
  scanKeys
  (scanKeys, Database, Function)
  (scanKeys, HashTable, Function)
 Headline
  apply a function to each key in a hash table or database
 Usage
  scanKeys(t, f)
 Inputs
  t:HashTable
   or Database
  f:Function
 Description
  Text
   {\tt scanKeys(t, f)} applies the function {\tt f} to each key
   in the hash table {\tt t}. 
  Example
   t = hashTable {{1,8},{2,20},{3,4},{4,20}}
   scanKeys(t, print)
   scanKeys(t, k -> if k>2 then print t#k)
 Caveat
  This function requires an immutable hash table.  To scan the keys in
  a mutable hash table, use {\tt scan(keys t, f)}.
 SeeAlso
  "hash tables"
  applyKeys
  keys
  scan
  scanPairs
  scanValues
///

doc ///
 Key
  scanPairs
  (scanPairs, HashTable, Function)
 Headline
  apply a function to the pairs in a hash table
 Usage
  scanPairs(t, f)
 Inputs
  t:HashTable
  f:Function
 Description
  Text
   {\tt scanPairs(t, f)} applies the function {\tt f} to each pair
   {\tt (k, t#k)} in the hash table {\tt t}. In other words, {\tt f}
   is applied to each key {\tt k} paired with its corresponding value
   {\tt t#k}.
  Example
   t = hashTable {{1,8},{2,20},{3,4},{4,20}}
   scanPairs(t, (k,v) -> print (k+v))
   scanPairs(t, (k,v) -> if v==20 then print k)   
 Caveat
  This function requires an immutable hash table.  To scan the pairs in
  a mutable hash table, use {\tt scan(pairs t, f)}.
 SeeAlso
  "hash tables"
  applyPairs
  pairs
  scan
  scanKeys
  scanValues
///

doc ///
 Key
  scanValues
  (scanValues, HashTable, Function)
 Headline
  apply a function to each value in a hash table or database
 Usage
  scanValues(t, f)
 Inputs
  t:HashTable
  f:Function
 Description
  Text
   {\tt scanValues(t, f)} applies the function {\tt f} to each value
   in the hash table {\tt t}. 
  Example
   t = hashTable {{1,8},{2,20},{3,4},{4,20}}
   scanValues(t, print)
   scanValues(t, v -> if v>10 then print v)
 Caveat
  This function requires an immutable hash table.  To scan the values in
  a mutable hash table, use {\tt scan(values t, f)}.
 SeeAlso
  "hash tables"
  applyValues
  scan
  scanKeys
  scanPairs
  values
///

doc ///
 Key
  values
  (values, Dictionary)
  (values, HashTable)
 Headline
  values in a hash table
 Usage
  values t
 Inputs
  t:HashTable
 Outputs
  :List
   the values occurring in the hash table {\tt t}
 Description
  Example
   x = new HashTable from {a => 1, b => 2}
   values x
 SeeAlso
  "hash tables"
  applyValues
  keys
  pairs
  scanValues
  "#"
  "#?"
///

doc ///
 Key
  symbol #
 Headline
  length or access to elements
 Description
  Text
   {\tt #} is used as both a unary and a binary operator.
   
   As a unary operator: 
   {\tt #x} returns the length or cardinality of a list, 
   set, hash table, or string {\tt x}. 

   As a binary operator: 
   {\tt x#i} returns the {\tt i}th element of a list, hash table, 
   database, or string {\tt x}.
  Example
   L = {23, 42, 107, 2, 50};
   #L
   L#2
 Caveat
  The precedence of {\tt #} when used as a binary operator is high,
  as high as @TO "."@, but when used as a unary operator the
  precedence is much lower.
 SeeAlso
  "#?"
  (symbol #, BasicList)
  (symbol #, BasicList, ZZ)
  "hash tables"
  "lists and sequences"
///

doc ///
 Key
  (symbol #, BasicList)
  (symbol #, HashTable)
  (symbol #, Set)
  (symbol #, String)
 Headline
  length or cardinality
 Usage
  #x
 Inputs
  x:BasicList
   HashTable, Set, or String
 Outputs
  :ZZ
   the length of {\tt x}
 Description
  Text
   If {\tt x} is a list, {\tt #x} is the number of elements in {\tt x}.
  Example
   L = {1, 2, 3, 2, 1};
   #L
  Text
   If {\tt x} is a set, {\tt #x} is the cardinality of {\tt x}.
  Example
   S = new Set from L 
   #S
  Text
   If {\tt x} is a hash table, {\tt #x} is the number of 
   key-value pairs stored in {\tt x}.
  Example
   T = new HashTable from {a => 1, b => 2}
   #T
  Text
   If {\tt x} is a string, {\tt #x} is the number of characters in {\tt x}.
  Example
   s = "a perfectly adequate example of a string";
   #s
 SeeAlso
  symbol #
  symbol #?
  (symbol #, BasicList, ZZ)
  keys
  pairs
  values
  "hash tables"
  "lists and sequences"
///

doc///
 Key
  (symbol #, BasicList, ZZ)
  (symbol #, Database, String)
  (symbol #, HashTable, Thing)
  (symbol #, String, ZZ)
 Headline
  get value from list, hash table, database, or string
 Usage
  x#i
 Inputs
  x:
   a list, hash table, or string
  i:
   an index or key
 Description
  Text
   If {\tt x} is a list, {\tt x#i} returns the {\tt i}th element of {\tt x}.
   The entries of the list are numbered starting with 0. If {\tt i}
   is negative, then the entries are numbered ending with -1. If {\tt i}
   is out of range, an error is signaled.
  Example
   L = {a, b, c, b, a};
   L#2
   L#-2
  Text
   If {\tt x} is a hash table or database, {\tt x#i} provides the
   value associated with the key {\tt i}.
  Example
   T = new HashTable from {a => 103, b => 89.4, c => 92};
   T#a
   T#b
  Text
   If {\tt x} is a string, {\tt x#i} provides the {\tt i}th character of {\tt x},
   if there is one. Negative indices are counted backward from the end, as with
   lists. If {\tt i} is out of range, an error is thrown.
  Example
   s = "a perfectly adequate example of a string";
   s#2
   s#-2
  Text
   Assignment to {\tt x#i} can change {\tt x} if {\tt x} is mutable.
  Example
   V = new MutableHashTable from T;
   V#a = 5;
   V#d = 22.3;
   peek V
 SeeAlso
  symbol #
  symbol #?
  (symbol #, BasicList)
  (symbol _, VisibleList, ZZ)
  "hash tables"
  "lists and sequences"
///

doc///
 Key
  symbol #?
  (symbol #?, BasicList, ZZ)
  (symbol #?, Database, String)
  (symbol #?, HashTable, Thing)
  (symbol #?, String, ZZ)
 Headline
  check existence of value in a list, hash table, database, or string
 Usage
  x#?i
 Inputs
  x:
   a list, hash table, or string
  i:
   an index or key
 Outputs
  :Boolean
   whether or not {\tt x} contains an element with index or key {\tt i}
 Description
  Text
   If {\tt x} is a list, {\tt x#?i} tells whether there is
   an {\tt i}th element of {\tt x}.
   The entries of the list are numbered starting with 0. If {\tt i}
   is negative, then the entries are numbered ending with -1. 
  Example
   L = {a, b, c, b, a};
   L#?2
   L#?12
  Text
   If {\tt x} is a hash table or database, {\tt x#?i} tells
   whether there is a value associated with the key {\tt i}.
  Example
   T = new HashTable from {a => 103, b => 89.4, c => 92};
   T#?a
   T#?A
  Text
   If {\tt x} is a string, {\tt x#?i} tells if {\tt x} has an
   {\tt i}th character.
  Example
   s = "a perfectly adequate example of a string";
   s#?2
   s#?52
  Text
   {\tt #?} can be very useful in avoiding errors from attempting
   to access nonexistent elements of lists or hash tables. 
 SeeAlso
  symbol #
  (symbol #, BasicList)
  (symbol _, VisibleList, ZZ)
  "hash tables"
  "lists and sequences"
///

document {
     Key => ".",
     Headline => "access to elements whose key is a symbol",
     TT "x.k", " -- the same as ", TT "x#(global k)", ", i.e., treat ", TT "k", " as
     a global symbol and provide the value stored in the hash table ", TT "x", " 
     under the key ", TT "k", ".",
     PARA{},
     "May also be used in an assignment.",
     PARA{},
     EXAMPLE {
	  "x = new MutableHashTable;",
      	  "x.k = 444",
      	  "x.k",
      	  "peek x",
	  },
     SeeAlso => {"#", ".?", "global"}
     }
document {
     Key => ".?",
     Headline => "check for presence of elements whose key is a symbol",
     TT "x.?k", " -- the same as ", TT "x#?(global k)", ", tells whether a value is
     available with ", TT "x.k", ".",
     PARA{},
     SeeAlso =>{ ".", "#?" }
     }

document {
     Key => hash,
     Headline => "hash code of an object",
     Usage => "hash x",
     Inputs => { "x" => Thing },
     Outputs => { ZZ => { "the hash code of ", TT "x" } },
     PARA{
	  "The hash code of ", TT "x", " is an integer produced in a deterministic way
	  from ", TT "x", ", and perhaps from the hash codes of the contents of ", TT "x", ".
	  See ", TO "hashing", " for a discussion of the requirements that
	  the hash codes used here are designed to satisfy."
	  },
     PARA {
	  "Hash codes may change from one version of Macaulay2 to the next, but changes to the hash codes
	  of the basic types will be avoided, if possible.  That includes lists, sequences, strings, hash 
	  tables, options, Boolean values, and numbers."
	  }
     }