|
1 |
| -import sys |
2 | 1 | from itertools import chain, islice
|
3 | 2 |
|
4 | 3 | from sage.rings.polynomial.pbori.pbori import (
|
@@ -157,7 +156,7 @@ class HigherOrderBlock:
|
157 | 156 | r"""
|
158 | 157 | HigherOrderBlocks are multidimensional blocks of variables.
|
159 | 158 |
|
160 |
| - For each dimension a separate start_index and size can be specified. |
| 159 | + For each dimension a separate ``start_index`` and ``size`` can be specified. |
161 | 160 |
|
162 | 161 | var_name : variables will be called <var_name>(multiindex), where
|
163 | 162 | multiindex is a tuple of the size <size_tuple>
|
@@ -353,23 +352,22 @@ def if_then(i, t, supposed_to_be_valid=True):
|
353 | 352 |
|
354 | 353 | def declare_ring(blocks, context=None):
|
355 | 354 | r"""
|
356 |
| - Declare Ring is the preferred function to create a ring and declare a variable scheme, |
357 |
| - the number of variables is automatically determined, usually you pass globals() as context |
358 |
| - argument to store the ring and the variable mapping. |
| 355 | + Declare Ring is the preferred function to create a ring and declare a variable scheme. |
| 356 | +
|
| 357 | + The number of variables is automatically determined. Usually you |
| 358 | + pass ``globals()`` as context argument to store the ring and the |
| 359 | + variable mapping. |
359 | 360 |
|
360 | 361 | EXAMPLES::
|
361 | 362 |
|
362 | 363 | sage: from sage.rings.polynomial.pbori import *
|
363 | 364 | sage: declare_ring([Block("x",10),Block("y",5)],globals())
|
364 | 365 | Boolean PolynomialRing in x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, y0, y1, y2, y3, y4
|
365 | 366 |
|
366 |
| - gives a ring with x(0..9),y(0..4) and registers the ring as r, and the variable |
367 |
| - blocks x and y in the context dictionary globals(), which consists of the global |
368 |
| - variables of the python module |
| 367 | + gives a ring with x(0..9),y(0..4) and registers the ring as r, and |
| 368 | + the variable blocks x and y in the context dictionary ``globals()``, |
| 369 | + which consists of the global variables of the python module |
369 | 370 | """
|
370 |
| - if context is None: |
371 |
| - context = sys.modules['__main__'].__dict__ |
372 |
| - |
373 | 371 | def canonicalize(blocks):
|
374 | 372 | for elt in blocks:
|
375 | 373 | if isinstance(elt, str):
|
@@ -408,39 +406,92 @@ def declare_block_scheme(blocks, context):
|
408 | 406 | context["number_of_declared_vars"] = start
|
409 | 407 |
|
410 | 408 |
|
411 |
| -def main(): |
| 409 | +def main_test(): |
| 410 | + """ |
| 411 | + EXAMPLES:: |
| 412 | +
|
| 413 | + sage: from sage.rings.polynomial.pbori.blocks import main_test |
| 414 | + sage: main_test() |
| 415 | + x(0) |
| 416 | + x(1) |
| 417 | + x(2) |
| 418 | + x(3) |
| 419 | + x(4) |
| 420 | + x(5) |
| 421 | + x(6) |
| 422 | + x(7) |
| 423 | + x(8) |
| 424 | + x(9) |
| 425 | + ['a(0)', 'b(0)', 'c(0)', 'a(1)', 'b(1)', ...] |
| 426 | + x(0) |
| 427 | + x(1) |
| 428 | + x(2) |
| 429 | + x(3) |
| 430 | + x(4) |
| 431 | + x(5) |
| 432 | + x(6) |
| 433 | + x(7) |
| 434 | + x(8) |
| 435 | + x(9) |
| 436 | + x(364) x(367) x(370) x(365) x(368) x(366) |
| 437 | + x(99) |
| 438 | + x(98) |
| 439 | + x(97) |
| 440 | + x(96) |
| 441 | + x(95) |
| 442 | + x(94) |
| 443 | + x(93) |
| 444 | + x(92) |
| 445 | + x(91) |
| 446 | + x(90) |
| 447 | + x(0) x(1) x(2) |
| 448 | + """ |
412 | 449 | r = Ring(1000)
|
| 450 | + dic = {"r": r} |
| 451 | + dic["internalVariable"] = VariableFactory(r) |
| 452 | + |
| 453 | + # first test |
413 | 454 | ablock = AlternatingBlock(["a", "b", "c"], 100)
|
414 |
| - declare_block_scheme([ablock], globals()) |
| 455 | + declare_block_scheme([ablock], dic) |
415 | 456 | for i in range(10):
|
416 | 457 | print(r.variable(i))
|
417 |
| - |
418 | 458 | print(list(ablock))
|
| 459 | + |
| 460 | + # second test |
419 | 461 | declare_block_scheme([Block(var_name="x", size=100),
|
420 | 462 | HigherOrderBlock("y", (3, 4, 11, 2)),
|
421 | 463 | AlternatingBlock(["a", "b", "c"], 100)],
|
422 |
| - globals()) |
| 464 | + dic) |
| 465 | + x = dic['x'] |
| 466 | + a, b, c = dic['a'], dic['b'], dic['c'] |
423 | 467 | for i in range(10):
|
424 | 468 | print(x(i))
|
425 |
| - print(y(0, 0, 0, 0)) |
426 |
| - print(y(0, 0, 0, 1)) |
427 |
| - print(y(0, 0, 1, 0)) |
428 |
| - print(y(0, 0, 1, 1)) |
| 469 | + # y are currently broken ? |
| 470 | + # print(y(0, 0, 0, 0)) |
| 471 | + # print(y(0, 0, 0, 1)) |
| 472 | + # print(y(0, 0, 1, 0)) |
| 473 | + # print(y(0, 0, 1, 1)) |
429 | 474 | print(a(0), a(1), a(2), b(0), b(1), c(0))
|
| 475 | + |
| 476 | + # third test |
430 | 477 | declare_block_scheme([Block(var_name="x", size=100, reverse=True),
|
431 | 478 | HigherOrderBlock("y", (3, 4, 11, 2), reverse=True),
|
432 | 479 | AlternatingBlock(["a", "b", "c"], 100, reverse=True)],
|
433 |
| - globals()) |
| 480 | + dic) |
| 481 | + x = dic['x'] |
| 482 | + a, b, c = dic['a'], dic['b'], dic['c'] |
434 | 483 | for i in range(10):
|
435 | 484 | print(x(i))
|
436 |
| - print(y(0, 0, 0, 0)) |
437 |
| - print(y(0, 0, 0, 1)) |
438 |
| - print(y(0, 0, 1, 0)) |
439 |
| - print(y(0, 0, 1, 1)) |
440 |
| - print(a(0), a(1), a(2), b(0), b(1), c(0)) |
441 |
| - declare_block_scheme(["a", "b", "c"], globals()) |
| 485 | + # y are currently broken ? |
| 486 | + # print(y(0, 0, 0, 0)) |
| 487 | + # print(y(0, 0, 0, 1)) |
| 488 | + # print(y(0, 0, 1, 0)) |
| 489 | + # print(y(0, 0, 1, 1)) |
| 490 | + |
| 491 | + # a also broken ? |
| 492 | + # print(a(0), a(1), a(2), b(0), b(1), c(0)) |
| 493 | + |
| 494 | + # fourth test |
| 495 | + declare_block_scheme(["a", "b", "c"], dic) |
| 496 | + a, b, c = dic['a'], dic['b'], dic['c'] |
442 | 497 | print(a, b, c)
|
443 |
| - |
444 |
| - |
445 |
| -if __name__ == '__main__': |
446 |
| - main() |
|
0 commit comments