tinyprove 0.1.4__tar.gz → 0.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tinyprove-0.1.4 → tinyprove-0.1.6}/PKG-INFO +1 -1
- {tinyprove-0.1.4 → tinyprove-0.1.6}/pyproject.toml +1 -1
- {tinyprove-0.1.4 → tinyprove-0.1.6}/src/tinyprove/inductive.py +35 -31
- {tinyprove-0.1.4 → tinyprove-0.1.6}/src/tinyprove/parser.py +11 -2
- {tinyprove-0.1.4 → tinyprove-0.1.6}/src/tinyprove.egg-info/PKG-INFO +1 -1
- {tinyprove-0.1.4 → tinyprove-0.1.6}/test/test.py +1 -1
- {tinyprove-0.1.4 → tinyprove-0.1.6}/README.md +0 -0
- {tinyprove-0.1.4 → tinyprove-0.1.6}/setup.cfg +0 -0
- {tinyprove-0.1.4 → tinyprove-0.1.6}/src/tinyprove/__init__.py +0 -0
- {tinyprove-0.1.4 → tinyprove-0.1.6}/src/tinyprove/axiom_defs.py +0 -0
- {tinyprove-0.1.4 → tinyprove-0.1.6}/src/tinyprove/core.py +0 -0
- {tinyprove-0.1.4 → tinyprove-0.1.6}/src/tinyprove/ir.py +0 -0
- {tinyprove-0.1.4 → tinyprove-0.1.6}/src/tinyprove.egg-info/SOURCES.txt +0 -0
- {tinyprove-0.1.4 → tinyprove-0.1.6}/src/tinyprove.egg-info/dependency_links.txt +0 -0
- {tinyprove-0.1.4 → tinyprove-0.1.6}/src/tinyprove.egg-info/top_level.txt +0 -0
|
@@ -52,28 +52,33 @@ class DefsExtend:
|
|
|
52
52
|
return self.base_defns.match_reduce(key, argchain, defns)
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
def type_level(
|
|
55
|
+
def type_level(ty_whnf:Term, ctx:List[Tuple[str, Term]], defns:Definitions):
|
|
56
56
|
""" Compute the effective universe level of a type. """
|
|
57
|
-
ty_whnf = whnf(ty, defns)
|
|
58
57
|
if isinstance(ty_whnf, Sort):
|
|
59
58
|
return ty_whnf.level
|
|
60
59
|
else:
|
|
61
60
|
ty_ty = whnf(infer(ty_whnf, ctx, defns), defns)
|
|
62
61
|
if not isinstance(ty_ty, Sort):
|
|
63
|
-
raise TypecheckError(f"Expected {
|
|
62
|
+
raise TypecheckError(f"Expected {ty_whnf.str(ctx)} to be a Sort but found type {ty_ty.str(ctx)}.")
|
|
64
63
|
return ty_ty.level
|
|
65
64
|
|
|
66
65
|
|
|
67
|
-
def typecheck_args(args:List[Tuple[str, IrNode]], ctx:List[Tuple[str, Term]], selfref_ir:IrNode, defns:Definitions,
|
|
66
|
+
def typecheck_args(args:List[Tuple[str, IrNode]], ctx:List[Tuple[str, Term]], selfref_ir:IrNode, defns:Definitions,
|
|
67
|
+
max_level:int|None=None, positive_typenm:str|None=None):
|
|
68
68
|
""" Given a list of args that might be type parameters or constructor args,
|
|
69
69
|
check that they are all some kind of Sort. Returns a full ctx containing all args. """
|
|
70
70
|
if len(args) == 0: return ctx
|
|
71
71
|
(arg_nm, arg_ty_ir), *args_rest = args
|
|
72
72
|
arg_ty = selfref_sub(arg_ty_ir, selfref_ir).to_term(ctx_to_names(ctx))
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
arg_ty_whnf = whnf(arg_ty, defns)
|
|
74
|
+
ty_level = type_level(arg_ty_whnf, ctx, defns) # typecheck and get the type's level
|
|
75
|
+
if max_level is not None and ty_level > max_level: # ensure constructor arguments lie within the correct universe
|
|
75
76
|
raise TypecheckError(f"Argument {arg_nm} is at the Type{ty_level} level but at most Type{max_level} would be sound.")
|
|
76
|
-
|
|
77
|
+
if positive_typenm is not None: # do a positivity check if a typename that must be positive was specificed
|
|
78
|
+
if not all(walk(positive_typenm, arg_ty_whnf, defns)):
|
|
79
|
+
raise DefinitionError(f"Constructor arg {arg_nm} fails positivity check.")
|
|
80
|
+
return typecheck_args(args_rest, [(arg_nm, arg_ty)] + ctx, selfref_ir, defns,
|
|
81
|
+
max_level, positive_typenm)
|
|
77
82
|
|
|
78
83
|
|
|
79
84
|
@dataclass(frozen=True)
|
|
@@ -122,28 +127,31 @@ def selfref_sub(node:IrNode, selfref_ir:IrNode) -> IrNode:
|
|
|
122
127
|
raise DefinitionError("Unknown node type.")
|
|
123
128
|
|
|
124
129
|
|
|
125
|
-
def walk(indty_name: str,
|
|
126
|
-
""" Do a polarity check of node
|
|
130
|
+
def walk(indty_name: str, arg_ty:Term, defns:Definitions, polarity:bool=True) -> List[bool]:
|
|
131
|
+
""" Do a polarity check of node and returns a list of polarities of self-references.
|
|
127
132
|
polarity: True = positive, and False = negative """
|
|
128
|
-
|
|
129
|
-
|
|
133
|
+
arg_ty = whnf(arg_ty, defns)
|
|
134
|
+
match arg_ty:
|
|
135
|
+
case Lam():
|
|
130
136
|
raise DefinitionError("Lambdas not supported in constructor definition.")
|
|
131
|
-
case
|
|
132
|
-
return walk(indty_name, A, not polarity)
|
|
133
|
-
case
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return
|
|
139
|
-
case
|
|
137
|
+
case Pi(param, A, B):
|
|
138
|
+
return walk(indty_name, A, defns, not polarity) + walk(indty_name, B, defns, polarity)
|
|
139
|
+
case App(fn, arg):
|
|
140
|
+
arg_appearances = [
|
|
141
|
+
False # this application could produce a result where the inductive type appears negatively
|
|
142
|
+
for _ in walk(indty_name, arg, defns, polarity)
|
|
143
|
+
]
|
|
144
|
+
return walk(indty_name, fn, defns, polarity) + arg_appearances
|
|
145
|
+
case Sort():
|
|
146
|
+
return []
|
|
147
|
+
case Var():
|
|
148
|
+
return []
|
|
149
|
+
case Const(name):
|
|
140
150
|
if name == indty_name:
|
|
141
|
-
|
|
142
|
-
return
|
|
143
|
-
case IrInductiveSelfRef(index_vals):
|
|
144
|
-
return polarity
|
|
151
|
+
return [polarity]
|
|
152
|
+
return []
|
|
145
153
|
case _:
|
|
146
|
-
raise DefinitionError("Unknown
|
|
154
|
+
raise DefinitionError("Unknown term.")
|
|
147
155
|
|
|
148
156
|
|
|
149
157
|
class ConstructorDef:
|
|
@@ -155,8 +163,8 @@ class ConstructorDef:
|
|
|
155
163
|
self.args = args
|
|
156
164
|
self.output_indices = output_indices
|
|
157
165
|
# type & positivity checking:
|
|
158
|
-
constructor_ctx = typecheck_args(self.args, self.indty.params_ctx, self.indty.selfref_ir, self.indty.defns_ext,
|
|
159
|
-
|
|
166
|
+
constructor_ctx = typecheck_args(self.args, self.indty.params_ctx, self.indty.selfref_ir, self.indty.defns_ext,
|
|
167
|
+
max_level=self.indty.get_level(), positive_typenm=self.indty.name)
|
|
160
168
|
self.check_output_indices(constructor_ctx, self.indty.inds_ctx)
|
|
161
169
|
# prep data that will be used by match-reduce
|
|
162
170
|
self.matchred_sig = self.get_matchred_sig()
|
|
@@ -190,10 +198,6 @@ class ConstructorDef:
|
|
|
190
198
|
self.output_indices),
|
|
191
199
|
applied_constructor_ty),
|
|
192
200
|
converted_args[::-1])
|
|
193
|
-
def check_positive(self):
|
|
194
|
-
for arg_nm, arg_ty in self.args:
|
|
195
|
-
if not walk(self.indty.name, arg_ty):
|
|
196
|
-
raise DefinitionError(f"Constructor {self.name} arg {arg_nm} fails positivity check.")
|
|
197
201
|
def check_output_indices(self, constructor_ctx:List[Tuple[str, Term]], inds_ctx:List[Tuple[str, Term]]):
|
|
198
202
|
num_inds = len(self.indty.indices)
|
|
199
203
|
assert len(self.output_indices) == num_inds, f"Constructor {self.name} definition has incorrect number of output indices."
|
|
@@ -16,14 +16,23 @@ _token_re = re.compile(
|
|
|
16
16
|
[\[\]()\|,:=λΠδι]| # punctuation (unicode lambdas, etc.)
|
|
17
17
|
""" + _ident_re + """ # identifiers
|
|
18
18
|
)
|
|
19
|
+
\s* # skip trailing whitespace
|
|
19
20
|
""",
|
|
20
21
|
re.VERBOSE,
|
|
21
22
|
)
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
def _tokenise(src: str) -> List[str]:
|
|
25
|
-
"""Return a
|
|
26
|
-
|
|
26
|
+
""" Return a list of string tokens (whitespace already stripped). """
|
|
27
|
+
pos = 0
|
|
28
|
+
ans = []
|
|
29
|
+
while pos < len(src):
|
|
30
|
+
m = _token_re.match(src, pos)
|
|
31
|
+
if not m:
|
|
32
|
+
raise SyntaxError(f"Unexpected character at position {pos}: {repr(src[pos])}")
|
|
33
|
+
ans.append(m.group(1))
|
|
34
|
+
pos = m.end()
|
|
35
|
+
return ans
|
|
27
36
|
|
|
28
37
|
|
|
29
38
|
def strip_comments(src:str) -> str:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|