A code syntax and logic checking method based on reinforcement learning

CN122173096APending Publication Date: 2026-06-09SHANXI TENGSHI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANXI TENGSHI TECH CO LTD
Filing Date
2026-03-10
Publication Date
2026-06-09

Smart Images

  • Figure CN122173096A_ABST
    Figure CN122173096A_ABST
Patent Text Reader

Abstract

The application discloses a code syntax and logic verification method based on reinforcement learning, which comprises the following steps: step one: parsing code syntax tree / control flow graph, generating inequality and building index mapping; step two: constructing bipartite graph and tree decomposition to get bag set, connection tree and separator; step three: PPO injection sequence, Chernikova increment to get local generator and tight constraint surface; step four: building association table and necessary pairing set, PPO priority updating generator; step five: redundancy judgment to get dual certificate and generate pruning rule cache; step six: along the connection tree separator subspace, adhesion and inert promotion to get global generator; step seven: path difference updating constraint and reuse cache to update local / global; step eight: generating verification certificate containing pruning rules from global generator, dual certificate and mapping. The application improves the multi-path verification efficiency and enhances the traceability positioning ability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of code syntax and logic verification technology, and in particular to a code syntax and logic verification method based on reinforcement learning. Background Technology

[0002] In modern software development, the correctness and robustness of code are crucial for the stable operation of a system. To ensure code quality and avoid potential errors, developers typically rely on various static analysis tools to check for syntax errors, logical errors, and potential defects in the code. These tools analyze the code structure by parsing the source code and constructing syntax trees and control flow graphs. However, most existing code verification methods are limited to syntax checking and static analysis, lacking effective verification of complex logic and dynamic behavior. Traditional methods rely on fixed rule sets and manual code reviews, making them unsuitable for software systems with frequently changing and complex logic.

[0003] Currently, traditional static analysis-based code verification methods primarily focus on syntax correctness checks. While these methods can effectively detect some common syntax errors and formatting issues, they cannot effectively handle complex logical errors, boundary cases, and behavioral problems that may occur under different execution paths. Control flow graphs and syntax trees can help detect basic program structure problems, but they still have significant limitations in analyzing complex program structures such as multi-branch logic, recursive calls, and circular dependencies. Furthermore, existing tools typically rely on predefined rule sets, often lacking flexibility and adaptability to new programming patterns and evolving code structures. This makes the limitations of traditional methods apparent when dealing with large, complex systems, easily overlooking potential logical errors and abnormal behaviors.

[0004] To overcome these shortcomings, in recent years, some emerging technologies have attempted to introduce machine learning and reinforcement learning methods to improve the intelligence level of code verification. Reinforcement learning, as a self-optimizing technique, continuously adjusts its strategy through interaction with the environment, gradually improving verification performance through trial and error without relying on predefined rules. However, the application of existing reinforcement learning methods in code verification still faces many challenges, especially in how to effectively construct the state space, how to design reward mechanisms, and how to handle complex code structures. Existing reinforcement learning methods often struggle to handle relationships between multiple constraints and exhibit high computational complexity and instability when dealing with different program behaviors. Therefore, existing technologies still suffer from problems such as insufficient accuracy, low efficiency, and inability to cover all potential errors when solving code syntax and logic verification problems.

[0005] Therefore, how to provide a code syntax and logic verification method based on reinforcement learning is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0006] One objective of this invention is to propose a code syntax and logic verification method based on reinforcement learning. This invention fully utilizes reinforcement learning algorithms, Chernikova incremental computation, and polyhedral constraint optimization techniques. It describes in detail how to automatically select the constraint injection order through tree decomposition algorithms and PPO algorithms, perform incremental computation, and generate accurate code verification results, which are efficient, accurate, and scalable.

[0007] A code syntax and logic verification method based on reinforcement learning according to an embodiment of the present invention includes the following steps: Step 1: Obtain the source code, construct the syntax tree and control flow graph, obtain syntax constraints, logical constraints, and path constraints, convert them into a set of inequality constraints, and establish a constraint index-code location mapping; Step 2: Construct a constraint-variable bipartite graph from the inequality constraint set, and execute the tree decomposition algorithm to generate the bag set, connection tree, and delimiter variable set; Step 3: For each bag in the bag set, use the PPO algorithm to select the constraint injection order, and perform Chernikova incremental calculation to obtain the local generator set and the tightly constrained surface set; Step 4: Build a face-generator association table from the tightly constrained face set, generate the required pairing set, use the PPO algorithm to determine the pairing priority, and update the local generator set; Step 5: Determine the redundancy of the local generator set to obtain the dual certificate, generate pruning rules according to the dual certificate, and write them into the pruning rule cache; Step 6: Perform consistent glue on the local generator set along the join tree in the delimiter variable set subspace, and lazily promote to generate the global generator representation; Step 7: Generate path constraint differences by adding and deleting path constraints and update the inequality constraint set. Call the pruning rule cache to update the local generator set, the surface-generator association table, and the global generator representation. Step 8: Generate a verification certificate from the global generator representation, dual certificate, and constraint index-code location mapping. The verification certificate includes pruning rules.

[0008] Optionally, step one specifically includes: Obtain the source code, perform lexical and syntactic analysis on the source code, construct a syntax tree, and associate the syntax tree nodes with node type, node number, file identifier, line number, and column number; A control flow graph is constructed based on a syntax tree. The control flow graph contains basic blocks and directed edges. Basic blocks are associated with the set of basic block numbers and syntax tree node numbers, and directed edges are associated with branch predicate numbers. Syntax constraints are obtained based on the syntax tree, which covers identifier scope relationships, declaration reference relationships, type consistency relationships, and array boundary relationships. Logical constraints and path constraints are obtained based on the syntax tree and control flow graph, which cover assignment relationships, comparison relationships, and assertion relationships. Path constraints are obtained by combining branch predicate numbers along the path of the control flow graph. Syntax constraints, logical constraints, and path constraints are transformed into a set of inequality constraints. A constraint index-code location mapping is established, which associates each inequality with a file identifier, line number, column number, and syntax tree node number.

