source: git/libfac/factor/helpstuff.cc @ b429551

spielwiese
Last change on this file since b429551 was b429551, checked in by Hans Schönemann <hannes@…>, 16 years ago
*hannes: sqrFree/InternalSqrFree -> factory git-svn-id: file:///usr/local/Singular/svn/trunk@10520 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.7 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.6 2008-01-22 09:51:37 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{
16  bool retvalue;
17  CanonicalForm aa,bb;
18  retvalue = divremt(f,g,a,bb);
19  aa= f-g*a;
20  if ( aa==bb ) { b=bb; }
21  else { b=aa; }
22  return retvalue;
23}
24
25void
26mydivrem( const CanonicalForm& f, const CanonicalForm& g, CanonicalForm& a, CanonicalForm& b )
27{
28  bool retvalue;
29  CanonicalForm aa,bb;
30  retvalue = divremt(f,g,a,bb);
31  aa= f-g*a;
32  if ( aa==bb ) { b=bb; }
33  else { b=aa; }
34}
35
36// Now some procedures used in MVMultiHensel and in Truefactors
37///////////////////////////////////////////////////////////////
38
39///////////////////////////////////////////////////////////////
40// mod_power: Return f mod I^k, where I is now the ideal     //
41// {x_1, .. x_(level(f)-1)}. Computation mod I^k is simply   //
42// done by dropping all the terms of degree >= k in          //
43// x_1, .. x_(level(f)-1); e.g. x_1*x_2 == 0 mod I^2 .       //
44// modpower: the real work is done here; called by mod_power //
45///////////////////////////////////////////////////////////////
46static void
47modpower( const CanonicalForm & f, int k , int td,
48          const CanonicalForm & t, CanonicalForm & result){
49
50  if ( td >= k ) return;
51  if ( getNumVars(f) == 0 ) result += f*t;
52  else{
53    Variable x(level(f));
54    for ( CFIterator i=f; i.hasTerms(); i++)
55      modpower(i.coeff(),k,td+i.exp(),t*power(x,i.exp()),result);
56  }
57}
58
59CanonicalForm
60mod_power( const CanonicalForm & f, int k, int levelU){
61  CanonicalForm result,dummy;
62  Variable x(levelU);
63
64  if ( levelU > level(f) )
65    modpower(f,k,0,1,result);
66  else{
67    for ( CFIterator i=f; i.hasTerms(); i++){
68      dummy = 0;
69      modpower(i.coeff(),k,0,1,dummy);
70      result += dummy * power(x,i.exp());
71// the following works, but is slower
72//    int degf=degree(f);
73//    for ( int i=0; i<=degf;i++){
74//      result+= mod_power(f[i],k,levelU)*power(x,i);
75    }
76  }
77
78  return result;
79}
80
81///////////////////////////////////////////////////////////////
82// Change poly:  x_i <- x_i +- a_i    for i= 1,..,level(f)-1 //
83///////////////////////////////////////////////////////////////
84CanonicalForm
85change_poly( const CanonicalForm & f , const SFormList & Substitutionlist ,int directionback ){
86  CanonicalForm F=f,g,k;
87  int level_i;
88//  Variable x;
89
90  for ( SFormListIterator i=Substitutionlist; i.hasItem(); i++){
91  // now we can access: i.getItem().factor()  -> level(~) gives x_i
92  //                    i.getItem().exp()     -> gives a_i
93  // ==> g = x_i ; k = a_i
94    level_i=level(i.getItem().factor());
95    g = power(
96                       Variable(level_i),1
97                       );
98    k= i.getItem().exp();
99    if ( directionback )
100    {
101      if ( degree(F, level_i) != 0 )
102        F=F(g-k, level_i /*level(i.getItem().factor())*/); // x_i <-- x_i - a_i
103    }
104    else
105    {
106      if ( degree(F, level_i) != 0 )
107        F=F(g+k, level_i /*level(i.getItem().factor())*/); // x_i <-- x_i +a_i
108    }
109  }
110
111  return F;
112}
113
114////////////////////////////////////////////////////////////
115/*
116$Log: not supported by cvs2svn $
117Revision 1.5  2007/05/25 12:59:05  Singular
118*hannes: fdivides2
119
120Revision 1.4  2001/06/19 15:29:04  Singular
121*hannes: optim.
122
123Revision 1.3  1997/09/12 07:19:56  Singular
124* hannes/michael: libfac-0.3.0
125
126Revision 1.3  1997/04/25 22:20:45  michael
127Version for libfac-0.2.1
128
129*/
Note: See TracBrowser for help on using the repository browser.