source: git/factory/cf_generator.cc @ ab4548f

spielwiese
Last change on this file since ab4548f was ab4548f, checked in by Jens Schmidt <schmidt@…>, 27 years ago
#include <config.h> added git-svn-id: file:///usr/local/Singular/svn/trunk@133 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.8 KB
Line 
1// emacs edit mode for this file is -*- C++ -*-
2// $Id: cf_generator.cc,v 1.1 1997-04-07 15:06:30 schmidt Exp $
3
4/*
5$Log: not supported by cvs2svn $
6Revision 1.0  1996/05/17 10:59:43  stobbe
7Initial revision
8
9*/
10
11#include <config.h>
12
13#include "assert.h"
14
15#include "cf_defs.h"
16#include "cf_generator.h"
17#include "imm.h"
18#include "gfops.h"
19#include "ffops.h"
20
21bool FFGenerator::hasItems() const
22{
23    return current < ff_prime;
24}
25
26CanonicalForm FFGenerator::item() const
27{
28    ASSERT( current < ff_prime, "no more items" );
29    return CanonicalForm( int2imm_p( current ) );
30}
31
32void FFGenerator::next()
33{
34    ASSERT( current < ff_prime, "no more items" );
35    current++;
36}
37
38
39GFGenerator::GFGenerator()
40{
41    current = gf_zero();
42}
43
44bool GFGenerator::hasItems() const
45{
46    return ( current != gf_q + 1 );
47}
48
49void GFGenerator::reset()
50{
51    current = gf_zero();
52}
53
54CanonicalForm GFGenerator::item() const
55{
56    ASSERT( current != gf_q + 1, "no more items" );
57    return CanonicalForm( int2imm_gf( current ) );
58}
59
60void GFGenerator::next()
61{
62    ASSERT( current != gf_q + 1, "no more items" );
63    if ( gf_iszero( current ) )
64        current = 0;
65    else  if ( current == gf_q1 - 1 )
66        current = gf_q + 1;
67    else
68        current++;
69}
70
71AlgExtGenerator::AlgExtGenerator()
72{
73    ASSERT( 0, "not a valid generator" );
74}
75
76AlgExtGenerator::AlgExtGenerator( const AlgExtGenerator & )
77{
78    ASSERT( 0, "not a valid generator" );
79}
80
81AlgExtGenerator& AlgExtGenerator::operator= ( const AlgExtGenerator & )
82{
83    ASSERT( 0, "not a valid generator" );
84    return *this;
85}
86
87AlgExtGenerator::AlgExtGenerator( const Variable & a )
88{
89    ASSERT( a.level() < 0, "not an algebraic extension" );
90    ASSERT( getCharacteristic() > 0, "not a finite field" );
91    algext = a;
92    n = degree( getMipo( a ) );
93    gens = new CFGenerator * [n];
94    nomoreitems = false;
95    for ( int i = 0; i < n; i++ )
96        gens[i] = CFGenFactory::generate();
97}
98
99AlgExtGenerator::~AlgExtGenerator()
100{
101    for ( int i = 0; i < n; i++ )
102        delete gens[i];
103    delete [] gens;
104}
105
106void AlgExtGenerator::reset()
107{
108    for ( int i = 0; i < n; i++ )
109        gens[i]->reset();
110    nomoreitems = false;
111}
112
113CanonicalForm AlgExtGenerator::item() const
114{
115    ASSERT( ! nomoreitems, "no more items" );
116    CanonicalForm result = 0;
117    for ( int i = 0; i < n; i++ )
118        result += power( algext, i ) * gens[i]->item();
119    return result;
120}
121
122void AlgExtGenerator::next()
123{
124    ASSERT( ! nomoreitems, "no more items" );
125    int i = 0;
126    bool stop = false;
127    while ( ! stop && i < n ) {
128        gens[i]->next();
129        if ( ! gens[i]->hasItems() ) {
130            gens[i]->reset();
131            i++;
132        }
133        else
134            stop = true;
135    }
136    if ( ! stop )
137        nomoreitems = true;
138}
139
140CFGenerator * CFGenFactory::generate()
141{
142    ASSERT( getCharacteristic() > 0, "not a finite field" );
143    if ( getGFDegree() > 1 )
144        return new GFGenerator();
145    else
146        return new FFGenerator();
147}
Note: See TracBrowser for help on using the repository browser.