[0009] Optionally, step two specifically involves: The constraint index set and variable set are determined by the inequality constraint set. A constraint-variable bipartite graph is established. The constraint-variable bipartite graph contains constraint nodes and variable nodes. Constraint nodes are associated with constraint indices, and variable nodes are associated with variable identifiers. The edges connecting constraint nodes and variable nodes indicate that the inequality corresponding to the constraint index contains variable identifiers. On a constraint-variable bipartite graph, a tree decomposition algorithm is performed to generate a bag set, a connection tree, and a separator variable set. The bag set contains bags, and each bag is associated with a bag number and a set of variable identifiers within the bag. The connection tree contains the edges between bags, and each edge between bags is associated with an edge index. The separator variable set is generated by the intersection of the sets of variable identifiers within the bags at both ends of the edge between bags and is associated with an edge index. The bag set, the connection tree, and the delimiter variable set are associated with a constraint-variable bipartite graph, which is used to select the constraint injection order for bag-by-bag using the PPO algorithm and to perform consistent glue along the connection tree in the delimiter variable set subspace.

[0010] Optionally, step three specifically includes: For a bag in the bag set, the constraint index set corresponding to the bag is determined based on the set of variable identifiers within the bag and the constraint-variable bipartite graph. The constraint index set consists of the constraint indices corresponding to the inequalities that satisfy the inequalities involving variable identifier sets belonging to the set of variable identifiers within the bag. The bag number is associated with the constraint index set. For the constraint index set, the PPO algorithm is used to generate the constraint injection order. The state of the PPO algorithm includes the bag number, the sequence of selected constraint indexes, the set of candidate constraint indexes, the size of the local generator set, and the inequality satisfaction statistics of the generators on the set of candidate constraint indexes. The action of the PPO algorithm is defined as selecting constraint indexes from the set of candidate constraint indexes. The reward of the PPO algorithm includes the change in the size of the local generator set and the change in the inequality satisfaction statistics. The PPO algorithm updates the constraint injection order based on the reward. Chernikova incremental computation is performed according to the constraint injection order. An initial local generator set is established. Inequalities corresponding to constraint indices are added to the computation process in sequence. Inequality satisfaction relations are calculated for the local generator set and the set is divided into satisfaction group, equality group, and violation group. Generators in the violation group are deleted. Equality generators are generated by pairing satisfaction group generators and violation group generators. Equality generators in the equality group are merged with equality generators to update the local generator set. During the Chernikova incremental computation, the set of tightly constrained surfaces is determined by the generators of the equality group. The set of tightly constrained surfaces consists of the constraint indices corresponding to the inequalities that satisfy the equality relationship. The bag number is associated with the local generator set and the set of tightly constrained surfaces.

[0011] Optionally, step four specifically includes: A face-generator association table is established by the set of tightly constrained faces and the set of local generators. The face-generator association table identifies faces with constraint indices in the set of tightly constrained faces and generators with generators in the set of local generators. For each constraint index in the set of tightly constrained faces, if the generator in the set of local generators satisfies the equality relationship with the inequality corresponding to the constraint index, the generator is written into the association item corresponding to the constraint index. The necessary pairing set is generated from the face-generator association table. For each constraint index in the tightly constrained face set, the first generator is selected from the association item corresponding to the constraint index, and the second generator is selected from the local generator set, requiring that the second generator does not belong to the association item corresponding to the constraint index. The first generator and the second generator form a generator pair. The generator pairs are summarized to form the necessary pairing set. The PPO algorithm is used to determine the pairing priority. The PPO algorithm represents the state by bag number, tightly constrained face set, required pairing set, face-generator association table, and local generator set size. The action is represented by selecting generator pairs from the required pairing set. The action sequence forms the pairing priority. Process the required pairing set according to the pairing priority, generate new generators for generator pairs, merge the new generators into the local generator set, and update the face-generator association table based on the new generators.

[0012] Optionally, step five specifically includes: Redundancy determination is performed on the local generator set associated with bag number. Redundancy determination is performed on each generator in the local generator set one by one. The redundancy determination uses the inequality corresponding to the constraint index set associated with bag number as the constraint condition. The determination objective of redundancy determination is that the generator is represented by the other generators in the local generator set under the constraint condition. A dual certificate is generated from the redundancy determination. The dual certificate contains the set of dual coefficients and the set of constraint indexes associated with the dual coefficients. The set of dual coefficients satisfies the non-negativity constraint. The dual certificate is associated with the generator. Pruning rules are generated based on dual certificates. The pruning rules include generator identifiers, constraint index sets, and dual coefficient sets. The pruning rules are used to determine the deletion conditions of generator identifiers when the local generator set is updated. The pruning rules are written to the pruning rule cache, which establishes a bag number index and a generator identifier index. The pruning rule cache also records the association between the pruning rules and the dual certificate.

[0013] Optionally, step six specifically includes: Select the root bag number on the connection tree, and determine the connection tree traversal order based on the root bag number. The connection tree traversal order includes the processing order of the edges between bags. For inter-bag edges in the connection tree traversal order, a consistency determination is performed on the local generator set associated with the child bag number and the local generator set associated with the parent bag number based on the delimiter variable set associated with the inter-bag edge. The consistency determination is based on the consistency relationship between the values ​​of the corresponding variable identifiers in the local generator set. When the consistency determination passes, consistent gluing is performed along the inter-bag edges in the subspace of the separator variable set on the local generator set associated with the parent bag number and the local generator set associated with the child bag number. Consistent gluing generates a gluing generator and forms a global generator representation, which is associated with the root bag number. If the consistency check fails, the inconsistent generator is deleted from the local generator set associated with the sub-bag number based on the consistency check result, and then the consistency check is performed again. Lazy promotion is performed in the order of traversing the connection tree. The lazy promotion determines the set of promotion variable identifiers based on the set of delimiter variables associated with the inter-bag edges. The set of promotion variable identifiers is then introduced into the global generator representation and the global generator representation is updated.

