A large model driven control algorithm mathematical formula self-adaptive normalization method
Patent Information
- Application Number
- CN202610558062.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-24
- Publication Date
- 2026-10-13
- Estimated Expiration
- 2046-04-24
AI Technical Summary
[0007]为了解决现有控制算法数学公式在解析过程中因不符合编写规范而导致解析阻断,且现有人工修复效率低、通用大模型修复效果差和缺乏闭环优化能力的问题,本发明实施例提供了一种大模型驱动的控制算法数学公式自适应规范化方法
1.现有技术中伪代码解析器的报错信息通常以底层语法错误或词法错误的形式呈现,不同报错信息之间缺乏语义关联,开发人员难以从离散的报错文本中定位具体的数学公式违规点。本方案通过对报错原因进行语义向量化并在语义向量空间中执行聚类分析,将语义表达不同但本质一致的错误归入同一语义类别,建立了从底层报错信息到高层语义错误类别的映射关系,实现了对非规范数学公式伪代码错误的结构化建模与精准分类,使后续修复过程能够针对特定错误类别制定针对性的修复策略。
Smart Images

Figure CN122471995B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of aerospace control software automation development technology, and in particular to an adaptive normalization method for mathematical formulas of control algorithms driven by a large model. Background Technology
[0002] In the development of spacecraft control systems, the mathematical formulas of control algorithms are the core carriers of control strategies. Algorithms for critical tasks such as attitude control, orbit control, and navigation filtering typically exist in the form of mathematical formulas or pseudocode in requirements documents, which engineers must translate into embedded C language code. With the continuous increase in the complexity of space missions and the ever-shortening of model development cycles, how to quickly and accurately translate mathematical formulas into code that meets reliability requirements has become a key issue in control software development.
[0003] In engineering practice, the developed parser can intelligently generate highly reliable C code from standardized mathematical formulas. However, pseudocode extracted from requirements documents often does not conform to coding standards, causing the parser to fail to parse it correctly. Existing technologies have the following shortcomings in solving the above-mentioned pseudocode standardization problem: First, the error messages returned by pseudocode parsers are mostly limited to descriptions of low-level syntax breaks or lexical errors. When faced with diverse non-standard mathematical formula inputs, it is difficult to establish a semantic mapping relationship between error messages and coding standards. There is a lack of effective means to uniformly classify, formally describe, and accurately locate complex error types, which makes it impossible for developers to quickly locate specific mathematical formula violations based on error messages.
[0004] Second, the standardization process of existing control algorithm mathematical formulas relies heavily on manual experience to check each item against the standard document. It lacks an intelligent mechanism that can automatically understand the parser feedback and transform it into a standardized repair strategy. When faced with large-scale and highly complex control logic, it is difficult to balance repair efficiency and repair accuracy.
[0005] Third, existing intelligent repair methods for mathematical formulas based on large language models mostly adopt a general end-to-end generation mode. When faced with strict writing specifications, they cannot establish a precise mapping relationship between error features and specific repair strategies. The repair process lacks specificity and lacks self-optimization capabilities based on feedback mechanisms, making it difficult to achieve full coverage and adaptive correction of various types of highly complex non-standard mathematical formulas.
[0006] Therefore, there is an urgent need to provide an adaptive normalization method for the mathematical formulas of control algorithms driven by large models. Summary of the Invention
[0007] To address the problems of existing control algorithm mathematical formulas being blocked during analysis due to non-compliance with coding standards, as well as the low efficiency of existing manual repair, poor repair effect of general large models, and lack of closed-loop optimization capabilities, this invention provides an adaptive normalization method for control algorithm mathematical formulas driven by large models.
[0008] On the one hand, an adaptive normalization method for mathematical formulas of control algorithms driven by large models is provided, the method comprising: The parser generates error triples for each error node based on non-standard mathematical formula pseudocode, and performs error semantic classification on the error triples to generate category labels, thereby obtaining a structured semantic description of the error node; wherein, the error triples include at least an error pseudocode fragment, a parser error description, and the line number of the error node in the pseudocode; Based on the structured semantic description, a large model is used to generate repair rules for this type of error, and the differentiated repair rules are dynamically fused to generate composite repair rules that cover multiple types of combined errors. By using a parser for verification, the repair rules and composite repair rules generated by the large model are iteratively optimized to obtain a large model prompt word library for the normalization and repair of non-standard mathematical formulas.
[0009] On the other hand, a large-model-driven adaptive normalization device for mathematical formulas of control algorithms based on the steps described in any method embodiment of the specification is provided. The device includes: The modeling unit is used to generate error triples for each error node using a parser based on non-canonical mathematical formula pseudocode, and to perform error semantic classification on the error triples to generate category labels, thereby obtaining a structured semantic description of the error node; wherein, the error triples include at least an error pseudocode fragment, a parser error description, and the line number of the error node in the pseudocode; The generation unit is used to generate repair rules for this type of error based on the structured semantic description using a large model, and to dynamically fuse the differentiated repair rules to generate composite repair rules that cover multiple types of combined errors. The optimization unit is used to iteratively optimize the repair rules and composite repair rules generated by the large model using the parser verification, so as to obtain a large model prompt word library for the normalization and repair of non-standard mathematical formulas.
[0010] On the other hand, a computer device is provided, the computer device including a memory and a processor, the memory for storing a computer program, and the processor for executing the computer program stored in the memory to implement the steps of the method described above.
[0011] On the other hand, a computer-readable storage medium is provided, wherein a computer program is stored therein, and when the computer program is executed by a processor, it implements the steps of the method described above.
[0012] On the other hand, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the method described above.
[0013] The technical solution provided by this invention can bring at least the following beneficial effects: 1. In existing technologies, error messages from pseudocode parsers are typically presented as low-level syntax or lexical errors. There is a lack of semantic correlation between different error messages, making it difficult for developers to pinpoint specific violations in mathematical formulas from discrete error texts. This solution semantically vectorizes the error causes and performs cluster analysis in the semantic vector space. Errors with different semantic expressions but consistent essence are grouped into the same semantic category, establishing a mapping relationship from low-level error messages to high-level semantic error categories. This achieves structured modeling and accurate classification of errors in non-standard mathematical formula pseudocode, enabling subsequent repair processes to develop targeted repair strategies for specific error categories.
[0014] 2. Existing code repair methods based on large language models typically use a single prompt word for end-to-end repair. When faced with concurrent errors of multiple types commonly found in control algorithm pseudocode, a single repair rule struggles to cover all error patterns, leading to incomplete repairs or the need for multiple iterations. This solution identifies heterogeneous error patterns with significant semantic differences by calculating the semantic similarity between repair rules of different categories. It then generates composite repair rules capable of covering multiple combined errors in a single repair, significantly improving the repair efficiency and completeness in complex error scenarios.
[0015] 3. Existing large language models may generate repair rules with issues such as semantic bias and missing boundary conditions, and lack mechanisms for quantitative evaluation and automatic optimization of repair results. This solution verifies the repair results by inputting them into a parser, iteratively optimizing the repair rules generated by the large model and composite repair rules, and transforming the uncertain output of the large language model into validated, high-confidence static rules, thus achieving continuous evolution and quality assurance of the repair rules. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart of an adaptive normalization method for mathematical formulas of a large model-driven control algorithm provided in an embodiment of the present invention; Figure 2 This is a flowchart of the adaptive normalization of mathematical formulas for a control algorithm provided in an embodiment of the present invention; Figure 3 This is a structural diagram of an adaptive normalization device for a large model-driven control algorithm mathematical formula provided in an embodiment of the present invention; Figure 4 This is a hardware architecture diagram of a computer device provided in an embodiment of the present invention. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are some embodiments of the present invention, but not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.
[0019] The specific implementation of the above concept is described below.
[0020] Please refer to Figure 1 This invention provides an adaptive normalization method for mathematical formulas of a large model-driven control algorithm, the method comprising: Step 100: Use the parser to generate error triples for each error node based on non-standard mathematical formula pseudocode, and perform error semantic classification on the error triples to generate category labels, thereby obtaining a structured semantic description of the error node; wherein, the error triples include at least the error pseudocode fragment, the parser error description, and the line number of the error node in the pseudocode; Step 102: Based on the structured semantic description, use the large model to generate the repair rules for this type of error, and dynamically fuse the differentiated repair rules to generate composite repair rules to cover multiple types of combined errors; Step 104: Using the parser for verification, the repair rules and composite repair rules generated by the large model are iteratively optimized to obtain a large model prompt word library for the normalization repair of non-standard mathematical formulas.
[0021] In this embodiment of the invention, 1. In the prior art, error messages from pseudocode parsers are typically presented as low-level syntax errors or lexical errors. There is a lack of semantic correlation between different error messages, making it difficult for developers to locate specific mathematical formula violations from discrete error texts. This solution semantically vectorizes the error causes and performs cluster analysis in the semantic vector space, grouping errors with different semantic expressions but the same essence into the same semantic category. This establishes a mapping relationship from low-level error messages to high-level semantic error categories, achieving structured modeling and accurate classification of non-standard mathematical formula pseudocode errors. This enables subsequent repair processes to develop targeted repair strategies for specific error categories.
[0022] 2. Existing code repair methods based on large language models typically use a single prompt word for end-to-end repair. When faced with concurrent errors of multiple types commonly found in control algorithm pseudocode, a single repair rule struggles to cover all error patterns, leading to incomplete repairs or the need for multiple, iterative repairs. This solution identifies heterogeneous error patterns with significant semantic differences by calculating the semantic similarity between repair rules of different categories. It then dynamically fuses the differentiated repair rules, error features, and repair examples to generate composite repair rules that can cover multiple combined errors in a single repair, significantly improving the repair efficiency and completeness in complex error scenarios.
[0023] 3. Existing large language models may generate repair rules with semantic biases and missing boundary conditions, and lack mechanisms for quantitative evaluation and automatic optimization of repair results. This solution verifies the repair results by inputting them into the parser. When verification fails, a reflective prompt word containing the original rule, the failure code, and the latest error message is constructed. This prompt drives the large language model to adaptively iteratively rewrite the rule. The parsing pass rate is used as a quantitative evaluation metric to control iterative convergence. This transforms the uncertain output of the large language model into validated, high-confidence static rules, achieving continuous evolution and quality assurance of the repair rules.
[0024] The proposed large-model-driven control algorithm mathematical formula adaptive normalization method addresses the problem of parsing blockage caused by non-compliance with writing standards in aerospace control software development. It achieves automated and accurate repair of non-standard mathematical formulas through three stages: parsing feedback semantic modeling, dynamic synthesis of composite repair rules, and closed-loop iterative optimization.
[0025] The following description Figure 1 The execution method of each step is shown.
[0026] For step 100: In some implementations, step 100 may include: The parser is used to construct a syntax tree of non-standard mathematical formula pseudocode, and the error nodes that fail to be constructed are identified. The error pseudocode fragment, parser error description and line number of the error node in the pseudocode of each error node are extracted as the error triplet of that error node. The parser error description of each error triplet is input into the pre-trained language model to obtain the error semantic vector of the parser error description. Based on the cosine similarity of the error semantic vectors, the error nodes are clustered to obtain the category label of each error node; By using category labels, error pseudocode snippets, line numbers, and error semantic vectors, a structured semantic description of each error node is generated.
[0027] In this embodiment, reference Figure 2 The flowchart illustrates how the goal of this embodiment is to transform the discrete error messages output by the parser into structured semantic descriptions, providing standardized input for the generation of subsequent repair rules. First, the non-standard mathematical formula pseudocode of the control algorithm is input into the pseudocode parser. This parser performs syntactic analysis on the input pseudocode based on predefined mathematical formula writing specifications, constructing the corresponding abstract syntax tree. In this embodiment, the writing specifications include 73 specific rules, covering requirements for format specifications, data type definitions, control flow structures, symbol usage, matrix representation, and typesetting. When the abstract syntax tree construction fails, the parser records the location information of the failed node during the syntax tree construction process. Through the syntax tree node backtracking mechanism, it traces back from the failed node to the corresponding original pseudocode location, extracting three key pieces of information: the erroneous pseudocode fragment of the erroneous node. Parser error description And the line number of the error node in the pseudocode. Constructing error triples Taking spacecraft attitude control algorithms as an example, when the parser encounters an error due to a dimension mismatch in matrix addition and subtraction, it may generate the following error triplet: The error pseudocode snippet is as follows: The parser reported an error: "Matrix addition and subtraction dimension mismatch," line number 22. When encountering a function parameter type mismatch, it may generate the following error pseudocode snippet: The parser reported an error message: "Function parameter type mismatch," line number 8. In practical projects, context code information indicating successful parsing can be appended to the error triplet. This refers to the code snippets that the parser has successfully converted during the construction of the abstract syntax tree, which are used to provide code context reference for subsequent fixes.
[0028] After obtaining a large number of erroneous triplet samples, the parser error description is... A unified semantic representation is performed. A pre-trained language model is used to encode each parser error description, mapping it to a fixed-dimensional real-number vector to obtain the error semantic vector of the parser error description. In the semantic vector space, clustering analysis is performed by calculating the cosine similarity between different error samples. The cosine similarity is calculated as the ratio of the inner product of two semantic vectors to the product of their magnitudes. Through this calculation, errors with different semantic expressions but identical essence can exhibit high similarity in the vector space, thus being grouped into the same high-level semantic category, resulting in category labels for each error node. In this embodiment, the non-standard expressions of the control algorithm are uniformly abstracted into six semantic problems: format and annotation standardization, data dictionary semantic alignment, control flow reconstruction, symbol and logic unification, vector or matrix expression repair, and typesetting encapsulation and detail issues. The above classification is based on semantic vector distribution, rather than simple keyword matching, thus ensuring the stability and scalability of the classification results. It should be noted that the above six semantic problems are the results of clustering based on actual engineering data in this embodiment. In different application scenarios, the number and specific categories obtained from clustering may vary.
[0029] After semantic clustering is completed, a structured semantic description is generated. ,in This represents the error category label. The structured semantic description is stored in key-value pair format, where the key includes the error category label, the error pseudocode snippet, the error line number, and the error semantic vector. Each structured semantic description corresponds to an independent error record. This representation enables error semantics to be expressed in a unified, computable form and serves as standard input to the subsequent remediation rule generation module.
[0030] Regarding step 102: In some implementations, step 102 includes: For each structured semantic description, obtain the correct baseline code, add the correct baseline code to the structured semantic description, and generate a quintuple repair sample; Using the five-tuple repair samples of each category, the large model outputs the repair rules for each five-tuple repair sample based on the syntactic and semantic differences between the erroneous pseudocode fragments and the correct baseline code of multiple repair samples under the same category, combined with the error semantic vector. Based on the cosine similarity of the semantic vectors between the repair rules corresponding to different categories, it is determined whether to perform repair rule fusion. When the cosine similarity of the semantic vectors between the repair rules of two quintuple repair samples is lower than the threshold, the repair rule, the error semantic vector, and the repair result of the error pseudocode fragment using the repair rule are concatenated to obtain a composite repair rule to replace the original repair rule of the two quintuple repair samples. If the cosine similarity of the semantic vectors between the repair rules of two quintuple repair samples is higher than a threshold, the repair rules of the two quintuple repair samples are unified into a repair rule with higher confidence.
[0031] In this embodiment, the goal is to use a large language model to reverse-engineer error correction rules for each category based on the structured semantic description output in step 100, and to dynamically fuse the differentiated rules through semantic similarity analysis to generate composite correction rules that can cover multiple combined errors. First, the structured semantic description output in step 100 is semantically enhanced and aligned. For each structured error sample, correct baseline code conforming to mathematical formula writing standards is introduced. The correct baseline code was obtained through manual or fully automated annotation, strictly adhering to pre-defined coding standards, and forms a one-to-one error-correct sample pair with the corresponding error pseudocode snippet. The error category label, error pseudocode snippet, error line number, error semantic vector, and correct baseline code are combined to construct a five-tuple repair sample. After obtaining the five-tuple repair samples, repair rules are automatically generated based on a large language model. Specifically, meta-hint words are constructed, grouping words belonging to the same error category... The set of five-tuple samples is used as input to the large language model as a few-shot example. The large language model receives multiple sets of five-tuple samples under the same error category and compares the error pseudocode fragments in each set of samples. With reference to the benchmark specification code The differences in syntactic structure and semantics between them, combined with error semantic vectors This study identifies the error characteristics in the data, summarizes the common repair patterns of this type of error, and outputs repair rules described in natural language. .
[0032] For example, for the category of "vector or matrix representation repair problem", the large language model may generate the following repair rule by analyzing multiple sets of error-correct sample pairs with mismatched matrix dimensions: "When there is a dimension inconsistency in matrix addition and subtraction operations, it is necessary to check whether the row and column dimensions of each matrix involved in the operation are the same. If they are different, the matrix needs to be transposed or divided into blocks to ensure that the dimensions of the matrices involved in the operation are strictly aligned." In the development of practical aerospace control algorithms, a piece of non-standard pseudocode often triggers multiple types of problems simultaneously. To improve the composite repair capability of large language models, this invention designs a dynamic prompt word fusion mechanism based on semantic differences. Utilizing a pre-trained text embedding model, the various repair rules generated by the large language model are integrated... Mapped to high-dimensional semantic feature vectors In the feature space, the cosine similarity between the repair rule vectors of different categories is calculated. A semantic difference judgment threshold is set. When the similarity between two repair rules is lower than this threshold, it is determined that the two error modes are significantly different in semantic space, that is, they belong to completely different but potentially concurrent error types. At this time, a heterogeneous rule fusion strategy is adopted to concatenate and aggregate the differentiated repair rules, error semantic vectors, and the repair results of the error pseudocode fragments using the repair rules. The concatenation and aggregation order is as follows: first, the system-level role setting instructions are placed; second, the natural language descriptions of each differentiated repair rule are concatenated in sequence; and finally, the repair results corresponding to each rule are attached to form a complete composite repair rule. This composite repair rule can effectively guide the large language model to perform multi-step reasoning in a complex control logic context, thereby achieving single full-coverage repair of multiple types of non-standard expressions. When the similarity between two repair rules is higher than or equal to the semantic difference judgment threshold, it indicates that the two error modes are relatively close in semantic space. At this time, the rule with higher confidence or wider coverage can be selected, and there is no need to fuse them.
[0033] In some implementations, correct baseline code is generated in a manner that enhances automation and reduces manual processing and review: By using the parser to validate the large model, the generated candidate expression set is sequentially subjected to variable lexical and syntactic standardization and operator standardization to obtain a standardized expression library. Based on the standardized expression library, semantic matching and semantic structure consistency verification are performed on erroneous pseudocode fragments to obtain the standardized formulas corresponding to the erroneous pseudocode fragments and thus obtain the correct baseline code.
[0034] In some implementations, parser validation and large modeling are used to sequentially perform variable lexical and syntactic standardization and operator standardization on the generated candidate expression set, resulting in a standardized expression library, including: Based on the defined lexical rules, a set of candidate expressions covering various combinations of syntactic structures is generated; among them, the structural combinations include at least subscript / superscript structures, nested bracket structures, function call structures, fractional structures, and matrix expression structures. The parser is used to perform lexical and syntactic analysis on each candidate expression in the candidate expression set, and the corresponding syntax tree is constructed. Discard the candidate expressions that fail to be constructed, and retain the candidate expressions that are successfully constructed, to obtain the initial set of canonical expressions; Using each equivalent transformation operator algorithm in the set of equivalent transformation operators, we perform operator transformation on each initial canonical expression in the set of initial canonical expressions, and use a parser to verify each initial canonical expression after operator canonicalization. After retaining the verified operator specifications, the initial specification expressions are replaced and merged with the initial specification expression set to obtain a specification mathematical expression library containing several specification expressions; Each canonical expression is input into the parser to construct a syntax tree, and the sequence of node types, hierarchical structure and child node relationships of the syntax tree are recorded to obtain the syntax tree structure representation of the canonical expression. The syntax tree of the specification expression is traversed in depth-first order. Each node is concatenated into a standardized string sequence according to the node type and child node structure. Then, the standardized string sequence is mapped into a fixed-dimensional semantic vector through a pre-trained large model to obtain a normalized semantic representation. By constructing triples using each canonical expression, syntax tree structure representation, and normalized semantic representation, a canonical expression library is obtained.
[0035] In this embodiment, the goal is to build a standardized expression library so that any expression in the library can be reliably verified by the parser, providing a reliable benchmark for subsequent semantic preservation mapping.
[0036] First, based on the lexical rules and grammatical production rules defined by the parser in the control algorithm code generation tool, a set of candidate expressions is systematically generated within the mathematical expression grammar space. Lexical rules define the construction methods of basic lexical units such as legal identifiers, operators, and delimiters; grammatical production rules define the structural combination methods of legal expressions, including subscript / superscript structures, nested bracket structures, function call structures, fractional structures, and matrix expression structures. The candidate expression generation process adopts a recursive expansion method based on grammatical production rules, starting from the top-level expression rules, selecting production branches layer by layer and filling in specific symbols to generate candidate expressions covering various structural combinations.
[0037] Taking spacecraft attitude control algorithms as an example, for quaternion operation formulas, the candidate expression set may contain multiple structural forms: different encapsulation methods for subscript variables, different index expressions for matrix elements, and different separation methods for function call parameters. For example, for the subscript expression of angular velocity components, the candidate set may contain both single-character subscript forms and curly brace-enclosed subscript forms.
[0038] Subsequently, each candidate expression is input into the parser for verification. The parser performs lexical and syntactic analysis on the candidate expressions, attempting to construct the corresponding abstract syntax tree. If the parser successfully constructs the syntax tree without errors, the verification is considered successful; otherwise, it is considered unsuccessful. Only the candidate expressions that have passed verification are retained, forming the initial set of canonical expressions.
[0039] In practical engineering, the same mathematical semantics often have multiple equivalent underlying expressions. For example, implicit multiplication and explicit multiplication have the same visual effect after rendering, but may produce different processing results during the parser's lexical analysis stage. To cover these boundary cases, this embodiment introduces a set of equivalent transformation operators. The set of equivalent transformation operators includes at least: an implicit multiplication to explicit multiplication transformation operator for inserting explicit multiplication signs between adjacent identifiers; a forced encapsulation transformation operator for uniformly encapsulating single-character subscripts or superscripts into curly braces; a unified transformation operator for flattening multi-level nested subscript and superscript structures into single-level subscript and superscript nesting levels; a normalization transformation operator for unifying inline fractions and independent fractions into standard fraction structures; and a function name standardization transformation operator for unifying non-standard function notation into standard function names recognizable by the parser. The above equivalent transformation operators are applied to each initial canonical expression in the initial canonical expression set to generate an operator-standardized initial canonical expression, which is then input into the parser for verification. Only the initial canonical expressions of the verified operators are retained and merged with the initial canonical expression set to finally construct a canonical mathematical expression library.
[0040] After constructing the standardized mathematical expression library, the syntax tree structure representation and normalized semantic representation are extracted for each standardized expression in the library. The syntax tree structure representation is extracted by inputting the standardized expression into the parser to construct a syntax tree, recording the node type sequence, hierarchical structure, and child node relationships. The normalized semantic representation is constructed by performing a depth-first traversal of the syntax tree, concatenating each node according to its node type and child node structure into a standardized string sequence, and then mapping this standardized string sequence into a fixed-dimensional semantic vector using a pre-trained text embedding model, resulting in the normalized semantic representation. Finally, a set of triplets containing the standardized expression, syntax tree structure representation, and normalized semantic representation is obtained. This set not only ensures parsingability at the syntactic level but also provides semantic comparability, offering a stable benchmark for subsequent input mapping.
[0041] In some implementations, based on a canonical expression library, semantic matching and semantic structure consistency checks are performed on erroneous pseudocode fragments to obtain the normalized formulas corresponding to the erroneous pseudocode fragments, thus obtaining the correct baseline code, including: The erroneous pseudocode fragment is pre-normalized to obtain a normalized representation of the erroneous pseudocode fragment; The normalized representation is input into a pre-trained large model, and the hidden layer vectors output by the model are extracted as the semantic representation vectors of the normalized representation. Calculate the cosine similarity between the semantic representation vector and each normalized semantic representation in the canonical representation library, and select the normalized semantic representation with the highest similarity as the candidate mapping result; Construct a target syntax tree for the normalized expression, and compare the node type sequences of the target syntax tree with those of the candidate mapping result syntax tree to perform semantic structure consistency verification. When the node type sequence matching rate is higher than the preset threshold, the verification is deemed to have passed, and the candidate mapping result is output as the normalized formula of the erroneous pseudocode fragment to obtain the correct baseline code; Otherwise, the next normalized semantic representation is selected in descending order of similarity and the semantic structure consistency is checked again until the check passes or the entire standard expression library is traversed.
[0042] In this embodiment, after obtaining the erroneous pseudocode fragment, it is first pre-normalized. Pre-normalization includes: eliminating whitespace differences by merging multiple consecutive spaces into a single space; unifying bracket representation by converting full-width brackets to half-width brackets; cleaning up redundant modifiers by deleting formatting modifiers that do not affect mathematical semantics; converting full-width characters to half-width characters; and unifying minus and multiplication signs of different encoding formats to standard minus and multiplication signs, respectively. After pre-normalization, a normalized expression is obtained. Subsequently, the semantic representation capability of the large model is used to construct the semantic representation vector of the normalized expression. Specifically, the normalized expression is input into a pre-trained language model, and the hidden layer vector output by the model is extracted as the semantic representation vector of the expression. In the triple set of the canonical expression library, the cosine similarity between the semantic representation vector of the normalized expression and the normalized semantic representation of each canonical expression is calculated, and the canonical expression with the highest similarity is selected as the candidate mapping result. To ensure semantic consistency in the mapping process, the semantic structure consistency of the normalized expression of the erroneous pseudocode fragment and the candidate mapping result is checked. The verification method is as follows: Construct a target syntax tree of the normalized expression, and compare the node type order of the target syntax tree with that of the candidate mapping result syntax tree. When the node type sequence matching rate is higher than a preset threshold, the verification is deemed successful, and the candidate mapping result is output as the normalization formula of the erroneous pseudocode fragment to obtain the correct baseline code; otherwise, the next normalized expression is selected in descending order of semantic similarity for re-verification until the verification is successful or the normalized expression library is traversed.
[0043] Taking attitude control algorithms in practical engineering as an example, the angular velocity vector representation in erroneous pseudocode snippets may use different subscript encapsulation methods. After pre-normalization, the semantically closest canonical expression is found in the canonical expression library through semantic similarity calculation. This canonical expression uses a standard subscript encapsulation form acceptable to the parser. After confirming the matching of the syntax tree structures of the two expressions through semantic structure consistency verification, the canonical expression is output as the final result, thus eliminating the problem of rendering equivalence but syntactic incompatibility while maintaining the mathematical semantics.
[0044] Regarding step 104: In some implementations, step 104 includes: For each category, perform the following: Construct a rule validation test set containing several non-standard pseudocode samples of the current category; Obtain the repair rules and composite repair rules generated by the large model in the current category. Use each repair rule and composite repair rule as the large model instruction to perform batch repair on the rule verification test set, and obtain several repair pseudocodes under each large model instruction. The parser is used to verify several repair pseudocodes under the large model instruction and generate an error log. The corresponding repair rules, the non-compliant code text after this repair, and the error log are concatenated to form a reflection prompt; Use reflection prompts as instructions for the large model to output optimized repair rules; After using the optimized repair rules to perform secondary repairs on several repair pseudocodes, the parser is used to verify the pseudocodes after secondary repairs, and the parsing pass rate of the current category on the rule verification test set is calculated. Determine whether the parsing pass rate meets the standard; If the criteria are met, it indicates that the current repair rule has been optimized, and the optimized repair rule will be solidified into the large model prompt word library; If the target is not met, it indicates that the current repair rule needs to be iterated and optimized. The optimized repair rule, the non-compliant code text after the second repair, and the error log are concatenated to form a new reflection prompt word. The execution jumps to use the reflection prompt word as a large model instruction and outputs the optimized repair rule until the optimization target is met or the maximum number of iterations is reached. The corresponding output is the final optimized repair rule solidified into the large model prompt word library or prompts that manual optimization failed. Continue optimizing every repair rule and composite repair rule for each category until the optimization is complete.
[0045] In this embodiment, the goal is to drive iterative optimization of the repair rules through parser verification feedback, gradually optimizing the initial repair rules and composite repair rules generated by the large language model into standardized rules with high confidence, and then solidifying them into the basic prompt word library.
[0046] Repair rules generated by reverse engineering the large language model in step 102 and composite repair rules A separate rule validation test suite is constructed. This test suite contains multiple non-standard pseudocode samples belonging to the corresponding error categories, used to evaluate the generality and effectiveness of the remediation rules. The remediation rules are then... and composite repair rules As an instruction, non-standard pseudocode samples in the test set are batch-repaired. The large language model standardizes each non-standard pseudocode according to the repair rules, generating several repaired pseudocodes. These repaired pseudocodes are then input into a pseudocode parser for verification. When the parser returns new error logs... When, it indicates the current repair rule. There are logical flaws or insufficient constraint strength. In this case, reflective prompts are constructed for adaptive iterative optimization. The reflective prompts are constructed by: taking the repair rules... The non-compliant code text after this fix and error log The system is assembled according to a preset template. The template is set to guide the large language model to analyze the reasons for rule failure and output the instructional statements for the improved rules.
[0047] After receiving reflection prompts, the large language model analyzes the root causes of the current rule's failure, identifies missing constraints or inaccurately defined boundary conditions, dynamically rewrites and strengthens the constraints and boundary definitions in the rule, and outputs the optimized and repaired rule. To improve the generality and engineering usability of the quantification rules, the statistically optimized repair rules are... Parsing pass rate on this type of error test set The parsing success rate represents the number of samples that successfully generated an abstract syntax tree without any parsing errors. Compared with the total number of test set samples The ratio of .
[0048] A threshold for rule validity is set. When the parsing pass rate is below this threshold, it indicates that the repair rule still needs further optimization, and the above iterative process continues. When the parsing pass rate reaches or exceeds the threshold, the validity of the repair rule is considered to have converged. A maximum iteration limit is set during the iteration process. When the iteration limit is reached but the parsing pass rate still does not reach the rule validity threshold, the iteration is terminated, and the current version of the repair rule is marked as awaiting manual review. Simultaneously, the repair rule version with the highest parsing pass rate in each iteration is output as a candidate rule for engineers to refer to and manually refine. Finally, the repair rule that meets the threshold standard is selected. The extracted and solidified words will be incorporated into a standardized basic prompting word library. This mechanism transforms the uncertainty of dynamic deduction in large language models into the determinism of static rules, enabling the system to directly call high-confidence basic prompting words when facing future control algorithm standardization tasks, achieving high-precision, low-latency automated repair.
[0049] Through the above three steps, this invention realizes a complete technical chain from analytical feedback semantic modeling to dynamic synthesis of composite repair rules, and then to closed-loop iterative optimization. It can effectively solve the analytical blocking problem caused by non-standard mathematical formulas of control algorithms, significantly improve the automatic standardization efficiency and repair accuracy of mathematical formulas of control algorithms, and provide core technical support for agile iteration and high-reliability delivery of spacecraft control software.
[0050] Please refer to Figure 3 This invention provides an adaptive normalization device for mathematical formulas of a large model-driven control algorithm, used to implement the steps of any method embodiment in the specification. The device includes: Modeling unit 301 is used to generate error triples for each error node using a parser based on non-standard mathematical formula pseudocode, and to perform error semantic classification on the error triples to generate category labels, thereby obtaining a structured semantic description of the error node; wherein, the error triples include at least an error pseudocode fragment, a parser error description, and the line number of the error node in the pseudocode; The generation unit 302 is used to generate repair rules for this type of error based on structured semantic description and large model, and to dynamically fuse the differentiated repair rules to generate composite repair rules to cover multiple types of combined errors. The optimization unit 303 is used to iteratively optimize the repair rules and composite repair rules generated by the large model using the parser verification, so as to obtain a large model prompt word library for the normalization repair of non-standard mathematical formulas.
[0051] It should be noted that the above device embodiments and method embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0052] Embodiments of this application also provide a computer device, please refer to... Figure 4 The computer device includes a processor and a memory, the memory storing at least one instruction, at least one program, code set, or instruction set, the at least one instruction, at least one program, code set, or instruction set being loaded and executed by the processor to implement the large model-driven control algorithm mathematical formula adaptive normalization method provided in the above method embodiments.
[0053] Embodiments of this application also provide a computer-readable storage medium storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, at least one program, code set, or instruction set is loaded and executed by a processor to implement the large model-driven control algorithm mathematical formula adaptive normalization method provided in the above-described method embodiments.
[0054] Embodiments of this application also provide a computer program product, which includes a computer program. A processor of a computer device reads the computer program from a computer-readable storage medium and executes the computer program, causing the computer device to perform any of the large model-driven control algorithm mathematical formula adaptive normalization methods described in the above embodiments.
[0055] For ease of description, the above devices or apparatuses are described separately according to their functions, divided into various modules or units. Of course, in implementing this application, the functions of each unit can be implemented in one or more software and / or hardware.
[0056] As can be seen from the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solution of this application, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of various embodiments or some parts of the embodiments of this application.
[0057] Finally, it should be noted that in this document, relational terms such as first, second, third, and fourth are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the element.
[0058] The above are merely preferred embodiments of this application. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. An adaptive normalization method for mathematical formulas of a large model-driven control algorithm, characterized in that, include: The parser generates error triples for each error node based on non-standard mathematical formula pseudocode, and performs error semantic classification on the error triples to generate category labels, thereby obtaining a structured semantic description of the error node; wherein, the error triples include at least an error pseudocode fragment, a parser error description, and the line number of the error node in the pseudocode; Based on the structured semantic description, a large model is used to generate repair rules for this type of error, and the differentiated repair rules are dynamically fused to generate composite repair rules that cover multiple types of combined errors. By using the parser for verification, the repair rules and composite repair rules generated by the large model are iteratively optimized to obtain a large model prompt word library for the normalization repair of non-standard mathematical formulas; Based on the structured semantic description, a large model is used to generate repair rules for this type of error, and the differentiated repair rules are dynamically fused to generate composite repair rules to cover multiple types of combined errors, including: For each of the structured semantic descriptions, obtain the correct baseline code, add the correct baseline code to the structured semantic description, and generate a quintuple repair sample; Using the five-tuple repair samples of each category, the large model outputs the repair rules for each five-tuple repair sample based on the syntactic and semantic differences between the error pseudocode fragments and the correct baseline code of multiple repair samples under the same category, combined with the error semantic vector. Based on the cosine similarity of the semantic vectors between the repair rules corresponding to different categories, it is determined whether to perform repair rule fusion. When the cosine similarity of the semantic vectors between the repair rules of two quintuple repair samples is lower than the threshold, the repair rule, the error semantic vector, and the repair result of the error pseudocode fragment using the repair rule are concatenated to obtain a composite repair rule to replace the original repair rule of the two quintuple repair samples. When the cosine similarity of the semantic vectors between the repair rules of two quintuple repair samples is higher than a threshold, the repair rules of the two quintuple repair samples are unified into a repair rule with high confidence. The correct baseline code is generated in the following manner: Using a parser and a large model, the generated candidate expression set is sequentially subjected to variable lexical and syntactic standardization and operator standardization to obtain a standardized expression library; Based on the aforementioned standardized expression library, semantic matching and semantic structure consistency verification are performed on the erroneous pseudocode fragments to obtain the standardized formulas corresponding to the erroneous pseudocode fragments and thus obtain the correct baseline code. The process involves using a parser and a large model to sequentially perform variable lexical and syntactic standardization and operator standardization on the generated candidate expression set, resulting in a standardized expression library, including: Based on the defined lexical rules, a set of candidate expressions covering various combinations of syntactic structures is generated; among them, the structural combinations include at least subscript / superscript structures, nested bracket structures, function call structures, fractional structures, and matrix expression structures. The parser is used to perform lexical and syntactic analysis on each candidate expression in the candidate expression set, and the corresponding syntax tree is constructed. Discard the candidate expressions that fail to be constructed, and retain the candidate expressions that are successfully constructed, to obtain the initial set of canonical expressions; Using each equivalent transformation operator algorithm in the set of equivalent transformation operators, perform operator transformation on each initial canonical expression in the set of initial canonical expressions, and use a parser to verify each initial canonical expression after operator canonicalization; After retaining the verified operator specifications, the initial specification expressions are replaced and merged with the initial specification expression set to obtain a specification mathematical expression library containing several specification expressions; Each of the canonical expressions is input into the parser to construct a syntax tree, and the node type sequence, hierarchical structure and child node relationship of the syntax tree are recorded to obtain the syntax tree structure representation of the canonical expression; The syntax tree of the specification expression is traversed in depth-first order. Each node is concatenated into a standardized string sequence according to the node type and child node structure. Then, the standardized string sequence is mapped into a fixed-dimensional semantic vector through a pre-trained large model to obtain a normalized semantic representation. By constructing triples using each of the canonical expressions, the syntax tree structure representation, and the normalized semantic representation, a canonical expression library is obtained.
2. The method as described in claim 1, characterized in that, The process involves using a parser to generate error triples for each error node based on non-canonical mathematical formula pseudocode, and then performing error semantic classification on the error triples to generate category labels, thereby obtaining a structured semantic description of the error node, including: The parser is used to construct a syntax tree of non-standard mathematical formula pseudocode, and the error nodes that failed to be constructed are identified. The error pseudocode fragment, parser error description and line number of the error node in the pseudocode of each error node are extracted as the error triplet of that error node. The parser error description of each error triple is input into the pre-trained language model to obtain the error semantic vector of the parser error description. Based on the cosine similarity of the error semantic vectors, clustering of error nodes is performed to obtain the category label of each error node; Using the category label, the error pseudocode snippet, the line number, and the error semantic vector, a structured semantic description of each error node is generated.
3. The method as described in claim 1, characterized in that, The parser-based verification process iteratively optimizes the repair rules and composite repair rules generated by the large model to obtain a large model-based suggestion lexicon for standardizing and repairing non-standard mathematical formulas, including: For each category, perform the following: Construct a rule validation test set containing several non-standard pseudocode samples of the current category; Obtain the repair rules and composite repair rules generated by the large model in the current category, use each repair rule and composite repair rule as a large model instruction, and perform batch repair on the rule verification test set respectively to obtain several repair pseudocodes under each large model instruction; The parser is used to verify several repair pseudocodes under the large model instruction and generate an error log. The corresponding repair rules for this instruction, the non-compliant code text after this repair, and the error log are concatenated to form a reflection prompt. The aforementioned reflection prompts are used as instructions for the large model to output optimized repair rules. After using the optimized repair rules to perform secondary repairs on several repair pseudocodes, the parser is used to verify the pseudocodes after secondary repairs, and the parsing pass rate of the current category on the rule verification test set is calculated. Determine whether the parsing pass rate meets the standard; If the criteria are met, it indicates that the current repair rule has been optimized, and the optimized repair rule will be solidified into the large model prompt word library; If the target is not met, it indicates that the current repair rule needs to be iterated and optimized. The optimized repair rule, the non-compliant code text after the second repair, and the error log are concatenated to form a new reflection prompt word. The execution jumps to the instruction of the reflection prompt word as the big model instruction, outputs the optimized repair rule, until the optimization target is met or the maximum number of iterations is reached. The corresponding output is the final optimized repair rule solidified into the big model prompt word library or prompts that manual optimization failed. This continues until the optimization of each repair rule and the composite repair rule for each category is completed.
4. A large model-driven control algorithm mathematical formula adaptive normalization device, used to implement the steps of the method described in any one of claims 1-3, characterized in that, include: The modeling unit is used to generate error triples for each error node using a parser based on non-canonical mathematical formula pseudocode, and to perform error semantic classification on the error triples to generate category labels, thereby obtaining a structured semantic description of the error node; wherein, the error triples include at least an error pseudocode fragment, a parser error description, and the line number of the error node in the pseudocode; The generation unit is used to generate repair rules for this type of error based on the structured semantic description using a large model, and to dynamically fuse the differentiated repair rules to generate composite repair rules that cover multiple types of combined errors. The optimization unit is used to iteratively optimize the repair rules and composite repair rules generated by the large model using the parser verification, so as to obtain a large model prompt word library for the normalization and repair of non-standard mathematical formulas.
5. A computer device, characterized in that, The computer device includes a memory and a processor. The memory is used to store computer programs, and the processor is used to execute the computer programs stored in the memory to implement the steps of the method according to any one of claims 1-3.
6. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the steps of the method described in any one of claims 1-3.
7. A computer program product, characterized in that, Includes a computer program, which, when executed by a processor, implements the steps of the method according to any one of claims 1-3.
Citation Information
Patent Citations
Code generation and repair method and device based on multi-round feedback of large language model
CN121523669A
Autonomous, exception-driven code-fixing system with intelligent log analysis and automated merge requests
DE202025102436U1