Skip to content

Commit 57d6aad

Browse files
committed
made name overlap more strict. maybe this makes external solvers easier?
1 parent 02e4902 commit 57d6aad

File tree

11 files changed

+95
-2748
lines changed

11 files changed

+95
-2748
lines changed

examples/soft_found/lf/Basics.ipynb

Lines changed: 0 additions & 2673 deletions
This file was deleted.

examples/soft_found/lf/Basics.py

Lines changed: 74 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
| saturday
9292
| sunday.
9393
"""
94-
#from kdrag.all import *
94+
95+
# from kdrag.all import *
9596
import kdrag as kd
9697
from kdrag import smt
9798

@@ -118,15 +119,19 @@
118119
end.
119120
"""
120121
d = smt.Const("d", day)
121-
next_weekday = kd.define("next_weekday", [d], kd.cond(
122-
(d.is_monday, day.tuesday),
123-
(d.is_tuesday, day.wednesday),
124-
(d.is_wednesday, day.thursday),
125-
(d.is_thursday, day.friday),
126-
(d.is_friday, day.monday),
127-
(d.is_saturday, day.monday),
128-
(d.is_sunday, day.monday),
129-
))
122+
next_weekday = kd.define(
123+
"next_weekday",
124+
[d],
125+
kd.cond(
126+
(d.is_monday, day.tuesday),
127+
(d.is_tuesday, day.wednesday),
128+
(d.is_wednesday, day.thursday),
129+
(d.is_thursday, day.friday),
130+
(d.is_friday, day.monday),
131+
(d.is_saturday, day.monday),
132+
(d.is_sunday, day.monday),
133+
),
134+
)
130135

131136

132137
# %% [markdown]
@@ -155,7 +160,7 @@
155160
# interpreter under your favorite IDE (see the [Preface] for
156161
# installation instructions) and try it for yourself. Load this
157162
# file, [Basics.v], from the book's Coq sources, find the above
158-
# example, submit it to Coq, and observe the result.)
163+
# example, submit it to Coq, and observe the result.)
159164
#
160165
# Second, we can record what we _expect_ the result to be in the
161166
# form of a Coq example:
@@ -175,7 +180,7 @@
175180
this:
176181
"""
177182
"""Proof. simpl. reflexivity. Qed."""
178-
#l.unfold(next_weekday, next_weekday)
183+
# l.unfold(next_weekday, next_weekday)
179184
l.auto(by=next_weekday.defn)
180185
l.qed()
181186

@@ -201,7 +206,7 @@
201206
# We'll come back to this topic in later chapters.
202207

203208
# %% [markdown]
204-
# ### Homework Submission Guidelines
209+
# ### Homework Submission Guidelines
205210
#
206211
# (** If you are using _Software Foundations_ in a course, your
207212
# instructor may use automatic scripts to help grade your homework
@@ -257,13 +262,13 @@
257262
# that the grading scripts can use it for internal purposes. *)
258263

259264
# %%
260-
#From Coq Require Export String.
265+
# From Coq Require Export String.
261266

262267
# %% [markdown]
263268
# ### Booleans
264269
# Following the pattern of the days of the week above, we can
265270
# define the standard type [bool] of booleans, with members [true]
266-
# and [false].
271+
# and [false].
267272

268273
# %%
269274
"""Inductive bool : Type :=
@@ -274,7 +279,7 @@
274279

275280
# %% [markdown]
276281
# Functions over booleans can be defined in the same way as
277-
# above:
282+
# above:
278283

279284
# %%
280285
"""
@@ -298,28 +303,42 @@
298303
"""
299304

300305

301-
302306
b, b1, b2 = smt.Consts("b b1 b2", bool)
303307

304308