[0014] Optionally, step seven specifically includes: The path constraint difference is generated by adding and deleting path constraints. The path constraint difference includes the set of newly added path constraints and the set of deleted path constraints. The newly added path constraint set and the deleted path constraint set are transformed into inequality constraint increments. The inequality constraint increments include the newly added inequality set and the deleted inequality set. The inequality constraint set is updated based on the inequality constraint increments. The update includes adding the newly added inequality set to the inequality constraint set and removing the deleted inequality set from the inequality constraint set. The bag number set is determined incrementally based on inequality constraints. The bag number set is determined by the inclusion relationship between the variable identifier set involved in the newly added inequality set, the variable identifier set involved in the deleted inequality set, and the variable identifier set within the bag. The pruning rule cache is invoked for the bag number set. The pruning rule cache locates the pruning rule set based on the bag number index. The pruning rule set matches the generator identifier in the local generator set based on the generator identifier. The pruning rule set matches the constraint index in the inequality constraint set based on the constraint index set. Based on the matching results, the generators in the local generator set are deleted and the associated items in the face-to-generator association table are deleted. Perform consistent glue along the connection tree on the local generator set associated with the bag number set in the delimiter variable set subspace, and update the global generator representation based on the consistent glue result.

[0015] Optionally, step eight specifically includes: A verification certificate is generated from the global generator representation, dual certificate, and constraint index-code location mapping. The verification certificate includes a certificate index table, a dual certificate section, a pruning rule section, and a global generator representation section. A certificate index table is generated based on the constraint index-code location mapping. The certificate index table establishes a correspondence between constraint indexes and code locations. The code location includes file identifier, line number, column number, and syntax tree node number. A dual certificate segment is generated based on the dual certificate. The dual certificate segment records the correspondence between the generator meta identifier, the constraint index set, and the dual coefficient set. Pruning rule segments are generated based on the pruning rule cache. The pruning rule segments record the correspondence between bag number, generator identifier, constraint index set, and dual coefficient set. Global generator representation segments are generated based on global generator representations. The global generator representation segment records the correspondence between bag numbers and generator identifiers, and records the generator values ​​corresponding to the generator identifiers.

[0016] The beneficial effects of this invention are: This invention overcomes the limitations of traditional code verification methods when handling complex logic and dynamic behavior by combining reinforcement learning and Chernikova incremental computation techniques. Unlike existing static analysis tools, this invention can automatically identify and verify potential logical errors and boundary conditions in code by dynamically optimizing the constraint injection order, greatly improving verification accuracy and adaptability. Utilizing the PPO algorithm in reinforcement learning, the system can autonomously adjust its verification strategy according to code changes, thereby ensuring timely detection of newly emerging programming patterns and complex logical errors.

[0017] Furthermore, the incremental calculation method of this invention effectively solves the problem of excessive computational complexity in traditional methods. By optimizing the update process of generators and constraint surface sets, redundant calculations are reduced, enabling high efficiency during the verification of large-scale codebases. This method not only improves the accuracy of code verification but also maintains high operating efficiency when dealing with complex systems, ensuring stable operation in projects of different sizes, and possesses strong scalability and practicality. Attached Figure Description

[0018] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings: Figure 1 This is a flowchart of a code syntax and logic verification method based on reinforcement learning proposed in this invention; Figure 2 This is a schematic diagram of the certificate generation structure for a code syntax and logic verification method based on reinforcement learning proposed in this invention. Detailed Implementation

[0019] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.

[0020] refer to Figures 1-2 A code syntax and logic verification method based on reinforcement learning includes the following steps: Step 1: Obtain the source code, construct the syntax tree and control flow graph, obtain syntax constraints, logical constraints, and path constraints, convert them into a set of inequality constraints, and establish a constraint index-code location mapping; Step 2: Construct a constraint-variable bipartite graph from the inequality constraint set, and execute the tree decomposition algorithm to generate the bag set, connection tree, and delimiter variable set; Step 3: For each bag in the bag set, use the PPO algorithm to select the constraint injection order, and perform Chernikova incremental calculation to obtain the local generator set and the tightly constrained surface set; Step 4: Build a face-generator association table from the tightly constrained face set, generate the required pairing set, use the PPO algorithm to determine the pairing priority, and update the local generator set; Step 5: Determine the redundancy of the local generator set to obtain the dual certificate, generate pruning rules according to the dual certificate, and write them into the pruning rule cache; Step 6: Perform consistent glue on the local generator set along the join tree in the delimiter variable set subspace, and lazily promote to generate the global generator representation; Step 7: Generate path constraint differences by adding and deleting path constraints and update the inequality constraint set. Call the pruning rule cache to update the local generator set, the surface-generator association table, and the global generator representation. Step 8: Generate a verification certificate from the global generator representation, dual certificate, and constraint index-code location mapping. The verification certificate includes pruning rules.

[0021] In this embodiment, step one specifically includes: The source code is obtained, and lexical and syntactic analysis are performed on the source code to form a sequence of lexical units. A syntax tree is constructed based on the sequence of lexical units. The syntax tree nodes record the node type and node number. The syntax tree nodes are located to the file identifier, line number, and column number of the source code. This is used to constrain the location of the syntax tree node number and code position when the index-code position mapping is established. The control flow graph is constructed based on the syntax tree. Sequential statements, branch statements, and loop statements in the syntax tree are mapped to basic blocks. The reachability transition relationship between basic blocks is written into the directed edges. Each directed edge is assigned a branch predicate number. The branch predicate number is associated with the syntax tree node number corresponding to the branch condition in the control flow graph. This is used to locate the branch condition by the branch predicate number when obtaining path constraints. Syntactic constraints are obtained based on the syntax tree. Scope entry and exit constraints are constructed according to the identifier scope relationship. Constraints on the consistency of declaration node numbers and reference node numbers are constructed according to the declaration reference relationship. Expression node number type matching constraints are constructed according to the type consistency relationship. Subscript value range constraints are constructed according to the array boundary relationship. Logical constraints and path constraints are obtained based on the syntax tree and control flow graph. Lvalue and rvalue relationship constraints are constructed according to the assignment relationship. Comparison expression relationship constraints are constructed according to the comparison relationship. Assertion condition constraints are constructed according to the assertion relationship. Path constraints are obtained by expanding the sequence of branch predicate numbers on the path of the control flow graph. The branch predicate numbers are mapped to branch condition constraints and combined according to the path order. Syntax constraints, logical constraints, and path constraints are transformed into a set of inequality constraints. Each constraint is normalized into an inequality form and written into the inequality constraint set. A constraint index is assigned to each inequality in the inequality constraint set. A constraint index-code location mapping is established based on the syntax tree node location information. The constraint index-code location mapping associates the constraint index with the file identifier, line number, column number, and syntax tree node number, which is used to verify the backtracking to the source code location when the certificate is generated.

