Manthan: A Data-Driven Approach for Boolean Function Synthesis

Boolean functional synthesis is a fundamental problem in computer science with wide-ranging applications and has witnessed a surge of interest resulting in progressively improved techniques over the past decade. Despite intense algorithmic development, a large number of problems remain beyond the reach of the state of the art techniques. Motivated by the progress in machine learning, we propose \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\textsf {Manthan}$$\end{document}, a novel data-driven approach to Boolean functional synthesis. \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\textsf {Manthan}$$\end{document} views functional synthesis as a classification problem, relying on advances in constrained sampling for data generation, and advances in automated reasoning for a novel proof-guided refinement and provable verification. On an extensive and rigorous evaluation over 609 benchmarks, we demonstrate that \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\textsf {Manthan}$$\end{document} significantly improves upon the current state of the art, solving 356 benchmarks in comparison to 280, which is the most solved by a state of the art technique; thereby, we demonstrate an increase of 76 benchmarks over the current state of the art. Furthermore, \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\textsf {Manthan}$$\end{document} solves 60 benchmarks that none of the current state of the art techniques could solve. The significant performance improvements, along with our detailed analysis, highlights several interesting avenues of future work at the intersection of machine learning, constrained sampling, and automated reasoning.


Introduction
Given an existentially quantified Boolean formula ∃Y F (X, Y ) over the set of variables X and Y , the problem of Boolean functional synthesis is to compute a vector of Boolean functions, denoted by Ψ (X) = ψ 1 (X), ψ 2 (X), . . . , ψ |Y | (X) , and referred to as Skolem function vector, such that ∃Y F (X, Y ) ≡ F (X, Ψ (X)). In the context of applications, the sets X and Y are viewed as inputs and outputs, and the formula F (X, Y ) is viewed as a functional specification capturing the relationship between X and Y , while the Skolem function vector Ψ (X) allows one to determine the value of Y for the given X by evaluating Ψ . The study of The open source tool is available at https://github.com/meelgroup/manthan. Boolean functional synthesis traces back to Boole [12], and over the decades, the problem has found applications in a wide variety of domains such as certified QBF solving [8,9,36,41], automated program repair [27], program synthesis [44], and cryptography [35].
Theoretical investigations have demonstrated that there exist instances where Boolean functional synthesis takes super-polynomial time. On the other hand, practical applicability has necessitated the development of algorithms with progressively impressive scaling. The algorithmic progress for Boolean functional synthesis has been driven by a diverse set of techniques: (i) the usage of incremental determinization employing the several heuristics in state-of-the-art Conflict Driven Clause Learning (CDCL) solvers [41], (ii) usage of decomposition techniques employing the progress in knowledge compilation [6,19,28,45], and (iii) Counter-Example Guided Abstraction Refinement (CEGAR)-based techniques relying on usage of SAT solvers as black boxes [4][5][6]28]. While the state of the art techniques are capable of handling problems of complexity beyond the capability of tools a decade ago, the design of scalable algorithms capable of handling industrial problems remains the holy grail.
In this work, we take a step towards the above goal by proposing a novel approach, called Manthan, at the intersection of machine learning, constrained sampling, and automated reasoning. Motivated by the unprecedented advances in machine learning, we view the problem of functional synthesis through the lens of multi-class classification aided by the generation of the data via constrained sampling and employ automated reasoning to certify and refine the learned functions. To this end, the architecture of Manthan comprises of the following three novel techniques: Data Generation. The state of the art machine learning techniques use training data represented as a set of samples where each sample consists of valuations to features and the corresponding label. In our context, we treat X as the features and Y as labels. Unlike the standard setup of machine learning wherein for each assignment to X, there is a unique label, i.e. assignment to Y , the relationship between X and Y is captured by a relation and not necessarily a function. To this end, we design a weighted sampling strategy to generate a representative data set that can be fitted using a compactly sized classifier. The weighted sampling strategy, implemented using state of the constrained sampler, seeks to uniformly sample input variables (X) while biasing the valuations of output variables towards a particular value. Dependency-Driven Classifier for Candidates. Given training data viewed as a valuation of features (X) and their corresponding labels (Y), a natural approach from machine learning perspective would be to perform multi-class classification to obtain Y = h(X), where h is a symbolic representation of the learned classifier. Such an approach, however, can not ensure that h can be expressed as a vector of Boolean functions. To this end, we design a dependency aware classifier to construct a vector of decision trees corresponding to each Y i , wherein each decision tree is expressed as a Boolean function.
Proof-Guided Refinement. Since machine learning techniques often produce good but inexact approximations, we augment our method with automated reasoning techniques to verify the correctness of decision tree-based candidate Skolem functions. To this end, we perform a counterexample driven refinement approach for candidate Skolem functions. To fully utilize the impressive test accuracy attained by machine learning models, we design a proof-guided refinement approach that seeks to identify and apply minor repairs to the candidate functions, in an iterative manner, until we converge to a provably correct Skolem function vector. In a departure from prior approaches utilizing the Shannon expansion and self-substitution, we first use a MaxSAT solver to determine potential repair candidates, and employ unsatisfiability cores obtained from the infeasibility proofs capturing the reason for current candidate functions to meet the specification, to construct a good repair.
Finally, We perform an extensive evaluation over a diverse set of benchmarks with state-of-the-art tools, viz. C2Syn [4], BFSS [5], and CADET [39]. Of 609 benchmarks, Manthan is able to solve 356 benchmarks while C2Syn, BFSS, and CADET solve 206, 247, and 280 benchmarks respectively. Significantly, Manthan can solve 60 benchmarks beyond the reach of all the other existing tools extending the reach of functional synthesis tools. We then perform an extensive empirical evaluation to understand the impact of different design choices on the performance of Manthan. Our study reveals several surprising observations arising from the inter-play of machine learning and automated reasoning.
Manthan owes its runtime performance to recent advances in machine learning, constrained sampling, and automated reasoning. Encouraged by Manthan's scalability, we will seek to extend the above approach to related problem domains such as automated program synthesis, program repair, and reactive synthesis.
The rest of the paper is organized as follows: We first introduce notations and preliminaries in Sect. 2. We then discuss the related work in Sect. 3. In Sect. 4 we present an overview of Manthan and give an algorithmic description in Section 5. We then describe the experimental methodology and discuss results in Sect. 6. Finally, we conclude in Sect. 7.

