Static iteration construction method and system for numerical expression type metamorphic relation

By constructing the edit distance matrix and backtracking rules, the static iterative construction of numerical expression-type metamorphic relationship is realized, which solves the problems of low efficiency and high cost in the existing technology, and improves the construction efficiency and quality of the metamorphic relationship.

CN119149392APending Publication Date: 2024-12-17HUANENG NUCLEAR ENERGY TECH RES INST CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411033864.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-30
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

The existing static iterative construction methods for numerical expression type metamorphism relationships are inefficient, and the composite initial MR method has a combination explosion problem. The dynamic method needs to execute the tested program and is costly, and the MR obtained by the data mining method is not reliable and time-consuming.

Method used

By obtaining numeric expression parameters, constructing an edit distance matrix, calculating expression similarity, constructing backtracking rules to obtain the initial set of metamorphic relationships, performing static iterative construction of numeric expression type metamorphic relationships, outputting a set of metamorphic relationships, using edit distance matrix and backtracking Rules do not need to execute the test program, reducing calculation time and cost.

Benefits of technology

The structure efficiency of the metamorphic relationship is improved, the structure of meaningless relationships for software testing is reduced, the number of participating in composite calculations is reduced, and the quality and structural efficiency of the metamorphic relationship are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149392A_ABST
    Figure CN119149392A_ABST
Patent Text Reader

Abstract

The invention discloses a static iteration construction method and system for a numerical expression type metamorphic relation, and relates to the technical field of software metamorphic tests.The static iteration construction method comprises the steps that numerical expression parameters are obtained to construct an editing distance matrix, and the similarity of numerical expression similarity analysis parameters is calculated; constructing a backtracking rule, and obtaining an editing operation for character string conversion by editing the distance matrix to obtain an initial metamorphic relation set; static iteration construction of the numerical expression type metamorphic relation is carried out, and a metamorphic relation set is output. According to the method, a tested program does not need to be executed through metamorphic relation compounding, calculation time consumption is reduced, the metamorphic relation construction cost is reduced, metamorphic relations which are meaningless to software testing are eliminated by utilizing the property of the numerical expression type metamorphic relation, the number of the metamorphic relations participating in compound calculation is reduced, and the metamorphic relation construction efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software metamorphosis testing, and in particular to a static iteration construction method and system for numerical expression type metamorphosis relations. Background Art

[0002] There are two core issues in software testing: the completeness of the test case set and the program correctness judgment mechanism. Software testing technology can be divided into traditional testing and non-traditional testing. The judgment mechanism of traditional testing technology is whether the program output is consistent with the expected result. When the expected value is difficult to construct and the acquisition cost is extremely high, the judgment mechanism fails. For example, this problem exists in scenarios such as nuclear reactor simulation, weapon detonation fluid simulation, and spacecraft space environment simulation. At the same time, traditional testing technology is only applicable to deterministic programs. When the results of multiple executions of the same set of inputs are not equal, the judgment mechanism will also fail. For example, this problem also exists in scenarios such as Monte Carlo calculations based on probability models, deep neural networks, and generative artificial intelligence.

[0003] Metamorphic Testing (MT) is a non-traditional testing technology. It is one of the effective technologies to alleviate the problem of expected value in software testing. It has broad application prospects in scenarios such as scientific computing and generative artificial intelligence. Metamorphic Relation (MR) is the core of metamorphic testing. According to the representation form, it is classified into numerical expression type, predicate expression type and others. Numerical expressions are expressions constructed using constants, variables, mathematical functions and operators. They are widely used in scientific research, engineering modeling and other fields.

