Changeset ec37c7 in git


Ignore:
Timestamp:
May 16, 2019, 2:40:22 PM (5 years ago)
Author:
Andreas Steenpass <steenpass@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
6c443d2e7ddf6100ffb70f9a46905d75df833663
Parents:
4e5fdad42de8a0a52366ead81619a2e027f2a8ef
git-author:
Andreas Steenpass <steenpass@mathematik.uni-kl.de>2019-05-16 14:40:22+02:00
git-committer:
Andreas Steenpass <steenpass@mathematik.uni-kl.de>2019-05-16 14:46:15+02:00
Message:
add create_ring() to ring.lib
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/ring.lib

    r4e5fda rec37c7  
    4141 addvarsTo(r,vars,i)      add variables to a ring
    4242 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))
    4344";
    4445
     
    13341335  rr;
    13351336}
     1337
     1338///////////////////////////////////////////////////////////////////////////////
     1339//   replacement for ring declarations via execute()
     1340///////////////////////////////////////////////////////////////////////////////
     1341
     1342/*
     1343 * parses "(v1,v2,v3,v4,v5)" to list("v1", "v2", "v3", "v4", "v5")
     1344 */
     1345static proc parse_L2(string l2)
     1346{
     1347  list V;
     1348  int index = 1;
     1349  int curr = 2;
     1350  int next = find(l2, ",", curr+1);
     1351  while (next != 0)
     1352  {
     1353    V[index] = l2[curr..(next-1)];
     1354    index++;
     1355    curr = next+1;
     1356    next = find(l2, ",", curr+1);
     1357  }
     1358  V[index] = l2[curr..(size(l2)-1)];
     1359  return(V);
     1360}
     1361
     1362static proc parse_L3(string l3, int n_vars)
     1363{
     1364  list L =  list(list(l3, intvec(n_vars)), list("C", intvec(0)));
     1365  return(L);
     1366}
     1367
     1368proc create_ring(def l1, def l2, def l3, list #)
     1369"USAGE:  create_ring(l1, l2, l3[, l4, \"no_minpoly\"]);
     1370         l1 int or list, l2 list or string, l3 list or string, l4 ideal
     1371RETURN:  ring(list(l1, l2, l3, l4))
     1372NOTE:    l1, l2, l3, l4 are assumed to be the four entries of ringlist(R)
     1373         where R is the ring to be returned.
     1374         @* Optional arguments: If l4 is not given, it is assumend to be
     1375         ideal(0). If \"no_minpoly\" is given, then the minimal polynomial
     1376         in l1, if present, is set to 0.
     1377         @* Shortcuts: Strings such as \"(x,y,z)\" can be given as l2.
     1378         Indexed variables as in \"(x(1..3),y,z)\" are not supported.
     1379         Strings representing simple orderings such as \"dp\" or \"lp\" can
     1380         be given as l3, but more complicated cases such as \"(c,dp)\" are
     1381         not supported.
     1382EXAMPLE: example create_ring; shows an example
     1383"
     1384{
     1385  /* setup */
     1386  list L;
     1387  int kill_ring;
     1388  if (!defined(basering))
     1389  {
     1390    ring R;
     1391    kill_ring = 1;
     1392  }
     1393
     1394  /* read optional arguments */
     1395  ideal l4;
     1396  int no_minpoly;
     1397  if (size(#) > 0)
     1398  {
     1399    if (typeof(#[1]) == "ideal")
     1400    {
     1401      ideal l4 = #[1];
     1402      # = delete(#, 1);
     1403    }
     1404    if (typeof(#[1]) == "string")
     1405    {
     1406      if (#[1] == "no_minpoly")
     1407      {
     1408        no_minpoly = 1;
     1409      }
     1410    }
     1411  }
     1412
     1413  /* L[1] */
     1414  if (no_minpoly)
     1415  {
     1416    if (typeof(l1) == "list")
     1417    {
     1418      if (size(l1) == 4)
     1419      {
     1420        if (typeof(l1[4]) == "ideal")
     1421        {
     1422          l1[4] = ideal(0);
     1423        }
     1424      }
     1425    }
     1426  }
     1427  L[1] = l1;
     1428
     1429  /* L[2] */
     1430  if (typeof(l2) == "list")
     1431  {
     1432    L[2] = l2;
     1433  }
     1434  else
     1435  {
     1436    L[2] = parse_L2(l2);
     1437  }
     1438
     1439  /* L[3] */
     1440  if (typeof(l3) == "list")
     1441  {
     1442    L[3] = l3;
     1443  }
     1444  else
     1445  {
     1446    L[3] = parse_L3(l3, size(L[2]));
     1447  }
     1448
     1449  /* L[4] */
     1450  L[4] = l4;
     1451
     1452  /* return ring */
     1453  def S = ring(L);
     1454  if (kill_ring)
     1455  {
     1456    kill(R);
     1457  }
     1458  return(S);
     1459}
     1460example
     1461{
     1462  "EXAMPLE:"; echo = 2;
     1463  ring R = (0,a), x, lp;
     1464  minpoly = a^2+1;
     1465  qring Q = ideal(x^3-2);
     1466  ring S = create_ring(ringlist(Q)[1], "(x,y,t)", "dp", "no_minpoly");
     1467  basering;
     1468}
Note: See TracChangeset for help on using the changeset viewer.