Changeset 321c9b in git
- Timestamp:
- Jul 9, 2019, 1:09:57 PM (5 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- b4cbc239fe58d1eb1df8cf159cc5216476421e53
- Parents:
- e2ce0cc505caa119e486a0c44578da7fd5a4c423
- git-author:
- Andreas Steenpass <steenpass@mathematik.uni-kl.de>2019-07-09 13:09:57+02:00
- git-committer:
- Andreas Steenpass <steenpass@mathematik.uni-kl.de>2019-07-15 12:51:16+02:00
- Location:
- Singular/LIB
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/ring.lib
re2ce0c r321c9b 41 41 addvarsTo(r,vars,i) add variables to a ring 42 42 addNvarsTo(r,N,name,i) add N variables to a ring 43 create_ring(l1,l2,l3,l4) return ring(list(l1, l2, l3, l4))44 43 "; 45 44 … … 1335 1334 rr; 1336 1335 } 1337 1338 ///////////////////////////////////////////////////////////////////////////////1339 // replacement for ring declarations via execute()1340 ///////////////////////////////////////////////////////////////////////////////1341 1342 /*1343 * parses1344 * "(v1,v2,v3,v4,v5)" to list("v1", "v2", "v3", "v4", "v5"),1345 * "(dp(3), a(1,2,3), ds(3))" to list("dp(3)", "a(1,2,3)", "ds(3)"), and1346 * "(1,2,3,4)" to list("1", "2", "3", "4")1347 */1348 static proc tuple_to_tokens(string s)1349 {1350 list L;1351 int index = 1;1352 int curr = 2;1353 while (s[curr] == " ")1354 {1355 curr++;1356 }1357 int next = find(s, ",", curr+1);1358 int b = find(s, "(", curr+1);1359 if (b != 0 && b < next)1360 {1361 next = find(s, ",", find(s, ")", b+1)+1);1362 }1363 while (next != 0)1364 {1365 L[index] = string(s[curr, next-curr]);1366 index++;1367 curr = next+1;1368 while (s[curr] == " ")1369 {1370 curr++;1371 }1372 next = find(s, ",", curr+1);1373 b = find(s, "(", curr+1);1374 if (b != 0 && b < next)1375 {1376 next = find(s, ",", find(s, ")", b+1)+1);1377 }1378 }1379 L[index] = string(s[curr, size(s)-curr]);1380 return(L);1381 }1382 1383 /*1384 * parses1385 * "0" and "(0)" to 0,1386 * "32003" and "(32003)" to 32003, and1387 * "(32003,a,b,c)" to1388 * list(32003, list("a", "b", "c"), list(list("lp", 1:3)), ideal(0))1389 */1390 static proc parse_L1(string l1)1391 {1392 if (find(l1, "(", 1) == 0) // no parentheses1393 {1394 return(int(l1));1395 }1396 list tokens = tuple_to_tokens(l1);1397 if (size(tokens) == 1)1398 {1399 return(int(tokens[1]));1400 }1401 list L = int(tokens[1]);1402 L[2] = list(tokens[2..size(tokens)]);1403 L[3] = list(list("lp", 1:(size(tokens)-1)));1404 L[4] = ideal(0);1405 return(L);1406 }1407 1408 static proc parse_var(string v)1409 {1410 if (v[1, 4] == "var(" && defined(basering))1411 {1412 int i = int(v[5,size(v)-5]);1413 v = ringlist(basering)[2][i];1414 }1415 return(v);1416 }1417 1418 /*1419 * parses1420 * "x" to list("x") and1421 * "(x,y,z)" to list("x", "y", "z")1422 */1423 static proc parse_L2(string l2)1424 {1425 if (find(l2, "(", 1) == 0) // no parentheses1426 {1427 return(list(parse_var(l2)));1428 }1429 list V = tuple_to_tokens(l2);1430 for (int i = size(V); i > 0; i--)1431 {1432 V[i] = parse_var(V[i]);1433 }1434 return(V);1435 }1436 1437 /*1438 * parses1439 * "dp" to list("dp", 1:n_vars),1440 * "dp(3)" to list("dp", 1:3),1441 * "c" to list("c", intvec(0)), and1442 * "wp(3,4)" to list("wp", intvec(3, 4))1443 */1444 static proc parse_ordering(string ordering, int n_vars)1445 {1446 string name;1447 intvec w;1448 int b1 = find(ordering, "(", 1);1449 if (b1 == 0) // no parentheses1450 {1451 name = ordering;1452 if (name == "C" || name == "c")1453 {1454 w = intvec(0);1455 }1456 else1457 {1458 w = 1:n_vars;1459 }1460 }1461 else1462 {1463 name = ordering[1, b1-1];1464 int b2 = find(ordering, ")", b1+1);1465 int c = find(ordering, ",", b1+1);1466 if (c == 0)1467 {1468 w = 1:int(ordering[b1+1, b2-b1-1]);1469 }1470 else1471 {1472 list W = tuple_to_tokens(ordering[b1, b2-b1+1]);1473 w = intvec(int(W[1..size(W)]));1474 }1475 }1476 return(list(name, w));1477 }1478 1479 static proc parse_L3(string l3, int n_vars)1480 {1481 if (l3[1] != "(")1482 {1483 list L = parse_ordering(l3, n_vars);1484 return(list(L));1485 }1486 // block orderings1487 list L = tuple_to_tokens(l3);1488 for (int i = size(L); i > 0; i--)1489 {1490 L[i] = parse_ordering(L[i], n_vars);1491 }1492 return(L);1493 }1494 1495 proc create_ring(def l1, def l2, def l3, list #)1496 "USAGE: create_ring(l1, l2, l3[, l4, \"no_minpoly\"]);1497 l1 int or list, l2 list or string, l3 list or string, l4 ideal1498 RETURN: ring(list(l1, l2, l3, l4))1499 NOTE: l1, l2, l3, l4 are assumed to be the four entries of ringlist(R)1500 where R is the ring to be returned.1501 @* Optional arguments: If l4 is not given, it is assumend to be1502 ideal(0). If \"no_minpoly\" is given, then the minimal polynomial1503 in l1, if present, is set to 0.1504 @* Shortcuts: Strings such as \"0\", \"(32003)\" or \"(0,a,b,c)\" can1505 be given as l1. Indexed parameters as in \"(0,a(1..3))\" are1506 not supported. Strings such as \"(x,y,z)\" can be given as l2.1507 Indexed variables as in \"(x(1..3),y,z)\" are not supported.1508 Strings representing orderings such as \"dp\" or \"(lp(3), ds(2))\"1509 can be given as l3, except matrix orderings given by1510 \"M([intmat_expression])\".1511 EXAMPLE: example create_ring; shows an example1512 "1513 {1514 /* setup */1515 list L;1516 int kill_ring;1517 if (!defined(basering))1518 {1519 ring R;1520 kill_ring = 1;1521 }1522 1523 /* read optional arguments */1524 ideal l4;1525 int no_minpoly;1526 if (size(#) > 0)1527 {1528 if (typeof(#[1]) == "ideal")1529 {1530 ideal l4 = #[1];1531 # = delete(#, 1);1532 }1533 if (typeof(#[1]) == "string")1534 {1535 if (#[1] == "no_minpoly")1536 {1537 no_minpoly = 1;1538 }1539 }1540 }1541 1542 /* L[1] */1543 if (typeof(l1) == "list")1544 {1545 if (no_minpoly)1546 {1547 if (typeof(l1) == "list")1548 {1549 if (size(l1) == 4)1550 {1551 if (typeof(l1[4]) == "ideal")1552 {1553 l1[4] = ideal(0);1554 }1555 }1556 }1557 }1558 }1559 if (typeof(l1) == "list" || typeof(l1) == "int")1560 {1561 L[1] = l1;1562 }1563 else1564 {1565 L[1] = parse_L1(l1);1566 }1567 1568 /* L[2] */1569 if (typeof(l2) == "list")1570 {1571 L[2] = l2;1572 }1573 else1574 {1575 L[2] = parse_L2(l2);1576 }1577 1578 /* L[3] */1579 if (typeof(l3) == "list")1580 {1581 L[3] = l3;1582 }1583 else1584 {1585 L[3] = parse_L3(l3, size(L[2]));1586 }1587 1588 /* L[4] */1589 L[4] = l4;1590 1591 /* return ring */1592 def S = ring(L);1593 if (kill_ring)1594 {1595 kill(R);1596 }1597 return(S);1598 }1599 example1600 {1601 "EXAMPLE:"; echo = 2;1602 ring R = (0,a), x, lp;1603 minpoly = a^2+1;1604 qring Q = ideal(x^3-2);1605 ring S = create_ring(ringlist(Q)[1], "(x,y,t)", "dp", "no_minpoly");1606 basering;1607 } -
Singular/LIB/standard.lib
re2ce0c r321c9b 19 19 max(i_1,...,i_k) maximum of i_1, ..., i_k 20 20 min(i_1,...,i_k) minimum of i_1, ..., i_k 21 create_ring(l1,l2,l3,l4) return ring(list(l1, l2, l3, l4)) 21 22 22 23 "; … … 24 25 // hilbRing([i]) ring for computing the (weighted) hilbert series 25 26 // quotientList(L,...) ringlist for creating a correct quotient ring 26 27 LIB "ring.lib";28 27 29 28 ////////////////////////////////////////////////////////////////////////////// … … 2463 2462 //exportto(Top,pagelength); 2464 2463 } 2464 2465 /////////////////////////////////////////////////////////////////////////////// 2466 // replacement for ring declarations via execute() 2467 /////////////////////////////////////////////////////////////////////////////// 2468 2469 /* 2470 * parses 2471 * "(v1,v2,v3,v4,v5)" to list("v1", "v2", "v3", "v4", "v5"), 2472 * "(dp(3), a(1,2,3), ds(3))" to list("dp(3)", "a(1,2,3)", "ds(3)"), and 2473 * "(1,2,3,4)" to list("1", "2", "3", "4") 2474 */ 2475 static proc tuple_to_tokens(string s) 2476 { 2477 list L; 2478 int index = 1; 2479 int curr = 2; 2480 while (s[curr] == " ") 2481 { 2482 curr++; 2483 } 2484 int next = find(s, ",", curr+1); 2485 int b = find(s, "(", curr+1); 2486 if (b != 0 && b < next) 2487 { 2488 next = find(s, ",", find(s, ")", b+1)+1); 2489 } 2490 while (next != 0) 2491 { 2492 L[index] = string(s[curr, next-curr]); 2493 index++; 2494 curr = next+1; 2495 while (s[curr] == " ") 2496 { 2497 curr++; 2498 } 2499 next = find(s, ",", curr+1); 2500 b = find(s, "(", curr+1); 2501 if (b != 0 && b < next) 2502 { 2503 next = find(s, ",", find(s, ")", b+1)+1); 2504 } 2505 } 2506 L[index] = string(s[curr, size(s)-curr]); 2507 return(L); 2508 } 2509 2510 /* 2511 * parses 2512 * "0" and "(0)" to 0, 2513 * "32003" and "(32003)" to 32003, and 2514 * "(32003,a,b,c)" to 2515 * list(32003, list("a", "b", "c"), list(list("lp", 1:3)), ideal(0)) 2516 */ 2517 static proc parse_L1(string l1) 2518 { 2519 if (find(l1, "(", 1) == 0) // no parentheses 2520 { 2521 return(int(l1)); 2522 } 2523 list tokens = tuple_to_tokens(l1); 2524 if (size(tokens) == 1) 2525 { 2526 return(int(tokens[1])); 2527 } 2528 list L = int(tokens[1]); 2529 L[2] = list(tokens[2..size(tokens)]); 2530 L[3] = list(list("lp", 1:(size(tokens)-1))); 2531 L[4] = ideal(0); 2532 return(L); 2533 } 2534 2535 static proc parse_var(string v) 2536 { 2537 if (v[1, 4] == "var(" && defined(basering)) 2538 { 2539 int i = int(v[5,size(v)-5]); 2540 v = ringlist(basering)[2][i]; 2541 } 2542 return(v); 2543 } 2544 2545 /* 2546 * parses 2547 * "x" to list("x") and 2548 * "(x,y,z)" to list("x", "y", "z") 2549 */ 2550 static proc parse_L2(string l2) 2551 { 2552 if (find(l2, "(", 1) == 0) // no parentheses 2553 { 2554 return(list(parse_var(l2))); 2555 } 2556 list V = tuple_to_tokens(l2); 2557 for (int i = size(V); i > 0; i--) 2558 { 2559 V[i] = parse_var(V[i]); 2560 } 2561 return(V); 2562 } 2563 2564 /* 2565 * parses 2566 * "dp" to list("dp", 1:n_vars), 2567 * "dp(3)" to list("dp", 1:3), 2568 * "c" to list("c", intvec(0)), and 2569 * "wp(3,4)" to list("wp", intvec(3, 4)) 2570 */ 2571 static proc parse_ordering(string ordering, int n_vars) 2572 { 2573 string name; 2574 intvec w; 2575 int b1 = find(ordering, "(", 1); 2576 if (b1 == 0) // no parentheses 2577 { 2578 name = ordering; 2579 if (name == "C" || name == "c") 2580 { 2581 w = intvec(0); 2582 } 2583 else 2584 { 2585 w = 1:n_vars; 2586 } 2587 } 2588 else 2589 { 2590 name = ordering[1, b1-1]; 2591 int b2 = find(ordering, ")", b1+1); 2592 int c = find(ordering, ",", b1+1); 2593 if (c == 0) 2594 { 2595 w = 1:int(ordering[b1+1, b2-b1-1]); 2596 } 2597 else 2598 { 2599 list W = tuple_to_tokens(ordering[b1, b2-b1+1]); 2600 w = intvec(int(W[1..size(W)])); 2601 } 2602 } 2603 return(list(name, w)); 2604 } 2605 2606 static proc parse_L3(string l3, int n_vars) 2607 { 2608 if (l3[1] != "(") 2609 { 2610 list L = parse_ordering(l3, n_vars); 2611 return(list(L)); 2612 } 2613 // block orderings 2614 list L = tuple_to_tokens(l3); 2615 for (int i = size(L); i > 0; i--) 2616 { 2617 L[i] = parse_ordering(L[i], n_vars); 2618 } 2619 return(L); 2620 } 2621 2622 proc create_ring(def l1, def l2, def l3, list #) 2623 "USAGE: create_ring(l1, l2, l3[, l4, \"no_minpoly\"]); 2624 l1 int or list, l2 list or string, l3 list or string, l4 ideal 2625 RETURN: ring(list(l1, l2, l3, l4)) 2626 NOTE: l1, l2, l3, l4 are assumed to be the four entries of ringlist(R) 2627 where R is the ring to be returned. 2628 @* Optional arguments: If l4 is not given, it is assumend to be 2629 ideal(0). If \"no_minpoly\" is given, then the minimal polynomial 2630 in l1, if present, is set to 0. 2631 @* Shortcuts: Strings such as \"0\", \"(32003)\" or \"(0,a,b,c)\" can 2632 be given as l1. Indexed parameters as in \"(0,a(1..3))\" are 2633 not supported. Strings such as \"(x,y,z)\" can be given as l2. 2634 Indexed variables as in \"(x(1..3),y,z)\" are not supported. 2635 Strings representing orderings such as \"dp\" or \"(lp(3), ds(2))\" 2636 can be given as l3, except matrix orderings given by 2637 \"M([intmat_expression])\". 2638 EXAMPLE: example create_ring; shows an example 2639 " 2640 { 2641 /* setup */ 2642 list L; 2643 int kill_ring; 2644 if (!defined(basering)) 2645 { 2646 ring R; 2647 kill_ring = 1; 2648 } 2649 2650 /* read optional arguments */ 2651 ideal l4; 2652 int no_minpoly; 2653 if (size(#) > 0) 2654 { 2655 if (typeof(#[1]) == "ideal") 2656 { 2657 ideal l4 = #[1]; 2658 # = delete(#, 1); 2659 } 2660 if (typeof(#[1]) == "string") 2661 { 2662 if (#[1] == "no_minpoly") 2663 { 2664 no_minpoly = 1; 2665 } 2666 } 2667 } 2668 2669 /* L[1] */ 2670 if (typeof(l1) == "list") 2671 { 2672 if (no_minpoly) 2673 { 2674 if (typeof(l1) == "list") 2675 { 2676 if (size(l1) == 4) 2677 { 2678 if (typeof(l1[4]) == "ideal") 2679 { 2680 l1[4] = ideal(0); 2681 } 2682 } 2683 } 2684 } 2685 } 2686 if (typeof(l1) == "list" || typeof(l1) == "int") 2687 { 2688 L[1] = l1; 2689 } 2690 else 2691 { 2692 L[1] = parse_L1(l1); 2693 } 2694 2695 /* L[2] */ 2696 if (typeof(l2) == "list") 2697 { 2698 L[2] = l2; 2699 } 2700 else 2701 { 2702 L[2] = parse_L2(l2); 2703 } 2704 2705 /* L[3] */ 2706 if (typeof(l3) == "list") 2707 { 2708 L[3] = l3; 2709 } 2710 else 2711 { 2712 L[3] = parse_L3(l3, size(L[2])); 2713 } 2714 2715 /* L[4] */ 2716 L[4] = l4; 2717 2718 /* return ring */ 2719 def S = ring(L); 2720 if (kill_ring) 2721 { 2722 kill(R); 2723 } 2724 return(S); 2725 } 2726 example 2727 { 2728 "EXAMPLE:"; echo = 2; 2729 ring R = (0,a), x, lp; 2730 minpoly = a^2+1; 2731 qring Q = ideal(x^3-2); 2732 ring S = create_ring(ringlist(Q)[1], "(x,y,t)", "dp", "no_minpoly"); 2733 basering; 2734 }
Note: See TracChangeset
for help on using the changeset viewer.