[0004] The construction of metamorphosis relations is the core issue of MT. Although some MR generation technologies have emerged, it is still a huge challenge to construct MRs that are meaningful for software testing and defect detection. According to whether an initial MR is needed, the current MR construction methods can be divided into two categories: ① Compound initial MR, constructing a "new" MR, that is, compound MR (CMR); ② Mining MR from program execution data. Because the initial MR has been tested and generally originates from the properties of physical models, numerical algorithms, and program specifications, it is interpretable. Therefore, the MR obtained by the former is of better quality, while the MR identified by the latter is usually a likelihood MR, that is, the MR is only satisfactory on the current data set, is not interpretable, and has average quality. Moreover, in order to obtain execution data, the program under test needs to be executed multiple times, which is very time-consuming, so the construction efficiency is low.

[0005] The existing technology has the following technical problems: the composite initial MR method has low construction efficiency. For example, IMT has a combinatorial explosion problem, and obtaining code path coverage information requires executing the program under test; the data mining method obtains likelihood MR, which is not reliable and requires multiple executions of the program under test, resulting in low construction efficiency. The main problems of the existing MR construction method are: ① The dynamic method is used, which requires the execution of the program under test and has high construction cost; ② MRs that are meaningless to software testing are not excluded, resulting in low construction efficiency. Summary of the invention

[0006] In view of the problems existing in the existing static iterative construction method of numerical expression type metamorphic relation, the present invention is proposed. Therefore, the problem to be solved by the present invention is how to provide a static iterative construction method and system of numerical expression type metamorphic relation.

[0007] In order to solve the above technical problems, the present invention provides the following technical solutions:

[0008] In the first aspect, the present invention provides a static iterative construction method for a numerical expression type metamorphosis relationship, which includes obtaining numerical expression parameters to construct an edit distance matrix, and calculating the similarity of numerical expression similarity analysis parameters; constructing backtracking rules, obtaining editing operations for string conversion through the edit distance matrix, and obtaining an initial metamorphosis relationship set; performing static iterative construction of a numerical expression type metamorphosis relationship, and outputting a metamorphosis relationship set.

[0009] As a preferred solution of the static iterative construction method of the numerical expression type metamorphosis relationship described in the present invention, the numerical expression parameters include arithmetic operators, relational operators, variables, variable times and constants.

[0010] As a preferred solution of the static iterative construction method of the numerical expression type metamorphosis relationship described in the present invention, wherein: the construction of the edit distance matrix includes the following steps: obtaining a parameter set to convert all numerical expressions into a unified form; defining edit operations to construct an edit operation set, the edit operations are used to perform expression conversion, and the edit operations include inserting, deleting, replacing symbols, variables or constant values; constructing a two-dimensional matrix, calculating the minimum edit distance for each pair of expressions, each cell represents the minimum number of operations required to convert from the first i characters of the first expression to the first j characters of the second expression; filling the edit distance matrix, each element in the matrix represents the edit distance between expressions; assigning weights to different edit operations, and adjusting the weights of the edit operations to reflect the similarity of the expressions.

[0011] As a preferred solution of the static iterative construction method of the numerical expression type metamorphosis relation of the present invention, wherein: the calculation of the similarity of the numerical expressions includes the following steps: extracting parameters from each numerical expression, using a regular expression or a parser to identify the operators in the expression, and recording the type and position; comparing the similarity of the expressions in terms of parameters, and calculating the similarity of the expressions, the calculation formula is:

[0012]

[0013] Where Sim(S,T) is the similarity between expressions S and T, |S| and |T| represent the lengths of the two expression sequences respectively, and Dmn represents the edit distance from expression S to expression T. According to the similarity criterion of the expressions, the specific measurement method of the expression string of the input-output relationship is obtained.

[0014] As a preferred solution of the static iterative construction method of the numerical expression type metamorphosis relation described in the present invention, wherein: the edit distance includes the minimum number of edit operations required to convert the sequence S into the sequence t, the weight represents the edit distance of a single edit operation, and the edit distance of two sequences is the sum of the distances of all single edit operations; if a character is inserted into the expression sequence, the edit distance of the sequence for a single operation is the length of the inserted character; if a character is deleted from the expression sequence, the edit distance of the sequence for a single operation is the length of the deleted character; if a character in the expression sequence is replaced with other characters, the edit distance of the sequence for a single operation is the length of the replaced character; construct a string S = s1, s2 ... s m and T = t1, t2…t n The edit distance matrix is ​​L D ={D ij}, 0≤i≤m, 0≤j≤m, the edit distance matrix is ​​constructed as:

[0015]

[0016] Calculate the edit distance of the string, compare the two character sequences from left to right and record the edit distance D of each comparison ij , construct an edit distance matrix according to the weight of each symbol; obtain the edit distance of two character sequences, and the value of the edit distance is the element Dmn in the lower right corner of the edit distance matrix; after obtaining the edit distance matrix, obtain each editing operation of converting the string S to the string T by backtracking.

[0017] As a preferred solution of the static iterative construction method of the numerical expression type metamorphosis relation of the present invention, wherein: the backtracking rule includes backtracking from the element in the lower right corner of the edit distance matrix, and the backtracking rule is: when s i =tj When element D ij Then trace back to D in the edit distance matrix i-1,j-1 element; when s i ≠t j When element D ij Then trace back to D in the edit distance matrix i-1,j-1 , D i,j-1 , D i-1,j The smallest element in the set, if the edit distance has an element value equal to the value of the element, the priority is D. i-1,j-1 , D i,j-1 , D i-1,j .

[0018] As a preferred solution of the static iterative construction method of the numerical expression type metamorphic relationship of the present invention, wherein: the static iterative construction of the numerical expression type metamorphic relationship includes the following steps: randomly selecting a metamorphic relationship from the initial metamorphic relationship set as the root metamorphic relationship; calculating the similarity between the root metamorphic relationship and other metamorphic relationships in the metamorphic relationship set, the metamorphic relationship includes an input relationship and an output relationship, and performing the similarity calculation of the metamorphic relationship. The similarity calculation formula of the metamorphic relationship is,

[0019] V=αV r +βV R

[0020] Among them, V represents the similarity of the transformation relationship, V r Represents the similarity of the input relation of the transformation relation, V R The output relation similarity of the metamorphosis relation is represented, α and β are the weights of the input relation and the output relation respectively, and α+β=1; the metamorphosis relation whose similarity is less than the limit threshold is taken as the sub-metamorphosis relation, and the root metamorphosis relation and the sub-metamorphosis relation are compounded to obtain the first-generation composite metamorphosis relation; a metamorphosis relation is randomly selected from the first-generation composite metamorphosis relation set as the root metamorphosis relation, and the steps are repeated to obtain the second-generation composite metamorphosis relation; the static iterative construction of the metamorphosis relation is repeated until the shutdown condition is met, and the metamorphosis relation set is output.

[0021] In the second aspect, the present invention provides a static iterative construction system for a numerical expression type metamorphic relationship, which includes: an acquisition module, which is used to acquire numerical expression parameters to construct an edit distance matrix and calculate the similarity of numerical expression similarity analysis parameters; a conversion module, which is used to construct a backtracking rule, obtain the editing operation for string conversion through the edit distance matrix, and obtain an initial metamorphic relationship set; a construction module. It is used to perform static iterative construction of a numerical expression type metamorphic relationship and output a metamorphic relationship set.

[0022] In a third aspect, the present invention provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: when the processor executes the computer program, it implements the steps of a static iterative construction method of a numerical expression type transformation relationship.

[0023] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein: when the computer program is executed by a processor, the steps of a static iterative construction method of a numerical expression type metamorphosis relationship are implemented.

[0024] The beneficial effects of the present invention are that there is no need to execute the tested program through metamorphosis relationship compounding, which reduces the consumption of computing time and the cost of constructing metamorphosis relationships. The properties of numerical expression type metamorphosis relationships are used to exclude metamorphosis relationships that are meaningless to software testing, and the number of metamorphosis relationships involved in compound calculations is reduced to improve the construction efficiency of metamorphosis relationships. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0026] Figure 1 The flowchart is a static iterative construction method for the transformation relation of numerical expression type.