[0022] In this embodiment, step two specifically includes: The constraint index set and variable set are determined by the inequality constraint set. The inequality constraint set is enumerated according to the constraint index. The variable identifiers involved in each inequality are merged into the variable set. A constraint-variable bipartite graph is established. The constraint-variable bipartite graph sets a constraint node set and a variable node set. The constraint node is identified by the constraint index, and the variable node is identified by the variable identifier. An edge is established between the constraint node and the variable node for the variable identifiers that appear in the inequality corresponding to the constraint index. On a constraint-variable bipartite graph, a tree decomposition algorithm is executed to generate a bag set, a connection tree, and a delimiter variable set. The tree decomposition algorithm generates bags with the goal of covering the variable nodes of the constraint-variable bipartite graph. Bags are identified by bag numbers and the set of variable identifiers inside the bag is recorded. The connection tree uses bags as nodes and establishes edges between bags. Edges between bags are identified by edge indices. The delimiter variable set is generated by finding the intersection of the sets of variable identifiers inside the bags at both ends of the edge between bags. The delimiter variable set is associated with the edge index. The bag set, connection tree, and delimiter variable set are associated with the constraint-variable bipartite graph. The association relationship includes the belonging relationship of the variable identifier in the variable identifier set within the bag according to the constraint index corresponding to the inequality, and the association relationship includes the positioning relationship of the delimiter variable set in the connection tree according to the edge index. This is used to select the constraint injection order for bag-by-bag using the PPO algorithm and to perform consistent glue along the connection tree in the delimiter variable set subspace.

[0023] In this embodiment, step three specifically includes: For a bag in the bag set, the constraint index set corresponding to the bag is determined based on the set of variable identifiers inside the bag and the constraint-variable bipartite graph. The edge relationships between constraint nodes and variable nodes in the constraint-variable bipartite graph are traversed to obtain the set of variable identifiers involved in the inequality corresponding to the constraint index. When it is determined that the set of variable identifiers involved in the inequality belongs to the set of variable identifiers inside the bag, the constraint index is added to the constraint index set, and the bag number is associated with the constraint index set. For the constraint index set, the PPO algorithm is used to generate the constraint injection order. The candidate constraint index set is initialized as the constraint index set, the selected constraint index sequence is initialized to empty, and the inequality satisfaction statistics between the local generator set size and the generators on the candidate constraint index set are initialized. The state consists of the bag number, the selected constraint index sequence, the candidate constraint index set, the local generator set size, and the inequality satisfaction statistics between the generators on the candidate constraint index set. The action consists of selecting a constraint index from the candidate constraint index set. After the action is executed, the selected constraint index is removed from the candidate constraint index set and appended to the selected constraint index sequence. The reward consists of the change in the local generator set size and the change in the inequality satisfaction statistics. The PPO algorithm updates the strategy based on the reward and iterates until the selected constraint index sequence contains the constraint index set to form the constraint injection order. Chernikova incremental computation is performed according to the constraint injection order. An initial local generator set is established and associated with bag numbers. Inequalities corresponding to constraint indices are processed one by one according to the constraint injection order. For each generator in the local generator set, the inequality satisfaction relation is calculated and divided into satisfaction group, equality group, and violation group. Generators in the violation group are deleted. For the satisfaction group generators and the violation group generators, the equality group generators are paired to generate equality generators. For each pair of paired generators, a new generator that satisfies the equality relation is constructed and associated with the constraint index that triggered the pairing. The equality group generators are merged with the equality generators to update the local generator set. The size of the local generator set and the inequality satisfaction relation statistics of the generators for the selected constraint index set are refreshed. During the Chernikova incremental calculation, the tight constraint surface set is determined by the generators of the equal sign group. For each inequality that has been added, the proportion of generators of the equal sign group is calculated. When the proportion of generators of the equal sign group meets the preset conditions, the constraint index corresponding to the inequality is recorded in the tight constraint surface set. The tight constraint surface set is composed of the constraint index corresponding to the inequality that satisfies the equality relationship. The bag number is associated with the local generator set and the tight constraint surface set.

[0024] In this embodiment, step four specifically includes: A face-generator association table is established by the set of tightly constrained faces and the set of local generators. The face-generator association table identifies faces with constraint indices in the set of tightly constrained faces and generators with generators in the set of local generators. For each constraint index in the set of tightly constrained faces, each generator in the set of local generators is traversed. The satisfaction relationship after substituting the generator into the inequality corresponding to the constraint index is calculated. When the equality relationship is satisfied, the generator is written into the association item corresponding to the constraint index. The face-generator association table records the correspondence between the constraint index and the generator identifier in the association item. A required pairing set is generated from the face-generator association table. For each constraint index in the tightly constrained face set, the first generator is selected from the association item corresponding to the constraint index, and the second generator is selected from the local generator set, satisfying that the second generator does not belong to the association item corresponding to the constraint index. The first generator and the second generator form a generator pair. The generator pair is associated with the constraint index and written into the required pairing set. The required pairing set records the generator pair identifier and the associated constraint index identifier. The PPO algorithm is used to determine the pairing priority. The PPO algorithm uses bag number, tightly constrained face set, required pairing set, face-generator association table, and local generator set size to represent the state. Selecting generator pairs from the required pairing set represents the action. After the action is executed, the selected generator pairs are removed from the required pairing set and the action sequence is recorded. The action sequence forms the pairing priority. The necessary pairing set is processed according to the pairing priority. For the generator pairs selected in the action sequence, the difference in the satisfaction relationship between the two generators is calculated on the inequality corresponding to the generator pair association constraint index. Based on the difference in the satisfaction relationship, a new generator that satisfies the equality relationship is constructed. The new generator is merged into the local generator set. For each constraint index in the tightly constrained surface set, the equality relationship of the new generator is re-determined and the surface-generator association table is updated.

