Cross-domain language optimization method and system based on formal semantics
By parsing the domain language into a unified action dependency graph and combining it with a meta-information catalog and hierarchical verification, candidate execution plans are generated and evaluated. This solves the problem of balancing rigor and flexibility in cross-domain language optimization, and achieves efficient cross-domain optimization and risk adaptation.
Patent Information
- Application Number
- CN202511599776.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-04
- Publication Date
- 2026-01-23
AI Technical Summary
In existing technologies, formal proof systems present a contradiction between rigor and flexibility, making them difficult to apply across different domains. Furthermore, systems based on large language models lack rigorous semantic guarantees, making it difficult for users to balance reliability and flexibility.
A cross-domain language optimization method based on formal semantics is adopted. By parsing the domain language into a unified action dependency graph, and combining the meta-information catalog and hierarchical verification strategy, multiple semantically preserved candidate execution plans are generated. Multi-objective evaluation is performed through a meta-information-aware cost model, and the optimal solution is finally selected.
It achieves a dynamic balance between rigor and flexibility, adapts to multiple domain languages, provides appropriate semantic equivalence guarantees, improves execution performance and resource utilization, and is particularly suitable for high-risk scenarios.
Smart Images

Figure CN121387946A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer software engineering, programming language processing, and artificial intelligence, specifically to a cross-domain language optimization method and system based on formal semantics. Background Technology
[0002] With the continuous development of information technology, domain-specific languages (DSLs) and general-purpose programming languages are widely used in data processing, business process automation, system monitoring, and other scenarios. Existing technologies include optimizers for specific languages, such as SQL query optimizers and compilers for relational databases. These optimizers are typically designed for a single language and are difficult to apply across different domains.
[0003] Existing technologies exhibit a clear polarization problem: on the one hand, formal proof systems (such as Coq and Lean) can provide strict correctness guarantees, but they have high barriers to entry, poor flexibility, and limited applicability; on the other hand, probabilistic semantic optimization systems based on large language models (LLM), while highly flexible, lack rigorous semantic guarantees and have insufficient reliability of results.
[0004] These two types of systems operate on separate technological paths, forcing users to make trade-offs between reliability and flexibility. Therefore, there is an urgent need in this field for a universal optimization framework that can achieve a dynamic balance between rigor and flexibility, thus ensuring both reliability and practicality. Summary of the Invention
[0005] The purpose of this invention is to provide a cross-domain language optimization method and system based on formal semantics to solve the problems mentioned in the background art.
[0006] To achieve the above objectives, the present invention provides the following technical solution:
[0007] A cross-domain language optimization method based on formal semantics includes the following steps:
[0008] It receives input in at least one domain language; the domain language includes, but is not limited to, SQL query language, natural language, programming language, mathematical language, and workflow definition language.
[0009] The input is parsed into a unified intermediate representation, which is an action-dependency graph constructed based on action nodes, dependency edges, and relative time anchors.
[0010] The metadata directory is queried to obtain contextual information related to optimization decisions; the metadata includes at least one of event metadata, data storage metadata, system runtime metadata, and permission and business constraint information.
[0011] transforming the action dependency graph based on predefined transformation rules (e.g. rewrite rules, algebraic transformation rules) to generate a plurality of candidate execution plans that preserve semantics.
[0012] performing semantic equivalence verification on the candidate execution plans using a hierarchical verification strategy that provides multiple verification levels (e.g. Level 0 to Level 3) from lightweight heuristic checks to fully formalized machine verification. The system dynamically selects the verification level based on the risk level of the target domain, confidence in the meta-information, or user configuration.
[0013] performing multi-objective cost evaluation on the verified candidate execution plans using a meta-information-aware cost model that takes into account estimated execution time, resource consumption, cognitive complexity, and handles uncertainty when meta-information is incomplete.
[0014] selecting and outputting the optimal plan from the candidate execution plans based on the results of the multi-objective cost evaluation.
[0015] Additionally, the method further comprises a feedback step of: executing the optimal plan, monitoring its actual performance, and writing data back to the meta-information catalog for continuous optimization of the cost model and transformation rules.
[0016] A formal semantics-based cross-domain language optimization system for implementing the above method, comprising:
[0017] an input parsing module configured to receive and parse different domain languages through an extensible adapter framework to generate a unified action dependency graph.
[0018] a meta-information catalog module that stores various contextual meta-information and provides a unified query interface.
[0019] a candidate generation module configured to transform the action dependency graph based on a predefined transformation rule library to generate a plurality of candidate execution plans.
[0020] a hierarchical verification module configured to implement multiple verification levels (e.g. Level 0 to Level 3) for verifying the semantic equivalence of candidate execution plans.
[0021] a meta-information-aware cost model module configured to combine meta-information to perform multi-objective cost quantitative evaluation on candidate execution plans.
[0022] a plan selection module configured to select the optimal plan from the verified candidate plans based on the cost evaluation results.
[0023] An execution and feedback module is configured to execute the optimal scheme, collect performance data, and feed back to the meta-information directory and the cost model to form a closed-loop learning optimization cycle.
[0024] Compared with the prior art, the present application has the following advantages:
[0025] 1、The present application can adapt to various fields from highly structured SQL to fuzzy natural language through unified action dependency graph intermediate representation and extensible adapter framework, so that the cost of developing an optimizer for each language is reduced.
[0026] 2、The present application provides just-right semantic equivalence protection for different risk level application scenarios through a configurable hierarchical verification mechanism, and is particularly suitable for high-risk scenarios such as finance and law.
[0027] 3、The present application enables the optimization decision to dynamically respond to system state and data characteristics through the meta-information-aware cost model, so that the decision is more accurate, and the execution performance, resource utilization and result quality can be effectively improved. BRIEF DESCRIPTION OF DRAWINGS
[0028] Figure 1 is a system architecture schematic diagram of the present application.
[0029] Figure 2 is a method flow schematic diagram of the present application.
[0030] Figure 3 is a meta-information directory data mode schematic diagram of the present application.
[0031] Figure 4 is a hierarchical verification strategy flow schematic diagram of the present application. DETAILED DESCRIPTION
[0032] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0033] Embodiment one
[0034] The present application aims to solve the problem that the existing language optimization technology cannot achieve dynamic balance between formal rigor and semantic flexibility. By introducing a meta-information directory and a configurable hierarchical verification mechanism, the present application realizes the purpose of adaptive optimization of cross-field languages under the premise of guaranteeing semantic reliability. Due to the real-time analysis of various field languages, dynamic query and reasoning of complex meta-information, and computationally intensive formal verification, the following technical targets need to be achieved relying on hardware architecture:
[0035] The primary objective is to provide high-throughput language parsing and intermediate representation conversion capabilities.
[0036] The second objective is to achieve low-latency metadata querying and cost estimation.
[0037] The third objective is to support parallelized candidate solution generation and hierarchical verification to fully utilize multi-core computing resources.
[0038] Based on the above technical requirements, this embodiment adopts the following... Figure 1 The architecture shown is a "streaming optimization based on meta-information catalog".
[0039] Front-end parsing and distribution cluster: This architecture consists of a group of stateless parser nodes, each equipped with a dedicated hardware accelerator (such as an FPGA) for syntax and lexical analysis of a specific language (SQL, natural language, etc.). Parser nodes receive input through a load balancer, bind the generated Action Dependency Graph (ADG) to a globally unique optimized session ID, and publish it to a high-speed message bus (such as Apache Kafka). This design ensures system resilience and scalability under high-concurrency input scenarios.
[0040] Metadata Catalog and Query Grid: This structure is the core of the system, implemented by a distributed key-value store (such as Redis Cluster) and a graph database (such as Neo4j). The key-value store is responsible for caching frequently accessed, simple metadata (such as real-time system load), while the graph database is responsible for storing and managing complex, highly relational metadata (such as data lineage and permission inheritance relationships). The query grid layer provides a unified GraphQL interface to upper-layer modules and has a built-in query optimizer that can decompose a complex multi-condition query into multiple parallel subqueries, thereby achieving low-latency response.
[0041] The core computing cluster is optimized as follows: This architecture consists of multiple heterogeneous computing units. The candidate generator module is deployed on general-purpose CPU servers, using a rule engine (such as Drools) to load transformation rules. The hierarchical validator module is scheduled to different hardware resources according to the verification level: Level 0-1 verification is performed on the CPU cluster; Level 2-3 formal verification is scheduled to workstations equipped with large memory and dedicated mathematical coprocessors, or even gateway nodes that can call remote formal verification services (such as Coq or Z3's cloud API). The cost model module, as an independent microservice, allows its computation process to be monitored and audited.
[0042] like Figures 2-4 As shown, the specific process of the "cross-domain language optimization method based on formal semantics" executed on this architecture includes:
[0043] Step S1, input parsing and action dependency graph construction.
[0044] Receive domain language input, automatically route to corresponding parser according to input header information or content. Parser converts input sentence into initial action dependency graph , where V0 is the set of action nodes, is the set of dependency edges. For each action node , extract its core semantic action , input / output data type , and explicit or implicit relative time constraints . Dependency edge indicates that the execution of node depends on the output of node . The ADG output by this step is a directed acyclic graph.
[0045] Step S2, meta-information association and context enhancement.
[0046] The system takes the optimized session ID as the context, submits the initial ADG to the meta-information directory query grid. The query grid performs a multi-step association query:
[0047] First, for each action node , according to its action type and data type , query its required permission set and recommended execution environment .
[0048] Second, for nodes involving data access, query data storage meta-information to obtain data distribution statistics such as cardinality and selectivity .
[0049] Finally, query system runtime meta-information to obtain current available resources and average service delay .
[0050] All these meta-information are injected into the ADG, forming an enhanced action dependency graph .
[0051] Step S3, candidate execution plan generation and cost preliminary estimation.
[0052] The candidate generator loads the transformation rule library suitable for the current language type . Each rule is defined as , where It is a pattern matching condition. It's a template transformation. The generator pairs... Perform a breadth-first search, apply all matching rules, and generate a set of candidate execution plans. .
[0053] For each candidate plan A preliminary cost estimate is then made using the cost model. Cost function. It is a multi-objective weighted sum:
[0054]
[0055] in, It is an estimated time cost. This is the basic operation time. It is the current system load factor. It is an estimate of resource consumption. For memory consumption, CPU consumption. The uncertainty lies in the outcome, the calculation of which depends on the confidence level of the metadata. .set up yes The set of meta-information on which it depends, then:
[0056]
[0057] in, It is a weighting coefficient, and The ratio is determined based on different optimization objectives.
[0058] Step S4: Hierarchical semantic equivalence verification.
[0059] The graded validator is Each candidate plan Dynamically select verification level The strategy selection is based on a risk assessment function. :
[0060]
[0061] in, This is the inherent risk coefficient of the field (e.g., 0.9 in the financial field and 0.1 in log analysis). yes The minimum confidence level of the metadata on which it is based. The complexity of the graph is given by the formula. The calculation shows that, among which and The figures are respectively The number of nodes and the number of edges, It is a normalization constant.
[0062] According to the value of , the verification level is mapped to:
[0063] < 0.2 → Level 0 (syntax and pattern matching).
[0064] 0.2 ≤ < 0.5 → Level 1 (constraint solving, verifying whether input / output constraints are satisfied).
[0065] 0.5 ≤ < 0.8 → Level 2 (theorem proving, verifying the equivalence of program fragments under an axiomatic system).
[0066] ≥ 0.8 → Level 3 (fully formalized machine verification, generating complete proof terms).
[0067] The verified candidate plan is marked as safe and enters the final selection pool .
[0068] Step S5, final cost optimization and scheme selection with meta-information awareness.
[0069] The scheme selector performs the final cost actuarial calculation on the plans in . At this time, the cost function will introduce a more refined model, especially for meta-information with uncertainty, to perform Monte Carlo simulation to calculate the expected cost and risk cost .
[0070] The final decision function is:
[0071]
[0072] where is the risk aversion coefficient. is selected as the optimal scheme.
[0073] Step S6, scheme execution and closed-loop feedback learning.
[0074] The execution engine executes , and monitors its real performance indicators throughout the process, including actual execution time , resource usage peak , etc. These data are packaged together with the optimization session ID as feedback data packets and sent back to the meta-information directory.
[0075] The cost model uses these feedback data to learn online, updating its internal parameters using stochastic gradient descent, e.g., to correct the estimate of
[0076]
[0077] where is the learning rate, is the actual time cost of a node , and is the predicted time cost. This allows the system’s cost prediction capability to evolve over time.
[0078] Embodiment Two
[0079] Suppose a user inputs the natural language instruction: “If the server CPU exceeds 90% for 5 minutes, then immediately scale out and notify the on-call staff.” The system needs to optimize this instruction into an executable workflow.
[0080] Step S1: The natural language parser identifies three core action nodes:
[0081] v1: Action = Monitor_CPU, Params = (threshold = 90%, duration = 5min)
[0082] v2: Action = Scale_Out, Params = (instance_type = 'large', count = 2)
[0083] v3: Action = Notify_OnCall, Params = (role = 'SRE')
[0084] Build the initial (i.e., the monitoring triggers the subsequent two parallel actions). The time anchor: is the starting point, and the relative time of both (immediately execute).
[0085] Step S2: Query the meta-information catalog to obtain:
[0086] For : the confidence of the monitoring data source .
[0087] For : the average delay of the current cloud platform scaling API , and the current regional resources are sufficient.
[0088] For : From CMDB query the current SRE on-call is "Zhang San", and his WeChat Work online status is "busy", confidence level .
[0089] Meta information is injected, forming .
[0090] Step S3: Candidate generator applies rules, e.g. "Parallelize independent actions", but since and are already parallel, this rule does not take effect. Apply "Route optimization" rule: since 's meta information shows the on-call status is busy, generate a candidate plan , where is replaced by , with action Notify_OnCall_With_Fallback, and parameter added fallback_strategy='escalate_to_team_chat'.
[0091] Cost preliminary estimation: assume 's is high, while is reduced by introducing fallback notification strategy, although is slightly increased, thus may be lower than the original plan.
[0092] Step S4: Calculate the risk level of .
[0093] Assume = 0.7 (IT operation), , is calculated as 0.4.
[0094] Then:
[0095]
[0096] Since 0.084 < 0.2, the system automatically selects Level 1 verification for this candidate plan. The verifier performs constraint solving, and the key constraint checked is: "The notification action must be acknowledged within 60 seconds after the scaling action occurs". Given and fallback notification strategy, the verifier proves that this time constraint can be satisfied, and the verification passes.
[0097] Step S5: Perform final cost calculation for the original plan in and .
[0098] Original plan Lower, but The risk is high because there is a risk of notification failure.
[0099] of Because the backup strategy is slightly higher, but Extremely low.
[0100] Assumption The risk aversion coefficient is set to a relatively high value of 0.8 in this operational scenario. The final decision function is calculated as follows:
[0101]
[0102]
[0103] because > ,final < (As originally planned), therefore the system selected As the optimal solution.
[0104] Step S6: System Execution Upon detecting an excessive CPU threshold, the system executes both capacity expansion and notification in parallel (first notifying Zhang San, who is busy, then automatically escalating to team group notification after 30 seconds). Actual execution time... Recorded. During this execution, because the fallback strategy was effective and notification omissions were avoided, the system recorded that this optimization brought positive benefits and used this data to update the notification action. of and By considering the confidence level and cost parameters of relevant metadata, closed-loop learning was completed.
[0105] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A cross-domain language optimization method based on formal semantics, characterized in that, Includes the following steps: It can receive input in at least one domain-specific language; The input is parsed into a unified intermediate representation, which is an action dependency graph constructed based on action nodes, dependency edges, and relative time anchors; Query the metadata directory to obtain contextual information relevant to optimization decisions; The action dependency graph is transformed based on predefined transformation rules to generate multiple semantically preserved candidate execution plans; A hierarchical verification strategy is adopted to perform semantic equivalence verification on the candidate execution plan. The hierarchical verification strategy provides multiple verification levels, from lightweight heuristic checks to fully formal machine verification. Using a cost model that is aware of meta-information, a multi-objective cost assessment is performed on the validated candidate execution plans; Based on the results of the multi-objective cost assessment, the optimal solution is selected and output from the candidate execution plans.
2. The cross-domain language optimization method and system based on formal semantics according to claim 1, characterized in that: The domain language includes at least one of SQL query language, natural language, programming language, mathematical language, and workflow definition language.
3. The cross-domain language optimization method and system based on formal semantics according to claim 1, characterized in that: The metadata stored in the metadata directory includes at least one of the following: Event metadata includes the event's occurrence time, source, and confidence level; Data storage metadata, including data index information, statistical information, and partition information; System runtime metadata, including system load, resource utilization, and network status; Permissions and business constraints information.
4. The cross-domain language optimization method and system based on formal semantics according to claim 1, characterized in that: The step of performing semantic equivalence verification on the candidate execution plan using a hierarchical verification strategy further includes: The verification level is dynamically selected based on the risk level of the target domain, the confidence information in the metadata catalog, or user configuration. The verification levels include at least the following: Level 0: Lightweight heuristic validation based on syntax checking and pattern matching; Level 1: Constraint satisfaction verification based on symbolic execution and constraint solving; Level 2: Formal equivalence verification based on theorem provers; Level 3: Achieve fully formalized machine verification with full path coverage.
5. The cross-domain language optimization method and system based on formal semantics according to claim 1, characterized in that: The multi-objective cost evaluated by the meta-information perception cost model includes at least one of the following: Estimated execution time; Estimated resource consumption; The cognitive complexity of the output results; The cost model is configured to perform uncertainty propagation and calculation when the metadata is incomplete or has a certain level of confidence.
6. The cross-domain language optimization method and system based on formal semantics according to claim 1, characterized in that: Also includes: Execute the optimal solution and monitor its actual performance. The actual operating performance is written back to the metadata directory as feedback data for continuous optimization of the cost model and transformation rules.
7. The cross-domain language optimization method and system based on formal semantics according to claim 1, characterized in that: The method employs a phased implementation strategy, specifically including: Prioritize implementation for SQL query optimization and workflow optimization scenarios, and configure the first verification level; Subsequently, a second verification level was implemented for natural language processing scenarios, which included a human-machine in-loop confirmation mechanism. The second verification level was more stringent than the first verification level.
8. A cross-domain language optimization system based on formal semantics for implementing the method as described in any one of claims 1 to 7, characterized in that, include: The input parsing module is configured to receive input from different domain languages and parse it into a unified action dependency graph; The metadata catalog module stores contextual information related to optimization decisions and provides a query interface; The candidate generation module is configured to transform the action dependency graph based on predefined transformation rules to generate multiple candidate execution plans; The hierarchical verification module is configured to provide multiple verification levels to verify the semantic equivalence between the candidate execution plan and the original input; The cost model module for meta-information perception is configured to perform multi-objective cost quantification evaluation of candidate execution plans by combining information from the meta-information catalog. The scheme selection module is configured to select the optimal scheme from the validated candidate execution plans based on the evaluation results of the cost model module.
9. The system according to claim 8, characterized in that, The input parsing module integrates multiple parsers through an extensible adapter framework, with each parser corresponding to a specific domain language.
10. The system according to claim 8, characterized in that, It also includes an execution and feedback module, configured to execute the selected optimal solution, collect runtime performance data, and feed the data back to the metadata catalog module and the cost model module to form a closed-loop learning optimization cycle.