[0027] Figure 2 is the backtracking path graph of the edit distance algorithm matrix. DETAILED DESCRIPTION

[0028] In order to make the above-mentioned purposes, features and advantages of the present invention more understandable, the specific implementation methods of the present invention are described in detail below in conjunction with the drawings of the specification. Obviously, the described embodiments are part of the embodiments of the present invention, but not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary persons in the art without creative work should fall within the scope of protection of the present invention.

[0029] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.

[0030] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The term "in one embodiment" that appears in different places in this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive with other embodiments.

[0031] Example 1

[0032] Reference Figure 1 , which is the first embodiment of the present invention, and which provides a static iterative construction method of a numerical expression type metamorphosis relation, comprising:

[0033] S1: Obtain numerical expression parameters to construct an edit distance matrix and calculate the similarity of numerical expression similarity analysis parameters;

[0034] Specifically, the numerical expression parameters include various types of characters such as arithmetic operators, relational operators, variables, variable times, constants, etc., and each character has different functions and importance in the expression.

[0035] Therefore, in order to enable the algorithm to distinguish different types of characters and more accurately capture the differences between expressions, a weight is given to each edit operation based on the minimum edit operation: different values ​​are assigned according to their role and importance in the expression. The weight represents the edit distance of a single edit operation, and the edit distance of two sequences is the sum of the distances of all single edit operations.

[0036] According to the similarity criterion of expressions, the specific measurement method of the expression string of the input-output relationship is as follows: (1) Variables in the expression. Variables are all numerical variables and are of the same type. Therefore, the weight of the variable is 1, and the similarity of the variable is recorded as k. If the expression contains n variables, the variable similarity is k = n.

[0037] For example: r(x1, x2)|(x1+x2-2π=0), then the variable similarity is: k=2.

[0038] (2) The number of variables in the expression. In terms of calculating similarity, the more similar the number of individual variables is, the smaller the similarity is. Therefore, the weight of the number of variables is 1, and the similarity of the number of variables is recorded as p. If the sum of the number of variables in the transformation relationship is m, then the similarity of the number of variables is: p = m.

[0039] Example: r(x1, x2)|(x1 2 +x2-1=0), the variable order similarity is: p=3.

[0040] (3) Arithmetic operators. Since different arithmetic operations are implemented differently at the bottom layer of the computer, taking addition and subtraction operators as reference, the implementation of multiplication requires continuous addition and shift operations, while division requires continuous subtraction and shift operations. Therefore, the weight of the arithmetic operators '+' and '-' is 1; the weight of '*' and ' / ' is 2, and the similarity of the arithmetic operators is denoted as a. If there are m '+', '-'; n '*', ' / ' operators in the transformation relationship, then the similarity of the arithmetic operators is: a = m + 2n, (only the operators between variables and variables, and between variables and constants are considered, and the arithmetic operators between constants are not considered).

[0041] For example: r(x1, x2, x3, x4)|(x1+x2*x3+x4-1=0), its arithmetic operator similarity is: a=3+(2*1)=5.

[0042] (4) Relational operators. From the perspective of similarity relations, the relational operators of metamorphic relations are all used to compare the relationship between two expressions. Therefore, the weights of the relational operators '>', '<', '=', '≤', and '≥' are all 1. The similarity of the relational operators is denoted as o. If there are m '>', '<', '=', '≤', and '≥' in the expression, the similarity of the relational operators is: o=m.

[0043] For example: r(x1,x2,x3)|((x2-3x1=0)^(x3-5x1=0)), the complexity of its relational operator is: o=2.

[0044] (5) First-order logic connectives. First-order logic connectives are operations on expressions. Therefore, first-order logic connectives '∧', '∨', The weights of are all 1, denoted as c. If the transformation relation contains m first-order logic connectives, the similarity of the first-order logic connectives is: c = m.