[0025] In this embodiment, step five specifically includes: Redundancy determination is performed on the local generator set associated with bag number. Redundancy determination is performed on each generator in the local generator set one by one. When selecting the generator to be determined, the generator to be determined is temporarily removed from the local generator set to form a reference generator set. Based on the constraint index set associated with bag number, the inequality is located and constrained. The constraint conditions are applied to the linear combination expression of the reference generator set. It is calculated whether the linear combination of the reference generator set can cover the generator to be determined under the constraint conditions. If the coverage is successful, the generator to be determined is marked as a redundant generator. Dual certificates are generated from redundancy determination. The dual certificates are constructed based on the constraints of redundancy determination. Each constraint index in the constraint index set corresponds to a dual coefficient. The combination of dual coefficients is solved to satisfy the non-negativity constraint and the dual feasibility condition. The set of dual coefficients and the constraint index set associated with the dual coefficients are obtained. The dual certificate is associated with the redundancy generator identifier. The dual certificate contains a pairwise correspondence between the set of dual coefficients and the set of constraint indexes. Pruning rules are generated based on dual certificates. The pruning rules include generator identifiers, constraint index sets, and dual coefficient sets. The pruning rules use the constraint index sets as matching keys, the dual coefficient sets as decision parameters, and generator identifiers as the objects of action. The pruning rules define the decision process when updating the local generator set. The decision process includes consistency checks of the constraint index sets and non-negativity checks of the dual coefficient sets. When the decision is valid, the generator identifier deletion condition is triggered. The pruning rules are written to the pruning rule cache. The pruning rule cache establishes a bag number index and a generator identifier index. The bag number index is used to locate the set of pruning rules associated with the bag number, and the generator identifier index is used to locate the set of pruning rules associated with the generator identifier. The pruning rule cache records the correspondence between pruning rules and dual certificates and retains the constraint index set and dual coefficient set.

[0026] In this embodiment, step six specifically includes: Select the root bag number on the connection tree, determine the connection tree traversal order based on the root bag number, and the connection tree traversal order includes the processing order of the inter-bag edges. The processing order of the inter-bag edges satisfies the directed expansion relationship from the root bag number to the leaf bag number. The processing order of the inter-bag edges is to specify the parent bag number and the child bag number for each inter-bag edge. For the inter-bag edges in the traversal order of the connection tree, a consistency determination is performed on the local generator set associated with the child bag number and the local generator set associated with the parent bag number based on the delimiter variable set associated with the inter-bag edge. The consistency determination constructs a delimiter generator set for the local generator set associated with the parent bag number and a delimiter generator set for the local generator set associated with the child bag number. The delimiter generator set consists of the values ​​of the local generator set on the corresponding variable identifier in the delimiter variable set. The consistency determination is based on the value matching relationship between the delimiter generator set of the parent bag number and the delimiter generator set of the child bag number. When the consistency determination is passed, consistency glue is performed on the local generator sets associated with the parent bag number and the local generator sets associated with the child bag number in the subspace of the separator variable set along the bag edges. Consistency glue generates glue generators for the separator value matching pairs of the local generators of the parent bag number and the local generators of the child bag number. The glue generators inherit the matching values ​​on the corresponding variable identifiers in the separator variable set, and combine the values ​​in the union of the variable identifier sets of the parent bag number and the variable identifier sets of the child bag number. The glue generator sets are merged to form a global generator representation, and the global generator representation is associated with the root bag number. If the consistency determination fails, the inconsistent generator is deleted from the local generator set associated with the sub-bag number based on the consistency determination result. The inconsistency generator determination is based on the fact that the separator value in the generator set containing the sub-bag number separator cannot be found in the generator set containing the separator of the parent bag number. The corresponding inconsistent generator is deleted from the local generator set associated with the sub-bag number before the consistency determination is performed again. Lazy promotion is performed in the order of traversing the connection tree. Lazy promotion determines the set of promotion variable identifiers based on the set of delimiter variables associated with the edges between bags. The set of promotion variable identifiers consists of bag variable identifiers not covered by the global generator representation. The set of promotion variable identifiers is introduced into the global generator representation. The promotion process is to fill in the values ​​of the promotion variable identifiers in the glue generator in the global generator representation and update the global generator representation.

[0027] In this embodiment, step seven specifically includes: The path constraint difference is generated by adding and deleting path constraints. The path constraint difference includes the set of newly added path constraints and the set of deleted path constraints. The set of newly added path constraints records the identifier of the added path constraint and the predicate number sequence of the corresponding branch of the path constraint. The set of deleted path constraints records the identifier of the removed path constraint and the predicate number sequence of the corresponding branch of the path constraint. The newly added path constraint set and the deleted path constraint set are transformed into inequality constraint increments. The inequality constraint increments include the newly added inequality set and the deleted inequality set. The newly added inequality set is obtained by locating the branch conditions from the branch predicate number sequence in the newly added path constraint set and transforming them. The deleted inequality set is obtained by locating the branch conditions from the branch predicate number sequence in the deleted path constraint set and transforming them. The inequality constraint set is updated based on the inequality constraint increments. The update includes adding the newly added inequality set to the inequality constraint set and removing the deleted inequality set from the inequality constraint set. A constraint index-code location mapping is established for the newly added inequalities and the deleted inequalities. The bag number set is determined incrementally based on inequality constraints. The set of newly added inequalities and the set of deleted inequalities are traversed to determine the set of variable identifiers involved in each inequality. The inclusion relationship between the variable identifier set and the variable identifier set of the corresponding bag in the bag set is compared. If the inclusion relationship is satisfied, the bag number is added to the bag number set. The pruning rule cache is invoked for the bag number set. The pruning rule cache locates the pruning rule set based on the bag number index. The pruning rule set contains generator identifiers, constraint index sets, and dual coefficient sets. The generator identifiers are matched with the generator identifiers in the local generator set, and the constraint index sets are matched with the constraint indices in the inequality constraint set. When a match is found, the generator corresponding to the generator identifier in the local generator set is deleted according to the pruning rules. After deleting the generator, the face-generator association table is updated and the association item corresponding to the generator identifier is deleted. Perform consistent gluing on the local generator set associated with the bag number set in the delimiter variable set subspace along the connector tree. Recalculate the value matching relationship on the delimiter variable set for the inter-bag edges involved in the bag number set in the connector tree traversal order. If the value matching relationship is true, generate the glued generator and merge it into the global generator representation. If the value matching relationship is false, keep the global generator representation unchanged and continue to process the inter-bag edges. Update the global generator representation based on the result of merging the glued generator.

