CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Path: gap4r8 / src / ariths.h
Views: 418346
1
/****************************************************************************
2
**
3
*W ariths.h GAP source Frank Celler
4
*W & Martin Schönert
5
**
6
**
7
*Y Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany
8
*Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland
9
*Y Copyright (C) 2002 The GAP Group
10
**
11
** This file declares the functions of the arithmetic operations package.
12
*/
13
14
#ifndef GAP_ARITHS_H
15
#define GAP_ARITHS_H
16
17
/****************************************************************************
18
**
19
20
*T CompaMethod . . . . . . . . . . type of methods for comparison operations
21
**
22
** 'CompaMethod' is the type of methods for comparison operations, i.e., a
23
** function accepting two arguments of type 'Obj' and returning an 'Int'.
24
*/
25
typedef Int (* CompaMethod) ( Obj opL, Obj opR );
26
27
28
/****************************************************************************
29
**
30
*T ArithMethod1 . . . . . . . . . type of methods for arithmetic operations
31
**
32
** 'ArithMethod1' is the type of methods for unary arithmetic operations,
33
** i.e., a function accepting one argument of type 'Obj' and returning an
34
** 'Obj'.
35
*/
36
typedef Obj (* ArithMethod1) ( Obj op );
37
38
39
/****************************************************************************
40
**
41
*T ArithMethod2 . . . . . . . . . type of methods for arithmetic operations
42
**
43
** 'ArithMethod2' is the type of methods for binary arithmetic operations,
44
** i.e., a function accepting two arguments of type 'Obj' and returning an
45
** 'Obj'.
46
*/
47
typedef Obj (* ArithMethod2) ( Obj opL, Obj opR );
48
49
50
/****************************************************************************
51
**
52
53
*F * * * * * * * * * * * unary arithmetic operations * * * * * * * * * * * *
54
*/
55
56
/****************************************************************************
57
**
58
*F ZERO( <op> ) . . . . . . . . . . . . . . . . . . . . . zero of an object
59
**
60
** 'ZERO' returns the zero of the object <op>.
61
*/
62
#define ZERO(op) ((*ZeroFuncs[TNUM_OBJ(op)])(op))
63
64
extern Obj ZEROOp;
65
66
67
/****************************************************************************
68
**
69
*V ZeroFuncs[<type>] . . . . . . . . . . . . . . . . . table of zero methods
70
*/
71
extern ArithMethod1 ZeroFuncs [LAST_VIRTUAL_TNUM+1];
72
73
74
/****************************************************************************
75
**
76
*F InstallZeroObject( <verb> )
77
*/
78
extern void InstallZeroObject ( Int );
79
80
/****************************************************************************
81
**
82
*F ZERO_MUT( <op> ) . . . . . . . . . . . . . . . . . . . . . zero of an object
83
**
84
** 'ZERO_MUT' returns the mutable zero of the object <op>.
85
*/
86
#define ZERO_MUT(op) ((*ZeroMutFuncs[TNUM_OBJ(op)])(op))
87
88
extern Obj ZeroOp;
89
90
91
/****************************************************************************
92
**
93
*V ZeroMutFuncs[<type>] . . . . . . . . . . . . . . . . . table of zero methods
94
*/
95
extern ArithMethod1 ZeroMutFuncs [LAST_VIRTUAL_TNUM+1];
96
97
98
/****************************************************************************
99
**
100
*F InstallZeroMutObject( <verb> )
101
*/
102
extern void InstallZeroMutObject ( Int );
103
104
105
/****************************************************************************
106
**
107
108
*F AINV( <op> ) . . . . . . . . . . . . . . . additive inverse of an object
109
**
110
** 'AINV' returns the additive inverse of the object <op>.
111
*/
112
#define AINV(op) ((*AInvFuncs[TNUM_OBJ(op)])(op))
113
114
extern Obj AInvOp;
115
116
117
/****************************************************************************
118
**
119
*V AInvFuncs[<type>] . . . . . . . . . . . table of additive inverse methods
120
*/
121
extern ArithMethod1 AInvFuncs [LAST_VIRTUAL_TNUM+1];
122
123
124
/****************************************************************************
125
**
126
*F InstallAinvObject( <verb> )
127
*/
128
extern void InstallAinvObject ( Int );
129
130
/****************************************************************************
131
**
132
*F AINV_MUT( <op> ) . . . . . . . . . . . . . additive inverse of an object
133
**
134
** 'AINV_MUT' returns the mutable additive inverse of the object <op>.
135
*/
136
#define AINV_MUT(op) ((*AInvMutFuncs[TNUM_OBJ(op)])(op))
137
138
extern Obj AdditiveInverseOp;
139
140
141
/****************************************************************************
142
**
143
*V AInvMutFuncs[<type>] . . . . . . . . . . . table of additive inverse methods
144
*/
145
extern ArithMethod1 AInvMutFuncs [LAST_VIRTUAL_TNUM+1];
146
147
148
/****************************************************************************
149
**
150
*F InstallAinvMutObject( <verb> )
151
*/
152
extern void InstallAinvMutObject ( Int );
153
154
155
/****************************************************************************
156
**
157
*F C_AINV( <val>, <left> ) . . . . . . . . . . . . . . . . . . compute ainv
158
*/
159
#define C_AINV(val,left) \
160
val = AINV_MUT( left );
161
162
163
/****************************************************************************
164
**
165
*F C_AINV_FIA( <val>, <left> ) . . . . . . . . . compute ainv, fast integer
166
*/
167
#define C_AINV_FIA(val,left) \
168
val = AINV_MUT( left );
169
170
171
/****************************************************************************
172
**
173
*F C_AINV_INTOBJS( <val>, <left> ) . . . . . . . compute ainv of an integer
174
*/
175
#define C_AINV_INTOBJS(val,left) \
176
val = AINV_MUT( left );
177
178
179
/****************************************************************************
180
**
181
*F ONE( <op> ) . . . . . . . . . . . . . . . . . . . . . . one of an object
182
**
183
** 'ONE' returns the one of the object <op>.
184
*/
185
#define ONE(op) ((*OneFuncs[TNUM_OBJ(op)])(op))
186
187
extern Obj OneOp;
188
189
190
/****************************************************************************
191
**
192
*V OneFuncs[<type>] . . . . . . . . . . . . . . . . . table of one methods
193
*/
194
extern ArithMethod1 OneFuncs [LAST_VIRTUAL_TNUM+1];
195
196
197
/****************************************************************************
198
**
199
*F InstallOneObject( <verb> )
200
*/
201
extern void InstallOneObject ( Int );
202
203
/****************************************************************************
204
**
205
*F ONE_MUT( <op> ) . . . . . . . . one of an object retaining mutability
206
**
207
** 'ONE_MUT' returns the one of the object <op> with the same
208
** mutability level as <op>.
209
*/
210
#define ONE_MUT(op) ((*OneMutFuncs[TNUM_OBJ(op)])(op))
211
212
extern Obj OneMutOp;
213
214
215
/****************************************************************************
216
**
217
*V OneMutFuncs[<type>] . . . . . .table of mutability preservingone methods
218
*/
219
extern ArithMethod1 OneMutFuncs [LAST_VIRTUAL_TNUM+1];
220
221
222
/****************************************************************************
223
**
224
*F InstallOneMutObject( <verb> )
225
*/
226
extern void InstallOneMutObject ( Int );
227
228
229
/****************************************************************************
230
**
231
*F INV( <op> ) . . . . . . . . . . . . . . . . . . . . inverse of an object
232
**
233
** 'INV' returns the multiplicative inverse of the object <op>.
234
*/
235
#define INV(op) ((*InvFuncs[TNUM_OBJ(op)])(op))
236
237
extern Obj InvOp;
238
239
240
/****************************************************************************
241
**
242
*V InvFuncs[<type>] . . . . . . . . . . . . . . table of inverse functions
243
*/
244
extern ArithMethod1 InvFuncs [LAST_VIRTUAL_TNUM+1];
245
246
247
/****************************************************************************
248
**
249
*F InstallInvObject( <verb> )
250
*/
251
extern void InstallInvObject ( Int );
252
253
254
/****************************************************************************
255
**
256
*F INV_MUT( <op> ) . . . . . . . . inverse of an object retaining mutability
257
**
258
** 'INV_MUT' returns the multiplicative inverse of the object <op>.
259
*/
260
#define INV_MUT(op) ((*InvMutFuncs[TNUM_OBJ(op)])(op))
261
262
extern Obj InvMutOp;
263
264
265
/****************************************************************************
266
**
267
*V InvMutFuncs[<type>] .. .table of mutability preserving inverse functions
268
*/
269
extern ArithMethod1 InvMutFuncs [LAST_VIRTUAL_TNUM+1];
270
271
272
/****************************************************************************
273
**
274
*F InstallInvMutObject( <verb> )
275
*/
276
extern void InstallInvMutObject ( Int );
277
278
279
/****************************************************************************
280
**
281
282
*F * * * * * * * * * * * * * comparison operations * * * * * * * * * * * * *
283
*/
284
285
/****************************************************************************
286
**
287
288
*F EQ( <opL>, <opR> ) . . . . . . . . . . . . . . comparison of two objects
289
**
290
** 'EQ' returns a nonzero value if the object <opL> is equal to the object
291
** <opR>, and zero otherwise.
292
*/
293
#define EQ(opL,opR) ((opL) == (opR) || \
294
(!ARE_INTOBJS(opL,opR) && \
295
(*EqFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR)))
296
297
#define EQ2(opL,opR) ((opL) == (opR) || \
298
(*EqFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR))
299
300
extern Obj EqOper;
301
302
303
/****************************************************************************
304
**
305
*V EqFuncs[<typeL>][<typeR>] . . . . . . . . . . table of comparison methods
306
*/
307
extern CompaMethod EqFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
308
309
310
/****************************************************************************
311
**
312
*F InstallEqObject( <verb> )
313
*/
314
extern void InstallEqObject ( Int );
315
316
317
/****************************************************************************
318
**
319
320
*F LT( <opL>, <opR> ) . . . . . . . . . . . . . . comparison of two objects
321
**
322
** 'LT' returns a nonzero value if the object <opL> is less than the object
323
** <opR>, and zero otherwise.
324
*/
325
#define LT(opL,opR) ((opL) == (opR) ? 0 : \
326
(ARE_INTOBJS(opL,opR) ? (Int)(opL) < (Int)(opR) : \
327
(*LtFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR)))
328
329
#define LT2(opL,opR) ((opL) == (opR) ? 0 : \
330
(*LtFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR))
331
332
extern Obj LtOper;
333
334
335
/****************************************************************************
336
**
337
*V LtFuncs[<typeL>][<typeR>] . . . . . . . . . . table of comparison methods
338
*/
339
extern CompaMethod LtFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
340
341
342
/****************************************************************************
343
**
344
*F InstallLtObject( <verb> )
345
*/
346
extern void InstallLtObject ( Int );
347
348
349
/****************************************************************************
350
**
351
352
*F IN( <opL>, <opR> ) . . . . . . . . . . . membership test of two objects
353
**
354
** 'IN' returns a nonzero value if the object <opL> is a member of the
355
** object <opR>, and zero otherwise.
356
*/
357
#define IN(opL,opR) ((*InFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR))
358
359
extern Obj InOper;
360
361
362
/****************************************************************************
363
**
364
*V InFuncs[<typeL>][<typeR>] . . . . . . . . . . table of membership methods
365
*/
366
extern CompaMethod InFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
367
368
369
/****************************************************************************
370
**
371
*F InstallInObject( <verb> )
372
*/
373
extern void InstallInObject ( Int );
374
375
376
/****************************************************************************
377
**
378
379
*F * * * * * * * * * * * binary arithmetic operations * * * * * * * * * * * *
380
*/
381
382
/****************************************************************************
383
**
384
385
*F SUM( <opL>, <opR> ) . . . . . . . . . . . . . . . . . sum of two objects
386
**
387
** 'SUM' returns the sum of the two objects <opL> and <opR>.
388
**
389
** At places where performance matters one should use the following code
390
**
391
** if ( ! ARE_INTOBJS( <opL>, <opR> )
392
** || ! SUM_INTOBJS( <res>, <opL>, <opR> ) )
393
** <res> = SUM( <opL>, <opR> );
394
*/
395
#define SUM(opL,opR) ((*SumFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR))
396
397
extern Obj SumOper;
398
399
400
/****************************************************************************
401
**
402
*V SumFuncs[<typeL>][<typeR>] . . . . . . . . . . . . table of sum methods
403
*/
404
extern ArithMethod2 SumFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
405
406
407
/****************************************************************************
408
**
409
*F InstallSumObject( <verb> )
410
*/
411
extern void InstallSumObject ( Int );
412
413
414
/****************************************************************************
415
**
416
*F C_SUM( <val>, <left>, <right> ) . . . . . . . . . . . . . . . compute sum
417
*/
418
#define C_SUM(val,left,right) \
419
val = SUM( left, right );
420
421
422
/****************************************************************************
423
**
424
*F C_SUM_FIA( <val>, <left>, <right> ) . . . . . compute sum, fast integers
425
*/
426
#define C_SUM_FIA(val,left,right) \
427
if ( ! ARE_INTOBJS(left,right) || ! SUM_INTOBJS(val,left,right) ) { \
428
val = SUM( left, right ); \
429
}
430
431
432
/****************************************************************************
433
**
434
*F C_SUM_INTOBJS( <val>, <left>, <right> ) . . . compute sum of two integers
435
*/
436
#define C_SUM_INTOBJS(val,left,right) \
437
if ( ! SUM_INTOBJS(val,left,right) ) { \
438
val = SUM( left, right ); \
439
}
440
441
442
/****************************************************************************
443
**
444
445
*F DIFF( <opL>, <opR> ) . . . . . . . . . . . . . difference of two objects
446
**
447
** 'DIFF' returns the difference of the two objects <opL> and <opR>.
448
**
449
** At places where performance matters one should use the following code
450
**
451
** if ( ! ARE_INTOBJS( <opL>, <opR> )
452
** || ! DIFF_INTOBJS( <res>, <opL>, <opR> ) )
453
** <res> = DIFF( <opL>, <opR> );
454
*/
455
#define DIFF(opL,opR) ((*DiffFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR))
456
457
extern Obj DiffOper;
458
459
460
/****************************************************************************
461
**
462
*V DiffFuncs[<typeL>][<typeR>] . . . . . . . . . table of difference methods
463
*/
464
extern ArithMethod2 DiffFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
465
466
467
/****************************************************************************
468
**
469
*F InstallDiffObject( <verb> )
470
*/
471
extern void InstallDiffObject ( Int );
472
473
474
/****************************************************************************
475
**
476
*F C_DIFF( <val>, <left>, <right> ) . . . . . . . . . . . . . compute diff
477
*/
478
#define C_DIFF(val,left,right) \
479
val = DIFF( left, right );
480
481
482
/****************************************************************************
483
**
484
*F C_DIFF_FIA( <val>, <left>, <right> ) . . . . compute diff, fast integers
485
*/
486
#define C_DIFF_FIA(val,left,right) \
487
if ( ! ARE_INTOBJS(left,right) || ! DIFF_INTOBJS(val,left,right) ) { \
488
val = DIFF( left, right ); \
489
}
490
491
492
/****************************************************************************
493
**
494
*F C_DIFF_INTOBJS( <val>, <left>, <right> ) . compute diff of two integers
495
*/
496
#define C_DIFF_INTOBJS(val,left,right) \
497
if ( ! DIFF_INTOBJS(val,left,right) ) { \
498
val = DIFF( left, right ); \
499
}
500
501
502
/****************************************************************************
503
**
504
505
*F PROD( <opL>, <opR> ) . . . . . . . . . . . . . . product of two objects
506
**
507
** 'PROD' returns the product of the two objects <opL> and <opR>.
508
**
509
** At places where performance matters one should use the following code
510
**
511
** if ( ! ARE_INTOBJS( <opL>, <opR> )
512
** || ! PROD_INTOBJS( <res>, <opL>, <opR> ) )
513
** <res> = PROD( <opL>, <opR> );
514
*/
515
#define PROD(opL,opR) ((*ProdFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR))
516
517
extern Obj ProdOper;
518
519
520
/****************************************************************************
521
**
522
*V ProdFuncs[<typeL>][<typeR>] . . . . . . . . . . table of product methods
523
*/
524
extern ArithMethod2 ProdFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
525
526
527
/****************************************************************************
528
**
529
*F InstallProdObject( <verb> )
530
*/
531
extern void InstallProdObject ( Int );
532
533
534
/****************************************************************************
535
**
536
*F C_PROD( <val>, <left>, <right> ) . . . . . . . . . . . . compute product
537
*/
538
#define C_PROD(val,left,right) \
539
val = PROD( left, right );
540
541
542
/****************************************************************************
543
**
544
*F C_PROD_FIA( <val>, <left>, <right> ) . . compute product, fast integers
545
*/
546
#define C_PROD_FIA(val,left,right) \
547
if ( ! ARE_INTOBJS(left,right) || ! PROD_INTOBJS(val,left,right) ) { \
548
val = PROD( left, right ); \
549
}
550
551
552
/****************************************************************************
553
**
554
*F C_PROD_INTOBJS( <val>, <left>, <right> ) compute product of two integers
555
*/
556
#define C_PROD_INTOBJS(val,left,right) \
557
if ( ! PROD_INTOBJS(val,left,right) ) { \
558
val = PROD( left, right ); \
559
}
560
561
562
/****************************************************************************
563
**
564
565
*F QUO( <opL>, <opR> ) . . . . . . . . . . . . . . . quotient of two objects
566
**
567
** 'QUO' returns the quotient of the object <opL> by the object <opR>.
568
*/
569
#define QUO(opL,opR) ((*QuoFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR))
570
571
extern Obj QuoOper;
572
573
574
/****************************************************************************
575
**
576
*V QuoFuncs[<typeL>][<typeR>] . . . . . . . . . . table of quotient methods
577
*/
578
extern ArithMethod2 QuoFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
579
580
581
/****************************************************************************
582
**
583
*F InstallQuoObject( <verb> )
584
*/
585
extern void InstallQuoObject ( Int );
586
587
588
/****************************************************************************
589
**
590
591
*F LQUO( <opL>, <opR> ) . . . . . . . . . . . left quotient of two operand
592
**
593
** 'LQUO' returns the left quotient of the object <opL> by the object <opR>.
594
*/
595
#define LQUO(opL,opR) ((*LQuoFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR))
596
597
extern Obj LQuoOper;
598
599
600
/****************************************************************************
601
**
602
*V LQuoFuncs[<typeL>][<typeR>] . . . . . . . table of left quotient methods
603
*/
604
extern ArithMethod2 LQuoFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
605
606
607
/****************************************************************************
608
**
609
*F InstallLQuoObject( <verb> )
610
*/
611
extern void InstallLQuoObject ( Int );
612
613
614
/****************************************************************************
615
**
616
617
*F POW( <opL>, <opR> ) . . . . . . . . . . . . . . . . power of two objects
618
**
619
** 'POW' returns the power of the object <opL> by the object <opL>.
620
*/
621
#define POW(opL,opR) ((*PowFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR))
622
623
extern Obj PowOper;
624
625
extern Obj PowDefault ( Obj opL, Obj opR );
626
627
628
/****************************************************************************
629
**
630
*V PowFuncs[<typeL>][<typeR>] . . . . . . . . . . . table of power methods
631
*/
632
extern ArithMethod2 PowFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
633
634
635
/****************************************************************************
636
**
637
*F InstallPowObject( <verb> )
638
*/
639
extern void InstallPowObject ( Int );
640
641
642
/****************************************************************************
643
**
644
645
*F COMM( <opL>, <opR> ) . . . . . . . . . . . . . commutator of two objects
646
**
647
** 'COMM' returns the commutator of the two objects <opL> and <opR>.
648
*/
649
#define COMM(opL,opR) ((*CommFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR))
650
651
extern Obj CommOper;
652
653
654
/****************************************************************************
655
**
656
*V CommFuncs[<typeL>][<typeR>] . . . . . . . . . table of commutator methods
657
*/
658
extern ArithMethod2 CommFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
659
660
661
/****************************************************************************
662
**
663
*F InstallCommObject( <verb> )
664
*/
665
extern void InstallCommObject ( Int );
666
667
668
/****************************************************************************
669
**
670
671
*F MOD( <opL>, <opR> ) . . . . . . . . . . . . . . remainder of two objects
672
**
673
** 'MOD' returns the remainder of the object <opL> by the object <opR>.
674
*/
675
#define MOD(opL,opR) ((*ModFuncs[TNUM_OBJ(opL)][TNUM_OBJ(opR)])(opL,opR))
676
677
extern Obj ModOper;
678
679
680
/****************************************************************************
681
**
682
*V ModFuncs[<typeL>][<typeR>] . . . . . . . . . table of remainder methods
683
*/
684
extern ArithMethod2 ModFuncs [LAST_VIRTUAL_TNUM+1][LAST_VIRTUAL_TNUM+1];
685
686
687
/****************************************************************************
688
**
689
*F InstallModObject( <verb> )
690
*/
691
extern void InstallModObject ( Int );
692
693
694
/****************************************************************************
695
**
696
697
*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *
698
*/
699
700
/****************************************************************************
701
**
702
703
*F InitInfoAriths() . . . . . . . . . . . . . . . . table of init functions
704
*/
705
StructInitInfo * InitInfoAriths ( void );
706
707
708
#endif // GAP_ARITHS_H
709
710
/****************************************************************************
711
**
712
713
*E ariths.h . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
714
*/
715
716