Spaces:
Sleeping
Sleeping
Commit
·
ea7fc19
1
Parent(s):
86dc7f0
Enrich string examples
Browse files- README.md +18 -1
- examples.py +7 -2
- synthesis.py +2 -2
README.md
CHANGED
@@ -50,6 +50,23 @@ Program weight: 3
|
|
50 |
Program return type: int
|
51 |
```
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
To add additional input-output examples, modify `examples.py`. Add a new key to the dictionary `example_set` and set the value to be a list of tuples.
|
54 |
|
55 |
## 🔎 Abstract Syntax Tree
|
@@ -85,7 +102,7 @@ source setup_jupyter.sh
|
|
85 |
|
86 |
## 🙏🏽 Acknowledgements
|
87 |
|
88 |
-
I thank [Tyler Holloway](mailto:[email protected]), teaching fellow in CS252R, for her guidance
|
89 |
|
90 |
## 📫 Contact
|
91 |
|
|
|
50 |
Program return type: int
|
51 |
```
|
52 |
|
53 |
+
We could also try a more involved example in the string domain:
|
54 |
+
```
|
55 |
+
python synthesis.py --domain strings --example concatenate_3 --max-weight 5
|
56 |
+
|
57 |
+
Synthesis Log:
|
58 |
+
- Extracted 13 constants from examples.
|
59 |
+
- Searching level 2 with 13 primitives.
|
60 |
+
- Searching level 3 with 79 primitives.
|
61 |
+
- Searching level 4 with 79 primitives.
|
62 |
+
|
63 |
+
Synthesis Results:
|
64 |
+
- Program found in 1.9864s.
|
65 |
+
- Program: Concat(x0, Concat(x1, x2))
|
66 |
+
- Program weight: 5
|
67 |
+
- Program return type: str
|
68 |
+
```
|
69 |
+
|
70 |
To add additional input-output examples, modify `examples.py`. Add a new key to the dictionary `example_set` and set the value to be a list of tuples.
|
71 |
|
72 |
## 🔎 Abstract Syntax Tree
|
|
|
102 |
|
103 |
## 🙏🏽 Acknowledgements
|
104 |
|
105 |
+
I thank [Tyler Holloway](mailto:[email protected]), teaching fellow in CS252R, for her guidance.
|
106 |
|
107 |
## 📫 Contact
|
108 |
|
examples.py
CHANGED
@@ -17,12 +17,17 @@ example_set = {
|
|
17 |
'multiplication': [([2, 3], 6), ([4, 5], 20), ([7, 8], 56), ([9, 2], 18), ([3, 4], 12)],
|
18 |
'division': [([6, 2], 3), ([8, 4], 2), ([9, 3], 3), ([10, 5], 2), ([12, 6], 2)],
|
19 |
|
20 |
-
#
|
21 |
'add_5_multiply_2': [([1, 2], 12), ([3, 4], 22), ([5, 6], 32), ([7, 8], 42), ([9, 10], 52)],
|
22 |
'multiply_add_9': [([1, 2], 11), ([3, 4], 21), ([5, 6], 39), ([7, 8], 65), ([9, 10], 9)],
|
23 |
|
24 |
-
# string examples
|
25 |
'concatenate': [(["a", "b"], "ab"), (["c", "d"], "cd"), (["e", "f"], "ef")],
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
# custom user examples
|
28 |
}
|
|
|
17 |
'multiplication': [([2, 3], 6), ([4, 5], 20), ([7, 8], 56), ([9, 2], 18), ([3, 4], 12)],
|
18 |
'division': [([6, 2], 3), ([8, 4], 2), ([9, 3], 3), ([10, 5], 2), ([12, 6], 2)],
|
19 |
|
20 |
+
# advanced arithmetic examples
|
21 |
'add_5_multiply_2': [([1, 2], 12), ([3, 4], 22), ([5, 6], 32), ([7, 8], 42), ([9, 10], 52)],
|
22 |
'multiply_add_9': [([1, 2], 11), ([3, 4], 21), ([5, 6], 39), ([7, 8], 65), ([9, 10], 9)],
|
23 |
|
24 |
+
# basic string examples
|
25 |
'concatenate': [(["a", "b"], "ab"), (["c", "d"], "cd"), (["e", "f"], "ef")],
|
26 |
+
'right': [(["hello", 3], "llo"), (["world", 4], "orld"), (["fox", 1], "x")],
|
27 |
+
'left': [(["hello", 2], "he"), (["world", 3], "wor"), (["fox", 2], "fo")],
|
28 |
+
|
29 |
+
# advanced string examples
|
30 |
+
'concatenate_3': [(["a", "b", "c"], "abc"), (["d", "e", "f"], "def"), (["g", "h", "i"], "ghi")],
|
31 |
|
32 |
# custom user examples
|
33 |
}
|
synthesis.py
CHANGED
@@ -30,7 +30,7 @@ def parse_args():
|
|
30 |
parser = argparse.ArgumentParser(description="Bottom-up enumerative synthesis in Python.")
|
31 |
|
32 |
# define valid choices for the 'domain' argument
|
33 |
-
valid_domain_choices = ["arithmetic", "
|
34 |
|
35 |
# add examples
|
36 |
parser.add_argument('--domain', type=str, required=True, # default="arithmetic",
|
@@ -139,7 +139,7 @@ def run_synthesizer(args):
|
|
139 |
# define operators
|
140 |
if args.domain == "arithmetic":
|
141 |
operators = arithmetic_operators
|
142 |
-
elif args.domain == "
|
143 |
operators = string_operators
|
144 |
else:
|
145 |
raise Exception('Domain not recognized. Must be either "arithmetic" or "string".')
|
|
|
30 |
parser = argparse.ArgumentParser(description="Bottom-up enumerative synthesis in Python.")
|
31 |
|
32 |
# define valid choices for the 'domain' argument
|
33 |
+
valid_domain_choices = ["arithmetic", "strings"]
|
34 |
|
35 |
# add examples
|
36 |
parser.add_argument('--domain', type=str, required=True, # default="arithmetic",
|
|
|
139 |
# define operators
|
140 |
if args.domain == "arithmetic":
|
141 |
operators = arithmetic_operators
|
142 |
+
elif args.domain == "strings":
|
143 |
operators = string_operators
|
144 |
else:
|
145 |
raise Exception('Domain not recognized. Must be either "arithmetic" or "string".')
|