Annotation of OpenXM_contrib2/asir2018/engine/num.c, Revision 1.2
1.1 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
26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
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.2 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2018/engine/num.c,v 1.1 2018/09/19 05:45:07 noro Exp $
1.1 noro 49: */
50: #include "ca.h"
51:
52: void addnum(VL vl,Num a,Num b,Num *c)
53: {
54: (*addnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c);
55: }
56:
57: void subnum(VL vl,Num a,Num b,Num *c)
58: {
59: (*subnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c);
60: }
61:
62: void mulnum(VL vl,Num a,Num b,Num *c)
63: {
64: (*mulnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c);
65: }
66:
67: void divnum(VL vl,Num a,Num b,Num *c)
68: {
69: (*divnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c);
70: }
71:
72: void pwrnum(VL vl,Num a,Num b,Num *c)
73: {
74: (*pwrnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c);
75: }
76:
77: void chsgnnum(Num a,Num *c)
78: {
79: (*chsgnnumt[a?NID(a):0])(a,c);
80: }
81:
82: int compnum(VL vl,Num a,Num b)
83: {
84: return (*cmpnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b);
85: }
86:
87: extern int current_ff;
88:
89: void one_ff(Num *c)
90: {
91: LM lm;
92: GFS fs;
93: GFSN fspn;
94:
95: switch ( current_ff ) {
96: case FF_GFP:
97: case FF_GFPN:
98: *c = (Num)ONELM;
99: break;
100: case FF_GFS:
101: mqtogfs(ONEM,&fs);
102: *c = (Num)fs;
103: break;
104: case FF_GFSN:
105: ntogfsn((Obj)ONE,&fspn);
106: *c = (Num)fspn;
107: break;
108: default:
109: error("one_ff : not implemented yet");
110: }
111: }
112:
113: int negative_number(Num c)
114: {
115: if ( !c )
116: return 0;
117: else {
118: switch ( NID(c) ) {
119: case N_Q:
120: return sgnq((Q)c)<0;
121: case N_R:
122: return BDY((Real)c)<0;
123: case N_B:
124: return 0; /* XXX */
125: default:
126: return 0;
127: }
128: }
129: }
130:
131: /* general simplifier for finite field elements */
132: /* XXX : we don't have appropriate file */
133:
134: void simp_ff(Obj p,Obj *rp)
135: {
136: LM s;
137: DCP dc,dcr0,dcr;
138: GF2N rg,sg;
139: GFPN rpn,spn;
140: GFS rs;
141: GFSN rspn,sspn;
142: P t;
143: Obj obj;
144:
145: lm_lazy = 0;
146: if ( !p )
147: *rp = 0;
148: else if ( OID(p) == O_N ) {
149: switch ( current_ff ) {
150: case FF_GFP:
151: ptolmp((P)p,&t); simplm((LM)t,&s); *rp = (Obj)s;
152: break;
153: case FF_GF2N:
154: ptogf2n((Obj)p,&rg); simpgf2n((GF2N)rg,&sg); *rp = (Obj)sg;
155: break;
156: case FF_GFPN:
157: ntogfpn((Obj)p,&rpn); simpgfpn((GFPN)rpn,&spn); *rp = (Obj)spn;
158: break;
159: case FF_GFS:
160: if ( NID((Num)p) == N_GFS )
161: *rp = p;
162: else {
163: ptomp(current_gfs_p,(P)p,&t); mqtogfs((MQ)t,&rs);
164: *rp = (Obj)rs;
165: }
166: break;
167: case FF_GFSN:
168: ntogfsn((Obj)p,&rspn); simpgfsn((GFSN)rspn,&sspn);
169: *rp = (Obj)sspn;
170: break;
171: default:
172: *rp = (Obj)p;
173: break;
174: }
175: } else if ( OID(p) == O_P ) {
176: for ( dc = DC((P)p), dcr0 = 0; dc; dc = NEXT(dc) ) {
177: simp_ff((Obj)COEF(dc),&obj);
178: if ( obj ) {
179: NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); COEF(dcr) = (P)obj;
180: }
181: }
182: if ( !dcr0 )
183: *rp = 0;
184: else {
185: NEXT(dcr) = 0; MKP(VR((P)p),dcr0,t); *rp = (Obj)t;
186: }
187: } else
188: error("simp_ff : not implemented yet");
189: }
190:
191:
192: void field_order_ff(Z *order)
193: {
194: UP2 up2;
195: UP up;
196: UM dp;
197: Z m,e;
198: mpz_t z;
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: mpz_init(z);
207: mpz_mul_2exp(z,BDY(ONE),d);
208: MPZTOZ(z,*order);
209: break;
210: case FF_GFPN:
211: getmod_lm(&m);
212: getmod_gfpn(&up);
1.2 ! noro 213: STOZ(up->d,e);
1.1 noro 214: pwrz(m,e,order);
215: break;
216: case FF_GFS:
1.2 ! noro 217: STOZ(current_gfs_q,*order); break;
1.1 noro 218: case FF_GFSN:
1.2 ! noro 219: STOZ(current_gfs_q,m);
1.1 noro 220: getmod_gfsn(&dp);
1.2 ! noro 221: STOZ(DEG(dp),e);
1.1 noro 222: pwrz(m,e,order);
223: break;
224: default:
225: error("field_order_ff : current_ff is not set");
226: }
227: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>