Lustre language instance generation method and system based on feedback and application
By introducing a feedback mechanism in the Lustre language instance generation process, dynamically detecting and correcting illegal situations, the problem of insufficient validity of instance generation in the prior art is solved, and an instance that complies with Lustre's legality constraints is generated, which improves the accuracy and efficiency of the generation process.
Patent Information
- Application Number
- CN202510064721.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-05-13
AI Technical Summary
The existing Lustre language instance generation technology lacks feedback mechanism, resulting in insufficient validity of the generated instances, insufficient test coverage, and potential design and implementation problems may be missed.
The feedback-based Lustre language instance generation method is used to dynamically detect and correct illegal situations in the generation process to ensure that the generated instance complies with the legality constraints of the Lustre language. The method includes candidate pool initialization, heuristic selection of candidate instances, random evolution, type checker legitimacy verification and feedback processing.
Through the feedback mechanism, the generated instances can be corrected in real time in each round of evolution, ensuring that the final generated instances comply with the legality constraints of the Lustre language, significantly improving the accuracy and efficiency of the generation process.
Smart Images

Figure BDA0005243916190000121 
Figure BDA0005243916190000122 
Figure BDA0005243916190000123
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of formal verification of software engineering, and relates to a method, system and application of generating a Lustre language instance based on feedback. Background Art
[0002] With the widespread application of embedded systems and real-time control systems in various key fields such as industry, aerospace, and rail transportation, the requirements for the reliability, real-time, and security of such systems are becoming increasingly higher. Formal verification technology, as a key means to ensure that system design meets specific logical and functional requirements, plays an important role in the system design, verification, and optimization process. Lustre, as a formal language specifically used to describe data flows and real-time control system behaviors, has become one of the main tools for designing and verifying such systems with its unique grammatical structure and powerful description capabilities. The characteristic of Lustre language is that it emphasizes logical constraints for periodic execution and can efficiently describe the timing behavior and control logic of the system.
[0003] When using the Lustre language, instance generation is one of the key steps. Valid Lustre instances can be used for functional and security testing to ensure software reliability. However, current instance generation technologies mostly use static rules and lack a feedback mechanism, which makes the generated instances insufficient in terms of effectiveness, resulting in insufficient test coverage, incomplete test results, and the possibility of missing potential design and implementation issues.
[0004] In industrial practice, feedback mechanisms have been applied in many verification processes. Through the feedback mechanism, the generation strategy can be continuously adjusted during the instance generation process, so that the generated instances are closer to the complexity and diversity requirements of the actual system. The introduction of the feedback mechanism can dynamically reflect the process results of instance generation and guide the generation process to gradually approach the verification goal. However, there are certain challenges in directly applying the feedback mechanism to Lustre instance generation. The grammatical structure and data flow characteristics of the Lustre language require special generation logic to ensure that the generated instances are representative on the basis of conforming to the grammar. The static instance generation method is difficult to ensure that the legality constraints imposed by the language are met, and relying solely on static rules may cause the generated random instances to be too simple and unable to effectively cover the potential diversity of Lustre instances. Therefore, there is an urgent need for an instance generation method that can combine the feedback mechanism and follow the Lustre grammar to meet the needs of complex system verification. Summary of the invention
[0005] In order to solve the deficiencies in the prior art, the purpose of the present invention is to provide a feedback-based Lustre language instance generation method, which is used to dynamically detect and correct illegal situations in the generation process during the generation of Lustre instances, so as to ensure that the generated instances meet the legality constraints of the Lustre language. The legality requirements of the Lustre language mainly include variable declaration and use constraints, type consistency, grammar rule matching, etc. However, the traditional method based on static generation rules is difficult to ensure the legality of the generated instances. The present invention introduces a feedback mechanism to dynamically check the legality of the instance during the generation process, and adjusts the generation strategy through the feedback mechanism to ensure that the instance can be applied to the functionality and security verification of the system under the premise of meeting the Lustre grammar requirements.
[0006] The present invention provides a method for generating a Lustre language instance based on feedback, the method comprising the following steps:
[0007] Step 1: Initialize the candidate pool to a set containing only one initial instance that satisfies the basic grammar rules of Lustre;
[0008] Step 2: Select a Lustre instance from the set of candidate pools based on heuristic rules;
[0009] Step 3: According to the Lustre syntax rules, the Lustre instance selected in step 2 is randomly evolved;
[0010] Step 4: Check the validity of the new Lustre instance after evolution;
[0011] Step 5: Based on the feedback information after the inspection, decide whether to keep the instance in the candidate pool or remove it from the candidate pool, and trigger a new round of evolution;
[0012] Step 6: Output the legal Lustre instance result set.
[0013] In step 1, the initial instance is set to comply with the basic legality constraints of Lustre;
[0014] The Lustre grammar for constructing the initial instance is recursively defined. The structure of the Lustre grammar recursively defines grammatical rules from atoms to operation declarations, providing a complete structural basis for the generation of Lustre instances.
[0015] The initial instance meets the basic syntax requirements of Lustre, including one or more variable declarations and calculations including integers, Boolean values or other basic types, and one or more operators and operation types;
[0016] Each instance in the candidate pool is identified by a unique identifier.
[0017] The recursive definition of the Lustre grammar is as follows:
[0018] user_op_decl::= op_kind visibility? ID params "returns" params opt_body
[0019] op_kind::= "FUNCTION" | "NODE"
[0020] visibility::= "PUBLIC" | "PRIVATE"
[0021] params::= "(" (var_decls (";" var_decls)*)? ")"
[0022] var_decls::= var_id ("," var_id)* ":" expr
[0023] var_id::= ("CLOCK"? "PROBE"? ) ID
[0024] opt_body::= equation ";"
[0025] equation::= lhs "=" expr
[0026] lhs::= ID ("," ID)*
[0027] expr::= atom
[0028] | expr "[" expr "]"
[0029] | expr "+" expr
[0030] | expr "-" expr
[0031] | expr "*" expr
[0032] | expr " / " expr
[0033] | expr "%" expr
[0034] | expr "&&" expr
[0035] | expr "||" expr
[0036] | "!" expr
[0037] | "(" expr ")"
[0038] atom::=ID|integer|boolean|character|STRING
[0039] The corresponding meanings include:
[0040] 1) Atoms are represented by atom, which contain identifiers represented by ID, as well as integers, Booleans, characters, and strings.
[0041] 2) Expression (expr), including atomic expressions (containing only single atoms) and compound expressions composed of connectors. Connectors include unary operators and binary operators. Unary operators include negation operators ("!") and bracket operators ("()"). Binary operators include arithmetic operators ("+", "-", "*", " / ", "%"), logical operators ("&&", "||"), and array operators ("[]").
[0042] 3) The left-hand expression (lhs) is used to define the assignment target in the equation. The left-hand expression can contain one or more identifiers (ID), and multiple identifiers are separated by commas. The left-hand expression represents the set of variables to be assigned in the equation.
[0043] 4) Equation: used to define the value of a variable or node. It is composed of the left expression (lhs) and the expression (expr) which form an assignment relationship and are connected by the "=" symbol. An equation represents the assignment or calculation result of one or more variables. The definition of an equation ends with a semicolon.
[0044] 5) Function body (opt_body), which represents the main logic structure of the Lustre instance, and contains one or more equations. The function body structure defines the behavior and calculation logic of the instance by providing one or more equations.
[0045] 6) Parameter declaration (params), used to define the input and output parameters of a function or node. The parameter declaration part is surrounded by parentheses and contains one or more variable declarations (var_decls). Each variable declaration consists of a set of variable identifiers (var_id), which are separated by commas. Each variable declaration is followed by its type expression (expr). Multiple parameter declarations are separated by semicolons. params is used to describe the input and output interfaces of a node or function.
[0046] 7) Variable declaration (var_decls), which represents a specific set of variables. A variable declaration consists of one or more variable identifiers (var_id), where multiple variable identifiers are separated by commas and followed by the variable type (expr). var_decls can be used to define the input parameters, return values, etc. of a function or node.
[0047] 8) Variable identifier (var_id) is the naming method of the variable, including optional prefix modifiers, such as "CLOCK" or "PROBE". These modifiers are used to control the clock information or debugging information of the variable, followed by a specific identifier (ID), which uniquely identifies the variable in the program.
[0048] 9) Visibility, which is used to identify the access rights of a function or node. Visibility is divided into "PUBLIC" and "PRIVATE", which respectively indicate whether the operation is public (accessible in external modules) or private (available only in the current module). Visibility is optional and is considered private by default if not declared.
[0049] 10) Operation type (op_kind), which is used to define the type of operation. op_kind includes two types: "FUNCTION" and "NODE", which respectively indicate that the operation is a function or a node. In Lustre, the behavior definitions of functions and nodes are similar, but nodes usually have state characteristics, while functions are stateless.
[0050] 11) User operation declaration (user_op_decl) is the overall definition of Lustre operation, including operation type (op_kind), visibility (visibility), identifier (ID), input and output parameters (params), and main logic (opt_body). The entire user_op_decl is used to describe an operation unit in the Lustre instance, which defines the behavior and function of the operation through a series of parameters and logic.
[0051] In step 2, the heuristic rule is used to guide the selection of candidate instances, and the instance is selected based on factors including structural complexity, variable declaration, coverage requirements, etc. of the instance;
[0052] The structural complexity takes into account the number of equations and variables contained in the instance, the diversity of operators, the depth of the syntax tree, etc.; the variable declaration situation focuses on the type and scope of the variables in the instance, etc.; the coverage requirement represents the test scenarios and functional points that the instance can cover, etc.;
[0053] Scoring each instance in the candidate pool based on the heuristic rule, and using the instance with the highest score for evolution;
[0054] The scoring rules include the following:
[0055] Complexity score: Considers the number of variable declarations, the number of equations, the number of variables in each equation, the diversity of operators, and the dependencies between variables. For variable declarations, one point is added for each variable declaration, and one additional point is added for each set of dependencies between variables (such as recursion or cross-references); for equations, one point is added for each equation, each variable used in each equation, and each operator;
[0056] Coverage requirement score: calculated based on the number of function points that the instance can cover; the more function points covered, the higher the score; specifically, the score increases by one point for each function point covered.
[0057] In step 3, evolving by randomly adding new Lustre components to the selected Lustre instance;
[0058] Evolution operations include: randomly inserting new variable declarations, modifying equations, adding or deleting expressions based on Lustre syntax rules; and / or,
[0059] Add new Lustre components including nodes, variables or expressions to expand the structure of the instance and achieve diversified and randomized generation effects.
[0060] After the evolution operation, the result instance generated by the evolution is checked through the built-in checking function. When the syntax of the result instance does not meet the Lustre syntax requirements, the original evolution operation is canceled, a new evolution strategy is replaced, and the evolution is performed again.
[0061] In step 4, the new Lustre instance generated by evolution is checked for consistency in variable declaration and usage, type consistency, and legality of grammatical structure.
[0062] The variable declaration and usage consistency check refers to checking the declaration of variables in the instance to ensure that the variables are correctly declared before use, marking undeclared variables as illegal, and providing specific error information;
[0063] The type consistency check refers to checking the type matching situation on the left and right sides of each equation;
[0064] The legality check of the grammatical structure refers to checking whether each expression and operator in the instance conforms to the grammatical specification of Lustre; the check includes: whether the array index operation is valid and whether the logical operator is used correctly;
[0065] Feedback information is generated for the error types obtained by the inspection, and the feedback information includes the nature of the error and possible solutions.
[0066] In step 5, if the check result is legal, the new Lustre instance is added to the candidate pool and a new round of evolution is performed, and steps 2 to 4 are repeated; or, if the check result is illegal, the illegal evolution instance is deleted, and a new instance is selected for a new round of evolution, and steps 2 to 4 are repeated;
[0067] and / or,
[0068] Instances with valid check results are added to the candidate pool and marked as "verified";
[0069] and / or,
[0070] The usage frequency of the corresponding evolutionary operation is selected according to the probability of the evolutionary operation generating illegal instances; in the specific implementation process, the evolutionary operation with a high probability of generating illegal instances is used less frequently.
[0071] The present invention also provides an instance generation system for implementing the above generation method, the instance generation system comprising: a candidate pool, a heuristic selection module, a random evolver, a type checker, a feedback processor, and a result output module;
[0072] The candidate pool stores and manages initial instances that meet Lustre language requirements and / or instances generated through evolution;
[0073] The heuristic selection module scores the instances based on heuristic rules to guide the selection of candidate instances;
[0074] The random evolvator performs an evolution operation on the selected candidate instance according to Lustre grammar rules;
[0075] The type checker performs a validity check on the instance generated by the random evolver and generates a validity check feedback result;
[0076] The feedback processor adds the evolved instance to the candidate pool or discards the evolved instance according to the legality check feedback result;
[0077] The result output module outputs a predetermined number of all instances that meet Lustre legality requirements.
[0078] The results of the type checker guide the implementation of the random evolver.
[0079] The present invention also provides the application of the above generation method or the above instance generation system in generating instances that meet the requirements of complexity and diversity of actual applications.
[0080] The beneficial effects of the present invention include: the present invention realizes dynamic detection and adjustment of illegal situations in the generation process through a feedback mechanism, effectively solving the problem that the traditional Lustre instance generation method is difficult to ensure the legitimacy. Through the feedback mechanism, the generated instance can be corrected in real time in each round of evolution to ensure that the final generated instance complies with the legal constraints of the Lustre language (such as syntax, type consistency, etc.), significantly improving the accuracy and legitimacy of the generation process.
[0081] In addition, the present invention improves the efficiency and reliability of the generation process through this feedback mechanism. Traditional methods often rely on static rules, the generation process lacks flexibility, and often requires a lot of manual intervention. The feedback mechanism of the present invention can automatically adjust the generation strategy according to the feedback information of each generation result, making the instance generation process more intelligent and adaptive. With the guidance of each round of feedback, the system can effectively avoid non-compliant instances in the generation process, thereby reducing the number of invalid generation and erroneous instances and improving the efficiency of generation.
[0082] Based on the dynamic feedback and adaptive generation characteristics of the present invention, in practical applications, the time efficiency of the generation process and the effectiveness of the generated instances have been significantly improved. For example, compared with the traditional random generation method, the proportion of legal instances in the generation process has been significantly improved, and the generation speed of legal instances has been increased by more than 60%. Compared with the traditional manual writing method, the potential of the automated method of the present invention in terms of generation speed and diversity also shows very positive expectations.
[0083] At the same time, since the generated instances have higher diversity, this is particularly critical for the verification of complex systems, especially in application scenarios with high safety requirements, such as aerospace, rail transportation and other fields. It can effectively improve the integrity and accuracy of system verification and reduce potential safety risks. BRIEF DESCRIPTION OF THE DRAWINGS
[0084] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0085] Figure 1 It is a system architecture diagram of the present invention.
[0086] Figure 2 It is a comparison chart of the efficiency of generating legal instances by the present invention and the traditional random method.
[0087] Figure 3 This is a diagram showing the evolution of a syntax tree in a Lustre instance. DETAILED DESCRIPTION
[0088] The present invention is further described in detail with reference to the following specific examples and drawings. The process, conditions, experimental methods, etc. for implementing the present invention, except for the contents specifically mentioned below, are all common knowledge and common common sense in the art and are not particularly limited by the present invention.
[0089] The core innovation of the present invention is that by introducing a feedback mechanism, the goal of "satisfying legality constraints" that cannot be achieved in the existing Lustre language instance generation process becomes possible. In traditional instance automatic generation methods, instances are usually generated by relying on random methods. These methods cannot adapt to the complexity of Lustre language constraints, and thus it is difficult to ensure the legality and comprehensive coverage of instances. However, the present invention successfully turns this originally difficult goal into a possible goal by detecting and correcting the legality of instances in real time during the generation process. Through the feedback mechanism, the generation process can be adjusted in real time according to the actual situation to ensure that the generated instances meet the constraints of the Lustre language.
[0090] This innovative approach breaks the limitations of traditional methods and makes the generation process more flexible and intelligent. Through dynamic feedback, the present invention can address the complexity of Lustre language instance generation, allowing system designers to automatically obtain legal instances instead of relying on pure manual writing. With this approach, the verification process that originally relied on manual intervention can be highly automated, thereby improving efficiency.
[0091] The present invention provides a method for generating Lustre language instances based on feedback, which includes six steps: initializing a candidate pool, selecting candidate instances heuristically, random evolution based on Lustre grammar rules, type checker legality verification, feedback evolution, and outputting a legal instance set. Each step cooperates with each other, and the feedback mechanism is used to ensure that the instances generated in each round meet the legality requirements of Lustre, thereby solving the problem of generating legal instances in Lustre.
[0092] Figure 1 The system architecture diagram for implementing the method of the present invention is described. It shows the system composition and workflow of the present invention in detail. The system of the present invention consists of the following main parts:
[0093] Candidate Pool: The candidate pool is the core component of the present invention, which is responsible for storing and managing all Lustre instances, including initial instances and / or instances generated through evolution. The initialization process of the candidate pool involves creating an initial instance according to the basic syntax rules of Lustre. The initial instance is a simple Lustre function, which has different types of operations such as basic input and output parameters, assignment statements, and expression calculations. This initial instance can be a basic addition function, multiplication function, or an instance containing more complex logic. The key is that it must meet the basic syntax requirements of Lustre and have diverse characteristics so that it can provide an effective starting point for the subsequent evolution process. For example, the initial instance may contain variable declarations and calculations of integers, Boolean values, or other basic types, and should cover common operators and operation types as much as possible to promote diverse evolution and generate more complex instances. In this way, it can be ensured that the generated instances are not only legal, but also help to enrich the generated instance library and improve the comprehensiveness and reliability of the test. In a specific implementation, the initial instance can be an integer addition function; on the basis of meeting the grammatical requirements, it also includes different types such as function definition, assignment statement and expression calculation, so it can serve as an effective starting point to promote the diversity and effectiveness of subsequent evolution processes.
[0094] In the candidate pool management mechanism, each instance, including the initial instance and the instances generated through evolution, is assigned a unique identifier to facilitate tracking and recording the evolution history and type checking results of each instance, which helps with error tracking and strategy adjustment during the generation process.
[0095] Heuristic Selection Module: Heuristic rules are the key mechanism used in the present invention to guide the selection of candidate instances, providing a quantitative basis for instance selection. These rules are based on factors such as the structural complexity of the instance, variable declarations, and coverage requirements. After calculation, each instance is scored and then guided for instance selection. The structural complexity takes into account the number of equations and variables contained in the instance, as well as the diversity of operators; the variable declarations focus on the type and scope of the variables in the instance; and the coverage requirements refer to the test scenarios and functional points that the instance can cover.
[0096] The heuristic selection module scores each instance in the candidate pool based on heuristic rules. The scoring rules include different scoring items such as complexity score and coverage requirement score, and finally calculate the final score based on the given weights. The complexity score considers the number of variable declarations, the number of equations, the number of variables in each equation, the diversity of operators, and the dependencies between variables in the instance. For variable declarations, one point is added for each variable declaration, and one additional point is added for each set of dependencies between variables (such as recursion or cross-references); for equations, one point is added for each equation, each variable used in each equation, and each operator. The coverage requirement score is calculated based on the number of function points that the instance can cover; the score increases by one point for each function point covered. For example, an instance with multiple equations and variables will get a higher complexity score, while an instance that can cover multiple test scenarios will get a higher coverage requirement score. The algorithm accumulates the weighted sum of the scores as the final score and selects the instance with the highest score for evolution. This approach not only ensures the objectivity of the selection process, but also improves the representativeness and effectiveness of the generated instances. In the specific implementation process, in different application scenarios, the tendency of generation can be influenced by adjusting the heuristic parameters. For example, in scenarios that emphasize diversity, such as aerospace, the weight of the diversity score can be increased to guide the invention to generate more diverse instances.
[0097] Random Evolver: Random evolution is a key step in the present invention for generating new instances. In this process, the random evolver operates on the selected candidate instances according to the Lustre syntax rules, including inserting new variable declarations, modifying equations, adding or deleting expressions, etc. For example, the random evolver may add a new variable declaration in a function, or modify an equation to include a new arithmetic operator.
[0098] To ensure that these operations comply with Lustre syntax rules, the random evolver has a built-in basic checking function. After each evolution operation, the module immediately checks the resulting instance. If an obviously illegal syntax is found (such as an addition operator is generated, but the added variable is not generated, resulting in a blank), the evolver will undo the operation and try another evolution strategy. This immediate syntax checking mechanism ensures that each instance generated complies with Lustre's syntax requirements, thereby reducing the workload of the subsequent type checker.
[0099] Type Checker: The type checker is a key component used to ensure the legitimacy of the instance in the present invention. It is responsible for checking the consistency of variable declaration and use, type consistency, and the legitimacy of the grammatical structure in the instance. The workflow of the type checker includes the following steps:
[0100] 1. Variable declaration and usage consistency check: The checker will traverse each variable in the instance to ensure that they are correctly declared before use. If an undeclared variable is found, the checker will mark the instance as illegal and provide detailed error information, including the specific illegal variable, location, etc.
[0101] 2. Type consistency check: The checker checks whether the left and right sides of each equation match. For example, if the left side of the equation is an integer variable, the expression on the right side must also return an integer value. Type mismatches are considered illegal instances. The checker marks the instance as illegal when it finds type inconsistencies and provides specific error information, including the location of the type mismatch, the variables or expressions involved, etc.
[0102] 3. Check the legality of the grammatical structure: The checker verifies whether each expression and operator in the instance complies with the Lustre grammatical specification. This includes checking whether the array index operation is valid and whether the logical operator is used correctly. Specifically, the checker verifies whether the array index is within the legal range, whether the logical operator is correctly applied to the Boolean expression, whether the parameter type when calling the function is correct, etc. For cases that do not comply with the Lustre grammatical specification, the checker will mark the instance as illegal and provide detailed error information, including the specific expression and location of the error and possible repair solutions.
[0103] When the type checker handles different types of errors, it generates detailed feedback that not only indicates the nature of the error but also provides possible solutions. This feedback mechanism is crucial to guide the tuning and optimization of the random evolver.
[0104] Feedback Handler: The feedback handler is a key component used in the present invention to make decisions based on the results of the type checker. It is responsible for processing the feedback information of the type checker and, based on this information, deciding whether to keep the instance in the candidate pool or remove it from the candidate pool and trigger a new round of evolution.
[0105] The feedback processor workflow consists of the following steps:
[0106] 1. Legality evaluation: The processor first collects feedback from the type checker to determine whether the instance is legal.
[0107] 2. Instance decision: If the instance is legal, the processor will add the instance to the candidate pool and mark it as "verified". If the instance is illegal, the processor will remove the instance from the candidate pool and log an error message.
[0108] 3. Evolution trigger: For illegal instances, the processor triggers a new round of evolution and selects new instances from the candidate pool for evolution.
[0109] 4. Strategy Adjustment: The processor will also adjust the evolution strategy based on the error information. For example, if it is found that a specific evolution operation frequently leads to illegal instances, the processor may reduce the frequency of use of this operation.
[0110] Through this feedback processing mechanism, the present invention can effectively reduce illegal situations caused by random generation, ensure that the generation process always meets the legality requirements of Lustre, and improve generation efficiency and reliability.
[0111] Result Output Module: After accumulating a sufficient number of legal instances in the candidate pool, output these instances as the final generation results.
[0112] On this basis, the method of the present invention mainly comprises the following steps:
[0113] 1. Candidate pool initialization
[0114] The candidate pool is initialized to contain an initial set of instances that meet the basic grammar rules of Lustre. The initial instance is used as the starting point of evolution, and new candidate instances are gradually generated through multiple rounds of feedback and evolution. In a specific implementation, the initial instance is set as an integer addition function to lay a legal foundation for subsequent instance evolution and ensure the initial correctness of the instance generation process.
[0115] 2. Heuristic selection of candidate instances
[0116] According to the heuristic rules, a Lustre instance is selected from the candidate pool for the next evolution. The heuristic selection rules are based on factors such as the structural complexity of the instance, variable declarations, and coverage requirements to ensure that legitimate instances are always selected during the evolution process. The goal of the heuristic selection process is to give priority to instances that are more likely to remain legitimate after evolution, thereby reducing the number of unnecessary feedback adjustments and improving generation efficiency.
[0117] 3. Random evolution based on Lustre grammar rules
[0118] The selected Lustre instance is randomly evolved based on grammatical rules to generate a new Lustre structure. The evolution operation includes variable declaration, introduction and replacement of equations, embedding of new expression structures, etc., to ensure that the generated instance structure is grammatically consistent with Lustre requirements. During the evolution process, the present invention strictly manages the use of variables and expressions, and provides basic legality guarantees for the evolution results while following the Lustre grammar rules. However, the occurrence of illegal situations cannot be avoided by grammar generation alone, so this step only provides preliminary legality guarantees.
[0119] 4. Type checker validity verification
[0120] The evolved instance is input into the type checker to verify the legitimacy of the instance. Type checking includes:
[0121] Consistency in variable declaration and usage: Make sure all variables in an instance are declared before use.
[0122] Type consistency: Checks that the left and right sides of an equation match.
[0123] Syntax structure validity: Verify whether the application of expressions and operators complies with Lustre syntax specifications.
[0124] If the instance passes the type check, it proceeds to the next step; if it fails, feedback information is returned, indicating the specific illegal items. As an important part of the feedback mechanism, the type checker plays a role in timely detecting and correcting illegal situations during the generation process.
[0125] 5. Feedback Evolution
[0126] According to the feedback results of type checking, the instance generation strategy is dynamically adjusted. If the instance is legal, the instance is added to the candidate pool and a new round of evolution continues; if the instance is illegal, relevant information is fed back, the instance is marked and deleted, and then a new instance is reselected from the candidate pool for evolution. Through the feedback mechanism, the present invention effectively reduces illegal situations caused by random generation, ensures that the generation process always meets the legality requirements of Lustre, and improves generation efficiency and reliability.
[0127] 6. Output the set of legal instances
[0128] When the candidate pool accumulates a specified number of legal instances, the final Lustre instance set is output. The output instance set not only meets the syntax rules and legality requirements of Lustre, but also has high efficiency and applicability, and can be used for system functionality and security verification.
[0129] In the specific implementation, the specific implementation steps of "a method for generating Lustre instances based on feedback" will be described in detail. In order to better illustrate the implementation of the present invention, a specific example will be used to show the process of each step, and the present invention will be further described in detail. The process, conditions, experimental methods, etc. for implementing the present invention, except for the contents specifically mentioned below, are all common knowledge and common common sense in the art, and the present invention does not specifically limit the contents.
[0130] Step 1: Initialize the candidate pool
[0131] In this step, you need to initialize a candidate pool that contains only an initial Lustre instance. This initial instance is carefully designed to ensure that it meets the basic syntax rules of Lustre. For example, you can start with a simple Lustre function that takes two integer parameters and returns their sum.
[0132] The following is a code example of an initial Lustre instance in a specific implementation:
[0133] FUNCTION add(x:int,y:int)RETURNS(result:int);
[0134] result = x + y; / / Returns the sum of two signed integers
[0135] }
[0136] This initial instance is simple and clear, easy to expand, and meets the basic syntax requirements of Lustre, laying the foundation for subsequent evolution.
[0137] Step 2: Heuristically select candidate instances
[0138] In one embodiment, the candidate pool includes only one initial instance: in this step, the heuristic rule will only select the initial instance for evolution. After parsing the instance, the random evolution step will perform random evolution operations; for example, a new multiplication operation can be inserted into the function:
[0139]
[0140] The generated new instance is more complex than the original instance, covers operators that were not covered before (multiplication operator), and is more suitable for subsequent evolution. Therefore, the new instance will be recorded in the candidate pool.
[0141] In a specific embodiment, the candidate pool includes the initial instance and the legal instance after evolution; in this step, a heuristic rule is used to select a Lustre instance from the candidate pool for evolution. The heuristic rule can be based on factors such as the structural complexity of the instance, the variable declaration situation, and the coverage requirements. For example, an instance with multiple variables and complex logic may be selected because it is more likely to produce diverse offspring during the evolution process. Assume that in addition to the initial instance, there is also an evolved legal instance complex_op in the candidate pool:
[0142]
[0143] This instance is more complex than the initial instance, contains multiple variables and operations, and is more suitable for evolution. In terms of structural complexity, the operator type score of this instance is 2 ('+' and '*'), and the syntax tree depth score is 3; in contrast, the operator type score and syntax tree depth score of the initial instance are 1 ('+') and 2 respectively; since the instance complex_op has a higher score, complex_op will be selected as the candidate instance for evolution.
[0144] Step 3: Random evolution according to Lustre grammar rules
[0145] In this step, the selected candidate instances are randomly evolved. Evolution operations may include inserting new variable declarations, modifying equations, adding or removing expressions, etc. For example, a new variable d can be added to the complex_op function and the calculation method of res2 can be modified:
[0146]
[0147] This modification maintains the legality of Lustre syntax, while also increasing the complexity of the instance and covering more operators.
[0148] Step 4: Use a type checker to check for legality
[0149] The evolved instance needs to be verified by the type checker. The type checker will check the consistency of variable declaration and use, type consistency, and the legality of the grammatical structure. For example, the checker will ensure that all variables are declared before use, the types on the left and right sides of the equation match, and all expressions and operators comply with Lustre's grammatical specifications. If the instance passes the type check, it will be retained; if not, it will be discarded and a new instance will be selected from the candidate pool for evolution. For example, the complex_op_correct above is a legal instance. But the following instance is illegal:
[0150] Illegal instance 1
[0151]
[0152] Here the variable e is used without being defined, which violates the Lustre syntax and is therefore illegal.
[0153] Illegal instance 2
[0154]
[0155] Here, the variable d is of array type and cannot be used for integer operations. This violates the type constraint and is therefore illegal.
[0156] Illegal instance 3
[0157]
[0158] Here the variable integer is divided by 0, which violates the language constraints and is therefore illegal.
[0159] Step 5: Further evolve based on feedback
[0160] If the type checker returns a valid instance, add the instance to the candidate pool and continue a new round of evolution (such as complex_op_correct above). If the instance is illegal (such as complex_op_wrong above), the instance will be deleted and no subsequent evolution will be based on it. In the above example, if the evolution produces complex_op_correct, the new candidate pool will be the set {add, complex_op, complex_op_correct}, and the new candidate instance will be selected from this candidate pool. If the evolution produces complex_op_wrong, the illegal instance will be discarded and the candidate pool will remain the set {add, complex_op}.
[0161] Step 6: Output the legal Lustre instance result set
[0162] When the candidate pool accumulates a specified number of legal instances, these instances will be output as the final generation results. These instances not only meet the grammatical rules and legality requirements of Lustre, but also have high efficiency and applicability, and can be used for functional and security verification of the system. For example, if it returns immediately, the following legal Lustre instance set can be output:
[0163]
[0164] These examples can be used for further system validation and testing.
[0165] In a specific implementation process, Figure 2 As shown, it is a comparison diagram of the efficiency of generating legal instances by the present invention and the traditional random method. In the figure, when the CPU consumes the same running time, the number of legal instances generated by the Lustre language instance generation method in the present invention far exceeds that of the traditional method.
[0166] Figure 3 This is a demonstration diagram of the syntax tree evolution process in a Lustre instance. The left side is the syntax tree of the expression to be evolved, indicating that the addition operation is performed first, and then the multiplication operation. The right side is the syntax tree of the new expression generated after evolution, indicating that the subtraction operation is added on the basis of the tree on the left. The depth of the evolved tree is greater than the tree before evolution, and the new operator ('-') is covered, so it is a successful evolution.
[0167] The above steps describe in detail the implementation process of a feedback-based Lustre instance generation method of the present invention in a specific implementation scenario. This process not only ensures the legitimacy of the generated Lustre instance, but also improves the generation efficiency and reliability, meeting the needs of complex system verification.
[0168] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of complete hardware embodiments, complete software embodiments, or embodiments in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code. The scheme in the embodiments of the present application can be implemented in various computer languages, for example, object-oriented programming language Java and literal scripting language JavaScript, etc.
[0169] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0170] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0171] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0172] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0173] The protection content of the present invention is not limited to the above embodiments. Without departing from the spirit and scope of the present invention, changes and advantages that can be thought of by those skilled in the art are included in the present invention and are protected by the attached claims.
Claims
1. A method for generating Lustre language instances based on feedback, characterized in that: The steps include: Step 1: Initialize the candidate pool to a set containing only one initial instance that satisfies the basic grammar rules of Lustre; Step 2: Select a Lustre instance from the set of candidate pools based on heuristic rules; Step 3: Randomly evolve the Lustre instance selected in step 2; Step 4: Check the validity of the new Lustre instance after evolution; Step 5: Based on the feedback information after the inspection, decide whether to keep the instance in the candidate pool or remove it from the candidate pool, and trigger a new round of evolution; Step 6: Output the legal Lustre instance result set.
2. The generation method according to claim 1, characterized in that: In step 1, the setting of the initial instance complies with the basic legality constraints of Lustre; includes one or more variable declarations and calculations including integers and Boolean values, and includes one or more operators and operation types; The Lustre grammar for constructing the initial instance is recursively defined. The structure of the Lustre grammar recursively defines grammatical rules from atoms to operation declarations, providing a complete structural basis for the generation of Lustre instances. Each instance in the candidate pool is identified by a unique identifier.
3. The generation method according to claim 2, characterized in that: The recursive definition of the Lustre grammar is as follows: user_op_decl::=op_kind visibility? ID params"returns"params opt_body op_kind::="FUNCTION"|"NODE" visibility::="PUBLIC"|"PRIVATE" params::="("(var_decls(";"var_decls)*)?")" var_decls::=var_id(","var_id)*":"expr var_id::=("CLOCK"?"PROBE"?)ID opt_body::=equation";" equation::=lhs"="expr lhs::=ID(","ID)* expr::=atom |expr"["expr"]" |expr"+"expr |expr"-"expr |expr"*"expr |expr" / "expr |expr"%"expr |expr"&&"expr |expr"||"expr |"!"expr |"("expr")" atom::=ID|integer|boolean|character|STRING The corresponding meanings include: 1) atoms represented by atom, which contain identifiers represented by ID, as well as integers, Boolean values, characters, and strings; 2) expression expr, including an atomic expression including only a single atom and a compound expression composed of connectors; the connectors include unary operators and binary operators, the unary operators include negation operators and bracket operators, and the binary operators include arithmetic operators, logical operators and array operators; 3) The left expression lhs is used to define the assignment target in the equation. The left expression may contain one or more identifiers ID, and multiple identifiers are separated by commas. The left expression represents the set of variables to be assigned in the equation. 4) Equation: used to define the value of a variable or node. It is composed of the left expression and the expression that form an assignment relationship, connected by the "=" symbol. An equation represents the assignment or calculation result of one or more variables. The definition of the equation ends with a semicolon. 5) Function body opt_body, which represents the main logic structure of the Lustre instance, and contains one or more equations. The function body structure defines the behavior and calculation logic of the instance by providing one or more equations; 6) Parameter declaration params, used to define the input and output parameters of a function or node. The parameter declaration part is enclosed in brackets and contains one or more variable declarations var_decls. Each variable declaration consists of a set of variable identifiers var_id, and the variable identifiers are separated by commas. Each variable declaration is followed by its type expression expr. Multiple parameter declarations are separated by semicolons. params is used to describe the input and output interfaces of a node or function. 7) Variable declaration var_decls, which indicates a specific variable set. Variable declaration consists of one or more variable identifiers var_id, where multiple variable identifiers are separated by commas and followed by the variable type expr; var_decls is used to define input parameters and return values of functions or nodes; 8) Variable identifier var_id is the naming method of the variable, including an optional prefix modifier; the prefix modifier is used to control the clock information or debugging information of the variable, followed by a specific identifier ID, which uniquely identifies the variable in the program; 9) Visibility, which is used to identify the access rights of a function or node. Visibility is divided into "PUBLIC" and "PRIVATE", which respectively indicate that the operation is a public operation accessible in external modules or a private operation only available in the current module. Visibility is optional and is considered private by default if not declared. 10) Operation type op_kind, which is used to define the type of operation. op_kind includes two types: "FUNCTION" and "NODE", which respectively indicate that the operation is a function or a node. In Lustre, the behavior definitions of functions and nodes are similar, but nodes have state characteristics, while functions are stateless. 11) User operation declaration user_op_decl is the overall definition of Lustre operation, including operation type op_kind, visibility, identifier ID, input and output parameters params, and main logic opt_body; the entire user_op_decl is used to describe an operation unit in the Lustre instance, which defines the behavior and function of the operation through a series of parameters and logic.
4. The generation method according to claim 1, characterized in that: In step 2, the heuristic rule is used to guide the selection of candidate instances, and the instance is selected based on factors including structural complexity, variable declaration, and coverage requirement of the instance; The structural complexity takes into account the number of equations and variables contained in the instance, the diversity of operators, and the depth of the syntax tree; the variable declaration situation focuses on the type and scope of the variables in the instance; the coverage requirement represents the test scenarios and functional points that the instance can cover; Each instance in the candidate pool is scored based on the heuristic rule, and the instance with the highest score is used for evolution.
5. The generation method according to claim 1, characterized in that: In step 3, evolving by randomly adding new Lustre components to the selected Lustre instance; Evolution operations include: inserting new variable declarations, modifying equations, adding or removing expressions; and / or, Adding new Lustre components including nodes, variables or expressions extends the instance structure; After the evolution operation, the result instance generated by the evolution is checked through the built-in checking function. When the syntax of the result instance does not meet the Lustre syntax requirements, the original evolution operation is canceled, a new evolution strategy is replaced, and the evolution is performed again.
6. The generation method according to claim 1, characterized in that: In step 4, the consistency of variable declaration and usage, type consistency, and legality of grammatical structure of the new Lustre instance generated by evolution are checked; The variable declaration and usage consistency check refers to checking the declaration of variables in the instance to ensure that the variables are correctly declared before use, marking undeclared variables as illegal, and providing specific error information; The type consistency check refers to checking the type matching situation on the left and right sides of each equation; The legality check of the grammatical structure refers to checking whether each expression and operator in the instance conforms to the grammatical specification of Lustre; the check includes: whether the array index operation is valid and whether the logical operator is used correctly.
7. The generation method according to claim 6, characterized in that: Feedback information is generated for the error types obtained by the inspection, and the feedback information includes the nature of the error and possible solutions.
8. The generation method according to claim 1, characterized in that: In step 5, if the check result is legal, the new Lustre instance is added to the candidate pool and a new round of evolution is performed; or, if the check result is illegal, the illegal evolution instance is deleted and a new instance is selected for a new round of evolution; and / or, Instances with valid check results are added to the candidate pool and marked as "verified"; and / or, The usage frequency of the corresponding evolution operation is selected according to the probability of the evolution operation generating illegal instances.
9. An instance generation system for implementing the generation method according to any one of claims 1 to 8, characterized in that: The instance generation system includes: a candidate pool, a heuristic selection module, a random evolver, a type checker, a feedback processor, and a result output module; The candidate pool stores and manages initial instances that meet Lustre language requirements and / or instances generated through evolution; The heuristic selection module scores the instances based on heuristic rules to guide the selection of candidate instances; The random evolvator performs an evolution operation on the selected candidate instance according to Lustre grammar rules; The type checker performs a validity check on the instance generated by the random evolver and generates a validity check feedback result; The feedback processor adds the evolved instance to the candidate pool or discards the evolved instance according to the legality check feedback result; The result output module outputs a predetermined number of all instances that meet Lustre legality requirements.
10. Application of the generation method according to any one of claims 1 to 8, or the instance generation system according to claim 9, in generating instances that meet the requirements of complexity and diversity of actual applications.