[0045] Example: r(x1,x2,x3)|((x2-3x1=0)^(x3-5x1=0)), its first-order logical connective is: c=1.

[0046] (6) Constants have no weights

[0047] In summary, the lengths of the input relational expression strings S and T are:

[0048] |S|=|T|=k r +p r +a r +o r +c r

[0049] The lengths of the output relational expression strings S and T are:

[0050] |S|=|T|=k R +p R +a R +o R +c R

[0051] Take the parameter set and convert all numeric expressions to a uniform normalized form; for example, ensure that all binary operations are arranged in the same way (left-associative or right-associative) and remove redundant parentheses.

[0052] Define Edit Operations Construct a set of edit operations that can be used to transform from one expression to another. Common edit operations include inserting, deleting, replacing symbols or variables, changing the number of variables or constant values, etc.

[0053] For each pair of expressions, the minimum edit distance is computed, which typically involves constructing a two-dimensional matrix where each cell represents the minimum number of operations required to transform from the first i characters of the first expression to the first j characters of the second expression.

[0054] Fill the edit distance matrix to create an n×n matrix, where n is the number of expression sets. Each element (i,j) in the matrix represents the edit distance between the i-th expression and the j-th expression.

[0055] Assign weights or costs to different editing operations. For example, replacing an operator might cost more than replacing a variable, or changing the number of a variable might cost less than inserting a new variable.

[0056] The weights and cost functions of editing operations are adjusted to more accurately reflect the similarity of expressions in specific scenarios.

[0057] Extract parameters from each numeric expression, use regular expressions or parsers to identify operators in the expression, and record the type and position; Variables: Identify all variable names in the expression. Variable count: Count the number of times each variable appears in the expression. Constants: Identify and record all numeric constants.

[0058] With two expressions S = s1, s2, ..., s m , T=t1,t2,…,t n As an example, construct the edit distance matrix L D ={D ij}, 0≤i≤m, 0≤j≤m, compare the similarity of the expressions in terms of parameters, and calculate the similarity of the expressions. The calculation formula is:

[0059]

[0060] Where Sim(S,T) is the similarity between expression S and expression T, |S| and |T| represent the lengths of the two expression sequences, respectively, and Dmn represents the edit distance from expression S to expression T;

[0061] According to the similarity criterion of expressions, the specific measurement method of the expression string of the input-output relationship is obtained, and weights are assigned to the parameters, which reflect the importance of these parameters in the similarity of expressions.

[0062] S2: Constructing backtracking rules, obtaining the editing operations for string conversion through the edit distance matrix, and obtaining the initial metamorphosis relationship set;

[0063] Specifically, the edit distance includes the minimum number of edit operations required to convert sequence S into sequence T, the weight represents the edit distance of a single edit operation, and the edit distance of two sequences is the sum of the distances of all single edit operations;

[0064] If a character is inserted into the expression sequence, the edit distance of a single operation of the sequence is the length of the inserted character; if a character is deleted from the expression sequence, the edit distance of a single operation of the sequence is the length of the deleted character; if a character in the expression sequence is replaced with another character, the edit distance of a single operation of the sequence is the length of the replaced character;

[0065] Construct string S = s1, s2…s m and T = t1, t2…t n The edit distance matrix is ​​L D ={D ij}, 0≤i≤m, 0≤j≤m, the edit distance matrix is ​​constructed as follows:

[0066]

[0067] Calculate the edit distance of the string, compare the two character sequences from left to right and record the edit distance D of each comparison ij , construct the edit distance matrix according to the weight of each symbol;

[0068] The calculation strategy of the edit distance adopts the idea of ​​dynamic programming, comparing two character sequences from left to right and recording the edit distance D of each comparison. ij , according to the weight of each symbol to complete L D The establishment of the matrix finally obtains the edit distance of two character sequences, and the value of the edit distance is the matrix L D The lower right element Dmn.

