Subset relation judgment method based on logarithmic prime number coding
By using a logarithmic prime encoding method, the overflow and computational complexity issues in prime product subset judgment are resolved, achieving efficient and accurate set relationship judgment, which is suitable for large-scale set operations and data processing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HARBIN ENG UNIV
- Filing Date
- 2025-12-23
- Publication Date
- 2026-05-12
AI Technical Summary
In existing technologies, prime product type subset determination methods suffer from problems such as data overflow risk, high computational complexity, low parallelization efficiency, and difficulty in efficient implementation under floating-point systems.
A method based on logarithmic prime number encoding is adopted. By assigning a unique prime number to each element of the set, calculating and accumulating the natural logarithm, using floating-point operations to replace integer division, and introducing dynamic adaptive tolerance to determine set relationships.
It effectively solves the integer overflow problem, significantly improves computing performance and parallel processing capabilities, and ensures efficient and high-precision set relationship judgment in the floating-point system.
Smart Images

Figure CN122018853A_ABST
Abstract
Description
Technical Field
[0001] It involves large-scale set operations and data processing, especially efficient methods for determining subset relationships. Background Technology
[0002] In fields such as reliability engineering, system security analysis, data mining, and artificial intelligence, set operations are among the most fundamental computational forms. The rapid determination of inclusion relationships (i.e., subset relationships) between sets is a core step in various computational tasks, including system modeling, feature extraction, cut-set simplification, pattern recognition, and database retrieval. Particularly in scenarios such as fault tree analysis (FTA), cut-set solving, minimum cut-set selection, set feature compression, and high-dimensional feature combination analysis, systems often need to handle inclusion relationship determinations between tens of thousands of sets, and computational efficiency directly determines the overall algorithm performance.
[0003] In existing technologies, researchers have proposed various set encoding and subset determination schemes, which mainly include the following categories: Boolean vector-based set representation method This type of method maps all elements of the set sequentially to the bits of a Boolean vector, and uses logical operations such as "AND", "OR", and "NOT" to determine the relationship between sets. This method has a clear structure and is easy to implement, but as the size of the set increases, the dimension of the Boolean vector increases sharply, occupying a large amount of storage space. Furthermore, it is difficult to perform vector comparisons and bitwise operations efficiently in large-scale parallel computing, resulting in a significant decrease in computational efficiency.
[0004] Encoding methods based on hashing or bitset compression To reduce the storage overhead of Boolean vectors, some studies employ hash mapping or bitset compression techniques to quickly determine set relationships by calculating element hash values or bitmasks. However, hash algorithms can lead to collisions, lack strict uniqueness, and cannot achieve precise inclusion determination between sets; while bitset compression can reduce space complexity to some extent, it incurs significant overhead for decoding and comparison across different platforms (CPU / GPU).
[0005] A unique encoding method based on prime number product In the field of reliability engineering, the prime product method is a classic set coding scheme. Its basic principle is to use the fundamental theorem of arithmetic to assign a unique prime number to each element in the universal set; a set is then represented as the product of these prime numbers. To determine whether set A is a subset of set B, it is only necessary to verify whether the code of B is divisible by the code of A. This method possesses good mathematical uniqueness and logical simplicity, and is therefore widely used in applications such as cut-set analysis, combinatorial reliability calculation, and data dependency determination.
[0006] Although the prime number product encoding method possesses elegant mathematical properties in theory, it reveals significant computational bottlenecks and accuracy issues in engineering implementation. Specifically: The product of prime numbers grows extremely fast. When the set contains a large number of elements, the product result will exceed the representation range of conventional integer data types (such as 64-bit integers), leading to numerical overflow problems. To resolve overflow, a high-precision large number library is needed for multiplication and division operations. However, large number operations rely entirely on software-level simulation, which is far less efficient than native hardware instructions. In particular, performance drops significantly in high-concurrency or GPU environments. Integer division is a highly complex operation, with a single instruction often requiring tens of times the time of multiplication or addition. Therefore, integer division significantly reduces the computational efficiency of an algorithm. To improve efficiency, some studies have attempted to reduce computational load through modulo partitioning, segmented integer division, and hash verification. However, these methods have not fundamentally solved the overflow and performance bottleneck problems caused by product-type encoding. Furthermore, they still involve a trade-off between maintaining mathematical uniqueness and computational accuracy, failing to simultaneously achieve speed, accuracy, and implementation simplicity.
[0007] In summary, existing methods for determining prime product subsets suffer from drawbacks such as data overflow risk, high computational complexity, low parallelization efficiency, and difficulty in efficient implementation under floating-point systems. Summary of the Invention
[0008] To address the shortcomings of existing methods for determining prime product subsets, such as data overflow risk, high computational complexity, low parallelization efficiency, and difficulty in efficient implementation on floating-point systems, the present invention provides the following technical solution: A subset relation determination method based on logarithmically converted prime number encoding includes: The steps are: to determine the entire set of problems to be processed, to assign a unique prime number to each basic element in the entire set, to establish a prime number mapping table, and to output prime number index data for subsequent set encoding. Based on the prime number mapping table, the steps are as follows: find the corresponding prime number number for each basic element in the input set, calculate the natural logarithm of each prime number and accumulate them to obtain the logarithmic code representing the characteristics of the set and output the logarithmic code data. The steps are: receiving log-encoded data of two sets and calculating their difference to obtain the logarithmic difference representing the ratio of the prime product of the two sets, and outputting the difference data; The logarithmic difference is subjected to exponential restoration to obtain the restoration result, and the result is rounded to obtain an integer candidate value. The integer candidate value is then output for subsequent judgment steps. The steps include calculating the deviation between the logarithmic difference and the corresponding logarithm of the integer candidate value, comparing it with the dynamic adaptive tolerance, and determining that the previous set is a subset of the next set when the deviation is less than the tolerance threshold, and outputting the judgment result.
[0009] Furthermore, a preferred implementation is provided in which the basic elements of the entire set are sorted in a predetermined order when establishing the prime number mapping table, and are sequentially assigned starting from the smallest prime number, so that each basic element has a one-to-one correspondence with a unique prime number number.
[0010] Furthermore, a preferred implementation is provided in which, during the logarithmic encoding process, the natural logarithm of prime numbers is pre-calculated and cached as a high-precision floating-point number, and the cached data is directly called through an index during encoding.
[0011] Furthermore, a preferred implementation is provided in which a pairwise summation algorithm or a compensated summation algorithm is used when calculating the logarithmic encoding of the set.
[0012] Furthermore, a preferred embodiment is provided in which the integer candidate value obtained by rounding the exponential restoration result of the logarithmic difference is used as the theoretical estimate of the multiple relationship between sets, and is used in subsequent steps to determine the inclusion relationship between sets.
[0013] Furthermore, a preferred implementation is provided, wherein the dynamic adaptive tolerance is automatically adjusted according to the magnitude of the exponential restoration result. When the exponential result is large, the tolerance threshold decreases, and when the exponential result is small, the tolerance threshold increases.
[0014] Based on the same inventive concept, the present invention also provides a subset relation determination device based on logarithmically converted prime number encoding, comprising: A module that determines the entire set of problems to be processed, assigns a unique prime number to each basic element in the entire set, establishes a prime number mapping table, and outputs prime number index data for subsequent set encoding. Based on the prime number mapping table, the module finds the corresponding prime number number for each basic element in the input set, calculates the natural logarithm of each prime number and accumulates them to obtain the logarithmic code representing the characteristics of the set and outputs the logarithmic code data. This module receives log-encoded data from two sets, calculates their difference to obtain the logarithmic difference representing the ratio of the prime product of the two sets, and outputs the difference data. The module performs an exponential restoration operation on the logarithmic difference to obtain the restoration result, and performs a rounding operation on the result to obtain an integer candidate value. The module outputs the integer candidate value for subsequent judgment. The module calculates the deviation between the logarithmic difference and the corresponding logarithm of the integer candidate value, compares it with the dynamic adaptive tolerance, and determines that the previous set is a subset of the next set when the deviation is less than the tolerance threshold, and outputs the judgment result.
[0015] Based on the same inventive concept, the present invention also provides a computer storage medium for storing a computer program, wherein when the computer program is read by a computer, the computer executes the method described thereon.
[0016] Based on the same inventive concept, the present invention also provides a computer, including a processor and a storage medium, wherein when the processor reads a computer program stored in the storage medium, the computer executes the method described thereon.
[0017] Based on the same inventive concept, the present invention also provides a computer program product, which, when executed, implements the method described.
[0018] Compared with the prior art, the advantages of the technical solution provided by the present invention are as follows: This scheme effectively solves the integer overflow problem by transforming the traditional prime product encoding into a logarithmic summation encoding. Traditional methods, when dealing with a large number of elements in the set, result in exponentially increasing prime product values, easily exceeding the range of integer representation. This scheme, however, linearizes the exponential growth by taking the natural logarithm of the prime numbers and summing them, ensuring the encoded result always remains within the range representable by floating-point numbers. Through this logarithmic mapping, this scheme preserves the uniqueness of prime number encoding while completely eliminating the overflow risk in high-dimensional set computations, achieving safe computation at standard 64-bit floating-point precision. Compared to traditional schemes that rely on high-precision, large datasets, this improvement not only reduces storage costs but also significantly improves data scalability.
[0019] This scheme replaces integer division with floating-point arithmetic, significantly improving computational performance. Existing prime product encoding methods rely on large number division operations for subset determination, which cannot be accelerated by CPU instruction sets. This scheme, however, replaces integer division with floating-point subtraction and exponent restoration, allowing subset determination to be performed entirely on hardware floating-point units. Since floating-point addition and subtraction are typically hundreds of times faster than software-simulated division, this method greatly improves computational efficiency. Compared to existing large number division algorithms, this scheme not only has a shorter execution time but also achieves high parallelism on GPUs and multi-core platforms, making it particularly suitable for batch determination tasks involving large sets.
[0020] This scheme effectively improves the precision of floating-point operations by introducing a pairwise summation algorithm into logarithmic calculations. Because floating-point addition suffers from accumulated rounding errors, ordinary addition can lead to precision loss when dealing with a large number of elements in the set. This scheme minimizes the error propagation path by accumulating pairs of elements and merging them layer by layer, ensuring stable and reliable results. Compared to conventional linear summation, pairwise summation improves the numerical stability of the results without significantly increasing computational cost, guaranteeing the accuracy of subset determination, and demonstrating significant advantages, especially when dealing with complex sets containing thousands of basic events.
[0021] This scheme introduces a dynamic adaptive tolerance mechanism to ensure stable and reliable judgment results across different numerical scales. Traditional fixed threshold methods cannot balance accuracy and tolerance in both small and large sets, while this scheme automatically adjusts the tolerance range based on the magnitude of the exponential reduction result, making the error judgment standard non-linearly change with the numerical scale. This adaptive tolerance strategy matches floating-point error control with the characteristics of logarithmic function variation, thus maintaining high-precision judgment results across different computational scales. Compared to fixed threshold judgment, this method effectively reduces the false positive rate and ensures the robustness of the algorithm in engineering-level reliability analysis.
[0022] This fully floating-point implementation further enhances the algorithm's scalability and versatility. By basing encoding, difference calculation, exponent restoration, and comparison entirely on floating-point operations, this solution avoids any integer multiplication and division operations, making the entire process naturally compatible with parallel acceleration platforms such as GPUs and FPGAs. Compared to traditional integer division-based algorithms, this implementation achieves high-precision judgments without requiring external large number libraries or additional hardware modules. This not only simplifies the program structure but also significantly reduces deployment costs and cross-platform portability, demonstrating excellent engineering applicability and scalability.
[0023] It is suitable for tasks that require quickly determining set inclusion relationships in reliability analysis, cut set solving, data mining, and large-scale set computation. Attached Figure Description
[0024] Figure 1 The overall process of the representation method. Detailed Implementation
[0025] To make the advantages and benefits of the technical solution provided by the present invention clearer, the technical solution provided by the present invention will now be described in further detail with reference to the accompanying drawings, specifically: Implementation Method 1: This implementation method provides a subset relation determination method based on logarithmically converted prime number encoding, including: The steps are: to determine the entire set of problems to be processed, to assign a unique prime number to each basic element in the entire set, to establish a prime number mapping table, and to output prime number index data for subsequent set encoding. Based on the prime number mapping table, the steps are as follows: find the corresponding prime number number for each basic element in the input set, calculate the natural logarithm of each prime number and accumulate them to obtain the logarithmic code representing the characteristics of the set and output the logarithmic code data. The steps are: receiving log-encoded data of two sets and calculating their difference to obtain the logarithmic difference representing the ratio of the prime product of the two sets, and outputting the difference data; The logarithmic difference is subjected to exponential restoration to obtain the restoration result, and the result is rounded to obtain an integer candidate value. The integer candidate value is then output for subsequent judgment steps. The steps include calculating the deviation between the logarithmic difference and the corresponding logarithm of the integer candidate value, comparing it with the dynamic adaptive tolerance, and determining that the previous set is a subset of the next set when the deviation is less than the tolerance threshold, and outputting the judgment result.
[0026] When establishing a prime number mapping table, the basic elements of the entire set are sorted in a predetermined order and assigned sequentially starting from the smallest prime number, so that each basic element has a one-to-one correspondence with a unique prime number number.
[0027] During the logarithmic encoding process, the natural logarithm of prime numbers is pre-calculated and cached as a high-precision floating-point number, and the cached data is directly called through the index during encoding.
[0028] When calculating the logarithmic encoding of a set, a pairwise summation algorithm or a compensated summation algorithm is used.
[0029] The integer candidate value obtained by rounding the exponential restoration result of the logarithmic difference is used as the theoretical estimate of the multiple relationship between sets, and is used in subsequent steps to determine the inclusion relationship between sets.
[0030] The dynamic adaptive tolerance is automatically adjusted based on the magnitude of the exponential restoration result. When the exponential result is large, the tolerance threshold decreases, and when the exponential result is small, the tolerance threshold increases.
[0031] Implementation Method Two: This implementation method is a further detailed description of the technical solution provided in Implementation Method One, specifically: First, determine the complete set of the problem to be processed and establish a prime number mapping table. Depending on the specific application scenario, determine the set of all basic elements that could appear in any set. For example, in system reliability analysis, basic elements could be failure events of various components; in data mining, they could be feature terms or keywords. Arrange these basic elements in a predetermined order (e.g., lexicographical or numbered order), assigning a unique prime number number to each element, starting with the smallest prime number. For example, the first element corresponds to prime number 2, the second to prime number 3, the third to prime number 5, and so on, until all elements in the complete set have been assigned a prime number, forming a one-to-one prime number mapping table. This table is the foundation of the entire encoding and judgment process, used to map the logical relationships in the set to computable numerical relationships in subsequent steps. To improve the system's portability and scalability, this mapping table can be stored in a database or memory structure as key-value pairs for fast lookup and indexing. The output prime number mapping table serves as the input basis for subsequent logarithmic encoding.
[0032] Then, each set is logarithmically encoded based on a prime number mapping table. For any input set, the system first iterates through each element and retrieves the unique prime number corresponding to that element from the prime number mapping table. Then, the natural logarithm of that prime number is performed, and the logarithmic values corresponding to all elements are summed. The sum is the logarithmic encoded value of the set. Because the natural logarithm has the mathematical property of transforming a product relationship into an addition relationship, this encoding process transforms the exponential growth form of traditional prime number products into a linear summation form, fundamentally avoiding the problem of large number overflow. To further improve computational efficiency, the natural logarithmic values of all prime numbers can be pre-calculated and stored as high-precision floating-point numbers during system initialization, so that they can be directly called during encoding without repeated calculations. To prevent cumulative bias introduced by floating-point rounding errors when summing a large number of elements, this step uses a paired summation algorithm or a Kahan compensated summation algorithm during the accumulation process. The pairwise summation method improves overall accuracy by adding adjacent numbers first and then merging them in layers, thus balancing the distribution of rounding errors. The Kahan summation algorithm introduces an error compensation variable to ensure that each addition operation offsets the impact of previous rounding errors as much as possible. These optimizations guarantee high accuracy and repeatability of the logarithmic encoded values even with large sets and a large number of elements. The logarithmic encoded value of each output set is used for subsequent subset determination.
[0033] Next, two sets whose inclusion relationship needs to be determined are input, and their logarithmic encoding values are compared. Taking sets A and B as an example, to determine whether set A is a subset of set B, the difference between their logarithmic encoding values is calculated, i.e., the logarithmic encoding of set B is subtracted from the logarithmic encoding of set A. This difference reflects the logarithmic result of the ratio of the prime product of the two sets in the logarithmic field. Since logarithmic subtraction is mathematically equivalent to division between the original products, this operation transforms the complex integer division relationship into a floating-point subtraction operation. Compared with traditional large number division judgment, this floating-point difference-based method can be executed directly by the hardware floating-point unit, increasing the speed by tens of times. The output of this step is the logarithmic difference between the two sets, providing input data for subsequent exponentiation restoration and error judgment.
[0034] Subsequently, the obtained logarithmic difference is exponentially restored to obtain the quotient. The system inputs the logarithmic difference into an exponential function to calculate its corresponding exponent value, which theoretically should be the quotient of the prime product of set B and set A. When set A is a subset of set B, the exponent value should be an integer or a floating-point value very close to an integer. Due to the slight error in floating-point calculations, to determine whether the value truly corresponds to an integer, the system performs a rounding operation on the calculation result to obtain the closest integer candidate value. This integer candidate value represents the prime product relationship corresponding to the elements in set B that are more numerous than those in set A. To avoid the computational burden of large numbers caused by exponential operations, the difference between the exponent result and its rounding result can be used to indirectly determine whether it is an integer, without having to explicitly calculate the extremely large exponent result value. Through this indirect judgment method, high-precision determination can be achieved without introducing large amounts of data. The output of this step is the integer candidate value and its logarithm, which are used for subsequent tolerance judgment.
[0035] Then, the deviation between the actual logarithmic difference and the candidate logarithms is calculated, and the subset relationship is determined according to the tolerance standard. The system calculates the absolute difference between the original logarithmic difference and the corresponding logarithm of the rounded integer candidate value, and compares it with the preset error tolerance. If the difference is less than the tolerance threshold, it means that the difference between the exponent restoration result and the integer candidate value is only caused by floating-point rounding error, so set A can be considered a subset of set B. If the difference is greater than the tolerance threshold, it means that the difference exceeds the normal floating-point error range, and set A is not a subset of set B. To enhance the robustness of the algorithm, this invention proposes a dynamic adaptive tolerance mechanism. This mechanism automatically adjusts the tolerance range according to the numerical value of the exponent restoration result. When the exponent result is large, the tolerance range is correspondingly reduced to ensure judgment accuracy; when the exponent result is small, the tolerance range is moderately widened to prevent overly strict misjudgment. This adaptive strategy utilizes the characteristic that the logarithmic function tends to flatten in the large value range and is sensitive to changes in the small value range to automatically adjust the judgment standard, so that the algorithm has good numerical stability at different orders of magnitude. The output clearly indicates whether a subset relationship exists between two sets.
[0036] Finally, the aforementioned subset relationship judgment process is applied to the analysis and screening of large-scale set data. It can be used for rapid screening of minimum cut sets in system reliability analysis, for removing redundant features or duplicate samples in data mining and set classification tasks, and for efficient inclusion relationship matching in database or knowledge graph retrieval. The entire algorithm is implemented entirely based on floating-point operations, avoiding the overflow risk caused by integer multiplication and division, and can be executed in parallel on GPU, FPGA, or multi-core CPU platforms, significantly improving computational throughput and response speed. This method not only maintains the mathematical rigor brought by the uniqueness of prime number encoding, but also combines the efficiency of the floating-point system, achieving a balance between high precision and high performance, ensuring excellent reliability and practical value in subset relationship judgment tasks of large-scale complex systems.
[0037] Implementation Method 3: Combination Figure 1 This embodiment describes the technical solution provided above in further detail through specific examples. Specifically: A subset relation determination method based on logarithmically converted prime number encoding includes the following steps: Step 1: Assign a unique prime number to each element in the set and establish a prime number mapping table. For example, for "High-pressure safety pump A failed to start", "Common cause valve B failed to open", or "Sensor D malfunctions", assign a unique prime number sequentially from the prime number sequence (2, 3, 5, 7, ...) as its identifier. This process will generate a complete mapping table; Step 2: Represent each set as the sum of the natural logarithms of the prime numbers corresponding to the basic events it contains, and construct the logarithmic encoding of the set; Step 3: Compare the difference between the logarithmic codes of the two sets, and determine whether the exponent of the difference can be considered a non-zero integer under a certain criterion. If it is within a set error tolerance, the subset relationship is considered valid. When this implementation needs to determine whether a second-order cut set (e.g., A = {pump A failure, valve B failure}) is a subset of a more complex third-order cut set (B = {pump A failure, valve B failure, sensor D failure}), this implementation no longer needs to compare elements one by one. Instead, this implementation directly calculates the difference between their logarithmic codes. According to the properties of logarithms, this difference is actually equal to the natural logarithm of the prime number corresponding to the additional failure event ("sensor D failure"). Therefore, this implementation performs an exponential operation (e to the power of e) on this difference, which theoretically can accurately restore the prime number. Considering that computer floating-point operations may have small errors, this implementation only needs to determine whether the result of this exponential operation is equal to a known prime number (or the product of several prime numbers) within a very small error tolerance. If the condition is true, it proves that set A is indeed a subset of set B, thus determining that set B is a non-minimum cut set and should be removed from the final result. This step transforms complex logical reasoning into an efficient floating-point operation and comparison.
[0038] To further understand this embodiment, the subset relationship judgment method based on logarithmic prime number encoding provided in this embodiment will be described in detail below with reference to the embodiments. The protection scope of this embodiment is not limited by the following embodiments.
[0039] Example 1 Taking two sets with an inclusion relationship as an example, the overall process of the subset relationship determination method based on logarithmic prime number encoding is as follows: Figure 1 As shown, it includes the following steps: Step 1: This step is fundamental to the entire encoding and judgment method. First, it is necessary to determine the complete set of the problem to be processed, that is, the set of all basic elements that can appear in any subset. The meaning of basic elements varies in different application scenarios. For example, in fault tree analysis, this complete set is the set of all basic events that could lead to the top event, which is the cut set.
[0040] Secondly, each elementary event in the universal set is uniquely identified and assigned a unique prime number. The most direct and easily implemented way is to sort all elementary events in a defined order (e.g., lexicographical order of their identifiers in the system), and then, starting with the smallest prime number 2, assign the prime numbers 2, 3, 5, 7, 11,... in ascending order to the sorted elementary events. For example, the set {a1, a2, a3, a4} corresponds to the prime numbers {2, 3, 5, 7}. This assignment method ensures that each elementary event corresponds to one and only one prime number, and vice versa, satisfying the requirement of uniqueness.
[0041] Step 2: This step aims to map the product of prime numbers representing set information into a floating-point summation computation domain through logarithmic transformation, thereby avoiding computational overflow problems that may be caused by the product of large numbers while preserving the uniqueness of the set.
[0042] Specifically, for any given cut set, the construction process of its logarithmic code is as follows: First, traverse every elementary event within the cut set; second, using the prime number mapping table established in step 1, find the unique prime number corresponding to each elementary event; next, perform a natural logarithmic operation on each found prime number; finally, sum the natural logarithmic values of the prime numbers corresponding to all elementary events within the cut set, and the sum is the unique logarithmic code of this cut set. For example, the logarithmic code of the set {a1,a2,a3,a4} (corresponding to prime number numbers {2,3,5,7}) is: .
[0043] To further improve computational efficiency, in the specific implementation, the high-precision floating-point natural logarithmic values of all prime numbers in the prime number mapping table are pre-calculated and stored in a lookup table or cache structure. Thus, when constructing the logarithmic encoding, the corresponding data is directly retrieved from the table using the element position as an index and then directly accumulated. This replaces time-consuming logarithmic function calls with efficient memory read operations, significantly accelerating the encoding process.
[0044] Furthermore, to ensure the computational accuracy of logarithmic encoding, especially when the cut set contains a large number of elements, the floating-point accumulation operation employs compensated summation algorithms, such as pairwise summation or the Kahan summation algorithm. These algorithms effectively reduce the accumulated errors caused by rounding operations in floating-point arithmetic, ensuring that the final generated logarithmic code has sufficiently high accuracy.
[0045] Step 3: This step is crucial in determining whether cut set A is a subset of cut set B. The fundamental mathematical principle is that if and only if cut set A is a subset of cut set B, the product of prime numbers P(B) of B is divisible by the product of prime numbers P(A) of A, and the quotient P(B) / P(A) is an integer. If A is not a subset of B, then the quotient must be a non-integer rational number. However, in computer floating-point arithmetic, this implementation method cannot directly perform a perfect divisibility check. The formula used in this implementation method utilizes logarithms and rounding operations to provide a highly robust test of this "integer property" in a floating-point environment.
[0046] The specific implementation process is as follows, taking the subset determination of set A{a1,a2} and set B{a1,a2,a3} as an example: Step 3.1 Calculate the logarithmic difference (i.e., the ratio of the logarithmic fields): First, obtain the logarithmic codes of set A and set B. L ( A )and L ( B Calculate their difference. According to the logarithmic rule, this value is equivalent to log(P(B) / P(A)), which is the logarithm of the quotient of the product of the prime numbers of the two cut sets. For example, set A{a1,a2} and set B{a1,a2,a3}, L ( A =log6≈1.791759, L ( B =log30≈3.401197, L_diff= .
[0047] Step 3.2: Restore the quotient. Restore the logarithmic difference L_diff using exponential operations (exp) to obtain the quotient value Ratio= The resulting Ratio value, if A is a subset of B, may be a floating-point number very close to an integer due to floating-point error. For example, Ratio = .
[0048] Step 3.3: Find the nearest integer candidate. Perform a rounding operation on the quotient Ratio: I = round(Ratio). The purpose of this step is to find the integer (still a floating-point number) that is closest to the current calculation result. For example, I = round( =5.
[0049] Step 3.4: Generate the logarithm of the integer candidate. Take the natural logarithm of this integer candidate I to get L_candidate=log(I), for example, log5=1.609437.
[0050] Step 3.5: Determine if the deviation is within the tolerance. Finally, compare the original logarithmic difference L_diff calculated in Step 1 with the candidate logarithm L_candidate generated in Step 2.3. Calculate the absolute difference between them and determine if this difference is less than a preset error tolerance used to control floating-point precision. .if If the original quotient ratio is very close to an integer, then cut set A is determined to be a subset of cut set B. This indicates that the original quotient ratio is very close to an integer, and the small difference between them can be attributed to normal floating-point errors in the calculation process. Otherwise, it is determined that there is no subset relationship between them. This indicates that there is a significant difference between the original quotient ratio and the nearest integer, and this difference cannot be explained by floating-point errors; its essence is that P(B) is not divisible by P(A). For example, L_diff = L_candidate=1.609437: It is important to note here that the purpose of this step is to determine whether the actual value corresponding to exp(L_diff) is an integer. However, this implementation does not actually calculate the value of exp(L_diff). Directly calculating exp(L_diff) would result in an extremely large number, which is precisely the problem this implementation aims to avoid. The solution in this implementation is to utilize a mathematical shortcut: to determine whether a number is an integer, this implementation only needs to check whether its decimal part is zero. In practice, this implementation can directly obtain the decimal part of the exp(L_diff) result by performing a simple standard floating-point operation on the value L_diff itself (e.g., using a function like modf), thus completely bypassing the calculation of its integer part.
[0051] Based on the above fixed tolerance Based on the existing methods, this embodiment provides a more advanced and robust preferred embodiment. This approach abandons fixed... Instead, a tolerance range is dynamically generated based on the magnitude of the numerical value itself, thereby adapting to the precision requirements of different numerical values in the logarithmic domain.
[0052] The core idea of this scheme is to use the "most likely integer" derived in reverse from L(B)-L(A) as an anchor point to define a small neighborhood in the integer field, and then map this neighborhood back to the logarithmic field to form a dynamic, non-linear tolerance.
[0053] The specific implementation process is as follows: Define a neighborhood in the integer domain. Around The rounded integer I is assigned a small integer neighborhood. The size of this neighborhood is determined by a configurable parameter 'a'. The boundaries of this neighborhood are: lower bound: I_lower = Ia; upper bound: I_upper = I + a. For example, let a = 0.005, I_lower = 4.995, and I_upper = 5.005. The significance of this neighborhood is that, in this implementation, a deviation of ±a is allowed in the final theoretical integer result due to floating-point cumulative errors.
[0054] Next, the integer neighborhood is mapped back to the logarithmic domain. The two boundary points of the integer neighborhood are mapped back to the logarithmic coordinate system using the natural logarithm (log) operation, thus forming the final adaptive dynamic tolerance interval: [log(I_lower),log(I_upper)].
[0055] Finally, an interval judgment is performed to determine whether the original logarithmic difference L_diff calculated in step 3.5 falls within the constructed dynamic tolerance interval. If log(Ia) ≤ L_diff ≤ log(I+a), then cut set A is determined to be a subset of cut set B. Otherwise, it is determined that there is no subset relationship between them. For example... For L_diff calculated in step 3.1 We can see that it falls within the above interval, therefore A can be judged as a subset of B.
[0056] The size of the tolerance interval (I_upper - I_lower) is no longer based on a fixed value. Instead, it decreases naturally as I increases. This perfectly matches the characteristics of the logarithmic function: the value of log(x) gradually flattens out as x increases. Therefore, for larger values, the judgment criteria automatically become more stringent; for smaller values, a reasonable tolerance is preserved.
[0057] The above description of several specific embodiments further details the technical solution provided by the present invention in order to highlight the advantages and benefits of the technical solution provided by the present invention. However, the above-described specific embodiments are not intended to limit the present invention. Any reasonable modifications and improvements to the present invention, combinations of embodiments, and equivalent substitutions based on the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A subset relation determination method based on logarithmically converted prime number encoding, characterized in that, include: The steps are: to determine the entire set of the problem to be processed, to assign a unique prime number to each basic element in the entire set, to establish a prime number mapping table, and to output the prime number index data for subsequent set encoding. Based on the prime number mapping table, the steps are as follows: find the corresponding prime number number for each basic element in the input set, calculate the natural logarithm of each prime number and accumulate them to obtain the logarithmic code representing the characteristics of the set and output the logarithmic code data. The steps are: receiving log-encoded data of two sets and calculating their difference to obtain the logarithmic difference representing the ratio of the prime product of the two sets, and outputting the difference data; The logarithmic difference is subjected to exponential restoration to obtain the restoration result, and the result is rounded to obtain an integer candidate value. The integer candidate value is then output for subsequent judgment steps. The steps include calculating the deviation between the logarithmic difference and the corresponding logarithm of the integer candidate value, comparing it with the dynamic adaptive tolerance, and determining that the previous set is a subset of the next set when the deviation is less than the tolerance threshold, and outputting the judgment result.
2. The subset relation determination method based on logarithmic prime number encoding according to claim 1, characterized in that, When establishing a prime number mapping table, the basic elements of the entire set are sorted in a predetermined order and assigned sequentially starting from the smallest prime number, so that each basic element has a one-to-one correspondence with a unique prime number number.
3. The subset relation determination method based on logarithmic prime number encoding according to claim 1, characterized in that, During the logarithmic encoding process, the natural logarithm of prime numbers is pre-calculated and cached as a high-precision floating-point number, and the cached data is directly called through the index during encoding.
4. The subset relation determination method based on logarithmic prime number encoding according to claim 1, characterized in that, When calculating the logarithmic encoding of a set, a pairwise summation algorithm or a compensated summation algorithm is used.
5. The subset relation determination method based on logarithmic prime number encoding according to claim 1, characterized in that, The integer candidate value obtained by rounding the exponential restoration result of the logarithmic difference is used as the theoretical estimate of the multiple relationship between sets, and is used in subsequent steps to determine the inclusion relationship between sets.
6. The subset relation determination method based on logarithmic prime number encoding according to claim 1, characterized in that, The dynamic adaptive tolerance is automatically adjusted based on the magnitude of the exponential restoration result. When the exponential result is large, the tolerance threshold decreases, and when the exponential result is small, the tolerance threshold increases.
7. A subset relation determination device based on logarithmically encoded prime numbers, characterized in that, include: A module that determines the entire set of problems to be processed, assigns a unique prime number to each basic element in the entire set, establishes a prime number mapping table, and outputs prime number index data for subsequent set encoding; Based on the prime number mapping table, the module finds the corresponding prime number number for each basic element in the input set, calculates the natural logarithm of each prime number and accumulates them to obtain the logarithmic code representing the characteristics of the set and outputs the logarithmic code data. This module receives log-encoded data from two sets, calculates their difference to obtain the logarithmic difference representing the ratio of the prime product of the two sets, and outputs the difference data. The module performs an exponential restoration operation on the logarithmic difference to obtain the restoration result, and performs a rounding operation on the result to obtain an integer candidate value. The module outputs the integer candidate value for subsequent judgment. The module calculates the deviation between the logarithmic difference and the corresponding logarithm of the integer candidate value, compares it with the dynamic adaptive tolerance, and determines that the previous set is a subset of the next set when the deviation is less than the tolerance threshold, and outputs the judgment result.
8. A computer storage medium for storing computer programs, characterized in that, When the computer program is read by the computer, the computer executes the method of claim 1.
9. A computer, comprising a processor and a storage medium, characterized in that, When the processor reads the computer program stored in the storage medium, the computer executes the method of claim 1.
10. A computer program product, as a computer program, is characterized by: When the computer program is executed, it implements the method of claim 1.