[0028] In this embodiment, step eight specifically includes: A verification certificate is generated from the global generator representation, dual certificate, and constraint index-code location mapping. The verification certificate sets a certificate identifier and establishes a certificate directory structure. The certificate directory structure includes a certificate index table, dual certificate section, pruning rule section, and global generator representation section. The certificate directory structure assigns a section identifier to each section and records the section length. A certificate index table is generated based on the constraint index-code location mapping. The constraint indexes of the constraint index-code location mapping are traversed, and index entries are generated by arranging them according to the constraint indexes. The index entries record the correspondence between the constraint indexes and the code locations. The code locations record the file identifier, line number, column number, and syntax tree node number. Based on the dual certificate, generate the dual certificate segment, traverse the dual certificates and generate dual entries according to the generator identifier. The dual entries record the constraint index set and dual coefficient set associated with the generator identifier, and record the pairwise correspondence between the constraint index set and the dual coefficient set. Based on the pruning rule cache, pruning rule segments are generated. The pruning rule cache is traversed and pruning entries are generated by arranging them according to bag number and generator identifier. The pruning entries record the constraint index set and dual coefficient set associated with bag number and generator identifier, and record the pairwise correspondence between constraint index set and dual coefficient set. Generate a global generator representation segment based on the global generator representation, traverse the global generator representation and generate generator entries by bag number. The generator entry records the correspondence between bag number and generator identifier, and records the generator value corresponding to the generator identifier. The generator value consists of variable identifier and variable identifier value.

[0029] Example 1: To verify the feasibility of this invention in practice, it was applied to the continuous integration code verification process of a large enterprise-level software system. This software system contains multi-language modules, complex branching and looping structures, and numerous assertions and boundary checks. It undergoes frequent daily iterations, and code changes introduce new constraints or delete old ones on different paths. Existing static analysis tools often employ fixed rules or one-time constraint processing. When encountering multi-path combinations, loop unrolling, and cross-basic block data dependencies, they often suffer from long verification times, high false alarm rates, and repetitive calculations for similar changes. Furthermore, when unsatisfiable conditions are found or assertions are falsifiable, existing tools struggle to accurately pinpoint specific code locations and responsible constraints, leading to high development costs and long repair cycles. This invention aims to solve these problems, ensuring the verification process remains scalable and efficient even in complex path scenarios, and outputting location-based and traceable certificate results to support the project closure loop.

[0030] In this scenario, lexical and syntactic analysis is first performed on the source code to be verified to construct a syntax tree. A control flow graph is then built based on the syntax tree, associating basic blocks with branch predicates. Subsequently, syntactic constraints, logical constraints, and path constraints are extracted from the syntax tree and control flow graph and uniformly transformed into a set of linear inequality constraints. Simultaneously, a constraint index is created for each inequality and mapped to a file identifier, row and column number, and syntax tree node number, ensuring that subsequent certificates can directly locate the source code location. Further, a constraint-variable bipartite graph is constructed from the inequality constraint set. Tree decomposition is performed on this graph to obtain a bag set, a connection tree, and a set of delimiter variables, thus splitting the global constraint problem into multiple local subproblems within multiple bags. For each bag, the PPO algorithm is used to generate a constraint injection order based on the bag number, the sequence of selected constraint indices, the set of candidate constraint indices, and the size of local generators. Chernikova incremental computation is then performed to update the local generator set according to this order. Simultaneously, a set of tight constraint surfaces is determined from the generators of the equality group. Then, based on the tight constraint surface set and the local generators... The generator set establishes a surface-generator association table, generates the necessary pairing set, and uses the PPO algorithm to give pairing priorities to control the intermediate scale expansion caused by pairing. This completes the update of the local generator set. Redundancy checks are performed on the updated local generator set to obtain the dual certificate, which is then used to generate pruning rules and write them to the pruning rule cache. Subsequently, when path constraints are added or deleted, path constraint differences are first formed and converted into inequality increments. Only the affected bag number set is called to perform local deletion and association table updates, avoiding full recalculation. Finally, consistency checks and consistency glue are performed on the local generator set along the connection tree in the delimiter variable subspace. Lazy promotion completes the required variable dimensions to form a global generator representation. A verification certificate is generated by combining the dual certificate and constraint index-code location mapping. The certificate includes a certificate index table, a dual certificate segment, a pruning rule segment, and a global generator representation segment, ensuring that each verification conclusion can point back to the constraint index that triggered the conclusion and its source code location, thereby improving the interpretability and reproducibility of alarms.

[0031] To quantify and verify the beneficial effects, verification tasks from multiple consecutive commits of the same codebase were selected as samples, covering change sets containing multi-branch paths, loop unrolling, and assertion-intensive operations. The methods of "traditional static analysis methods," "traditional one-time polyhedron solving (without tree decomposition and incremental reuse)," and "the method of this invention" were compared. Under the same hardware resources and concurrent configuration, the average verification time per pipeline, peak memory usage, false positive rate, false negative rate, assertion falsifiability detection rate, and average alarm location time were statistically analyzed. The results are shown in Table 1. This invention outperforms the method in terms of average time, peak memory usage, false positive rate, and location efficiency. Especially in iterative scenarios with minor additions and deletions of path constraints, thanks to path differentiation and pruning rule caching, redundant calculations are significantly reduced, resulting in a more significant improvement in throughput.