305-
negb = kd.define("negb", [b], kd.cond(
306-
(b.is_true, bool.false),
307-
(b.is_false, bool.true),
308-
))
309-
andb = kd.define("andb", [b1, b2], kd.cond(
310-
(b1.is_true, b2),
311-
(b1.is_false, bool.false),
312-
))
313-
orb = kd.define("orb", [b1, b2], kd.cond(
314-
(b1.is_true, bool.true),
315-
(b1.is_false, b2),
316-
))
317-
318-
negb1 = kd.define("negb1", [b],
319-
b.match_(
320-
(bool.true, bool.false),
321-
(bool.false, bool.true),
322-
))
309+
negb = kd.define(
310+
"negb",
311+
[b],
312+
kd.cond(
313+
(b.is_true, bool.false),
314+
(b.is_false, bool.true),
315+
),
316+
)
317+
andb = kd.define(
318+
"andb",
319+
[b1, b2],
320+
kd.cond(
321+
(b1.is_true, b2),
322+
(b1.is_false, bool.false),
323+
),
324+
)
325+
orb = kd.define(
326+
"orb",
327+
[b1, b2],
328+
kd.cond(
329+
(b1.is_true, bool.true),
330+
(b1.is_false, b2),
331+
),
332+
)
333+
334+
negb1 = kd.define(
335+
"negb1",
336+
[b],
337+
b.match_(
338+
(bool.true, bool.false),
339+
(bool.false, bool.true),
340+
),
341+
)
323342

324343
kd.prove(smt.ForAll([b], negb(b) == negb1(b)), by=[negb1.defn, negb.defn])
325344

@@ -357,7 +376,7 @@
357376
# %% [markdown]
358377
# We can also introduce some familiar infix syntax for the
359378
# boolean operations we have just defined. The [Notation] command
360-
# defines a new symbolic notation for an existing definition.
379+
# defines a new symbolic notation for an existing definition.
361380
#
362381

363382
# %%
@@ -402,9 +421,9 @@
402421
if b1 then true
403422
else b2.
404423
"""
405-
negb1 = kd.define("negb1", [b], smt.If(b1.is_true, bool.false, bool.true))
406-
andb1 = kd.define("andb1", [b1, b2], smt.If(b1.is_true, b2, bool.false))
407-
orb1 = kd.define("orb1", [b1, b2], smt.If(b1.is_true, bool.true, b2))
424+
negb2 = kd.define("negb2", [b], smt.If(b1.is_true, bool.false, bool.true))
425+
andb2 = kd.define("andb2", [b1, b2], smt.If(b1.is_true, b2, bool.false))
426+
orb2 = kd.define("orb2", [b1, b2], smt.If(b1.is_true, bool.true, b2))
408427

409428

410429
# %% [markdown]
@@ -630,19 +649,19 @@
630649
# %%
631650
c = smt.Const("c", color)
632651
p = smt.Const("p", rgb)
633-
monochome = kd.define("monochrome", [c],
634-
c.match_(
635-
(color.black, bool.true),
636-
(color.white, bool.true),
637-
(color.primary(p), bool.false)
638-
)
639-
)
640-
641-
isred = kd.define("isred", [c],
642-
c.match_(
643-
(color.primary(rgb.red), bool.true),
644-
default=bool.false)
645-
)
652+
monochome = kd.define(
653+
"monochrome",
654+
[c],
655+
c.match_(
656+
(color.black, bool.true),
657+
(color.white, bool.true),
658+
(color.primary(p), bool.false),
659+
),
660+
)
661+
662+
isred = kd.define(
663+
"isred", [c], c.match_((color.primary(rgb.red), bool.true), default=bool.false)
664+
)
646665
isred.defn
647666

648667
# %% [markdown]
@@ -719,18 +738,13 @@
719738
bit = kd.Enum("bit", "B1 B0")
720739
nybble = kd.Struct("nybble", ("b0", bit), ("b1", bit), ("b2", bit), ("b3", bit))
721740

722-
nybble(
723-
b0=bit.B0,
724-
b1=bit.B1,
725-
b2=bit.B0,
726-
b3=bit.B1
727-
)
741+
nybble(b0=bit.B0, b1=bit.B1, b2=bit.B0, b3=bit.B1)
728742

729743
# %% [markdown]
730744
#
731745
#
732746
# (* ================================================================= *)
733-
# ## Numbers
747+
# ## Numbers
734748
#
735749
# (** We put this section in a module so that our own definition of
736750
# natural numbers does not interfere with the one from the
@@ -852,10 +866,7 @@
852866

853867
# %%
854868
n = smt.Const("n", Nat)
855-
pred = kd.define("pred", [n], n.match_(
856-
(Nat.O, Nat.O),
857-
(Nat.S(n), n)
858-
))
869+
pred = kd.define("pred", [n], n.match_((Nat.O, Nat.O), (Nat.S(n), n)))
859870
pred.defn
860871

861872
# %% [markdown]

src/kdrag/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
admit_enabled = True
77
# timeout = 1000
88
admit_level = 50
9-
9+
strict_define = True
1010

1111
# TODO: Someday, when it is annoyingly slow to check built in theories, we can add a flag to disable them
1212
# check_lib = True

src/kdrag/kernel.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ def define(name: str, args: list[smt.ExprRef], body: smt.ExprRef) -> smt.FuncDec
263263
if f not in defns or defns[f].ax.thm.eq(def_ax.thm):
264264
defns[f] = defn
265265
else:
266+
if config.strict_define:
267+
raise ValueError(
268+
"Redefining function",
269+
f,
270+
"from",
271+
defns[f].ax,
272+
"to",
273+
def_ax.thm,
274+
)
266275
print("WARNING: Redefining function", f, "from", defns[f].ax, "to", def_ax.thm)
267276
defns[f] = defn
268277
if len(args) == 0:

src/kdrag/notation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ def define(self, args, body):
149149
Shorthand to define a new function for this dispatch. Calls kdrag.define.
150150
"""
151151
assert isinstance(self.name, str)
152-
defn = kd.define(self.name, args, body)
153-
self.register(args[0].sort(), defn)
152+
sort = args[0].sort()
153+
defn = kd.define(sort.name() + "." + self.name, args, body)
154+
self.register(sort, defn)
154155
return defn
155156