Notations and Preliminaries
We use lower case letters (with subscripts) to denote propositional variables and upper case letters to denote a subset of variables. The formula ∃Y F (X, Y ) is existentially quantified in Y , where X = {x 1 , · · · , x n } and Y = {y 1 , · · · , y m }. For notational clarity, we use F to refer to F (X, Y ) when clear from the context. We denote V ars(F ) as the set of variables appearing in F (X, Y ). A literal is a boolean variable or its negation. We often abbreviate universally (resp. existentially) quantified variables as universal (resp. existential) variables.
A satisfying assignment of a formula F (X, Y ) is a mapping σ : V ars(F ) → {0, 1}, on which the formula evaluates to True. For V ⊆ V ars(F ), σ[V ] represents the truth values of variables in V in a satisfying assignment σ of F . We denote the set of all witnesses of F as R F . For a formula in conjunctive normal form, the unsatisfiable core(UnsatCore) is a subset of clauses of the formula for which no satisfying assignment exists.
We use F (X, Y )| yi=b to denote substitutions: a formula obtained after substituting every occurrence of y i in F (X, Y ) by b, where b can be a constant (0 or 1) or a formula. The operator ite(condition,exp1,exp2) is used to represent the if-else case: if the condition is true, then it returns exp1, else it returns exp2.
A variable y i is considered as a positive unate if and only if Given a function vector ψ 1 , . . . , ψ m for the vector of variables y 1 , . . . y m such that ψ i is the function corresponding to y i , we say that there exists a partial order ≺ d over the variables In decision tree learning, a fraction of incorrectly assigned labels refer to the impurity. We use Gini Index [38] as a measure of impurity for a class label. The impurity decrease at a node is the difference of its impurity to the mean of impurities of its children. The minimum impurity decrease is a hyper-parameter used to control the maximum allowable impurity at the leaf nodes, thereby providing a lever for how closely the classifier fits the training data.
Given a propositional formula F (X, Y ) and a weight function W (·) assigning non-negative weights to every literal, we refer to the weight of a satisfying assignment σ, denoted as W (σ), as the product of weights of all the literals appearing in σ, i.e., W (σ) = l∈σ W (l). A sampler A(·, ·) is a probabilistic generator that We use a function Bias that takes a mapping from a sequence of variables to the desired weights of their positive literals, and assigns corresponding weights to each of the positive literals. We use a simpler notation, Bias(a,b) to denote that positive literals corresponding to all universal variables are assigned a weight a and positive literals corresponding to all existential variables are assigned a weight b. For example, Bias(0.5, 0.9) assigns a weight of 0.5 to the positive literals of the universally quantified variables and 0.9 to the positive literals of the existentially quantified variables.
Problem Statement: Given a Boolean specification F (X, Y ) between set of inputs X = {x 1 , · · · , x n } and vector of outputs Y = y 1 , · · · , y m , the problem of Skolem function synthesis is to synthesize a function vector Ψ = ψ 1 (X), · · · , ψ m (X) such that y i ↔ ψ i (X) and ∃Y F (X, Y ) ≡ F (X, Ψ ). We refer to Ψ as the Skolem function vector and ψ i as the Skolem function for y i .
A variable y i is called self-substituted variable, if the Skolem function ψ i corresponding to y i is set to F (X, Y )| yi=1 [19].
Given a formula ∃Y F (X, Y ) and a Skolem function vector Ψ , we refer to E(X, Y, Y ) as an error formula [28], where Y = {y 1 , · · · , y |Y | }, and Y = Y .
We use the following theorems from prior work:

Related Work
The origins of the problem of Boolean functional synthesis traces back to Boole's seminal work [12], which was subsequently rigorously pursued, albeit focused on decidability, by Lowenheim and Skolem [33]. The complexity theoretic studies have shown that there exist instances where Boolean functional synthesis takes super polynomial time and was also shown that there exist instances for which polynomial size Skolem function vector does not suffice unless Polynomial Hierarchy (PH) collapses [5]. Motivated by the success of the CEGAR (Counter-Example Guided Abstraction Refinement) approach in model checking, CEGAR-based approaches have been pursued in the context of synthesis as well, where the key idea is to use a Conflict-Driven Clause Learning (CDCL) SAT solver to verify and refine the candidate Skolem functions [4][5][6]28].
Another line of work has focused on the representation of specification, i.e., F (X, Y ), in representations that are amenable to efficient synthesis for a class of functions. The early approaches focused on ROBDD representation building on the functional composition approach proposed by Balabanov and Jiang [8]. Building on Tabajara and Vardi's ROBDD-based approach [45], Chakraborty et al. extended the approach to factored specifications [14]. It is worth mentioning that factored specifications had earlier been pursued in the context of CEGAR-based approaches. Motivated by the success of knowledge compilation in the field of probabilistic reasoning, Akshay et al. achieved a significant breakthrough over a series of papers [5,6,28] to propose a new negation normal form, SynNNF [4]. The generalization and a functional specification presented in SynNNF is amenable to efficient functional synthesis [4]. Another line of work focused on the usage of incremental determinization to incrementally construct the Skolem functions [25,30,36,39,41].
Several approaches have been proposed for the particular case when the specification, ∃Y F (X, Y ) is valid, i.e., ∀X∃Y F (X, Y ) is True. Inspired by the sequential relational decomposition, Chakraborty et al. [14] recently proposed an approach focused on viewing each CNF clause of the specification consisting of input and output clauses and employing a cooperation-based strategy. The progress in modern CDCL solvers has led to an exploration of usage of heuristics for problems in complexity classes beyond NP. This has led to work on the extraction of Skolem functions from the proofs constructed for the formulas expressed as ∀X∃Y F (X, Y ) [8,9].
The performance of Manthan crucially depends on its ability to employ constrained sampling, which has witnessed a surge of interest with approaches ranging from those based on hashing-based techniques [15], knowledge compilation [24,42], augmentation of SAT solvers with heuristics [43].
The recent success of machine learning has led to several attempts to the usage of machine learning in several related synthesis domains such as program synthesis [7], invariant generation, decision-tree for functions in Linear Integer Arithmetic theory using pre-specified examples [18], strategy synthesis for QBF [26]. Use of data-driven approaches for invariant synthesis has been investigated in the ICE learning framework [17,20,21] aimed with data about the program behavior from test executions, it proposes invariants by learning from data, checks for inductiveness and, on failure, extend the data by the generated counterexamples. The usage of proof-artifacts such as unsat cores has been explored in verification since early 2000s [23] and in program repair in Wolverine [46], while MaxSAT has been used in program debugging in [10,29].

Manthan: An overview
In this section, we provide an overview of our proposed framework, Manthan, before divulging into core algorithmic details in the following section. Manthan takes in a function specification, represented as F (X, Y ), and returns a Skolem function vector Ψ (X) such that ∃Y F (X, Y ) ≡ F (X, Ψ (X)). As shown in Fig. 1 Manthan consists of following three phases: 1. Preprocess employs state-of-the-art pre-processing techniques on F to compute a partial Skolem function vector. 2. LearnSkF takes in the pre-processed formula and uses constrained samplers, and classification techniques to compute candidate Skolem functions for all the variables in Y . 3. Refine performs verification and proof-guided refinement procedure wherein a SAT solver is employed to verify the correctness of candidate functions and a MaxSAT solver in conjunction with a SAT solver is employed to refine the candidate functions until the entire candidate Skolem function vector passes the verification check. We now provide a high-level description of different phases to highlight the technical challenges, which provides context for several algorithmic design choices presented in the next section.

Phase 1: Preprocess
Preprocess focuses on pre-processing of the formula to search for unates among the variables in Y ; if y i is positive (resp. negative) unate, then ψ i = 1(resp. 0) suffices as a Skolem function. We employ the algorithmic routine proposed by Akshay et al. [5] to drive this preprocessing.

