File: binaryfactors.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 (64 lines) | stat: -rw-r--r-- 1,921 bytes parent folder | download | duplicates (4)
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


TestPoly(poly,requiredResult):=
[
//Echo(poly);
  Local(realResult);
  realResult:=BinaryFactors(poly);
  Verify(Length(realResult),Length(requiredResult));

//Echo(requiredResult,realResult);
  Local(intersection);
  intersection:={};
  ForEach(item1,requiredResult)
    ForEach(item2,realResult)
    [
      If(Simplify(item1-item2) = {0,0},
        intersection := (item1:intersection));
    ];
  Verify(Length(realResult),Length(intersection/*Intersection(requiredResult,realResult)*/));
  Verify(Simplify(poly-FW(realResult)),0);
];

// Simple factorizations
TestPoly((x+1)*(x-1),{{x+1,1},{x-1,1}});

// Simple with multiple factors
TestPoly((x+1)^2,{{x+1,2}});

// Test: term with lowest power not zero power
TestPoly(x^2*(x+1)*(x-1),{{x,2},{x+1,1},{x-1,1}});
TestPoly(x^3*(x+1)*(x-1),{{x,3},{x+1,1},{x-1,1}});

// Variable different from x
TestPoly((y+1)*(y-1),{{y+1,1},{y-1,1}});

// Test from Wester 1994 test
TestPoly(Differentiate(x)(x+1)^20,{{20,1},{x+1,19}});

// From regression test, and verify that polys with unfactorizable parts works
TestPoly((x^6-1),{{x^4+x^2+1,1},{x+1,1},{x-1,1}});

// Non-monic polynomials
TestPoly((x+13)^2*(3*x-5)^3,{{27,1},{x+13,2},{x-5/3,3}});
TestPoly((x+13)^2*(4*x-5)^3,{{64,1},{x+13,2},{x-5/4,3}});

// Heavy: binary coefficients
TestPoly((x+1024)*(x+2048),{{x+1024,1},{x+2048,1}});
TestPoly((x+1024)^2*(x+2048)^3,{{x+1024,2},{x+2048,3}});
TestPoly((16*x+1024)*(x+2048),{{16,1},{x+64,1},{x+2048,1}});
TestPoly((x+1024)*(x+2047),{{x+1024,1},{x+2047,1}});
TestPoly((x+1024)*(x+2049),{{x+1024,1},{x+2049,1}});

TestPoly((x+1024)*(x-2047),{{x+1024,1},{x-2047,1}});
TestPoly((x-1024)*(x+2047),{{x-1024,1},{x+2047,1}});
TestPoly((x-1024)*(x-2047),{{x-1024,1},{x-2047,1}});

// Rational coefficients
TestPoly((x+4/7)*(x-5/9),{{x+4/7,1},{x-5/9,1}});

// More than two factors ;-)
TestPoly((x+1)*(x-2)*(x+3)*(x-4)*(x+5)*(x-6),{{x+1,1},{x-2,1},{x+3,1},{x-4,1},{x+5,1},{x-6,1}});