156157

src/kdrag/theories/algebra/filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FilterMod:
3232
A module encapsulating filter theory over sets of type T.
3333
3434
>>> FilterMod(smt.RealSort()).filter_full
35-
|= ForAll(F, Implies(wf(F), sets(F)[K(Real, True)]))
35+
|= ForAll(F, Implies(Filter_Real.wf(F), sets(F)[K(Real, True)]))
3636
"""
3737

3838
def __init__(self, T: smt.SortRef):

src/kdrag/theories/bitvec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def BitVecSort(N):
127127
BVN = BitVecN
128128
BVN.empty = BVN(smt.Empty(seq.Seq(BV1))) # type: ignore
129129
x, y, z = smt.Consts("x y z", BitVecN)
130-
to_int = smt.Function("to_int", BitVecN, smt.IntSort())
130+
to_int = smt.Function("BitVecN.to_int", BitVecN, smt.IntSort())
131131
to_int = kd.notation.to_int.define(
132132
[x],
133133
smt.If(

src/kdrag/theories/real/vec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def Vec0(N: int) -> smt.DatatypeSortRef:
5656
>>> u[1]
5757
val(u)[X1]
5858
>>> dot(u, v)
59-
dot(u, v)
59+
Vec0_2.dot(u, v)
6060
"""
6161
Fin = FinSort(N)
6262
S = kd.NewType("Vec0_" + str(N), smt.ArraySort(Fin, kd.R))
@@ -116,7 +116,7 @@ def Vec(N):
116116
u, v = kd.smt.Consts("u v", Vec3)
117117
# kd.notation.add.define([u, v], Vec3(u.x0 + v.x0, u.x1 + v.x1, u.x2 + v.x2))
118118
# kd.notation.sub.define([u, v], Vec3(u.x0 - v.x0, u.x1 - v.x1, u.x2 - v.x2))
119-
norm2.define([u], u.x0 * u.x0 + u.x1 * u.x1 + u.x2 * u.x2)
119+
# norm2.define([u], u.x0 * u.x0 + u.x1 * u.x1 + u.x2 * u.x2)
120120

121121
cross = kd.define(
122122
"cross",

tests/test_kernel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ def test_no_mix_keyword():
357357

358358
def test_smart_prove():
359359
x = smt.Int("x")
360-
f = kd.define("f", [x], x + 1)
361-
g = kd.define("g", [x], x + 1)
362-
d = kd.define("d", [x], f(x))
360+
f = kd.define("mysilly_f20", [x], x + 1)
361+
g = kd.define("mysilly_g20", [x], x + 1)
362+
d = kd.define("mysilly_d20", [x], f(x))
363363
kd.prove(smt.ForAll([x], f(x) == x + 1), unfold=1)
364364
kd.prove(
365365
smt.ForAll([x], f(x) == x + 1),

tests/test_notebooks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import examples.soft_found.lf.Tactics
88
notebooks = [
99
"examples/nng.ipynb",
10-
"examples/soft_found/lf/Basics.ipynb",
1110
"examples/soft_found/lf/IndProp.ipynb",
1211
"examples/soft_found/lf/Imp.ipynb",
1312
"examples/soft_found/lf/Lists.ipynb",

0 commit comments

Comments
 (0)