-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
547dccd
commit c02b952
Showing
11 changed files
with
198 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
from . import kernel | ||
from . import notation | ||
from . import tactics | ||
import z3 | ||
|
||
lemma = kernel.lemma | ||
lemma = tactics.lemma | ||
axiom = kernel.axiom | ||
define = kernel.define | ||
|
||
QForAll = notation.QForAll | ||
QExists = notation.QExists | ||
|
||
Calc = tactics.Calc | ||
|
||
R = z3.RealSort() | ||
Z = z3.IntSort() | ||
RSeq = Z >> R | ||
RFun = R >> R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import knuckledragger as kd | ||
import z3 | ||
|
||
C = kd.notation.Record("C", ("re", z3.RealSort()), ("im", z3.RealSort())) | ||
|
||
z, w, u, z1, z2 = z3.Consts("z w u z1 z2", C) | ||
add = kd.define("add", [z1, z2], C.mk(z1.re + z2.re, z1.im + z2.im)) | ||
kd.notation.add.register(C, add) | ||
mul = kd.define( | ||
"mul", [z1, z2], C.mk(z1.re * z2.re - z1.im * z2.im, z1.re * z2.im + z1.im * z2.re) | ||
) | ||
kd.notation.mul.register(C, mul) | ||
conj = kd.define("conj", [z], C.mk(z.re, -z.im)) | ||
|
||
|
||
div = kd.define( | ||
"div", | ||
[z1, z2], | ||
C.mk( | ||
(z1.re * z2.re + z1.im * z2.im) / (z2.re**2 + z2.im**2), | ||
(z1.im * z2.re - z1.re * z2.im) / (z2.re**2 + z2.im**2), | ||
), | ||
) | ||
kd.notation.div.register(C, div) | ||
|
||
C0 = C.mk(0, 0) | ||
C1 = C.mk(1, 0) | ||
|
||
add_zero = kd.lemma(z3.ForAll([z], z + C0 == z), by=[add.defn]) | ||
mul_zero = kd.lemma(z3.ForAll([z], z * C0 == C0), by=[mul.defn]) | ||
mul_one = kd.lemma(z3.ForAll([z], z * C1 == z), by=[mul.defn]) | ||
add_comm = kd.lemma(z3.ForAll([z, w], z + w == w + z), by=[add.defn]) | ||
add_assoc = kd.lemma( | ||
z3.ForAll([z, w, u], (z + (w + u)) == ((z + w) + u)), by=[add.defn] | ||
) | ||
mul_comm = kd.lemma(z3.ForAll([z, w], z * w == w * z), by=[mul.defn]) | ||
|
||
# unstable perfoamnce. | ||
# mul_div = kd.lemma(ForAll([z,w], Implies(w != C0, z == z * w / w)), by=[div.defn, mul.defn], timeout=1000) | ||
##mul_div = Calc() | ||
div_one = kd.lemma(z3.ForAll([z], z / C1 == z), by=[div.defn]) | ||
div_inv = kd.lemma(z3.ForAll([z], z3.Implies(z != C0, z / z == C1)), by=[div.defn]) | ||
|
||
# inv = kd.define("inv", [z], ) | ||
|
||
# conjugate | ||
# polar | ||
norm2 = kd.define("norm2", [z], z * conj(z)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import knuckledragger as kd | ||
import knuckledragger.theories.Real as R | ||
import z3 | ||
|
||
Interval = kd.notation.Record("Interval", ("lo", kd.R), ("hi", kd.R)) | ||
x, y, z = z3.Reals("x y z") | ||
i, j, k = z3.Consts("i j k", Interval) | ||
|
||
setof = kd.define("setof", [i], z3.Lambda([x], z3.And(i.lo <= x, x <= i.hi))) | ||
|
||
meet = kd.define("meet", [i, j], Interval.mk(R.max(i.lo, j.lo), R.min(i.hi, j.hi))) | ||
meet_intersect = kd.lemma( | ||
z3.ForAll([i, j], z3.SetIntersect(setof(i), setof(j)) == setof(meet(i, j))), | ||
by=[setof.defn, meet.defn, R.min.defn, R.max.defn], | ||
) | ||
|
||
join = kd.define("join", [i, j], Interval.mk(R.min(i.lo, j.lo), R.max(i.hi, j.hi))) | ||
join_union = kd.lemma( | ||
z3.ForAll([i, j], z3.IsSubset(z3.SetUnion(setof(i), setof(j)), setof(join(i, j)))), | ||
by=[setof.defn, join.defn, R.min.defn, R.max.defn], | ||
) | ||
|
||
|
||
width = kd.define("width", [i], i.hi - i.lo) | ||
mid = kd.define("mid", [i], (i.lo + i.hi) / 2) | ||
|
||
add = kd.notation.add.define([i, j], Interval.mk(i.lo + j.lo, i.hi + j.hi)) | ||
add_set = kd.lemma( | ||
z3.ForAll([x, y, i, j], z3.Implies(setof(i)[x] & setof(j)[y], setof(i + j)[x + y])), | ||
by=[add.defn, setof.defn], | ||
) | ||
|
||
sub = kd.notation.sub.define([i, j], Interval.mk(i.lo - j.hi, i.hi - j.lo)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
from knuckledragger.theories.Nat import Nat | ||
from knuckledragger.theories.Real import R | ||
from z3 import ArraySort | ||
import knuckledragger as kd | ||
import z3 | ||
|
||
"""A Sequence type of Nat -> R""" | ||
Seq = ArraySort(Nat, R) | ||
# TODO: seq needs well formedness condition inherited from elements | ||
|
||
|
||
def induct(T: z3.SortRef, P) -> kd.kernel.Proof: | ||
z = z3.FreshConst(T, prefix="z") | ||
sort = z3.SeqSort(T) | ||
x, y = z3.FreshConst(sort), z3.FreshConst(sort) | ||
return kd.axiom( | ||
z3.And( | ||
P(z3.Empty(sort)), | ||
kd.QForAll([z], P(z3.Unit(z))), | ||
kd.QForAll([x, y], P(x), P(y), P(z3.Concat(x, y))), | ||
) # ------------------------------------------------- | ||
== kd.QForAll([x], P(x)) | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters