File: GaussianIntegers.mpt

package info (click to toggle)
mathpiper 0.81f%2Bsvn4469%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 36,572 kB
  • sloc: java: 57,479; lisp: 13,721; objc: 1,300; xml: 988; makefile: 114; awk: 95; sh: 38
file content (44 lines) | stat: -rw-r--r-- 1,575 bytes parent folder | download | duplicates (13)
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

NextTest("Gaussian Integers");

/* TestGaussianFactors: test if Gaussian Factors Really works!
Computes in r the product of the factors, and checks if each
one is a Gaussian prime and if r is associated to z (i.e. if r/z
is a Gaussian Unit */
TestGaussianFactors(z_IsGaussianInteger) <--
[
 Local(r,gfactors,Ok);
// Echo("TestGaussianFactors: factoring ",z);
 gfactors := GaussianFactors(z);
// Echo(gfactors);
 Ok := True;
 r :=1;
 ForEach(p,gfactors)
 [
  r  := r*p[1]^p[2];
  Ok := Ok And IsGaussianPrime(p[1]);
 ];
// Echo(r);
 Ok := Ok And IsGaussianUnit(r/z);
 If(Ok,True,Echo("FAILED: GaussianFactors(", z, ")=", gfactors, " which is wrong."));
];

TestGaussianFactors((9!)+1);
TestGaussianFactors(2+3*I);
TestGaussianFactors(-1+2*I);
TestGaussianFactors(17);
TestGaussianFactors(41);

Verify(GaussianFactors(157+28*I), {{Complex(5,2),1},{Complex(-29,6),1}});
Verify(GaussianFactors(1), {});	// is this the correct behavior? why not {{}} or {{1,1}}?
Verify(GaussianFactors(-1), {});	// is this the correct behavior?
Verify(GaussianFactors(I), {});	// is this the correct behavior?
Verify(GaussianFactors(0), {});	// is this the correct behavior?
Verify(GaussianFactors(2), {{Complex(1,1),1},{Complex(1,-1),1}});
Verify(GaussianFactors(-2), {{Complex(1,1),1},{Complex(1,-1),1}});
Verify(GaussianFactors(3), {{3,1}});
Verify(GaussianFactors(3*I), {{3,1}});
Verify(GaussianFactors(4), {{Complex(1,1),2},{Complex(1,-1),2}});
Verify(GaussianFactors(-5*I), {{Complex(2,1),1},{Complex(2,-1),1}});
Verify(GaussianFactors(Complex(1,1)^11*163^4),{{Complex(1,1),11},{163,4}});