1 | #include "mod2.h" |
---|
2 | |
---|
3 | #ifdef HAVE_VANISHING_IDEAL |
---|
4 | |
---|
5 | #include "structs.h" |
---|
6 | #include "polys.h" |
---|
7 | #include "ideals.h" |
---|
8 | #include "VanishingIdeal.h" |
---|
9 | #include "FactoredNumber.h" |
---|
10 | |
---|
11 | using namespace std; |
---|
12 | |
---|
13 | ideal gBForVanishingIdealDirect (const bool printOperationDetails) |
---|
14 | { |
---|
15 | ideal iii = idInit(1, 0); |
---|
16 | idInsertPoly(iii, pISet(17)); // will include po only if it is not the zero polynomial |
---|
17 | idSkipZeroes(iii); // remove zero generators (resulting from block-wise allocation of memory) |
---|
18 | return iii; |
---|
19 | } |
---|
20 | |
---|
21 | ideal gBForVanishingIdealRecursive (const bool printOperationDetails) |
---|
22 | { |
---|
23 | ideal iii = idInit(1, 0); |
---|
24 | idInsertPoly(iii, pISet(3)); // will include po only if it is not the zero polynomial |
---|
25 | idSkipZeroes(iii); // remove zero generators (resulting from block-wise allocation of memory) |
---|
26 | return iii; |
---|
27 | } |
---|
28 | |
---|
29 | poly normalForm (const poly f, const bool printOperationDetails) |
---|
30 | { |
---|
31 | poly p = NULL; |
---|
32 | return p; |
---|
33 | } |
---|
34 | |
---|
35 | bool isZeroFunction (const poly f, const bool printOperationDetails) |
---|
36 | { |
---|
37 | printf("\nFactoredNumber(%d) = %s\n", 1, FactoredNumber(1).toString()); |
---|
38 | printf("\nFactoredNumber(%d) = %s\n", 5, FactoredNumber(5).toString()); |
---|
39 | printf("\nFactoredNumber(%d) = %s\n", 10, FactoredNumber(10).toString()); |
---|
40 | printf("\nFactoredNumber(%d) = %s\n", 50, FactoredNumber(50).toString()); |
---|
41 | printf("\nFactoredNumber(%d) = %s\n", 128, FactoredNumber(128).toString()); |
---|
42 | printf("\nFactoredNumber(%d) = %s\n", -1, FactoredNumber(2, 64).toString()); |
---|
43 | return false; |
---|
44 | } |
---|
45 | |
---|
46 | /* expects a >= 1, b >= 1 */ |
---|
47 | int helper_gcd (const int a, const int b) |
---|
48 | { |
---|
49 | if ((a == 1) || (b == 1)) return 1; |
---|
50 | int m = (a > b) ? a : b; |
---|
51 | int n = (a > b) ? b : a; |
---|
52 | int temp = 0; |
---|
53 | /* m >= n */ |
---|
54 | while ((n != 1) && (n != 0)) |
---|
55 | { |
---|
56 | temp = m - n; |
---|
57 | m = (temp > n) ? temp : n; |
---|
58 | n = (temp > n) ? n : temp; |
---|
59 | } |
---|
60 | if (n == 1) return 1; |
---|
61 | if (n == 0) return m; |
---|
62 | } |
---|
63 | |
---|
64 | /* expects m >= 1 */ |
---|
65 | int smarandache (const int m, const bool printOperationDetails) |
---|
66 | { |
---|
67 | /* naive algorithm */ |
---|
68 | int lambda = 1; |
---|
69 | int factorial = 1; |
---|
70 | int mm = m; |
---|
71 | int temp = 0; |
---|
72 | int multCounter = 0; |
---|
73 | int gcdCounter = 0; |
---|
74 | int divCounter = 0; |
---|
75 | while (factorial % mm != 0) |
---|
76 | { |
---|
77 | lambda++; |
---|
78 | factorial = factorial * lambda; multCounter++; |
---|
79 | temp = helper_gcd(mm, factorial); gcdCounter++; |
---|
80 | mm = mm / temp; divCounter++; |
---|
81 | factorial = factorial / temp; divCounter++; |
---|
82 | } |
---|
83 | if (printOperationDetails) |
---|
84 | { |
---|
85 | printf("\nperformed operations:\n int-int-multiplications: %d,\n int-int-gcd's: %d,\n int-int-divisions: %d.\n\n", |
---|
86 | multCounter, gcdCounter, divCounter); |
---|
87 | } |
---|
88 | return lambda; |
---|
89 | } |
---|
90 | |
---|
91 | #endif |
---|
92 | /* HAVE_VANISHING_IDEAL */ |
---|