<html><head><title>[CRISP] 2 Set theoretical classes</title></head>
<body text="#000000" bgcolor="#ffffff">
[<a href = "chapters.htm">Up</a>] [<a href ="CHAP001.htm">Previous</a>] [<a href ="CHAP003.htm">Next</a>] [<a href = "theindex.htm">Index</a>]
<h1>2 Set theoretical classes</h1><p>
<P>
<H3>Sections</H3>
<oL>
<li> <A HREF="CHAP002.htm#SECT001">Creating set theoretical classes</a>
<li> <A HREF="CHAP002.htm#SECT002">Properties of classes</a>
<li> <A HREF="CHAP002.htm#SECT003">Lattice operations for classes</a>
</ol><p>
<p>
In <font face="Gill Sans,Helvetica,Arial">CRISP</font>, a class (in the set-theoretical sense) is usually represented
by an algorithm which decides membership in that class. Wherever this makes
sense, sets (see <a href="../../../doc/ref/chap30.html#X7E399AC97FD98217">Set</a>) may also be used as classes.
<p>
<p>
<h2><a name="SECT001">2.1 Creating set theoretical classes</a></h2>
<p><p>
<a name = "I0"></a>
<a name = "SSEC001.1"></a>
<li><code>IsClass(</code><var>C</var><code>) C</code>
<p>
returns true if <var>C</var> is a class object. The category of class objects is a
subcategory of the category <code>IsListOrCollection</code>.
<p>
<a name = "SSEC001.2"></a>
<li><code>Class(</code><var>rec</var><code>) O</code>
<li><code>Class(</code><var>func</var><code>) O</code>
<p>
returns a class <var>C</var>. In the first form, <var>rec</var> must be a record having a
component <code>\in</code> and an optional component <code>name</code>. The values of these
components, if present, are bound to the attributes <code>MemberFunction</code> and
<code>Name</code> (see <a href="../../../doc/ref/chap12.html#X7F14EF9D81432113">Name</a>) of the class created. The value bound to <code>\in</code> must be a function
<var>func</var> which returns <code>true</code> if a <font face="Gill Sans,Helvetica,Arial">GAP</font> object belongs to <var>C</var>, and <code>false</code>
otherwise; cf. <a href="CHAP002.htm#SSEC002.2">MemberFunction</a> below. The second form is equivalent to <code>Class(rec(\in
:= </code><var>func</var><code>))</code>. It is the user's responsibility to ensure that func returns the same
result for different <font face="Gill Sans,Helvetica,Arial">GAP</font> objects representing the same mathematical object (or
element, in the <font face="Gill Sans,Helvetica,Arial">GAP</font> sense; see <a href="../../../doc/ref/chap12.html#X86710F997832ABA4">Objects and Elements</a> in the <font face="Gill Sans,Helvetica,Arial">GAP</font>
reference manual).
<p>
<pre>
gap> FermatPrimes := Class(p -> IsPrime(p) and p = 2^LogInt(p, 2) + 1);
Class(in:=function( p ) ... end)
</pre>
<p>
<a name = "SSEC001.3"></a>
<li><code>View(</code><var>class</var><code>)</code>
<p>
If the class does not have a name, this produces a brief description of the
information defining <var>class</var> which has been supplied by the user. If the
class has a name, only its name will be printed.
<p>
<pre>
gap> View(FermatPrimes);
Class(in:=function( p ) ... end)
</pre>
<p>
<a name = "SSEC001.4"></a>
<li><code>Print(</code><var>class</var><code>)</code>
<p>
<code>Print</code> behaves very similarly to <code>View</code>, except that the defining
information is being printed in a more explicit way if possible.
<p>
<pre>
gap> Print(FermatPrimes);
Class(rec( in = function( p )
return IsPrime( p ) and p = 2 ^ LogInt( p, 2 ) + 1;
end))
</pre>
<p>
<a name = "SSEC001.5"></a>
<li><code>Display(</code><var>class</var><code>)</code>
<p>
For classes, <code>Display</code> works exactly as <code>Print</code>.
<p>
<a name = "SSEC001.6"></a>
<li><code></code><var>obj</var><code> in </code><var>class</var><code></code>
<p>
<a name = "I1"></a>
<a name = "I2"></a>
returns true or false, depending upon whether <var>obj</var> belongs to <var>class</var> or
not. If <var>obj</var> can store attributes, the outcome of the membership test is
stored in an attribute <code>ComputedIsMembers</code> of <var>obj</var>.
<p>
<a name = "SSEC001.7"></a>
<li><code></code><var>C1</var><code> = </code><var>C2</var><code></code>
<p>
Since it is not possible to compare classes given by membership algorithms,
two classes are equal in <font face="Gill Sans,Helvetica,Arial">GAP</font> if and only if they are the same <font face="Gill Sans,Helvetica,Arial">GAP</font> object (see <a href="../../../doc/ref/chap12.html#X7961183378DFB902">IsIdenticalObj</a> in the <font face="Gill Sans,Helvetica,Arial">GAP</font> reference manual).
<p>
<a name = "SSEC001.8"></a>
<li><code></code><var>C1</var><code> < </code><var>C2</var><code></code>
<p>
The operation <code><</code> for classes has no mathematical meaning; it only exists
so that one can form sorted lists of classes.
<p>
<p>
<h2><a name="SECT002">2.2 Properties of classes</a></h2>
<p><p>
<a name = "I3"></a>
<a name = "I4"></a>
<a name = "SSEC002.1"></a>
<li><code>IsEmpty(</code><var>C</var><code>) P</code>
<p>
This property may be set to <code>true</code> or <code>false</code> if the class <var>C</var> is empty
resp. not empty.
<p>
<a name = "SSEC002.2"></a>
<li><code>MemberFunction(</code><var>C</var><code>) A</code>
<p>
This attribute, if bound, stores a function with one argument, <var>obj</var>,
which decides if <var>obj</var> belongs to <var>C</var> or not, and returns <code>true</code> and <code>false</code> accordingly.
If present, this function is called by the default method for <code>\in</code>.
<code>MemberFunction</code> is part of the definition of <var>C</var> and should not be called
directly by the user.
<p>
<p>
<h2><a name="SECT003">2.3 Lattice operations for classes</a></h2>
<p><p>
<a name = "I5"></a>
<a name = "SSEC003.1"></a>
<li><code>Complement(</code><var>C</var><code>) O</code>
<p>
returns the unary complement of the class <var>C</var>, that is, the class consisting
of all objects not in <var>C</var>. <var>C</var> may also be a set.
<p>
<pre>
gap> cmpl := Complement([1,2]);
Complement([ 1, 2 ])
gap> Complement(cmpl);
[ 1, 2 ]
</pre>
<p>
<a name = "SSEC003.2"></a>
<li><code>Intersection(</code><var>list</var><code>) F</code>
<li><code>Intersection(</code><var>C1</var><code>, </code><var>C2</var><code>, ...) F</code>
<a name = "I6"></a>
<p>
returns the intersection of the groups in <var>list</var>, resp. of the classes
<var>C1</var>, <var>C2</var>, .... If one of the classes is a list with fewer than
<code>INTERSECTION_LIMIT</code> elements, then the result will be
a sublist of that list. By default, <code>INTERSECTION_LIMIT</code> is 1000.
<p>
<pre>
gap> Intersection(Class(IsPrimeInt), [1..10]);
[ 2, 3, 5, 7 ]
gap> Intersection(Class(IsPrimeInt), Class(n -> n = 2^LogInt(n+1, 2) - 1));
Intersection([ Class(in:=function( N ) ... end),
Class(in:=function( n ) ... end) ])
</pre>
<p>
<a name = "SSEC003.3"></a>
<li><code>Union(</code><var>C</var><code>, </code><var>D</var><code>) F</code>
<p>
returns the union of <var>C</var> and <var>D</var>.
<p>
<pre>
gap> Union(Class(n -> n mod 2 = 0), Class(n -> n mod 3 = 0));
Union([ Class(in:=function( n ) ... end), Class(in:=function( n ) ... end)
])
</pre>
<p>
<a name = "SSEC003.4"></a>
<li><code>Difference(</code><var>C</var><code>, </code><var>D</var><code>) O</code>
<p>
returns the difference of <var>C</var> and <var>D</var>. If <var>C</var> is a list, then the
result will be a sublist of <var>C</var>.
<p>
<pre>
gap> Difference(Class(IsPrimePowerInt), Class(IsPrimeInt));
Intersection([ Class(in:=function( n ) ... end),
Complement(Class(in:=function( N ) ... end)) ])
gap> Difference([1..10], Class(IsPrimeInt));
[ 1, 4, 6, 8, 9, 10 ]
</pre>
<p>
<p>
[<a href = "chapters.htm">Up</a>] [<a href ="CHAP001.htm">Previous</a>] [<a href ="CHAP003.htm">Next</a>] [<a href = "theindex.htm">Index</a>]
<P>
<address>CRISP manual<br>August 2025
</address></body></html>
¤ Dauer der Verarbeitung: 0.27 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.