├── README.md ├── boolector_solving ├── boolector_check_after_simplify.py ├── boolector_check_after_simplify_peertools.py ├── boolector_check_before_simplify.py ├── makefile └── total.py ├── dataset ├── pldi_dataset_linear_MBA.txt ├── pldi_dataset_linear_MBA.txt.simplify.txt ├── pldi_dataset_linear_MBA.txt.simplify.txt.z3.verify.64bit.after.simplify.txt ├── pldi_dataset_linear_MBA.txt.z3.verify.64bit.before.simplify.txt ├── pldi_dataset_nonpoly_MBA.txt ├── pldi_dataset_nonpoly_MBA.txt.simplify.txt ├── pldi_dataset_nonpoly_MBA.txt.simplify.txt.z3.verify.64bit.after.simplify.txt ├── pldi_dataset_nonpoly_MBA.txt.z3.verify.64bit.before.simplify.txt ├── pldi_dataset_poly_MBA.txt ├── pldi_dataset_poly_MBA.txt.simplify.txt ├── pldi_dataset_poly_MBA.txt.simplify.txt.z3.verify.64bit.after.simplify.txt ├── pldi_dataset_poly_MBA.txt.z3.verify.64bit.before.simplify.txt └── sub-dataset-generator.py ├── full-dataset ├── pldi_dataset_linear_MBA.txt ├── pldi_dataset_linear_MBA.txt.boolector.verify.64bit.before.simplify.txt ├── pldi_dataset_linear_MBA.txt.simplify.txt ├── pldi_dataset_linear_MBA.txt.simplify.txt.boolector.verify.64bit.before.simplify.txt ├── pldi_dataset_linear_MBA.txt.simplify.txt.stp.verify.64bit.after.simplify.txt ├── pldi_dataset_linear_MBA.txt.simplify.txt.z3.verify.64bit.after.simplify.txt ├── pldi_dataset_linear_MBA.txt.stp.verify.64bit.before.simplify.txt ├── pldi_dataset_linear_MBA.txt.z3.verify.64bit.before.simplify.txt ├── pldi_dataset_nonpoly_MBA.txt ├── pldi_dataset_nonpoly_MBA.txt.simplify.txt ├── pldi_dataset_poly_MBA.txt ├── pldi_dataset_poly_MBA.txt.boolector.verify.64bit.before.simplify.txt ├── pldi_dataset_poly_MBA.txt.simplify.txt ├── pldi_dataset_poly_MBA.txt.simplify.txt.boolector.verify.64bit.before.simplify.txt ├── pldi_dataset_poly_MBA.txt.simplify.txt.stp.verify.64bit.after.simplify.txt ├── pldi_dataset_poly_MBA.txt.simplify.txt.z3.verify.64bit.after.simplify.txt ├── pldi_dataset_poly_MBA.txt.stp.verify.64bit.before.simplify.txt └── pldi_dataset_poly_MBA.txt.z3.verify.64bit.before.simplify.txt ├── license ├── makefile ├── mba-simplifier ├── makefile ├── pldi_dataset_simplify_linear.py ├── pldi_dataset_simplify_nonpoly.py └── pldi_dataset_simplify_poly.py ├── sspam ├── linear.MBA.SSPAM.result.txt ├── makefile ├── nonpoly.MBA.SSPAM.result.txt ├── poly.MBA.SSPAM.result.txt └── sspam-evaluation.py ├── stp_solving ├── makefile ├── stp_check_after_simplify.py ├── stp_check_after_simplify_peertools.py ├── stp_check_before_simplify.py └── total.py ├── syntia ├── linear.64bit.result.txt ├── makefile ├── mcts_synthesis │ ├── game.py │ ├── grammar.py │ ├── graph.py │ ├── mcts.py │ ├── mcts_synthesis_multi_core.py │ ├── mctsutils.py │ ├── metrics.py │ ├── paralleliser.py │ ├── sample_synthesis.py │ ├── sampling_synthesis_helpers.py │ ├── transform_manual_sampling_io_pairs.py │ └── utils.py ├── nonpoly.64bit.result.txt ├── poly.64bit.result.txt ├── syntia-evaluation.py ├── testmcts.py └── transformation.py ├── tools ├── 1variable_truthtable.txt ├── 2variable_truthtable.txt ├── 3variable_truthtable.txt ├── 4variable_truthtable.txt ├── __init__.py ├── commons.py ├── mba_ast_operation.py ├── mba_string_operation.py ├── mba_string_operation.pyc ├── svector_simplify.py └── truthtable_search_simplify.py └── z3_solving ├── makefile ├── total.py ├── z3_check_after_simplify.py ├── z3_check_after_simplify_peertools.py └── z3_check_before_simplify.py /README.md: -------------------------------------------------------------------------------- 1 | # MBA-Solver Code and Dataset 2 | 3 | MBA-Solver is a tool to make MBA expressions easier for SMT solving. 4 | 5 | ## How to Build 6 | 7 | ### MBA-Solver 8 | 9 | MBA-Solver is written in Python 3.6. It relies on ast, numpy, sympy, astparse 10 | libraries, which can be easily installed by `pip3 install ast numpy astparse 11 | sympy`. 12 | 13 | ### Solvers and their Python interface 14 | The following solvers are supported. MBA-Solver uses python interface 15 | to communicate with the solvers. 16 | 17 | 1. Z3: [GitHub Link](https://github.com/Z3Prover/z3) 18 | Python interface: `pip3 install z3-solver` 19 | 2. Boolector: [GitHub Link](https://github.com/boolector/boolector) 20 | Python interface: [Link](https://boolector.github.io/docs/index.html) 21 | 3. STP: [Github Link](https://github.com/stp/stp) 22 | Python interface: [Link](https://stp.readthedocs.io/en/latest/#python-usage) 23 | 24 | ## Source Files 25 | 1. tools/svector_simplify.py: simplify linear MBA sub-expression 26 | 2. tools/truthtable_search_simplify.py: simplify poly MBA sub-expression 27 | 3. mba-simplifier/pldi_dataset_simplify_*.py: split MBA expression and apply the corresponding simplification (linear, poly, nonpoly) to them. 28 | 29 | ## Step-by-Step Instructions 30 | ### Dataset 31 | The folder "full-dataset" contains the compete dataset: 1000 linear MBA expression, 1000 poly MBA expression, and 1000 nonpoly MBA expression. 32 | 33 | To facilitate the artifact evaluation, the folder "dataset" include a sub-dataset: 21 linear MBA expression, 21 poly MBA expression, and 20 nonpoly MBA expression. 34 | 35 | If you would like to run on the full-dataset, please rename "full-dataset" to "dataset". 36 | 37 | ### Quick Demo 38 | 39 | Run `make quick-demo` will first use Z3 to solve the original MBA, then use MBA-Solver to simplify them, and then use Z3 to solve the simplified MBA. 40 | 41 | ### Simplify MBA 42 | 43 | Run MBA-Solver: `make mba-solver-simplify-mba`. 44 | 45 | Functions for analyzing and manipulating MBA expressions are in the "tools" folder. The simplification results are stored in the "dataset" folder. 46 | 47 | ## SMT Solving 48 | 49 | Each script will print out the number of correctly simplified cases (True), incorrectly simplified cases (False), Timeout cases and total number. 50 | 51 | ### Timeout 52 | 53 | The timeout can be configured at the beginning of the makefiles under boolector_solving, stp_solving, and z3_solving. The default timeout is set to 5 seconds for quick evaluation. The evaluation in our paper is set to one hour. Please note that, running with shorter timeout may reduce the ratio of solved cases in peer tools. 54 | 55 | ### Z3 56 | 1. Solve original MBA: `make z3-solving-original`. 57 | 2. Solve MBA after simplification by MBA-Solver: `make z3-solving-mba-solver-simplify`. 58 | 3. Solve MBA after simplification by SSPAM: `make z3-solving-sspam-simplify`. 59 | 4. Solve MBA after simplification by Syntia: `make z3-solving-syntia-simplify`. 60 | 61 | Run `make z3` will run these four experiments in a batch. 62 | 63 | ### Boolector 64 | 1. Solve original MBA: `make boolector-solving-original`. 65 | 2. Solve MBA after simplification by MBA-Solver: `make boolector-solving-mba-solver-simplify`. 66 | 3. Solve MBA after simplification by SSPAM: `make boolector-solving-sspam-simplify`. 67 | 4. Solve MBA after simplification by Syntia: `make boolector-solving-syntia-simplify`. 68 | 69 | Run `make boolector` will run these four experiments in a batch. 70 | 71 | ### STP 72 | 1. Solve original MBA: `make stp-solving-original`. 73 | 2. Solve MBA after simplification by MBA-Solver: `make stp-solving-mba-solver-simplify`. 74 | 3. Solve MBA after simplification by SSPAM: `make stp-solving-sspam-simplify`. 75 | 4. Solve MBA after simplification by Syntia: `make stp-solving-syntia-simplify`. 76 | 77 | Run `make stp` will run these four experiments in a batch. 78 | 79 | ## Peer tools 80 | 81 | 1. SSPAM: [GitHub Link](https://github.com/quarkslab/sspam/blob/master/README.md). 82 | 2. Syntia: [GitHub link](https://github.com/RUB-SysSec/syntia/blob/master/README.md). 83 | 84 | Running peer tools may take around 18 hours on the subset. To save time, we have already include the simplified result from these tools. So you do not have to run the commands in this section. 85 | 86 | Run SSPAM on MBA dataset: `make sspam-simplify-mba`. 87 | 88 | Run Syntia on MBA dataset: `make syntia-simplify-mba`. 89 | -------------------------------------------------------------------------------- /boolector_solving/boolector_check_after_simplify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | import pyboolector 4 | import re 5 | import sys 6 | sys.path.append("../tools") 7 | import time 8 | from pyboolector import Boolector, BoolectorException 9 | from mba_string_operation import variable_list 10 | from multiprocessing import Process, Value 11 | 12 | def verify_mba_unsat(leftExpre, rightExpre, bitnumber, res): 13 | """check the relaion whether the left expression is euqal to the right expression. 14 | Args: 15 | leftExpre: left expression. 16 | rightExpre: right expression. 17 | bitnumber: the number of the bits of the variable. 18 | Returns: 19 | True: equation. 20 | False: unequal. 21 | Raises: 22 | None. 23 | """ 24 | btor = Boolector() 25 | btor.Set_opt(pyboolector.BTOR_OPT_INCREMENTAL, True) 26 | btor.Set_opt(pyboolector.BTOR_OPT_MODEL_GEN, 1) 27 | _bv = btor.BitVecSort(bitnumber) 28 | 29 | x = btor.Var(_bv, "x") 30 | y = btor.Var(_bv, "y") 31 | z = btor.Var(_bv, "z") 32 | t = btor.Var(_bv, "t") 33 | a = btor.Var(_bv, "a") 34 | b = btor.Var(_bv, "b") 35 | c = btor.Var(_bv, "c") 36 | d = btor.Var(_bv, "d") 37 | e = btor.Var(_bv, "e") 38 | f = btor.Var(_bv, "f") 39 | 40 | try: 41 | leftEval = eval(leftExpre) 42 | rightEval = eval(rightExpre) 43 | except: 44 | res.value = 2 45 | return None 46 | 47 | if not re.search("[xyztabcdef]", leftExpre) and not re.search("[xyztabcdef]", rightExpre): 48 | #whether is a constant 49 | if leftEval - rightEval == 0: 50 | res.value = 1 51 | else: 52 | res.value = 2 53 | else: 54 | btor.Assert(leftEval != rightEval) 55 | btor.Sat() 56 | 57 | variableList = variable_list(leftExpre) 58 | try: 59 | for variable in variableList: 60 | eval(variable).assignment 61 | except: 62 | res.value = 1 63 | else: 64 | res.value = 2 65 | 66 | return None 67 | 68 | def variable_count(expreStr): 69 | """get the set of variable of expression. 70 | Args: 71 | expreStr: the mba expression string. 72 | Return: 73 | variableList: the list of variables. 74 | Raise: 75 | None. 76 | """ 77 | varSet = set(expreStr) 78 | variableList = [] 79 | for i in varSet: 80 | #the variable name 81 | if i in ["x", "y", "z", "t", "a", "b", "c", "d", "e", "f"]: 82 | variableList.append(i) 83 | 84 | return variableList 85 | 86 | 87 | 88 | def boolector_check_time(sourcefilename, timeout, bv=64): 89 | """input the expression from the source file, then check the equation and output the time of process to desination file. 90 | Args: 91 | sourcefilename: source file. 92 | Returns: 93 | None. 94 | Raises: 95 | None. 96 | """ 97 | desfilename = "{source}.boolector.verify.{bv}bit.after.simplify.txt".format(source=sourcefilename, bv=bv) 98 | fwrite = open(desfilename, "w") 99 | comment = "#complex,groundtruth,simcomplex,simground,boolectorres,verificationtime\n" 100 | fwrite.write(comment) 101 | 102 | solvingList = [0, 0, 0] 103 | with open(sourcefilename, "r") as data: 104 | linenum = 0 105 | for line in data: 106 | line = line.strip().replace(" ", "") 107 | if "#" not in line: 108 | expreStrList = re.split(",", line) 109 | sourceExpreStr = expreStrList[0] 110 | groundExpreStr = expreStrList[1] 111 | sourceSimStr = expreStrList[2] 112 | groundSimStr = expreStrList[3] 113 | 114 | start = time.time() 115 | #res = verify_mba_unsat(sourceSimStr, groundSimStr, bv) 116 | res = Value('i', 0) 117 | p = Process(target=verify_mba_unsat, args=(sourceSimStr, groundSimStr, bv, res,)) 118 | p.start() 119 | p.join(timeout) # wait timeout seconds or it finishes 120 | 121 | if p.is_alive(): 122 | print("Still solving, but kill it as timeout set to", timeout, "seconds ...") 123 | p.terminate() 124 | p.join() 125 | 126 | result = { 127 | 0: "Timeout", 128 | 1: "True", 129 | 2: "False", 130 | } 131 | end = time.time() 132 | elapsed = end - start 133 | resultStr = "{source},{ground},{ssim}, {gsim},{res},{vtime}\n".format(source=sourceExpreStr, ground=groundExpreStr, ssim=sourceSimStr, gsim=groundSimStr, res=result[res.value], vtime=elapsed) 134 | fwrite.write(resultStr) 135 | fwrite.flush() 136 | 137 | # print linenum, sourceExpreStr, groundExpreStr, sourceSimStr, groundSimStr, result[res.value], elapsed 138 | print linenum, result[res.value], "Time =", elapsed 139 | linenum += 1 140 | solvingList[res.value] += 1 141 | 142 | fwrite.close() 143 | print("Timeout: ", solvingList[0]) 144 | print("True: ", solvingList[1]) 145 | print("False: ", solvingList[2]) 146 | return None 147 | 148 | 149 | def main(sourcefilename, timeout): 150 | boolector_check_time(sourcefilename, timeout) 151 | 152 | return None 153 | 154 | 155 | 156 | if __name__ =="__main__": 157 | sourcefilename = sys.argv[1] 158 | timeout = int(sys.argv[2]) 159 | main(sourcefilename, timeout) 160 | 161 | -------------------------------------------------------------------------------- /boolector_solving/boolector_check_after_simplify_peertools.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | import pyboolector 4 | import re 5 | import sys 6 | sys.path.append("../tools") 7 | import time 8 | from pyboolector import Boolector, BoolectorException 9 | from mba_string_operation import variable_list 10 | from multiprocessing import Process, Value 11 | 12 | def verify_mba_unsat(leftExpre, rightExpre, bitnumber, res): 13 | """check the relaion whether the left expression is euqal to the right expression. 14 | Args: 15 | leftExpre: left expression. 16 | rightExpre: right expression. 17 | bitnumber: the number of the bits of the variable. 18 | Returns: 19 | True: equation. 20 | False: unequal. 21 | Raises: 22 | None. 23 | """ 24 | btor = Boolector() 25 | btor.Set_opt(pyboolector.BTOR_OPT_INCREMENTAL, True) 26 | btor.Set_opt(pyboolector.BTOR_OPT_MODEL_GEN, 1) 27 | _bv = btor.BitVecSort(bitnumber) 28 | 29 | x = btor.Var(_bv, "x") 30 | y = btor.Var(_bv, "y") 31 | z = btor.Var(_bv, "z") 32 | t = btor.Var(_bv, "t") 33 | a = btor.Var(_bv, "a") 34 | b = btor.Var(_bv, "b") 35 | c = btor.Var(_bv, "c") 36 | d = btor.Var(_bv, "d") 37 | e = btor.Var(_bv, "e") 38 | f = btor.Var(_bv, "f") 39 | 40 | try: 41 | leftEval = eval(leftExpre) 42 | rightEval = eval(rightExpre) 43 | except: 44 | res.value = 2 45 | return None 46 | 47 | if not re.search("[xyztabcdef]", leftExpre) and not re.search("[xyztabcdef]", rightExpre): 48 | #whether is a constant 49 | if leftEval - rightEval == 0: 50 | res.value = 1 51 | else: 52 | res.value = 2 53 | else: 54 | btor.Assert(leftEval != rightEval) 55 | btor.Sat() 56 | 57 | variableList = variable_list(leftExpre) 58 | try: 59 | for variable in variableList: 60 | eval(variable).assignment 61 | except: 62 | res.value = 1 63 | else: 64 | res.value = 2 65 | 66 | return None 67 | 68 | def variable_count(expreStr): 69 | """get the set of variable of expression. 70 | Args: 71 | expreStr: the mba expression string. 72 | Return: 73 | variableList: the list of variables. 74 | Raise: 75 | None. 76 | """ 77 | varSet = set(expreStr) 78 | variableList = [] 79 | for i in varSet: 80 | #the variable name 81 | if i in ["x", "y", "z", "t", "a", "b", "c", "d", "e", "f"]: 82 | variableList.append(i) 83 | 84 | return variableList 85 | 86 | 87 | 88 | def boolector_check_time(sourcefilename, timeout, bv=64): 89 | """input the expression from the source file, then check the equation and output the time of process to desination file. 90 | Args: 91 | sourcefilename: source file. 92 | Returns: 93 | None. 94 | Raises: 95 | None. 96 | """ 97 | desfilename = "{source}.boolector.verify.{bv}bit.after.simplify.txt".format(source=sourcefilename, bv=bv) 98 | fwrite = open(desfilename, "w") 99 | comment = "#complex,groundtruth,simcomplex,boolectorres,verificationtime\n" 100 | fwrite.write(comment) 101 | 102 | with open(sourcefilename, "r") as data: 103 | linenum = 0 104 | for line in data: 105 | line = line.strip().replace(" ", "") 106 | if "#" not in line: 107 | expreStrList = re.split(",", line) 108 | sourceExpreStr = expreStrList[0] 109 | groundExpreStr = expreStrList[1] 110 | sourceSimStr = expreStrList[2] 111 | 112 | start = time.time() 113 | res = Value('i', 0) 114 | p = Process(target=verify_mba_unsat, args=(sourceSimStr, groundExpreStr, bv, res,)) 115 | p.start() 116 | p.join(timeout) # wait timeout seconds or it finishes 117 | 118 | if p.is_alive(): 119 | print("Still solving, but kill it as timeout set to", timeout, "seconds ...") 120 | p.terminate() 121 | p.join() 122 | 123 | result = { 124 | 0: "Timeout", 125 | 1: "True", 126 | 2: "False", 127 | } 128 | #res = verify_mba_unsat(sourceSimStr, groundExpreStr, bv) 129 | end = time.time() 130 | elapsed = end - start 131 | resultStr = "{source},{ground},{ssim},{res},{vtime}\n".format(source=sourceExpreStr, ground=groundExpreStr, ssim=sourceSimStr, res=result[res.value], vtime=elapsed) 132 | fwrite.write(resultStr) 133 | fwrite.flush() 134 | 135 | # print linenum, sourceExpreStr, groundExpreStr, sourceSimStr, result[res.value], elapsed 136 | print linenum, result[res.value], "Time =", elapsed 137 | linenum += 1 138 | 139 | fwrite.close() 140 | return None 141 | 142 | 143 | def main(sourcefilename, timeout): 144 | boolector_check_time(sourcefilename, timeout) 145 | 146 | return None 147 | 148 | 149 | 150 | if __name__ =="__main__": 151 | sourcefilename = sys.argv[1] 152 | timeout = int(sys.argv[2]) 153 | main(sourcefilename, timeout) 154 | 155 | -------------------------------------------------------------------------------- /boolector_solving/boolector_check_before_simplify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | import pyboolector 4 | import re 5 | import sys 6 | sys.path.append("../tools") 7 | import time 8 | from pyboolector import Boolector, BoolectorException 9 | #from mba_string_operation import variable_list 10 | from multiprocessing import Process, Value 11 | 12 | def verify_mba_unsat(leftExpre, rightExpre, bitnumber, res): 13 | """check the relaion whether the left expression is euqal to the right expression. 14 | Args: 15 | leftExpre: left expression. 16 | rightExpre: right expression. 17 | bitnumber: the number of the bits of the variable. 18 | Returns: 19 | True: equation. 20 | False: unequal. 21 | Raises: 22 | None. 23 | """ 24 | btor = Boolector() 25 | btor.Set_opt(pyboolector.BTOR_OPT_INCREMENTAL, True) 26 | btor.Set_opt(pyboolector.BTOR_OPT_MODEL_GEN, 1) 27 | _bv = btor.BitVecSort(bitnumber) 28 | 29 | x = btor.Var(_bv, "x") 30 | y = btor.Var(_bv, "y") 31 | z = btor.Var(_bv, "z") 32 | t = btor.Var(_bv, "t") 33 | a = btor.Var(_bv, "a") 34 | b = btor.Var(_bv, "b") 35 | c = btor.Var(_bv, "c") 36 | d = btor.Var(_bv, "d") 37 | e = btor.Var(_bv, "e") 38 | f = btor.Var(_bv, "f") 39 | 40 | leftEval = eval(leftExpre) 41 | rightEval = eval(rightExpre) 42 | btor.Assert(leftEval != rightEval) 43 | btor.Sat() 44 | 45 | variableList = variable_list(leftExpre) 46 | try: 47 | for variable in variableList: 48 | eval(variable).assignment 49 | except: 50 | res.value = 1 51 | else: 52 | res.value = 2 53 | 54 | return None 55 | 56 | def variable_list(expreStr): 57 | """get the set of variable of expression. 58 | Args: 59 | expreStr: the mba expression string. 60 | Return: 61 | variableList: the list of variables. 62 | Raise: 63 | None. 64 | """ 65 | varSet = set(expreStr) 66 | variableList = [] 67 | for i in varSet: 68 | #the variable name 69 | if i in ["x", "y", "z", "t", "a", "b", "c", "d", "e", "f"]: 70 | variableList.append(i) 71 | 72 | return variableList 73 | 74 | 75 | 76 | def boolector_check_time(sourcefilename, timeout, bv=64): 77 | """input the expression from the source file, then check the equation and output the time of process to desination file. 78 | Args: 79 | sourcefilename: source file. 80 | Returns: 81 | None. 82 | Raises: 83 | None. 84 | """ 85 | desfilename = "{source}.boolector.verify.{bv}bit.before.simplify.txt".format(source=sourcefilename, bv=bv) 86 | fwrite = open(desfilename, "w") 87 | comment = "#complex,groundtruth,boolectorres,verificationtime\n" 88 | fwrite.write(comment) 89 | 90 | with open(sourcefilename, "r") as data: 91 | linenum = 0 92 | for line in data: 93 | line = line.strip().replace(" ", "") 94 | if "#" not in line: 95 | expreStrList = re.split(",", line) 96 | sourceExpreStr = expreStrList[0] 97 | groundExpreStr = expreStrList[1] 98 | start = time.time() 99 | #res = verify_mba_unsat(sourceExpreStr, groundExpreStr, bv) 100 | res = Value('i', 0) 101 | p = Process(target=verify_mba_unsat, args=(sourceExpreStr, groundExpreStr, bv, res,)) 102 | p.start() 103 | p.join(timeout) # wait timeout seconds or it finishes 104 | 105 | if p.is_alive(): 106 | print("Still solving, but kill it as timeout set to", timeout, "seconds ...") 107 | p.terminate() 108 | p.join() 109 | 110 | result = { 111 | 0: "Timeout", 112 | 1: "True", 113 | 2: "False", 114 | } 115 | end = time.time() 116 | elapsed = end - start 117 | resultStr = "{source},{ground},{res},{vtime}\n".format(source=sourceExpreStr, ground=groundExpreStr, res=result[res.value], vtime=elapsed) 118 | fwrite.write(resultStr) 119 | fwrite.flush() 120 | 121 | # print linenum, sourceExpreStr, groundExpreStr, result[res.value], elapsed 122 | print linenum, result[res.value], "Time =", elapsed 123 | linenum += 1 124 | 125 | fwrite.close() 126 | return None 127 | 128 | 129 | def main(sourcefilename, timeout): 130 | boolector_check_time(sourcefilename, timeout) 131 | 132 | return None 133 | 134 | 135 | if __name__ =="__main__": 136 | sourcefilename = sys.argv[1] 137 | timeout = int(sys.argv[2]) 138 | main(sourcefilename, timeout) 139 | 140 | -------------------------------------------------------------------------------- /boolector_solving/makefile: -------------------------------------------------------------------------------- 1 | timeout = 5 2 | 3 | boolector-linear-before-simplify: 4 | python2 boolector_check_before_simplify.py ../dataset/pldi_dataset_linear_MBA.txt $(timeout) 5 | 6 | boolector-poly-before-simplify: 7 | python2 boolector_check_before_simplify.py ../dataset/pldi_dataset_poly_MBA.txt $(timeout) 8 | 9 | boolector-nonpoly-before-simplify: 10 | python2 boolector_check_before_simplify.py ../dataset/pldi_dataset_nonpoly_MBA.txt $(timeout) 11 | 12 | boolector-linear-after-simplify: 13 | python2 boolector_check_after_simplify.py ../dataset/pldi_dataset_linear_MBA.txt.simplify.txt $(timeout) 14 | 15 | boolector-poly-after-simplify: 16 | python2 boolector_check_after_simplify.py ../dataset/pldi_dataset_poly_MBA.txt.simplify.txt $(timeout) 17 | 18 | boolector-nonpoly-after-simplify: 19 | python2 boolector_check_after_simplify.py ../dataset/pldi_dataset_nonpoly_MBA.txt.simplify.txt $(timeout) 20 | 21 | boolector-linear-after-simplify-sspam: 22 | python2 boolector_check_after_simplify_peertools.py ../sspam/linear.MBA.SSPAM.result.txt $(timeout) 23 | 24 | boolector-poly-after-simplify-sspam: 25 | python2 boolector_check_after_simplify_peertools.py ../sspam/poly.MBA.SSPAM.result.txt $(timeout) 26 | 27 | boolector-nonpoly-after-simplify-sspam: 28 | python2 boolector_check_after_simplify_peertools.py ../sspam/nonpoly.MBA.SSPAM.result.txt $(timeout) 29 | 30 | boolector-linear-after-simplify-syntia: 31 | python2 boolector_check_after_simplify_peertools.py ../syntia/linear.64bit.result.txt $(timeout) 32 | 33 | boolector-poly-after-simplify-syntia: 34 | python2 boolector_check_after_simplify_peertools.py ../syntia/poly.64bit.result.txt $(timeout) 35 | 36 | boolector-nonpoly-after-simplify-syntia: 37 | python2 boolector_check_after_simplify_peertools.py ../syntia/nonpoly.64bit.result.txt $(timeout) 38 | 39 | boolector-solving-before-simplify-total: 40 | python3 total.py boolector 0 41 | boolector-solving-before-simplify: 42 | @echo "--------------------boolector solving linear MBA samples-------------------------" 43 | @make boolector-linear-before-simplify 44 | @echo "--------------------boolector solving linear MBA samples completion--------------" 45 | @echo "--------------------boolector solving poly MBA samples---------------------------" 46 | @make boolector-poly-before-simplify 47 | @echo "--------------------boolector solving poly MBA samples completion----------------" 48 | @echo "--------------------boolector solving nonpoly MBA samples------------------------" 49 | @make boolector-nonpoly-before-simplify 50 | @echo "--------------------boolector solving nonpoly MBA samples completion-------------" 51 | @echo "--------------------boolector solving MBA samples before simplification-------------" 52 | @make boolector-solving-before-simplify-total 53 | 54 | boolector-solving-mba-solver-total: 55 | python3 total.py boolector 1 mba 56 | boolector-solving-mba-solver: 57 | @echo "--------------------boolector solving linear MBA samples after MBA-Solver simplification--------------------------" 58 | @make boolector-linear-after-simplify 59 | @echo "--------------------boolector solving linear MBA samples after MBA-Solver simplification completion---------------" 60 | @echo "--------------------boolector solving poly MBA samples after MBA-Solver simplification----------------------------" 61 | @make boolector-poly-after-simplify 62 | @echo "--------------------boolector solving poly MBA samples after MBA-Solver simplification completion-----------------" 63 | @echo "--------------------boolector solving nonpoly MBA samples after MBA-Solver simplification-------------------------" 64 | @make boolector-nonpoly-after-simplify 65 | @echo "--------------------boolector solving nonpoly MBA samples after MBA-Solver simplification completion--------------" 66 | @echo "--------------------boolector solving MBA samples after MBA-Solver simplification --------------" 67 | @make boolector-solving-mba-solver-total 68 | 69 | boolector-solving-sspam-total: 70 | python3 total.py boolector 1 sspam 71 | boolector-solving-sspam: 72 | @echo "--------------------boolector solving linear MBA samples after SSPAM simplification--------------------------" 73 | @make boolector-linear-after-simplify-sspam 74 | @echo "--------------------boolector solving linear MBA samples after SSPAM simplification completion---------------" 75 | @echo "--------------------boolector solving poly MBA samples after SSPAM simplification----------------------------" 76 | @make boolector-poly-after-simplify-sspam 77 | @echo "--------------------boolector solving poly MBA samples after SSPAM simplification completion-----------------" 78 | @echo "--------------------boolector solving nonpoly MBA samples after SSPAM simplification-------------------------" 79 | @make boolector-nonpoly-after-simplify-sspam 80 | @echo "--------------------boolector solving nonpoly MBA samples after SSPAM simplification completion--------------" 81 | @echo "--------------------boolector solving MBA samples after SSPAM simplification --------------" 82 | @make boolector-solving-sspam-total 83 | 84 | boolector-solving-syntia-total: 85 | python3 total.py boolector 1 syntia 86 | boolector-solving-syntia: 87 | @echo "--------------------boolector solving linear MBA samples after Syntia simplification--------------------------" 88 | @make boolector-linear-after-simplify-syntia 89 | @echo "--------------------boolector solving linear MBA samples after Syntia simplification completion---------------" 90 | @echo "--------------------boolector solving poly MBA samples after Syntia simplification----------------------------" 91 | @make boolector-poly-after-simplify-syntia 92 | @echo "--------------------boolector solving poly MBA samples after Syntia simplification completion-----------------" 93 | @echo "--------------------boolector solving nonpoly MBA samples after Syntia simplification-------------------------" 94 | @make boolector-nonpoly-after-simplify-syntia 95 | @echo "--------------------boolector solving nonpoly MBA samples after Syntia simplification completion--------------" 96 | @echo "--------------------boolector solving MBA samples after Syntia simplification --------------" 97 | @make boolector-solving-syntia-total 98 | -------------------------------------------------------------------------------- /boolector_solving/total.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import re 4 | import sys 5 | import time 6 | 7 | 8 | 9 | def total_simplify(smtsolver, solver): 10 | """count the solving number after solving by smt solver. 11 | """ 12 | true = 0 13 | false = 0 14 | timeout = 0 15 | 16 | if "mba" in solver: 17 | path = "../dataset" 18 | dataFile = ["linear", "poly", "nonpoly"] 19 | for data in dataFile: 20 | fileread = "{path}/pldi_dataset_{data}_MBA.txt.simplify.txt.{smtsolver}.verify.64bit.after.simplify.txt".format(path=path, data=data, smtsolver=smtsolver) 21 | with open(fileread, "r") as fr: 22 | for line in fr: 23 | line = line.strip().replace(" ", "") 24 | if "#" not in line: 25 | expreStrList = re.split(",", line) 26 | flag = expreStrList[4] 27 | if "ue" in flag: 28 | true += 1 29 | elif "out" in flag: 30 | timeout += 1 31 | else: 32 | false += 1 33 | elif "sspam" in solver: 34 | path = "../sspam" 35 | dataFile = ["linear", "poly", "nonpoly"] 36 | for data in dataFile: 37 | fileread = "{path}/{data}.MBA.SSPAM.result.txt.{smtsolver}.verify.64bit.after.simplify.txt".format(path=path, data=data, smtsolver=smtsolver) 38 | with open(fileread, "r") as fr: 39 | for line in fr: 40 | line = line.strip().replace(" ", "") 41 | if "#" not in line: 42 | expreStrList = re.split(",", line) 43 | flag = expreStrList[3] 44 | if "ue" in flag: 45 | true += 1 46 | elif "out" in flag: 47 | timeout += 1 48 | else: 49 | false += 1 50 | elif "syntia" in solver: 51 | path = "../syntia" 52 | dataFile = ["linear", "poly", "nonpoly"] 53 | for data in dataFile: 54 | fileread = "{path}/{data}.64bit.result.txt.{smtsolver}.verify.64bit.after.simplify.txt".format(path=path, data=data, smtsolver=smtsolver) 55 | with open(fileread, "r") as fr: 56 | for line in fr: 57 | line = line.strip().replace(" ", "") 58 | if "#" not in line: 59 | expreStrList = re.split(",", line) 60 | flag = expreStrList[3] 61 | if "ue" in flag: 62 | true += 1 63 | elif "out" in flag: 64 | timeout += 1 65 | else: 66 | false += 1 67 | total = true+false+timeout 68 | print("Total: ", total) 69 | print("True: ", true) 70 | print("False: ", false) 71 | print("Timeout: ", timeout) 72 | 73 | return None 74 | 75 | 76 | 77 | def total_original(smtsolver): 78 | """count the solving number before solving by smt solver. 79 | """ 80 | true = 0 81 | false = 0 82 | timeout = 0 83 | 84 | 85 | path = "../dataset" 86 | dataFile = ["linear", "poly", "nonpoly"] 87 | for data in dataFile: 88 | fileread = "{path}/pldi_dataset_{data}_MBA.txt.{smtsolver}.verify.64bit.before.simplify.txt".format(path=path, data=data, smtsolver=smtsolver) 89 | with open(fileread, "r") as fr: 90 | for line in fr: 91 | line = line.strip().replace(" ", "") 92 | if "#" not in line: 93 | expreStrList = re.split(",", line) 94 | flag = expreStrList[2] 95 | if "ue" in flag: 96 | true += 1 97 | elif "out" in flag: 98 | timeout += 1 99 | else: 100 | false += 1 101 | total = true+false+timeout 102 | print("Total: ", total) 103 | print("True: ", true) 104 | print("False: ", false) 105 | print("Timeout: ", timeout) 106 | 107 | return None 108 | 109 | 110 | 111 | 112 | 113 | def main(smtsolver, flag, solver=None): 114 | if flag: 115 | #after simplification 116 | total_simplify(smtsolver, solver) 117 | else: 118 | #before simplification 119 | total_original(smtsolver) 120 | 121 | 122 | 123 | if __name__ =="__main__": 124 | #smt solver 125 | smtsolver = sys.argv[1] 126 | #before/after simplification 127 | flag = int(sys.argv[2]) 128 | #if simplificationn, tools 129 | if len(sys.argv) > 3: 130 | solver = sys.argv[3] 131 | main(smtsolver, flag, solver) 132 | else: 133 | main(smtsolver, flag) 134 | 135 | 136 | -------------------------------------------------------------------------------- /dataset/pldi_dataset_linear_MBA.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth 2 | (x|y)+y-(~x&y),x+y 3 | 3*(x&~y)-(x^y)+~x-~(x&y),x-y 4 | -1*(~(x&y))+(x|y)-1*(x^y)-1*x+2*~x-1*(~(x&~y))-1*(~(x^y))-1*(x|~y)+3*(~(x|y))+1*(~(x|~y))+4*(x&~y)+4*(x&y),1*y+1*~y 5 | -2*(~(x&y))-2*~y-2*~x+(~(x^y))-2*x-1*y-1*(x|y)+(x|~y)+6*(~(x|y))+8*(~(x|~y))+7*(x&~y)+4*(x&y),1*(~(x&~x))+1*(~(x&~y)) 6 | -1*(x|y)+(~(x&~y))+2*y-2*~y-1*~x-1*(~(x&~x))+(~(x^y))+x+2*(~(x|y))-1*(~(x|~y))+3*(x&~y)-2*(x&y),-(~(x&y))+1*(x|~y) 7 | -1*x-1*~y+4*(~(x&~x))-1*(~(x^y))+y-4*(~(x&y))-1*(~(x&~y))+2*(~(x|y))-1*(~(x|~y))+2*(x&~y)-2*(x&y),-~x 8 | (~(x&~x))+y-2*(x^y)-1*~y+x-1*(~(x&~y))-2*~x-3*(~(x|y))-2*(~(x|~y))-4*(x&~y)-3*(x&y),-5*(~(x&y))-(~(x^y)) 9 | (~(x&y))+(x^y)-1*y+x-2*(x|~y)+2*(~(x&~y))+~y-1*(~(x^y))-1*(~(x|y))-4*(~(x|~y))-3*(x&~y),-(x|y) 10 | -1*x-1*~x+4*(x|~y)-1*(~(x&~y))-1*~y-4*(x&~y)-1*(x&y),1*(~(x^y))-2*(x^y) 11 | 2*~x+5*(~(x^y))-1*(~(x&y))+(x^y)+x-1*(~(x&~y))+(x|~y)-7*(~(x|y))-3*(~(x|~y))-3*(x&~y)-8*(x&y),-y-(~(x&~x)) 12 | -3*~(x^y)-6*~y-2*(x^y)-7*~(x&y)+1*~(x&~x)+2*~(x&~y)-11*(x|~y)-6*x-2*y+24*~(x|y)+8*~(x|~y)+31*(x&~y),-19*(x&y) 13 | 1*((x|y)&~(y^z))+1*~(x|(y|z))-2*~(~x|(y|z))-2*(x&(y&z)),1*(~x&(~y|z))-1*((x|~y)&(x^(y^z))) 14 | -3*(z^~(~x|(~y&z)))-1*(x&(~y|z))-4*~(x|(~y|z))-1*~(~x|(~y|z))+3*(~x&(~y&z))-1*(~x&(y&z))-3*(x&(y&z)),-4*(x|y) 15 | 2*(y|~(x^z))-1*(~x&(~y|z))+2*~(x^(y|z))-3*~(x|(y|z))-2*~(x|(~y|z))+1*(~x&(~y&z))-4*(x&(~y&z))-4*(x&(y&z)),4*~(~x|(~y|z))+1*(~x&(y&z)) 16 | 5*(~x&(y^z))+1*(x&(y^z))+1*((x&~y)|(x^(y^z)))-6*~(x|(~y|z))-1*~(~x|(y|z))-1*~(~x|(~y|z))-2*(x&(~y&z))-1*(x&(y&z)),6*(~x&(~y&z)) 17 | -7*((x^y)&~(x^z))+5*(~z|~(x^y))-3*~(x|(y|z))+4*~(x|(~y|z))-3*~(~x|(y|z))-3*~(~x|(~y|z))-3*(~x&(~y&z))+9*(x&(~y&z))-5*(x&(y&z)),2*~(y&z) 18 | -3*~(y^z)+5*(z^(~x|(y|z)))-12*~(x|(y|z))-15*~(x|(~y|z))-8*~(~x|(y|z))-16*~(~x|(~y|z))-8*(~x&(y&z))+1*(x&(~y&z))+3*(x&(y&z)),1*(z^(~x|(y&z)))-11*(z^~(~x&(y&z))) 19 | -2*(y|~z)+1*(x^y)+2*~(x|(y|z))+3*~(~x|(y|z))+4*~(~x|(~y|z))+2*(~x&(~y&z))+3*(~x&(y&z))-1*(x&(~y&z))+4*(x&(y&z)),2*(z^~(~x|(y&z)))-1*~(x|(~y|z)) 20 | -1*((~(x^(~y&z))&~t)|((z^(~x|(y&z)))&t))+1*((((x&y)^(x^(y&z)))&~t)|(((x&~y)|~(y^z))&t))+1*(((z^~(x&y))&~t)|(((x|y)&~(x^(y^z)))&t))-2*~(~x|(y|(z|t)))-2*~(~x|(~y|(~z|t)))+1*(~x&(y&(~z&t)))-1*(x&(~y&(~z&t)))-2*(~x&(y&(z&t)))-1*(x&(y&(z&t))),1*(x&(y&(~z&t)))+1*(x&(~y&(z&t))) 21 | 2*((((y&z)|(~x&(y|z)))&~t)|((y^~(x&(~y&z)))&t))-2*(((z^~(~x&(y|z)))&~t)|(((x|y)&~(y^z))&t))-2*(((z^~(x|(~y&z)))&~t)|(((x&y)^(x^(~y|z)))&t))-2*((((x^y)&(x^z))&~t)|((~(x|y)|~(y^z))&t))+4*~(x|(y|(z|t)))+4*~(~x|(y|(z|t)))+2*~(~x|(~y|(z|t)))+2*~(x|(y|(~z|t)))+2*~(x|(~y|(~z|t)))+2*~(~x|(y|(~z|t)))+2*(~x&(~y&(~z&t)))+2*(~x&(~y&(z&t)))+6*(~x&(y&(z&t)))+6*(x&(y&(z&t))),-2*(x&(~y&(~z&t))) 22 | 3*(((z^~(x|y))&~t)|((y^~(x&(y&z)))&t))+7*(((~y&~(x^z))&~t)|(~(x&~y)&t))+1*(((y^~(~x|(y&z)))&~t)|((x&~x)&t))-1*((~(x|(y|z))&~t)|((z^~(x|(~y&z)))&t))+2*((((x&z)^(x^(~y&z)))&~t)|(((x&y)^~(x^(y&z)))&t))-9*(((x^(y|z))&~t)|(((y&z)|(~x&(y|z)))&t))+1*(((y|(x&~z))&~t)|((~(x|y)|~(x^(y^z)))&t))-5*(((~(x^y)|~(x^z))&~t)|(((x|y)&(x^(y^z)))&t))-4*((((x|~y)&~(x^(y^z)))&~t)|((y|(x^z))&t))+9*(((y^~(x|(~y&z)))&~t)|((x&z)&t))-1*((((x&y)^(x^(~y|z)))&~t)|((z^~(x&~y))&t))-3*(((y^~(x&(y^z)))&~t)|((z^~(~x&(~y|z)))&t))+1*((~(~x&(y&z))&~t)|(~(x^(~y&z))&t))-4*(((x&~z)&~t)|((z&~(x^y))&t))+11*~(x|(~y|(z|t)))+11*~(~x|(y|(z|t)))+3*~(~x|(~y|(z|t)))+15*~(x|(y|(~z|t)))+5*~(x|(~y|(~z|t)))-9*~(~x|(~y|(~z|t)))-12*(~x&(~y&(~z&t)))+13*(~x&(y&(~z&t)))+15*(x&(~y&(~z&t)))+4*(x&(y&(~z&t)))+14*(~x&(~y&(z&t)))+13*(~x&(y&(z&t)))-12*(x&(~y&(z&t)))+10*(x&(y&(z&t))),-1*~(~x|(y|(~z|t)))+6*(((~y&~(x^z))&~t)|((z^~(~x|(y&z)))&t)) 23 | -------------------------------------------------------------------------------- /dataset/pldi_dataset_linear_MBA.txt.simplify.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,simplifiedcomplex,simplifiedgroundtruth,z3flag,simtime 2 | (x|y)+y-(~x&y),x+y,1*~(x|~y)+1*(x&~y)+2*(x&y),1*~(x|~y)+1*(x&~y)+2*(x&y),True,0.019237756729125977 3 | 3*(x&~y)-(x^y)+~x-~(x&y),x-y,-1*~(x|~y)+1*(x&~y),-1*~(x|~y)+1*(x&~y),True,0.0010426044464111328 4 | -1*(~(x&y))+(x|y)-1*(x^y)-1*x+2*~x-1*(~(x&~y))-1*(~(x^y))-1*(x|~y)+3*(~(x|y))+1*(~(x|~y))+4*(x&~y)+4*(x&y),1*y+1*~y,-1,-1,True,0.0012309551239013672 5 | -2*(~(x&y))-2*~y-2*~x+(~(x^y))-2*x-1*y-1*(x|y)+(x|~y)+6*(~(x|y))+8*(~(x|~y))+7*(x&~y)+4*(x&y),1*(~(x&~x))+1*(~(x&~y)),2*~(x|y)+2*~(x|~y)+1*(x&~y)+2*(x&y),2*~(x|y)+2*~(x|~y)+1*(x&~y)+2*(x&y),True,0.0015075206756591797 6 | -1*(x|y)+(~(x&~y))+2*y-2*~y-1*~x-1*(~(x&~x))+(~(x^y))+x+2*(~(x|y))-1*(~(x|~y))+3*(x&~y)-2*(x&y),-(~(x&y))+1*(x|~y),-1*~(x|~y)+1*(x&y),-1*~(x|~y)+1*(x&y),True,0.0012502670288085938 7 | -1*x-1*~y+4*(~(x&~x))-1*(~(x^y))+y-4*(~(x&y))-1*(~(x&~y))+2*(~(x|y))-1*(~(x|~y))+2*(x&~y)-2*(x&y),-~x,-1*~x,-1*~x,True,0.0011723041534423828 8 | (~(x&~x))+y-2*(x^y)-1*~y+x-1*(~(x&~y))-2*~x-3*(~(x|y))-2*(~(x|~y))-4*(x&~y)-3*(x&y),-5*(~(x&y))-(~(x^y)),-6*~(x|y)-5*~(x|~y)-5*(x&~y)-1*(x&y),-6*~(x|y)-5*~(x|~y)-5*(x&~y)-1*(x&y),True,0.0018951892852783203 9 | (~(x&y))+(x^y)-1*y+x-2*(x|~y)+2*(~(x&~y))+~y-1*(~(x^y))-1*(~(x|y))-4*(~(x|~y))-3*(x&~y),-(x|y),-1*(x|y),-1*(x|y),True,0.00356292724609375 10 | -1*x-1*~x+4*(x|~y)-1*(~(x&~y))-1*~y-4*(x&~y)-1*(x&y),1*(~(x^y))-2*(x^y),1*~(x|y)-2*~(x|~y)-2*(x&~y)+1*(x&y),1*~(x|y)-2*~(x|~y)-2*(x&~y)+1*(x&y),True,0.0014660358428955078 11 | 2*~x+5*(~(x^y))-1*(~(x&y))+(x^y)+x-1*(~(x&~y))+(x|~y)-7*(~(x|y))-3*(~(x|~y))-3*(x&~y)-8*(x&y),-y-(~(x&~x)),-1*~(x|y)-2*~(x|~y)-1*(x&~y)-2*(x&y),-1*~(x|y)-2*~(x|~y)-1*(x&~y)-2*(x&y),True,0.001287221908569336 12 | -3*~(x^y)-6*~y-2*(x^y)-7*~(x&y)+1*~(x&~x)+2*~(x&~y)-11*(x|~y)-6*x-2*y+24*~(x|y)+8*~(x|~y)+31*(x&~y),-19*(x&y),-19*(x&y),-19*(x&y),True,0.002896547317504883 13 | 1*((x|y)&~(y^z))+1*~(x|(y|z))-2*~(~x|(y|z))-2*(x&(y&z)),1*(~x&(~y|z))-1*((x|~y)&(x^(y^z))),1*~(x|(y|z))-1*~(~x|(y|z))+1*(~x&(y&z))-1*(x&(y&z)),1*~(x|(y|z))-1*~(~x|(y|z))+1*(~x&(y&z))-1*(x&(y&z)),True,0.0026865005493164062 14 | -3*(z^~(~x|(~y&z)))-1*(x&(~y|z))-4*~(x|(~y|z))-1*~(~x|(~y|z))+3*(~x&(~y&z))-1*(~x&(y&z))-3*(x&(y&z)),-4*(x|y),-4*(x|y),-4*(x|y),True,0.0037043094635009766 15 | 2*(y|~(x^z))-1*(~x&(~y|z))+2*~(x^(y|z))-3*~(x|(y|z))-2*~(x|(~y|z))+1*(~x&(~y&z))-4*(x&(~y&z))-4*(x&(y&z)),4*~(~x|(~y|z))+1*(~x&(y&z)),4*~(~x|(~y|z))+1*(~x&(y&z)),4*~(~x|(~y|z))+1*(~x&(y&z)),True,0.0028769969940185547 16 | 5*(~x&(y^z))+1*(x&(y^z))+1*((x&~y)|(x^(y^z)))-6*~(x|(~y|z))-1*~(~x|(y|z))-1*~(~x|(~y|z))-2*(x&(~y&z))-1*(x&(y&z)),6*(~x&(~y&z)),6*(~x&(~y&z)),6*(~x&(~y&z)),True,0.00534510612487793 17 | -7*((x^y)&~(x^z))+5*(~z|~(x^y))-3*~(x|(y|z))+4*~(x|(~y|z))-3*~(~x|(y|z))-3*~(~x|(~y|z))-3*(~x&(~y&z))+9*(x&(~y&z))-5*(x&(y&z)),2*~(y&z),2*~(y&z),2*~(y&z),True,0.0033311843872070312 18 | -3*~(y^z)+5*(z^(~x|(y|z)))-12*~(x|(y|z))-15*~(x|(~y|z))-8*~(~x|(y|z))-16*~(~x|(~y|z))-8*(~x&(y&z))+1*(x&(~y&z))+3*(x&(y&z)),1*(z^(~x|(y&z)))-11*(z^~(~x&(y&z))),-10*~(x|(y|z))-10*~(x|(~y|z))-11*~(~x|(y|z))-11*~(~x|(~y|z))-11*(~x&(y&z))+1*(x&(~y&z)),-10*~(x|(y|z))-10*~(x|(~y|z))-11*~(~x|(y|z))-11*~(~x|(~y|z))-11*(~x&(y&z))+1*(x&(~y&z)),True,0.005104780197143555 19 | -2*(y|~z)+1*(x^y)+2*~(x|(y|z))+3*~(~x|(y|z))+4*~(~x|(~y|z))+2*(~x&(~y&z))+3*(~x&(y&z))-1*(x&(~y&z))+4*(x&(y&z)),2*(z^~(~x|(y&z)))-1*~(x|(~y|z)),-1*~(x|(~y|z))+2*~(~x|(y|z))+2*~(~x|(~y|z))+2*(~x&(~y&z))+2*(~x&(y&z))+2*(x&(y&z)),-1*~(x|(~y|z))+2*~(~x|(y|z))+2*~(~x|(~y|z))+2*(~x&(~y&z))+2*(~x&(y&z))+2*(x&(y&z)),True,0.004362344741821289 20 | -1*((~(x^(~y&z))&~t)|((z^(~x|(y&z)))&t))+1*((((x&y)^(x^(y&z)))&~t)|(((x&~y)|~(y^z))&t))+1*(((z^~(x&y))&~t)|(((x|y)&~(x^(y^z)))&t))-2*~(~x|(y|(z|t)))-2*~(~x|(~y|(~z|t)))+1*(~x&(y&(~z&t)))-1*(x&(~y&(~z&t)))-2*(~x&(y&(z&t)))-1*(x&(y&(z&t))),1*(x&(y&(~z&t)))+1*(x&(~y&(z&t))),1*(((x&~x)&~t)|((x&(y^z))&t)),1*(((x&~x)&~t)|((x&(y^z))&t)),True,0.48560190200805664 21 | 2*((((y&z)|(~x&(y|z)))&~t)|((y^~(x&(~y&z)))&t))-2*(((z^~(~x&(y|z)))&~t)|(((x|y)&~(y^z))&t))-2*(((z^~(x|(~y&z)))&~t)|(((x&y)^(x^(~y|z)))&t))-2*((((x^y)&(x^z))&~t)|((~(x|y)|~(y^z))&t))+4*~(x|(y|(z|t)))+4*~(~x|(y|(z|t)))+2*~(~x|(~y|(z|t)))+2*~(x|(y|(~z|t)))+2*~(x|(~y|(~z|t)))+2*~(~x|(y|(~z|t)))+2*(~x&(~y&(~z&t)))+2*(~x&(~y&(z&t)))+6*(~x&(y&(z&t)))+6*(x&(y&(z&t))),-2*(x&(~y&(~z&t))),-2*(x&(~y&(~z&t))),-2*(x&(~y&(~z&t))),True,0.453047513961792 22 | 3*(((z^~(x|y))&~t)|((y^~(x&(y&z)))&t))+7*(((~y&~(x^z))&~t)|(~(x&~y)&t))+1*(((y^~(~x|(y&z)))&~t)|((x&~x)&t))-1*((~(x|(y|z))&~t)|((z^~(x|(~y&z)))&t))+2*((((x&z)^(x^(~y&z)))&~t)|(((x&y)^~(x^(y&z)))&t))-9*(((x^(y|z))&~t)|(((y&z)|(~x&(y|z)))&t))+1*(((y|(x&~z))&~t)|((~(x|y)|~(x^(y^z)))&t))-5*(((~(x^y)|~(x^z))&~t)|(((x|y)&(x^(y^z)))&t))-4*((((x|~y)&~(x^(y^z)))&~t)|((y|(x^z))&t))+9*(((y^~(x|(~y&z)))&~t)|((x&z)&t))-1*((((x&y)^(x^(~y|z)))&~t)|((z^~(x&~y))&t))-3*(((y^~(x&(y^z)))&~t)|((z^~(~x&(~y|z)))&t))+1*((~(~x&(y&z))&~t)|(~(x^(~y&z))&t))-4*(((x&~z)&~t)|((z&~(x^y))&t))+11*~(x|(~y|(z|t)))+11*~(~x|(y|(z|t)))+3*~(~x|(~y|(z|t)))+15*~(x|(y|(~z|t)))+5*~(x|(~y|(~z|t)))-9*~(~x|(~y|(~z|t)))-12*(~x&(~y&(~z&t)))+13*(~x&(y&(~z&t)))+15*(x&(~y&(~z&t)))+4*(x&(y&(~z&t)))+14*(~x&(~y&(z&t)))+13*(~x&(y&(z&t)))-12*(x&(~y&(z&t)))+10*(x&(y&(z&t))),-1*~(~x|(y|(~z|t)))+6*(((~y&~(x^z))&~t)|((z^~(~x|(y&z)))&t)),6*~(x|(y|(z|t)))+5*~(~x|(y|(~z|t)))+6*(x&(~y&(~z&t)))+6*(x&(y&(~z&t)))+6*(~x&(~y&(z&t)))+6*(~x&(y&(z&t)))+6*(x&(y&(z&t))),6*~(x|(y|(z|t)))+5*~(~x|(y|(~z|t)))+6*(x&(~y&(~z&t)))+6*(x&(y&(~z&t)))+6*(~x&(~y&(z&t)))+6*(~x&(y&(z&t)))+6*(x&(y&(z&t))),True,0.4736015796661377 23 | -------------------------------------------------------------------------------- /dataset/pldi_dataset_linear_MBA.txt.simplify.txt.z3.verify.64bit.after.simplify.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,simcomplex,simground,z3res,verificationtime 2 | (x|y)+y-(~x&y),x+y,1*~(x|~y)+1*(x&~y)+2*(x&y),1*~(x|~y)+1*(x&~y)+2*(x&y),True,0.02516460418701172 3 | 3*(x&~y)-(x^y)+~x-~(x&y),x-y,-1*~(x|~y)+1*(x&~y),-1*~(x|~y)+1*(x&~y),True,0.021987438201904297 4 | -1*(~(x&y))+(x|y)-1*(x^y)-1*x+2*~x-1*(~(x&~y))-1*(~(x^y))-1*(x|~y)+3*(~(x|y))+1*(~(x|~y))+4*(x&~y)+4*(x&y),1*y+1*~y,-1,-1,True,0.024457931518554688 5 | -2*(~(x&y))-2*~y-2*~x+(~(x^y))-2*x-1*y-1*(x|y)+(x|~y)+6*(~(x|y))+8*(~(x|~y))+7*(x&~y)+4*(x&y),1*(~(x&~x))+1*(~(x&~y)),2*~(x|y)+2*~(x|~y)+1*(x&~y)+2*(x&y),2*~(x|y)+2*~(x|~y)+1*(x&~y)+2*(x&y),True,0.02544236183166504 6 | -1*(x|y)+(~(x&~y))+2*y-2*~y-1*~x-1*(~(x&~x))+(~(x^y))+x+2*(~(x|y))-1*(~(x|~y))+3*(x&~y)-2*(x&y),-(~(x&y))+1*(x|~y),-1*~(x|~y)+1*(x&y),-1*~(x|~y)+1*(x&y),True,0.02810811996459961 7 | -1*x-1*~y+4*(~(x&~x))-1*(~(x^y))+y-4*(~(x&y))-1*(~(x&~y))+2*(~(x|y))-1*(~(x|~y))+2*(x&~y)-2*(x&y),-~x,-1*~x,-1*~x,True,0.036657094955444336 8 | (~(x&~x))+y-2*(x^y)-1*~y+x-1*(~(x&~y))-2*~x-3*(~(x|y))-2*(~(x|~y))-4*(x&~y)-3*(x&y),-5*(~(x&y))-(~(x^y)),-6*~(x|y)-5*~(x|~y)-5*(x&~y)-1*(x&y),-6*~(x|y)-5*~(x|~y)-5*(x&~y)-1*(x&y),True,0.028145551681518555 9 | (~(x&y))+(x^y)-1*y+x-2*(x|~y)+2*(~(x&~y))+~y-1*(~(x^y))-1*(~(x|y))-4*(~(x|~y))-3*(x&~y),-(x|y),-1*(x|y),-1*(x|y),True,0.02967524528503418 10 | -1*x-1*~x+4*(x|~y)-1*(~(x&~y))-1*~y-4*(x&~y)-1*(x&y),1*(~(x^y))-2*(x^y),1*~(x|y)-2*~(x|~y)-2*(x&~y)+1*(x&y),1*~(x|y)-2*~(x|~y)-2*(x&~y)+1*(x&y),True,0.030411243438720703 11 | 2*~x+5*(~(x^y))-1*(~(x&y))+(x^y)+x-1*(~(x&~y))+(x|~y)-7*(~(x|y))-3*(~(x|~y))-3*(x&~y)-8*(x&y),-y-(~(x&~x)),-1*~(x|y)-2*~(x|~y)-1*(x&~y)-2*(x&y),-1*~(x|y)-2*~(x|~y)-1*(x&~y)-2*(x&y),True,0.035628318786621094 12 | -3*~(x^y)-6*~y-2*(x^y)-7*~(x&y)+1*~(x&~x)+2*~(x&~y)-11*(x|~y)-6*x-2*y+24*~(x|y)+8*~(x|~y)+31*(x&~y),-19*(x&y),-19*(x&y),-19*(x&y),True,0.036316633224487305 13 | 1*((x|y)&~(y^z))+1*~(x|(y|z))-2*~(~x|(y|z))-2*(x&(y&z)),1*(~x&(~y|z))-1*((x|~y)&(x^(y^z))),1*~(x|(y|z))-1*~(~x|(y|z))+1*(~x&(y&z))-1*(x&(y&z)),1*~(x|(y|z))-1*~(~x|(y|z))+1*(~x&(y&z))-1*(x&(y&z)),True,0.03185009956359863 14 | -3*(z^~(~x|(~y&z)))-1*(x&(~y|z))-4*~(x|(~y|z))-1*~(~x|(~y|z))+3*(~x&(~y&z))-1*(~x&(y&z))-3*(x&(y&z)),-4*(x|y),-4*(x|y),-4*(x|y),True,0.02678203582763672 15 | 2*(y|~(x^z))-1*(~x&(~y|z))+2*~(x^(y|z))-3*~(x|(y|z))-2*~(x|(~y|z))+1*(~x&(~y&z))-4*(x&(~y&z))-4*(x&(y&z)),4*~(~x|(~y|z))+1*(~x&(y&z)),4*~(~x|(~y|z))+1*(~x&(y&z)),4*~(~x|(~y|z))+1*(~x&(y&z)),True,0.024659156799316406 16 | 5*(~x&(y^z))+1*(x&(y^z))+1*((x&~y)|(x^(y^z)))-6*~(x|(~y|z))-1*~(~x|(y|z))-1*~(~x|(~y|z))-2*(x&(~y&z))-1*(x&(y&z)),6*(~x&(~y&z)),6*(~x&(~y&z)),6*(~x&(~y&z)),True,0.02594757080078125 17 | -7*((x^y)&~(x^z))+5*(~z|~(x^y))-3*~(x|(y|z))+4*~(x|(~y|z))-3*~(~x|(y|z))-3*~(~x|(~y|z))-3*(~x&(~y&z))+9*(x&(~y&z))-5*(x&(y&z)),2*~(y&z),2*~(y&z),2*~(y&z),True,0.024266719818115234 18 | -3*~(y^z)+5*(z^(~x|(y|z)))-12*~(x|(y|z))-15*~(x|(~y|z))-8*~(~x|(y|z))-16*~(~x|(~y|z))-8*(~x&(y&z))+1*(x&(~y&z))+3*(x&(y&z)),1*(z^(~x|(y&z)))-11*(z^~(~x&(y&z))),-10*~(x|(y|z))-10*~(x|(~y|z))-11*~(~x|(y|z))-11*~(~x|(~y|z))-11*(~x&(y&z))+1*(x&(~y&z)),-10*~(x|(y|z))-10*~(x|(~y|z))-11*~(~x|(y|z))-11*~(~x|(~y|z))-11*(~x&(y&z))+1*(x&(~y&z)),True,0.028255462646484375 19 | -2*(y|~z)+1*(x^y)+2*~(x|(y|z))+3*~(~x|(y|z))+4*~(~x|(~y|z))+2*(~x&(~y&z))+3*(~x&(y&z))-1*(x&(~y&z))+4*(x&(y&z)),2*(z^~(~x|(y&z)))-1*~(x|(~y|z)),-1*~(x|(~y|z))+2*~(~x|(y|z))+2*~(~x|(~y|z))+2*(~x&(~y&z))+2*(~x&(y&z))+2*(x&(y&z)),-1*~(x|(~y|z))+2*~(~x|(y|z))+2*~(~x|(~y|z))+2*(~x&(~y&z))+2*(~x&(y&z))+2*(x&(y&z)),True,0.027940988540649414 20 | -1*((~(x^(~y&z))&~t)|((z^(~x|(y&z)))&t))+1*((((x&y)^(x^(y&z)))&~t)|(((x&~y)|~(y^z))&t))+1*(((z^~(x&y))&~t)|(((x|y)&~(x^(y^z)))&t))-2*~(~x|(y|(z|t)))-2*~(~x|(~y|(~z|t)))+1*(~x&(y&(~z&t)))-1*(x&(~y&(~z&t)))-2*(~x&(y&(z&t)))-1*(x&(y&(z&t))),1*(x&(y&(~z&t)))+1*(x&(~y&(z&t))),1*(((x&~x)&~t)|((x&(y^z))&t)),1*(((x&~x)&~t)|((x&(y^z))&t)),True,0.022180795669555664 21 | 2*((((y&z)|(~x&(y|z)))&~t)|((y^~(x&(~y&z)))&t))-2*(((z^~(~x&(y|z)))&~t)|(((x|y)&~(y^z))&t))-2*(((z^~(x|(~y&z)))&~t)|(((x&y)^(x^(~y|z)))&t))-2*((((x^y)&(x^z))&~t)|((~(x|y)|~(y^z))&t))+4*~(x|(y|(z|t)))+4*~(~x|(y|(z|t)))+2*~(~x|(~y|(z|t)))+2*~(x|(y|(~z|t)))+2*~(x|(~y|(~z|t)))+2*~(~x|(y|(~z|t)))+2*(~x&(~y&(~z&t)))+2*(~x&(~y&(z&t)))+6*(~x&(y&(z&t)))+6*(x&(y&(z&t))),-2*(x&(~y&(~z&t))),-2*(x&(~y&(~z&t))),-2*(x&(~y&(~z&t))),True,0.028020858764648438 22 | 3*(((z^~(x|y))&~t)|((y^~(x&(y&z)))&t))+7*(((~y&~(x^z))&~t)|(~(x&~y)&t))+1*(((y^~(~x|(y&z)))&~t)|((x&~x)&t))-1*((~(x|(y|z))&~t)|((z^~(x|(~y&z)))&t))+2*((((x&z)^(x^(~y&z)))&~t)|(((x&y)^~(x^(y&z)))&t))-9*(((x^(y|z))&~t)|(((y&z)|(~x&(y|z)))&t))+1*(((y|(x&~z))&~t)|((~(x|y)|~(x^(y^z)))&t))-5*(((~(x^y)|~(x^z))&~t)|(((x|y)&(x^(y^z)))&t))-4*((((x|~y)&~(x^(y^z)))&~t)|((y|(x^z))&t))+9*(((y^~(x|(~y&z)))&~t)|((x&z)&t))-1*((((x&y)^(x^(~y|z)))&~t)|((z^~(x&~y))&t))-3*(((y^~(x&(y^z)))&~t)|((z^~(~x&(~y|z)))&t))+1*((~(~x&(y&z))&~t)|(~(x^(~y&z))&t))-4*(((x&~z)&~t)|((z&~(x^y))&t))+11*~(x|(~y|(z|t)))+11*~(~x|(y|(z|t)))+3*~(~x|(~y|(z|t)))+15*~(x|(y|(~z|t)))+5*~(x|(~y|(~z|t)))-9*~(~x|(~y|(~z|t)))-12*(~x&(~y&(~z&t)))+13*(~x&(y&(~z&t)))+15*(x&(~y&(~z&t)))+4*(x&(y&(~z&t)))+14*(~x&(~y&(z&t)))+13*(~x&(y&(z&t)))-12*(x&(~y&(z&t)))+10*(x&(y&(z&t))),-1*~(~x|(y|(~z|t)))+6*(((~y&~(x^z))&~t)|((z^~(~x|(y&z)))&t)),6*~(x|(y|(z|t)))+5*~(~x|(y|(~z|t)))+6*(x&(~y&(~z&t)))+6*(x&(y&(~z&t)))+6*(~x&(~y&(z&t)))+6*(~x&(y&(z&t)))+6*(x&(y&(z&t))),6*~(x|(y|(z|t)))+5*~(~x|(y|(~z|t)))+6*(x&(~y&(~z&t)))+6*(x&(y&(~z&t)))+6*(~x&(~y&(z&t)))+6*(~x&(y&(z&t)))+6*(x&(y&(z&t))),True,0.03368663787841797 23 | -------------------------------------------------------------------------------- /dataset/pldi_dataset_linear_MBA.txt.z3.verify.64bit.before.simplify.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,z3res,verificationtime 2 | (x|y)+y-(~x&y),x+y,True,0.056780099868774414 3 | 3*(x&~y)-(x^y)+~x-~(x&y),x-y,True,1.4941563606262207 4 | -1*(~(x&y))+(x|y)-1*(x^y)-1*x+2*~x-1*(~(x&~y))-1*(~(x^y))-1*(x|~y)+3*(~(x|y))+1*(~(x|~y))+4*(x&~y)+4*(x&y),1*y+1*~y,Timeout,5.011584043502808 5 | -2*(~(x&y))-2*~y-2*~x+(~(x^y))-2*x-1*y-1*(x|y)+(x|~y)+6*(~(x|y))+8*(~(x|~y))+7*(x&~y)+4*(x&y),1*(~(x&~x))+1*(~(x&~y)),Timeout,5.010826349258423 6 | -1*(x|y)+(~(x&~y))+2*y-2*~y-1*~x-1*(~(x&~x))+(~(x^y))+x+2*(~(x|y))-1*(~(x|~y))+3*(x&~y)-2*(x&y),-(~(x&y))+1*(x|~y),Timeout,5.009274244308472 7 | -1*x-1*~y+4*(~(x&~x))-1*(~(x^y))+y-4*(~(x&y))-1*(~(x&~y))+2*(~(x|y))-1*(~(x|~y))+2*(x&~y)-2*(x&y),-~x,Timeout,5.010176420211792 8 | (~(x&~x))+y-2*(x^y)-1*~y+x-1*(~(x&~y))-2*~x-3*(~(x|y))-2*(~(x|~y))-4*(x&~y)-3*(x&y),-5*(~(x&y))-(~(x^y)),Timeout,5.008573532104492 9 | (~(x&y))+(x^y)-1*y+x-2*(x|~y)+2*(~(x&~y))+~y-1*(~(x^y))-1*(~(x|y))-4*(~(x|~y))-3*(x&~y),-(x|y),Timeout,5.010337829589844 10 | -1*x-1*~x+4*(x|~y)-1*(~(x&~y))-1*~y-4*(x&~y)-1*(x&y),1*(~(x^y))-2*(x^y),Timeout,5.008653163909912 11 | 2*~x+5*(~(x^y))-1*(~(x&y))+(x^y)+x-1*(~(x&~y))+(x|~y)-7*(~(x|y))-3*(~(x|~y))-3*(x&~y)-8*(x&y),-y-(~(x&~x)),Timeout,5.010957956314087 12 | -3*~(x^y)-6*~y-2*(x^y)-7*~(x&y)+1*~(x&~x)+2*~(x&~y)-11*(x|~y)-6*x-2*y+24*~(x|y)+8*~(x|~y)+31*(x&~y),-19*(x&y),Timeout,5.010417222976685 13 | 1*((x|y)&~(y^z))+1*~(x|(y|z))-2*~(~x|(y|z))-2*(x&(y&z)),1*(~x&(~y|z))-1*((x|~y)&(x^(y^z))),True,1.62892746925354 14 | -3*(z^~(~x|(~y&z)))-1*(x&(~y|z))-4*~(x|(~y|z))-1*~(~x|(~y|z))+3*(~x&(~y&z))-1*(~x&(y&z))-3*(x&(y&z)),-4*(x|y),Timeout,5.00928521156311 15 | 2*(y|~(x^z))-1*(~x&(~y|z))+2*~(x^(y|z))-3*~(x|(y|z))-2*~(x|(~y|z))+1*(~x&(~y&z))-4*(x&(~y&z))-4*(x&(y&z)),4*~(~x|(~y|z))+1*(~x&(y&z)),Timeout,5.057357549667358 16 | 5*(~x&(y^z))+1*(x&(y^z))+1*((x&~y)|(x^(y^z)))-6*~(x|(~y|z))-1*~(~x|(y|z))-1*~(~x|(~y|z))-2*(x&(~y&z))-1*(x&(y&z)),6*(~x&(~y&z)),Timeout,5.011525869369507 17 | -7*((x^y)&~(x^z))+5*(~z|~(x^y))-3*~(x|(y|z))+4*~(x|(~y|z))-3*~(~x|(y|z))-3*~(~x|(~y|z))-3*(~x&(~y&z))+9*(x&(~y&z))-5*(x&(y&z)),2*~(y&z),Timeout,5.009667873382568 18 | -3*~(y^z)+5*(z^(~x|(y|z)))-12*~(x|(y|z))-15*~(x|(~y|z))-8*~(~x|(y|z))-16*~(~x|(~y|z))-8*(~x&(y&z))+1*(x&(~y&z))+3*(x&(y&z)),1*(z^(~x|(y&z)))-11*(z^~(~x&(y&z))),Timeout,5.009520530700684 19 | -2*(y|~z)+1*(x^y)+2*~(x|(y|z))+3*~(~x|(y|z))+4*~(~x|(~y|z))+2*(~x&(~y&z))+3*(~x&(y&z))-1*(x&(~y&z))+4*(x&(y&z)),2*(z^~(~x|(y&z)))-1*~(x|(~y|z)),Timeout,5.010574817657471 20 | -1*((~(x^(~y&z))&~t)|((z^(~x|(y&z)))&t))+1*((((x&y)^(x^(y&z)))&~t)|(((x&~y)|~(y^z))&t))+1*(((z^~(x&y))&~t)|(((x|y)&~(x^(y^z)))&t))-2*~(~x|(y|(z|t)))-2*~(~x|(~y|(~z|t)))+1*(~x&(y&(~z&t)))-1*(x&(~y&(~z&t)))-2*(~x&(y&(z&t)))-1*(x&(y&(z&t))),1*(x&(y&(~z&t)))+1*(x&(~y&(z&t))),Timeout,5.009374380111694 21 | 2*((((y&z)|(~x&(y|z)))&~t)|((y^~(x&(~y&z)))&t))-2*(((z^~(~x&(y|z)))&~t)|(((x|y)&~(y^z))&t))-2*(((z^~(x|(~y&z)))&~t)|(((x&y)^(x^(~y|z)))&t))-2*((((x^y)&(x^z))&~t)|((~(x|y)|~(y^z))&t))+4*~(x|(y|(z|t)))+4*~(~x|(y|(z|t)))+2*~(~x|(~y|(z|t)))+2*~(x|(y|(~z|t)))+2*~(x|(~y|(~z|t)))+2*~(~x|(y|(~z|t)))+2*(~x&(~y&(~z&t)))+2*(~x&(~y&(z&t)))+6*(~x&(y&(z&t)))+6*(x&(y&(z&t))),-2*(x&(~y&(~z&t))),Timeout,5.010774850845337 22 | 3*(((z^~(x|y))&~t)|((y^~(x&(y&z)))&t))+7*(((~y&~(x^z))&~t)|(~(x&~y)&t))+1*(((y^~(~x|(y&z)))&~t)|((x&~x)&t))-1*((~(x|(y|z))&~t)|((z^~(x|(~y&z)))&t))+2*((((x&z)^(x^(~y&z)))&~t)|(((x&y)^~(x^(y&z)))&t))-9*(((x^(y|z))&~t)|(((y&z)|(~x&(y|z)))&t))+1*(((y|(x&~z))&~t)|((~(x|y)|~(x^(y^z)))&t))-5*(((~(x^y)|~(x^z))&~t)|(((x|y)&(x^(y^z)))&t))-4*((((x|~y)&~(x^(y^z)))&~t)|((y|(x^z))&t))+9*(((y^~(x|(~y&z)))&~t)|((x&z)&t))-1*((((x&y)^(x^(~y|z)))&~t)|((z^~(x&~y))&t))-3*(((y^~(x&(y^z)))&~t)|((z^~(~x&(~y|z)))&t))+1*((~(~x&(y&z))&~t)|(~(x^(~y&z))&t))-4*(((x&~z)&~t)|((z&~(x^y))&t))+11*~(x|(~y|(z|t)))+11*~(~x|(y|(z|t)))+3*~(~x|(~y|(z|t)))+15*~(x|(y|(~z|t)))+5*~(x|(~y|(~z|t)))-9*~(~x|(~y|(~z|t)))-12*(~x&(~y&(~z&t)))+13*(~x&(y&(~z&t)))+15*(x&(~y&(~z&t)))+4*(x&(y&(~z&t)))+14*(~x&(~y&(z&t)))+13*(~x&(y&(z&t)))-12*(x&(~y&(z&t)))+10*(x&(y&(z&t))),-1*~(~x|(y|(~z|t)))+6*(((~y&~(x^z))&~t)|((z^~(~x|(y&z)))&t)),Timeout,5.011717081069946 23 | -------------------------------------------------------------------------------- /dataset/pldi_dataset_nonpoly_MBA.txt.z3.verify.64bit.before.simplify.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,z3res,verificationtime 2 | ((3*(a&b)+2*(a&~b)-2*~(a&~a)+1*~(a|b)+2*~(a|~b)+1*~b)&y)*((3*(a&b)+2*(a&~b)-2*~(a&~a)+1*~(a|b)+2*~(a|~b)+1*~b)|y)+((3*(a&b)+2*(a&~b)-2*~(a&~a)+1*~(a|b)+2*~(a|~b)+1*~b)&~y)*(~(3*(a&b)+2*(a&~b)-2*~(a&~a)+1*~(a|b)+2*~(a|~b)+1*~b)&y),a*y,Timeout,5.01941180229187 3 | (x&(-3*(a&b)+1*(a&~b)-1*~(a&b)+4*~(a^b)-3*~(a|b)+2*~(a|~b)))*(x|(-3*(a&b)+1*(a&~b)-1*~(a&b)+4*~(a^b)-3*~(a|b)+2*~(a|~b)))+(x&~(-3*(a&b)+1*(a&~b)-1*~(a&b)+4*~(a^b)-3*~(a|b)+2*~(a|~b)))*(~x&(-3*(a&b)+1*(a&~b)-1*~(a&b)+4*~(a^b)-3*~(a|b)+2*~(a|~b))),x*b,Timeout,5.012365341186523 4 | (~((-1*(a&b)-1*(a&~b)-3*(a|b)+5*a+3*~(a|~b))&y))+y+2*(~((-1*(a&b)-1*(a&~b)-3*(a|b)+5*a+3*~(a|~b))&~(-1*(a&b)-1*(a&~b)-3*(a|b)+5*a+3*~(a|~b))))+(-1*(a&b)-1*(a&~b)-3*(a|b)+5*a+3*~(a|~b))-1*(~((-1*(a&b)-1*(a&~b)-3*(a|b)+5*a+3*~(a|~b))&~y))+2*(~((-1*(a&b)-1*(a&~b)-3*(a|b)+5*a+3*~(a|~b))^y))-4*(~((-1*(a&b)-1*(a&~b)-3*(a|b)+5*a+3*~(a|~b))|y))-4*(~((-1*(a&b)-1*(a&~b)-3*(a|b)+5*a+3*~(a|~b))|~y))-5*((-1*(a&b)-1*(a&~b)-3*(a|b)+5*a+3*~(a|~b))&~y)-5*((-1*(a&b)-1*(a&~b)-3*(a|b)+5*a+3*~(a|~b))&y),-(a^y),Timeout,5.009170055389404 5 | -1*(~((6*(a&b)-1*(a&~b)-5*b-2*~(a|b)+5*~(a|~b)+2*~b)^y))+~(6*(a&b)-1*(a&~b)-5*b-2*~(a|b)+5*~(a|~b)+2*~b)-1*(6*(a&b)-1*(a&~b)-5*b-2*~(a|b)+5*~(a|~b)+2*~b)-1*((6*(a&b)-1*(a&~b)-5*b-2*~(a|b)+5*~(a|~b)+2*~b)^y)+((6*(a&b)-1*(a&~b)-5*b-2*~(a|b)+5*~(a|~b)+2*~b)|~y)-2*~y-1*((6*(a&b)-1*(a&~b)-5*b-2*~(a|b)+5*~(a|~b)+2*~b)|y)+2*(~((6*(a&b)-1*(a&~b)-5*b-2*~(a|b)+5*~(a|~b)+2*~b)|~y))+3*((6*(a&b)-1*(a&~b)-5*b-2*~(a|b)+5*~(a|~b)+2*~b)&~y)+4*((6*(a&b)-1*(a&~b)-5*b-2*~(a|b)+5*~(a|~b)+2*~b)&y),2*y-(~(a&y)),Timeout,5.010430812835693 6 | (~((6*(a&b)+8*(a&~b)-5*b+7*~(a|b)+5*~(a|~b)-7*~b)&y))-1*((6*(a&b)+8*(a&~b)-5*b+7*~(a|b)+5*~(a|~b)-7*~b)|y)+~(6*(a&b)+8*(a&~b)-5*b+7*~(a|b)+5*~(a|~b)-7*~b)+(~((6*(a&b)+8*(a&~b)-5*b+7*~(a|b)+5*~(a|~b)-7*~b)^y))+2*(~((6*(a&b)+8*(a&~b)-5*b+7*~(a|b)+5*~(a|~b)-7*~b)&~y))+(6*(a&b)+8*(a&~b)-5*b+7*~(a|b)+5*~(a|~b)-7*~b)-1*((6*(a&b)+8*(a&~b)-5*b+7*~(a|b)+5*~(a|~b)-7*~b)^y)+~y-2*(~((6*(a&b)+8*(a&~b)-5*b+7*~(a|b)+5*~(a|~b)-7*~b)|y))-2*(~((6*(a&b)+8*(a&~b)-5*b+7*~(a|b)+5*~(a|~b)-7*~b)|~y))+3*((6*(a&b)+8*(a&~b)-5*b+7*~(a|b)+5*~(a|~b)-7*~b)&~y)+1*((6*(a&b)+8*(a&~b)-5*b+7*~(a|b)+5*~(a|~b)-7*~b)&y),4*(a|~y),Timeout,5.00696325302124 7 | -1*~y+(~((1*(a&b)-1*(a&~b)+2*~(a&b)+3*~(a|b)+3*~(a|~b)-5*~a)&~(1*(a&b)-1*(a&~b)+2*~(a&b)+3*~(a|b)+3*~(a|~b)-5*~a)))-5*(~((1*(a&b)-1*(a&~b)+2*~(a&b)+3*~(a|b)+3*~(a|~b)-5*~a)&~y))-1*(~((1*(a&b)-1*(a&~b)+2*~(a&b)+3*~(a|b)+3*~(a|~b)-5*~a)^y))-1*(1*(a&b)-1*(a&~b)+2*~(a&b)+3*~(a|b)+3*~(a|~b)-5*~a)+((1*(a&b)-1*(a&~b)+2*~(a&b)+3*~(a|b)+3*~(a|~b)-5*~a)|y)+5*(~((1*(a&b)-1*(a&~b)+2*~(a&b)+3*~(a|b)+3*~(a|~b)-5*~a)|y))+5*(~((1*(a&b)-1*(a&~b)+2*~(a&b)+3*~(a|b)+3*~(a|~b)-5*~a)|~y))+1*((1*(a&b)-1*(a&~b)+2*~(a&b)+3*~(a|b)+3*~(a|~b)-5*~a)&~y)+4*((1*(a&b)-1*(a&~b)+2*~(a&b)+3*~(a|b)+3*~(a|~b)-5*~a)&y),2*(a^y)-(a|~y),Timeout,5.011230707168579 8 | -4*~(-3*(a&b)-10*(a&~b)+11*(a|b)-7*b-4*~(a|~b))-1*((-3*(a&b)-10*(a&~b)+11*(a|b)-7*b-4*~(a|~b))|~y)-1*y+~y-2*(-3*(a&b)-10*(a&~b)+11*(a|b)-7*b-4*~(a|~b))+(~((-3*(a&b)-10*(a&~b)+11*(a|b)-7*b-4*~(a|~b))^y))+(~((-3*(a&b)-10*(a&~b)+11*(a|b)-7*b-4*~(a|~b))&y))-2*((-3*(a&b)-10*(a&~b)+11*(a|b)-7*b-4*~(a|~b))|y)+2*(~((-3*(a&b)-10*(a&~b)+11*(a|b)-7*b-4*~(a|~b))|y))+5*(~((-3*(a&b)-10*(a&~b)+11*(a|b)-7*b-4*~(a|~b))|~y))+2*((-3*(a&b)-10*(a&~b)+11*(a|b)-7*b-4*~(a|~b))&~y)+5*((-3*(a&b)-10*(a&~b)+11*(a|b)-7*b-4*~(a|~b))&y),-(a^y),Timeout,5.008637428283691 9 | -1*(-11*(a&b)-10*(a&~b)+11*(a|~b)+1*~(a^b)-12*~(a|b))-1*(~((-11*(a&b)-10*(a&~b)+11*(a|~b)+1*~(a^b)-12*~(a|b))&y))+2*((-11*(a&b)-10*(a&~b)+11*(a|~b)+1*~(a^b)-12*~(a|b))^y)+2*(~((-11*(a&b)-10*(a&~b)+11*(a|~b)+1*~(a^b)-12*~(a|b))&~y))-1*(~((-11*(a&b)-10*(a&~b)+11*(a|~b)+1*~(a^b)-12*~(a|b))^y))-1*y-2*((-11*(a&b)-10*(a&~b)+11*(a|~b)+1*~(a^b)-12*~(a|b))|~y)+((-11*(a&b)-10*(a&~b)+11*(a|~b)+1*~(a^b)-12*~(a|b))|y)+6*(~((-11*(a&b)-10*(a&~b)+11*(a|~b)+1*~(a^b)-12*~(a|b))|y))-4*(~((-11*(a&b)-10*(a&~b)+11*(a|~b)+1*~(a^b)-12*~(a|b))|~y))+5*((-11*(a&b)-10*(a&~b)+11*(a|~b)+1*~(a^b)-12*~(a|b))&~y)+1*((-11*(a&b)-10*(a&~b)+11*(a|~b)+1*~(a^b)-12*~(a|b))&y),5*~y-(~(a&~a)),Timeout,5.010581970214844 10 | ((-1*(a&b)+3*(a&~b)-2*(a|~b)+4*~(a&~b)-2*~(a|b)-4*~(a|~b))^y)+~y-2*((-1*(a&b)+3*(a&~b)-2*(a|~b)+4*~(a&~b)-2*~(a|b)-4*~(a|~b))|y)-1*(~((-1*(a&b)+3*(a&~b)-2*(a|~b)+4*~(a&~b)-2*~(a|b)-4*~(a|~b))&y))-1*(~((-1*(a&b)+3*(a&~b)-2*(a|~b)+4*~(a&~b)-2*~(a|b)-4*~(a|~b))&~(-1*(a&b)+3*(a&~b)-2*(a|~b)+4*~(a&~b)-2*~(a|b)-4*~(a|~b))))+2*(~((-1*(a&b)+3*(a&~b)-2*(a|~b)+4*~(a&~b)-2*~(a|b)-4*~(a|~b))&~y))-1*(-1*(a&b)+3*(a&~b)-2*(a|~b)+4*~(a&~b)-2*~(a|b)-4*~(a|~b))+y+2*~(-1*(a&b)+3*(a&~b)-2*(a|~b)+4*~(a&~b)-2*~(a|b)-4*~(a|~b))-4*(~((-1*(a&b)+3*(a&~b)-2*(a|~b)+4*~(a&~b)-2*~(a|b)-4*~(a|~b))|y))-2*(~((-1*(a&b)+3*(a&~b)-2*(a|~b)+4*~(a&~b)-2*~(a|b)-4*~(a|~b))|~y))+3*((-1*(a&b)+3*(a&~b)-2*(a|~b)+4*~(a&~b)-2*~(a|b)-4*~(a|~b))&~y),-(~(a^y)),Timeout,5.007885932922363 11 | -1*~(5*(a&b)+5*(a&~b)-2*(a|b)-2*a+2*~(a|~b))-1*(~((5*(a&b)+5*(a&~b)-2*(a|b)-2*a+2*~(a|~b))^y))+2*~y-1*((5*(a&b)+5*(a&~b)-2*(a|b)-2*a+2*~(a|~b))^y)-1*((5*(a&b)+5*(a&~b)-2*(a|b)-2*a+2*~(a|~b))|~y)-1*y-1*(~((5*(a&b)+5*(a&~b)-2*(a|b)-2*a+2*~(a|~b))&y))-1*(~((5*(a&b)+5*(a&~b)-2*(a|b)-2*a+2*~(a|~b))&~y))-1*(~((5*(a&b)+5*(a&~b)-2*(a|b)-2*a+2*~(a|~b))|y))+1*(~((5*(a&b)+5*(a&~b)-2*(a|b)-2*a+2*~(a|~b))|~y))-3*((5*(a&b)+5*(a&~b)-2*(a|b)-2*a+2*~(a|~b))&~y),-4*(~(a&~a)),Timeout,5.011698961257935 12 | 2*y+5*~((-10*(a&b)+1*(a&~b)+11*b+11*~(a|b)-11*~a)^y)-2*~(-10*(a&b)+1*(a&~b)+11*b+11*~(a|b)-11*~a)+1*~((-10*(a&b)+1*(a&~b)+11*b+11*~(a|b)-11*~a)&y)+1*(-10*(a&b)+1*(a&~b)+11*b+11*~(a|b)-11*~a)-11*((-10*(a&b)+1*(a&~b)+11*b+11*~(a|b)-11*~a)^y)+4*~((-10*(a&b)+1*(a&~b)+11*b+11*~(a|b)-11*~a)&~y)+1*((-10*(a&b)+1*(a&~b)+11*b+11*~(a|b)-11*~a)|y)-7*~((-10*(a&b)+1*(a&~b)+11*b+11*~(a|b)-11*~a)&~(-10*(a&b)+1*(a&~b)+11*b+11*~(a|b)-11*~a))+4*~((-10*(a&b)+1*(a&~b)+11*b+11*~(a|b)-11*~a)|y)+20*((-10*(a&b)+1*(a&~b)+11*b+11*~(a|b)-11*~a)&~y)-1*((-10*(a&b)+1*(a&~b)+11*b+11*~(a|b)-11*~a)&y),5*(a|~y)-12*~(a|~y),Timeout,5.010175704956055 13 | 1*((7*(a&b)+4*(a&~b)-3*a-3*~(a^b)+3*~(a|b))^(y&z))+1*~((7*(a&b)+4*(a&~b)-3*a-3*~(a^b)+3*~(a|b))|(y|z))+1*~(~(7*(a&b)+4*(a&~b)-3*a-3*~(a^b)+3*~(a|b))|(y|z))+1*((7*(a&b)+4*(a&~b)-3*a-3*~(a^b)+3*~(a|b))&(~y&z))+2*((7*(a&b)+4*(a&~b)-3*a-3*~(a^b)+3*~(a|b))&(y&z)),1*((a&z)|~(y|z))+1*(a|(y&z)),Timeout,5.010781526565552 14 | 1*(z^((-10*(a&b)+1*(a^b)+11*~(a&~b)-11*~(a|b)-12*~(a|~b))&(y|z)))+1*(((-10*(a&b)+1*(a^b)+11*~(a&~b)-11*~(a|b)-12*~(a|~b))&y)^(y|z))+1*(y^(~(-10*(a&b)+1*(a^b)+11*~(a&~b)-11*~(a|b)-12*~(a|~b))|(y&z)))-2*~(~(-10*(a&b)+1*(a^b)+11*~(a&~b)-11*~(a|b)-12*~(a|~b))|(~y|z))-3*(~(-10*(a&b)+1*(a^b)+11*~(a&~b)-11*~(a|b)-12*~(a|~b))&(~y&z))-2*(~(-10*(a&b)+1*(a^b)+11*~(a&~b)-11*~(a|b)-12*~(a|~b))&(y&z))-1*((-10*(a&b)+1*(a^b)+11*~(a&~b)-11*~(a|b)-12*~(a|~b))&(~y&z)),1*~(a|(y|z))+1*~(a|(~y|z)),Timeout,5.0105791091918945 15 | 1*(~(4*(a&b)-2*(a&~b)-3*~(a^b)+3*~b)&(~y|z))-5*(y^~(~(4*(a&b)-2*(a&~b)-3*~(a^b)+3*~b)&(y^z)))-2*(z|((4*(a&b)-2*(a&~b)-3*~(a^b)+3*~b)^y))+7*~((4*(a&b)-2*(a&~b)-3*~(a^b)+3*~b)|(~y|z))+7*~(~(4*(a&b)-2*(a&~b)-3*~(a^b)+3*~b)|(y|z))+1*(~(4*(a&b)-2*(a&~b)-3*~(a^b)+3*~b)&(y&z))+7*((4*(a&b)-2*(a&~b)-3*~(a^b)+3*~b)&(~y&z))+2*((4*(a&b)-2*(a&~b)-3*~(a^b)+3*~b)&(y&z)),-4*~(a|(y|z))-1*(~a&(~y&z)),Timeout,5.0103161334991455 16 | -1*(((-10*(a&b)-17*(a&~b)+7*(a^b)+11*(a|~b)-11*~(a|b)-7*~(a|~b))&z)^((-10*(a&b)-17*(a&~b)+7*(a^b)+11*(a|~b)-11*~(a|b)-7*~(a|~b))^(y&z)))+2*(~((-10*(a&b)-17*(a&~b)+7*(a^b)+11*(a|~b)-11*~(a|b)-7*~(a|~b))&~y)&~(y^z))+1*((y&~z)^((-10*(a&b)-17*(a&~b)+7*(a^b)+11*(a|~b)-11*~(a|b)-7*~(a|~b))|(y^z)))+1*~(~(-10*(a&b)-17*(a&~b)+7*(a^b)+11*(a|~b)-11*~(a|b)-7*~(a|~b))|(~y|z))-1*(~(-10*(a&b)-17*(a&~b)+7*(a^b)+11*(a|~b)-11*~(a|b)-7*~(a|~b))&(~y&z))-1*(~(-10*(a&b)-17*(a&~b)+7*(a^b)+11*(a|~b)-11*~(a|b)-7*~(a|~b))&(y&z))-1*((-10*(a&b)-17*(a&~b)+7*(a^b)+11*(a|~b)-11*~(a|b)-7*~(a|~b))&(~y&z))-2*((-10*(a&b)-17*(a&~b)+7*(a^b)+11*(a|~b)-11*~(a|b)-7*~(a|~b))&(y&z)),2*~(a|(y|z)),Timeout,5.011632442474365 17 | -7*~((1*(a&b)+1*(a&~b)+5*b-5*~(a&~b)+5*~(a|b))&~z)-7*(~z&~((1*(a&b)+1*(a&~b)+5*b-5*~(a&~b)+5*~(a|b))^y))+3*(y^z)+14*~((1*(a&b)+1*(a&~b)+5*b-5*~(a&~b)+5*~(a|b))|(y|z))+4*~((1*(a&b)+1*(a&~b)+5*b-5*~(a&~b)+5*~(a|b))|(~y|z))+4*~(~(1*(a&b)+1*(a&~b)+5*b-5*~(a&~b)+5*~(a|b))|(~y|z))+7*(~(1*(a&b)+1*(a&~b)+5*b-5*~(a&~b)+5*~(a|b))&(y&z))+4*((1*(a&b)+1*(a&~b)+5*b-5*~(a&~b)+5*~(a|b))&(~y&z))+7*((1*(a&b)+1*(a&~b)+5*b-5*~(a&~b)+5*~(a|b))&(y&z)),-4*(~a&(~y&z)),Timeout,5.0098865032196045 18 | -2*(~((3*(a&b)+8*(a&~b)+5*b-7*~(a&~a)+7*~(a|b)+2*~(a|~b))|~y)|(y^z))-2*(((3*(a&b)+8*(a&~b)+5*b-7*~(a&~a)+7*~(a|b)+2*~(a|~b))&y)^~((3*(a&b)+8*(a&~b)+5*b-7*~(a&~a)+7*~(a|b)+2*~(a|~b))^(~y|z)))+2*(~((3*(a&b)+8*(a&~b)+5*b-7*~(a&~a)+7*~(a|b)+2*~(a|~b))^y)|~((3*(a&b)+8*(a&~b)+5*b-7*~(a&~a)+7*~(a|b)+2*~(a|~b))^z))+3*(z^(~(3*(a&b)+8*(a&~b)+5*b-7*~(a&~a)+7*~(a|b)+2*~(a|~b))&(y|z)))-2*~((3*(a&b)+8*(a&~b)+5*b-7*~(a&~a)+7*~(a|b)+2*~(a|~b))|(y|z))-1*~((3*(a&b)+8*(a&~b)+5*b-7*~(a&~a)+7*~(a|b)+2*~(a|~b))|(~y|z))+2*~(~(3*(a&b)+8*(a&~b)+5*b-7*~(a&~a)+7*~(a|b)+2*~(a|~b))|(~y|z))+2*(~(3*(a&b)+8*(a&~b)+5*b-7*~(a&~a)+7*~(a|b)+2*~(a|~b))&(y&z))-1*((3*(a&b)+8*(a&~b)+5*b-7*~(a&~a)+7*~(a|b)+2*~(a|~b))&(~y&z)),5*(a&(y&z))-2*~(~a|(y|z)),Timeout,5.009333848953247 19 | 7*~(~(-1*(a&~b)+1*(a|~b)+1*~(a&b)-2*~(a|b)-1*~(a|~b))|(~y&z))-7*(y^~((-1*(a&~b)+1*(a|~b)+1*~(a&b)-2*~(a|b)-1*~(a|~b))|z))-11*(~(-1*(a&~b)+1*(a|~b)+1*~(a&b)-2*~(a|b)-1*~(a|~b))|(~y|z))-6*((-1*(a&~b)+1*(a|~b)+1*~(a&b)-2*~(a|b)-1*~(a|~b))&(~y|z))+11*~((-1*(a&~b)+1*(a|~b)+1*~(a&b)-2*~(a|b)-1*~(a|~b))|(~y|z))+10*~(~(-1*(a&~b)+1*(a|~b)+1*~(a&b)-2*~(a|b)-1*~(a|~b))|(y|z))+18*(~(-1*(a&~b)+1*(a|~b)+1*~(a&b)-2*~(a|b)-1*~(a|~b))&(y&z))+17*((-1*(a&~b)+1*(a|~b)+1*~(a&b)-2*~(a|b)-1*~(a|~b))&(~y&z))+17*((-1*(a&~b)+1*(a|~b)+1*~(a&b)-2*~(a|b)-1*~(a|~b))&(y&z)),-18*~(a|(y|z))-11*(~a&(~y&z)),Timeout,5.010852098464966 20 | (x&~(y-1))*(x|~(y-1))+(x&~(~(y-1)))*(~x&~(y-1))+(x|~y)+2*y+4*x+(~(x&~y))+(~(x^y))+2*(~(x&~x))-5*(~(x|y))-6*(~(x|~y))-8*(x&~y)-12*(x&y),x*(-y)-(x|y),Timeout,5.013050079345703 21 | (x&~(y-1))*(x|~(y-1))+(x&~(~(y-1)))*(~x&~(y-1))-3*(~(x^y))-5*(x|y)-1*(~(x&y))-3*(~(x&~y))-1*(x^y)+(x|~y)-1*x+(~(x&~x))+4*(~(x|y))+8*(~(x|~y))+6*(x&~y)+10*(x&y),x*(-y)-~x,Timeout,5.010507106781006 22 | -------------------------------------------------------------------------------- /dataset/pldi_dataset_poly_MBA.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth 2 | (x&y)*(x|y)+(x&~y)*(~x&y)-41,x*y-41 3 | (x&y)*(x|y)+(x&~y)*(~x&y)-253,x*y-253 4 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*~x+1*(x|~y)-1*~(x|~y)-3*(x&~y),x*y+1*(x&y)-2*(x^y) 5 | (x&y)*(x|y)+(x&~y)*(~x&y)+5*~y-11*(x|~y)+6*~(x|y)+8*(x&~y),x*y-13*(x&y)+2*x 6 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*y+2*~(x&y)-2*(x^y)+1*(x&y),x*y-3*~(x|~y)+2*~x 7 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*~(x&y)-11*~(x^y)+12*~(x|y)+1*~(x|~y)+11*(x&y),x*y+2*~x+1*(x&~y) 8 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*~x+5*x-2*~(x^y)+13*~(x|y)+11*~(x|~y),x*y+5*(x&~y)+3*(x&y) 9 | (x&y)*(x|y)+(x&~y)*(~x&y)-2*~(x&~x)+2*y+3*~(x|y)+1*~(x|~y)+2*(x&~y),x*y+1*~x 10 | (x&y)*(x|y)+(x&~y)*(~x&y)+11*(x|~y)+3*~(x&~x)+5*~(x&y)-19*(x&~y)-14*(x&y),x*y+19*~(x|y)+8*~(x|~y) 11 | (x&y)*(x|y)+(x&~y)*(~x&y)+7*~y+4*~(x&y)+11*~(x&~x)-22*~(x|y)-11*(x&y),x*y+15*~(x|~y)+22*(x&~y) 12 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*(x|~y)-3*~y+2*x+14*~(x|y)+12*(x&~y),x*y-9*(x&y) 13 | (x&y)*(x|y)+(x&~y)*(~x&y)+2*(x|y)-4*~(x|y)-2*~(x|~y)-1*(x&~y)-7*(x&y),x*y-5*~(x^y)+1*~y 14 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*~y+1*y+3*~(x|y)+3*(x&~y)+1*(x&y),x*y-1*~(x|~y)+2*~(x&~x) 15 | (x&y)*(x|y)+(x&~y)*(~x&y)+2*~(x&~y)-5*~(x&y)-1*x+5*~(x|y)+3*~(x|~y)+1*(x&y),x*y-6*(x&~y)+2*~(x^y) 16 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(y^~(~x|(~y&z)))-1*(y^~(x|~z))+1*~(x|(~y|z))+1*~(~x|(~y|z))+1*(x&(~y&z))+1*(x&(y&z)),x*y+1*(x^y)-1*(~x&(~y&z)) 17 | (x&y)*(x|y)+(x&~y)*(~x&y)+4*(y&z)-1*~(x^y)+2*(~x|(y&z))-1*~(x|(y|z))-2*~(x|(~y|z))+1*~(~x|(~y|z))-1*(~x&(~y&z)),x*y+6*(~x&(y&z))+5*(x&(y&z)) 18 | (x&y)*(x|y)+(x&~y)*(~x&y)+3*(z^(~x|(y&z)))-11*(y&~(x&z))+4*(z^(~x|(y|z)))-7*~(x|(y|z))+4*~(x|(~y|z))+7*~(~x|(~y|z))+11*(~x&(y&z)),x*y+3*(x&(~y&z)) 19 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(z^~(x&(y&z)))-2*((x|~y)&~(y^z))+1*~(x|(y|z))-1*~(x|(~y|z))-10*~(~x|(y|z))-12*~(~x|(~y|z))-11*(~x&(y&z))-10*(x&(y&z)),x*y-11*((x&z)^(x^(y&z))) 20 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*((y&~z)|~(~x|(~y&z)))+4*(z^~(~x|(y&z)))+11*~(x|(~y|z))+7*~(~x|(y|z))+6*~(~x|(~y|z))-4*(~x&(y&z))-1*(x&(~y&z))+7*(x&(y&z)),x*y-1*(x&(y^z))+4*(~x&(~y&z)) 21 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(y^~(~x|(y^z)))+2*(y^~(x|~z))+1*((x&y)^(y|~z))-1*~(x|(y|z))-4*~(x|(~y|z))-3*~(~x|(~y|z))-2*(~x&(~y&z))-2*(~x&(y&z)),x*y+2*(x&(y&z))+2*~(~x|(y|z)) 22 | (x&y)*(x|y)+(x&~y)*(~x&y)+11*(y^(~x|(y^z)))-7*(x^y)+1*(z^~(~x&(y|z)))-1*(~x|(y|z))-2*(~(x&~y)&(x^(y^z)))+1*(~z|~(x^y))+1*(y^~(x&(y^z)))+3*~(x&(y|z))-2*(~(x&y)&~(x^(y^z)))-5*~(~x&(~y|z))+1*((x&z)^~(x^(y&z)))+7*(x|~y)+5*(y^~(x&~z))-3*(~(x|y)|(y^z))+11*(~z|(x^y))-1*((x&~y)|(y^z))-11*~(x&(y&z))+14*~(x|(~y|z))-5*~(~x|(~y|z))-12*(~x&(~y&z))+6*(~x&(y&z))-5*(x&(~y&z))-11*(x&(y&z)),x*y+24*~(x|(y|z)) 23 | -------------------------------------------------------------------------------- /dataset/pldi_dataset_poly_MBA.txt.simplify.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,simplifiedcomplex,simplifiedgroundtruth,z3flag,simtime 2 | (x&y)*(x|y)+(x&~y)*(~x&y)-41,x*y-41,x*y+41*~(x&~x),x*y+41*~(x&~x),True,0.5204839706420898 3 | (x&y)*(x|y)+(x&~y)*(~x&y)-253,x*y-253,x*y+253*~(x&~x),x*y+253*~(x&~x),True,0.03568553924560547 4 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*~x+1*(x|~y)-1*~(x|~y)-3*(x&~y),x*y+1*(x&y)-2*(x^y),x*y+3*x+3*y-5*(x|y),x*y+3*x+3*y-5*(x|y),True,0.05966973304748535 5 | (x&y)*(x|y)+(x&~y)*(~x&y)+5*~y-11*(x|~y)+6*~(x|y)+8*(x&~y),x*y-13*(x&y)+2*x,x*y-11*x-13*y+13*(x|y),x*y-11*x-13*y+13*(x|y),True,0.05811810493469238 6 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*y+2*~(x&y)-2*(x^y)+1*(x&y),x*y-3*~(x|~y)+2*~x,x*y+x-3*(x|y)+2*~(x&~x),x*y+x-3*(x|y)+2*~(x&~x),True,0.04904937744140625 7 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*~(x&y)-11*~(x^y)+12*~(x|y)+1*~(x|~y)+11*(x&y),x*y+2*~x+1*(x&~y),x*y-2*x-y+(x|y)+2*~(x&~x),x*y-2*x-y+(x|y)+2*~(x&~x),True,0.071502685546875 8 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*~x+5*x-2*~(x^y)+13*~(x|y)+11*~(x|~y),x*y+5*(x&~y)+3*(x&y),x*y+3*x-2*y+2*(x|y),x*y+3*x-2*y+2*(x|y),True,0.05661463737487793 9 | (x&y)*(x|y)+(x&~y)*(~x&y)-2*~(x&~x)+2*y+3*~(x|y)+1*~(x|~y)+2*(x&~y),x*y+1*~x,x*y-x+~(x&~x),x*y-x+~(x&~x),True,0.045102834701538086 10 | (x&y)*(x|y)+(x&~y)*(~x&y)+11*(x|~y)+3*~(x&~x)+5*~(x&y)-19*(x&~y)-14*(x&y),x*y+19*~(x|y)+8*~(x|~y),x*y-8*x-11*(x|y)+19*~(x&~x),x*y-8*x-11*(x|y)+19*~(x&~x),True,0.0661630630493164 11 | (x&y)*(x|y)+(x&~y)*(~x&y)+7*~y+4*~(x&y)+11*~(x&~x)-22*~(x|y)-11*(x&y),x*y+15*~(x|~y)+22*(x&~y),x*y-15*x-22*y+37*(x|y),x*y-15*x-22*y+37*(x|y),True,0.058561086654663086 12 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*(x|~y)-3*~y+2*x+14*~(x|y)+12*(x&~y),x*y-9*(x&y),x*y-9*x-9*y+9*(x|y),x*y-9*x-9*y+9*(x|y),True,0.05002331733703613 13 | (x&y)*(x|y)+(x&~y)*(~x&y)+2*(x|y)-4*~(x|y)-2*~(x|~y)-1*(x&~y)-7*(x&y),x*y-5*~(x^y)+1*~y,x*y-5*x-6*y+10*(x|y)-4*~(x&~x),x*y-5*x-6*y+10*(x|y)-4*~(x&~x),True,0.07141613960266113 14 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*~y+1*y+3*~(x|y)+3*(x&~y)+1*(x&y),x*y-1*~(x|~y)+2*~(x&~x),x*y+x-(x|y)+2*~(x&~x),x*y+x-(x|y)+2*~(x&~x),True,0.044994354248046875 15 | (x&y)*(x|y)+(x&~y)*(~x&y)+2*~(x&~y)-5*~(x&y)-1*x+5*~(x|y)+3*~(x|~y)+1*(x&y),x*y-6*(x&~y)+2*~(x^y),x*y+2*x+8*y-10*(x|y)+2*~(x&~x),x*y+2*x+8*y-10*(x|y)+2*~(x&~x),True,0.06714129447937012 16 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(y^~(~x|(~y&z)))-1*(y^~(x|~z))+1*~(x|(~y|z))+1*~(~x|(~y|z))+1*(x&(~y&z))+1*(x&(y&z)),x*y+1*(x^y)-1*(~x&(~y&z)),x*y+x+y-z-2*(x&y)+(y&z)+(x&z)-(x&y&z),x*y+x+y-z-2*(x&y)+(y&z)+(x&z)-(x&y&z),True,0.0675041675567627 17 | (x&y)*(x|y)+(x&~y)*(~x&y)+4*(y&z)-1*~(x^y)+2*(~x|(y&z))-1*~(x|(y|z))-2*~(x|(~y|z))+1*~(~x|(~y|z))-1*(~x&(~y&z)),x*y+6*(~x&(y&z))+5*(x&(y&z)),x*y+6*(y&z)-(x&y&z),x*y+6*(y&z)-(x&y&z),True,0.04415774345397949 18 | (x&y)*(x|y)+(x&~y)*(~x&y)+3*(z^(~x|(y&z)))-11*(y&~(x&z))+4*(z^(~x|(y|z)))-7*~(x|(y|z))+4*~(x|(~y|z))+7*~(~x|(~y|z))+11*(~x&(y&z)),x*y+3*(x&(~y&z)),x*y+3*(x&z)-3*(x&y&z),x*y+3*(x&z)-3*(x&y&z),True,0.045854806900024414 19 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(z^~(x&(y&z)))-2*((x|~y)&~(y^z))+1*~(x|(y|z))-1*~(x|(~y|z))-10*~(~x|(y|z))-12*~(~x|(~y|z))-11*(~x&(y&z))-10*(x&(y&z)),x*y-11*((x&z)^(x^(y&z))),x*y-11*x-11*(y&z)+11*(x&z),x*y-11*x-11*(y&z)+11*(x&z),True,0.052782297134399414 20 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*((y&~z)|~(~x|(~y&z)))+4*(z^~(~x|(y&z)))+11*~(x|(~y|z))+7*~(~x|(y|z))+6*~(~x|(~y|z))-4*(~x&(y&z))-1*(x&(~y&z))+7*(x&(y&z)),x*y-1*(x&(y^z))+4*(~x&(~y&z)),x*y+4*z-(x&y)-4*(y&z)-5*(x&z)+6*(x&y&z),x*y+4*z-(x&y)-4*(y&z)-5*(x&z)+6*(x&y&z),True,0.07485461235046387 21 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(y^~(~x|(y^z)))+2*(y^~(x|~z))+1*((x&y)^(y|~z))-1*~(x|(y|z))-4*~(x|(~y|z))-3*~(~x|(~y|z))-2*(~x&(~y&z))-2*(~x&(y&z)),x*y+2*(x&(y&z))+2*~(~x|(y|z)),x*y+2*x-2*(x&y)-2*(x&z)+4*(x&y&z),x*y+2*x-2*(x&y)-2*(x&z)+4*(x&y&z),True,0.05471205711364746 22 | (x&y)*(x|y)+(x&~y)*(~x&y)+11*(y^(~x|(y^z)))-7*(x^y)+1*(z^~(~x&(y|z)))-1*(~x|(y|z))-2*(~(x&~y)&(x^(y^z)))+1*(~z|~(x^y))+1*(y^~(x&(y^z)))+3*~(x&(y|z))-2*(~(x&y)&~(x^(y^z)))-5*~(~x&(~y|z))+1*((x&z)^~(x^(y&z)))+7*(x|~y)+5*(y^~(x&~z))-3*(~(x|y)|(y^z))+11*(~z|(x^y))-1*((x&~y)|(y^z))-11*~(x&(y&z))+14*~(x|(~y|z))-5*~(~x|(~y|z))-12*(~x&(~y&z))+6*(~x&(y&z))-5*(x&(~y&z))-11*(x&(y&z)),x*y+24*~(x|(y|z)),x*y-24*x-24*y-24*z+24*(x&y)+24*(y&z)+24*(x&z)-24*(x&y&z)+24*~(x&~x),x*y-24*x-24*y-24*z+24*(x&y)+24*(y&z)+24*(x&z)-24*(x&y&z)+24*~(x&~x),True,0.09815120697021484 23 | -------------------------------------------------------------------------------- /dataset/pldi_dataset_poly_MBA.txt.simplify.txt.z3.verify.64bit.after.simplify.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,simcomplex,simground,z3res,verificationtime 2 | (x&y)*(x|y)+(x&~y)*(~x&y)-41,x*y-41,x*y+41*~(x&~x),x*y+41*~(x&~x),True,0.02458500862121582 3 | (x&y)*(x|y)+(x&~y)*(~x&y)-253,x*y-253,x*y+253*~(x&~x),x*y+253*~(x&~x),True,0.02291560173034668 4 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*~x+1*(x|~y)-1*~(x|~y)-3*(x&~y),x*y+1*(x&y)-2*(x^y),x*y+3*x+3*y-5*(x|y),x*y+3*x+3*y-5*(x|y),True,0.025364160537719727 5 | (x&y)*(x|y)+(x&~y)*(~x&y)+5*~y-11*(x|~y)+6*~(x|y)+8*(x&~y),x*y-13*(x&y)+2*x,x*y-11*x-13*y+13*(x|y),x*y-11*x-13*y+13*(x|y),True,0.024629592895507812 6 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*y+2*~(x&y)-2*(x^y)+1*(x&y),x*y-3*~(x|~y)+2*~x,x*y+x-3*(x|y)+2*~(x&~x),x*y+x-3*(x|y)+2*~(x&~x),True,0.023906230926513672 7 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*~(x&y)-11*~(x^y)+12*~(x|y)+1*~(x|~y)+11*(x&y),x*y+2*~x+1*(x&~y),x*y-2*x-y+(x|y)+2*~(x&~x),x*y-2*x-y+(x|y)+2*~(x&~x),True,0.025180816650390625 8 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*~x+5*x-2*~(x^y)+13*~(x|y)+11*~(x|~y),x*y+5*(x&~y)+3*(x&y),x*y+3*x-2*y+2*(x|y),x*y+3*x-2*y+2*(x|y),True,0.02537250518798828 9 | (x&y)*(x|y)+(x&~y)*(~x&y)-2*~(x&~x)+2*y+3*~(x|y)+1*~(x|~y)+2*(x&~y),x*y+1*~x,x*y-x+~(x&~x),x*y-x+~(x&~x),True,0.027803897857666016 10 | (x&y)*(x|y)+(x&~y)*(~x&y)+11*(x|~y)+3*~(x&~x)+5*~(x&y)-19*(x&~y)-14*(x&y),x*y+19*~(x|y)+8*~(x|~y),x*y-8*x-11*(x|y)+19*~(x&~x),x*y-8*x-11*(x|y)+19*~(x&~x),True,0.024382591247558594 11 | (x&y)*(x|y)+(x&~y)*(~x&y)+7*~y+4*~(x&y)+11*~(x&~x)-22*~(x|y)-11*(x&y),x*y+15*~(x|~y)+22*(x&~y),x*y-15*x-22*y+37*(x|y),x*y-15*x-22*y+37*(x|y),True,0.029717683792114258 12 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*(x|~y)-3*~y+2*x+14*~(x|y)+12*(x&~y),x*y-9*(x&y),x*y-9*x-9*y+9*(x|y),x*y-9*x-9*y+9*(x|y),True,0.025109291076660156 13 | (x&y)*(x|y)+(x&~y)*(~x&y)+2*(x|y)-4*~(x|y)-2*~(x|~y)-1*(x&~y)-7*(x&y),x*y-5*~(x^y)+1*~y,x*y-5*x-6*y+10*(x|y)-4*~(x&~x),x*y-5*x-6*y+10*(x|y)-4*~(x&~x),True,0.024605751037597656 14 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*~y+1*y+3*~(x|y)+3*(x&~y)+1*(x&y),x*y-1*~(x|~y)+2*~(x&~x),x*y+x-(x|y)+2*~(x&~x),x*y+x-(x|y)+2*~(x&~x),True,0.023714542388916016 15 | (x&y)*(x|y)+(x&~y)*(~x&y)+2*~(x&~y)-5*~(x&y)-1*x+5*~(x|y)+3*~(x|~y)+1*(x&y),x*y-6*(x&~y)+2*~(x^y),x*y+2*x+8*y-10*(x|y)+2*~(x&~x),x*y+2*x+8*y-10*(x|y)+2*~(x&~x),True,0.03356504440307617 16 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(y^~(~x|(~y&z)))-1*(y^~(x|~z))+1*~(x|(~y|z))+1*~(~x|(~y|z))+1*(x&(~y&z))+1*(x&(y&z)),x*y+1*(x^y)-1*(~x&(~y&z)),x*y+x+y-z-2*(x&y)+(y&z)+(x&z)-(x&y&z),x*y+x+y-z-2*(x&y)+(y&z)+(x&z)-(x&y&z),True,0.025049448013305664 17 | (x&y)*(x|y)+(x&~y)*(~x&y)+4*(y&z)-1*~(x^y)+2*(~x|(y&z))-1*~(x|(y|z))-2*~(x|(~y|z))+1*~(~x|(~y|z))-1*(~x&(~y&z)),x*y+6*(~x&(y&z))+5*(x&(y&z)),x*y+6*(y&z)-(x&y&z),x*y+6*(y&z)-(x&y&z),True,0.024612903594970703 18 | (x&y)*(x|y)+(x&~y)*(~x&y)+3*(z^(~x|(y&z)))-11*(y&~(x&z))+4*(z^(~x|(y|z)))-7*~(x|(y|z))+4*~(x|(~y|z))+7*~(~x|(~y|z))+11*(~x&(y&z)),x*y+3*(x&(~y&z)),x*y+3*(x&z)-3*(x&y&z),x*y+3*(x&z)-3*(x&y&z),True,0.024043798446655273 19 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(z^~(x&(y&z)))-2*((x|~y)&~(y^z))+1*~(x|(y|z))-1*~(x|(~y|z))-10*~(~x|(y|z))-12*~(~x|(~y|z))-11*(~x&(y&z))-10*(x&(y&z)),x*y-11*((x&z)^(x^(y&z))),x*y-11*x-11*(y&z)+11*(x&z),x*y-11*x-11*(y&z)+11*(x&z),True,0.024516820907592773 20 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*((y&~z)|~(~x|(~y&z)))+4*(z^~(~x|(y&z)))+11*~(x|(~y|z))+7*~(~x|(y|z))+6*~(~x|(~y|z))-4*(~x&(y&z))-1*(x&(~y&z))+7*(x&(y&z)),x*y-1*(x&(y^z))+4*(~x&(~y&z)),x*y+4*z-(x&y)-4*(y&z)-5*(x&z)+6*(x&y&z),x*y+4*z-(x&y)-4*(y&z)-5*(x&z)+6*(x&y&z),True,0.02718973159790039 21 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(y^~(~x|(y^z)))+2*(y^~(x|~z))+1*((x&y)^(y|~z))-1*~(x|(y|z))-4*~(x|(~y|z))-3*~(~x|(~y|z))-2*(~x&(~y&z))-2*(~x&(y&z)),x*y+2*(x&(y&z))+2*~(~x|(y|z)),x*y+2*x-2*(x&y)-2*(x&z)+4*(x&y&z),x*y+2*x-2*(x&y)-2*(x&z)+4*(x&y&z),True,0.025650978088378906 22 | (x&y)*(x|y)+(x&~y)*(~x&y)+11*(y^(~x|(y^z)))-7*(x^y)+1*(z^~(~x&(y|z)))-1*(~x|(y|z))-2*(~(x&~y)&(x^(y^z)))+1*(~z|~(x^y))+1*(y^~(x&(y^z)))+3*~(x&(y|z))-2*(~(x&y)&~(x^(y^z)))-5*~(~x&(~y|z))+1*((x&z)^~(x^(y&z)))+7*(x|~y)+5*(y^~(x&~z))-3*(~(x|y)|(y^z))+11*(~z|(x^y))-1*((x&~y)|(y^z))-11*~(x&(y&z))+14*~(x|(~y|z))-5*~(~x|(~y|z))-12*(~x&(~y&z))+6*(~x&(y&z))-5*(x&(~y&z))-11*(x&(y&z)),x*y+24*~(x|(y|z)),x*y-24*x-24*y-24*z+24*(x&y)+24*(y&z)+24*(x&z)-24*(x&y&z)+24*~(x&~x),x*y-24*x-24*y-24*z+24*(x&y)+24*(y&z)+24*(x&z)-24*(x&y&z)+24*~(x&~x),True,0.028421640396118164 23 | -------------------------------------------------------------------------------- /dataset/pldi_dataset_poly_MBA.txt.z3.verify.64bit.before.simplify.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,z3res,verificationtime 2 | (x&y)*(x|y)+(x&~y)*(~x&y)-41,x*y-41,Timeout,5.016896724700928 3 | (x&y)*(x|y)+(x&~y)*(~x&y)-253,x*y-253,Timeout,5.011383295059204 4 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*~x+1*(x|~y)-1*~(x|~y)-3*(x&~y),x*y+1*(x&y)-2*(x^y),Timeout,5.011294841766357 5 | (x&y)*(x|y)+(x&~y)*(~x&y)+5*~y-11*(x|~y)+6*~(x|y)+8*(x&~y),x*y-13*(x&y)+2*x,Timeout,5.010409832000732 6 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*y+2*~(x&y)-2*(x^y)+1*(x&y),x*y-3*~(x|~y)+2*~x,Timeout,5.012860298156738 7 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*~(x&y)-11*~(x^y)+12*~(x|y)+1*~(x|~y)+11*(x&y),x*y+2*~x+1*(x&~y),Timeout,5.016038417816162 8 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*~x+5*x-2*~(x^y)+13*~(x|y)+11*~(x|~y),x*y+5*(x&~y)+3*(x&y),Timeout,5.012874126434326 9 | (x&y)*(x|y)+(x&~y)*(~x&y)-2*~(x&~x)+2*y+3*~(x|y)+1*~(x|~y)+2*(x&~y),x*y+1*~x,Timeout,5.007569789886475 10 | (x&y)*(x|y)+(x&~y)*(~x&y)+11*(x|~y)+3*~(x&~x)+5*~(x&y)-19*(x&~y)-14*(x&y),x*y+19*~(x|y)+8*~(x|~y),Timeout,5.00753378868103 11 | (x&y)*(x|y)+(x&~y)*(~x&y)+7*~y+4*~(x&y)+11*~(x&~x)-22*~(x|y)-11*(x&y),x*y+15*~(x|~y)+22*(x&~y),Timeout,5.0125133991241455 12 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*(x|~y)-3*~y+2*x+14*~(x|y)+12*(x&~y),x*y-9*(x&y),Timeout,5.012587070465088 13 | (x&y)*(x|y)+(x&~y)*(~x&y)+2*(x|y)-4*~(x|y)-2*~(x|~y)-1*(x&~y)-7*(x&y),x*y-5*~(x^y)+1*~y,Timeout,5.007381200790405 14 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*~y+1*y+3*~(x|y)+3*(x&~y)+1*(x&y),x*y-1*~(x|~y)+2*~(x&~x),Timeout,5.01177191734314 15 | (x&y)*(x|y)+(x&~y)*(~x&y)+2*~(x&~y)-5*~(x&y)-1*x+5*~(x|y)+3*~(x|~y)+1*(x&y),x*y-6*(x&~y)+2*~(x^y),Timeout,5.0114476680755615 16 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(y^~(~x|(~y&z)))-1*(y^~(x|~z))+1*~(x|(~y|z))+1*~(~x|(~y|z))+1*(x&(~y&z))+1*(x&(y&z)),x*y+1*(x^y)-1*(~x&(~y&z)),Timeout,5.0108819007873535 17 | (x&y)*(x|y)+(x&~y)*(~x&y)+4*(y&z)-1*~(x^y)+2*(~x|(y&z))-1*~(x|(y|z))-2*~(x|(~y|z))+1*~(~x|(~y|z))-1*(~x&(~y&z)),x*y+6*(~x&(y&z))+5*(x&(y&z)),Timeout,5.0070273876190186 18 | (x&y)*(x|y)+(x&~y)*(~x&y)+3*(z^(~x|(y&z)))-11*(y&~(x&z))+4*(z^(~x|(y|z)))-7*~(x|(y|z))+4*~(x|(~y|z))+7*~(~x|(~y|z))+11*(~x&(y&z)),x*y+3*(x&(~y&z)),Timeout,5.011311292648315 19 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(z^~(x&(y&z)))-2*((x|~y)&~(y^z))+1*~(x|(y|z))-1*~(x|(~y|z))-10*~(~x|(y|z))-12*~(~x|(~y|z))-11*(~x&(y&z))-10*(x&(y&z)),x*y-11*((x&z)^(x^(y&z))),Timeout,5.009489059448242 20 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*((y&~z)|~(~x|(~y&z)))+4*(z^~(~x|(y&z)))+11*~(x|(~y|z))+7*~(~x|(y|z))+6*~(~x|(~y|z))-4*(~x&(y&z))-1*(x&(~y&z))+7*(x&(y&z)),x*y-1*(x&(y^z))+4*(~x&(~y&z)),Timeout,5.012082099914551 21 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(y^~(~x|(y^z)))+2*(y^~(x|~z))+1*((x&y)^(y|~z))-1*~(x|(y|z))-4*~(x|(~y|z))-3*~(~x|(~y|z))-2*(~x&(~y&z))-2*(~x&(y&z)),x*y+2*(x&(y&z))+2*~(~x|(y|z)),Timeout,5.011809825897217 22 | (x&y)*(x|y)+(x&~y)*(~x&y)+11*(y^(~x|(y^z)))-7*(x^y)+1*(z^~(~x&(y|z)))-1*(~x|(y|z))-2*(~(x&~y)&(x^(y^z)))+1*(~z|~(x^y))+1*(y^~(x&(y^z)))+3*~(x&(y|z))-2*(~(x&y)&~(x^(y^z)))-5*~(~x&(~y|z))+1*((x&z)^~(x^(y&z)))+7*(x|~y)+5*(y^~(x&~z))-3*(~(x|y)|(y^z))+11*(~z|(x^y))-1*((x&~y)|(y^z))-11*~(x&(y&z))+14*~(x|(~y|z))-5*~(~x|(~y|z))-12*(~x&(~y&z))+6*(~x&(y&z))-5*(x&(~y&z))-11*(x&(y&z)),x*y+24*~(x|(y|z)),Timeout,5.030344724655151 23 | -------------------------------------------------------------------------------- /dataset/sub-dataset-generator.py: -------------------------------------------------------------------------------- 1 | #/usr/bin/python3 2 | 3 | 4 | def generate_sub_dataset(): 5 | """generate a sub-dataset of the entire dataset. 6 | """ 7 | linear_dataset = "../dataset/pldi_dataset_linear_MBA.txt" 8 | poly_dataset = "../dataset/pldi_dataset_poly_MBA.txt" 9 | nonpoly_dataset = "../dataset/pldi_dataset_nonpoly_MBA.txt" 10 | 11 | datasets = [linear_dataset, poly_dataset, nonpoly_dataset] 12 | subNameList = ["pldi_dataset_linear_MBA.txt", "pldi_dataset_poly_MBA.txt", "pldi_dataset_nonpoly_MBA.txt"] 13 | for (i, dataset) in enumerate(datasets): 14 | linenum = 0 15 | fw = open(subNameList[i], "w") 16 | print("#complex,groundtruth", file=fw) 17 | with open(dataset, "r") as fr: 18 | for line in fr: 19 | if "#" not in line: 20 | linenum += 1 21 | if linenum % 50 == 3: 22 | print(line, end="", file=fw) 23 | 24 | fw.close() 25 | 26 | return None 27 | 28 | if __name__ == "__main__": 29 | generate_sub_dataset() 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /full-dataset/pldi_dataset_linear_MBA.txt.boolector.verify.64bit.before.simplify.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,boolectorres,verificationtime 2 | -x-1,~x,True,0.000498056411743 3 | -(x&y)-(x&~y),-x,True,0.000665187835693 4 | (x|y)+y-(~x&y),x+y,True,0.0560688972473 5 | (x|y)+3*~(x|y)-2*~(x^y)-~(x&y),-(x&y),True,0.460586071014 6 | x+y-(x&y),x|y,True,0.000893831253052 7 | -~(x&y)+(~x|y)+(x&~y),x&y,True,0.0530490875244 8 | -------------------------------------------------------------------------------- /full-dataset/pldi_dataset_linear_MBA.txt.stp.verify.64bit.before.simplify.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,stpres,verificationtime 2 | -x-1,~x,True,0.000393867492676 3 | -(x&y)-(x&~y),-x,True,0.0103130340576 4 | (x|y)+y-(~x&y),x+y,True,0.0138099193573 5 | (x|y)+3*~(x|y)-2*~(x^y)-~(x&y),-(x&y),True,0.758054971695 6 | x+y-(x&y),x|y,True,0.0224099159241 7 | -~(x&y)+(~x|y)+(x&~y),x&y,True,0.0029399394989 8 | -------------------------------------------------------------------------------- /full-dataset/pldi_dataset_linear_MBA.txt.z3.verify.64bit.before.simplify.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,z3res,verificationtime 2 | -x-1,~x,True,0.011144161224365234 3 | -(x&y)-(x&~y),-x,True,0.01035928726196289 4 | (x|y)+y-(~x&y),x+y,True,0.026297569274902344 5 | -------------------------------------------------------------------------------- /full-dataset/pldi_dataset_poly_MBA.txt.boolector.verify.64bit.before.simplify.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softsec-unh/MBA-Solver/c76231aadb8b033d9e8e6be2baa05ff1464f247e/full-dataset/pldi_dataset_poly_MBA.txt.boolector.verify.64bit.before.simplify.txt -------------------------------------------------------------------------------- /full-dataset/pldi_dataset_poly_MBA.txt.stp.verify.64bit.before.simplify.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softsec-unh/MBA-Solver/c76231aadb8b033d9e8e6be2baa05ff1464f247e/full-dataset/pldi_dataset_poly_MBA.txt.stp.verify.64bit.before.simplify.txt -------------------------------------------------------------------------------- /full-dataset/pldi_dataset_poly_MBA.txt.z3.verify.64bit.before.simplify.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,z3res,verificationtime 2 | (x&y)*(x|y)+(x&~y)*(~x&y),x*y,False,13.843185186386108 3 | (x&x)*(x|x)+(x&~x)*(~x&x),x*x,True,0.010366201400756836 4 | (x&y)*(x|y)+(x&~y)*(~x&y)-41,x*y-41,False,2.078094720840454 5 | (x&y)*(x|y)+(x&~y)*(~x&y)-165,x*y-165,False,1.6393213272094727 6 | (x&y)*(x|y)+(x&~y)*(~x&y)-113,x*y-113,False,1.00537109375 7 | (x&y)*(x|y)+(x&~y)*(~x&y)+35,x*y+35,False,0.46757054328918457 8 | (x&y)*(x|y)+(x&~y)*(~x&y)+237,x*y+237,False,0.8047294616699219 9 | (x&y)*(x|y)+(x&~y)*(~x&y)-101,x*y-101,False,0.2569258213043213 10 | (x&y)*(x|y)+(x&~y)*(~x&y)+46,x*y+46,False,0.19785714149475098 11 | (x&y)*(x|y)+(x&~y)*(~x&y)-129,x*y-129,False,0.32764530181884766 12 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MBA-Solver is free software: you can redistribute it and/or modify 2 | it under the terms of the GNU General Public License as published by 3 | the Free Software Foundation, either version 3 of the License, or 4 | (at your option) any later version. 5 | 6 | MBA-Solver is distributed in the hope that it will be useful, 7 | but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | GNU General Public License for more details. 10 | 11 | You should have received a copy of the GNU General Public License 12 | along with MBA-Solver. If not, see . -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | quick-demo: z3-solving-original mba-solver-simplify-mba z3-solving-mba-solver-simplify 2 | 3 | boolector: boolector-solving-original boolector-solving-mba-solver-simplify boolector-solving-sspam-simplify boolector-solving-syntia-simplify 4 | 5 | stp: stp-solving-original stp-solving-mba-solver-simplify stp-solving-sspam-simplify stp-solving-syntia-simplify 6 | 7 | z3: z3-solving-original z3-solving-mba-solver-simplify z3-solving-sspam-simplify z3-solving-syntia-simplify 8 | 9 | boolector-solving-original: 10 | @cd boolector_solving && make boolector-solving-before-simplify 11 | boolector-solving-mba-solver-simplify: 12 | @cd boolector_solving && make boolector-solving-mba-solver 13 | boolector-solving-sspam-simplify: 14 | @cd boolector_solving && make boolector-solving-sspam 15 | boolector-solving-syntia-simplify: 16 | @cd boolector_solving && make boolector-solving-syntia 17 | 18 | stp-solving-original: 19 | @cd stp_solving && make stp-solving-before-simplify 20 | stp-solving-mba-solver-simplify: 21 | @cd stp_solving && make stp-solving-mba-solver 22 | stp-solving-sspam-simplify: 23 | @cd stp_solving && make stp-solving-sspam 24 | stp-solving-syntia-simplify: 25 | @cd stp_solving && make stp-solving-syntia 26 | 27 | z3-solving-original: 28 | @cd z3_solving && make z3-solving-before-simplify 29 | z3-solving-mba-solver-simplify: 30 | @cd z3_solving && make z3-solving-mba-solver 31 | z3-solving-sspam-simplify: 32 | @cd z3_solving && make z3-solving-sspam 33 | z3-solving-syntia-simplify: 34 | @cd z3_solving && make z3-solving-syntia 35 | 36 | mba-solver-simplify-mba: 37 | @cd ./mba-simplifier && make mba-solver-simplify 38 | 39 | sspam-simplify-mba: 40 | @cd ./sspam && make sspam-simplify 41 | 42 | syntia-simplify-mba: 43 | @cd ./syntia && make syntia-simplify 44 | -------------------------------------------------------------------------------- /mba-simplifier/makefile: -------------------------------------------------------------------------------- 1 | linear-simplify: 2 | python3 pldi_dataset_simplify_linear.py ../dataset/pldi_dataset_linear_MBA.txt 3 | 4 | poly-simplify: 5 | python3 pldi_dataset_simplify_poly.py ../dataset/pldi_dataset_poly_MBA.txt 6 | 7 | nonpoly-simplify: 8 | python3 pldi_dataset_simplify_nonpoly.py ../dataset/pldi_dataset_nonpoly_MBA.txt 9 | 10 | mba-solver-simplify: 11 | @echo "-----------MBA-Solver simplify linear MBA samples------------------" 12 | @make linear-simplify 13 | @echo "-----------MBA-Solver simplify linear MBA samples completion-------" 14 | @echo "-----------MBA-Solver simplify poly MBA samples--------------------" 15 | @make poly-simplify 16 | @echo "-----------MBA-Solver simplify poly MBA samples completion---------" 17 | @echo "-----------MBA-Solver simplify nonpoly MBA samples-----------------" 18 | @make nonpoly-simplify 19 | @echo "-----------MBA-Solver simplify nonpoly MBA samples completion------" 20 | -------------------------------------------------------------------------------- /mba-simplifier/pldi_dataset_simplify_linear.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | 5 | import re 6 | import sys 7 | sys.path.append("../tools") 8 | import time 9 | from mba_string_operation import verify_mba_unsat, variable_list 10 | from svector_simplify import SvectorSimplify 11 | from truthtable_search_simplify import PMBASimplify 12 | 13 | 14 | 15 | def simplify_lmba(datafile): 16 | """simplify linear mba expression by the signatrue vector. 17 | Args: 18 | datafile: file storing the original mba expression. 19 | """ 20 | filewrite = "{source}.simplify.txt".format(source=datafile) 21 | 22 | fw = open(filewrite, "w") 23 | print("#complex,groundtruth,simplifiedcomplex,simplifiedgroundtruth,z3flag,simtime", file=fw) 24 | 25 | svObj = SvectorSimplify() 26 | linenum = 0 27 | with open(datafile, "rt") as fr: 28 | for line in fr: 29 | if "#" not in line: 30 | linenum += 1 31 | line = line.strip() 32 | itemList = re.split(",", line) 33 | cmbaExpre = itemList[0] 34 | groundtruth = itemList[1] 35 | vnumber = len(variable_list(cmbaExpre)) 36 | start = time.time() 37 | simExpre1 = svObj.standard_simplify(cmbaExpre, vnumber) 38 | simExpre2 = svObj.standard_simplify(groundtruth, vnumber) 39 | elapsed = time.time() - start 40 | print("z3 solving...") 41 | #z3res = verify_mba_unsat(groundtruth, simExpre) 42 | z3res = verify_mba_unsat(simExpre1, simExpre2, 2) 43 | print(linenum, cmbaExpre, groundtruth, simExpre1, simExpre2, z3res) 44 | print("z3 solved: ", z3res) 45 | print(cmbaExpre, groundtruth, simExpre1, simExpre2, z3res, elapsed, sep=",", file=fw) 46 | 47 | fw.close() 48 | return None 49 | 50 | 51 | 52 | 53 | def main(fileread): 54 | simplify_lmba(fileread) 55 | 56 | return None 57 | 58 | 59 | 60 | if __name__ == "__main__": 61 | fileread = sys.argv[1] 62 | main(fileread) 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /mba-simplifier/pldi_dataset_simplify_nonpoly.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | 5 | import re 6 | import sys 7 | sys.path.append("../tools") 8 | import time 9 | from mba_string_operation import verify_mba_unsat, variable_list, expression_2_term 10 | from svector_simplify import SvectorSimplify 11 | from truthtable_search_simplify import PMBASimplify 12 | 13 | 14 | def simplify_pmba(mbaExpre): 15 | """ 16 | """ 17 | basisVec = ["x", "y", "(x|y)", "~(x&~x)"] 18 | vnumber = 2 19 | if re.search("z", mbaExpre): 20 | basisVec = ["x", "y", "z", "(x&y)", "(y&z)", "(x&z)", "(x&y&z)", "~(x&~x)"] 21 | vnumber = 3 22 | psObj = PMBASimplify(vnumber, basisVec) 23 | simExpre = psObj.simplify(mbaExpre) 24 | z3res = verify_mba_unsat(simExpre, mbaExpre, 2) 25 | if z3res: 26 | return simExpre 27 | else: 28 | print("error in simplify_pmba") 29 | 30 | 31 | 32 | def simplify_npmba(datafile): 33 | """simplify nonpoly mba expression by the signatrue vector. 34 | Args: 35 | datafile: file storing the original mba expression. 36 | """ 37 | filewrite = "{source}.simplify.txt".format(source=datafile) 38 | 39 | fw = open(filewrite, "w") 40 | print("#complex,groundtruth,simplifiedcomplex,simplifiedgroundtruth,z3flag,simtime", file=fw) 41 | 42 | linenum = 0 43 | with open(datafile, "rt") as fr: 44 | for line in fr: 45 | if "#" not in line: 46 | linenum += 1 47 | line = line.strip() 48 | itemList = re.split(",", line) 49 | cmbaExpre = itemList[0] 50 | groundtruth = itemList[1] 51 | 52 | #cannot simplify 53 | if len(itemList) < 3: 54 | start = time.time() 55 | cmbaSimExpre = cmbaExpre 56 | #print("z3 solving: ") 57 | z3res = verify_mba_unsat(cmbaSimExpre, groundtruth, 2) 58 | elapsed = time.time() - start 59 | #print("z3 solved: ", z3res) 60 | if z3res: 61 | print("MBA Solver cannot process: unkown expression") 62 | print(linenum, cmbaExpre, groundtruth, cmbaSimExpre, groundtruth, "unknown") 63 | print(cmbaExpre, groundtruth, cmbaSimExpre, groundtruth, "unknown", elapsed, sep=",",file=fw) 64 | else: 65 | print("error in simplify_npmba") 66 | exit(1) 67 | continue 68 | #can simplify 69 | subExpre = itemList[2] 70 | start = time.time() 71 | #process complex MBA expression 72 | if re.search("x", cmbaExpre): 73 | #process sub-expression 74 | subExpre1 = subExpre.replace("a", "x").replace("b", "y")[1:-1] 75 | subSimExpre = simplify_pmba(subExpre1) 76 | subSimExpre = subSimExpre.replace("x", "a").replace("y", "b") 77 | #replace the sub expression with y variable 78 | cmbaExpre1 = cmbaExpre.replace(subExpre, "y") 79 | cmbaSimExpre = simplify_pmba(cmbaExpre1) 80 | #replace the "y" variable with subSimExpre 81 | cmbaSimExpre = cmbaSimExpre.replace("y", subSimExpre) 82 | elif re.search("y", cmbaExpre): 83 | #process sub-expression 84 | subExpre1 = subExpre.replace("a", "x").replace("b", "y")[1:-1] 85 | subSimExpre = simplify_pmba(subExpre1) 86 | subSimExpre = subSimExpre.replace("x", "a").replace("y", "b") 87 | #replace the sub expression with x variable 88 | cmbaExpre1 = cmbaExpre.replace(subExpre, "x") 89 | cmbaSimExpre = simplify_pmba(cmbaExpre1) 90 | #replace the "y" variable with subSimExpre 91 | cmbaSimExpre = cmbaSimExpre.replace("x", subSimExpre) 92 | #process ground truth 93 | if re.search("x", groundtruth): 94 | groundtruthSim = groundtruth.replace("b", "y") 95 | groundtruthSim = simplify_pmba(groundtruthSim) 96 | groundtruthSim = groundtruthSim.replace("y", "b") 97 | elif re.search("y", cmbaExpre): 98 | groundtruthSim = groundtruth.replace("a", "x") 99 | groundtruthSim = simplify_pmba(groundtruthSim) 100 | groundtruthSim = groundtruthSim.replace("x", "a") 101 | 102 | elapsed = time.time() - start 103 | print("z3 solving: ") 104 | z3res = verify_mba_unsat(cmbaSimExpre, groundtruth, 2) 105 | print("z3 solved: ", z3res) 106 | if z3res: 107 | print(linenum, cmbaExpre, groundtruth, cmbaSimExpre, groundtruthSim, z3res) 108 | print(cmbaExpre, groundtruth, cmbaSimExpre, groundtruthSim, z3res, elapsed, sep=",",file=fw) 109 | else: 110 | print("error in simplify_npmba") 111 | exit(1) 112 | 113 | fw.close() 114 | return None 115 | 116 | 117 | 118 | def main(fileread): 119 | simplify_npmba(fileread) 120 | 121 | return None 122 | 123 | 124 | 125 | if __name__ == "__main__": 126 | fileread = sys.argv[1] 127 | main(fileread) 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /mba-simplifier/pldi_dataset_simplify_poly.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | 5 | import re 6 | import sys 7 | sys.path.append("../tools") 8 | import time 9 | from mba_string_operation import verify_mba_unsat, variable_list, expression_2_term 10 | from svector_simplify import SvectorSimplify 11 | from truthtable_search_simplify import PMBASimplify 12 | 13 | 14 | def simplify_linear_combination(mbaExpre): 15 | """ 16 | """ 17 | #basisVec2 = ["x", "y", "(x|y)", "~(x&~x)"] 18 | basisVec2 = ["(x&y)", "(~x&y)", "(x&~y)", "(~x&~y)"] 19 | basisVec4 = ["x", "y", "z", "t", "(x&y)", "(x&z)", "(x&t)", "(y&z)", "(y&t)","(z&t)", "(x&y&z)", "(x&y&t)", "(x&z&t)", "(y&z&t)", "(x&y&z&t)", "~(x&~x)"] 20 | #basisVec4 = ["(x&y&z&t)", "(~x&y&t&z)", "(x&~y&z&t)", "(x&y&~z&t)", "(x&y&z&~t)", "(~x&~y&z&t)", "(x&~y&~z&t)", "(x&y&~z&~t)", "(~x&y&~z&t)","(~x&y&z&~t)", "(x&~y&z&~t)", "(x&~y&~z&~t)", "(~x&y&~z&~t)", "(~x&~y&z&~t)", "(~x&~y&~z&t)", "(~x&~y&~z&~t)"] 21 | termList = expression_2_term(mbaExpre) 22 | xytermList = [] 23 | nxytermList = [] 24 | for term in termList: 25 | if len(variable_list(term)) == 2: 26 | xytermList.append(term) 27 | else: 28 | nxytermList.append(term) 29 | xyExpre = "".join(xytermList) 30 | nxyExpre = "".join(nxytermList) 31 | psObj = PMBASimplify(2, basisVec2) 32 | simxyExpre = psObj.simplify(xyExpre) 33 | psObj = PMBASimplify(4, basisVec4) 34 | simnxyExpre = psObj.simplify(nxyExpre) 35 | if simnxyExpre[0] == "-" or simnxyExpre[0] == "+": 36 | simExpre = simxyExpre + simnxyExpre 37 | else: 38 | simExpre = simxyExpre + "+" + simnxyExpre 39 | 40 | return simExpre 41 | 42 | 43 | def simplify_pmba(datafile): 44 | """simplify poly mba expression by the signatrue vector. 45 | Args: 46 | datafile: file storing the original mba expression. 47 | """ 48 | filewrite = "{source}.simplify.txt".format(source=datafile) 49 | 50 | fw = open(filewrite, "w") 51 | print("#complex,groundtruth,simplifiedcomplex,simplifiedgroundtruth,z3flag,simtime", file=fw) 52 | 53 | linenum = 0 54 | with open(datafile, "rt") as fr: 55 | for line in fr: 56 | if "#" not in line: 57 | linenum += 1 58 | line = line.strip() 59 | itemList = re.split(",", line) 60 | cmbaExpre = itemList[0] 61 | groundtruth = itemList[1] 62 | vnumber = len(variable_list(cmbaExpre)) 63 | if vnumber == 1: 64 | #basisVec = ["x","~(x&~x)"] 65 | basisVec = ["x","~x"] 66 | elif vnumber == 2: 67 | basisVec = ["x", "y", "(x|y)", "~(x&~x)"] 68 | #basisVec = ["(x&y)", "(~x&y)", "(x&~y)", "(~x&~y)"] 69 | elif vnumber == 3: 70 | basisVec = ["x", "y", "z", "(x&y)", "(y&z)", "(x&z)", "(x&y&z)", "~(x&~x)"] 71 | #basisVec = ["(x&y&z)", "(~x&y&z)", "(x&~y&z)", "(x&y&~z)", "(~x&~y&z)", "(~x&y&~z)", "(x&~y&~z)", "(~x&~y&~z)"] 72 | elif vnumber == 4: 73 | #basisVec = ["x", "y", "z", "t", "(x&y)", "(x&z)", "(x&t)", "(y&z)", "(y&t)","(z&t)", "(x&y&z)", "(x&y&t)", "(x&z&t)", "(y&z&t)", "(x&y&z&t)", "~(x&~x)"] 74 | basisVec = ["(x&y&z&t)", "(~x&y&t&z)", "(x&~y&z&t)", "(x&y&~z&t)", "(x&y&z&~t)", "(~x&~y&z&t)", "(x&~y&~z&t)", "(x&y&~z&~t)", "(~x&y&~z&t)","(~x&y&z&~t)", "(x&~y&z&~t)", "(x&~y&~z&~t)", "(~x&y&~z&~t)", "(~x&~y&z&~t)", "(~x&~y&~z&t)", "(~x&~y&~z&~t)"] 75 | if vnumber == 4: 76 | start = time.time() 77 | simExpre1 = simplify_linear_combination(cmbaExpre) 78 | simExpre2 = simplify_linear_combination(groundtruth) 79 | elapsed = time.time() - start 80 | print("z3 solving...") 81 | z3res = verify_mba_unsat(simExpre1, simExpre2, 2) 82 | print(linenum, cmbaExpre, groundtruth, simExpre1, simExpre2, z3res) 83 | print("z3 solved: ", z3res) 84 | print(cmbaExpre, groundtruth, simExpre1, simExpre2, z3res, elapsed, sep=",", file=fw) 85 | continue 86 | psObj = PMBASimplify(vnumber, basisVec) 87 | start = time.time() 88 | simExpre1 = psObj.simplify(cmbaExpre) 89 | simExpre2 = psObj.simplify(groundtruth) 90 | elapsed = time.time() - start 91 | print("z3 solving...") 92 | z3res = verify_mba_unsat(simExpre1, simExpre2, 2) 93 | print(linenum, cmbaExpre, groundtruth, simExpre1, simExpre2, z3res) 94 | print("z3 solved: ", z3res) 95 | print(cmbaExpre, groundtruth, simExpre1, simExpre2, z3res, elapsed, sep=",", file=fw) 96 | 97 | fw.close() 98 | return None 99 | 100 | 101 | 102 | def main(fileread): 103 | simplify_pmba(fileread) 104 | 105 | return None 106 | 107 | 108 | 109 | if __name__ == "__main__": 110 | fileread = sys.argv[1] 111 | main(fileread) 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /sspam/linear.MBA.SSPAM.result.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,simplified,simtime 2 | (x|y)+y-(~x&y),x+y,(x+y),1.20063877106 3 | 3*(x&~y)-(x^y)+~x-~(x&y),x-y,((((3*(x&(~y)))+(~x))-(~(x&y)))-(x^y)),6.81257891655 4 | -1*(~(x&y))+(x|y)-1*(x^y)-1*x+2*~x-1*(~(x&~y))-1*(~(x^y))-1*(x|~y)+3*(~(x|y))+1*(~(x|~y))+4*(x&~y)+4*(x&y),1*y+1*~y,((((((((13*x)+(5*(x&y)))+(4*(x&(15-y))))+(x&(~y)))-(2*(x|y)))-(x|(15-y)))-(x|(~y)))+13),437.961981058 5 | -2*(~(x&y))-2*~y-2*~x+(~(x^y))-2*x-1*y-1*(x|y)+(x|~y)+6*(~(x|y))+8*(~(x|~y))+7*(x&~y)+4*(x&y),1*(~(x&~x))+1*(~(x&~y)),(((((((y+(6*(x&y)))+(7*(x&(15-y))))-(7*(x|y)))+(x|(15-y)))-(8*(x|(~y))))-(x^y))+7),524.628734112 6 | -1*(x|y)+(~(x&~y))+2*y-2*~y-1*~x-1*(~(x&~x))+(~(x^y))+x+2*(~(x|y))-1*(~(x|~y))+3*(x&~y)-2*(x&y),-(~(x&y))+1*(x|~y),((((((3*y)-(3*(x|y)))-(x^y))+(x^(x&(3-y))))+(x^(~y)))-((3-y)^x)),289.070914984 7 | -1*x-1*~y+4*(~(x&~x))-1*(~(x^y))+y-4*(~(x&y))-1*(~(x&~y))+2*(~(x|y))-1*(~(x|~y))+2*(x&~y)-2*(x&y),-~x,((((((2*x)+y)-(4*(x&(15-x))))-(2*(x|y)))+(y^x))+1),178.024003029 8 | (~(x&~x))+y-2*(x^y)-1*~y+x-1*(~(x&~y))-2*~x-3*(~(x|y))-2*(~(x|~y))-4*(x&~y)-3*(x&y),-5*(~(x&y))-(~(x^y)),((((((((((3*x)+(2*y))-(3*(x&y)))-(4*(x&(15-y))))-(x&(~x)))+(x&(~y)))+(3*(x|y)))+(2*(x|(~y))))-(2*(x^y)))+8),356.784096956 9 | (~(x&y))+(x^y)-1*y+x-2*(x|~y)+2*(~(x&~y))+~y-1*(~(x^y))-1*(~(x|y))-4*(~(x|~y))-3*(x&~y),-(x|y),(((((-x)-(3*(x&(15-y))))+(4*(x|(~y))))+(3*(x^y)))+4),256.034775019 10 | -1*x-1*~x+4*(x|~y)-1*(~(x&~y))-1*~y-4*(x&~y)-1*(x&y),1*(~(x^y))-2*(x^y),(((((y-(x&y))-(4*(x&(15-y))))+(x&(~y)))+(4*(x|(15-y))))+3),98.1647589207 11 | 2*~x+5*(~(x^y))-1*(~(x&y))+(x^y)+x-1*(~(x&~y))+(x|~y)-7*(~(x|y))-3*(~(x|~y))-3*(x&~y)-8*(x&y),-y-(~(x&~x)),(((((((9*(x&y))-(3*(x&(15-y))))+(~y))+(7*(x|y)))+(3*(x|(~y))))-(4*(x^y)))+5),285.620533943 12 | -3*~(x^y)-6*~y-2*(x^y)-7*~(x&y)+1*~(x&~x)+2*~(x&~y)-11*(x|~y)-6*x-2*y+24*~(x|y)+8*~(x|~y)+31*(x&~y),-19*(x&y),(((((((((((250*x)+(4*y))+(7*(x&y)))+(31*(x&(255-y))))-(x&(~x)))-(2*(x&(~y))))-(24*(x|y)))-(11*(x|(255-y))))-(8*(x|(~y))))+(x^y))+237),460.661790133 13 | 1*((x|y)&~(y^z))+1*~(x|(y|z))-2*~(~x|(y|z))-2*(x&(y&z)),1*(~x&(~y|z))-1*((x|~y)&(x^(y^z))),((((2*(x&(y&z)))+((x|y)&(~(y^z))))+(~(x|(y|z))))-(2*(~((~x)|(y|z))))),24.5619001389 14 | -3*(z^~(~x|(~y&z)))-1*(x&(~y|z))-4*~(x|(~y|z))-1*~(~x|(~y|z))+3*(~x&(~y&z))-1*(~x&(y&z))-3*(x&(y&z)),-4*(x|y),(((((((13*(x&(y&z)))-((15-x)&(y&z)))+(3*((15-x)&((15-y)&z))))+(~x))+(4*(x|((~y)|z))))-(3*(z^(15-((~x)|((~y)&z))))))+5),120.689991951 15 | 2*(y|~(x^z))-1*(~x&(~y|z))+2*~(x^(y|z))-3*~(x|(y|z))-2*~(x|(~y|z))+1*(~x&(~y&z))-4*(x&(~y&z))-4*(x&(y&z)),4*~(~x|(~y|z))+1*(~x&(y&z)),((((((((12*(x&(y&z)))-(4*(x&((~y)&z))))+((~x)&((~y)&z)))-((~x)&((~y)|z)))-(3*(~(x|(y|z)))))-(2*(~(x|((~y)|z)))))+(2*(~(x^(y|z)))))+(2*(y|(~(x^z))))),167.521622896 16 | 5*(~x&(y^z))+1*(x&(y^z))+1*((x&~y)|(x^(y^z)))-6*~(x|(~y|z))-1*~(~x|(y|z))-1*~(~x|(~y|z))-2*(x&(~y&z))-1*(x&(y&z)),6*(~x&(~y&z)),((((((((-(x&(y&z)))-(2*(x&((~y)&z))))+(x&(y^z)))+(5*((~x)&(y^z))))-(6*(~(x|((~y)|z)))))-(~((~x)|(y|z))))-(~((~x)|((~y)|z))))+((x&(~y))|(z^(x^y)))),247.096101999 17 | -7*((x^y)&~(x^z))+5*(~z|~(x^y))-3*~(x|(y|z))+4*~(x|(~y|z))-3*~(~x|(y|z))-3*~(~x|(~y|z))-3*(~x&(~y&z))+9*(x&(~y&z))-5*(x&(y&z)),2*~(y&z),(((((((((11*(x&(y&z)))+(9*(x&((~y)&z))))-(3*((~x)&((~y)&z))))-(7*((x^y)&(~(x^z)))))-(3*(~(x|(y|z)))))+(4*(~(x|((~y)|z)))))-(3*(~((~x)|(y|z)))))-(3*(~((~x)|((~y)|z)))))+(5*((~z)|(~(x^y))))),204.11549592 18 | -3*~(y^z)+5*(z^(~x|(y|z)))-12*~(x|(y|z))-15*~(x|(~y|z))-8*~(~x|(y|z))-16*~(~x|(~y|z))-8*(~x&(y&z))+1*(x&(~y&z))+3*(x&(y&z)),1*(z^(~x|(y&z)))-11*(z^~(~x&(y&z))),(((((((((3*(x&(y&z)))+(x&((~y)&z)))-(8*((~x)&(y&z))))-(12*(~(x|(y|z)))))-(15*(~(x|((~y)|z)))))-(8*(~((~x)|(y|z)))))-(16*(~((~x)|((~y)|z)))))-(3*(~(y^z))))+(5*(z^((~x)|(y|z))))),158.738569975 19 | -2*(y|~z)+1*(x^y)+2*~(x|(y|z))+3*~(~x|(y|z))+4*~(~x|(~y|z))+2*(~x&(~y&z))+3*(~x&(y&z))-1*(x&(~y&z))+4*(x&(y&z)),2*(z^~(~x|(y&z)))-1*~(x|(~y|z)),(((((((((4*(x&(y&z)))-(x&((~y)&z)))+(3*((~x)&(y&z))))+(2*((~x)&((~y)&z))))+(2*(~(x|(y|z)))))+(3*(~((~x)|(y|z)))))+(4*(~((~x)|((~y)|z)))))-(2*(y|(~z))))+(x^y)),221.283245087 20 | -1*((~(x^(~y&z))&~t)|((z^(~x|(y&z)))&t))+1*((((x&y)^(x^(y&z)))&~t)|(((x&~y)|~(y^z))&t))+1*(((z^~(x&y))&~t)|(((x|y)&~(x^(y^z)))&t))-2*~(~x|(y|(z|t)))-2*~(~x|(~y|(~z|t)))+1*(~x&(y&(~z&t)))-1*(x&(~y&(~z&t)))-2*(~x&(y&(z&t)))-1*(x&(y&(z&t))),1*(x&(y&(~z&t)))+1*(x&(~y&(z&t))),(((((((((-(x&(y&(z&t))))-(x&((~y)&((~z)&t))))-(2*((~x)&(y&(z&t)))))+((~x)&(y&((~z)&t))))-(2*(~((~x)|(y|(z|t))))))-(2*(~((~x)|((~y)|((~z)|t))))))-(((~(x^((~y)&z)))&(~t))|((z^((~x)|(y&z)))&t)))+(((z^(~(x&y)))&(~t))|(((x|y)&(~(z^(x^y))))&t)))+((((x&y)^(x^(y&z)))&(~t))|(((x&(~y))|(~(y^z)))&t))),548.3627491 21 | 2*((((y&z)|(~x&(y|z)))&~t)|((y^~(x&(~y&z)))&t))-2*(((z^~(~x&(y|z)))&~t)|(((x|y)&~(y^z))&t))-2*(((z^~(x|(~y&z)))&~t)|(((x&y)^(x^(~y|z)))&t))-2*((((x^y)&(x^z))&~t)|((~(x|y)|~(y^z))&t))+4*~(x|(y|(z|t)))+4*~(~x|(y|(z|t)))+2*~(~x|(~y|(z|t)))+2*~(x|(y|(~z|t)))+2*~(x|(~y|(~z|t)))+2*~(~x|(y|(~z|t)))+2*(~x&(~y&(~z&t)))+2*(~x&(~y&(z&t)))+6*(~x&(y&(z&t)))+6*(x&(y&(z&t))),-2*(x&(~y&(~z&t))),((((((((((((((6*(x&(y&(z&t))))+(6*((~x)&(y&(z&t)))))+(2*((~x)&((~y)&(z&t)))))+(2*((~x)&((~y)&((~z)&t)))))+(4*(~(x|(y|(z|t))))))+(2*(~(x|(y|((~z)|t))))))+(2*(~(x|((~y)|((~z)|t))))))+(4*(~((~x)|(y|(z|t))))))+(2*(~((~x)|(y|((~z)|t))))))+(2*(~((~x)|((~y)|(z|t))))))-(2*((((x^y)&(x^z))&(~t))|(((~(x|y))|(~(y^z)))&t))))+(2*((((y&z)|((~x)&(y|z)))&(~t))|((y^(~(x&((~y)&z))))&t))))-(2*(((z^(~((~x)&(y|z))))&(~t))|(((x|y)&(~(y^z)))&t))))-(2*(((z^(~(x|((~y)&z))))&(~t))|(((x&y)^(x^((~y)|z)))&t)))),1117.31286597 22 | 3*(((z^~(x|y))&~t)|((y^~(x&(y&z)))&t))+7*(((~y&~(x^z))&~t)|(~(x&~y)&t))+1*(((y^~(~x|(y&z)))&~t)|((x&~x)&t))-1*((~(x|(y|z))&~t)|((z^~(x|(~y&z)))&t))+2*((((x&z)^(x^(~y&z)))&~t)|(((x&y)^~(x^(y&z)))&t))-9*(((x^(y|z))&~t)|(((y&z)|(~x&(y|z)))&t))+1*(((y|(x&~z))&~t)|((~(x|y)|~(x^(y^z)))&t))-5*(((~(x^y)|~(x^z))&~t)|(((x|y)&(x^(y^z)))&t))-4*((((x|~y)&~(x^(y^z)))&~t)|((y|(x^z))&t))+9*(((y^~(x|(~y&z)))&~t)|((x&z)&t))-1*((((x&y)^(x^(~y|z)))&~t)|((z^~(x&~y))&t))-3*(((y^~(x&(y^z)))&~t)|((z^~(~x&(~y|z)))&t))+1*((~(~x&(y&z))&~t)|(~(x^(~y&z))&t))-4*(((x&~z)&~t)|((z&~(x^y))&t))+11*~(x|(~y|(z|t)))+11*~(~x|(y|(z|t)))+3*~(~x|(~y|(z|t)))+15*~(x|(y|(~z|t)))+5*~(x|(~y|(~z|t)))-9*~(~x|(~y|(~z|t)))-12*(~x&(~y&(~z&t)))+13*(~x&(y&(~z&t)))+15*(x&(~y&(~z&t)))+4*(x&(y&(~z&t)))+14*(~x&(~y&(z&t)))+13*(~x&(y&(z&t)))-12*(x&(~y&(z&t)))+10*(x&(y&(z&t))),-1*~(~x|(y|(~z|t)))+6*(((~y&~(x^z))&~t)|((z^~(~x|(y&z)))&t)),((((((((((((((((((((((((((((10*(x&(y&(z&t))))+(4*(x&(y&((~z)&t)))))-(12*(x&((~y)&(z&t)))))+(15*(x&((~y)&((~z)&t)))))+(13*((~x)&(y&(z&t)))))+(13*((~x)&(y&((~z)&t)))))+(14*((~x)&((~y)&(z&t)))))-(12*((~x)&((~y)&((~z)&t)))))+(15*(~(x|(y|((~z)|t))))))+(11*(~(x|((~y)|(z|t))))))+(5*(~(x|((~y)|((~z)|t))))))+(11*(~((~x)|(y|(z|t))))))+(3*(~((~x)|((~y)|(z|t))))))-(9*(~((~x)|((~y)|((~z)|t))))))-(4*(((x&(~z))&(~t))|((z&(~(x^y)))&t))))+(7*((((~y)&(~(x^z)))&(~t))|((~(x&(~y)))&t))))-(4*((((x|(~y))&(~(z^(x^y))))&(~t))|((y|(x^z))&t))))+(((~((~x)&(y&z)))&(~t))|((~(x^((~y)&z)))&t)))-(((~(x|(y|z)))&(~t))|((z^(~(x|((~y)&z))))&t)))+(((y|(x&(~z)))&(~t))|(((~(x|y))|(~(z^(x^y))))&t)))-(5*((((~(x^y))|(~(x^z)))&(~t))|(((x|y)&(z^(x^y)))&t))))-(9*(((x^(y|z))&(~t))|(((y&z)|((~x)&(y|z)))&t))))-(3*(((y^(~(x&(y^z))))&(~t))|((z^(~((~x)&((~y)|z))))&t))))+(9*(((y^(~(x|((~y)&z))))&(~t))|((x&z)&t))))+(((y^(~((~x)|(y&z))))&(~t))|((x&(~x))&t)))+(3*(((z^(~(x|y)))&(~t))|((y^(~(x&(y&z))))&t))))-((((x&y)^(x^((~y)|z)))&(~t))|((z^(~(x&(~y))))&t)))+(2*((((x&z)^(x^((~y)&z)))&(~t))|(((x&y)^(~(x^(y&z))))&t)))),23207.72229 23 | -------------------------------------------------------------------------------- /sspam/makefile: -------------------------------------------------------------------------------- 1 | sspam-mba-linear: 2 | python2 sspam-evaluation.py ../dataset/pldi_dataset_linear_MBA.txt linear.MBA.SSPAM.result.txt 3 | 4 | sspam-mba-poly: 5 | python2 sspam-evaluation.py ../dataset/pldi_dataset_poly_MBA.txt poly.MBA.SSPAM.result.txt 6 | 7 | sspam-mba-nonpoly: 8 | python2 sspam-evaluation.py ../dataset/pldi_dataset_nonpoly_MBA.txt nonpoly.MBA.SSPAM.result.txt 9 | 10 | sspam-simplify: 11 | @echo "----------------------sspam simplify linear MBA samples-------------------" 12 | @make sspam-mba-linear 13 | @echo "----------------------sspam simplify linear MBA samples completion---------" 14 | @echo "----------------------sspam simplify poly MBA samples----------------------" 15 | @make sspam-mba-poly 16 | @echo "----------------------sspam simplify poly MBA samples completion-----------" 17 | @echo "----------------------sspam simplify nonpoly MBA samples--------------------" 18 | @make sspam-mba-nonpoly 19 | @echo "----------------------sspam simplify nonpoly MBA samples completion---------" 20 | 21 | -------------------------------------------------------------------------------- /sspam/poly.MBA.SSPAM.result.txt: -------------------------------------------------------------------------------- 1 | #complex,groundtruth,simplified,simtime 2 | (x&y)*(x|y)+(x&~y)*(~x&y)-41,x*y-41,((((x&y)*(x|y))+((x&(~y))*((~x)&y)))+215),5.90864896774 3 | (x&y)*(x|y)+(x&~y)*(~x&y)-253,x*y-253,((((x&y)*(x|y))+((x&(~y))*((~x)&y)))+3),5.78629302979 4 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*~x+1*(x|~y)-1*~(x|~y)-3*(x&~y),x*y+1*(x&y)-2*(x^y),(((((((x&y)*(x|y))+((x&(~y))*((~x)&y)))-(3*(x&(~y))))-(~x))-(~(x|(~y))))+(x|(~y))),86.0902190208 5 | (x&y)*(x|y)+(x&~y)*(~x&y)+5*~y-11*(x|~y)+6*~(x|y)+8*(x&~y),x*y-13*(x&y)+2*x,(((((((x&y)*(x|y))+((x&(~y))*((~x)&y)))+(8*(x&(~y))))+(5*(~y)))+(6*(~(x|y))))-(11*(x|(~y)))),69.03540802 6 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*y+2*~(x&y)-2*(x^y)+1*(x&y),x*y-3*~(x|~y)+2*~x,((((((-y)+((x&y)*(x|y)))+(x&y))+((x&(~y))*((~x)&y)))+(2*(~(x&y))))-(2*(x^y))),61.9674310684 7 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*~(x&y)-11*~(x^y)+12*~(x|y)+1*~(x|~y)+11*(x&y),x*y+2*~x+1*(x&~y),((((((((x&y)*(x|y))+(11*(x&y)))+((x&(~y))*((~x)&y)))+(~(x&y)))+(12*(~(x|y))))+(~(x|(~y))))-(11*(~(x^y)))),88.6971399784 8 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*~x+5*x-2*~(x^y)+13*~(x|y)+11*~(x|~y),x*y+5*(x&~y)+3*(x&y),(((((((5*x)+((x&y)*(x|y)))+((x&(~y))*((~x)&y)))-(11*(~x)))+(13*(~(x|y))))+(11*(~(x|(~y)))))-(2*(~(x^y)))),65.8701269627 9 | (x&y)*(x|y)+(x&~y)*(~x&y)-2*~(x&~x)+2*y+3*~(x|y)+1*~(x|~y)+2*(x&~y),x*y+1*~x,(((((((2*y)+((x&y)*(x|y)))+((x&(~y))*((~x)&y)))+(2*(x&(~y))))-(2*(~(x&(~x)))))+(3*(~(x|y))))+(~(x|(~y)))),127.249729872 10 | (x&y)*(x|y)+(x&~y)*(~x&y)+11*(x|~y)+3*~(x&~x)+5*~(x&y)-19*(x&~y)-14*(x&y),x*y+19*~(x|y)+8*~(x|~y),((((((((x&y)*(x|y))-(14*(x&y)))+((x&(~y))*((~x)&y)))-(19*(x&(~y))))+(5*(~(x&y))))+(3*(~(x&(~x)))))+(11*(x|(~y)))),112.562524796 11 | (x&y)*(x|y)+(x&~y)*(~x&y)+7*~y+4*~(x&y)+11*~(x&~x)-22*~(x|y)-11*(x&y),x*y+15*~(x|~y)+22*(x&~y),((((((249*y)+((x&y)*(x|y)))-(15*(x&y)))+((x&(255-y))*((255-x)&y)))-(11*(x&(~x))))+(22*(x|y))),134.239772081 12 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*(x|~y)-3*~y+2*x+14*~(x|y)+12*(x&~y),x*y-9*(x&y),(((((((2*x)+((x&y)*(x|y)))+((x&(~y))*((~x)&y)))+(12*(x&(~y))))-(3*(~y)))+(14*(~(x|y))))-(11*(x|(~y)))),113.309473038 13 | (x&y)*(x|y)+(x&~y)*(~x&y)+2*(x|y)-4*~(x|y)-2*~(x|~y)-1*(x&~y)-7*(x&y),x*y-5*~(x^y)+1*~y,((((((((x&y)*(x|y))-(7*(x&y)))+((x&(~y))*((~x)&y)))-(x&(~y)))-(4*(~(x|y))))-(2*(~(x|(~y)))))+(2*(x|y))),126.740795851 14 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*~y+1*y+3*~(x|y)+3*(x&~y)+1*(x&y),x*y-1*~(x|~y)+2*~(x&~x),((((((y+((x&y)*(x|y)))+(x&y))+((x&(~y))*((~x)&y)))+(3*(x&(~y))))-(~y))+(3*(~(x|y)))),109.680879116 15 | (x&y)*(x|y)+(x&~y)*(~x&y)+2*~(x&~y)-5*~(x&y)-1*x+5*~(x|y)+3*~(x|~y)+1*(x&y),x*y-6*(x&~y)+2*~(x^y),((((((((-x)+((x&y)*(x|y)))+(x&y))+((x&(~y))*((~x)&y)))-(5*(~(x&y))))+(2*(~(x&(~y)))))+(5*(~(x|y))))+(3*(~(x|(~y))))),132.639131784 16 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(y^~(~x|(~y&z)))-1*(y^~(x|~z))+1*~(x|(~y|z))+1*~(~x|(~y|z))+1*(x&(~y&z))+1*(x&(y&z)),x*y+1*(x^y)-1*(~x&(~y&z)),(((((((((x&y)*(x|y))+(x&(y&z)))+(x&((~y)&z)))+((x&(~y))*((~x)&y)))+(~(x|((~y)|z))))+(~((~x)|((~y)|z))))-(y^(~(x|(~z)))))+(y^(~((~x)|((~y)&z))))),227.068584919 17 | (x&y)*(x|y)+(x&~y)*(~x&y)+4*(y&z)-1*~(x^y)+2*(~x|(y&z))-1*~(x|(y|z))-2*~(x|(~y|z))+1*~(~x|(~y|z))-1*(~x&(~y&z)),x*y+6*(~x&(y&z))+5*(x&(y&z)),((((((((((x&y)*(x|y))+((x&(~y))*((~x)&y)))+(4*(y&z)))-((~x)&((~y)&z)))-(~(x|(y|z))))-(2*(~(x|((~y)|z)))))+(~((~x)|((~y)|z))))-(~(x^y)))+(2*((~x)|(y&z)))),350.16226387 18 | (x&y)*(x|y)+(x&~y)*(~x&y)+3*(z^(~x|(y&z)))-11*(y&~(x&z))+4*(z^(~x|(y|z)))-7*~(x|(y|z))+4*~(x|(~y|z))+7*~(~x|(~y|z))+11*(~x&(y&z)),x*y+3*(x&(~y&z)),((((((((((x&y)*(x|y))+((x&(~y))*((~x)&y)))-(11*(y&(~(x&z)))))+(11*((~x)&(y&z))))-(7*(~(x|(y|z)))))+(4*(~(x|((~y)|z)))))+(7*(~((~x)|((~y)|z)))))+(3*(z^((~x)|(y&z)))))+(4*(z^((~x)|(y|z))))),228.91146493 19 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(z^~(x&(y&z)))-2*((x|~y)&~(y^z))+1*~(x|(y|z))-1*~(x|(~y|z))-10*~(~x|(y|z))-12*~(~x|(~y|z))-11*(~x&(y&z))-10*(x&(y&z)),x*y-11*((x&z)^(x^(y&z))),(((((((((((x&y)*(x|y))-(10*(x&(y&z))))+((x&(~y))*((~x)&y)))-(11*((~x)&(y&z))))-(2*((x|(~y))&(~(y^z)))))+(~(x|(y|z))))-(~(x|((~y)|z))))-(10*(~((~x)|(y|z)))))-(12*(~((~x)|((~y)|z)))))+(z^(~(x&(y&z))))),421.189121008 20 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*((y&~z)|~(~x|(~y&z)))+4*(z^~(~x|(y&z)))+11*~(x|(~y|z))+7*~(~x|(y|z))+6*~(~x|(~y|z))-4*(~x&(y&z))-1*(x&(~y&z))+7*(x&(y&z)),x*y-1*(x&(y^z))+4*(~x&(~y&z)),(((((((((((x&y)*(x|y))+(7*(x&(y&z))))-(x&((~y)&z)))+((x&(~y))*((~x)&y)))-(4*((~x)&(y&z))))+(11*(~(x|((~y)|z)))))+(7*(~((~x)|(y|z)))))+(6*(~((~x)|((~y)|z)))))-(11*((y&(~z))|(~((~x)|((~y)&z))))))+(4*(z^(~((~x)|(y&z)))))),360.299180031 21 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(y^~(~x|(y^z)))+2*(y^~(x|~z))+1*((x&y)^(y|~z))-1*~(x|(y|z))-4*~(x|(~y|z))-3*~(~x|(~y|z))-2*(~x&(~y&z))-2*(~x&(y&z)),x*y+2*(x&(y&z))+2*~(~x|(y|z)),(((((((((((x&y)*(x|y))+((x&(~y))*((~x)&y)))-(2*((~x)&(y&z))))-(2*((~x)&((~y)&z))))-(~(x|(y|z))))-(4*(~(x|((~y)|z)))))-(3*(~((~x)|((~y)|z)))))+(2*(y^(~(x|(~z))))))+(y^(~((~x)|(y^z)))))+((x&y)^(y|(~z)))),379.76443696 22 | (x&y)*(x|y)+(x&~y)*(~x&y)+11*(y^(~x|(y^z)))-7*(x^y)+1*(z^~(~x&(y|z)))-1*(~x|(y|z))-2*(~(x&~y)&(x^(y^z)))+1*(~z|~(x^y))+1*(y^~(x&(y^z)))+3*~(x&(y|z))-2*(~(x&y)&~(x^(y^z)))-5*~(~x&(~y|z))+1*((x&z)^~(x^(y&z)))+7*(x|~y)+5*(y^~(x&~z))-3*(~(x|y)|(y^z))+11*(~z|(x^y))-1*((x&~y)|(y^z))-11*~(x&(y&z))+14*~(x|(~y|z))-5*~(~x|(~y|z))-12*(~x&(~y&z))+6*(~x&(y&z))-5*(x&(~y&z))-11*(x&(y&z)),x*y+24*~(x|(y|z)),((((((((((((((((((((((((((x&y)*(x|y))-(11*(x&(y&z))))-(5*(x&((~y)&z))))+((x&(~y))*((~x)&y)))+(6*((~x)&(y&z))))-(12*((~x)&((~y)&z))))-(2*((~(x&y))&(~(z^(x^y))))))-(2*((~(x&(~y)))&(z^(x^y)))))-(11*(~(x&(y&z)))))+(3*(~(x&(y|z)))))-(5*(~((~x)&((~y)|z)))))+(14*(~(x|((~y)|z)))))-(5*(~((~x)|((~y)|z)))))+(7*(x|(~y))))-((x&(~y))|(y^z)))-((~x)|(y|z)))+((~z)|(~(x^y))))+(11*((~z)|(x^y))))-(3*((~(x|y))|(y^z))))-(7*(x^y)))+(5*(y^(~(x&(~z))))))+(y^(~(x&(y^z)))))+(11*(y^((~x)|(y^z)))))+(z^(~((~x)&(y|z)))))+((x&z)^(~(x^(y&z))))),7693.47148085 23 | -------------------------------------------------------------------------------- /sspam/sspam-evaluation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | import re 4 | import sspam 5 | from sspam import simplifier 6 | import sys 7 | import time 8 | 9 | 10 | 11 | def sspam_simplify(sourcefilename, desfilename): 12 | fwrite = open(desfilename, "w") 13 | fwrite.write("#complex,groundtruth,simplified,simtime\n") 14 | 15 | with open(sourcefilename) as data: 16 | linenum = 0 17 | for line in data: 18 | line = line.replace("\n","") 19 | if "#" not in line and line: 20 | expreStrList = re.split(",", line) 21 | sourceStr = expreStrList[0] 22 | start = time.time() 23 | simStr = simplifier.simplify(sourceStr).replace(" ", "") 24 | end = time.time() 25 | elapsed = end - start 26 | resultStr = line 27 | resultStr += "," + simStr + "," + str(elapsed) + "\n" 28 | fwrite.write(resultStr) 29 | fwrite.flush() 30 | print linenum, sourceStr, simStr 31 | linenum += 1 32 | 33 | return None 34 | 35 | 36 | def main(sourcefilename, desfilename): 37 | sspam_simplify(sourcefilename, desfilename) 38 | 39 | 40 | 41 | if __name__ == "__main__": 42 | sourcefilename = sys.argv[1] 43 | desfilename = sys.argv[2] 44 | main(sourcefilename, desfilename) 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /stp_solving/makefile: -------------------------------------------------------------------------------- 1 | timeout = 5 2 | 3 | stp-linear-before-simplify: 4 | python2 stp_check_before_simplify.py ../dataset/pldi_dataset_linear_MBA.txt $(timeout) 5 | 6 | stp-poly-before-simplify: 7 | python2 stp_check_before_simplify.py ../dataset/pldi_dataset_poly_MBA.txt $(timeout) 8 | 9 | stp-nonpoly-before-simplify: 10 | python2 stp_check_before_simplify.py ../dataset/pldi_dataset_nonpoly_MBA.txt $(timeout) 11 | 12 | stp-linear-after-simplify: 13 | python2 stp_check_after_simplify.py ../dataset/pldi_dataset_linear_MBA.txt.simplify.txt $(timeout) 14 | 15 | stp-poly-after-simplify: 16 | python2 stp_check_after_simplify.py ../dataset/pldi_dataset_poly_MBA.txt.simplify.txt $(timeout) 17 | 18 | stp-nonpoly-after-simplify: 19 | python2 stp_check_after_simplify.py ../dataset/pldi_dataset_nonpoly_MBA.txt.simplify.txt $(timeout) 20 | 21 | stp-linear-after-simplify-sspam: 22 | python2 stp_check_after_simplify_peertools.py ../sspam/linear.MBA.SSPAM.result.txt $(timeout) 23 | 24 | stp-poly-after-simplify-sspam: 25 | python2 stp_check_after_simplify_peertools.py ../sspam/poly.MBA.SSPAM.result.txt $(timeout) 26 | 27 | stp-nonpoly-after-simplify-sspam: 28 | python2 stp_check_after_simplify_peertools.py ../sspam/nonpoly.MBA.SSPAM.result.txt $(timeout) 29 | 30 | stp-linear-after-simplify-syntia: 31 | python2 stp_check_after_simplify_peertools.py ../syntia/linear.64bit.result.txt $(timeout) 32 | 33 | stp-poly-after-simplify-syntia: 34 | python2 stp_check_after_simplify_peertools.py ../syntia/poly.64bit.result.txt $(timeout) 35 | 36 | stp-nonpoly-after-simplify-syntia: 37 | python2 stp_check_after_simplify_peertools.py ../syntia/nonpoly.64bit.result.txt $(timeout) 38 | 39 | 40 | stp-solving-before-simplify-total: 41 | python3 total.py stp 0 42 | stp-solving-before-simplify: 43 | @echo "--------------------stp solving linear MBA samples-------------------------" 44 | @make stp-linear-before-simplify 45 | @echo "--------------------stp solving linear MBA samples completion--------------" 46 | @echo "--------------------stp solving poly MBA samples---------------------------" 47 | @make stp-poly-before-simplify 48 | @echo "--------------------stp solving poly MBA samples completion----------------" 49 | @echo "--------------------stp solving nonpoly MBA samples------------------------" 50 | @make stp-nonpoly-before-simplify 51 | @echo "--------------------stp solving nonpoly MBA samples completion-------------" 52 | @echo "--------------------stp solving MBA samples before simplification-------------" 53 | @make stp-solving-before-simplify-total 54 | 55 | stp-solving-mba-solver-total: 56 | python3 total.py stp 1 mba 57 | stp-solving-mba-solver: 58 | @echo "--------------------stp solving linear MBA samples after MBA-Solver simplification--------------------------" 59 | @make stp-linear-after-simplify 60 | @echo "--------------------stp solving linear MBA samples after MBA-Solver simplification completion---------------" 61 | @echo "--------------------stp solving poly MBA samples after MBA-Solver simplification----------------------------" 62 | @make stp-poly-after-simplify 63 | @echo "--------------------stp solving poly MBA samples after MBA-Solver simplification completion-----------------" 64 | @echo "--------------------stp solving nonpoly MBA samples after MBA-Solver simplification-------------------------" 65 | @make stp-nonpoly-after-simplify 66 | @echo "--------------------stp solving nonpoly MBA samples after MBA-Solver simplification completion--------------" 67 | @echo "--------------------stp solving MBA samples after MBA-Solver simplification --------------" 68 | @make stp-solving-mba-solver-total 69 | 70 | stp-solving-sspam-total: 71 | python3 total.py stp 1 sspam 72 | stp-solving-sspam: 73 | @echo "--------------------stp solving linear MBA samples after SSPAM simplification--------------------------" 74 | @make stp-linear-after-simplify-sspam 75 | @echo "--------------------stp solving linear MBA samples after SSPAM simplification completion---------------" 76 | @echo "--------------------stp solving poly MBA samples after SSPAM simplification----------------------------" 77 | @make stp-poly-after-simplify-sspam 78 | @echo "--------------------stp solving poly MBA samples after SSPAM simplification completion-----------------" 79 | @echo "--------------------stp solving nonpoly MBA samples after SSPAM simplification-------------------------" 80 | @make stp-nonpoly-after-simplify-sspam 81 | @echo "--------------------stp solving nonpoly MBA samples after SSPAM simplification completion--------------" 82 | @echo "--------------------stp solving MBA samples after SSPAM simplification --------------" 83 | @make stp-solving-sspam-total 84 | 85 | stp-solving-syntia-total: 86 | python3 total.py stp 1 syntia 87 | stp-solving-syntia: 88 | @echo "--------------------stp solving linear MBA samples after Syntia simplification--------------------------" 89 | @make stp-linear-after-simplify-syntia 90 | @echo "--------------------stp solving linear MBA samples after Syntia simplification completion---------------" 91 | @echo "--------------------stp solving poly MBA samples after Syntia simplification----------------------------" 92 | @make stp-poly-after-simplify-syntia 93 | @echo "--------------------stp solving poly MBA samples after Syntia simplification completion-----------------" 94 | @echo "--------------------stp solving nonpoly MBA samples after Syntia simplification-------------------------" 95 | @make stp-nonpoly-after-simplify-syntia 96 | @echo "--------------------stp solving nonpoly MBA samples after Syntia simplification completion--------------" 97 | @echo "--------------------stp solving MBA samples after Syntia simplification --------------" 98 | @make stp-solving-syntia-total 99 | -------------------------------------------------------------------------------- /stp_solving/stp_check_after_simplify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | import re 4 | import sys 5 | import time 6 | import stp 7 | from multiprocessing import Process, Value 8 | 9 | def verify_mba_unsat(leftExpre, rightExpre, bitnumber, res): 10 | """check the relaion whether the left expression is euqal to the right expression. 11 | Args: 12 | leftExpre: left expression. 13 | rightExpre: right expression. 14 | bitnumber: the number of the bits of the variable. 15 | Returns: 16 | True: equation. 17 | False: unequal. 18 | Raises: 19 | None. 20 | """ 21 | s = stp.Solver() 22 | x = s.bitvec("x", bitnumber) 23 | y = s.bitvec("y", bitnumber) 24 | z = s.bitvec("z", bitnumber) 25 | t = s.bitvec("t", bitnumber) 26 | a = s.bitvec("a", bitnumber) 27 | b = s.bitvec("b", bitnumber) 28 | c = s.bitvec("c", bitnumber) 29 | d = s.bitvec("d", bitnumber) 30 | e = s.bitvec("e", bitnumber) 31 | f = s.bitvec("f", bitnumber) 32 | 33 | try: 34 | leftEval = eval(leftExpre) 35 | rightEval = eval(rightExpre) 36 | except: 37 | res.value = 2 38 | return None 39 | 40 | if not re.search("[xyztabcdef]", leftExpre) and not re.search("[xyztabcdef]", rightExpre): 41 | #whether is a constant 42 | if leftEval - rightEval == 0: 43 | res.value = 1 44 | else: 45 | res.value = 2 46 | else: 47 | s.add(leftEval != rightEval) 48 | result = s.check() 49 | 50 | if result: 51 | res.value = 2 52 | else: 53 | res.value = 1 54 | 55 | return None 56 | 57 | 58 | def stp_check_time(sourcefilename, timeout, bv=64): 59 | """input the expression from the source file, then check the equation and output the time and memory of process to desination file. 60 | Args: 61 | sourcefilename: source file. 62 | """ 63 | desfilename = "{source}.stp.verify.{bv}bit.after.simplify.txt".format(source=sourcefilename, bv=bv) 64 | fwrite = open(desfilename, "w") 65 | comment = "#complex,groundtruth,simcomplex,simground,stpres,verificationtime\n" 66 | fwrite.write(comment) 67 | 68 | solvingList = [0, 0, 0] 69 | with open(sourcefilename, "r") as data: 70 | linenum = 0 71 | for line in data: 72 | line = line.strip().replace(" ", "") 73 | if "#" not in line: 74 | expreStrList = re.split(",", line) 75 | sourceExpreStr = expreStrList[0] 76 | groundExpreStr = expreStrList[1] 77 | sourceSimStr = expreStrList[2] 78 | groundSimStr = expreStrList[3] 79 | start = time.time() 80 | #res = verify_mba_unsat(sourceSimStr, groundSimStr, bv) 81 | res = Value('i', 0) 82 | p = Process(target=verify_mba_unsat, args=(sourceSimStr, groundSimStr, bv, res,)) 83 | p.start() 84 | p.join(timeout) # wait timeout seconds or it finishes 85 | 86 | if p.is_alive(): 87 | print("Still solving, but kill it as timeout set to", timeout, "seconds ...") 88 | p.terminate() 89 | p.join() 90 | 91 | result = { 92 | 0: "Timeout", 93 | 1: "True", 94 | 2: "False", 95 | } 96 | end = time.time() 97 | elapsed = end - start 98 | resultStr = "{source},{ground},{ssim},{gsim},{res},{vtime}\n".format(source=sourceExpreStr, ground=groundExpreStr, ssim=sourceSimStr, gsim=groundSimStr, res=result[res.value], vtime=elapsed) 99 | fwrite.write(resultStr) 100 | fwrite.flush() 101 | 102 | # print linenum, sourceExpreStr, groundExpreStr, sourceSimStr, groundSimStr, result[res.value], elapsed 103 | print linenum, result[res.value], "Time =", elapsed 104 | linenum += 1 105 | solvingList[res.value] += 1 106 | 107 | fwrite.close() 108 | print("Timeout: ", solvingList[0]) 109 | print("True: ", solvingList[1]) 110 | print("False: ", solvingList[2]) 111 | return None 112 | 113 | 114 | 115 | def main(sourcefilename, timeout): 116 | stp_check_time(sourcefilename, timeout) 117 | 118 | return None 119 | 120 | 121 | 122 | if __name__ =="__main__": 123 | sourcefilename = sys.argv[1] 124 | timeout = int(sys.argv[2]) 125 | main(sourcefilename, timeout) 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /stp_solving/stp_check_after_simplify_peertools.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | import re 4 | import sys 5 | import time 6 | import stp 7 | from multiprocessing import Process, Value 8 | 9 | def verify_mba_unsat(leftExpre, rightExpre, bitnumber, res): 10 | """check the relaion whether the left expression is euqal to the right expression. 11 | Args: 12 | leftExpre: left expression. 13 | rightExpre: right expression. 14 | bitnumber: the number of the bits of the variable. 15 | Returns: 16 | True: equation. 17 | False: unequal. 18 | Raises: 19 | None. 20 | """ 21 | s = stp.Solver() 22 | x = s.bitvec("x", bitnumber) 23 | y = s.bitvec("y", bitnumber) 24 | z = s.bitvec("z", bitnumber) 25 | t = s.bitvec("t", bitnumber) 26 | a = s.bitvec("a", bitnumber) 27 | b = s.bitvec("b", bitnumber) 28 | c = s.bitvec("c", bitnumber) 29 | d = s.bitvec("d", bitnumber) 30 | e = s.bitvec("e", bitnumber) 31 | f = s.bitvec("f", bitnumber) 32 | 33 | try: 34 | leftEval = eval(leftExpre) 35 | rightEval = eval(rightExpre) 36 | except: 37 | res.value = 2 38 | return None 39 | 40 | if not re.search("[xyztabcdef]", leftExpre) and not re.search("[xyztabcdef]", rightExpre): 41 | #whether is a constant 42 | if leftEval - rightEval == 0: 43 | res.value = 1 44 | else: 45 | res.value = 2 46 | else: 47 | s.add(leftEval != rightEval) 48 | result = s.check() 49 | 50 | if result: 51 | res.value = 2 52 | else: 53 | res.value = 1 54 | 55 | return None 56 | 57 | 58 | def stp_check_time(sourcefilename, timeout, bv=64): 59 | """input the expression from the source file, then check the equation and output the time and memory of process to desination file. 60 | Args: 61 | sourcefilename: source file. 62 | """ 63 | desfilename = "{source}.stp.verify.{bv}bit.after.simplify.txt".format(source=sourcefilename, bv=bv) 64 | fwrite = open(desfilename, "w") 65 | comment = "#complex,groundtruth,simcomplex,stpres,verificationtime\n" 66 | fwrite.write(comment) 67 | 68 | solvingList = [0, 0, 0] 69 | with open(sourcefilename, "r") as data: 70 | linenum = 0 71 | for line in data: 72 | line = line.strip().replace(" ", "") 73 | if "#" not in line: 74 | expreStrList = re.split(",", line) 75 | sourceExpreStr = expreStrList[0] 76 | groundExpreStr = expreStrList[1] 77 | sourceSimStr = expreStrList[2] 78 | 79 | start = time.time() 80 | #res = verify_mba_unsat(sourceSimStr, groundExpreStr, bv) 81 | res = Value('i', 0) 82 | p = Process(target=verify_mba_unsat, args=(sourceSimStr, groundExpreStr, bv, res,)) 83 | p.start() 84 | p.join(timeout) # wait timeout seconds or it finishes 85 | 86 | if p.is_alive(): 87 | print("Still solving, but kill it as timeout set to", timeout, "seconds ...") 88 | p.terminate() 89 | p.join() 90 | 91 | result = { 92 | 0: "Timeout", 93 | 1: "True", 94 | 2: "False", 95 | } 96 | end = time.time() 97 | elapsed = end - start 98 | resultStr = "{source},{ground},{ssim},{res},{vtime}\n".format(source=sourceExpreStr, ground=groundExpreStr, ssim=sourceSimStr, res=result[res.value], vtime=elapsed) 99 | fwrite.write(resultStr) 100 | fwrite.flush() 101 | 102 | # print linenum, sourceExpreStr, groundExpreStr, sourceSimStr, result[res.value], elapsed 103 | print linenum, result[res.value], "Time =", elapsed 104 | linenum += 1 105 | solvingList[res.value] += 1 106 | 107 | fwrite.close() 108 | print("Timeout: ", solvingList[0]) 109 | print("True: ", solvingList[1]) 110 | print("False: ", solvingList[2]) 111 | return None 112 | 113 | 114 | 115 | def main(sourcefilename, timeout): 116 | stp_check_time(sourcefilename, timeout) 117 | 118 | 119 | 120 | if __name__ =="__main__": 121 | sourcefilename = sys.argv[1] 122 | timeout = int(sys.argv[2]) 123 | main(sourcefilename, timeout) 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /stp_solving/stp_check_before_simplify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | import re 4 | import sys 5 | import time 6 | import stp 7 | from multiprocessing import Process, Value 8 | 9 | def verify_mba_unsat(leftExpre, rightExpre, bitnumber, res): 10 | """check the relaion whether the left expression is euqal to the right expression. 11 | Args: 12 | leftExpre: left expression. 13 | rightExpre: right expression. 14 | bitnumber: the number of the bits of the variable. 15 | Returns: 16 | True: equation. 17 | False: unequal. 18 | Raises: 19 | None. 20 | """ 21 | s = stp.Solver() 22 | x = s.bitvec("x", bitnumber) 23 | y = s.bitvec("y", bitnumber) 24 | z = s.bitvec("z", bitnumber) 25 | t = s.bitvec("t", bitnumber) 26 | a = s.bitvec("a", bitnumber) 27 | b = s.bitvec("b", bitnumber) 28 | c = s.bitvec("c", bitnumber) 29 | d = s.bitvec("d", bitnumber) 30 | e = s.bitvec("e", bitnumber) 31 | f = s.bitvec("f", bitnumber) 32 | 33 | leftEval = eval(leftExpre) 34 | rightEval = eval(rightExpre) 35 | 36 | s.add(leftEval != rightEval) 37 | result = s.check() 38 | 39 | if result: 40 | res.value = 2 41 | else: 42 | res.value = 1 43 | 44 | return None 45 | 46 | 47 | 48 | def stp_check_time(sourcefilename, timeout, bv=64): 49 | """input the expression from the source file, then check the equation and output the time and memory of process to desination file. 50 | Args: 51 | sourcefilename: source file. 52 | """ 53 | desfilename = "{source}.stp.verify.{bv}bit.before.simplify.txt".format(source=sourcefilename, bv=bv) 54 | fwrite = open(desfilename, "w") 55 | comment = "#complex,groundtruth,stpres,verificationtime\n" 56 | fwrite.write(comment) 57 | 58 | with open(sourcefilename, "r") as data: 59 | linenum = 0 60 | for line in data: 61 | line = line.strip().replace(" ", "") 62 | if "#" not in line: 63 | expreStrList = re.split(",", line) 64 | sourceExpreStr = expreStrList[0] 65 | groundExpreStr = expreStrList[1] 66 | start = time.time() 67 | res = Value('i', 0) 68 | #res = verify_mba_unsat(sourceExpreStr, groundExpreStr, bv) 69 | p = Process(target=verify_mba_unsat, args=(sourceExpreStr, groundExpreStr, bv, res,)) 70 | p.start() 71 | p.join(timeout) # wait timeout seconds or it finishes 72 | 73 | if p.is_alive(): 74 | print("Still solving, but kill it as timeout set to", timeout, "seconds ...") 75 | p.terminate() 76 | p.join() 77 | 78 | result = { 79 | 0: "Timeout", 80 | 1: "True", 81 | 2: "False", 82 | } 83 | 84 | end = time.time() 85 | elapsed = end - start 86 | resultStr = "{source},{ground},{res},{vtime}\n".format(source=sourceExpreStr, ground=groundExpreStr, res=result[res.value], vtime=elapsed) 87 | fwrite.write(resultStr) 88 | fwrite.flush() 89 | 90 | # print linenum, sourceExpreStr, groundExpreStr, result[res.value], elapsed 91 | print linenum, result[res.value], "Time =", elapsed 92 | linenum += 1 93 | 94 | fwrite.close() 95 | return None 96 | 97 | 98 | 99 | def main(sourcefilename, timeout): 100 | stp_check_time(sourcefilename, timeout) 101 | 102 | 103 | 104 | if __name__ =="__main__": 105 | sourcefilename = sys.argv[1] 106 | timeout = int(sys.argv[2]) 107 | main(sourcefilename, timeout) 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /stp_solving/total.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import re 4 | import sys 5 | import time 6 | 7 | 8 | 9 | def total_simplify(smtsolver, solver): 10 | """count the solving number after solving by smt solver. 11 | """ 12 | true = 0 13 | false = 0 14 | timeout = 0 15 | 16 | if "mba" in solver: 17 | path = "../dataset" 18 | dataFile = ["linear", "poly", "nonpoly"] 19 | for data in dataFile: 20 | fileread = "{path}/pldi_dataset_{data}_MBA.txt.simplify.txt.{smtsolver}.verify.64bit.after.simplify.txt".format(path=path, data=data, smtsolver=smtsolver) 21 | with open(fileread, "r") as fr: 22 | for line in fr: 23 | line = line.strip().replace(" ", "") 24 | if "#" not in line: 25 | expreStrList = re.split(",", line) 26 | flag = expreStrList[4] 27 | if "ue" in flag: 28 | true += 1 29 | elif "out" in flag: 30 | timeout += 1 31 | else: 32 | false += 1 33 | elif "sspam" in solver: 34 | path = "../sspam" 35 | dataFile = ["linear", "poly", "nonpoly"] 36 | for data in dataFile: 37 | fileread = "{path}/{data}.MBA.SSPAM.result.txt.{smtsolver}.verify.64bit.after.simplify.txt".format(path=path, data=data, smtsolver=smtsolver) 38 | with open(fileread, "r") as fr: 39 | for line in fr: 40 | line = line.strip().replace(" ", "") 41 | if "#" not in line: 42 | expreStrList = re.split(",", line) 43 | flag = expreStrList[3] 44 | if "ue" in flag: 45 | true += 1 46 | elif "out" in flag: 47 | timeout += 1 48 | else: 49 | false += 1 50 | elif "syntia" in solver: 51 | path = "../syntia" 52 | dataFile = ["linear", "poly", "nonpoly"] 53 | for data in dataFile: 54 | fileread = "{path}/{data}.64bit.result.txt.{smtsolver}.verify.64bit.after.simplify.txt".format(path=path, data=data, smtsolver=smtsolver) 55 | with open(fileread, "r") as fr: 56 | for line in fr: 57 | line = line.strip().replace(" ", "") 58 | if "#" not in line: 59 | expreStrList = re.split(",", line) 60 | flag = expreStrList[3] 61 | if "ue" in flag: 62 | true += 1 63 | elif "out" in flag: 64 | timeout += 1 65 | else: 66 | false += 1 67 | total = true+false+timeout 68 | print("Total: ", total) 69 | print("True: ", true) 70 | print("False: ", false) 71 | print("Timeout: ", timeout) 72 | 73 | return None 74 | 75 | 76 | 77 | def total_original(smtsolver): 78 | """count the solving number before solving by smt solver. 79 | """ 80 | true = 0 81 | false = 0 82 | timeout = 0 83 | 84 | 85 | path = "../dataset" 86 | dataFile = ["linear", "poly", "nonpoly"] 87 | for data in dataFile: 88 | fileread = "{path}/pldi_dataset_{data}_MBA.txt.{smtsolver}.verify.64bit.before.simplify.txt".format(path=path, data=data, smtsolver=smtsolver) 89 | with open(fileread, "r") as fr: 90 | for line in fr: 91 | line = line.strip().replace(" ", "") 92 | if "#" not in line: 93 | expreStrList = re.split(",", line) 94 | flag = expreStrList[2] 95 | if "ue" in flag: 96 | true += 1 97 | elif "out" in flag: 98 | timeout += 1 99 | else: 100 | false += 1 101 | total = true+false+timeout 102 | print("Total: ", total) 103 | print("True: ", true) 104 | print("False: ", false) 105 | print("Timeout: ", timeout) 106 | 107 | return None 108 | 109 | 110 | 111 | 112 | 113 | def main(smtsolver, flag, solver=None): 114 | if flag: 115 | #after simplification 116 | total_simplify(smtsolver, solver) 117 | else: 118 | #before simplification 119 | total_original(smtsolver) 120 | 121 | 122 | 123 | if __name__ =="__main__": 124 | #smt solver 125 | smtsolver = sys.argv[1] 126 | #before/after simplification 127 | flag = int(sys.argv[2]) 128 | #if simplificationn, tools 129 | if len(sys.argv) > 3: 130 | solver = sys.argv[3] 131 | main(smtsolver, flag, solver) 132 | else: 133 | main(smtsolver, flag) 134 | 135 | 136 | -------------------------------------------------------------------------------- /syntia/linear.64bit.result.txt: -------------------------------------------------------------------------------- 1 | #original,correct,simplified,simplificationTrue/False,z3time 2 | ##all synthesis time:1261.83443284 3 | (x|y)+y-(~x&y),x+y,(y ^ x),False,0.0168790817261 4 | 3*(x&~y)-(x^y)+~x-~(x&y),x-y,(x - y),True,0.0121159553528 5 | -1*(~(x&y))+(x|y)-1*(x^y)-1*x+2*~x-1*(~(x&~y))-1*(~(x^y))-1*(x|~y)+3*(~(x|y))+1*(~(x|~y))+4*(x&~y)+4*(x&y),1*y+1*~y,(x + ((b + d) << y)),0,0,0,0,False,0 6 | -2*(~(x&y))-2*~y-2*~x+(~(x^y))-2*x-1*y-1*(x|y)+(x|~y)+6*(~(x|y))+8*(~(x|~y))+7*(x&~y)+4*(x&y),1*(~(x&~x))+1*(~(x&~y)),(((z | c) & 1) + a),False,0.0132389068604 7 | -1*(x|y)+(~(x&~y))+2*y-2*~y-1*~x-1*(~(x&~x))+(~(x^y))+x+2*(~(x|y))-1*(~(x|~y))+3*(x&~y)-2*(x&y),-(~(x&y))+1*(x|~y),(((a & b) & 1) + b),False,0.0200791358948 8 | -1*x-1*~y+4*(~(x&~x))-1*(~(x^y))+y-4*(~(x&y))-1*(~(x&~y))+2*(~(x|y))-1*(~(x|~y))+2*(x&~y)-2*(x&y),-~x,(- (~ x)),True,0.0118489265442 9 | (~(x&~x))+y-2*(x^y)-1*~y+x-1*(~(x&~y))-2*~x-3*(~(x|y))-2*(~(x|~y))-4*(x&~y)-3*(x&y),-5*(~(x&y))-(~(x^y)),(1 + (f << e)),0,0,0,0,False,0 10 | (~(x&y))+(x^y)-1*y+x-2*(x|~y)+2*(~(x&~y))+~y-1*(~(x^y))-1*(~(x|y))-4*(~(x|~y))-3*(x&~y),-(x|y),((x & t) + e),False,0.0133409500122 11 | -1*x-1*~x+4*(x|~y)-1*(~(x&~y))-1*~y-4*(x&~y)-1*(x&y),1*(~(x^y))-2*(x^y),(1 | c),False,0.0364170074463 12 | 2*~x+5*(~(x^y))-1*(~(x&y))+(x^y)+x-1*(~(x&~y))+(x|~y)-7*(~(x|y))-3*(~(x|~y))-3*(x&~y)-8*(x&y),-y-(~(x&~x)),(~ (- y)),False,0.0151410102844 13 | -3*~(x^y)-6*~y-2*(x^y)-7*~(x&y)+1*~(x&~x)+2*~(x&~y)-11*(x|~y)-6*x-2*y+24*~(x|y)+8*~(x|~y)+31*(x&~y),-19*(x&y),(- (~ c)),False,0.0134990215302 14 | 1*((x|y)&~(y^z))+1*~(x|(y|z))-2*~(~x|(y|z))-2*(x&(y&z)),1*(~x&(~y|z))-1*((x|~y)&(x^(y^z))),(((~ z) & 1) + y),False,0.0202009677887 15 | -3*(z^~(~x|(~y&z)))-1*(x&(~y|z))-4*~(x|(~y|z))-1*~(~x|(~y|z))+3*(~x&(~y&z))-1*(~x&(y&z))-3*(x&(y&z)),-4*(x|y),(((x | y) & a) + a),False,0.0231871604919 16 | 2*(y|~(x^z))-1*(~x&(~y|z))+2*~(x^(y|z))-3*~(x|(y|z))-2*~(x|(~y|z))+1*(~x&(~y&z))-4*(x&(~y&z))-4*(x&(y&z)),4*~(~x|(~y|z))+1*(~x&(y&z)),((t & a) + d),False,0.0159850120544 17 | 5*(~x&(y^z))+1*(x&(y^z))+1*((x&~y)|(x^(y^z)))-6*~(x|(~y|z))-1*~(~x|(y|z))-1*~(~x|(~y|z))-2*(x&(~y&z))-1*(x&(y&z)),6*(~x&(~y&z)),(((z >> a) & t) + t),0,0,0,0,False,0 18 | -7*((x^y)&~(x^z))+5*(~z|~(x^y))-3*~(x|(y|z))+4*~(x|(~y|z))-3*~(~x|(y|z))-3*~(~x|(~y|z))-3*(~x&(~y&z))+9*(x&(~y&z))-5*(x&(y&z)),2*~(y&z),(t + (c & 1)),False,0.0141570568085 19 | -3*~(y^z)+5*(z^(~x|(y|z)))-12*~(x|(y|z))-15*~(x|(~y|z))-8*~(~x|(y|z))-16*~(~x|(~y|z))-8*(~x&(y&z))+1*(x&(~y&z))+3*(x&(y&z)),1*(z^(~x|(y&z)))-11*(z^~(~x&(y&z))),((x & c) + x),False,0.0656371116638 20 | -2*(y|~z)+1*(x^y)+2*~(x|(y|z))+3*~(~x|(y|z))+4*~(~x|(~y|z))+2*(~x&(~y&z))+3*(~x&(y&z))-1*(x&(~y&z))+4*(x&(y&z)),2*(z^~(~x|(y&z)))-1*~(x|(~y|z)),((d & y) + y),False,0.0224850177765 21 | -1*((~(x^(~y&z))&~t)|((z^(~x|(y&z)))&t))+1*((((x&y)^(x^(y&z)))&~t)|(((x&~y)|~(y^z))&t))+1*(((z^~(x&y))&~t)|(((x|y)&~(x^(y^z)))&t))-2*~(~x|(y|(z|t)))-2*~(~x|(~y|(~z|t)))+1*(~x&(y&(~z&t)))-1*(x&(~y&(~z&t)))-2*(~x&(y&(z&t)))-1*(x&(y&(z&t))),1*(x&(y&(~z&t)))+1*(x&(~y&(z&t))),((d & z) + z),False,0.0196537971497 22 | 2*((((y&z)|(~x&(y|z)))&~t)|((y^~(x&(~y&z)))&t))-2*(((z^~(~x&(y|z)))&~t)|(((x|y)&~(y^z))&t))-2*(((z^~(x|(~y&z)))&~t)|(((x&y)^(x^(~y|z)))&t))-2*((((x^y)&(x^z))&~t)|((~(x|y)|~(y^z))&t))+4*~(x|(y|(z|t)))+4*~(~x|(y|(z|t)))+2*~(~x|(~y|(z|t)))+2*~(x|(y|(~z|t)))+2*~(x|(~y|(~z|t)))+2*~(~x|(y|(~z|t)))+2*(~x&(~y&(~z&t)))+2*(~x&(~y&(z&t)))+6*(~x&(y&(z&t)))+6*(x&(y&(z&t))),-2*(x&(~y&(~z&t))),(b + (a & f)),False,0.0122909545898 23 | 3*(((z^~(x|y))&~t)|((y^~(x&(y&z)))&t))+7*(((~y&~(x^z))&~t)|(~(x&~y)&t))+1*(((y^~(~x|(y&z)))&~t)|((x&~x)&t))-1*((~(x|(y|z))&~t)|((z^~(x|(~y&z)))&t))+2*((((x&z)^(x^(~y&z)))&~t)|(((x&y)^~(x^(y&z)))&t))-9*(((x^(y|z))&~t)|(((y&z)|(~x&(y|z)))&t))+1*(((y|(x&~z))&~t)|((~(x|y)|~(x^(y^z)))&t))-5*(((~(x^y)|~(x^z))&~t)|(((x|y)&(x^(y^z)))&t))-4*((((x|~y)&~(x^(y^z)))&~t)|((y|(x^z))&t))+9*(((y^~(x|(~y&z)))&~t)|((x&z)&t))-1*((((x&y)^(x^(~y|z)))&~t)|((z^~(x&~y))&t))-3*(((y^~(x&(y^z)))&~t)|((z^~(~x&(~y|z)))&t))+1*((~(~x&(y&z))&~t)|(~(x^(~y&z))&t))-4*(((x&~z)&~t)|((z&~(x^y))&t))+11*~(x|(~y|(z|t)))+11*~(~x|(y|(z|t)))+3*~(~x|(~y|(z|t)))+15*~(x|(y|(~z|t)))+5*~(x|(~y|(~z|t)))-9*~(~x|(~y|(~z|t)))-12*(~x&(~y&(~z&t)))+13*(~x&(y&(~z&t)))+15*(x&(~y&(~z&t)))+4*(x&(y&(~z&t)))+14*(~x&(~y&(z&t)))+13*(~x&(y&(z&t)))-12*(x&(~y&(z&t)))+10*(x&(y&(z&t))),-1*~(~x|(y|(~z|t)))+6*(((~y&~(x^z))&~t)|((z^~(~x|(y&z)))&t)),((1 & z) + z),False,0.0253689289093 24 | -------------------------------------------------------------------------------- /syntia/makefile: -------------------------------------------------------------------------------- 1 | linear-program-synthesis-64:testmcts.py 2 | python2 testmcts.py 64 ../dataset/pldi_dataset_linear_MBA.txt linear.syntia.64bit.middle.json 3 | 4 | linear-json-transformation-64: 5 | python2 transformation.py linear.syntia.64bit.middle.json linear.64bit.middle.txt 6 | 7 | linear-syntia-evaluation-64:linear-program-synthesis-64 linear-json-transformation-64 8 | python2 syntia-evaluation.py 64 linear.64bit.middle.txt linear.64bit.result.txt 9 | 10 | poly-program-synthesis-64:testmcts.py 11 | python2 testmcts.py 64 ../dataset/pldi_dataset_poly_MBA.txt poly.syntia.64bit.middle.json 12 | 13 | poly-json-transformation-64: 14 | python2 transformation.py poly.syntia.64bit.middle.json poly.64bit.middle.txt 15 | 16 | poly-syntia-evaluation-64:poly-program-synthesis-64 poly-json-transformation-64 17 | python2 syntia-evaluation.py 64 poly.64bit.middle.txt poly.64bit.result.txt 18 | 19 | nonpoly-program-synthesis-64:testmcts.py 20 | python2 testmcts.py 64 ../dataset/pldi_dataset_nonpoly_MBA.txt nonpoly.syntia.64bit.middle.json 21 | 22 | nonpoly-json-transformation-64: 23 | python2 transformation.py nonpoly.syntia.64bit.middle.json nonpoly.64bit.middle.txt 24 | 25 | nonpoly-syntia-evaluation-64:nonpoly-program-synthesis-64 nonpoly-json-transformation-64 26 | python2 syntia-evaluation.py 64 nonpoly.64bit.middle.txt nonpoly.64bit.result.txt 27 | 28 | syntia-simplify: 29 | @echo "------------syntia simplify linear MBA samples-------------------" 30 | @make linear-syntia-evaluation-64 31 | @echo "------------syntia simplify linear MBA samples completion--------" 32 | @echo "------------syntia simplify poly MBA samples-------------------" 33 | @make poly-syntia-evaluation-64 34 | @echo "------------syntia simplify poly MBA samples completion--------" 35 | @echo "------------syntia simplify nonpoly MBA samples-------------------" 36 | @make nonpoly-syntia-evaluation-64 37 | @echo "------------syntia simplify nonpoly MBA samples completion--------" 38 | -------------------------------------------------------------------------------- /syntia/mcts_synthesis/grammar.py: -------------------------------------------------------------------------------- 1 | from collections import OrderedDict 2 | from orderedset import OrderedSet 3 | 4 | OP1 = OrderedSet(["bvnot", 5 | "bvneg", 6 | ]) 7 | OP2 = OrderedSet(["bvadd", 8 | "bvsub", 9 | "bvmul", 10 | "bvudiv", 11 | "bvsdiv", 12 | "bvurem", 13 | "bvsrem", 14 | "bvshl", 15 | "bvlshr", 16 | "bvashr", 17 | "bvand", 18 | "bvor", 19 | "bvxor", 20 | "zero_extend", 21 | "bvconcat", 22 | ]) 23 | 24 | OP3 = OrderedSet(["bvextract", 25 | "sign_extend" 26 | ]) 27 | 28 | COMMUTATIVE_OPS = OrderedSet(["bvadd", 29 | "bvmul", 30 | "bvand", 31 | "bvor", 32 | "bvxor"]) 33 | 34 | NON_TERMINALS = OrderedSet(["u8", 35 | "u16", 36 | "u32", 37 | "u64", 38 | ]) 39 | 40 | 41 | class Grammar(object): 42 | def __init__(self, variables, constants=OrderedSet(), bitsize=64): 43 | self.variables = OrderedDict([(v.name, v.size) for v in variables]) 44 | self.constants = constants 45 | self.bit_sizes = self.gen_sizes(bitsize) 46 | 47 | self.terminals = OrderedSet([v.name for v in variables] + list(constants)) 48 | self.non_terminals = OrderedSet(["u{}".format(size) for size in self.bit_sizes]) 49 | 50 | self.op1 = OP1.copy() 51 | self.op2 = OP2.copy() 52 | self.op3 = OP3.copy() 53 | self.commutative_ops = COMMUTATIVE_OPS.copy() 54 | 55 | self.rules = self.gen_rules() 56 | 57 | def gen_sizes(self, bit_size): 58 | sizes = set([bit_size]) 59 | for v in self.variables: 60 | size = self.variables[v] 61 | sizes.add(size) 62 | return list(sizes) 63 | 64 | def gen_rules(self): 65 | rules = OrderedDict() 66 | for index in xrange(len(self.bit_sizes)): 67 | size = self.bit_sizes[index] 68 | non_terminal = self.non_terminals[index] 69 | rules[non_terminal] = self.gen_size_rules(size) 70 | 71 | return rules 72 | 73 | def gen_size_rules(self, size): 74 | rules = OrderedSet() 75 | 76 | rules.add("{} u{} u{} bvadd".format(size, size, size)) 77 | rules.add("{} u{} u{} bvsub".format(size, size, size)) 78 | rules.add("{} u{} u{} bvmul".format(size, size, size)) 79 | rules.add("{} {} u{} u{} bvconcat u{} bvudiv".format(size, size, size, size, size)) 80 | rules.add("{} {} u{} u{} bvconcat u{} bvsdiv".format(size, size, size, size, size)) 81 | rules.add("{} {} u{} u{} bvconcat u{} bvurem".format(size, size, size, size, size)) 82 | rules.add("{} {} u{} u{} bvconcat u{} bvsrem".format(size, size, size, size, size)) 83 | # rules.add("{} u{} u{} bvudiv".format(size, size, size)) 84 | # rules.add("{} u{} u{} bvsdiv".format(size, size, size)) 85 | # rules.add("{} u{} u{} bvurem".format(size, size, size)) 86 | # rules.add("{} u{} u{} bvsrem".format(size, size, size)) 87 | rules.add("{} u{} u{} bvshl".format(size, size, size)) 88 | rules.add("{} u{} u{} bvlshr".format(size, size, size)) 89 | rules.add("{} u{} u{} bvashr".format(size, size, size)) 90 | rules.add("{} u{} u{} bvand".format(size, size, size)) 91 | rules.add("{} u{} u{} bvor".format(size, size, size)) 92 | rules.add("{} u{} u{} bvxor".format(size, size, size)) 93 | rules.add("{} u{} bvnot".format(size, size)) 94 | rules.add("{} u{} bvneg".format(size, size)) 95 | 96 | if size == 64: 97 | # movzx 98 | if 32 in self.bit_sizes: 99 | rules.add("32 64 u32 zero_extend") 100 | if 16 in self.bit_sizes: 101 | rules.add("16 64 u16 zero_extend") 102 | if 8 in self.bit_sizes: 103 | rules.add("8 64 u8 zero_extend") 104 | # movsx 105 | if 32 in self.bit_sizes: 106 | rules.add("32 64 32 u32 sign_extend") 107 | if 16 in self.bit_sizes: 108 | rules.add("16 64 16 u16 sign_extend") 109 | if 8 in self.bit_sizes: 110 | rules.add("8 64 8 u8 sign_extend") 111 | # concat 112 | if 32 in self.bit_sizes: 113 | rules.add("32 u32 u32 bvconcat") 114 | if size == 32: 115 | # movzx 116 | if 16 in self.bit_sizes: 117 | rules.add("16 32 u16 zero_extend".format(size)) 118 | if 8 in self.bit_sizes: 119 | rules.add("8 32 u8 zero_extend".format(size)) 120 | # movsx 121 | if 16 in self.bit_sizes: 122 | rules.add("16 32 16 u16 sign_extend") 123 | if 8 in self.bit_sizes: 124 | rules.add("8 32 8 u8 sign_extend") 125 | # extract 126 | if 64 in self.bit_sizes: 127 | rules.add("64 u64 0 31 bvextract") 128 | # concat 129 | if 16 in self.bit_sizes: 130 | rules.add("16 u16 u16 bvconcat") 131 | if size == 16: 132 | # movzx 133 | if 8 in self.bit_sizes: 134 | rules.add("8 16 u8 zero_extend".format(size)) 135 | # movsx 136 | if 8 in self.bit_sizes: 137 | rules.add("8 16 8 u8 sign_extend") 138 | # extract 139 | if 64 in self.bit_sizes: 140 | rules.add("64 u64 0 15 bvextract") 141 | if 32 in self.bit_sizes: 142 | rules.add("32 u32 0 15 bvextract") 143 | # concat 144 | if 8 in self.bit_sizes: 145 | rules.add("8 u8 u8 bvconcat") 146 | if size == 8: 147 | # extract 148 | if 64 in self.bit_sizes: 149 | rules.add("64 u64 0 7 bvextract") 150 | rules.add("64 u64 8 15 bvextract") 151 | if 32 in self.bit_sizes: 152 | rules.add("32 u32 0 7 bvextract") 153 | rules.add("32 u32 8 15 bvextract") 154 | if 16 in self.bit_sizes: 155 | rules.add("16 u16 0 7 bvextract") 156 | rules.add("16 u16 8 15 bvextract") 157 | 158 | for v in self.variables: 159 | if self.variables[v] == size: 160 | rules.add(v) 161 | 162 | for c in self.constants: 163 | rules.add(c) 164 | 165 | return rules 166 | 167 | def dump(self): 168 | """ 169 | Dumps state to a nested dict 170 | :return: dict 171 | """ 172 | ret = OrderedDict() 173 | ret["variables"] = list(self.variables) 174 | ret["constants"] = list(self.constants) 175 | ret["terminals"] = list(self.terminals) 176 | ret["non_terminals"] = list(self.non_terminals) 177 | ret["op1"] = list(self.op1) 178 | ret["op2"] = list(self.op2) 179 | ret["commutative_ops"] = list(self.commutative_ops) 180 | ret["u64_rules"] = list(self.u64_rules) 181 | 182 | return ret 183 | -------------------------------------------------------------------------------- /syntia/mcts_synthesis/mcts_synthesis_multi_core.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from z3 import simplify 3 | from mcts import * 4 | from game import Game, Variable 5 | from grammar import Grammar 6 | from mctsutils import get_random_inputs 7 | from paralleliser import Paralleliser 8 | 9 | BITSIZE = 32 10 | MAX_UNSIGNED = 2 ** BITSIZE 11 | 12 | if len(sys.argv) < 2: 13 | max_iter = 30000 14 | else: 15 | max_iter = int(sys.argv[1]) 16 | 17 | if len(sys.argv) < 3: 18 | uct_scalar = 1.2 19 | else: 20 | uct_scalar = float(sys.argv[2]) 21 | 22 | 23 | def oracle(args): 24 | x = args[0] 25 | y = args[1] 26 | z = args[2] 27 | return (x + x + x) % MAX_UNSIGNED 28 | # return ((x + y) - (x * z)) % MAX_UNSIGNED 29 | 30 | 31 | def synthesise(command, result, index): 32 | ret = "" 33 | 34 | max_iter = command[0] 35 | uct_scalar = command[1] 36 | game = command[2] 37 | oracle = command[3] 38 | synthesis_inputs = command[4] 39 | 40 | mc = MCTS(game, oracle, synthesis_inputs, uct_scalar=uct_scalar) 41 | mc.verbosity_level = 1 42 | s = State(game, BITSIZE) 43 | 44 | mc.search(s, max_iter) 45 | 46 | if mc.final_expression: 47 | ret = rpn_to_infix(mc.final_expression) 48 | print "{} ({} iterations)".format(rpn_to_infix(mc.final_expression), mc.current_iter) 49 | try: 50 | simplified = simplify(game.to_z3(mc.final_expression)) 51 | print "{} (simplified)".format(simplified) 52 | except: 53 | pass 54 | 55 | result[index] = ret 56 | 57 | 58 | variables = [] 59 | for var_index in xrange(3): 60 | v = Variable("V.{}".format(var_index), BITSIZE) 61 | variables.append(v) 62 | 63 | constants = OrderedSet(["1"]) 64 | 65 | grammar = Grammar(variables, constants=constants) 66 | 67 | game = Game(grammar, variables, bitsize=BITSIZE) 68 | 69 | task_groups = [] 70 | workers = [] 71 | commands = [] 72 | 73 | for index in xrange(1): 74 | task_group = "TG" 75 | task_groups.append(task_group) 76 | 77 | # this may take some time 78 | synthesis_inputs = get_random_inputs(len(variables), 20) 79 | 80 | command = [max_iter, uct_scalar, game, oracle, synthesis_inputs] 81 | 82 | workers.append(synthesise) 83 | commands.append(command) 84 | 85 | number_of_tasks = len(commands) 86 | 87 | print "Starting main synthesis" 88 | print number_of_tasks 89 | 90 | paralleliser = Paralleliser(commands, workers, number_of_tasks, task_groups) 91 | 92 | start_time = time() 93 | paralleliser.execute() 94 | 95 | end_time = time() 96 | 97 | print "Synthesis finished in {} seconds".format(end_time - start_time) 98 | -------------------------------------------------------------------------------- /syntia/mcts_synthesis/metrics.py: -------------------------------------------------------------------------------- 1 | from __future__ import division 2 | 3 | 4 | def bitcount(v): 5 | """ 6 | Number of set bits in v 7 | :param v: int 8 | :return: int 9 | """ 10 | return bin(v).count("1") 11 | 12 | 13 | def leading_zeros(v, bitsize): 14 | """ 15 | Count leading zeros 16 | :param v: int 17 | :param bitsize: bit length 18 | :return: int, leading zeros of v 19 | """ 20 | # padd bit string 21 | s = format(v, "0{}b".format(bitsize)) 22 | 23 | return len(s) - len(s.lstrip('0')) 24 | 25 | 26 | def trailing_zeros(v, bitsize): 27 | """ 28 | Count trailing zeros 29 | :param v: int 30 | :param bitsize: int 31 | :return: int, leading zeros of v 32 | """ 33 | # padd bit string 34 | s = format(v, "0{}b".format(bitsize)) 35 | 36 | return len(s) - len(s.rstrip('0')) 37 | 38 | 39 | def leading_ones(v, bitsize): 40 | """ 41 | Count leading ones 42 | :param v: int 43 | :param bitsize: bit length 44 | :return: int, leading ones of v 45 | """ 46 | # padd bit string 47 | s = format(v, "0{}b".format(bitsize)) 48 | 49 | return len(s) - len(s.lstrip('1')) 50 | 51 | 52 | def trailing_ones(v, bitsize): 53 | """ 54 | Count trailing zeros 55 | :param v: int 56 | :param bitsize: int 57 | :return: int, leading ones of v 58 | """ 59 | # padd bit string 60 | s = format(v, "0{}b".format(bitsize)) 61 | 62 | return len(s) - len(s.rstrip('1')) 63 | 64 | 65 | def num_distance(a, b): 66 | """ 67 | Numeric distance of a and b 68 | :param a: int 69 | :param b: int 70 | :return: int 71 | """ 72 | return abs(a - b) 73 | 74 | 75 | def rotate_left(a, b, size): 76 | """ 77 | Rotates bits of a to the left b times 78 | 79 | :param a: int to shift 80 | :param b: int, number of shifts 81 | :param size: bit length 82 | :return: int 83 | """ 84 | shift = b & (size - 1) 85 | return ((a << shift) | (a >> size - shift)) % 2 ** size 86 | 87 | 88 | def metric_hamming_distance(a, b, bitsize): 89 | """ 90 | Hamming distance 91 | :param a: int 92 | :param b: int 93 | :param bitsize: int 94 | :return: flaot 95 | """ 96 | n = bitcount(a ^ b) 97 | return 1 - (n / bitsize) 98 | 99 | 100 | def metric_leading_zeros(a, b, bitsize): 101 | """ 102 | Numeric difference of the leading 103 | zeros from a and b 104 | :param a: int 105 | :param b: int 106 | :param bitsize: int 107 | :return: float 108 | """ 109 | # leading zeros 110 | a = leading_zeros(a, bitsize) 111 | b = leading_zeros(b, bitsize) 112 | 113 | # numeric difference 114 | n = abs(a - b) 115 | 116 | return 1 - float(n / bitsize) 117 | 118 | 119 | def metric_trailing_zeros(a, b, bitsize): 120 | """ 121 | Numeric difference of the trailing 122 | zeros from a and b 123 | :param a: int 124 | :param b: int 125 | :param bitsize: int 126 | :return: float 127 | """ 128 | # leading zeros 129 | a = trailing_zeros(a, bitsize) 130 | b = trailing_zeros(b, bitsize) 131 | 132 | # numeric difference 133 | n = abs(a - b) 134 | 135 | return 1 - float(n / bitsize) 136 | 137 | 138 | def metric_leading_ones(a, b, bitsize): 139 | """ 140 | Numeric difference of the leading 141 | ones from a and b 142 | :param a: int 143 | :param b: int 144 | :param bitsize: int 145 | :return: float 146 | """ 147 | # leading ones 148 | a = leading_ones(a, bitsize) 149 | b = leading_ones(b, bitsize) 150 | 151 | # numeric difference 152 | n = abs(a - b) 153 | 154 | return 1 - float(n / bitsize) 155 | 156 | 157 | def metric_trailing_ones(a, b, bitsize): 158 | """ 159 | Numeric difference of the trailing 160 | ones from a and b 161 | :param a: int 162 | :param b: int 163 | :param bitsize: int 164 | :return: float 165 | """ 166 | # trailing ones 167 | a = trailing_ones(a, bitsize) 168 | b = trailing_ones(b, bitsize) 169 | 170 | # numeric difference 171 | n = abs(a - b) 172 | 173 | return 1 - float(n / bitsize) 174 | 175 | 176 | def metric_num_distance(a, b): 177 | """ 178 | Numeric distance of a and b. 179 | Normalised with their local 180 | maximum. 181 | :param a: int 182 | :param b: int 183 | :return: float 184 | """ 185 | # numeric distance 186 | d = num_distance(a, b) 187 | 188 | # avoid division by 0 189 | if a == b: 190 | return 1 191 | else: 192 | # maximum of a and b 193 | maximum = max([abs(a), abs(b)]) 194 | return 1 - (d / maximum) 195 | 196 | 197 | def distance_metric(a, b, bitsize): 198 | """ 199 | Combines different distance metrics 200 | :param a: int 201 | :param b: int 202 | :param bitsize: int 203 | :return: float 204 | """ 205 | # initial score 206 | score = 0.0 207 | 208 | # apply metrics 209 | for x, y in [(a, b)]: 210 | score += metric_hamming_distance(x, y, bitsize) 211 | score += metric_leading_zeros(x, y, bitsize) 212 | score += metric_trailing_zeros(x, y, bitsize) 213 | score += metric_leading_ones(x, y, bitsize) 214 | score += metric_trailing_ones(x, y, bitsize) 215 | score += metric_num_distance(x, y) 216 | 217 | # normalise weights 218 | d = score / 6 219 | 220 | return d 221 | -------------------------------------------------------------------------------- /syntia/mcts_synthesis/paralleliser.py: -------------------------------------------------------------------------------- 1 | import multiprocessing 2 | from random import choice, shuffle 3 | 4 | 5 | class Paralleliser(object): 6 | def __init__(self, commands, workers, number_of_tasks, task_groups, number_of_cpus=0): 7 | self.commands = commands 8 | self.workers = workers 9 | self.number_of_tasks = number_of_tasks 10 | self.task_groups = task_groups 11 | 12 | self.process_to_task_group = dict() 13 | self.process_to_task_id = dict() 14 | self.task_group_results = dict() 15 | 16 | if not number_of_cpus: 17 | number_of_cpus = multiprocessing.cpu_count() 18 | self.number_of_cpus = number_of_cpus 19 | 20 | def execute(self): 21 | # initialise parallel data structures 22 | manager = multiprocessing.Manager() 23 | results = manager.list() 24 | processes = [None] * self.number_of_tasks 25 | 26 | # set task_groups to not-finished 27 | task_group_states = {} 28 | for task in self.task_groups: 29 | task_group_states[task] = 0 30 | 31 | # initialise process mappings 32 | process_to_task_group = dict() 33 | process_to_index = dict() 34 | 35 | # initialise processes 36 | for i in range(len(processes)): 37 | # extend results 38 | results.append(None) 39 | 40 | # get command 41 | command = self.commands[i] 42 | 43 | # create process 44 | processes[i] = multiprocessing.Process(target=self.workers[i], args=(command, results, i)) 45 | 46 | # map process to process index 47 | process_to_index[processes[i]] = i 48 | 49 | # choose task group randomly 50 | process_to_task_group[processes[i]] = self.task_groups[i] 51 | 52 | # initialise data structures 53 | active_processes = set() 54 | done = set() 55 | process_counter = -1 56 | 57 | # random permutation of process indexes 58 | random_process_indices = list(range(len(processes))) 59 | shuffle(random_process_indices) 60 | 61 | # iterate until all processes have been processed 62 | while len(done) < len(processes): 63 | # add more processes, if # processes < # cpu cores and there are processes remaining 64 | while len(active_processes) < self.number_of_cpus and process_counter < len(processes) - 1: 65 | # increase index 66 | process_counter += 1 67 | # random process index 68 | random_process_index = random_process_indices.pop() 69 | # get next process 70 | process = processes[random_process_index] 71 | 72 | # get process' task group 73 | task_group = process_to_task_group[process] 74 | 75 | # print random_process_index, task_group 76 | 77 | # process' taskgroup has been solved 78 | if task_group_states[task_group]: 79 | done.add(process) 80 | 81 | # get next process 82 | if process in done: 83 | continue 84 | 85 | # start process 86 | process.start() 87 | 88 | # add to active processes 89 | active_processes.add(process) 90 | 91 | # if there are active processes 92 | if active_processes: 93 | # choose random process 94 | process = choice(list(active_processes.copy())) 95 | 96 | # process has been terminated 97 | if not process.is_alive(): 98 | # get process index 99 | process_index = process_to_index[process] 100 | # get result 101 | result = results[process_index] 102 | 103 | # if process terminated with a result: 104 | if result: 105 | # get process' task group 106 | task_group = process_to_task_group[process] 107 | # set task group to finished 108 | task_group_states[task_group] = 1 109 | 110 | # store task group's result 111 | self.task_group_results[task_group] = result 112 | 113 | # terminate active processes in current task group 114 | for process in active_processes.copy(): 115 | # process is in the same task group? 116 | if task_group == process_to_task_group[process]: 117 | # kill process 118 | process.terminate() 119 | # add to done 120 | done.add(process) 121 | # remove from active processes 122 | active_processes.remove(process) 123 | 124 | # delete process 125 | else: 126 | # add to done 127 | done.add(process) 128 | # remove from active processes 129 | active_processes.remove(process) 130 | 131 | return results -------------------------------------------------------------------------------- /syntia/mcts_synthesis/sample_synthesis.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from orderedset import OrderedSet 3 | from collections import OrderedDict 4 | 5 | from sampling_synthesis_helpers import AssemblyOracleSynthesizer, worker_synthesize_from_assembly_oracle 6 | from utils import dump_to_json 7 | 8 | # check stdin 9 | if len(sys.argv) < 3: 10 | print "[*] Syntax: " 11 | sys.exit(0) 12 | 13 | # parse stdin 14 | sampling_file_path = sys.argv[1] 15 | output_file = sys.argv[2] 16 | 17 | # constants for program synthesizer 18 | constants = OrderedSet(["1", "0"]) 19 | 20 | assembly_synthesizer = AssemblyOracleSynthesizer(sampling_file_path, constants) 21 | 22 | # init lists for parallel synthesis 23 | worker_parameters = [] 24 | workers = [] 25 | task_groups = [] 26 | 27 | # walk over outputs 28 | for output_number in xrange(assembly_synthesizer.number_of_outputs): 29 | # prepare output configuration 30 | parameters, task_group = assembly_synthesizer.prepare_output_synthesis(output_number) 31 | 32 | worker_parameters.append(parameters) 33 | workers.append(worker_synthesize_from_assembly_oracle) 34 | task_groups.append(task_group) 35 | 36 | # start parallel synthesis 37 | synthesis_results = assembly_synthesizer.synthesize_parallel(worker_parameters, workers, task_groups) 38 | 39 | # prepare output 40 | results = OrderedDict() 41 | for index in xrange(len(synthesis_results)): 42 | results[index] = synthesis_results[index] 43 | 44 | # write to json file 45 | dump_to_json(output_file, results) 46 | 47 | -------------------------------------------------------------------------------- /syntia/mcts_synthesis/sampling_synthesis_helpers.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | from grammar import Grammar 4 | from paralleliser import Paralleliser 5 | from mcts import * 6 | from game import Game, Variable 7 | from grammar import Grammar 8 | from paralleliser import Paralleliser 9 | from mctsutils import * 10 | from z3 import simplify 11 | from orderedset import OrderedSet 12 | 13 | 14 | def parse_sampling_data(file_path): 15 | # load json file 16 | json_dump = json.load(open(file_path), object_pairs_hook=OrderedDict) 17 | 18 | # initialise 19 | data = OrderedDict() 20 | sampling_data = json_dump["sampling"] 21 | inputs = [] 22 | outputs = [] 23 | 24 | # 25 | initial_inputs = name_value_and_size(json_dump["initial"]["inputs"]) 26 | initial_outputs = name_value_and_size(json_dump["initial"]["outputs"]) 27 | 28 | # single iteration 29 | for iteration in sampling_data: 30 | # get inputs and outputs 31 | current_inputs = value_and_size(sampling_data[iteration]["inputs"]) 32 | current_outputs = value_and_size(sampling_data[iteration]["outputs"]) 33 | 34 | # verify if inputs/outputs are usable 35 | if not (verify(current_inputs, initial_inputs) and verify(current_outputs, initial_outputs)): 36 | continue 37 | 38 | # add to list 39 | inputs.append(current_inputs) 40 | outputs.append(current_outputs) 41 | 42 | # set inputs/outputs 43 | data["initial_inputs"] = initial_inputs 44 | data["initial_outputs"] = initial_outputs 45 | data["sampling_inputs"] = inputs 46 | data["sampling_outputs"] = outputs 47 | 48 | return data 49 | 50 | 51 | def gen_variables(inputs): 52 | """ 53 | Generates variables from inputs 54 | :param inputs: list 55 | :return: list 56 | """ 57 | # initialise 58 | variables = [] 59 | # iterate inputs 60 | for index in xrange(len(inputs)): 61 | # parse 62 | size = inputs[index][1] 63 | v_name = inputs[index][2] 64 | # create variable 65 | v = Variable(v_name, size=size * 8) 66 | # add to list 67 | variables.append(v) 68 | 69 | return variables 70 | 71 | 72 | def value_and_size(data): 73 | """ 74 | Parses tuples of (value, size) 75 | :param data: json dict 76 | :return: list of tuples 77 | """ 78 | ret = [] 79 | for index in data: 80 | value = int(data[index]["value"], 16) 81 | size = int(data[index]["size"], 16) 82 | current_result = (value, size) 83 | ret.append(current_result) 84 | return ret 85 | 86 | 87 | def name_value_and_size(data): 88 | """ 89 | Parses tuples of (value, size, name) 90 | :param data: json dict 91 | :return: list of tuples 92 | """ 93 | ret = [] 94 | for index in data: 95 | name = data[index]["location"] 96 | try: 97 | name = int(name, 16) 98 | name = "M.{}".format(name) 99 | except: 100 | name = str(name) 101 | value = int(data[index]["value"], 16) 102 | size = int(data[index]["size"], 16) 103 | current_result = (value, size, name) 104 | ret.append(current_result) 105 | return ret 106 | 107 | 108 | def verify(current, original): 109 | """ 110 | Verifies that current values are usable 111 | :param current: current {in,out}puts 112 | :param original: original {in,out}puts 113 | :return: True/False 114 | """ 115 | # check length 116 | if len(current) != len(original): 117 | return False 118 | if not current: 119 | return False 120 | 121 | # check size of elements 122 | for index in xrange(len(current)): 123 | if current[index][1] != original[index][1]: 124 | return False 125 | 126 | return True 127 | 128 | 129 | def inputs_without_size(arguments): 130 | """ 131 | Strips the size from inputs 132 | :param arguments: list of inputs 133 | :return: list of inputs without size 134 | """ 135 | # initialise 136 | ret = [] 137 | # walk over inputs 138 | for args in arguments: 139 | # strip size 140 | args = [x[0] for x in args] 141 | # add to list 142 | ret.append(args) 143 | return ret 144 | 145 | 146 | class AssemblyOracleSynthesizer: 147 | def __init__(self, json_file, constants): 148 | self.sampling_data = parse_sampling_data(json_file) 149 | 150 | self.inital_inputs = self.sampling_data["initial_inputs"] 151 | self.inital_outputs = self.sampling_data["initial_outputs"] 152 | self.number_of_outputs = len(self.inital_outputs) 153 | 154 | self.sampling_inputs = inputs_without_size(self.sampling_data["sampling_inputs"]) 155 | self.sampling_outputs = self.sampling_data["sampling_outputs"] 156 | 157 | self.variables = gen_variables(self.inital_inputs) 158 | self.variables_grammar = OrderedSet([v.name for v in self.variables]) 159 | 160 | # constants 161 | self.constants = constants 162 | 163 | def prepare_output_synthesis(self, output_index, uct_scalar=1.2, max_mcts_rounds=20000, 164 | playout_depth=0): 165 | """ 166 | Prepares the MTS configuration for an given output number. MCTS configuration is pre-defined per default. 167 | :param output_index: output number 168 | :param uct_scalar: uct scalar for MCTS 169 | :param max_mcts_rounds: number of mcts rounds 170 | :param playout_depth: playout depth 171 | :return: 172 | """ 173 | # output details 174 | output_name = self.inital_outputs[output_index][2] 175 | output_bitsize = self.inital_outputs[output_index][1] 176 | 177 | # task group 178 | task_group = "TG.{}".format(output_index) 179 | 180 | # get sampling outputs 181 | current_outputs = [out[output_index][0] for out in self.sampling_outputs] 182 | 183 | # define grammar 184 | grammar = Grammar(self.variables, constants=self.constants, bitsize=output_bitsize * 8) 185 | # synthesis command 186 | configuration = [self.variables, grammar, uct_scalar, max_mcts_rounds, playout_depth, output_name, output_index, 187 | output_bitsize, self.sampling_inputs, current_outputs] 188 | 189 | return configuration, task_group 190 | 191 | @staticmethod 192 | def synthesize_parallel(worker_parameters, workers, task_groups): 193 | number_of_tasks = len(worker_parameters) 194 | paralleliser = Paralleliser(worker_parameters, workers, number_of_tasks, task_groups) 195 | 196 | # filter None instances 197 | return [r for r in paralleliser.execute() if r] 198 | 199 | 200 | def oracle(args): 201 | """ 202 | Synthesis oracle 203 | :param args: list of inputs 204 | :return: output 205 | """ 206 | # initialise 207 | global in_out_map 208 | 209 | # calc hash 210 | args_sha1 = to_sha1(str(args).replace("L", "")) 211 | 212 | # return output 213 | return in_out_map[args_sha1] 214 | 215 | 216 | def worker_synthesize_from_assembly_oracle(commands, result, worker_index): 217 | # initialise 218 | global in_out_map 219 | 220 | # parse synthesis parameters 221 | variables = commands[0] 222 | grammar = commands[1] 223 | utc_scalar = commands[2] 224 | max_mcts_rounds = commands[3] 225 | playout_depth = commands[4] 226 | output_name = commands[5] 227 | output_index = commands[6] 228 | output_bitsize = commands[7] 229 | synthesis_inputs = commands[8] 230 | synthesis_outputs = commands[9] 231 | 232 | # fill in/out map 233 | in_out_map = dict() 234 | for index in xrange(len(synthesis_inputs)): 235 | current_inputs_sha1 = to_sha1(str(synthesis_inputs[index]).replace("L", "")) 236 | in_out_map[current_inputs_sha1] = synthesis_outputs[index] 237 | 238 | # init mcts 239 | game = Game(grammar, variables, bitsize=output_bitsize * 8) 240 | s = State(game, output_bitsize * 8) 241 | 242 | mc = MCTS(game, oracle, synthesis_inputs, uct_scalar=utc_scalar) 243 | mc.playout_nesting = playout_depth 244 | mc.verbosity_level = 0 245 | 246 | # start synthesis 247 | mc.search(s, max_mcts_rounds) 248 | 249 | # prepare output json 250 | ret = OrderedDict() 251 | 252 | ret["output"] = OrderedDict() 253 | ret["output"]["name"] = output_name 254 | ret["output"]["number"] = output_index 255 | ret["output"]["size"] = output_bitsize * 8 256 | 257 | # top non-terminal 258 | ret["top_non_terminal"] = OrderedDict() 259 | ret["top_non_terminal"]["expression"] = OrderedDict() 260 | ret["top_non_terminal"]["expression"]["infix"] = rpn_to_infix(mc.top_non_terminal_node.state.expr) 261 | ret["top_non_terminal"]["reward"] = mc.top_non_terminal_reward 262 | 263 | # top terminal 264 | ret["top_terminal"] = OrderedDict() 265 | ret["top_terminal"]["expression"] = OrderedDict() 266 | expr = mc.top_terminal_node.state.expr if not mc.final_expression else mc.final_expression 267 | reward = mc.top_terminal_reward if not mc.final_expression else 1.0 268 | ret["top_terminal"]["expression"]["infix"] = rpn_to_infix(expr) 269 | ret["top_terminal"]["reward"] = reward 270 | 271 | # synthesis results 272 | ret["successful"] = "yes" if mc.final_expression else "no" 273 | if mc.final_expression: 274 | ret["result"] = OrderedDict() 275 | ret["result"]["final_expression"] = OrderedDict() 276 | ret["result"]["final_expression"]["infix"] = rpn_to_infix(mc.final_expression) 277 | try: 278 | ret["result"]["final_expression"]["simplified"] = str(simplify(game.to_z3(mc.final_expression))) 279 | except: 280 | ret["result"]["final_expression"]["simplified"] = rpn_to_infix(mc.final_expression) 281 | 282 | # store return value 283 | result[worker_index] = ret 284 | -------------------------------------------------------------------------------- /syntia/mcts_synthesis/transform_manual_sampling_io_pairs.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import json 3 | from collections import OrderedDict 4 | from utils import to_json 5 | 6 | 7 | def build_arguments(data): 8 | ret = OrderedDict() 9 | for number in data: 10 | ret[number] = build_argument(data[number]["location"], data[number]["size"], "0x0") 11 | return ret 12 | 13 | def build_argument(location, size, value): 14 | ret = OrderedDict() 15 | ret["location"] = location 16 | ret["size"] = size 17 | ret["value"] = value 18 | return ret 19 | 20 | def build_sampling_args(values, args): 21 | assert(len(values) == len(args)) 22 | ret = OrderedDict() 23 | for index in args: 24 | ret[index] = args[index].copy() 25 | ret[index]["value"] = values[int(index)] 26 | 27 | return ret 28 | 29 | def build_sampling(data, inputs, outputs): 30 | ret = OrderedDict() 31 | for index in xrange(len(data)): 32 | ret[str(index)] = OrderedDict() 33 | ret[str(index)]["inputs"] = build_sampling_args(data[index][:len(inputs)], inputs) 34 | ret[str(index)]["outputs"] = build_sampling_args(data[index][len(inputs):], outputs) 35 | 36 | return ret 37 | 38 | def transform_sampling_data(data): 39 | ret = OrderedDict() 40 | ret["initial"] = OrderedDict() 41 | ret["initial"]["inputs"] = build_arguments(data["inputs"]) 42 | ret["initial"]["outputs"] = build_arguments(data["outputs"]) 43 | ret["sampling"] = build_sampling(data["samples"], ret["initial"]["inputs"], ret["initial"]["outputs"]) 44 | 45 | return ret 46 | 47 | if len(sys.argv) != 3: 48 | print "[*] Syntax: " 49 | exit() 50 | 51 | input_file_path = sys.argv[1] 52 | output_file_path = sys.argv[2] 53 | 54 | data = json.load(open(input_file_path), object_pairs_hook=OrderedDict) 55 | 56 | open(output_file_path, "wb").write(to_json(transform_sampling_data(data))) 57 | 58 | -------------------------------------------------------------------------------- /syntia/mcts_synthesis/utils.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | 4 | def to_json(data): 5 | """ 6 | Dumps data to JSON 7 | :param data: nested dict 8 | :return: json dump 9 | """ 10 | return json.dumps(data, sort_keys=False, indent=4) 11 | 12 | 13 | def dump_to_json(file_path, data): 14 | """ 15 | Dumps data into a JSON file 16 | :param file_path: file path 17 | :param data: nested dict 18 | """ 19 | open(file_path, "wb").write(to_json(data)) 20 | -------------------------------------------------------------------------------- /syntia/poly.64bit.result.txt: -------------------------------------------------------------------------------- 1 | #original,correct,simplified,simplificationTrue/False,z3time 2 | ##all synthesis time:1564.84885502 3 | (x&y)*(x|y)+(x&~y)*(~x&y)-41,x*y-41,(((e | x) & 1) + y),False,0.155067920685 4 | (x&y)*(x|y)+(x&~y)*(~x&y)-253,x*y-253,((b & 1) + f),False,0.0141098499298 5 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*~x+1*(x|~y)-1*~(x|~y)-3*(x&~y),x*y+1*(x&y)-2*(x^y),(t + (d << c)),0,0,0,0,False,0 6 | (x&y)*(x|y)+(x&~y)*(~x&y)+5*~y-11*(x|~y)+6*~(x|y)+8*(x&~y),x*y-13*(x&y)+2*x,((b & 1) + b),False,0.311382055283 7 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*y+2*~(x&y)-2*(x^y)+1*(x&y),x*y-3*~(x|~y)+2*~x,(1 + (y << b)),0,0,0,0,False,0 8 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*~(x&y)-11*~(x^y)+12*~(x|y)+1*~(x|~y)+11*(x&y),x*y+2*~x+1*(x&~y),(x + (y << t)),0,0,0,0,False,0 9 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*~x+5*x-2*~(x^y)+13*~(x|y)+11*~(x|~y),x*y+5*(x&~y)+3*(x&y),(a + (1 << (~ z))),0,0,0,0,False,0 10 | (x&y)*(x|y)+(x&~y)*(~x&y)-2*~(x&~x)+2*y+3*~(x|y)+1*~(x|~y)+2*(x&~y),x*y+1*~x,(y | 1),False,0.122719049454 11 | (x&y)*(x|y)+(x&~y)*(~x&y)+11*(x|~y)+3*~(x&~x)+5*~(x&y)-19*(x&~y)-14*(x&y),x*y+19*~(x|y)+8*~(x|~y),(((~ x) & 1) + y),False,0.128576993942 12 | (x&y)*(x|y)+(x&~y)*(~x&y)+7*~y+4*~(x&y)+11*~(x&~x)-22*~(x|y)-11*(x&y),x*y+15*~(x|~y)+22*(x&~y),((e << a) + y),0,0,0,0,False,0 13 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*(x|~y)-3*~y+2*x+14*~(x|y)+12*(x&~y),x*y-9*(x&y),((1 & z) + z),False,0.371737003326 14 | (x&y)*(x|y)+(x&~y)*(~x&y)+2*(x|y)-4*~(x|y)-2*~(x|~y)-1*(x&~y)-7*(x&y),x*y-5*~(x^y)+1*~y,(~ (- f)),False,0.0135128498077 15 | (x&y)*(x|y)+(x&~y)*(~x&y)-1*~y+1*y+3*~(x|y)+3*(x&~y)+1*(x&y),x*y-1*~(x|~y)+2*~(x&~x),((y << t) + y),0,0,0,0,False,0 16 | (x&y)*(x|y)+(x&~y)*(~x&y)+2*~(x&~y)-5*~(x&y)-1*x+5*~(x|y)+3*~(x|~y)+1*(x&y),x*y-6*(x&~y)+2*~(x^y),(a + (a & 1)),False,0.282330989838 17 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(y^~(~x|(~y&z)))-1*(y^~(x|~z))+1*~(x|(~y|z))+1*~(~x|(~y|z))+1*(x&(~y&z))+1*(x&(y&z)),x*y+1*(x^y)-1*(~x&(~y&z)),(1 + (x << f)),0,0,0,0,False,0 18 | (x&y)*(x|y)+(x&~y)*(~x&y)+4*(y&z)-1*~(x^y)+2*(~x|(y&z))-1*~(x|(y|z))-2*~(x|(~y|z))+1*~(~x|(~y|z))-1*(~x&(~y&z)),x*y+6*(~x&(y&z))+5*(x&(y&z)),(1 + (b << t)),0,0,0,0,False,0 19 | (x&y)*(x|y)+(x&~y)*(~x&y)+3*(z^(~x|(y&z)))-11*(y&~(x&z))+4*(z^(~x|(y|z)))-7*~(x|(y|z))+4*~(x|(~y|z))+7*~(~x|(~y|z))+11*(~x&(y&z)),x*y+3*(x&(~y&z)),(f + (y << (~ 1))),0,0,0,0,False,0 20 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(z^~(x&(y&z)))-2*((x|~y)&~(y^z))+1*~(x|(y|z))-1*~(x|(~y|z))-10*~(~x|(y|z))-12*~(~x|(~y|z))-11*(~x&(y&z))-10*(x&(y&z)),x*y-11*((x&z)^(x^(y&z))),(e + (c & d)),False,0.0143580436707 21 | (x&y)*(x|y)+(x&~y)*(~x&y)-11*((y&~z)|~(~x|(~y&z)))+4*(z^~(~x|(y&z)))+11*~(x|(~y|z))+7*~(~x|(y|z))+6*~(~x|(~y|z))-4*(~x&(y&z))-1*(x&(~y&z))+7*(x&(y&z)),x*y-1*(x&(y^z))+4*(~x&(~y&z)),(z + (~ 1)),False,0.278483867645 22 | (x&y)*(x|y)+(x&~y)*(~x&y)+1*(y^~(~x|(y^z)))+2*(y^~(x|~z))+1*((x&y)^(y|~z))-1*~(x|(y|z))-4*~(x|(~y|z))-3*~(~x|(~y|z))-2*(~x&(~y&z))-2*(~x&(y&z)),x*y+2*(x&(y&z))+2*~(~x|(y|z)),((1 << f) + y),0,0,0,0,False,0 23 | (x&y)*(x|y)+(x&~y)*(~x&y)+11*(y^(~x|(y^z)))-7*(x^y)+1*(z^~(~x&(y|z)))-1*(~x|(y|z))-2*(~(x&~y)&(x^(y^z)))+1*(~z|~(x^y))+1*(y^~(x&(y^z)))+3*~(x&(y|z))-2*(~(x&y)&~(x^(y^z)))-5*~(~x&(~y|z))+1*((x&z)^~(x^(y&z)))+7*(x|~y)+5*(y^~(x&~z))-3*(~(x|y)|(y^z))+11*(~z|(x^y))-1*((x&~y)|(y^z))-11*~(x&(y&z))+14*~(x|(~y|z))-5*~(~x|(~y|z))-12*(~x&(~y&z))+6*(~x&(y&z))-5*(x&(~y&z))-11*(x&(y&z)),x*y+24*~(x|(y|z)),(1 + (t << t)),0,0,0,0,False,0 24 | -------------------------------------------------------------------------------- /syntia/syntia-evaluation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | import re 4 | import sys 5 | import time 6 | import z3 7 | 8 | 9 | def verify_mba_expression(leftExpre, rightExpre, bitnumber=2): 10 | """check the relaion whether the left expression is euqal to the right expression. 11 | Args: 12 | leftExpre: left expression. 13 | rightExpre: right expression. 14 | bitnumber: the number of the bits of the variable. 15 | Returns: 16 | True: equation. 17 | False: unequal. 18 | Raises: 19 | None. 20 | """ 21 | x,y,z,t,a,b,c,d,e,f = z3.BitVecs("x y z t a b c d e f", bitnumber) 22 | 23 | leftEval = eval(leftExpre) 24 | rightEval = eval(rightExpre) 25 | 26 | solver = z3.Solver() 27 | solver.add(leftEval != rightEval) 28 | result = solver.check() 29 | 30 | if str(result) != "unsat": 31 | return False 32 | else: 33 | return True 34 | 35 | 36 | 37 | def SimpCheck(simExpreStr): 38 | """check the expression whether obtain the special operator: <<, >>, %, ++,/.... 39 | Args: 40 | simExpreStr: the expression string. 41 | Return: 42 | True/False 43 | Raise: 44 | None. 45 | """ 46 | if re.search(r"<<", simExpreStr): 47 | return False 48 | elif re.search(r">>", simExpreStr): 49 | return False 50 | elif re.search(r"\+\+", simExpreStr): 51 | return False 52 | elif re.search(r"/", simExpreStr): 53 | return False 54 | elif re.search(r"%", simExpreStr): 55 | return False 56 | elif re.search(r"sign_ext", simExpreStr): 57 | return False 58 | elif re.search(r"zero_ext", simExpreStr): 59 | return False 60 | elif re.search(r"extract", simExpreStr): 61 | return False 62 | else: 63 | return True 64 | 65 | return None 66 | 67 | 68 | 69 | def SyntiaEvaluation(bitNum, readfilename, writefilename): 70 | """do the syntia evaluation 71 | Args: 72 | bitNum: the bit number of the variables. 73 | readfilename: from this file read the expression. 74 | writefilename: write the results to this file. 75 | Return: 76 | None. 77 | Raise: 78 | None. 79 | """ 80 | fwrite = open(writefilename, "w") 81 | 82 | fwrite.write("#original,correct,simplified,simplificationTrue/False,z3time\n") 83 | 84 | with open(readfilename, "r") as data: 85 | for line in data: 86 | line = line.replace("\n", "") 87 | resultStr = line 88 | 89 | if line[0] != "#" and line: 90 | expreStrList = re.split(",", line) 91 | sourceExpreStr = expreStrList[0] 92 | correctExpreStr = expreStrList[1] 93 | simExpreStr = expreStrList[2] 94 | #z3 check the simplification results. 95 | if SimpCheck(simExpreStr): 96 | #get the nodes and alternance of the expression. 97 | start = time.time() 98 | z3Result = verify_mba_expression(simExpreStr, correctExpreStr, bitNum) 99 | end = time.time() 100 | elapsed = end - start 101 | resultStr += "," + str(z3Result) + "," + str(elapsed) + "\n" 102 | else: 103 | resultStr += ",0,0,0,0" 104 | resultStr += "," + "False" + "," + str(0) + "\n" 105 | fwrite.write(resultStr) 106 | elif line[0] == "#" and line[1] == "#": 107 | fwrite.write(line + "\n") 108 | fwrite.flush 109 | 110 | fwrite.close() 111 | return None 112 | 113 | 114 | 115 | def main(bitNum, readfilename, writefilename): 116 | SyntiaEvaluation(bitNum, readfilename, writefilename) 117 | 118 | 119 | 120 | if __name__ == "__main__": 121 | bitNum = int(sys.argv[1]) 122 | readfilename = sys.argv[2] 123 | writefilename = sys.argv[3] 124 | main(bitNum, readfilename, writefilename) 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /syntia/testmcts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | import json 4 | import random 5 | import re 6 | import sys 7 | import time 8 | import os 9 | 10 | def JsonHead(bitNum): 11 | """build the json file head to meet the requirement of MCTS synthesis method. 12 | Args: 13 | bitNum: the number of the bits of variables. 14 | Returns: 15 | jsonDict. 16 | Raise: 17 | None. 18 | """ 19 | jsonDict = {} 20 | 21 | sizeStr = str(bitNum / 8) 22 | 23 | #the symbol x information 24 | itemDict0 = {} 25 | itemDict0["location"] = "mem0" 26 | itemDict0["size"] = sizeStr 27 | #the symbol y information 28 | itemDict1 = {} 29 | itemDict1["location"] = "mem1" 30 | itemDict1["size"] = sizeStr 31 | #the symbol z information 32 | itemDict2 = {} 33 | itemDict2["location"] = "mem2" 34 | itemDict2["size"] = sizeStr 35 | #the symbol t information 36 | itemDict9 = {} 37 | itemDict9["location"] = "mem3" 38 | itemDict9["size"] = sizeStr 39 | #the symbol a information 40 | itemDict3 = {} 41 | itemDict3["location"] = "mem4" 42 | itemDict3["size"] = sizeStr 43 | #the symbol b information 44 | itemDict4 = {} 45 | itemDict4["location"] = "mem5" 46 | itemDict4["size"] = sizeStr 47 | #the symbol c information 48 | itemDict5 = {} 49 | itemDict5["location"] = "mem6" 50 | itemDict5["size"] = sizeStr 51 | #the symbol d information 52 | itemDict6 = {} 53 | itemDict6["location"] = "mem7" 54 | itemDict6["size"] = sizeStr 55 | #the symbol e information 56 | itemDict7 = {} 57 | itemDict7["location"] = "mem8" 58 | itemDict7["size"] = sizeStr 59 | #the symbol f information 60 | itemDict8 = {} 61 | itemDict8["location"] = "mem9" 62 | itemDict8["size"] = sizeStr 63 | #inputs information 64 | inputDict = {} 65 | inputDict["0"] = itemDict0 66 | inputDict["1"] = itemDict1 67 | inputDict["2"] = itemDict2 68 | inputDict["3"] = itemDict3 69 | inputDict["4"] = itemDict4 70 | inputDict["5"] = itemDict5 71 | inputDict["6"] = itemDict6 72 | inputDict["7"] = itemDict7 73 | inputDict["8"] = itemDict8 74 | inputDict["9"] = itemDict9 75 | jsonDict["inputs"] = inputDict 76 | 77 | #the symbol result information 78 | itemDict2 = {} 79 | if bitNum == 8: 80 | itemDict2["location"] = "AL" 81 | if bitNum == 16: 82 | itemDict2["location"] = "AX" 83 | if bitNum == 32: 84 | itemDict2["location"] = "EAX" 85 | if bitNum == 64: 86 | itemDict2["location"] = "RAX" 87 | itemDict2["size"] = sizeStr 88 | #outputs information 89 | outputDict = {} 90 | outputDict["0"] = itemDict2 91 | jsonDict["outputs"] = outputDict 92 | 93 | return jsonDict 94 | 95 | 96 | def Sampling(expreStr, number=20, bitNum=32): 97 | """sampling the I/O pairs based on the expression. 98 | Args: 99 | expreStr: the expression string. 100 | Returns: 101 | samplingList: the I/O pairs list. 102 | number: the sampling times. 103 | bitNum: the number of bits of the variables. 104 | Raise: 105 | None. 106 | """ 107 | samplingList = [] 108 | 109 | modNum = 2**bitNum - 1 110 | 111 | for i in range(number): 112 | item = [] 113 | 114 | x = random.randint(0, modNum) 115 | y = random.randint(0, modNum) 116 | z = random.randint(0, modNum) 117 | t = random.randint(0, modNum) 118 | a = random.randint(0, modNum) 119 | b = random.randint(0, modNum) 120 | c = random.randint(0, modNum) 121 | d = random.randint(0, modNum) 122 | e = random.randint(0, modNum) 123 | f = random.randint(0, modNum) 124 | res = eval(expreStr) % 2**bitNum 125 | 126 | item.append(str(x)) 127 | item.append(str(y)) 128 | item.append(str(z)) 129 | item.append(str(t)) 130 | item.append(str(a)) 131 | item.append(str(b)) 132 | item.append(str(c)) 133 | item.append(str(d)) 134 | item.append(str(e)) 135 | item.append(str(f)) 136 | item.append(str(res)) 137 | samplingList.append(item) 138 | 139 | return samplingList 140 | 141 | 142 | def ProgramSynthesis(expreStr, bitNum): 143 | """synthesizing the semantics of the expression based on the MCTS synthesis method. 144 | step1: sampling. 145 | step2: synthesis. 146 | step3: successful or fail. 147 | Args: 148 | expreStr: the expression synthesized. 149 | bitNum: the number of the bit of the variables. 150 | Returns: 151 | None. 152 | Raises: 153 | None. 154 | """ 155 | #sampling json file 156 | jsonDict = {} 157 | jsonDict = JsonHead(bitNum) 158 | 159 | #sampling list 160 | sampleList = Sampling(expreStr, 20, bitNum) 161 | jsonDict["samples"] = sampleList 162 | 163 | #write the I/O pairs into file 164 | manuallyfile = str(bitNum) + "bit.manually.json" 165 | with open(manuallyfile, "w") as f: 166 | json.dump(jsonDict, f) 167 | 168 | #transform the I/O pairs to meet the requirement of MCTS synthesis program 169 | samplingfile = str(bitNum) + "bit.sampling.json" 170 | pythonorder = "python ./mcts_synthesis/transform_manual_sampling_io_pairs.py " + manuallyfile + " " + samplingfile 171 | os.system(pythonorder) 172 | #using the MCTS method to synthesize the MBA expression 173 | outputfile = str(bitNum) + "bit.output.json" 174 | pythonorder = "python ./mcts_synthesis/sample_synthesis.py " + samplingfile + " " + outputfile 175 | os.system(pythonorder) 176 | 177 | return None 178 | 179 | def main(bitNum, readfile, desfilename): 180 | outputfile = str(bitNum) + "bit.output.json" 181 | resDict = {} 182 | start = time.time() 183 | #test this program 184 | #with open("test.txt", "r") as data: 185 | with open(readfile, "r") as data: 186 | linenum = 1 187 | jsonDict = {} 188 | for line in data: 189 | itemDict = {} 190 | line = line.strip("\n") 191 | expreStr = "" 192 | if line and line[0] != "#": 193 | dataList = re.split(",", line) 194 | sourceExpreStr = dataList[0] 195 | correctExpreStr = dataList[1] 196 | #print linenum, sourceExpreStr 197 | ProgramSynthesis(sourceExpreStr, bitNum) 198 | 199 | #get result in json format 200 | with open(outputfile, "r") as f: 201 | jsonDict = json.load(f) 202 | 203 | jsonDict["0"]["orignalExpression"] = sourceExpreStr 204 | jsonDict["0"]["correctExpression"] = correctExpreStr 205 | resDict[linenum] = jsonDict["0"] 206 | 207 | linenum += 1 208 | #print 209 | 210 | end = time.time() 211 | elapsed = end - start 212 | resDict[0] = str(elapsed) 213 | 214 | #write the result to file 215 | with open(desfilename, "w") as fw: 216 | json.dump(resDict, fw, indent=4) 217 | 218 | 219 | 220 | if __name__ == "__main__": 221 | bitNum = int(sys.argv[1]) 222 | readfile = sys.argv[2] 223 | desfilename = sys.argv[3] 224 | main(bitNum, readfile, desfilename) 225 | 226 | -------------------------------------------------------------------------------- /syntia/transformation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | from collections import OrderedDict 4 | import json 5 | import re 6 | import sys 7 | 8 | 9 | def TransforExpre(simExpreStr): 10 | """transformate the result to format result. 11 | Args: 12 | simExpreStr: expression string. 13 | Returns: 14 | expreStr: new expression string. 15 | Raise: 16 | None. 17 | """ 18 | expreStr = simExpreStr 19 | expreStr = expreStr.replace("mem0", "x") 20 | expreStr = expreStr.replace("mem1", "y") 21 | expreStr = expreStr.replace("mem2", "z") 22 | expreStr = expreStr.replace("mem3", "t") 23 | expreStr = expreStr.replace("mem4", "a") 24 | expreStr = expreStr.replace("mem5", "b") 25 | expreStr = expreStr.replace("mem6", "c") 26 | expreStr = expreStr.replace("mem7", "d") 27 | expreStr = expreStr.replace("mem8", "e") 28 | expreStr = expreStr.replace("mem9", "f") 29 | #dont process the special operator 30 | #in the check process, it directly is wrong! 31 | """ 32 | if re.search("<<", expreStr): 33 | obj = re.search("<<", expreStr) 34 | index = obj.span()[0] 35 | starStr = expreStr[index:index + 4] 36 | expreStr = expreStr.replace(starStr, "*(2**" + expreStr[index + 3] + ")") 37 | elif re.search(">>", expreStr): 38 | obj = re.search(">>", expreStr) 39 | index = obj.span()[0] 40 | starStr = expreStr[index:index + 4] 41 | expreStr = expreStr.replace(starStr, "/(2**" + expreStr[index + 3] + ")") 42 | """ 43 | return expreStr 44 | 45 | def transformation(sourcefile, desfile): 46 | """transformate the json result to format result. 47 | Args: 48 | sourcefile: the source json file. 49 | desfile: the file store the result. 50 | Return: 51 | None. 52 | Raise: 53 | None. 54 | """ 55 | jsonDict = {} 56 | with open(sourcefile, "r") as data: 57 | jsonDict = json.load(data) 58 | 59 | alltime = jsonDict["0"] 60 | del jsonDict["0"] 61 | 62 | fwrite = open(desfile, "w") 63 | fwrite.write("#original,correct,simplified\n") 64 | fwrite.write("##all synthesis time:" + alltime + "\n") 65 | 66 | #let the dictionary be ordered. 67 | dataDict1 = OrderedDict() 68 | for (key, value) in jsonDict.items(): 69 | dataDict1[int(key)] = jsonDict[key] 70 | del jsonDict 71 | 72 | keys = sorted(dataDict1.keys()) 73 | dataDict = OrderedDict() 74 | for key in keys: 75 | dataDict[key] = dataDict1[key] 76 | del dataDict1 77 | 78 | for (key, value) in dataDict.items(): 79 | sourceExpreStr = value["orignalExpression"] 80 | correctExpreStr = value["correctExpression"] 81 | simExpreStr = value["top_terminal"]["expression"]["infix"] 82 | simExpreStr = TransforExpre(simExpreStr) 83 | expreStr = sourceExpreStr + "," + correctExpreStr 84 | expreStr += "," + simExpreStr + "\n" 85 | fwrite.write(expreStr) 86 | 87 | fwrite.close() 88 | 89 | 90 | 91 | def main(sourcefile, desfile): 92 | transformation(sourcefile, desfile) 93 | 94 | 95 | 96 | if __name__ == "__main__": 97 | sourcefile = sys.argv[1] 98 | desfile = sys.argv[2] 99 | main(sourcefile, desfile) 100 | -------------------------------------------------------------------------------- /tools/1variable_truthtable.txt: -------------------------------------------------------------------------------- 1 | #truth_table, bitwiseExpression 2 | [0 0],(x&~x) 3 | [1 0],~x 4 | [0 1],x 5 | [1 1],~(x&~x) 6 | -------------------------------------------------------------------------------- /tools/2variable_truthtable.txt: -------------------------------------------------------------------------------- 1 | #truth_table, bitwiseExpression 2 | [0 0 0 0],(x&~x) 3 | [1 0 0 0],~(x|y) 4 | [0 1 0 0],~(x|~y) 5 | [1 1 0 0],~x 6 | [0 0 1 0],(x&~y) 7 | [1 0 1 0],~y 8 | [0 1 1 0],(x^y) 9 | [1 1 1 0],~(x&y) 10 | [0 0 0 1],(x&y) 11 | [1 0 0 1],~(x^y) 12 | [0 1 0 1],y 13 | [1 1 0 1],~(x&~y) 14 | [0 0 1 1],x 15 | [1 0 1 1],(x|~y) 16 | [0 1 1 1],(x|y) 17 | [1 1 1 1],~(x&~x) 18 | -------------------------------------------------------------------------------- /tools/3variable_truthtable.txt: -------------------------------------------------------------------------------- 1 | #truth_table, bitwiseExpression 2 | [0 0 0 0 0 0 0 0],(x&~x) 3 | [1 0 0 0 0 0 0 0],~(x|(y|z)) 4 | [0 1 0 0 0 0 0 0],~(x|(~y|z)) 5 | [1 1 0 0 0 0 0 0],~(x|z) 6 | [0 0 1 0 0 0 0 0],~(~x|(y|z)) 7 | [1 0 1 0 0 0 0 0],~(y|z) 8 | [0 1 1 0 0 0 0 0],(~z&(x^y)) 9 | [1 1 1 0 0 0 0 0],(z^(~x|(~y|z))) 10 | [0 0 0 1 0 0 0 0],~(~x|(~y|z)) 11 | [1 0 0 1 0 0 0 0],(~z&~(x^y)) 12 | [0 1 0 1 0 0 0 0],(y&~z) 13 | [1 1 0 1 0 0 0 0],(z^(~x|(y|z))) 14 | [0 0 1 1 0 0 0 0],(x&~z) 15 | [1 0 1 1 0 0 0 0],(z^(x|(~y|z))) 16 | [0 1 1 1 0 0 0 0],(z^(x|(y|z))) 17 | [1 1 1 1 0 0 0 0],~z 18 | [0 0 0 0 1 0 0 0],(~x&(~y&z)) 19 | [1 0 0 0 1 0 0 0],~(x|y) 20 | [0 1 0 0 1 0 0 0],(~x&(y^z)) 21 | [1 1 0 0 1 0 0 0],~(x|(y&z)) 22 | [0 0 1 0 1 0 0 0],(~y&(x^z)) 23 | [1 0 1 0 1 0 0 0],(y^~(x&(~y&z))) 24 | [0 1 1 0 1 0 0 0],(~(x&y)&(x^(y^z))) 25 | [1 1 1 0 1 0 0 0],((y&z)^~(x&(y^z))) 26 | [0 0 0 1 1 0 0 0],(~(x^y)&(x^z)) 27 | [1 0 0 1 1 0 0 0],(y^(~x|(y&z))) 28 | [0 1 0 1 1 0 0 0],(~(x&~y)&(y^z)) 29 | [1 1 0 1 1 0 0 0],((x&y)^~(x^(y&z))) 30 | [0 0 1 1 1 0 0 0],(z^(x|(y&z))) 31 | [1 0 1 1 1 0 0 0],(y^~(x&(y^z))) 32 | [0 1 1 1 1 0 0 0],(z^(x|y)) 33 | [1 1 1 1 1 0 0 0],(z^~(~x&(~y&z))) 34 | [0 0 0 0 0 1 0 0],(~x&(y&z)) 35 | [1 0 0 0 0 1 0 0],~(x|(y^z)) 36 | [0 1 0 0 0 1 0 0],~(x|~y) 37 | [1 1 0 0 0 1 0 0],~(x|(~y&z)) 38 | [0 0 1 0 0 1 0 0],((x^y)&(x^z)) 39 | [1 0 1 0 0 1 0 0],(~(x&y)&~(y^z)) 40 | [0 1 1 0 0 1 0 0],(y^~(~x|(~y&z))) 41 | [1 1 1 0 0 1 0 0],((x&y)^(y|~z)) 42 | [0 0 0 1 0 1 0 0],(y&(x^z)) 43 | [1 0 0 1 0 1 0 0],(~(x&~y)&~(x^(y^z))) 44 | [0 1 0 1 0 1 0 0],(y&~(x&z)) 45 | [1 1 0 1 0 1 0 0],((y&~z)|~(x|(~y&z))) 46 | [0 0 1 1 0 1 0 0],(z^(x|(~y&z))) 47 | [1 0 1 1 0 1 0 0],(z^(x|~y)) 48 | [0 1 1 1 0 1 0 0],(y^~(~x|(y^z))) 49 | [1 1 1 1 0 1 0 0],(z^~(~x&(y&z))) 50 | [0 0 0 0 1 1 0 0],~(x|~z) 51 | [1 0 0 0 1 1 0 0],(~x&(~y|z)) 52 | [0 1 0 0 1 1 0 0],(~x&(y|z)) 53 | [1 1 0 0 1 1 0 0],~x 54 | [0 0 1 0 1 1 0 0],(z^(x&(~y|z))) 55 | [1 0 1 0 1 1 0 0],((x&z)^~(y&~z)) 56 | [0 1 1 0 1 1 0 0],(x^(y|z)) 57 | [1 1 1 0 1 1 0 0],~(x&(y|z)) 58 | [0 0 0 1 1 1 0 0],(z^(x&(y|z))) 59 | [1 0 0 1 1 1 0 0],(x^(~y|z)) 60 | [0 1 0 1 1 1 0 0],((x&z)^(y|z)) 61 | [1 1 0 1 1 1 0 0],~(x&(~y|z)) 62 | [0 0 1 1 1 1 0 0],(x^z) 63 | [1 0 1 1 1 1 0 0],(z^~(~x&(y|z))) 64 | [0 1 1 1 1 1 0 0],(z^~(~x&(~y|z))) 65 | [1 1 1 1 1 1 0 0],~(x&z) 66 | [0 0 0 0 0 0 1 0],(x&(~y&z)) 67 | [1 0 0 0 0 0 1 0],(~y&~(x^z)) 68 | [0 1 0 0 0 0 1 0],((x^y)&~(x^z)) 69 | [1 1 0 0 0 0 1 0],(z^(~x|(y&z))) 70 | [0 0 1 0 0 0 1 0],(x&~y) 71 | [1 0 1 0 0 0 1 0],(y^~(~x&(~y&z))) 72 | [0 1 1 0 0 0 1 0],(y^(x|(y&z))) 73 | [1 1 1 0 0 0 1 0],(y^~(~x&(y^z))) 74 | [0 0 0 1 0 0 1 0],(x&(y^z)) 75 | [1 0 0 1 0 0 1 0],((x|~y)&~(x^(y^z))) 76 | [0 1 0 1 0 0 1 0],((x|y)&(y^z)) 77 | [1 1 0 1 0 0 1 0],(z^~(x&~y)) 78 | [0 0 1 1 0 0 1 0],~(~x|(y&z)) 79 | [1 0 1 1 0 0 1 0],((y&z)^~(~x&(y^z))) 80 | [0 1 1 1 0 0 1 0],((x&y)^~(x^(~y|z))) 81 | [1 1 1 1 0 0 1 0],(z^~(x&(~y&z))) 82 | [0 0 0 0 1 0 1 0],~(y|~z) 83 | [1 0 0 0 1 0 1 0],(y^(~x|(y|z))) 84 | [0 1 0 0 1 0 1 0],(~(x&y)&(y^z)) 85 | [1 1 0 0 1 0 1 0],((x&z)^~(x^(y&z))) 86 | [0 0 1 0 1 0 1 0],(y^(x|(y|z))) 87 | [1 0 1 0 1 0 1 0],~y 88 | [0 1 1 0 1 0 1 0],(y^(x|z)) 89 | [1 1 1 0 1 0 1 0],(y^(x|(~y|z))) 90 | [0 0 0 1 1 0 1 0],((x|~y)&(y^z)) 91 | [1 0 0 1 1 0 1 0],(y^~(x&~z)) 92 | [0 1 0 1 1 0 1 0],(y^z) 93 | [1 1 0 1 1 0 1 0],(~(x|y)|(y^z)) 94 | [0 0 1 1 1 0 1 0],((x&z)^(x^(~y&z))) 95 | [1 0 1 1 1 0 1 0],(y^(~x|(~y|z))) 96 | [0 1 1 1 1 0 1 0],((x&~y)|(y^z)) 97 | [1 1 1 1 1 0 1 0],~(y&z) 98 | [0 0 0 0 0 1 1 0],(z&(x^y)) 99 | [1 0 0 0 0 1 1 0],(~(x&y)&~(x^(y^z))) 100 | [0 1 0 0 0 1 1 0],(y^(x&(y|z))) 101 | [1 1 0 0 0 1 1 0],~(x^(~y&z)) 102 | [0 0 1 0 0 1 1 0],(y^~(~x&(~y|z))) 103 | [1 0 1 0 0 1 1 0],(y^(x|~z)) 104 | [0 1 1 0 0 1 1 0],(x^y) 105 | [1 1 1 0 0 1 1 0],(y^~(~x&(y|z))) 106 | [0 0 0 1 0 1 1 0],((x|y)&~(x^(y^z))) 107 | [1 0 0 1 0 1 1 0],~(x^(y^z)) 108 | [0 1 0 1 0 1 1 0],(y^(x&z)) 109 | [1 1 0 1 0 1 1 0],(~(x|~y)|~(x^(y^z))) 110 | [0 0 1 1 0 1 1 0],(x^(y&z)) 111 | [1 0 1 1 0 1 1 0],((x&~y)|~(x^(y^z))) 112 | [0 1 1 1 0 1 1 0],(y^(x&(~y|z))) 113 | [1 1 1 1 0 1 1 0],(~z|(x^y)) 114 | [0 0 0 0 1 1 1 0],(z&~(x&y)) 115 | [1 0 0 0 1 1 1 0],((y&~z)^(~x|(y^z))) 116 | [0 1 0 0 1 1 1 0],((x&y)^(y|z)) 117 | [1 1 0 0 1 1 1 0],(~x|(~y&z)) 118 | [0 0 1 0 1 1 1 0],(y^(x|(y^z))) 119 | [1 0 1 0 1 1 1 0],(y^~(~x&(y&z))) 120 | [0 1 1 0 1 1 1 0],(y^(x|(~y&z))) 121 | [1 1 1 0 1 1 1 0],~(x&y) 122 | [0 0 0 1 1 1 1 0],(z^(x&y)) 123 | [1 0 0 1 1 1 1 0],(~(x|y)|~(x^(y^z))) 124 | [0 1 0 1 1 1 1 0],(~(x|~y)|(y^z)) 125 | [1 1 0 1 1 1 1 0],(~x|(y^z)) 126 | [0 0 1 1 1 1 1 0],(z^~(~x|(~y&z))) 127 | [1 0 1 1 1 1 1 0],(~y|(x^z)) 128 | [0 1 1 1 1 1 1 0],((x^y)|(x^z)) 129 | [1 1 1 1 1 1 1 0],~(x&(y&z)) 130 | [0 0 0 0 0 0 0 1],(x&(y&z)) 131 | [1 0 0 0 0 0 0 1],(~(x^y)&~(x^z)) 132 | [0 1 0 0 0 0 0 1],(y&~(x^z)) 133 | [1 1 0 0 0 0 0 1],(z^(~x|(~y&z))) 134 | [0 0 1 0 0 0 0 1],~(~x|(y^z)) 135 | [1 0 1 0 0 0 0 1],((x|~y)&~(y^z)) 136 | [0 1 1 0 0 0 0 1],((x|y)&(x^(y^z))) 137 | [1 1 1 0 0 0 0 1],(z^~(x&y)) 138 | [0 0 0 1 0 0 0 1],(x&y) 139 | [1 0 0 1 0 0 0 1],(y^~(x|(~y&z))) 140 | [0 1 0 1 0 0 0 1],(y&(x|~z)) 141 | [1 1 0 1 0 0 0 1],(y^~(x|(y^z))) 142 | [0 0 1 1 0 0 0 1],~(~x|(~y&z)) 143 | [1 0 1 1 0 0 0 1],((x&y)|~(y|z)) 144 | [0 1 1 1 0 0 0 1],((y&~z)|~(~x|(~y&z))) 145 | [1 1 1 1 0 0 0 1],(z^~(x&(y&z))) 146 | [0 0 0 0 1 0 0 1],(z&~(x^y)) 147 | [1 0 0 0 1 0 0 1],(y^~(x&(~y|z))) 148 | [0 1 0 0 1 0 0 1],(~(x&~y)&(x^(y^z))) 149 | [1 1 0 0 1 0 0 1],~(x^(y&z)) 150 | [0 0 1 0 1 0 0 1],((x|~y)&(x^(y^z))) 151 | [1 0 1 0 1 0 0 1],(y^~(x&z)) 152 | [0 1 1 0 1 0 0 1],(x^(y^z)) 153 | [1 1 1 0 1 0 0 1],(~(x|y)|(x^(y^z))) 154 | [0 0 0 1 1 0 0 1],(y^(~x&(y|z))) 155 | [1 0 0 1 1 0 0 1],~(x^y) 156 | [0 1 0 1 1 0 0 1],(y^~(x|~z)) 157 | [1 1 0 1 1 0 0 1],(y^(~x&(~y|z))) 158 | [0 0 1 1 1 0 0 1],(x^(~y&z)) 159 | [1 0 1 1 1 0 0 1],(y^~(x&(y|z))) 160 | [0 1 1 1 1 0 0 1],((x&y)|(x^(y^z))) 161 | [1 1 1 1 1 0 0 1],(~z|~(x^y)) 162 | [0 0 0 0 0 1 0 1],(y&z) 163 | [1 0 0 0 0 1 0 1],(~(x&~y)&~(y^z)) 164 | [0 1 0 0 0 1 0 1],(y&~(x&~z)) 165 | [1 1 0 0 0 1 0 1],((x&z)^~(x^(~y&z))) 166 | [0 0 1 0 0 1 0 1],((x|y)&~(y^z)) 167 | [1 0 1 0 0 1 0 1],~(y^z) 168 | [0 1 1 0 0 1 0 1],(y^(x&~z)) 169 | [1 1 1 0 0 1 0 1],(~(x|~y)|~(y^z)) 170 | [0 0 0 1 0 1 0 1],(y&(x|z)) 171 | [1 0 0 1 0 1 0 1],(y^~(x|z)) 172 | [0 1 0 1 0 1 0 1],y 173 | [1 1 0 1 0 1 0 1],(y|~(x|z)) 174 | [0 0 1 1 0 1 0 1],((x&z)^(x^(y&z))) 175 | [1 0 1 1 0 1 0 1],((x&y)|~(y^z)) 176 | [0 1 1 1 0 1 0 1],(y|(x&~z)) 177 | [1 1 1 1 0 1 0 1],(y|~z) 178 | [0 0 0 0 1 1 0 1],(z&~(x&~y)) 179 | [1 0 0 0 1 1 0 1],((x&y)^(x^(~y|z))) 180 | [0 1 0 0 1 1 0 1],((y&z)|(~x&(y|z))) 181 | [1 1 0 0 1 1 0 1],(~x|(y&z)) 182 | [0 0 1 0 1 1 0 1],(z^(x&~y)) 183 | [1 0 1 0 1 1 0 1],(~(x|y)|~(y^z)) 184 | [0 1 1 0 1 1 0 1],(~(x|~y)|(x^(y^z))) 185 | [1 1 1 0 1 1 0 1],~(x&(y^z)) 186 | [0 0 0 1 1 1 0 1],(y^(~x&(y^z))) 187 | [1 0 0 1 1 1 0 1],(y^~(x|(y&z))) 188 | [0 1 0 1 1 1 0 1],(y|~(x|~z)) 189 | [1 1 0 1 1 1 0 1],~(x&~y) 190 | [0 0 1 1 1 1 0 1],(z^~(~x|(y&z))) 191 | [1 0 1 1 1 1 0 1],(~(x^y)|(x^z)) 192 | [0 1 1 1 1 1 0 1],(y|(x^z)) 193 | [1 1 1 1 1 1 0 1],~(x&(~y&z)) 194 | [0 0 0 0 0 0 1 1],(x&z) 195 | [1 0 0 0 0 0 1 1],(z^(~x&(~y|z))) 196 | [0 1 0 0 0 0 1 1],(z^(~x&(y|z))) 197 | [1 1 0 0 0 0 1 1],~(x^z) 198 | [0 0 1 0 0 0 1 1],(x&(~y|z)) 199 | [1 0 1 0 0 0 1 1],((x&z)|~(y|z)) 200 | [0 1 1 0 0 0 1 1],~(x^(~y|z)) 201 | [1 1 1 0 0 0 1 1],(z^~(x&(y|z))) 202 | [0 0 0 1 0 0 1 1],(x&(y|z)) 203 | [1 0 0 1 0 0 1 1],~(x^(y|z)) 204 | [0 1 0 1 0 0 1 1],((x&z)|(y&~z)) 205 | [1 1 0 1 0 0 1 1],(z^~(x&(~y|z))) 206 | [0 0 1 1 0 0 1 1],x 207 | [1 0 1 1 0 0 1 1],~(~x&(y|z)) 208 | [0 1 1 1 0 0 1 1],~(~x&(~y|z)) 209 | [1 1 1 1 0 0 1 1],(x|~z) 210 | [0 0 0 0 1 0 1 1],(z&(x|~y)) 211 | [1 0 0 0 1 0 1 1],(y^(~x|(y^z))) 212 | [0 1 0 0 1 0 1 1],(z^~(x|~y)) 213 | [1 1 0 0 1 0 1 1],(z^~(x|(~y&z))) 214 | [0 0 1 0 1 0 1 1],((y&~z)^(x|(y^z))) 215 | [1 0 1 0 1 0 1 1],(y^~(x&(y&z))) 216 | [0 1 1 0 1 0 1 1],((x&~y)|(x^(y^z))) 217 | [1 1 1 0 1 0 1 1],(~y|~(x^z)) 218 | [0 0 0 1 1 0 1 1],((x&y)|~(y|~z)) 219 | [1 0 0 1 1 0 1 1],(y^(~x|(~y&z))) 220 | [0 1 0 1 1 0 1 1],((x&y)|(y^z)) 221 | [1 1 0 1 1 0 1 1],(~(x^y)|~(x^z)) 222 | [0 0 1 1 1 0 1 1],(x|(~y&z)) 223 | [1 0 1 1 1 0 1 1],(x|~y) 224 | [0 1 1 1 1 0 1 1],(x|(y^z)) 225 | [1 1 1 1 1 0 1 1],~(~x&(y&z)) 226 | [0 0 0 0 0 1 1 1],(z&(x|y)) 227 | [1 0 0 0 0 1 1 1],(z^~(x|y)) 228 | [0 1 0 0 0 1 1 1],(y^(x&(y^z))) 229 | [1 1 0 0 0 1 1 1],(z^~(x|(y&z))) 230 | [0 0 1 0 0 1 1 1],((x&y)^(x^(y&z))) 231 | [1 0 1 0 0 1 1 1],((x&~y)|~(y^z)) 232 | [0 1 1 0 0 1 1 1],(y^~(~x|(y&z))) 233 | [1 1 1 0 0 1 1 1],((x^y)|~(x^z)) 234 | [0 0 0 1 0 1 1 1],((y&z)|(x&(y|z))) 235 | [1 0 0 1 0 1 1 1],((x&y)|~(x^(y^z))) 236 | [0 1 0 1 0 1 1 1],(y|(x&z)) 237 | [1 1 0 1 0 1 1 1],(y|~(x^z)) 238 | [0 0 1 1 0 1 1 1],(x|(y&z)) 239 | [1 0 1 1 0 1 1 1],~(~x&(y^z)) 240 | [0 1 1 1 0 1 1 1],(x|y) 241 | [1 1 1 1 0 1 1 1],~(~x&(~y&z)) 242 | [0 0 0 0 1 1 1 1],z 243 | [1 0 0 0 1 1 1 1],(z|~(x|y)) 244 | [0 1 0 0 1 1 1 1],(z|~(x|~y)) 245 | [1 1 0 0 1 1 1 1],~(x&~z) 246 | [0 0 1 0 1 1 1 1],(z|(x&~y)) 247 | [1 0 1 0 1 1 1 1],~(y&~z) 248 | [0 1 1 0 1 1 1 1],(z|(x^y)) 249 | [1 1 1 0 1 1 1 1],(~x|(~y|z)) 250 | [0 0 0 1 1 1 1 1],(z|(x&y)) 251 | [1 0 0 1 1 1 1 1],(z|~(x^y)) 252 | [0 1 0 1 1 1 1 1],(y|z) 253 | [1 1 0 1 1 1 1 1],(~x|(y|z)) 254 | [0 0 1 1 1 1 1 1],(x|z) 255 | [1 0 1 1 1 1 1 1],(x|(~y|z)) 256 | [0 1 1 1 1 1 1 1],(x|(y|z)) 257 | [1 1 1 1 1 1 1 1],~(x&~x) 258 | -------------------------------------------------------------------------------- /tools/__init__.py: -------------------------------------------------------------------------------- 1 | """Tools module, containing: 2 | 3 | - mba_string_operation: functions to analyze and manipulate the string's format of MBA expression. 4 | - mba_ast_operation: functions to analyze and manipulate the AST of MBA expression. 5 | - svector_simplify: functions to simplify mba expression by signal vector. 6 | - truthtable_search_simplify: functions to simplify mba expressio by the truth table transformation 7 | - mba_flatten: functions to simplify mba expresion by the multiple rules. 8 | 9 | """ 10 | -------------------------------------------------------------------------------- /tools/commons.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | 5 | import re 6 | import os 7 | import traceback 8 | 9 | 10 | def get_entire_bitwise(vnumber): 11 | """get the entire bitwise expression of 2/3/4-variable. 12 | Args: 13 | vnumber: the number of the variables. 14 | Return: 15 | bitList: the entire bitwise expression. 16 | """ 17 | if not vnumber in [1, 2,3,4]: 18 | print("vnumber must be 1, 2,3 or 4.") 19 | traceback.print_stack() 20 | sys.exit(0) 21 | abspath = os.path.realpath(__file__) 22 | (dirpath, filename) = os.path.split(abspath) 23 | truthfile = "{dirpath}/{vnumber}variable_truthtable.txt".format(dirpath=dirpath, vnumber=vnumber) 24 | bitList = [] 25 | with open(truthfile, "r") as fr: 26 | for line in fr: 27 | if "#" not in line: 28 | line = line.strip() 29 | itemList = re.split(",", line) 30 | bit = itemList[1] 31 | bitList.append(bit) 32 | 33 | return bitList 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /tools/mba_ast_operation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | """ 4 | This file including the operation of MBA expression by AST. 5 | """ 6 | 7 | import ast 8 | import astunparse 9 | 10 | 11 | # Store all subtree 12 | def store_all_subtree(ast_root, buf): 13 | for node in ast.iter_child_nodes(ast_root): 14 | buf.append([ast.dump(node, annotate_fields=False), node]) 15 | store_all_subtree(node, buf) 16 | 17 | # Return the max_common_subtree in buf 18 | def max_common_subtree(buf): 19 | maxlen = 0 20 | mcsubtree = [] 21 | s = set() 22 | for e in buf: 23 | if e[0] in s: 24 | if len(e[0]) > maxlen: 25 | maxlen = len(e[0]) 26 | mcsubtree = e 27 | else: 28 | s.add(e[0]) 29 | 30 | return mcsubtree 31 | 32 | 33 | def main(): 34 | mba3 = '((((x|y)*2)-(x^y))|z)+((((x|y)*2)-(x^y))&z)' 35 | mba5 = '((((x^y)+((x&y)+(x&y)))^~z)+((((x^y)+((x&y)+(x&y)))|z)+(((x^y)+((x&y)+(x&y)))|z)))+1' 36 | mba1000 = '(((~(x-1)&y)*(~(x-1)|y)+(~(x-1)&~y)*(~(~(x-1))&y))&z)*(((~(x-1)&y)*(~(x-1)|y)+(~(x-1)&~y)*(~(~(x-1))&y))|z)+(((~(x-1)&y)*(~(x-1)|y)+(~(x-1)&~y)*(~(~(x-1))&y))&~z)*(~((~(x-1)&y)*(~(x-1)|y)+(~(x-1)&~y)*(~(~(x-1))&y))&z)-1*~(x&~x)-2*(x|~y)-1*~(x&~y)+5*~(x|y)+9*~(x|~y)+3*(x&~y)+12*(x&y),((-x*y)*z)+1*~(x^y)+7*y' 37 | 38 | root = ast.parse(mba1000) 39 | subtree_buf = [] 40 | store_all_subtree(root, subtree_buf) 41 | m = max_common_subtree(subtree_buf) 42 | 43 | print(m[0]) 44 | print(astunparse.unparse(m[1])) 45 | 46 | if __name__ =="__main__": 47 | # sourcefilename = sys.argv[1] 48 | # main(sourcefilename) 49 | main() 50 | -------------------------------------------------------------------------------- /tools/mba_string_operation.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softsec-unh/MBA-Solver/c76231aadb8b033d9e8e6be2baa05ff1464f247e/tools/mba_string_operation.pyc -------------------------------------------------------------------------------- /z3_solving/makefile: -------------------------------------------------------------------------------- 1 | timeout = 5 2 | 3 | z3-linear-before-simplify: 4 | python3 z3_check_before_simplify.py ../dataset/pldi_dataset_linear_MBA.txt $(timeout) 5 | 6 | z3-poly-before-simplify: 7 | python3 z3_check_before_simplify.py ../dataset/pldi_dataset_poly_MBA.txt $(timeout) 8 | 9 | z3-nonpoly-before-simplify: 10 | python3 z3_check_before_simplify.py ../dataset/pldi_dataset_nonpoly_MBA.txt $(timeout) 11 | 12 | z3-linear-after-simplify: 13 | python3 z3_check_after_simplify.py ../dataset/pldi_dataset_linear_MBA.txt.simplify.txt $(timeout) 14 | 15 | z3-poly-after-simplify: 16 | python3 z3_check_after_simplify.py ../dataset/pldi_dataset_poly_MBA.txt.simplify.txt $(timeout) 17 | 18 | z3-nonpoly-after-simplify: 19 | python3 z3_check_after_simplify.py ../dataset/pldi_dataset_nonpoly_MBA.txt.simplify.txt $(timeout) 20 | 21 | z3-linear-after-simplify-sspam: 22 | python3 z3_check_after_simplify_peertools.py ../sspam/linear.MBA.SSPAM.result.txt $(timeout) 23 | 24 | z3-poly-after-simplify-sspam: 25 | python3 z3_check_after_simplify_peertools.py ../sspam/poly.MBA.SSPAM.result.txt $(timeout) 26 | 27 | z3-nonpoly-after-simplify-sspam: 28 | python3 z3_check_after_simplify_peertools.py ../sspam/nonpoly.MBA.SSPAM.result.txt $(timeout) 29 | 30 | z3-linear-after-simplify-syntia: 31 | python3 z3_check_after_simplify_peertools.py ../syntia/linear.64bit.result.txt $(timeout) 32 | 33 | z3-poly-after-simplify-syntia: 34 | python3 z3_check_after_simplify_peertools.py ../syntia/poly.64bit.result.txt $(timeout) 35 | 36 | z3-nonpoly-after-simplify-syntia: 37 | python3 z3_check_after_simplify_peertools.py ../syntia/nonpoly.64bit.result.txt $(timeout) 38 | 39 | z3-solving-before-simplify-total: 40 | python3 total.py z3 0 41 | z3-solving-before-simplify: 42 | @echo "--------------------z3 solving linear MBA samples-------------------------" 43 | @make z3-linear-before-simplify 44 | @echo "--------------------z3 solving linear MBA samples completion--------------" 45 | @echo "--------------------z3 solving poly MBA samples---------------------------" 46 | @make z3-poly-before-simplify 47 | @echo "--------------------z3 solving poly MBA samples completion----------------" 48 | @echo "--------------------z3 solving nonpoly MBA samples------------------------" 49 | @make z3-nonpoly-before-simplify 50 | @echo "--------------------z3 solving nonpoly MBA samples completion-------------" 51 | @echo "--------------------z3 solving MBA samples -------------------------------" 52 | @make z3-solving-before-simplify-total 53 | 54 | z3-solving-mba-solver-total: 55 | python3 total.py z3 1 mba 56 | z3-solving-mba-solver: 57 | @echo "--------------------z3 solving linear MBA samples after MBA-Solver simplification--------------------------" 58 | @make z3-linear-after-simplify 59 | @echo "--------------------z3 solving linear MBA samples after MBA-Solver simplification completion---------------" 60 | @echo "--------------------z3 solving poly MBA samples after MBA-Solver simplification----------------------------" 61 | @make z3-poly-after-simplify 62 | @echo "--------------------z3 solving poly MBA samples after MBA-Solver simplification completion-----------------" 63 | @echo "--------------------z3 solving nonpoly MBA samples after MBA-Solver simplification-------------------------" 64 | @make z3-nonpoly-after-simplify 65 | @echo "--------------------z3 solving nonpoly MBA samples after MBA-Solver simplification completion--------------" 66 | @echo "--------------------z3 solving MBA samples after MBA-Solver simplification --------------" 67 | @make z3-solving-mba-solver-total 68 | 69 | z3-solving-sspam-total: 70 | python3 total.py z3 1 sspam 71 | z3-solving-sspam: 72 | @echo "--------------------z3 solving linear MBA samples after SSPAM simplification--------------------------" 73 | @make z3-linear-after-simplify-sspam 74 | @echo "--------------------z3 solving linear MBA samples after SSPAM simplification completion---------------" 75 | @echo "--------------------z3 solving poly MBA samples after SSPAM simplification----------------------------" 76 | @make z3-poly-after-simplify-sspam 77 | @echo "--------------------z3 solving poly MBA samples after SSPAM simplification completion-----------------" 78 | @echo "--------------------z3 solving nonpoly MBA samples after SSPAM simplification-------------------------" 79 | @make z3-nonpoly-after-simplify-sspam 80 | @echo "--------------------z3 solving nonpoly MBA samples after SSPAM simplification completion--------------" 81 | @echo "--------------------z3 solving MBA samples after SSPAM simplification --------------" 82 | @make z3-solving-sspam-total 83 | 84 | z3-solving-syntia-total: 85 | python3 total.py z3 1 syntia 86 | z3-solving-syntia: 87 | @echo "--------------------z3 solving linear MBA samples after Syntia simplification--------------------------" 88 | @make z3-linear-after-simplify-syntia 89 | @echo "--------------------z3 solving linear MBA samples after Syntia simplification completion---------------" 90 | @echo "--------------------z3 solving poly MBA samples after Syntia simplification----------------------------" 91 | @make z3-poly-after-simplify-syntia 92 | @echo "--------------------z3 solving poly MBA samples after Syntia simplification completion-----------------" 93 | @echo "--------------------z3 solving nonpoly MBA samples after Syntia simplification-------------------------" 94 | @make z3-nonpoly-after-simplify-syntia 95 | @echo "--------------------z3 solving nonpoly MBA samples after Syntia simplification completion--------------" 96 | @echo "--------------------z3 solving MBA samples after Syntia simplification--------------" 97 | @make z3-solving-syntia-total 98 | -------------------------------------------------------------------------------- /z3_solving/total.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import re 4 | import sys 5 | import time 6 | 7 | 8 | 9 | def total_simplify(smtsolver, solver): 10 | """count the solving number after solving by smt solver. 11 | """ 12 | true = 0 13 | false = 0 14 | timeout = 0 15 | 16 | if "mba" in solver: 17 | path = "../dataset" 18 | dataFile = ["linear", "poly", "nonpoly"] 19 | for data in dataFile: 20 | fileread = "{path}/pldi_dataset_{data}_MBA.txt.simplify.txt.{smtsolver}.verify.64bit.after.simplify.txt".format(path=path, data=data, smtsolver=smtsolver) 21 | with open(fileread, "r") as fr: 22 | for line in fr: 23 | line = line.strip().replace(" ", "") 24 | if "#" not in line: 25 | expreStrList = re.split(",", line) 26 | flag = expreStrList[4] 27 | if "ue" in flag: 28 | true += 1 29 | elif "out" in flag: 30 | timeout += 1 31 | else: 32 | false += 1 33 | elif "sspam" in solver: 34 | path = "../sspam" 35 | dataFile = ["linear", "poly", "nonpoly"] 36 | for data in dataFile: 37 | fileread = "{path}/{data}.MBA.SSPAM.result.txt.{smtsolver}.verify.64bit.after.simplify.txt".format(path=path, data=data, smtsolver=smtsolver) 38 | with open(fileread, "r") as fr: 39 | for line in fr: 40 | line = line.strip().replace(" ", "") 41 | if "#" not in line: 42 | expreStrList = re.split(",", line) 43 | flag = expreStrList[3] 44 | if "ue" in flag: 45 | true += 1 46 | elif "out" in flag: 47 | timeout += 1 48 | else: 49 | false += 1 50 | elif "syntia" in solver: 51 | path = "../syntia" 52 | dataFile = ["linear", "poly", "nonpoly"] 53 | for data in dataFile: 54 | fileread = "{path}/{data}.64bit.result.txt.{smtsolver}.verify.64bit.after.simplify.txt".format(path=path, data=data, smtsolver=smtsolver) 55 | with open(fileread, "r") as fr: 56 | for line in fr: 57 | line = line.strip().replace(" ", "") 58 | if "#" not in line: 59 | expreStrList = re.split(",", line) 60 | flag = expreStrList[3] 61 | if "ue" in flag: 62 | true += 1 63 | elif "out" in flag: 64 | timeout += 1 65 | else: 66 | false += 1 67 | total = true + false + timeout 68 | print("Total: ", total) 69 | print("True: ", true) 70 | print("False: ", false) 71 | print("Timeout: ", timeout) 72 | 73 | return None 74 | 75 | 76 | 77 | def total_original(smtsolver): 78 | """count the solving number before solving by smt solver. 79 | """ 80 | true = 0 81 | false = 0 82 | timeout = 0 83 | 84 | 85 | path = "../dataset" 86 | dataFile = ["linear", "poly", "nonpoly"] 87 | for data in dataFile: 88 | fileread = "{path}/pldi_dataset_{data}_MBA.txt.{smtsolver}.verify.64bit.before.simplify.txt".format(path=path, data=data, smtsolver=smtsolver) 89 | with open(fileread, "r") as fr: 90 | for line in fr: 91 | line = line.strip().replace(" ", "") 92 | if "#" not in line: 93 | expreStrList = re.split(",", line) 94 | flag = expreStrList[2] 95 | if "ue" in flag: 96 | true += 1 97 | elif "out" in flag: 98 | timeout += 1 99 | else: 100 | false += 1 101 | total = true+false+timeout 102 | print("Total: ", total) 103 | print("True: ", true) 104 | print("False: ", false) 105 | print("Timeout: ", timeout) 106 | 107 | return None 108 | 109 | 110 | 111 | 112 | 113 | def main(smtsolver, flag, solver=None): 114 | if flag: 115 | #after simplification 116 | total_simplify(smtsolver, solver) 117 | else: 118 | #before simplification 119 | total_original(smtsolver) 120 | 121 | 122 | 123 | if __name__ =="__main__": 124 | #smt solver 125 | smtsolver = sys.argv[1] 126 | #before/after simplification 127 | flag = int(sys.argv[2]) 128 | #if simplificationn, tools 129 | if len(sys.argv) > 3: 130 | solver = sys.argv[3] 131 | main(smtsolver, flag, solver) 132 | else: 133 | main(smtsolver, flag) 134 | 135 | 136 | -------------------------------------------------------------------------------- /z3_solving/z3_check_after_simplify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import re 4 | import sys 5 | import time 6 | import z3 7 | from multiprocessing import Process, Value 8 | 9 | def verify_mba_unsat(leftExpre, rightExpre, bitnumber, res): 10 | """check the relaion whether the left expression is euqal to the right expression. 11 | Args: 12 | leftExpre: left expression. 13 | rightExpre: right expression. 14 | bitnumber: the number of the bits of the variable. 15 | Returns: 16 | True: equation. 17 | False: unequal. 18 | Raises: 19 | None. 20 | """ 21 | x,y,z,t,a,b,c,d,e,f = z3.BitVecs("x y z t a b c d e f", bitnumber) 22 | 23 | try: 24 | leftEval = eval(leftExpre) 25 | rightEval = eval(rightExpre) 26 | solver = z3.Solver() 27 | solver.add(leftEval != rightEval) 28 | result = solver.check() 29 | except: 30 | res.value = 2 31 | return None 32 | 33 | if str(result) != "unsat": 34 | res.value = 2 # False 35 | else: 36 | res.value = 1 # True 37 | 38 | return None 39 | 40 | 41 | def z3_check_time(sourcefilename, timeout, bv=64): 42 | """input the expression from the source file, then check the equation and output the time of process to desination file. 43 | Args: 44 | sourcefilename: source file. 45 | bv: the bit of the variable. 46 | """ 47 | desfilename = "{source}.z3.verify.{bv}bit.after.simplify.txt".format(source=sourcefilename, bv=bv) 48 | fwrite = open(desfilename, "w") 49 | print("#complex,groundtruth,simcomplex,simground,z3res,verificationtime", file=fwrite) 50 | 51 | solvingList = [0, 0, 0] 52 | with open(sourcefilename, "r") as data: 53 | linenum = 0 54 | for line in data: 55 | line = line.strip().replace(" ", "") 56 | if "#" not in line: 57 | expreStrList = re.split(",", line) 58 | sourceExpreStr = expreStrList[0] 59 | groundtruthStr = expreStrList[1] 60 | sourceSimStr = expreStrList[2] 61 | groundtruthSimStr = expreStrList[3] 62 | start = time.time() 63 | 64 | res = Value('i', 0) # Default value is 0 65 | # res = verify_mba_unsat(sourceSimStr, groundtruthSimStr, bv) 66 | p = Process(target=verify_mba_unsat, args=(sourceSimStr, groundtruthSimStr, bv, res,)) 67 | p.start() 68 | p.join(timeout) # wait timeout seconds or it finishes 69 | 70 | if p.is_alive(): 71 | print("Still solving, but kill it as timeout set to", timeout, "seconds ...") 72 | p.terminate() 73 | p.join() 74 | 75 | result = { 76 | 0: "Timeout", 77 | 1: "True", 78 | 2: "False", 79 | } 80 | 81 | end = time.time() 82 | elapsed = end - start 83 | print(sourceExpreStr, groundtruthStr, sourceSimStr, groundtruthSimStr, result[res.value], elapsed, sep=",", file=fwrite, flush=True) 84 | 85 | # print(linenum, sourceExpreStr, groundtruthStr, sourceSimStr, groundtruthSimStr, result[res.value], elapsed) 86 | print(linenum, result[res.value], "Time =", elapsed) 87 | linenum += 1 88 | solvingList[res.value] += 1 89 | 90 | fwrite.close() 91 | print("Timeout: ", solvingList[0]) 92 | print("True: ", solvingList[1]) 93 | print("False: ", solvingList[2]) 94 | return None 95 | 96 | 97 | 98 | 99 | def main(sourcefilename, timeout): 100 | z3_check_time(sourcefilename, timeout) 101 | 102 | 103 | 104 | if __name__ =="__main__": 105 | sourcefilename = sys.argv[1] 106 | timeout = int(sys.argv[2]) 107 | main(sourcefilename, timeout) 108 | -------------------------------------------------------------------------------- /z3_solving/z3_check_after_simplify_peertools.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import re 4 | import sys 5 | import time 6 | import z3 7 | from multiprocessing import Process, Value 8 | 9 | def verify_mba_unsat(leftExpre, rightExpre, bitnumber, res): 10 | """check the relaion whether the left expression is euqal to the right expression. 11 | Args: 12 | leftExpre: left expression. 13 | rightExpre: right expression. 14 | bitnumber: the number of the bits of the variable. 15 | Returns: 16 | True: equation. 17 | False: unequal. 18 | Raises: 19 | None. 20 | """ 21 | x,y,z,t,a,b,c,d,e,f = z3.BitVecs("x y z t a b c d e f", bitnumber) 22 | try: 23 | leftEval = eval(leftExpre) 24 | rightEval = eval(rightExpre) 25 | solver = z3.Solver() 26 | solver.add(leftEval != rightEval) 27 | result = solver.check() 28 | except: 29 | res.value = 2 30 | return None 31 | 32 | if str(result) != "unsat": 33 | res.value = 2 # False 34 | else: 35 | res.value = 1 # True 36 | 37 | return None 38 | 39 | 40 | 41 | def z3_check_time(sourcefilename, timeout, bv=64): 42 | """input the expression from the source file, then check the equation and output the time of process to desination file. 43 | Args: 44 | sourcefilename: source file. 45 | bv: the bit of the variable. 46 | """ 47 | desfilename = "{source}.z3.verify.{bv}bit.after.simplify.txt".format(source=sourcefilename, bv=bv) 48 | fwrite = open(desfilename, "w") 49 | print("#complex,groundtruth,simcomplex,z3res,verificationtime", file=fwrite) 50 | 51 | solvingList = [0, 0, 0] 52 | with open(sourcefilename, "r") as data: 53 | linenum = 0 54 | for line in data: 55 | line = line.strip().replace(" ", "") 56 | if "#" not in line: 57 | expreStrList = re.split(",", line) 58 | sourceExpreStr = expreStrList[0] 59 | groundtruthStr = expreStrList[1] 60 | sourceSimStr = expreStrList[2] 61 | start = time.time() 62 | 63 | res = Value('i', 0) # Default value is 0 64 | # res = verify_mba_unsat(sourceSimStr, groundtruthSimStr, bv) 65 | p = Process(target=verify_mba_unsat, args=(sourceSimStr, groundtruthStr, bv, res,)) 66 | p.start() 67 | p.join(timeout) # wait timeout seconds or it finishes 68 | 69 | if p.is_alive(): 70 | print("Still solving, but kill it as timeout set to", timeout, "seconds ...") 71 | p.terminate() 72 | p.join() 73 | 74 | result = { 75 | 0: "Timeout", 76 | 1: "True", 77 | 2: "False", 78 | } 79 | 80 | end = time.time() 81 | elapsed = end - start 82 | print(sourceExpreStr, groundtruthStr, sourceSimStr, result[res.value], elapsed, sep=",", file=fwrite, flush=True) 83 | 84 | # print(linenum, sourceExpreStr, groundtruthStr, sourceSimStr, result[res.value], elapsed) 85 | print(linenum, result[res.value], "Time =", elapsed) 86 | linenum += 1 87 | solvingList[res.value] += 1 88 | 89 | fwrite.close() 90 | print("Timeout: ", solvingList[0]) 91 | print("True: ", solvingList[1]) 92 | print("False: ", solvingList[2]) 93 | return None 94 | 95 | 96 | 97 | 98 | def main(sourcefilename, timeout): 99 | z3_check_time(sourcefilename, timeout) 100 | 101 | 102 | 103 | if __name__ =="__main__": 104 | sourcefilename = sys.argv[1] 105 | timeout = int(sys.argv[2]) 106 | main(sourcefilename, timeout) 107 | -------------------------------------------------------------------------------- /z3_solving/z3_check_before_simplify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import re 4 | import sys 5 | import time 6 | import z3 7 | from multiprocessing import Process, Value 8 | 9 | def verify_mba_unsat(leftExpre, rightExpre, bitnumber, res): 10 | """check the relaion whether the left expression is euqal to the right expression. 11 | Args: 12 | leftExpre: left expression. 13 | rightExpre: right expression. 14 | bitnumber: the number of the bits of the variable. 15 | Returns: 16 | True: equation. 17 | False: unequal. 18 | Raises: 19 | None. 20 | """ 21 | x,y,z,t,a,b,c,d,e,f = z3.BitVecs("x y z t a b c d e f", bitnumber) 22 | 23 | try: 24 | leftEval = eval(leftExpre) 25 | rightEval = eval(rightExpre) 26 | solver = z3.Solver() 27 | solver.add(leftEval != rightEval) 28 | result = solver.check() 29 | except: 30 | res.value = 2 31 | return None 32 | 33 | if str(result) != "unsat": 34 | res.value = 2 # False 35 | else: 36 | res.value = 1 # True 37 | 38 | return None 39 | 40 | 41 | def z3_check_time(sourcefilename, timeout, bv=64): 42 | """input the expression from the source file, then check the equation and output the time of process to desination file. 43 | Args: 44 | sourcefilename: source file. 45 | bv: the bit of the variable. 46 | """ 47 | desfilename = "{source}.z3.verify.{bv}bit.before.simplify.txt".format(source=sourcefilename, bv=bv) 48 | fwrite = open(desfilename, "w") 49 | print("#complex,groundtruth,z3res,verificationtime", file=fwrite) 50 | 51 | solvingList = [0, 0, 0] 52 | with open(sourcefilename, "r") as data: 53 | linenum = 0 54 | for line in data: 55 | line = line.strip().replace(" ", "") 56 | if "#" not in line: 57 | expreStrList = re.split(",", line) 58 | sourceExpreStr = expreStrList[0] 59 | groundtruthStr = expreStrList[1] 60 | start = time.time() 61 | res = Value('i', 0) # Default value is 0 62 | # res = verify_mba_unsat(sourceExpreStr, groundtruthStr, bv) 63 | p = Process(target=verify_mba_unsat, args=(sourceExpreStr, groundtruthStr, bv, res,)) 64 | p.start() 65 | p.join(timeout) # wait timeout seconds or it finishes 66 | 67 | if p.is_alive(): 68 | print("Still solving, but kill it as timeout set to", timeout, "seconds ...") 69 | p.terminate() 70 | p.join() 71 | 72 | result = { 73 | 0: "Timeout", 74 | 1: "True", 75 | 2: "False", 76 | } 77 | end = time.time() 78 | elapsed = end - start 79 | print(sourceExpreStr, groundtruthStr, result[res.value], elapsed, sep=",", file=fwrite, flush=True) 80 | 81 | # print(linenum, sourceExpreStr, groundtruthStr, result[res.value], elapsed) 82 | print(linenum, result[res.value], "Time =", elapsed) 83 | linenum += 1 84 | solvingList[res.value] += 1 85 | 86 | fwrite.close() 87 | print("Timeout: ", solvingList[0]) 88 | print("True: ", solvingList[1]) 89 | print("False: ", solvingList[2]) 90 | return None 91 | 92 | 93 | def main(sourcefilename, timeout): 94 | z3_check_time(sourcefilename, timeout) 95 | 96 | 97 | 98 | if __name__ =="__main__": 99 | sourcefilename = sys.argv[1] 100 | timeout = int(sys.argv[2]) 101 | main(sourcefilename, timeout) 102 | --------------------------------------------------------------------------------