[0032] Table 1 Comparison of Code Validation Methods

[0033] Further analysis revealed that in multi-path scenarios, traditional one-time polyhedron solving is prone to memory and time fluctuations caused by the rapid expansion of intermediate generator size. In contrast, this invention restricts computation to subspaces within bags through tree decomposition and avoids full-dimensional combinatorial explosion through separator consistency glue and lazy lifting, making peak memory usage more stable. For constraint additions and deletions in small-step iterations, this invention uses path constraint differential to locate affected bags and uses pruning rules to cache and quickly delete unnecessary generators and associated items based on dual certificates, thus making incremental update costs significantly lower than full recalculation. At the same time, the certificate index table in the verification certificate maps constraint indexes to code locations, enabling alarms to be directly located to files, rows, columns, and syntax tree nodes. Developers can trace the minimum responsible constraint set based on dual certificate segments and pruning rule segments, reducing the workload of manual investigation and regression verification.

[0034] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.

Claims

1. A code syntax and logic verification method based on reinforcement learning, characterized in that, Includes the following steps: Step 1: Obtain the source code, construct the syntax tree and control flow graph, obtain syntax constraints, logical constraints, and path constraints, convert them into a set of inequality constraints, and establish a constraint index-code location mapping; Step 2: Construct a constraint-variable bipartite graph from the inequality constraint set, and execute the tree decomposition algorithm to generate the bag set, connection tree, and delimiter variable set; Step 3: For each bag in the bag set, use the PPO algorithm to select the constraint injection order, and perform Chernikova incremental calculation to obtain the local generator set and the tightly constrained surface set; Step 4: Build a face-generator association table from the tightly constrained face set, generate the required pairing set, use the PPO algorithm to determine the pairing priority, and update the local generator set; Step 5: Determine the redundancy of the local generator set to obtain the dual certificate, generate pruning rules according to the dual certificate, and write them into the pruning rule cache; Step 6: Perform consistent glue on the local generator set along the join tree in the delimiter variable set subspace, and lazily promote to generate the global generator representation; Step 7: Generate path constraint differences by adding and deleting path constraints and update the inequality constraint set. Call the pruning rule cache to update the local generator set, the surface-generator association table, and the global generator representation. Step 8: Generate a verification certificate from the global generator representation, dual certificate, and constraint index-code location mapping. The verification certificate includes pruning rules.

2. The code syntax and logic verification method based on reinforcement learning according to claim 1, characterized in that, Step one specifically involves: Obtain the source code, perform lexical and syntactic analysis on the source code, construct a syntax tree, and associate the syntax tree nodes with node type, node number, file identifier, line number, and column number; A control flow graph is constructed based on a syntax tree. The control flow graph contains basic blocks and directed edges. Basic blocks are associated with the set of basic block numbers and syntax tree node numbers, and directed edges are associated with branch predicate numbers. Syntax constraints are obtained based on the syntax tree, which covers identifier scope relationships, declaration reference relationships, type consistency relationships, and array boundary relationships. Logical constraints and path constraints are obtained based on the syntax tree and control flow graph, which cover assignment relationships, comparison relationships, and assertion relationships. Path constraints are obtained by combining branch predicate numbers along the path of the control flow graph. Syntax constraints, logical constraints, and path constraints are transformed into a set of inequality constraints. A constraint index-code location mapping is established, which associates each inequality with a file identifier, line number, column number, and syntax tree node number.

3. The code syntax and logic verification method based on reinforcement learning according to claim 1, characterized in that, Step two specifically involves: The constraint index set and variable set are determined by the inequality constraint set. A constraint-variable bipartite graph is established. The constraint-variable bipartite graph contains constraint nodes and variable nodes. Constraint nodes are associated with constraint indices, and variable nodes are associated with variable identifiers. The edges connecting constraint nodes and variable nodes indicate that the inequality corresponding to the constraint index contains variable identifiers. On a constraint-variable bipartite graph, a tree decomposition algorithm is performed to generate a bag set, a connection tree, and a separator variable set. The bag set contains bags, and each bag is associated with a bag number and a set of variable identifiers within the bag. The connection tree contains the edges between bags, and each edge between bags is associated with an edge index. The separator variable set is generated by the intersection of the sets of variable identifiers within the bags at both ends of the edge between bags and is associated with an edge index. The bag set, the connection tree, and the delimiter variable set are associated with a constraint-variable bipartite graph, which is used to select the constraint injection order for bag-by-bag using the PPO algorithm and to perform consistent glue along the connection tree in the delimiter variable set subspace.

4. The code syntax and logic verification method based on reinforcement learning according to claim 1, characterized in that, Step three specifically involves: For a bag in the bag set, the constraint index set corresponding to the bag is determined based on the set of variable identifiers within the bag and the constraint-variable bipartite graph. The constraint index set consists of the constraint indices corresponding to the inequalities that satisfy the inequalities involving variable identifier sets belonging to the set of variable identifiers within the bag. The bag number is associated with the constraint index set. For the constraint index set, the PPO algorithm is used to generate the constraint injection order. The state of the PPO algorithm includes the bag number, the sequence of selected constraint indexes, the set of candidate constraint indexes, the size of the local generator set, and the inequality satisfaction statistics of the generators on the set of candidate constraint indexes. The action of the PPO algorithm is defined as selecting constraint indexes from the set of candidate constraint indexes. The reward of the PPO algorithm includes the change in the size of the local generator set and the change in the inequality satisfaction statistics. The PPO algorithm updates the constraint injection order based on the reward. Chernikova incremental computation is performed according to the constraint injection order. An initial local generator set is established. Inequalities corresponding to constraint indices are added to the computation process in sequence. Inequality satisfaction relations are calculated for the local generator set and the set is divided into satisfaction group, equality group, and violation group. Generators in the violation group are deleted. Equality generators are generated by pairing satisfaction group generators and violation group generators. Equality generators in the equality group are merged with equality generators to update the local generator set. During the Chernikova incremental computation, the set of tightly constrained surfaces is determined by the generators of the equality group. The set of tightly constrained surfaces consists of the constraint indices corresponding to the inequalities that satisfy the equality relationship. The bag number is associated with the local generator set and the set of tightly constrained surfaces.

