-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_keymaera_examples.py
58 lines (50 loc) · 2.6 KB
/
generate_keymaera_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import re
import sys
from pprint import pprint
ignored_sodes = 0
num_found = 0
sodes = set()
for root, _, files in os.walk("/put/the/path/to/keymaera/examples/here"):
for file_name in files:
file_path = os.path.join(root, file_name)
if file_path.endswith(".key"):
try:
with open(file_path) as fp:
for line in fp.readlines():
for bracketed in re.findall(r"\{[^}]+\}", line):
num_found += 1
#print(bracketed)
ode_vars = []
ode_eqs = []
ode_strs = re.findall(
r"[a-z0-9]+['`]\ *=\ *.+?[,}]",
bracketed,
re.IGNORECASE
)
if ode_strs == []:
print("Failed to parse ode:" + bracketed, file=sys.stderr) # TODO: look into these cases
else:
for ode_str in ode_strs:
parts = re.match(r"([a-z0-9]+)['`]\ *=\ *(.+?)[,}&]", ode_str, re.IGNORECASE)
ode_vars.append(parts.group(1))
ode_eqs.append(parts.group(2))
#"(λ (t::real) (x, y). (t, x))"
# NOTE: the independent variable is not accessed by name is KeYmaera. If
# needed, it is obtained by t' = 1 (to make t the independent
# variable).
conv_str = f"(λ ind ({', '.join(ode_vars)}). ({', '.join(ode_eqs)}))"
if False and all((re.match(r"^(-?([a-z0-9]+|([0-9](\.[0-9])?)+))$", ode_eq, re.IGNORECASE) is not None
for ode_eq in ode_eqs)):
print("Ignoring: " + conv_str, file=sys.stderr)
ignored_sodes += 1
else:
print("Adding: " + conv_str + "from: " + line)
sodes.add("ode_solve_thm \"" + conv_str + "\"")
except:
print("Error in :" + file_path)
raise
print("Found: " + str(num_found), file=sys.stderr)
print("Generated: " + str(len(sodes)), file=sys.stderr)
print("Ignored: " + str(ignored_sodes), file=sys.stderr)
print("\n".join(sodes))