[go: up one dir, main page]

Menu

[9a0086]: / man / man3 / Fraction.3  Maximize  Restore  History

Download this file

621 lines (618 with data), 7.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
.TH "fraction" 3 "Mar 12, 2023"
.SH Fraction
.PP
.B
Inherits from:
CAObject
.PP
.B
Maturity Index:
Relatively immature
.SH Class Description
.PP
Fraction objects consist of a
.I
numerator
object divided by a
.I
denominator
object\&. The numerators and denominators can be arbitrary Computer Algebra Kit objects, but the current implementation has been tested only in the case of
.I
total
fractions i\&.e\&., numerators and denominators are taken as elements of the same set\&. For example, a fraction of two integers is a rational number; a fraction of two polynomials is a rational function\&.
.SH Canonical Form
.PP
The arithmetical operations on fractions assume that the fractions are in a simplified (canonical) form, and produce, as result, a fraction in canonical form\&. In the case of the integers, or any ordered, integral domain (see
.B
inIntegralDomain
and
.B
inOrderedSet
), the numerator and denominator are kept coprime (common gcd is divided out) and the denominator is kept positive\&. For example, the fraction minus one, is represented as (-1)/1, and never as 1/(-1)\&. In the case of an unordered, integral domain, such as polynomials over the integers or over a field, the denominator and numerator are also coprime, and the leading unit of the denominator is equal to one (over fields, this means that the denominator is kept monic, see
.B
leadingUnit
)\&. For example, the fraction minus
.I
x
is represented over
.B
Z
mod 3 as (2
.I
x
)/1 and not as
.I
x
/2\&. Finally, for rational functions with floating-point coefficients, no gcd is computed, but the denominator of the fraction is kept monic\&.
.SH Method types
.PP
.B
Creation
.RS 3
.br
* totalFraction:
.br
* numerator:denominator:
.br
* copy
.br
* deepCopy
.RE
.PP
.B
Identity
.RS 3
.br
* numerator
.br
* denominator
.br
* hash
.br
* isEqual:
.br
* compare:
.RE
.PP
.B
Coercion
.RS 3
.br
* asNumerical
.br
* asModp:
.br
* asIntegral
.RE
.PP
.B
Addition
.RS 3
.br
* zero
.br
* isZero
.br
* isOpposite:
.br
* negate
.br
* double
.br
* add:
.br
* subtract:
.RE
.PP
.B
Multiplication
.RS 3
.br
* one
.br
* isOne
.br
* isMinusOne
.br
* square
.br
* inverse
.br
* multiply:
.br
* divide:
.br
* power:
.RE
.PP
.B
Multiplication by Int Value
.RS 3
.br
* intValue:
.br
* intValue
.br
* multiplyIntValue:
.br
* divideIntValue:
.RE
.PP
.B
Printing
.RS 3
.br
* printsLeadingSign
.br
* printsSum
.br
* printsProduct
.br
* printOn:
.RE
.SH Methods
.PP
totalFraction:
.RS 1
+
.B
totalFraction
:
.I
aNumerator
.RE
.PP
Returns a new fraction with numerator set to
.I
aNumerator
and denominator set to the element one for
.I
aNumerator
\&.
.PP
numerator:denominator:
.RS 1
+
.B
numerator
:
.I
aNumerator
.B
denominator
:
.I
aDenominator
.RE
.PP
Returns a new fraction with numerator set to
.I
aNumerator
and denominator set to
.I
aDenominator
\&.
.PP
copy
.RS 1
-
.B
copy
.RE
.PP
Returns a new copy of the fraction\&.
.PP
deepCopy
.RS 1
-
.B
deepCopy
.RE
.PP
Returns a new copy of the fraction; sends
.B
deepCopy
messages to denominator and numerator\&.
.PP
numerator
.RS 1
-
.B
numerator
.RE
.PP
Returns
.I
a
for a fraction
.I
a
/
.I
b
\&.
.PP
denominator
.RS 1
-
.B
denominator
.RE
.PP
Returns
.I
b
for a fraction
.I
a
/
.I
b
\&.
.PP
hash
.RS 1
- (
unsigned
)
.B
hash
.RE
.PP
Returns a small integer that is the same for fractions that are equal in the sense of
.B
isEqual:
\&.
.PP
isEqual:
.RS 1
- (
BOOL
)
.B
isEqual
:
.I
b
.RE
.PP
Two fractions are equal if they are pointer equal, or if their numerators and denominators are equal\&. If the numerators and denominators are coprime, but not ordered, the method returns YES if numerators and denominators are opposite to each other\&. If the fraction is not in canonical form, it is verified that the difference of the two fractions is zero\&.
.PP
compare:
.RS 1
- (
int
)
.B
compare
:
.I
b
.RE
.PP
Compares the fractions by comparing the products of numerators and denominators\&.
.PP
asNumerical
.RS 1
-
.B
asNumerical
.RE
.PP
Returns the numerical value of the fraction\&. Attempts to divide the numerical value of the numerator and denominator\&.
.PP
asModp:
.RS 1
-
.B
asModp
:(unsigned short)
.I
p
.RE
.PP
Returns the value of the fraction modulo
.I
p
\&. Attempts to divide the values of the numerator and denominator\&. If the division fails, the method generates an error message\&.
.PP
asIntegral
.RS 1
-
.B
asIntegral
.RE
.PP
Returns, if the denominator of the fraction is equal to one, a new reference to the numerator\&. Otherwise, the method generates an error message\&.
.PP
zero
.RS 1
-
.B
zero
.RE
.PP
Returns a new fraction with numerator equal to zero\&.
.PP
isZero
.RS 1
- (
BOOL
)
.B
isZero
.RE
.PP
Whether the numerator of the fraction is equal to zero\&.
.PP
isOpposite:
.RS 1
- (
BOOL
)
.B
isOpposite
:
.I
b
.RE
.PP
Two fractions are opposite if their numerators are opposite and the denominators are equal\&. However, if the numerators and denominators are coprime, but not ordered, the method returns YES if the numerators are equal and the denominators are opposite to each other\&. If the fraction is not in canonical form, it is verified that the sum of the two fractions is zero\&.
.PP
negate
.RS 1
-
.B
negate
.RE
.PP
Returns a new fraction, the opposite of
.B
self
by negating the numerator\&.
.PP
double
.RS 1
-
.B
double
.RE
.PP
Returns a new fraction, the double of
.B
self
by doubling the numerator\&.
.PP
add:
.RS 1
-
.B
add
:
.I
b
.RE
.PP
Returns a new fraction, the sum of
.B
self
and
.I
b
\&. The method first handles some special cases and then distinguishes between the case that both fractions have a common denominator or not\&.
.PP
subtract:
.RS 1
-
.B
subtract
:
.I
b
.RE
.PP
Returns a new fraction, the difference of
.B
self
and
.I
b
\&. The method first handles some special cases and then distinguishes between the case that both fractions have a common denominator or not\&.
.PP
one
.RS 1
-
.B
one
.RE
.PP
Returns a new fraction with numerator equal to one\&.
.PP
isOne
.RS 1
- (
BOOL
)
.B
isOne
.RE
.PP
Whether the numerator is equal to the denominator\&.
.PP
isMinusOne
.RS 1
- (
BOOL
)
.B
isMinusOne
.RE
.PP
Whether the numerator is the opposite of the denominator\&.
.PP
square
.RS 1
-
.B
square
.RE
.PP
Returns a new fraction; squares numerator and denominator\&.
.PP
inverse
.RS 1
-
.B
inverse
.RE
.PP
Returns the inverse of the fraction; interchanges, in the case of a total fraction, denominator and numerator\&.
.PP
multiply:
.RS 1
-
.B
multiply
:
.I
b
.RE
.PP
Returns a new fraction; multiplies the numerators and the denominators together\&.
.PP
divide:
.RS 1
-
.B
divide
:
.I
b
.RE
.PP
Returns a new fraction by multiplying the fraction by the inverse of
.I
b
\&.
.PP
power:
.RS 1
-
.B
power
:(int)
.I
n
.RE
.PP
Returns a new fraction; raises numerator and denominator to the
.I
n
-th power\&.
.PP
intValue:
.RS 1
-
.B
intValue
:(int)
.I
intValue
.RE
.PP
Creates a fraction with numerator equal to
.I
intValue
and denominator one\&.
.PP
intValue
.RS 1
- (
int
)
.B
intValue
.RE
.PP
Returns intValue of numerator divided by intValue of denominator\&.
.PP
multiplyIntValue:
.RS 1
-
.B
multiplyIntValue
:(int)
.I
intValue
.RE
.PP
Returns a new fraction by multiplying the numerator by
.I
intValue
\&.
.PP
divideIntValue:
.RS 1
-
.B
divideIntValue
:(int)
.I
intValue
.RE
.PP
Returns a new fraction by multiplying the denominator by
.I
intValue
\&.
.PP
printsLeadingSign
.RS 1
- (
BOOL
)
.B
printsLeadingSign
.RE
.PP
Whether the fraction prints a leading minus sign\&.
.PP
printsSum
.RS 1
- (
BOOL
)
.B
printsSum
.RE
.PP
Whether the fraction prints as a sum\&.
.PP
printsProduct
.RS 1
- (
BOOL
)
.B
printsProduct
.RE
.PP
Whether the fraction prints as a product\&.
.PP
printOn:
.RS 1
-
.B
printOn
:(IOD)
.I
aFile
.RE
.PP
Prints the fraction to
.I
aFile
by sending
.B
printOn:
messages to numerator and denominator\&.