Phase 2: LearnSkF
LearnSkF views the problem of functional synthesis through the lens of machine learning where the learned machine learning model for classification of a variable y i can be viewed as a candidate Skolem function for y i . We gather training data about the function's behavior by exploiting the progress in constrained sampling to sample solutions of F (X, Y ). Recall that F (X, Y ) defines a relation (and not necessarily a function) between X and Y , and the machine learning techniques typically assume the existence of function between features and labels, necessitating the need for sophisticated sampling strategy as discussed below. Moving on to features and labels, since we want to learn Y in terms of X, we view X as a set of features while assignments to Y as a set of class labels.
The off-the-shelf classification techniques typically require that the size of training data is several times larger than the size of possible class labels, which would be prohibitively large for the typical problems involving more than thousand variables. To mitigate the requirement of large training data, we make note of two well-known observations in functional synthesis literature: (1) the Skolem function ψ i for a variable y i typically does not depend on all the variables in X, (2) A Skolem function vector Ψ where ψ i depends on variable y j is a valid vector if the Skolem function ψ j is not dependent on y i (i.e., acyclic dependency), i.e., there exists a partial order ≺ d over {y 1 , . . . y m }.
The above observations lead us to design an algorithmic procedure where we learn candidate Skolem functions as decision trees in an iterative manner, i.e., one y i at a time, thereby allowing us to constrain ourselves to the binary classification. The learned classifier can then be represented as the disjunction of all the paths from the root to the leaves in the learnt decision tree. We update the set of possible features for a given y i depending on the candidate functions generated so far, i.e., valuation of X variables and Y variables, which are not dependent on y i . Finally, we compute the candidate Skolem function for y i as the disjunction of labels along edges for all the paths from the root to leaf nodes with label 1. Once, we have the candidate Skolem function vector Ψ , we obtain a valid linear extension, TotalOrder , of the partial order ≺ d in accordance to Ψ .
Before moving on to the next phase, we return to the formulation of sampling. The past few years have witnessed the design of uniform [15,42], and weighted samplers [24], and one wonders what kind of sampler should we choose to generate samples for training data. A straightforward choice would be to perform uniform sampling over X and Y , but the relational nature of specification, F , between X and Y offers interesting challenges and opportunities. Recall while F specifies a relation between X and Y , we are interested in a Skolem function, and we would like to tailor our sampling subroutines to allow discovery of Skolem functions with small description given the relationship between description and sample complexity. To this end, consider X = {x 1 , x 2 } and Y = {y 1 }, and let F := (x 1 ∨ x 2 ∨ y 1 ). Note that F has 7 solutions over X ∪ Y , out of which y 1 = 0 appears in 3 solutions while y 1 = 1 appears in 4. Also, note that there are several possible Skolem functions such as y 1 = ¬(x 1 ∧ x 2 ). Now, if we uniformly sample solutions of F over x 1 , x 2 , y 1 , i.e. Bias(0.5, 0.5), we would see (almost) equal number of samples with y 1 = 0 and y 1 = 1. A closer look at F reveals that it is possible to construct a Skolem function by knowing that the only case where y 1 cannot be assigned 0 is when x 1 = x 2 = 0. To encode this intuition, we propose a novel idea of collecting samples with weighted sampling, i.e., Bias(0.5, q) where q is chosen in a multi-step process of first drawing a small set of samples with both q = 0.9 and q = 0.1, and then drawing rest of the samples by fixing the value of q following analysis of an initial set of samples. To the best of our knowledge, this is the first application of weighted sampling in the context of synthesis, and our experimental results point to several interesting avenues of future work.

Phase 3: Refine
The candidate Skolem functions generated in LearnSkF may not always be the actual Skolem functions. Hence, we require a verification check to see if candidate Skolem functions are indeed correct; if not, the generated counterexample can be used to repair it. The verification query constructs an error formula E(X, Y, Y ) (Formula 1): if unsatisfiable, the candidate Skolem function vector is indeed a Skolem function vector and the procedure can terminate; else, when E(X, Y, Y ) is SAT, the solution of E(X, Y, Y ) is used to identify and refine the erring functions among the candidate Skolem function vector.
In contrast to prior techniques that apply Shannon expansion or selfsubstitution, the refinement strategy in Manthan is guided by the view that the candidate function vector from the LearnSkF phase is almost correct, and hence, attempts to identify and apply a series of minor repairs to the erring functions to arrive at the correct Skolem function vector. To this end, Manthan uses two key techniques: fault localization and repair synthesis. Let us assume that σ is a satisfying assignment of E(X, Y, Y ) and referred to as counterexample for the current candidate Skolem function vector Ψ .

Fault Localization.
In order to identify the initial candidates to repair for the counterexample σ, Manthan attempts to identify a small number of Skolem functions (correspondingly Y variables) whose outputs must undergo a change for the formula to behave correctly on σ; in other words, it makes a best-effort attempt to ensure that most of the Skolem functions (correspondingly Y variables) can retain their current output on σ while satisfying the formula. Manthan encodes this problem as a partial MaxSAT query with F (X, Y ) ∧ (X ↔ σ[X]) as a hard constraint and (Y ↔ σ[Y ]) as soft constraints. All Y variables whose valuation constraint (Y ↔ σ[Y ]) does not hold in the MaxSAT solution are identified as erring Skolem functions that may need to be repaired.

Repair Synthesis.
Let y k be the variable corresponding to the erring function, ψ k , identified in the previous step. To synthesize a repair for the function, Manthan applies a proof-guided strategy: it constructs a formula G k (X, Y ), such that if G k (X, Y ) is unsatisfiable then ψ k must undergo a change. The Unsat-Core of G k (X, Y ) provides a reason that explains the discrepancy between the specification and the current Skolem function.
Manthan uses the UnsatCore to constructs a repair formula, say β, as a conjunction over literals in the unsatisfiable core; if ψ k is true with the current valuation of X andŶ , Manthan updates the function ψ k by conjoining it with the negation of repair formula (ψ k ← ψ k ∧ ¬β); otherwise, Manthan updates the function ψ k , by disjoining it with the repair formula (ψ k ← ψ k ∨ β).

