Method and system for automatically generating functions based on truth table
By using a truth table-based automatic function generation method, and leveraging an encoder-decoder neural network model and a self-attention mechanism, the shortcomings of existing binary stream example programming and logical expression generation technologies are addressed. This achieves efficient generation of logical expressions and ensures that the relationships between logical expression syntax symbols are independent of distance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INST OF COMPUTING TECH CHINESE ACAD OF SCI
- Filing Date
- 2022-08-22
- Publication Date
- 2026-06-05
Smart Images

Figure CN115329949B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of truth tables, neural networks, and program synthesis, and particularly to a method and system for automatic function generation based on truth tables. Background Technology
[0002] Program synthesis is one of the core problems in programming theory. It involves automatically finding programs from the underlying programming language that satisfy user intents represented by certain constraints. The main challenges lie in the complexity of the program space and the ambiguity of user intents. Current mainstream program synthesis techniques have been applied to fields such as data processing, strategy design, code repair, and code optimization, providing convenience for programmers. For example, automating Excel programming can reduce development time from days to seconds.
[0003] The most common program synthesis problem currently is example programming, which conveys user intent based on given constraints from examples. Example programming problems were first addressed in the Karel problem of 1981, which involves generating programs in a programming language or domain-specific language given a small number of input / output example samples. Input / output examples may be data in the form of strings, lists of integers, spreadsheets, grids, etc. Binary data, as a universal data representation in computers, is currently the most common and readily available data representation in information systems. However, there is currently little research on example programming using binary streams as the example format. Therefore, there is an urgent need for example programming methods based on truth tables for automated function generation.
[0004] In 2008, Solar-Lezama proposed using a syntax for constrained program spaces in program synthesis, giving the solution a structured character. While the syntax for program spaces can correspond to the syntax of actual programming languages used in computer programming, the program spaces defined by programming languages are often not conducive to the description and solution of program synthesis problems. Therefore, to express user intent through constraints and to select suitable programs from the program space, researchers have designed domain-specific languages for specific program synthesis problems. Example programming typically uses domain-specific languages, which offer mixed-function operations. The domain-specific language for the FlashFill task can perform operations such as string extraction, splitting, concatenation, and replacement; the domain-specific language for the Deepcoder task can perform operations such as filtering, sorting, reversing, summing, and multiplying integer lists; and the domain-specific language for the Karel task can specify operations such as agent displacement, orientation, addition and subtraction on a grid, as well as some branching structures. Therefore, there is an urgent need for a domain design language that is compatible with some compiler structures.
[0005] Binary data, as a universal data representation in computers, is currently the most common and readily available data representation in information systems. However, there are few example programming studies that use binary streams as an example format.
[0006] Example programming problems were first introduced in the Karel problem of 1981. Given a small number of input / output example samples, the goal is to generate a program in a programming language or a domain-specific language. Input / output examples can be data in the form of strings, lists of integers, spreadsheets, grids, etc. Example programming uses the input and output examples of the program to describe the user's intent; the examples can be various forms of data. The Karel problem of 1981 used the grid layout of the agent as an example to obtain a program instructing the agent's actions. The FlashFill problem, proposed by Gulwani in 2011, interactively generates an autofill program using the example of string conversion in Microsoft Excel. Since its inception, the FlashFill problem has received widespread attention and extensive research, with one of the most advanced methods being the RobustFill framework. RobustFill combines recurrent neural networks and attention mechanisms, using three sequentially connected long short-term memory (LSTM) networks as encoders for string sample inputs and outputs, and decoders for generating the program. The Deepcoder problem, proposed by Balog and Gaunt in 2015, generates a chained list processing program using an example of an integer list. In 2021, Chen et al. used a spreadsheet provided by Google Sheets as an example to generate a program for manipulating spreadsheets. Summary of the Invention
[0007] The purpose of this invention is to address the problem that there is currently little research on example programming that uses binary streams as the example format. It overcomes the shortcomings of existing example programming techniques in handling the problem of generating expressions based on truth tables, such as the relationship between the syntactic symbols in the sequence of syntactic symbols of logical expressions being independent of their distance, and the semantic rules for generating logical expressions being independent of the length of the sampled results of Boolean vector functions. The invention proposes a neural network method and system based on the automatic generation of truth table functions.
[0008] To address the shortcomings of existing technologies, this invention proposes a method for automatic function generation based on truth tables, including:
[0009] Step 1: Construct a function generation model consisting of an input encoder, an output encoder, and a decoder. The input encoder includes an input encoding sub-layer, which is composed of a self-attention mechanism layer and a feedforward network connected in series. The output encoder includes an output encoding sub-layer, which is composed of a self-attention mechanism layer, a first attention mechanism layer, and a feedforward network connected in series. The input of the first attention mechanism layer also includes the output of the input encoder. The decoder includes a decoding sub-layer, which is composed of a self-attention mechanism layer, a second attention mechanism layer, a third attention mechanism layer, and a feedforward network connected in series. The input of the second attention mechanism layer also includes the pooled output of the input encoder, and the input of the third attention mechanism layer also includes the pooled output of the output encoder.
[0010] Step 2: Obtain the dataset in which the labels are expressed by the truth table and its corresponding function; send the position encoding result of the output Boolean function corresponding to the truth table into the input encoding sub-layer to obtain the encoding vector as the output of the input encoder; send the position encoding result of the output Boolean function corresponding to the truth table into the output encoding sub-layer to obtain the encoding vector as the output of the output encoder.
[0011] Step 3: The decoder generates a logical expression starting with "START". The decoder receives all the generated syntax symbols in the logical expression one by one, performs positional encoding on them, and generates the next syntax symbol in the logical expression after passing through the decoding sub-layer, fully connected layer and activation layer, until "END" is added to the end of the logical expression. The current logical expression from "START" to "END" is saved as the function generation result. The loss function is constructed using the function generation result and the function expression label to train the function generation model.
[0012] Step 4: Input the truth table of the function to be generated into the function generation model after training, and obtain the function generation result of the truth table of the function to be generated.
[0013] The aforementioned function automatic generation method based on truth tables includes step 3, which involves: performing positional encoding on all syntax symbols and passing them through the decoding sublayer, fully connected layer, and activation layer to obtain the probability that the next position of the logical expression belongs to each symbol in the symbol set, and taking the symbol with the highest probability as the next syntax symbol of the logical expression; the symbol set includes: function symbols, logical operators, reduction operators, arithmetic operators, shift operators, and input operand symbols.
[0014] The aforementioned method for automatically generating functions based on truth tables includes the following steps in the generation process of the dataset:
[0015] The symbol set is sampled using an adversarial sampling method to obtain logical expressions and their corresponding input and output examples. The truth table of the dataset is constructed based on these input and output examples, and the obtained logical expression is used as the label for the function expression.
[0016] The aforementioned method for automatically generating functions based on truth tables, wherein the truth table to be generated is a sample of the input and output of the algorithm to be generated, and the result of generating the function is used as an equivalent form of the syntax tree calculated by the programming language in the compiler between the input and output samples; or
[0017] The truth table generated by the input function is the input sample of the circuit under test and its corresponding circuit output sample. The result generated by the function is used as the expression of the circuit under test. The circuit under test is checked against the target circuit based on the expression.
[0018] This invention also proposes an automatic function generation system based on truth tables, which includes:
[0019] Module 1 is used to construct a function generation model consisting of an input encoder, an output encoder, and a decoder. The input encoder includes an input encoding sub-layer, which is composed of a self-attention mechanism layer and a feedforward network connected in series. The output encoder includes an output encoding sub-layer, which is composed of a self-attention mechanism layer, a first attention mechanism layer, and a feedforward network connected in series, and the input of the first attention mechanism layer also includes the output of the input encoder. The decoder includes a decoding sub-layer, which is composed of a self-attention mechanism layer, a second attention mechanism layer, a third attention mechanism layer, and a feedforward network connected in series, and the input of the second attention mechanism layer also includes the pooled output of the input encoder, and the input of the third attention mechanism layer also includes the pooled output of the output encoder.
[0020] Module 2 is used to obtain a dataset in which labels are expressed by a truth table and its corresponding function; the positional encoding result of the output Boolean function corresponding to the truth table is sent to the input encoding sub-layer to obtain an encoding vector as the output of the input encoder; the positional encoding result of the output Boolean function corresponding to the truth table is sent to the output encoding sub-layer to obtain an encoding vector as the output of the output encoder.
[0021] Module 3 is used to enable the decoder to generate logical expressions starting with "START". The decoder receives all the generated syntax symbols in the logical expression one by one, performs positional encoding on them, and generates the next syntax symbol of the logical expression after passing through the decoding sub-layer, fully connected layer and activation layer, until "END" is added to the end of the logical expression. The current logical expression from "START" to "END" is saved as the function generation result. The loss function is constructed using the function generation result and the function expression label to train the function generation model.
[0022] Module 4 is used to input the truth table of the function to be generated into the function generation model after training, and obtain the function generation result of the truth table of the function to be generated.
[0023] The aforementioned function automatic generation system based on truth tables, wherein module 3 is used to perform positional encoding on all syntax symbols and, after passing through the decoding sublayer, fully connected layer, and activation layer, obtain the probability that the next position of the logical expression belongs to each symbol in the symbol set, and take the symbol with the highest probability as the next syntax symbol of the logical expression; the symbol set includes: function symbols, logical operators, reduction operators, arithmetic operators, shift operators, and input operand symbols.
[0024] The aforementioned function automatic generation system based on truth tables includes the following data generation process:
[0025] The symbol set is sampled using an adversarial sampling method to obtain logical expressions and their corresponding input and output examples. The truth table of the dataset is constructed based on these input and output examples, and the obtained logical expression is used as the label for the function expression.
[0026] The aforementioned function automatic generation system based on truth tables, wherein the input truth table to be generated is a sample of the input and output of the algorithm to be generated, and the function generation result is used as an equivalent form of the syntax tree calculated by the programming language in the compiler between the input and output samples; or
[0027] The truth table generated by the input function is the input sample of the circuit under test and its corresponding circuit output sample. The result generated by the function is used as the expression of the circuit under test. The circuit under test is checked against the target circuit based on the expression.
[0028] The present invention also proposes a storage medium for storing a program that executes any of the aforementioned methods for automatically generating functions based on truth tables.
[0029] The present invention also proposes a client for any of the aforementioned truth table-based function automatic generation systems.
[0030] As can be seen from the above solutions, the advantages of the present invention are:
[0031] The neural network model of this invention was compared with existing technology models RobustFill and Transformer on the same dataset. The results were evaluated on metrics such as program synthesis, functional equivalence, and sequence matching. The results showed that the method of this invention outperformed mainstream benchmark models of the same period and used fewer neural network model parameters. Attached Figure Description
[0032] Figure 1 This is a diagram showing the correspondence between logical expressions and syntax trees.
[0033] Figure 2 A schematic diagram illustrating the processing of syntax symbol sequences using LSTM;
[0034] Figure 3 These are two different sampling result images corresponding to the same expression;
[0035] Figure 4 This is a diagram of the outer algorithm layer of the neural network model.
[0036] Figure 5 This is a diagram of the network structure of a neural network model.
[0037] Figure 6 The calculation process of AttentionOtoI() is shown in the diagram.
[0038] Figure 7 The calculation process of AttentionPtoO() is shown in the diagram.
[0039] Figure 8 The calculation process of AttentionPtoI() is shown in the diagram.
[0040] Figure 9 Generate algorithm graphs for the dataset;
[0041] Figure 10 Logical expression sampling algorithm diagram;
[0042] Figure 11 Example sampling algorithm diagram. Detailed Implementation
[0043] To achieve the above-mentioned technical effects, the present invention mainly includes the following key technical points:
[0044] Key point 1: The scientific principle that the relationship between the syntactic symbols of a logical expression in a truth table problem is independent of their distance in the actual processed sequence, and that the semantic rules for generating logical expressions are independent of the length of the sampled results of Boolean vector functions, serves as the scientific basis for solving the problem of automated generation of truth table functions.
[0045] Key Point 2: A neural network model with an encoder-decoder structure is designed to solve the problem of generating functions based on truth tables. This model uses two self-attention mechanism encoders to encode the input and output respectively, and one self-attention mechanism decoder to autoregressively output the corresponding logical expression. An attention mechanism is used between the encoder and decoder. This provides a technical solution for solving the problem of automatic generation of functions based on truth tables, and achieves better results on the specified dataset compared with mainstream benchmark models of the same period.
[0046] Key point 3: A dataset of artificially synthesized truth table generation functions for adversarial data generation was constructed, and different evaluation metrics were used; a scheme for evaluating the effectiveness of automated problem generation based on truth table functions was provided.
[0047] To make the above features and effects of the present invention clearer and easier to understand, specific embodiments are described below, and detailed descriptions are provided in conjunction with the accompanying drawings.
[0048] The overall input of this invention is a set of samples (truth table) of a certain Boolean vector function, each set of samples including the input sample and the corresponding output sample; the overall output is the logical expression of the Boolean vector function.
[0049] While researching example programming problems based on truth table generation functions, the inventors discovered that the deficiency in the existing technology is due to two scientific laws governing the problem of generating expressions based on truth tables: first, the relationship between the syntactic symbols in the sequence of syntactic symbols of a logical expression is independent of their distance; second, the semantic rules for generating logical expressions are independent of the length of the sampled result of Boolean vector functions.
[0050] (1) Example programming problem based on truth table generation function
[0051] Given a Boolean vector function f(X = y) and a set of syntax rules, construct a logical expression using a small number of samples. The Boolean vector function is given by a set of truth tables, and the number and bit width of the input vectors are limited in the practical problem discussion; the syntax rules are a domain-specific language.
[0052] A Boolean vector function f(X = y) based on a truth table is represented by a set of truth tables. In the expression of this Boolean vector function, the input X = {X1, X2, ..., X...} k It consists of a set of k Boolean vectors, each of which... By l i Composed of several Boolean variables, representing the original code of a binary number, it is used as a whole in the Boolean vector function; output It consists of m Boolean variables arranged in sequence.
[0053] Each Boolean vector function can be represented as a truth table for all inputs with a bit width of [k, +∞) under the given mapping rule. The output of the truth table is related to the specific mapping relationship. By limiting the maximum bit width B of each input Boolean vector, each Boolean vector function represents a truth table for all inputs with a bit width of [k, kB] under the given mapping rule.
[0054] For each Boolean vector function, the present invention samples a small number of rows from these truth tables to synthesize a logical expression that equivalently describes the relationship of the Boolean vector function.
[0055] This invention employs a domain-specific language to represent the syntax rules of logical expressions. This domain-specific language is consistent with the syntax tree form obtained from syntax analysis in a compiler, and can replace the program synthesis process from user requirements to compiler syntax analysis, becoming an efficient step in the automated process of computer architecture design.
[0056] Domain-specific languages specify the basic methods for constructing logical expressions. For example... Figure 5 As shown, a logical expression is represented by a sequence of syntax symbols, with "START" as the beginning of the sequence and "END" as the end of the sequence. The sequence between them is the result of the preorder traversal of the logical expression syntax tree. Figure 1 A set of examples showing the correspondence between syntax trees and logical expressions is given. In the syntax tree on the left, each non-leaf node represents an operator, and each leaf node represents an operand, which is a Boolean vector as the input to the Boolean vector function. Expanding the syntax tree through a preorder traversal and adding "START" and "END" to the beginning and end respectively yields the logical expression on the right.
[0057] Table 1. Syntactic Symbols for Domain-Specific Languages
[0058]
[0059] The syntax symbols include function symbols indicating the start and end of a sequence and placeholders after the end of a sequence, operators representing logical, reduction, arithmetic, and shift operations, and input operand symbols representing different input operands. Operators include unary and binary operators, with the last letter of each operator indicating the number of operands required. The output bit width of an operator is related to its type and the bit width of its operands; the maximum possible effective bit width in the operator's computational structure is determined based on the operand bit width. The various syntax symbols of this invention and their functions are given in Table 1.
[0060] (2) Syntactic sign relations are independent of distance.
[0061] Excluding "START" and "END", the sequence of syntax symbols is the result of a preorder traversal of the syntax tree corresponding to the logical expression. In the above syntax rules, this invention intuitively defines the position of the syntax symbols in the sequence and the distance between any two different syntax symbols: the positions of the syntax symbols are encoded using natural numbers according to their order of arrangement, and the distance between the syntax symbols is the difference between their position codes. Table 2 shows... Figure 1 Position encoding of the sequence of syntax symbols in Chinese.
[0062] Table 2. Syntax symbol sequence position encoding (in words) Figure 1 (For example, the expression)
[0063]
[0064] The relationships between the symbols in a logical expression's sequence of symbols are independent of their distance. However, the existing RobustFill technique does not conform to this rule.
[0065] A diagram illustrating the LSTM processing of the syntax symbol sequence in Table 2 in RobustFill. Figure 2 Given that, in the LSTM processing, generally, within the same sequence of syntax symbols, the degree of mutual influence between different symbols is affected by their distance. The greater the distance between two syntax symbols, the smaller their mutual influence. Therefore, LSTM assigns a higher degree of mutual influence to the parent node and its left child node, and a lower degree of mutual influence to other child nodes and the parent node and its left child node. Figure 1 In the example in Table 2, the distance between the root node "OR2" and its left child node "AND2" is 1, and the distance between it and its right child node "XOR2" is 5. Figure 2 In this model, LSTM assigns a higher degree of mutual influence to the root node "OR2" and its left child node "AND2", and a lower degree of mutual influence to the root node "OR2" and its right child node "XOR2".
[0066] The above processing method does not conform to the actual semantic relationship of logical expressions. This invention qualitatively defines the relationship between any two different syntactic symbols in a sequence of syntactic symbols at the semantic level: a parent node has a closer relationship with its child nodes, and a child node has a closer relationship with its sibling nodes. This is because in actual operations, a parent node and all its child nodes together represent a specific operation. Figure 1 In the example, the root node "OR2" and its left and right children represent the last operation of the logical expression, that is, the result of the operation of "AND2" and the result of the operation of "XOR2" are bitwise ORed according to the rules in Table 1.
[0067] This invention uses a self-attention mechanism instead of LSTM to process the sequence of logical expression syntax symbols to solve the above problems. The self-attention mechanism treats the distance between all symbols in the sequence as 1, and trains the relationship between each syntax symbol through data-driven training, unaffected by the distance between syntax symbols.
[0068] (3) The generation rules are independent of the example length.
[0069] Each Boolean vector function corresponds to a set of different truth tables with the same semantic function, but their input or output bit widths are different. That is to say, for each logical expression, the length of the sampled result is not certain, and the specific length depends on the sampling method. Figure 3 The document presents two different sets of sampling results (each set containing 3 pairs of input / output examples), both derived from... Figure 1 The expression is obtained by sampling.
[0070] This invention discovers that the semantic rules for generating logical expressions are independent of the sample length of Boolean vector function examples. In fact, all truth tables represented by the same Boolean vector function correspond to the same logical expression; different samples merely reflect different ways users describe their intentions, and the process of synthesizing logical expressions should not be affected by the sample length.
[0071] In RobustFill's LSTM network, processing samples of different lengths requires different numbers of LSTM iterations. To enable batch processing, the LSTM network typically determines the maximum sample length, pads insufficient samples with placeholders, and uses a Boolean tensor of equal size to indicate the effective length. In other words, during forward computation, different sample lengths require different numbers of iterations, and placeholders are used to pad for the required number of iterations; therefore, the computational result is still affected by the sample length.
[0072] This invention uses a self-attention mechanism instead of LSTM to process the sampled result sequence to solve the above problems. The self-attention mechanism places the sequence length in the batch size dimension, so the training and inference processes are not affected by the length of the sampled result sequence.
[0073] This invention presents a solution to the problem of generating logical expressions based on truth tables. It employs a neural network model to learn a method for generating logical expressions from input-output sampling of Boolean vector functions and the grammar rules defined in this invention. Furthermore, this invention utilizes an adversarial approach to construct a dataset. The following sections first explain the design principles of the neural network model, which is an encoder-decoder network structure; then, they detail its encoder and decoder; finally, the dataset of this invention is introduced.
[0074] 1. Design Principles
[0075] This invention designs an encoder-decoder neural network model for the problem of generating logical expressions based on truth tables. The model has two encoders, one decoder, and a pairwise attention mechanism between these three components. Its outer algorithm and network structure are described in detail below. Figure 4 and Figure 5 The following is provided. Two encoders are used: one input encoder and one output encoder, which process the input and output of the Boolean vector function, respectively. An attention mechanism exists between the output encoder and the input encoder. The decoder has attention mechanisms with both the output encoder and the input encoder, and outputs the logical expression autoregressively.
[0076] The encoder-decoder structure, attention mechanism, and self-attention mechanism of this neural network model are all adapted to the characteristics of truth table-based generation function problems.
[0077] The structure of two encoders and one decoder is suitable for problems based on truth table-based generation functions: the two encoders handle the input and output of Boolean vector functions respectively, and the one decoder is used to autoregressively generate logical expressions.
[0078] Attention mechanisms are well-suited for generating variable-length sequences from variable-length sequences. In truth-table-based logical expression generation, the inputs and outputs of Boolean functions have a difficult-to-abstract mapping relationship, and there is no obvious correspondence between them and logical expressions. Attention mechanisms assign pairwise associations between the inputs, outputs, and logical expressions of Boolean functions, and these associations apply to every syntax symbol, making it easier to abstract the relationships and generate logical expressions.
[0079] Self-attention mechanisms are well-suited for handling the complex internal relationships between the sampling results of Boolean functions based on truth table generation functions and the corresponding sequences of syntactic symbols in the generated logical expressions, successfully addressing the shortcomings of LSTM networks in RobustFill. On one hand, self-attention treats all distances between syntactic symbols in the sequence as 1, learning to determine their relationships, effectively addressing the situation where the relationships between syntactic symbols in the logical expression sequence are independent of their distances. On the other hand, self-attention places the sequence length in the batch size dimension, sharing weights when processing all valid positions, consistent with the characteristic that the semantic rules of logical expression generation are independent of the length of the sampled results from Boolean vector functions.
[0080] 2. Input encoder
[0081] The input encoder receives a Boolean vector function as input and produces an encoded vector, similar to the encoder in a Transformer. It receives a sequence of inputs, encodes their positions, and then passes them through N concatenated encoding sub-layers. Each sub-layer consists of a self-attention mechanism and a feedforward network, surrounded by residual connections and layer normalization. The final output is a set of encoded vectors. This set of encoded vectors is not directly used as input to the subsequent output encoder and decoder, but rather in the attention mechanisms of the output encoder and decoder.
[0082] 3. Output encoder
[0083] The output encoder receives the output of a Boolean vector function and produces an encoded vector. Similar to the input encoder, the output encoder receives a sequence of inputs, encodes their positions, and then passes them through N concatenated encoding sub-layers, finally outputting a set of encoded vectors (keys and values). Again, this set of encoded vectors is not directly used as input to the subsequent decoder, but is used in the decoder's attention mechanism.
[0084] The output encoder differs from the input encoder's encoding sublayer: an attention mechanism, AttentionOtoI(), is added between the self-attention mechanism and the feedforward network, focusing on the input encoder. The computation of AttentionOtoI() takes place within... Figure 6 Given that the query is the output of the self-attention mechanism (line 1), and the key and value are the outputs of the input encoder (lines 2 and 3), residual connections are also used around AttentionOtoI() and layer normalization is performed.
[0085] The output encoder generates a set of floating-point vectors, which are used as input to the subsequent attention layer AttentionPtoO(). The attention layer accepts three inputs: request, key, and value. The key and value of AttentionPtoO() are both the output encoder's generated encoding vectors.
[0086] The generation process and Figure 2 Similarly, except that instead of using LSTM, the decoder described in this method is used.
[0087] by Figure 1 , 2 Taking the expression in the example, the generation process is as follows (illustrated):
[0088] Step 1: Input the expression "START", output the expression "START OR2"
[0089] Step 2: Input the expression "START OR2", output the expression "START OR2 AND2"
[0090] ...
[0091] Step n: Input expression “START OR2…”, output expression “START OR2……END”, the last symbol is “END”, and the calculation is terminated.
[0092] 4. Decoder
[0093] The decoder uses an autoregressive approach to generate a logical expression. Starting with "START", the decoder receives all the generated syntax symbols in the logical expression one by one, encodes their positions, and then passes them through N concatenated decoding sub-layers, followed by a fully connected layer and a softmax layer to generate the next syntax symbol in the logical expression, until "END" is encountered.
[0094] All symbols in Table 1 are placed in a set, and the decoder adds one symbol from this set to the end of each logical expression. Both "START" and "END" may be added. When "END" is added, the decoder ends the computation.
[0095] The decoder is simply a neural network model; it doesn't explicitly restrict the semantics or syntax of the generated expression. The core of neural network methods is adjusting the parameters in the network through training. An ideal decoder generates an accurate logical expression based on the model input. During this process, the decoder doesn't know when the logical expression ends—that is, how many times it needs to be calculated—so a terminator is added to tell the decoder to end the computation when this symbol is obtained.
[0096] Each decoding sublayer consists of a self-attention mechanism, an attention mechanism, and a feedforward network. Each attention mechanism or feedforward network is surrounded by residual connections and layer normalization. Unlike the two encoders, the decoder's self-attention mechanism adds certain restrictions to the receptive field, ensuring that each grammar symbol only pays attention to the grammar symbols preceding it, and not to the grammar symbols following it, based on the order of generating logical expressions.
[0097] Attention mechanisms include AttentionPtoO() for the output encoder and AttentionPtoI() for the input encoder. The computation process of AttentionPtoO() is as follows: Figure 7Given that the query is the output of the self-attention mechanism (line 1), and the key and value are the pooling results of the output encoder's output in terms of the number of samples (lines 2 and 3), the calculation process of AttentionPtoI() is as follows: Figure 8 Given that the query is the output of AttentionPtoO() (line 1), and the key and value are the results of pooling the output of the input encoder in terms of the number of samples (lines 2 and 3).
[0098] 5. Dataset
[0099] The dataset used in this invention is generated by sampling in the order of logical expression-input / output examples. Based on the syntax in Table 1, this invention constructs an artificially synthesized dataset based on a truth table generation function using an adversarial sampling method. The adversarial aspect is reflected in the use of uniform random sampling at each possible sampling stage, ensuring that the sampling results are distributed as evenly as possible across the sampling space (including the program space and the example space). The dataset generation algorithm in... Figure 9 The invention describes that for each piece of data in the dataset, the present invention first samples the logical expression (line 4), then removes duplicates from the obtained logical expressions (lines 5 and 6), and finally samples input / output pairs for each logical expression (line 7).
[0100] For each piece of data, according to Figure 10 The algorithm samples its logical expression. L T This represents a list of all generated syntax trees (nodes), initially consisting of the leaf nodes represented by all K input operands (lines 1-6). First, sample m values from U{1,2,…,M} (line 7). Then, uniformly sample m operators with replacement from all operators (line 10). For each operator, starting from L… T In the first line, multiple elements are randomly selected with replacement as children of this operator to form a new syntax tree (line 11), which is then added to the L. T The last element of the multiple elements is selected as the syntax tree T corresponding to the generated logical expression. The nodes of T are preorder traversed, and "START" and "END" are added to the beginning and end respectively (line 15) to obtain the syntax symbol sequence P of the generated logical expression. The number of these multiple elements depends on how many children the operator needs. For example, "AND2" represents the addition of two numbers, which requires two children, while "NOT1" represents the negation of a number, which requires only one child.
[0101] The generated logical expression needs to be deduplicated to determine whether to retain it. The hash value of the syntax symbol sequence is calculated and compared with the hash values of the syntax symbol sequences of all previously generated logical expressions. If there are no duplicates, the current logical expression is retained.
[0102] For each logical expression, according to Figure 11 The algorithm samples N pairs of inputs / outputs as references for generating logical expressions. These N pairs of inputs / outputs are sampled one by one (lines 3-10), and after each sampling, a deduplication operation is performed with the sampled input / output (lines 11-13). For each pair of input / output samples, the bit width of each of its K inputs is sampled one by one on U{1,2,…,B} (line 5). Then, for each bit width, the bit width is sampled on U{0,1,…,2… bitwidth The upsampling of `-1` corresponds to the input value `value` (line 6). The bit width and value specify a Boolean vector with a specific bit width (line 7), specifying these K Boolean vectors as input samples for a logical expression. Will Substituting into the logical expression yields a new Boolean vector O (line 10), which is designated as the vector corresponding to the logical expression. One of the output samples.
[0103] To facilitate training on the experimental platform and to select a dataset as close as possible to the baseline method RobustFill, the experiment in this invention uses K=2, M=5, N=5, and B=8. Following this method, the present invention samples data line by line to construct a training dataset of 200,000 data points and a test dataset of 20,000 data points. The maximum length of the syntax symbol sequence corresponding to the logical expressions in the dataset is 41.
[0104] This invention can be used to solve technical problems such as compilation, formal verification, and FlashFill.
[0105] Compiled by:
[0106] This method can be applied to generate syntax trees directly from user constraints during the compilation process.
[0107] Compilation involves converting a programming language (high-level language) into machine language (symbolic representations that a computer can execute), which requires generating a syntax tree (e.g., a syntax tree for the current program). Figure 1 (The syntax tree). The origin of a programming language lies in the user's needs and design. This method can eliminate the need for designing the programming language and part of the compilation process, thereby improving compilation efficiency.
[0108] In this context, the input of this method is a sample of the input and output corresponding to the algorithm requested by the user (e.g., if the user wants the computer to perform a two-number addition calculation, the user provides the two numbers and the result of the computer's calculation of the sum of the two numbers; the samples of these two addends and their corresponding sum are the input of this method). The output of this method is the equivalent form of the syntax tree result obtained by the compiler for the two-number addition programming language (i.e.,...). Figure 1 The expression form in the text can be equivalently converted to Figure 1 (in the form of a syntax tree).
[0109] Formal verification:
[0110] This method can also be applied to the equivalence verification of formal verification in the verification stage of circuit design.
[0111] Formal verification refers to verifying the functional design of a circuit using formal (non-numerical) methods. Equivalence verification is a common method in formal verification, which involves checking whether the circuit under test (DUT) and the target circuit are equivalent. This method generates an expression corresponding to the DUT using an example of the DUT and checks whether it is consistent with the target circuit.
[0112] In this scenario, the inputs to this method are the input samples of the circuit under test and the corresponding circuit outputs; the output of this method is the generated expression corresponding to the circuit under test.
[0113] FlashFill:
[0114] This method can also be applied to other problems in programming, such as the classic FlashFill problem. FlashFill is a classic programming synthesis problem that generates a transformation program from a small number of string samples. RobustFill, which is referenced in this method, is one approach used to solve FlashFill.
[0115] In this scenario, the input to this method is a set of sampled strings and the corresponding converted strings, and the output is the string conversion function.
[0116] The following are system embodiments corresponding to the above method embodiments. This embodiment can be implemented in conjunction with the above embodiments. The relevant technical details mentioned in the above embodiments are still valid in this embodiment, and will not be repeated here to reduce repetition. Accordingly, the relevant technical details mentioned in this embodiment can also be applied to the above embodiments.
[0117] This invention also proposes an automatic function generation system based on truth tables, which includes:
[0118] Module 1 is used to construct a function generation model consisting of an input encoder, an output encoder, and a decoder. The input encoder includes an input encoding sub-layer, which is composed of a self-attention mechanism layer and a feedforward network connected in series. The output encoder includes an output encoding sub-layer, which is composed of a self-attention mechanism layer, a first attention mechanism layer, and a feedforward network connected in series, and the input of the first attention mechanism layer also includes the output of the input encoder. The decoder includes a decoding sub-layer, which is composed of a self-attention mechanism layer, a second attention mechanism layer, a third attention mechanism layer, and a feedforward network connected in series, and the input of the second attention mechanism layer also includes the pooled output of the input encoder, and the input of the third attention mechanism layer also includes the pooled output of the output encoder.
[0119] Module 2 is used to obtain a dataset in which labels are expressed by a truth table and its corresponding function; the positional encoding result of the output Boolean function corresponding to the truth table is sent to the input encoding sub-layer to obtain an encoding vector as the output of the input encoder; the positional encoding result of the output Boolean function corresponding to the truth table is sent to the output encoding sub-layer to obtain an encoding vector as the output of the output encoder.
[0120] Module 3 is used to enable the decoder to generate logical expressions starting with "START". The decoder receives all the generated syntax symbols in the logical expression one by one, performs positional encoding on them, and generates the next syntax symbol of the logical expression after passing through the decoding sub-layer, fully connected layer and activation layer, until "END" is added to the end of the logical expression. The current logical expression from "START" to "END" is saved as the function generation result. The loss function is constructed using the function generation result and the function expression label to train the function generation model.
[0121] Module 4 is used to input the truth table of the function to be generated into the function generation model after training, and obtain the function generation result of the truth table of the function to be generated.
[0122] The aforementioned function automatic generation system based on truth tables, wherein module 3 is used to perform positional encoding on all syntax symbols and, after passing through the decoding sublayer, fully connected layer, and activation layer, obtain the probability that the next position of the logical expression belongs to each symbol in the symbol set, and take the symbol with the highest probability as the next syntax symbol of the logical expression; the symbol set includes: function symbols, logical operators, reduction operators, arithmetic operators, shift operators, and input operand symbols.
[0123] The aforementioned function automatic generation system based on truth tables includes the following data generation process:
[0124] The symbol set is sampled using an adversarial sampling method to obtain logical expressions and their corresponding input and output examples. The truth table of the dataset is constructed based on these input and output examples, and the obtained logical expression is used as the label for the function expression.
[0125] The aforementioned function automatic generation system based on truth tables, wherein the input truth table to be generated is a sample of the input and output of the algorithm to be generated, and the function generation result is used as an equivalent form of the syntax tree calculated by the programming language in the compiler between the input and output samples; or
[0126] The truth table generated by the input function is the input sample of the circuit under test and its corresponding circuit output sample. The result generated by the function is used as the expression of the circuit under test. The circuit under test is checked against the target circuit based on the expression.
[0127] The present invention also proposes a storage medium for storing a program that executes any of the aforementioned methods for automatically generating functions based on truth tables.
[0128] The present invention also proposes a client for any of the aforementioned truth table-based function automatic generation systems.
Claims
1. A method for automatically generating functions based on truth tables, characterized in that, include: Step 1: Construct a function generation model consisting of an input encoder, an output encoder, and a decoder. The input encoder includes an input encoding sub-layer, which is composed of a self-attention mechanism layer and a feedforward network connected in series. The output encoder includes an output encoding sub-layer, which is composed of a self-attention mechanism layer, a first attention mechanism layer, and a feedforward network connected in series. The input of the first attention mechanism layer also includes the output of the input encoder. The decoder includes a decoding sub-layer, which is composed of a self-attention mechanism layer, a second attention mechanism layer, a third attention mechanism layer, and a feedforward network connected in series. The input of the second attention mechanism layer also includes the pooled output of the input encoder, and the input of the third attention mechanism layer also includes the pooled output of the output encoder. Step 2: Obtain the dataset in which the labels are expressed by the truth table and its corresponding function; send the position encoding result of the output Boolean function corresponding to the truth table into the input encoding sub-layer to obtain the encoding vector as the output of the input encoder; send the position encoding result of the output Boolean function corresponding to the truth table into the output encoding sub-layer to obtain the encoding vector as the output of the output encoder. Step 3: The decoder generates a logical expression starting with "START". The decoder receives all the generated syntax symbols in the logical expression one by one, performs positional encoding on them, and then processes them... The decoding sublayer, fully connected layer, and activation layer generate the next syntax symbol for the logical expression until "END" is added to the end of the logical expression. The logical expression from "START" to "END" is saved as the function generation result. The loss function is constructed using the function generation result and the function expression label to train the function generation model. Step 4: Input the truth table of the function to be generated into the function generation model after training, and obtain the function generation result of the truth table of the function to be generated; The truth table generated by the input function is the input sample of the circuit under test and its corresponding circuit output sample. The result generated by the function is used as the expression of the circuit under test. The circuit under test is checked against the target circuit based on the expression.
2. The method for automatically generating functions based on truth tables as described in claim 1, characterized in that, Step 3 includes: performing positional encoding on all syntax symbols and then... After the decoding sublayer, fully connected layer, and activation layer, the probability of the next position of the logical expression belonging to each symbol in the symbol set is obtained, and the symbol with the highest probability is taken as the next syntax symbol of the logical expression; the symbol set includes: function symbols, logical operators, reduction operators, arithmetic operators, shift operators, and input operand symbols.
3. The method for automatically generating functions based on truth tables as described in claim 2, characterized in that, The process of generating this dataset includes: The symbol set is sampled using an adversarial sampling method to obtain logical expressions and their corresponding input and output examples. The truth table of the dataset is constructed based on these input and output examples, and the obtained logical expression is used as the label for the function expression.
4. A function automatic generation system based on truth tables, characterized in that, include: Module 1 is used to construct a function generation model consisting of an input encoder, an output encoder, and a decoder. The input encoder includes an input encoding sub-layer, which is composed of a self-attention mechanism layer and a feedforward network connected in series. The output encoder includes an output encoding sub-layer, which is composed of a self-attention mechanism layer, a first attention mechanism layer, and a feedforward network connected in series, and the input of the first attention mechanism layer also includes the output of the input encoder. The decoder includes a decoding sub-layer, which is composed of a self-attention mechanism layer, a second attention mechanism layer, a third attention mechanism layer, and a feedforward network connected in series, and the input of the second attention mechanism layer also includes the pooled output of the input encoder, and the input of the third attention mechanism layer also includes the pooled output of the output encoder. Module 2 is used to obtain a dataset in which labels are expressed by a truth table and its corresponding function; the positional encoding result of the output Boolean function corresponding to the truth table is sent to the input encoding sub-layer to obtain an encoding vector as the output of the input encoder; the positional encoding result of the output Boolean function corresponding to the truth table is sent to the output encoding sub-layer to obtain an encoding vector as the output of the output encoder. Module 3 is used to enable the decoder to generate logical expressions starting with "START". The decoder receives all the generated syntax symbols in the logical expression one by one, performs positional encoding on them, and then processes them... The decoding sublayer, fully connected layer, and activation layer generate the next syntax symbol for the logical expression until "END" is added to the end of the logical expression. The logical expression from "START" to "END" is saved as the function generation result. The loss function is constructed using the function generation result and the function expression label to train the function generation model. Module 4 is used to input the truth table of the function to be generated into the function generation model after training, and obtain the function generation result of the truth table of the function to be generated; The truth table generated by the input function is the input sample of the circuit under test and its corresponding circuit output sample. The result generated by the function is used as the expression of the circuit under test. The circuit under test is checked against the target circuit based on the expression.
5. The function automatic generation system based on truth tables as described in claim 4, characterized in that, Module 3 is used to perform positional encoding on all syntax symbols and then... After the decoding sublayer, fully connected layer, and activation layer, the probability of the next position of the logical expression belonging to each symbol in the symbol set is obtained, and the symbol with the highest probability is taken as the next syntax symbol of the logical expression; the symbol set includes: function symbols, logical operators, reduction operators, arithmetic operators, shift operators, and input operand symbols.
6. The function automatic generation system based on truth tables as described in claim 5, characterized in that, The process of generating this dataset includes: The symbol set is sampled using an adversarial sampling method to obtain logical expressions and their corresponding input and output examples. The truth table of the dataset is constructed based on these input and output examples, and the obtained logical expression is used as the label for the function expression.
7. A storage medium for storing a program that executes the function automatic generation method based on a truth table as described in any one of claims 1 to 3.
8. A client for the automatic function generation system based on truth tables as described in any one of claims 4 to 6.