source: git/libfac/factor/helpstuff.cc @ 4a81ec

fieker-DuValspielwiese
Last change on this file since 4a81ec was 4a81ec, checked in by Hans Schönemann <hannes@…>, 27 years ago
* hannes/michael: libfac-0.3.0 git-svn-id: file:///usr/local/Singular/svn/trunk@708 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.2 KB
Line 
1/* Copyright 1997 Michael Messollen. All rights reserved. */
2////////////////////////////////////////////////////////////
3// emacs edit mode for this file is -*- C++ -*-
4// static char * rcsid = "$Id: helpstuff.cc,v 1.3 1997-09-12 07:19:56 Singular Exp $";
5////////////////////////////////////////////////////////////
6// FACTORY - Includes
7#include <factory.h>
8// Factor - Includes
9#include "tmpl_inst.h"
10// some CC's need this:
11#include "helpstuff.h"
12
13bool 
14mydivremt ( const CanonicalForm& f, const CanonicalForm& g, CanonicalForm& a, CanonicalForm& b ){
15  bool retvalue;
16  CanonicalForm aa,bb;
17  retvalue = divremt(f,g,a,bb);
18  aa= f-g*a;
19  if ( aa==bb ) { b=bb; }
20  else { b=aa; }
21  return retvalue;
22}
23
24void
25mydivrem( const CanonicalForm& f, const CanonicalForm& g, CanonicalForm& a, CanonicalForm& b ){
26  bool retvalue;
27  CanonicalForm aa,bb;
28  retvalue = divremt(f,g,a,bb);
29  aa= f-g*a;
30  if ( aa==bb ) { b=bb; }
31  else { b=aa; }
32}
33
34// Now some procedures used in SqrFree and in Factor
35///////////////////////////////////////////////////////////////
36///////////////////////////////////////////////////////////////
37// We have to include a version of <CFFList>.append(CFFactor)//
38// and Union( CFFList, CFFList)                              //
39// because we have to look for multiplicities in SqrFree.    //
40// e.g.: SqrFree( f^3 ) with char <> 3                       //
41///////////////////////////////////////////////////////////////
42CFFList
43myappend( const CFFList & Inputlist, const CFFactor & TheFactor){
44  CFFList Outputlist ;
45  CFFactor copy;
46  CFFListIterator i;
47  int exp=0;
48
49  for ( i=Inputlist ; i.hasItem() ; i++ ){
50    copy = i.getItem();
51    if ( copy.factor() == TheFactor.factor() )
52      exp += copy.exp();
53    else 
54      Outputlist.append(copy);
55  }
56  Outputlist.append( CFFactor(TheFactor.factor(), exp + TheFactor.exp()));
57  return Outputlist;
58}
59
60CFFList
61myUnion(const CFFList & Inputlist1,const CFFList & Inputlist2){
62  CFFList Outputlist;
63  CFFListIterator i;
64
65  for ( i=Inputlist1 ; i.hasItem() ; i++ )
66    Outputlist = myappend(Outputlist, i.getItem() );
67  for ( i=Inputlist2 ; i.hasItem() ; i++ )
68    Outputlist = myappend(Outputlist, i.getItem() );
69
70  return Outputlist;
71}
72
73int
74Powerup( const int base , const int exp){
75  int retvalue=1;
76  if ( exp == 0 )  return retvalue ; 
77  else for ( int i=1 ; i <= exp; i++ ) retvalue *= base ;
78
79  return retvalue;
80}
81
82// Now some procedures used in MVMultiHensel and in Truefactors
83///////////////////////////////////////////////////////////////
84
85///////////////////////////////////////////////////////////////
86// mod_power: Return f mod I^k, where I is now the ideal     //
87// {x_1, .. x_(level(f)-1)}. Computation mod I^k is simply   //
88// done by dropping all the terms of degree >= k in          //
89// x_1, .. x_(level(f)-1); e.g. x_1*x_2 == 0 mod I^2 .       //
90// modpower: the real work is done here; called by mod_power //
91///////////////////////////////////////////////////////////////
92static void 
93modpower( const CanonicalForm & f, int k , int td, 
94          const CanonicalForm & t, CanonicalForm & result){
95
96  if ( td >= k ) return;
97  if ( getNumVars(f) == 0 ) result += f*t;
98  else{
99    Variable x(level(f));
100    for ( CFIterator i=f; i.hasTerms(); i++)
101      modpower(i.coeff(),k,td+i.exp(),t*power(x,i.exp()),result);
102  }
103}
104
105CanonicalForm
106mod_power( const CanonicalForm & f, int k, int levelU){
107  CanonicalForm result,dummy;
108  Variable x(levelU);
109
110  if ( levelU > level(f) )
111    modpower(f,k,0,1,result);
112  else{
113    for ( CFIterator i=f; i.hasTerms(); i++){
114      dummy = 0;
115      modpower(i.coeff(),k,0,1,dummy);
116      result += dummy * power(x,i.exp());
117// the following works, but is slower
118//    int degf=degree(f);
119//    for ( int i=0; i<=degf;i++){
120//      result+= mod_power(f[i],k,levelU)*power(x,i);
121    }
122  }
123
124  return result;
125}
126
127///////////////////////////////////////////////////////////////
128// Return the deg of F in the Variables x_1,..,x_(levelF-1)  //
129///////////////////////////////////////////////////////////////
130int 
131subvardegree( const CanonicalForm & F, int levelF ){
132  int n=0,m=degree(F,levelF),newn=0;
133
134  for ( int k=0; k<=m; k++ ){
135    newn = totaldegree( F[k] );
136    if ( newn > n ) n=newn;
137  }
138  return n;
139}
140
141///////////////////////////////////////////////////////////////
142// Change poly:  x_i <- x_i +- a_i    for i= 1,..,level(f)-1 //
143///////////////////////////////////////////////////////////////
144CanonicalForm
145change_poly( const CanonicalForm & f , const SFormList & Substitutionlist ,int directionback ){
146  CanonicalForm F=f,g,k;
147  int level_i;
148//  Variable x;
149
150  for ( SFormListIterator i=Substitutionlist; i.hasItem(); i++){
151  // now we can access: i.getItem().factor()  -> level(~) gives x_i
152  //                    i.getItem().exp()     -> gives a_i
153  // ==> g = x_i ; k = a_i
154    level_i=level(i.getItem().factor());
155    g = power( 
156                       Variable(level_i),1
157                       ); 
158    k= i.getItem().exp();
159    if ( directionback ){
160      if ( degree(F, level_i) != 0 )
161        F=F(g-k, level(i.getItem().factor())); // x_i <-- x_i - a_i
162    }
163    else{
164      if ( degree(F, level_i) != 0 )
165        F=F(g+k, level(i.getItem().factor())); // x_i <-- x_i +a_i
166    }
167  }
168
169  return F;
170}
171
172////////////////////////////////////////////////////////////
173/*
174$Log: not supported by cvs2svn $
175Revision 1.3  1997/04/25 22:20:45  michael
176Version for libfac-0.2.1
177
178*/
Note: See TracBrowser for help on using the repository browser.