[0069] After obtaining the edit distance matrix, each editing operation of converting string S into string T is obtained by backtracking.

[0070] S3: Perform static iterative construction of numerical expression type transformation relations and output a set of transformation relations.

[0071] Specifically, ① randomly select a metamorphosis relationship from the initial metamorphosis relationship set as the root metamorphosis relationship;

[0072] ② Calculate the similarity between the root metamorphosis relation and other metamorphosis relations in the metamorphosis relation set;

[0073] Because the transformation relationship is composed of input relationship and output relationship, the similarity between transformation relationships needs to consider a set of relationship pairs, specifically:

[0074] Similarity calculation: Assume that the similarity of the input relationship of the transformation relationship uses V r Indicates that the output relationship similarity uses V R The similarity of the transformation relationship is represented by V. Obviously, the value of V is related to V r With V R They are all related.

[0075] The similarity calculation formula of the metamorphosis relationship is as follows, where α and β are the input relationship and output relationship weights respectively verified by experiments, and α+β=1:

[0076] V=αV r +βV R

[0077] Perform input relationship similarity V r Calculation, the input relationship similarity calculation formula is as follows:

[0078]

[0079] Where S and T represent the strings encoded by the two input relational expressions, Dmn represents the edit distance between S and T, and |S| and |T| represent the lengths of the input relational expressions S and T, respectively.

[0080] Output relationship similarity V R Calculate and output the relationship similarity calculation formula as follows:

[0081]

[0082] Where S and T represent the strings encoded by the two output relational expressions, Dmn represents the edit distance between S and T, and |S| and |T| represent the lengths of the output relational expressions S and T, respectively.

[0083] ③ The metamorphosis relationship with similarity less than the threshold is regarded as the sub-metamorphosis relationship;

[0084] ④ The root metamorphosis relationship is compounded with the daughter metamorphosis relationship to obtain the first-generation compound metamorphosis relationship;

[0085] ⑤ Randomly select a metamorphosis relationship from the first-generation compound metamorphosis relationship set as the root metamorphosis relationship, repeat the steps to obtain the second-generation compound metamorphosis relationship;

[0086] ⑥ Repeat the above process until the shutdown condition is met and output the set of transformation relations.

[0087] Furthermore, the present embodiment also provides a static iterative construction system of a numerical expression type metamorphic relationship, including: an acquisition module, used to acquire numerical expression parameters to construct an edit distance matrix, and calculate the similarity of numerical expression similarity analysis parameters; a conversion module, used to construct a backtracking rule, obtain the editing operation for string conversion through the edit distance matrix, and obtain an initial metamorphic relationship set; a construction module. It is used to perform static iterative construction of a numerical expression type metamorphic relationship and output a metamorphic relationship set.

[0088] This embodiment also provides a computer device, which is suitable for the static iterative construction method of numerical expression type transformation relations, including: a memory and a processor; the memory is used to store computer executable instructions, and the processor is used to execute computer executable instructions to implement all or part of the steps of the method described in the embodiment of the present invention as proposed in the above embodiment.

[0089] This embodiment also provides a storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the method in any optional implementation of the above embodiment is executed. Wherein, the storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random Access Memory, referred to as SRAM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, referred to as EEPROM), erasable programmable read-only memory (Erasable Programmable Read-Only Memory, referred to as EPROM), programmable read-only memory (Programmable Red-Only Memory, referred to as PROM), read-only memory (Read-Only Memory, referred to as ROM), magnetic memory, flash memory, disk or optical disk.

[0090] The storage medium proposed in this embodiment and the data storage method proposed in the above embodiment belong to the same inventive concept. The technical details not fully described in this embodiment can be found in the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.

[0091] Example 2