5. The code syntax and logic verification method based on reinforcement learning according to claim 1, characterized in that, Step four specifically involves: A face-generator association table is established by the set of tightly constrained faces and the set of local generators. The face-generator association table identifies faces with constraint indices in the set of tightly constrained faces and generators with generators in the set of local generators. For each constraint index in the set of tightly constrained faces, if the generator in the set of local generators satisfies the equality relationship with the inequality corresponding to the constraint index, the generator is written into the association item corresponding to the constraint index. The necessary pairing set is generated from the face-generator association table. For each constraint index in the tightly constrained face set, the first generator is selected from the association item corresponding to the constraint index, and the second generator is selected from the local generator set, requiring that the second generator does not belong to the association item corresponding to the constraint index. The first generator and the second generator form a generator pair. The generator pairs are summarized to form the necessary pairing set. The PPO algorithm is used to determine the pairing priority. The PPO algorithm represents the state by bag number, tightly constrained face set, required pairing set, face-generator association table, and local generator set size. The action is represented by selecting generator pairs from the required pairing set. The action sequence forms the pairing priority. Process the required pairing set according to the pairing priority, generate new generators for generator pairs, merge the new generators into the local generator set, and update the face-generator association table based on the new generators.

6. The code syntax and logic verification method based on reinforcement learning according to claim 1, characterized in that, Step five specifically involves: Redundancy determination is performed on the local generator set associated with bag number. Redundancy determination is performed on each generator in the local generator set one by one. The redundancy determination uses the inequality corresponding to the constraint index set associated with bag number as the constraint condition. The determination objective of redundancy determination is that the generator is represented by the other generators in the local generator set under the constraint condition. A dual certificate is generated from the redundancy determination. The dual certificate contains the set of dual coefficients and the set of constraint indexes associated with the dual coefficients. The set of dual coefficients satisfies the non-negativity constraint. The dual certificate is associated with the generator. Pruning rules are generated based on dual certificates. The pruning rules include generator identifiers, constraint index sets, and dual coefficient sets. The pruning rules are used to determine the deletion conditions of generator identifiers when the local generator set is updated. The pruning rules are written to the pruning rule cache, which establishes a bag number index and a generator identifier index. The pruning rule cache also records the association between the pruning rules and the dual certificate.

7. The code syntax and logic verification method based on reinforcement learning according to claim 1, characterized in that, Step six specifically involves: Select the root bag number on the connection tree, and determine the connection tree traversal order based on the root bag number. The connection tree traversal order includes the processing order of the edges between bags. For inter-bag edges in the connection tree traversal order, a consistency determination is performed on the local generator set associated with the child bag number and the local generator set associated with the parent bag number based on the delimiter variable set associated with the inter-bag edge. The consistency determination is based on the consistency relationship between the values ​​of the corresponding variable identifiers in the local generator set. When the consistency determination passes, consistent gluing is performed along the inter-bag edges in the subspace of the separator variable set on the local generator set associated with the parent bag number and the local generator set associated with the child bag number. Consistent gluing generates a gluing generator and forms a global generator representation, which is associated with the root bag number. If the consistency check fails, the inconsistent generator is deleted from the local generator set associated with the sub-bag number based on the consistency check result, and then the consistency check is performed again. Lazy promotion is performed in the order of traversing the connection tree. The lazy promotion determines the set of promotion variable identifiers based on the set of delimiter variables associated with the inter-bag edges. The set of promotion variable identifiers is then introduced into the global generator representation and the global generator representation is updated.

8. The code syntax and logic verification method based on reinforcement learning according to claim 1, characterized in that, Step seven specifically involves: The path constraint difference is generated by adding and deleting path constraints. The path constraint difference includes the set of newly added path constraints and the set of deleted path constraints. The newly added path constraint set and the deleted path constraint set are transformed into inequality constraint increments. The inequality constraint increments include the newly added inequality set and the deleted inequality set. The inequality constraint set is updated based on the inequality constraint increments. The update includes adding the newly added inequality set to the inequality constraint set and removing the deleted inequality set from the inequality constraint set. The bag number set is determined incrementally based on inequality constraints. The bag number set is determined by the inclusion relationship between the variable identifier set involved in the newly added inequality set, the variable identifier set involved in the deleted inequality set, and the variable identifier set within the bag. The pruning rule cache is invoked for the bag number set. The pruning rule cache locates the pruning rule set based on the bag number index. The pruning rule set matches the generator identifier in the local generator set based on the generator identifier. The pruning rule set matches the constraint index in the inequality constraint set based on the constraint index set. Based on the matching results, the generators in the local generator set are deleted and the associated items in the face-to-generator association table are deleted. Perform consistent glue along the connection tree on the local generator set associated with the bag number set in the delimiter variable set subspace, and update the global generator representation based on the consistent glue result.

9. A code syntax and logic verification method based on reinforcement learning according to claim 1, characterized in that, Step eight specifically involves: A verification certificate is generated from the global generator representation, dual certificate, and constraint index-code location mapping. The verification certificate includes a certificate index table, a dual certificate section, a pruning rule section, and a global generator representation section. A certificate index table is generated based on the constraint index-code location mapping. The certificate index table establishes a correspondence between constraint indexes and code locations. The code location includes file identifier, line number, column number, and syntax tree node number. A dual certificate segment is generated based on the dual certificate. The dual certificate segment records the correspondence between the generator meta identifier, the constraint index set, and the dual coefficient set. Pruning rule segments are generated based on the pruning rule cache. The pruning rule segments record the correspondence between bag number, generator identifier, constraint index set, and dual coefficient set. Global generator representation segments are generated based on global generator representations. The global generator representation segment records the correspondence between bag numbers and generator identifiers, and records the generator values ​​corresponding to the generator identifiers.