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 | |
---|
13 | bool |
---|
14 | mydivremt ( 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 | |
---|
25 | void |
---|
26 | mydivrem( 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 | /////////////////////////////////////////////////////////////// |
---|
46 | static void |
---|
47 | modpower( 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 | |
---|
59 | CanonicalForm |
---|
60 | mod_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 | /////////////////////////////////////////////////////////////// |
---|
84 | CanonicalForm |
---|
85 | change_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 $ |
---|
117 | Revision 1.5 2007/05/25 12:59:05 Singular |
---|
118 | *hannes: fdivides2 |
---|
119 | |
---|
120 | Revision 1.4 2001/06/19 15:29:04 Singular |
---|
121 | *hannes: optim. |
---|
122 | |
---|
123 | Revision 1.3 1997/09/12 07:19:56 Singular |
---|
124 | * hannes/michael: libfac-0.3.0 |
---|
125 | |
---|
126 | Revision 1.3 1997/04/25 22:20:45 michael |
---|
127 | Version for libfac-0.2.1 |
---|
128 | |
---|
129 | */ |
---|