Self-substitution for Poorly Learnt Functions.
Some Skolem functions are difficult to learn through data. In our implementation, the corresponding variables escape the LearnSkF phase with poor candidate functions, thereby requiring a long sequence of incremental repairs for convergence. To handle such scenarios, we make the following observation: though synthesizing Skolem functions via self-substitution [19] can lead to an exponential blowup in the worst case, it is inexpensive if the number of variables synthesized via this technique is small. We use this observation to quickly synthesize a Skolem function for an erring variable if we detect its candidate function is poor (detected by comparing the number of times it enters refinement against an empirically determined threshold). Of course, this heuristic does not scale well if the number of such variables is large; in our experiments, we found less than 20% of the instances solved required self-substitution, and for over 75% of these instances, only one variable needed self-substitution. We elaborate more on the empirical evidence on the success of this heuristic in Sect. 6. A theoretical understanding of the learnability of Boolean functions from data seems to be an interesting direction for future work.

Manthan: Algorithmic Description
In this section, we present a detailed algorithmic description of Manthan, whose pseudocode is presented in Algorithm 1. Manthan takes in a formula F (X, Y ) as input and returns a Skolem vector Ψ . The algorithm starts off by preprocessing (line 1) the formula F (X, Y ) to get the unates (U ) and their corresponding Skolem functions (Ψ ). Next, it invokes the sampler (line 2) to collect a set of samples(Σ) as training data for the learning phase.
For each of the existential variables that are not unates, Manthan attempts to learn candidate Skolem functions (lines [4][5]. To generate a variable order, CandidateSkF uses a collection of sets d 1 , · · · , d |Y | ∈ D, such that y i ∈ d j indicates that y j depends on y i . Next, the FindOrder routine (line 6) construct TotalOrder of the Y variables in accordance to the dependencies in D. The verification and refinement phase (line 8) commences by constructing the error formula and launching the verification check (line 9). If the error formula is satisfiable, the counterexample model (σ) is used to refine the formula. Once the verification check is successful, the refinement phase ends and the subroutine Substitute is invoked to recursively substitute all y i ∈ Y appearing in Skolem functions with their corresponding Skolem functions such that only X variables entirely describe all Skolem functions. The strict variable ordering enforced above ensures that Substitute always succeeds and does not get stuck in a cycle. Finally, the Skolem function vector Ψ is returned.
It is worth noting that Manthan can successfully solve an instance without having to necessarily execute all the phases. In particular, if U = Y , then Manthan terminates after Preprocess (i.e., line 1). Similarly, if the CheckSat return UNSAT during the first iteration of loop (lines 8-11), then Manthan does not invoke RefineSkF.
We now discuss each subroutine in detail. The pseudocode for Preprocess, GetSamples and Substitute is deferred to technical report [22].

Preprocess:
We perform the pre-processing step as described in [5], which performs SAT queries on the formulas constructed as specified in Theorem 2.
GetSamples: GetSamples takes F (X, Y ) as input and returns a subset of satisfying assignments of F (X, Y ). GetSamples first generates a small set of samples (500) with Bias(0.5, 0.9) and calculates m i for all y i , m i is a ratio of number of samples with y i being 1 to the total number of samples. Similarity, GetSamples generates 500 samples with Bias(0.5, 0.1) and calculates n i for all y i , n i is a ratio Algorithm 2: CandidateSkF(Σ, F (X, Y ), y j , D) f eatset ← f eatset ∪ y k /* if y k is not dependent on yj */ 5 feat, lbl ← Σ ↓f eatset , Σ ↓y j 6 t ← CreateDecisionTree(feat, lbl) 7 foreach n ∈ LeafNodes(t) do 8 if Label(n) = 1 then 9 π ← Path(t, root, n) 10 ψj ← ψj ∨ π 11 foreach y k ∈ ψj do CandidateSkF: CandidateSkF, presented in Algorithm 2, assumes access to following three subroutines: 1. CreateDecisionTree takes the feature and label sets as input (training data) and returns a decision tree t. We use the ID3 algorithm [38] to construct a decision tree t where the internal node of t represents a feature on which a decision is made, the branches represent partitioning of the training data on the decision, and the leaf nodes represent the classification outcomes (i.e class labels). The ID3 algorithm iterates over the training data, and in each iteration, it selects a new attribute to extend the tree by a new decision node: the selected attribute is one that causes the maximum drop in the impurity of the resulting classes; we use Gini Index [38] as the measure of impurity. The algorithm, then, extends the tree by the selected decision and continues extending building the tree. The algorithm terminates on a path if either it exhausts all attributes for decisions, or the impurity of the resulting classes drop below a (user-specified) impurity decrease parameter. 2. Label takes a leaf node of the decision tree as input and returns the class label corresponding to the node. 3. Path takes a tree t and two nodes of t (node a and node b) as input and outputs a conjunction of literals in the path from node a to node b in t.
As we seek to learn Boolean functions, we employ binary classifiers with class labels 0 and 1. CandidateSkF shows our algorithm for extracting a Boolean function from the decision trees: lines 2-4 find a feature set (featset) to predict y j . The feature set includes all X variables and the subset of Y variables that are not dependent on y j . CandidateSkF creates decision tree t using samples Σ over the feature set. Lines 7-10 generate candidate Skolem function ψ j by iterating over all the leaf nodes of t. In particular, if a leaf node is labeled with 1, the candidate function is updated by disjoining with the formula returned by subroutine Path. CandidateSkF also updates d j in D, d j is set of all Y variables on which, y j depends. If y j depends on y k , then by transitivity y j also depends on d k ; in line 12, CandidateSkF updates d j accordingly.
FindOrder: FindOrder takes D as an input to output a valid linear extension of the partial order ≺ d defined over {y 1 , . . . y m } with respect to the candidate Skolem function vector Ψ . RefineSkF: RefineSkF is invoked with a counterexample σ. RefineSkF first performs fault localization to find the initial set of erring candidate functions; to this end, it calls the MaxSATList subroutine (line 2) with F (X, Y ) ∧ (X ↔ σ[X]) as hard-constraints and (Y ↔ σ[Y ]) as soft-constraints. MaxSATList employs a MaxSAT solver to find the solution that satisfies all the hard constraints and maximizes the number of satisfied soft constraints, and then returns a list (Ind) of Y variables such that for each of the variables appearing in (Ind) the corresponding soft-constraint was not satisfied by the optimal solution returned by MaxSAT solver.
Since candidate Skolem function corresponding to the variables in Ind needs to refine, RefineSkF now attempts to synthesize a repair for each of these candidate Skolem functions. Repair synthesis loop (lines 3-19) starts off by collecting the set of Y variables,Ŷ , on which y k of Ind can depend on as per the ordering constraints (line 4). Next, it invokes the subroutine CheckSubstitute, which returns True if the candidate function corresponding to y k has been refined more than a chosen threshold times (fixed to 10 in our implementation), and the corresponding decision tree constructed during execution CandidateSkF has exactly one node. If CheckSubstitute returns true, RefineSkF calls DoSelfSubstitution to perform self-substitution. DoSelfSubstitution takes a formula F (X, Y ), an existentially quantified variable y k and a list of variables which depends on y k and performs self substitution of y k with constant 1 in the formula F (X, Y ) [28].
If CheckSubstitute returns false, RefineSkF attempts a proof-guided repair for y k . RefineSkF calls CheckSat in line 9 on G k , which corresponds to formula 2: if G k is SAT, then CheckSat returns a satisfying assignment(ρ) of G k in σ, else CheckSat returns unsatisfiable in the result, ret.
1. If ret is UNSAT, we proceed to refine ψ k such that for

Experimental Results
We evaluate the performance of Manthan on the union of all the benchmarks employed in the most recent works [4,5],which includes 609 benchmarks from different sources: Prenex-2QBF track of QBFEval-17 [2], QBFEval-18 [3], disjunctive [6], arithmetic [45] and factorization [6]. We ran all the tools as per the specification laid out by their authors. We used Open-WBO [34] for our MaxSAT queries and PicoSAT [11] to compute UnsatCore. We used PicoSAT for its ease of usage and we expect further performance improvements by upgrading to one of the state of the art SAT solvers. We have used the Scikit-Learn [37] to create decision trees in LearnSkF phase of Manthan. We have also used ABC [31] to represent and manipulate Boolean functions. To allow for the input formats supported by the different tools, we use the utility scripts available with the BFSS distribution [5] to convert each of the instances to both QDIMACS and Verilog formats. For Manthan, unless otherwise specified, we set the number of samples according to heuristic based on |Y | as described in Sect. 6.3 and minimum impurity decrease to 0.005. All our experiments were conducted on a high-performance computer cluster with each node consisting of a E5-2690 v3 CPU with 24 cores and 96 GB of RAM, with a memory limit set to 4 GB per core. All tools were run in a single-threaded mode on a single core with a timeout of 7200 s. The objective of our experimental evaluation was two-fold: to understand the impact of various design choices on the runtime performance of Manthan and to perform an extensive comparison of runtime performance vis-a-vis state of the art synthesis tools. In particular, we sought to answer the following questions: 1. How does the performance of Manthan compare with state of the functional synthesis engines? 2. How do the usage of different sampling schemes and the quality of samplers impact the performance of Manthan? 3. What is the impact of LearnSkF on the performance of Manthan? 4. What is the distribution of the time spent in each phase of Manthan? 5. How does using MaxSAT solver to identify the potential erring Skolem functions impacts on the performance of Manthan? 6. How does employing self-substitution for some Skolem functions impact Manthan?
We observe that Manthan significantly improves upon state of the art, and solves 356 benchmarks while the state of the art tool can only solve 280; in particular, Manthan solves 60 more benchmarks that could not be solved by any of the state of the art tools. To put the runtime performance statistics in a broader context, the number of benchmarks solved by techniques developed over the past five years range from 206 to 280, i.e., a difference of 74, which is same as an increase of 76 (i.e., from 280 to 356) due to Manthan.
Our experimental evaluation leads to interesting conclusions and several directions for future work. We observe that the performance of Manthan is sensitive to different sampling schemes and the underlying samplers; in fact, we found that biased sampling yields better results than uniform sampling. This raises interesting questions on the possibility of designing specialized samplers for this task. Similarly, we observe interesting trade offs between the number of samples and the minimum impurity decrease in LearnSkF. The diversity of our extensive benchmark suite produces a nuanced picture with respect to time distribution across different phases, highlighting the critical nature of each of the phases to the performance of Manthan. Manthan shows significant performance improvement by using MaxSAT solver to identify candidates to refine. Manthan also has significant performance improvement with self substitution in terms of the required number of refinements.

Comparison with Other Tools
We now present performance comparison of Manthan with the current state of the art synthesis tools, BFSS [5], C2Syn [4], BaFSyn [14] and the current state of the art 2-QBF solvers CADET [39],CAQE [40] and DepQBF [32]. The certifying 2-QBF solver produces QBF certificates, that can be used to extract Skolem functions [8]. Developers of BaFSyn and DepQBF confirmed that the tools produce Skolem function for only valid instances, i.e. when ∀X∃Y F (X, Y ) is valid. Note that the current version of CAQE does not support certification and we have used CAQE version 2 for the experiments after consultation with the developers of CAQE. We present the number of instances solved Table 1. Out of 609 benchmarks, the most number of instances solved by any of the remaining techniques is 280 while Manthan is able to solve 356 instances -a significant improvement over state of the art. We will focus on top 4 synthesis tools from Table 1 for further analysis.
For a deeper analysis of runtime behavior, we present the cactus plot in Fig. 2: the number of instances are shown on the x-axis and the time taken on the y-axis; a point (x, y) implies that a solver took less than or equal to y seconds to find Skolem function of x instances on a total of 609 instances. An interesting behavior predicted by cactus plot and verified upon closer analysis is that for instances that can be solved by most of the tools, the initial overhead due to a multi-phase approach may lead to relatively larger runtime for Manthan. However, with the rise in empirically observed hardness of instances, one can observe the strengths of the multi-phase approach. Overall, Manthan solves 76 more instances than the rest of the remaining techniques.
We show a pairwise comparison of Manthan vis-a-vis other techniques in Table 2. The second row of the table lists the number of instances that were solved by the technique in the corresponding column but not by Manthan while the third row lists the number of instances that were solved by Manthan but not the corresponding technique. First, we observe that Manthan solves 163, 194, and 187 instances that are not solved by C2Syn, BFSS, and CADET respectively. Though   [4] suggest that C2Syn is an orthogonal approach to BFSS. Manthan solves 81 instances that neither C2Syn nor BFSS is able to solve, and these tools together solve 86 instances that Manthan fails to solve. Overall, Manthan solves 60 instances beyond the reach of any of the above state of the art tools.

Impact of the Sampling Scheme
To analyze the impact of the adaptive sampling and the quality of distributions generated by underlying samplers, we augmented Manthan with samples drawn from different samplers for adaptive and non-adaptive sampling. In particular, we employed QuickSampler [16], KUS [42], UniGen2 [15], and BiasGen 1 . The samplers KUS and UniGen2 could only produce samples for mere 14 and 49 benchmarks respectively within a timeout of 3600 s. Hence, we have omitted KUS and UniGen2 from further analysis. We also experimented with a naive enumeration of solution using off-the-shelf SAT solver, CryptoMiniSat [43]. It is worth noting that QuickSampler performs worse than BiasGen for uniformity testing using Barbarik [13]. In our implementation, we had to turn off the validation phase of QuickSampler to allow generation number of samples within a reasonable time. To statistically validate our intuition described in Sect. 4, we performed adaptive sampling using BiasGen. We use AdaBiasGen to refer to the adaptive sampling implementation. Table 3 presents the performance of Manthan with different samplers listed in Column 1. The columns 2, 3, and 4 lists the number of instances that were solved during the execution of respective phases: Preprocess, LearnSkF, and Refine. Finally, column 5 lists the total number of instances solved. Two important findings emerge from Table 3: Firstly, as the quality of samplers improve, so does the performance of Manthan. In particular, we observe that with the improvement in the quality of samples leads to Manthan solving more instances in LearnSkF. Secondly, we see a significant increase in the number of instances that can be solved due to LearnSkF with samples from AdaBiasGen. It is worth remarking that one should view the adaptive scheme proposed in Sect. 4 to be a proof of concept and our results will encourage the development of more complex schemes.

Impact of LearnSkF
To analyze the impact of different design choices in LearnSkF, we analyzed the performance of Manthan for different samples (1000, 5000 and 10000) generated by GetSamples and for different choices of minimum impurity decrease (0.001, 0.005, 0.0005). Figure 3 shows a heatmap on the number of instances solved on each combination of the hyperparameters; the closer the color of a cell is to the red end of the spectrum, the better the performance of Manthan.
At the first look, Fig. 3 presents a puzzling picture: It seems that increasing the number of samples does not improve the performance of Manthan. On a closer analysis, we found that the increase in the number of samples leads to an increase in the runtime of CandidateSkF but without significantly increasing the number of instances solved during LearnSkF. The runtime of CandidateSkF is dependent on the number of samples and |Y |. On the other hand, we see an interesting trend with respect to minimum impurity decrease where the performance first improves and then degrades. A plausible explanation for such a behavior is that with an increase in minimum impurity decrease, the generated decision trees tend to underfit while significantly low values of minimum impurity decrease lead to overfitting. We intend to study this in detail in the future.

Division of Time Taken Across Different Phases
To analyze the time taken by different phases of Manthan across different categories of the benchmarks, we normalize the time taken for each of the four core subroutines, Preprocess, GetSamples, CandidateSkF, and RefineSkF, for every benchmark that was solved by Manthan such that the sum of time taken for each benchmark is 1. We then compute the mean of the normalized times across different categories instances. Figure 4 shows the distribution of mean normalized times for different categories: Arithmetic, Disjunction, Factorization, QBFEval, and all the instances. The diversity of our benchmark suite shows a nuanced picture and shows that the time taken by different phases strongly depends on the family of instances. For example, the disjunctive instances are particularly hard to sample and an improvement in the sampling techniques would lead to significant performance gains. On the other hand, a significant fraction of runtime is spent in the CandidateSkF subroutine indicating the potential gains due to improvement in decision tree generation routines. In all, Fig. 4 identifies the categories of instances that would benefit from algorithmic and engineering improvements in Manthan's different subroutines.

Impact of Using MaxSAT
In RefineSkF, Manthan invokes the MaxSATList subroutine, which calls MaxSAT solver to identify the potential erring Skolem functions. To observe the impact of using MaxSAT solver to identify the candidates to refine, we did an experiment with Manthan, without MaxSATList subroutine call. For all y i , where σ[y i ] = σ[y i ] were considered as candidates to refine. Manthan without MaxSATList subroutine call solved 204 instances that represents a significant drop in the number of solved instances by Manthan with MaxSATList subroutine.

Impact of Self-substitution
To understand the impact of self-substitution, we profile the behavior of candidate Skolem functions with respect to number of refinements for two of our benchmarks; pdtpmsmiim-all-bit and pdtpmsmiim. In Fig. 5, we use histograms with the number of candidate Skolem functions on y-axis and required number of refinements on x-axis. A bar of height a i.e y = a at b i.e x = b in Fig. 5 represents that a candidate Skolem functions converged in b refinements. The histograms show that only a few Skolem functions require a large number of refinements: the tiny bar towards the right end in Fig. 5a represents that for the benchmark pdtpmsmiim-all-bit only 1 candidate Skolem function required more than 60 refinements whereas all other candidate Skolem functions needed less than 15 refinements. Similarly, for the benchmark pdtpmsmiim, Fig. 5b shows that only 1 candidate Skolem function was refined more than 15 times, whereas all other Skolem functions required less than 5 refinements. We found similar behaviors in many of our other benchmarks.
Based on the above trend and an examination of the decision trees corresponding to these instances, we hypothesize that some Skolem functions are hard to learn through data. For such functions, the candidate Skolem function generated from the data-driven phase in Manthan tends to be poor, and hence Manthan requires a long series of refinements for convergence. Since our refinement algorithm is designed for small, efficient corrections, we handle such hard to learn Skolem functions by synthesizing via self-substitution. Manthan detects such functions via a threshold on the number of refinements, which is empirically determined as 10, to identify hard to learn instances and sets them up for self-substitution.
In our experiments, we found 75 instances out of 356 solved instances required self-substitution, and for 51 of these 75 instances, only one variable undergoes self-substitution. Table 4 shows the impact of self-substitution for five of our benchmarks: Manthan has significant performance improvement with selfsubstitution in terms of the required number of refinements, which in turns affects the overall time. Note that Manthan can refine multiple candidates in a single RefineSkF call. For the first four benchmarks, all the other Skolem function except the poor candidates were synthesized earlier than 10 refinement iteration, and at the 10 th refinement iteration the poor candidate functions hit our threshold for self-substitution. Taking the case of the last benchmark, all the other Skolem functions for it were synthesized earlier than 40 refinement cycles, and the last 16 iterations were only needed for 2 of the poor candidate functions to hit our threshold for self-substitution. Note that self-substitution can lead to an exponential blowup in the size of the formula, but it works quite well in our design as most Skolem functions are learnt quite well in the LearnSkF phase.

Conclusion
Boolean functional synthesis is a fundamental problem in Computer Science with a wide variety of applications. In this work, we propose a novel data-driven approach to synthesis that employs constrained sampling techniques for generation of data, machine learning for candidate Skolem functions, and automated reasoning to verify and refine to generate Skolem functions. Our approach achieves significant performance improvements. As pointed out in Sects. 5 and 6, our work opens up several interesting directions for future work at the intersection of machine learning, constrained sampling, and automated reasoning.