[0092] Reference Figure 2 , which is the second embodiment of the present invention, and this embodiment provides a static iterative construction method of a numerical expression type metamorphosis relationship. In order to verify the beneficial effects of the present invention, scientific demonstration is carried out through economic benefit calculation and simulation experiments.

[0093] The calculation process of the edit distance assumes that the input transformation relationship r1(x1, x2)|(x1-2*x2+2π=0), r2(x1, x2)|(x1+x2-x3+2π=0), the string S='x1+x2-x3+2π=0', the string T='x1-2*x2+2π=0', and the matrix L D And its backtracking path is as follows Figure 2 As shown:

[0094] Depend on Figure 2 It can be seen that the edit distance between character S and string T is 6, and the three edit operations to convert string S to T are:

[0095] (1) Change the second character '+' in the string S to the character '-', and the resulting new string is 'x1-x2-x3+2π=0';

[0096] (2) Insert two characters '2*' before the third character 'x2' in the string 'x1-x2-x3+2π=0' to obtain a new string 'x1-2*x2-x3+2π=0';

[0097] (3) In the string 'x1-2*x2-x3+2π=0', delete the 6th and 7th characters '-x3' to obtain a new string 'x1-2*x2+2π=0'; this string is the same as the string T.

[0098] Table 1 Technical characteristics comparison table

[0099]

[0100] As can be seen from the above, this method can quantify the differences between different numerical expressions by constructing an edit distance matrix, which helps to identify code duplication and similarity and lays the foundation for subsequent metamorphosis relationship analysis. The measurement of the structural and semantic similarity of numerical expressions is achieved, which facilitates the identification and understanding of the evolution path of expressions in subsequent processing. By analyzing parameter similarity, it is possible to gain an in-depth understanding of the subtle differences between numerical expressions and help track the root causes of code changes in complex systems. Building backtracking rules can accurately identify and perform necessary editing operations to convert one numerical expression to another at minimal cost. It improves the accuracy and efficiency of code modification and also provides technical support for automated code review and repair. It helps developers predict future code change trends and provides decision support for continuous integration and version control.

[0101] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.

Claims

1. A static iterative construction method of a numerical expression type metamorphosis relation, characterized in that: include, Get the numerical expression parameters to construct the edit distance matrix and calculate the similarity of the numerical expression similarity analysis parameters; Construct backtracking rules, obtain the editing operations for string conversion through the edit distance matrix, and obtain the initial metamorphosis relationship set; Perform static iterative construction of transformation relations of numerical expression type and output a set of transformation relations.

2. The static iterative construction method of the numerical expression type metamorphosis relation according to claim 1, characterized in that: The numerical expression parameters include arithmetic operators, relational operators, variables, variable times and constants.

3. The static iterative construction method of the numerical expression type metamorphosis relation as claimed in claim 2, characterized in that: The construction of the edit distance matrix comprises the following steps: Get the parameter set and convert all numerical expressions into a unified form; Define edit operations to construct an edit operation set. Edit operations are used to transform expressions. Edit operations include inserting, deleting, and replacing symbols, variables, or constant values. Construct a two-dimensional matrix and calculate the minimum edit distance for each pair of expressions. Each cell represents the minimum number of operations required to convert the first i characters of the first expression to the first j characters of the second expression. Fill in the edit distance matrix, where each element in the matrix represents the edit distance between expressions; Assign weights to different editing operations, and adjust the weights of editing operations to reflect the similarity of expressions.

4. The static iterative construction method of the numerical expression type metamorphosis relation as claimed in claim 3, characterized in that: The calculation of the similarity of numerical expressions comprises the following steps: Extract parameters from each numerical expression, identify operators in the expression using regular expressions or parsers, and record the type and position; Compare the similarity of expressions in terms of parameters and calculate the similarity of expressions. The calculation formula is: Where Sim(S,T) is the similarity between expression S and expression T, |S| and |T| represent the lengths of the two expression sequences, respectively, and Dmn represents the edit distance from expression S to expression T; According to the similarity criterion of the expression, a specific measurement method of the expression string of the input-output relationship is obtained.

