1 | /***************************************** |
---|

2 | * Computer Algebra System SINGULAR * |
---|

3 | *****************************************/ |
---|

4 | /* $Id: units.cc,v 1.1.1.1 2003-10-06 12:16:04 Singular Exp $ */ |
---|

5 | /* |
---|

6 | * ABSTRACT: procedures to compute with units |
---|

7 | */ |
---|

8 | |
---|

9 | #include "mod2.h" |
---|

10 | #include "structs.h" |
---|

11 | #include "febase.h" |
---|

12 | #include "numbers.h" |
---|

13 | #include "polys.h" |
---|

14 | #include "ideals.h" |
---|

15 | #include "intvec.h" |
---|

16 | #include "matpol.h" |
---|

17 | #include "kstd1.h" |
---|

18 | #include "units.h" |
---|

19 | |
---|

20 | ideal redNF(ideal N,ideal M,matrix U,int d,intvec *w) |
---|

21 | { |
---|

22 | matrix U0=NULL; |
---|

23 | if(U!=NULL) |
---|

24 | { |
---|

25 | U0=mpCopy(U); |
---|

26 | number u0; |
---|

27 | for(int i=IDELEMS(M)-1;i>=0;i--) |
---|

28 | { |
---|

29 | u0=nInvers(pGetCoeff(MATELEM(U0,i+1,i+1))); |
---|

30 | MATELEM(U0,i+1,i+1)=pMult_nn(MATELEM(U0,i+1,i+1),u0); |
---|

31 | M->m[i]=pMult_nn(M->m[i],u0); |
---|

32 | } |
---|

33 | } |
---|

34 | ideal M0=idInit(IDELEMS(M),M->rank); |
---|

35 | ideal M1=kNF(N,currQuotient,M,0,2); |
---|

36 | while(idElem(M1)>0&&(d==-1||idMinDegW(M1,w)<=d)) |
---|

37 | { |
---|

38 | for(int i=IDELEMS(M)-1;i>=0;i--) |
---|

39 | { |
---|

40 | M0->m[i]=pAdd(M0->m[i],pHead(pCopy(M1->m[i]))); |
---|

41 | if(U0!=NULL) |
---|

42 | M->m[i]=pSub(M->m[i],pMult(pHead(pCopy(M1->m[i])), |
---|

43 | pCopy(MATELEM(U0,i+1,i+1)))); |
---|

44 | else |
---|

45 | M->m[i]=pSub(M->m[i],pHead(pCopy(M1->m[i]))); |
---|

46 | } |
---|

47 | idDelete(&M1); |
---|

48 | M1=kNF(N,currQuotient,M,0,2); |
---|

49 | } |
---|

50 | idDelete(&M1); |
---|

51 | idDelete(&N); |
---|

52 | idDelete(&M); |
---|

53 | if(U0!=NULL) |
---|

54 | idDelete((ideal*)&U0); |
---|

55 | return M0; |
---|

56 | } |
---|

57 | |
---|

58 | poly redNF(ideal N,poly p,poly u,int d,intvec *w) |
---|

59 | { |
---|

60 | ideal M=idInit(1,pGetComp(p)); |
---|

61 | M->m[0]=p; |
---|

62 | ideal M0; |
---|

63 | if(u==NULL) |
---|

64 | M0=redNF(N,M,NULL,d,w); |
---|

65 | else |
---|

66 | { |
---|

67 | matrix U=mpNew(1,1); |
---|

68 | MATELEM(U,1,1)=u; |
---|

69 | M0=redNF(N,M,U,d,w); |
---|

70 | idDelete((ideal*)&U); |
---|

71 | } |
---|

72 | poly p0=M0->m[0]; |
---|

73 | M0->m[0]=NULL; |
---|

74 | idDelete(&M0); |
---|

75 | return p0; |
---|

76 | } |
---|

77 | |
---|