1 | /*****************************************************************************\ |
---|
2 | * Computer Algebra System SINGULAR |
---|
3 | \*****************************************************************************/ |
---|
4 | /** @file misc_ip.h |
---|
5 | * |
---|
6 | * This file provides miscellaneous functionality. |
---|
7 | * |
---|
8 | * ABSTRACT: This file provides the following miscellaneous functionality: |
---|
9 | * - prime factorisation of bigints with prime factors < 2^31 |
---|
10 | * (This will require at most 256 MByte of RAM.) |
---|
11 | * - approximate square root of a bigint |
---|
12 | * |
---|
13 | * Most of the functioanlity implemented here had earlier been |
---|
14 | * coded in SINGULAR in some library. Due to performance reasons |
---|
15 | * these algorithms have been moved to the C/C++ kernel. |
---|
16 | * |
---|
17 | * @author Frank Seelisch, Oleksandr Motsak |
---|
18 | * |
---|
19 | * @internal @version \$Id$ |
---|
20 | * |
---|
21 | **/ |
---|
22 | /*****************************************************************************/ |
---|
23 | |
---|
24 | #ifndef MISC_H |
---|
25 | #define MISC_H |
---|
26 | |
---|
27 | #include <misc/auxiliary.h> |
---|
28 | #include <coeffs/coeffs.h> |
---|
29 | |
---|
30 | #include <kernel/structs.h> |
---|
31 | #include <coeffs/si_gmp.h> |
---|
32 | |
---|
33 | #include <Singular/lists.h> |
---|
34 | |
---|
35 | /** |
---|
36 | * Divides 'n' as many times as possible by 'd' and returns the number |
---|
37 | * of divisions (without remainder) in 'times', |
---|
38 | * e.g., n = 48, d = 4, divTimes(n, d, t) = 3 produces n = 3, t = 2, |
---|
39 | * since 48 = 4*4*3; |
---|
40 | * assumes that d is positive |
---|
41 | **/ |
---|
42 | void divTimes(mpz_t n, /**< [in] a GMP number >= 0 */ |
---|
43 | mpz_t d, /**< [in] the divisor, a GMP number >= 0 */ |
---|
44 | int* times /**< [out] number of divisions without remainder */ |
---|
45 | ); |
---|
46 | |
---|
47 | /** |
---|
48 | * Factorises a given bigint number n into its prime factors less |
---|
49 | * than or equal to a given bound, with corresponding multiplicities. |
---|
50 | * |
---|
51 | * The method finds all prime factors with multiplicities. If a positive |
---|
52 | * bound is given, then only the prime factors <= pBound are being found. |
---|
53 | * In this case, there may remain an unfactored portion m of n. |
---|
54 | * Also, when n is negative, m will contain the sign. If n is zero, m will |
---|
55 | * be zero. |
---|
56 | * The method returns a list L filled with four entries: |
---|
57 | * L[1] a list; L[1][i] contains the i-th prime factor of |n| as int or |
---|
58 | * bigint (sorted in ascending order), |
---|
59 | * L[2] a list; L[2][i] contains the multiplicity of L[1, i] in |n| as int |
---|
60 | * L[3] contains the remainder m as int or bigint, depending on the size, |
---|
61 | * L[4] 1 iff |m| is probably a prime, 0 otherwise |
---|
62 | * |
---|
63 | * We thus have: n = L[1][1]^L[2][1] * ... * L[1][k]^L[2][k] * L[1], where |
---|
64 | * k is the number of mutually distinct prime factors (<= a provided non- |
---|
65 | * zero bound). |
---|
66 | * Note that for n = 0, L[2] and L[3] will be emtpy lists and L[4] will be |
---|
67 | * zero. |
---|
68 | * |
---|
69 | * @return the factorisation data in a SINGULAR-internal list |
---|
70 | **/ |
---|
71 | lists primeFactorisation( |
---|
72 | const number n, /**< [in] the bigint > 0 to be factorised */ |
---|
73 | const number pBound /**< [in] bigint bound on the prime factors |
---|
74 | seeked */ |
---|
75 | ); |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | #ifdef PDEBUG |
---|
80 | #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) |
---|
81 | // #include <polys/polys.h> |
---|
82 | /* Needed for debug Version of p_SetRingOfLeftv, Oliver */ |
---|
83 | void p_SetRingOfLeftv(leftv l, ring r); |
---|
84 | #endif |
---|
85 | #endif |
---|
86 | |
---|
87 | #endif |
---|
88 | /* MISC_H */ |
---|