How to present on GAP a set with given conditions

66 Views Asked by At

Let there be given a set $X$ of triples of nonnegative integers $(A,V,R)$. How to find set PS of triples of nonnegative integers $(p,q,r)$ satisfying the following conditions:

  1. If $(p,q,r) \in PS, p \gt 0$ then $(p-1,q,r) \in PS$,
  2. If $(p,q,r) \in PS, q\gt 0$ then $(p,q-1,r) \in PS$,
  3. If $(p,q,r) \in PS, r\gt 0$ then $(p,q,r-1) \in PS$,
  4. $(A-1,0,0) (0,V-1,0), (0,0,R-1) \in PS $,
  5. $(A,0,0) (0,V,0), (0,0,R) \notin PS $,

How to present fifth condition? I proved with if condition but it doesnt work

gap> PS:=[]; [ ] gap> for p in [0..10] do

for q in [0..10] do

for r in [0..10] do

AddSet(PS,[p,q,r]);

od;

od;

od;

gap> if [10, 0,0] not in PS and [0, 10,0] not in PS and [0, 0,10]not in PS then

Syntax error: then expected if [10, 0,0] not in PS and [0, 10,0] not in PS and [0, 0,10]not in PS then ^^^

Also I tried on this way

gap> SubstractSet(PS,[[10,0,0],[0,10,0],[0,0,10]]); set;

Error, Variable: 'SubstractSet' must have a value not in any function at stdin:9

1

There are 1 best solutions below

3
On

There are two problems with your code.

The first is GAP syntax. You cannot simply run over tuples (well, one could iterate over CartesianProduct, but lets leave that aside), but needs to run for each component separately. Also one needs to indicate the scope for each variable. Your for loop thus should look like (I'm picking the range $0\ldots10$ arbitrarily, presumably these are your $A$, $V$, $R$:

for p in [0..10] do
  for q in [0..10] do
    for r in [0..10] do
    ...
    od;
  od;
od;

The second problem is that your condition is recursive -- that is for a given triple $p,q,r$ you require further triples, and these require further triples again. I suspect the while loop is intended to catch this, but doesn't realy -- this will not work.

One could code this condition recursively, but that likely will end up with highly inefficient code. Basically this needs fundamental rethinking of the strategy.

Given that you want three points, $(A-1,0,0)$ etc. in your code, I would simply write a routine that for a given point as input adds the dependent "cone" (the $p-1$'s etc.) to the set. You then call this routine for the three points you require.

(Likely you will want more points, since otherwise you simply will get the set $$ \{(p,0,0),(0,q,0),(0,r,0)\mid 0\le p<A, 0\le q<V, 0\le r<R\} $$ that is not very interesting.)