Annotation of OpenXM_contrib2/asir2000/engine/num.c, Revision 1.6
1.2 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.6 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/engine/num.c,v 1.5 2001/09/05 09:01:27 noro Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
51:
1.6 ! noro 52: void addnum(VL vl,Num a,Num b,Num *c)
1.1 noro 53: {
54: (*addnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c);
55: }
56:
1.6 ! noro 57: void subnum(VL vl,Num a,Num b,Num *c)
1.1 noro 58: {
59: (*subnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c);
60: }
61:
1.6 ! noro 62: void mulnum(VL vl,Num a,Num b,Num *c)
1.1 noro 63: {
64: (*mulnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c);
65: }
66:
1.6 ! noro 67: void divnum(VL vl,Num a,Num b,Num *c)
1.1 noro 68: {
69: (*divnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c);
70: }
71:
1.6 ! noro 72: void pwrnum(VL vl,Num a,Num b,Num *c)
1.1 noro 73: {
74: (*pwrnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c);
75: }
76:
1.6 ! noro 77: void chsgnnum(Num a,Num *c)
1.1 noro 78: {
79: (*chsgnnumt[a?NID(a):0])(a,c);
80: }
81:
1.6 ! noro 82: int compnum(VL vl,Num a,Num b)
1.1 noro 83: {
84: return (*cmpnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b);
1.4 noro 85: }
86:
87: extern int current_ff;
88:
1.6 ! noro 89: void one_ff(Num *c)
1.4 noro 90: {
91: LM lm;
92: GFS fs;
93: GFSN fspn;
94:
95: switch ( current_ff ) {
96: case FF_GFP:
97: case FF_GFPN:
98: MKLM(ONEN,lm);
99: *c = (Num)lm;
100: break;
101: case FF_GFS:
102: mqtogfs(ONEM,&fs);
103: *c = (Num)fs;
104: break;
105: case FF_GFSN:
1.6 ! noro 106: ntogfsn((Obj)ONE,&fspn);
1.4 noro 107: *c = (Num)fspn;
108: break;
109: default:
110: error("one_ff : not implemented yet");
1.5 noro 111: }
112: }
113:
1.6 ! noro 114: int negative_number(Num c)
1.5 noro 115: {
116: if ( !c )
117: return 0;
118: else {
119: switch ( NID(c) ) {
120: case N_Q:
121: return SGN((Q)c)<0;
122: case N_R:
123: return BDY((Real)c)<0;
124: case N_B:
125: return 0; /* XXX */
126: default:
127: return 0;
128: }
1.6 ! noro 129: }
! 130: }
! 131:
! 132: /* general simplifier for finite field elements */
! 133: /* XXX : we don't have appropriate file */
! 134:
! 135: void simp_ff(Obj p,Obj *rp)
! 136: {
! 137: LM s;
! 138: DCP dc,dcr0,dcr;
! 139: GF2N rg,sg;
! 140: GFPN rpn,spn;
! 141: GFS rs;
! 142: GFSN rspn,sspn;
! 143: P t;
! 144: Obj obj;
! 145:
! 146: lm_lazy = 0;
! 147: if ( !p )
! 148: *rp = 0;
! 149: else if ( OID(p) == O_N ) {
! 150: switch ( current_ff ) {
! 151: case FF_GFP:
! 152: ptolmp((P)p,&t); simplm((LM)t,&s); *rp = (Obj)s;
! 153: break;
! 154: case FF_GF2N:
! 155: ptogf2n((Obj)p,&rg); simpgf2n((GF2N)rg,&sg); *rp = (Obj)sg;
! 156: break;
! 157: case FF_GFPN:
! 158: ntogfpn((Obj)p,&rpn); simpgfpn((GFPN)rpn,&spn); *rp = (Obj)spn;
! 159: break;
! 160: case FF_GFS:
! 161: if ( NID((Num)p) == N_GFS )
! 162: *rp = p;
! 163: else {
! 164: ptomp(current_gfs_p,(P)p,&t); mqtogfs((MQ)t,&rs);
! 165: *rp = (Obj)rs;
! 166: }
! 167: break;
! 168: case FF_GFSN:
! 169: ntogfsn((Obj)p,&rspn); simpgfsn((GFSN)rspn,&sspn);
! 170: *rp = (Obj)sspn;
! 171: break;
! 172: default:
! 173: *rp = (Obj)p;
! 174: break;
! 175: }
! 176: } else if ( OID(p) == O_P ) {
! 177: for ( dc = DC((P)p), dcr0 = 0; dc; dc = NEXT(dc) ) {
! 178: simp_ff((Obj)COEF(dc),&obj);
! 179: if ( obj ) {
! 180: NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); COEF(dcr) = (P)obj;
! 181: }
! 182: }
! 183: if ( !dcr0 )
! 184: *rp = 0;
! 185: else {
! 186: NEXT(dcr) = 0; MKP(VR((P)p),dcr0,t); *rp = (Obj)t;
! 187: }
! 188: } else
! 189: error("simp_ff : not implemented yet");
! 190: }
! 191:
! 192:
! 193: void field_order_ff(N *order)
! 194: {
! 195: UP2 up2;
! 196: UP up;
! 197: UM dp;
! 198: N m;
! 199: int d,w;
! 200:
! 201: switch ( current_ff ) {
! 202: case FF_GFP:
! 203: getmod_lm(order); break;
! 204: case FF_GF2N:
! 205: getmod_gf2n(&up2); d = degup2(up2);
! 206: w = (d>>5)+1;
! 207: *order = m = NALLOC(w);
! 208: PL(m)=w;
! 209: bzero((char *)BD(m),w*sizeof(unsigned int));
! 210: BD(m)[d>>5] |= 1<<(d&31);
! 211: break;
! 212: case FF_GFPN:
! 213: getmod_lm(&m);
! 214: getmod_gfpn(&up); pwrn(m,up->d,order);
! 215: break;
! 216: case FF_GFS:
! 217: STON(current_gfs_q,*order); break;
! 218: case FF_GFSN:
! 219: STON(current_gfs_q,m);
! 220: getmod_gfsn(&dp); pwrn(m,DEG(dp),order);
! 221: break;
! 222: default:
! 223: error("field_order_ff : current_ff is not set");
1.4 noro 224: }
1.1 noro 225: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>