5. The static iterative construction method of the numerical expression type metamorphosis relation as claimed in claim 4, characterized in that: The edit distance includes the minimum number of edit operations required to convert sequence S into sequence T. The weight represents the edit distance of a single edit operation. The edit distance of two sequences is the sum of the distances of all single edit operations. If a character is inserted into the expression sequence, the edit distance of a single operation of the sequence is the length of the inserted character; If a character is deleted from the expression sequence, the edit distance of a single operation of the sequence is the length of the deleted character; If the characters in the expression sequence are replaced with other characters, the edit distance of a single operation of the sequence is the length of the replaced characters; Construct string S = s1, s2…s m and T = t1, t2…t n The edit distance matrix is ​​L D ={D ij }, 0≤i≤m, 0≤j≤m, the edit distance matrix is ​​constructed as: Calculate the edit distance of the string, compare the two character sequences from left to right and record the edit distance D of each comparison ij , construct the edit distance matrix according to the weight of each symbol; Get the edit distance between two character sequences. The value of the edit distance is the element Dmn in the lower right corner of the edit distance matrix. After obtaining the edit distance matrix, each editing operation of converting string S into string T is obtained by backtracking.

6. The static iterative construction method of the numerical expression type metamorphosis relation according to claim 5, characterized in that: The backtracking rule includes backtracking from the element in the lower right corner of the edit distance matrix. The backtracking rule is: when s i =t j When element D ij Then trace back to D in the edit distance matrix i-1,j-1 element; When i ≠t j When element D ij Then trace back to D in the edit distance matrix i-1,j-1 , D i,j-1 , D i-1,j The smallest element in the set, if the edit distance has an element value equal to the value of the element, the priority is D. i-1,j-1 , D i,j-1 , D i-1,j .

7. The static iterative construction method of the numerical expression type metamorphosis relation according to claim 6, characterized in that: The static iterative construction of the numerical expression type metamorphosis relation comprises the following steps: Randomly select a metamorphosis relationship from the initial metamorphosis relationship set as the root metamorphosis relationship; Calculate the similarity between the root metamorphosis relationship and other metamorphosis relationships in the metamorphosis relationship set. The metamorphosis relationship includes the input relationship and the output relationship. The similarity calculation formula of the metamorphosis relationship is: V=αV r +βV R Among them, V represents the similarity of the transformation relationship, V r Represents the similarity of the input relation of the transformation relation, V R Represents the output relation similarity of the transformation relation, α and β are the input relation and output relation weights respectively, and α+β=1; The metamorphosis relationship with similarity less than the limit threshold is taken as the sub-metamorphosis relationship, and the root metamorphosis relationship and the sub-metamorphosis relationship are compounded to obtain the first-generation compound metamorphosis relationship; Randomly select a metamorphosis relationship from the first-generation compound metamorphosis relationship set as the root metamorphosis relationship, and repeat the steps to obtain the second-generation compound metamorphosis relationship; Repeat the static iterative construction of the transformation relation until the stop condition is met, and output the transformation relation set.

8. A static iterative construction system of a numerical expression type metamorphic relation, based on the static iterative construction method of a numerical expression type metamorphic relation according to any one of claims 1 to 7, characterized in that: include, An acquisition module is used to acquire numerical expression parameters to construct an edit distance matrix and calculate the similarity of numerical expression similarity analysis parameters; The conversion module is used to construct the backtracking rules, obtain the editing operation for string conversion through the edit distance matrix, and obtain the initial metamorphosis relationship set; Construction module. It is used to perform static iterative construction of transformation relations of numerical expression type and output a set of transformation relations.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the processor implements the steps of the static iterative construction method of the numerical expression type transformation relationship described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the static iterative construction method of the numerical expression type metamorphosis relationship described in any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Program preview method and device

    CN120407344A