Skip to content
This repository was archived by the owner on Oct 14, 2021. It is now read-only.

Commit 27da39b

Browse files
committed
commit
1 parent a38d4ec commit 27da39b

27 files changed

+269
-172
lines changed

frontend/projects/main/math.js

+47-18
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,54 @@ const O = require('omikron');
77
const Expr = require('./expr');
88

99
const pidents = {
10-
'a.': '\\varphi',
11-
'b.': '\\psi',
12-
'c.': '\\chi',
13-
'd.': '\\theta',
10+
'phi': '\\varphi',
11+
'psi': '\\psi',
12+
'chi': '\\chi',
13+
'theta': '\\theta',
1414
};
1515

16-
const precs = {
17-
impl: 10,
18-
neg: 10,
16+
const idents = {
17+
'a.': 'a',
18+
'b.': 'b',
19+
'c.': 'c',
20+
'd.': 'd',
1921
};
2022

23+
const ops = [
24+
'impl',
25+
'pnot',
26+
'pelem',
27+
'forall',
28+
];
29+
30+
const precs = O.obj();
31+
32+
ops.forEach((op, index) => {
33+
precs[op] = index << 1;
34+
});
35+
36+
const precMin = -1;
37+
const precMax = O.N;
38+
2139
const expr2math = expr => {
22-
const expr2math = function*(expr, prec=-1){
40+
const expr2math = function*(expr, prec=precMin){
2341
if(expr.isSym){
2442
const {name} = expr;
2543

2644
if(O.has(pidents, name))
2745
return pidents[name];
2846

47+
if(O.has(idents, name))
48+
return idents[name];
49+
2950
assert.fail();
3051
return;
3152
}
3253

33-
const {baseSym} = expr;
34-
const prec1 = precs[baseSym];
54+
const op = expr.baseSym
55+
assert(O.has(precs, op), op);
56+
57+
const prec1 = precs[op];
3558
const args = Expr.expr2args(expr);
3659
const argsNum = args.length;
3760

@@ -40,23 +63,29 @@ const expr2math = expr => {
4063
return str;
4164
};
4265

43-
if(baseSym === 'impl'){
44-
assert(argsNum === 2);
66+
if(op === 'impl')
4567
return disambiguate(`${
4668
yield [expr2math, args[0], prec1 + 1]} \\to ${
4769
yield [expr2math, args[1], prec1]}`);
48-
}
4970

50-
if(baseSym === 'pnot'){
51-
assert(argsNum === 1);
71+
if(op === 'pnot')
5272
return disambiguate(`\\lnot ${
5373
yield [expr2math, args[0], prec1]}`);
54-
}
5574

56-
assert.fail();
75+
if(op === 'forall')
76+
return disambiguate(`\\forall ${
77+
yield [expr2math, args[0], precMax]} ${
78+
yield [expr2math, args[1], prec1]}`);
79+
80+
if(op === 'pelem')
81+
return disambiguate(`${
82+
yield [expr2math, args[0], precMax]} \\in ${
83+
yield [expr2math, args[1], precMax]}`);
84+
85+
assert.fail(op);
5786
};
5887

59-
return O.rec(expr2math, expr);
88+
return log(O.rec(expr2math, expr));
6089
};
6190

6291
const str2math = str => {

local-test/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const drift = require('..');
99
const {Database} = drift;
1010

1111
const main = () => {
12-
drift.verifyAll();
12+
drift.verifyAll(1);
1313
};
1414

1515
main();

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"test": "node test"
1616
},
1717
"dependencies": {
18-
"omikron": "~1.2.54",
18+
"omikron": "~1.2.55",
1919
"@hakerh400/list": "~1.0.6",
2020
"@hakerh400/fs-rec": "~1.0.4"
2121
},

src/index.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,18 @@ const verifyAll = (force=0) => {
4343
saveVerified();
4444
}
4545

46-
for(const thName of O.keys(ths))
47-
verify(thName);
46+
for(const thName of O.keys(ths)){
47+
log(thName);
48+
log.inc();
49+
50+
if(prog.hasIdent(thName)){
51+
verify(thName);
52+
}else{
53+
log('Skip');
54+
}
55+
56+
log.dec();
57+
}
4858
};
4959

5060
const verify = (thName, force=0) => {
@@ -57,8 +67,6 @@ const verify = (thName, force=0) => {
5767
update(0);
5868
}
5969

60-
log(thName);
61-
6270
const db = new database.OperativeDatabase();
6371

6472
const reduceIdent = function*(ident){

system/core/consts/idents.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
a. = zero
2+
b. = nextIdent a.
3+
c. = nextIdent b.
4+
d. = nextIdent c.
5+
6+
nextIdent = succ

system/core/consts/pidents.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
phi = pident zero
2+
psi = nextPident phi
3+
chi = nextPident psi
4+
theta = nextPident chi
5+
6+
nextPident (Pident a) = pident (succ a)
File renamed without changes.

system/core/funcs/basic.txt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
id a = a
2+
3+
dot a b c = a (b c)
4+
dot2 a b c d = a (b c d)
5+
6+
b1 a * = a
7+
b0 * a = a
8+
9+
extract (* a) = a
10+
11+
const a * = a
12+
13+
const2 = dot const const
14+
const3 = dot const const2

system/core/funcs/list.txt

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
head (Pair * a *) = a
2+
tail (Pair * * a) = a
3+
4+
singleton a = pair a nil
5+
6+
map f Nil = nil
7+
map f (Pair x xs) = pair (f x) (map f xs)
8+
9+
foldl f z Nil = z
10+
foldl f z (Pair x xs) = foldl f (f z x) xs
11+
12+
foldr f z Nil = z
13+
foldr f z (Pair x xs) = f x (foldr f z xs)
14+
15+
all f list = foldl (all_ f) true list
16+
all_ f a b = and a (f b)
17+
18+
any f list = foldl (any_ f) false list
19+
any_ f a b = or a (f b)
20+
21+
rawList = rawList_ nil
22+
rawList_ list Nil = list
23+
rawList_ list a = rawList_ (pair a list)
24+
25+
length = foldl (dot2 succ b1) zero
26+
27+
empty = eq nil
28+
29+
nempty = dot not empty
30+
31+
elem e Nil = False
32+
elem e (Pair e *) = True
33+
elem e (Pair * rest) = elem e rest
34+
35+
reverse list = reverse_ list nil
36+
reverse_ Nil list = list
37+
reverse_ (Pair x xs) list = reverse_ xs (pair x list)
38+
39+
takeWhile f Nil = nil
40+
takeWhile f (Pair x xs) = ite (f x)
41+
takeWhile_ (const3 nil) f x xs
42+
takeWhile_ f x xs = pair x (takeWhile f xs)
43+
44+
dropWhile f Nil = nil
45+
dropWhile f y:(Pair x xs) = ite (f x)
46+
dropWhile_1 dropWhile_2 f x xs
47+
dropWhile_1 f x xs = dropWhile f xs
48+
dropWhile_2 f x xs = pair x xs

system/core/funcs/nat-set.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
natSet.empty = nil
2+
3+
natSet.has = elem
4+
5+
natSet.insert Zero Nil = singleton true
6+
natSet.insert Zero (Pair * xs) = pair true xs
7+
natSet.insert (Succ n) Nil = pair false (natSet.insert n nil)
8+
natSet.insert (Succ n) (Pair x xs) = pair x (natSet.insert n xs)
9+
10+
natSet.remove n set = reverse (dropWhile not (natSet.remove_ n (reverse set)))
11+
natSet.remove_ * Nil = nil
12+
natSet.remove_ Zero (Pair * xs) = pair false xs
13+
natSet.remove_ (Succ n) (Pair x xs) = pair x (natSet.remove_ n xs)

system/core/nat.txt

-11
This file was deleted.

system/core/proof.txt

-9
This file was deleted.

system/types/bool.txt system/core/types/bool.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Bool:
2+
bool a:True = Bool a
3+
bool a:False = Bool a
4+
15
True:
26
true = True
37

system/core/types/nat.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Nat:
2+
nat a:Zero = Nat a
3+
nat a:(Succ *) = Nat a
4+
5+
Zero:
6+
zero = Zero
7+
8+
Succ:
9+
succ a:Zero = Succ a
10+
succ a:(Succ *) = Succ a
11+
12+
for f z Zero = z
13+
for f z (Succ a) = f (for f z a)
File renamed without changes.
File renamed without changes.

system/core/pred.txt system/core/types/pred.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Pred:
66
pred a:(Pelem * *) = Pred a
77

88
Pident:
9-
pident_ (Strict.Nat a) = Pident a
9+
pident_ (Nat a) = Pident a
1010

1111
Impl:
1212
impl_ (Pred a) (Pred b) = Impl a b
@@ -15,13 +15,13 @@ Pnot:
1515
pnot_ (Pred a) = Pnot a
1616

1717
Forall:
18-
forall_ (Strict.Nat a) (Pred b) = Forall a b
18+
forall_ (Nat a) (Pred b) = Forall a b
1919

2020
Pelem:
21-
pelem_ (Strict.Nat a) (Strict.Nat b) = Pelem a b
21+
pelem_ (Nat a) (Nat b) = Pelem a b
2222

23-
pident a = pident_ (strict.nat a)
23+
pident a = pident_ (nat a)
2424
impl a b = impl_ (pred a) (pred b)
2525
pnot a = pnot_ (pred a)
26-
forall a b = forall_ (strict.nat a) (pred b)
27-
pelem a b = pelem_ (strict.nat a) (strict.nat b)
26+
forall a b = forall_ (nat a) (pred b)
27+
pelem a b = pelem_ (nat a) (nat b)

system/core/types/proof.txt

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Proof:
2+
rule.inst_ (Proof phi) a:(Pident *) (Pred p) = assert (noFreeIdents p)
3+
(Proof (substPident a p phi))
4+
rule.mp (Proof (Impl a b)) (Proof a) = Proof b
5+
6+
ax.prop.1 = Proof (impl phi (impl psi phi))
7+
ax.prop.2 = Proof (impl (impl phi (impl psi chi)) (impl (impl phi psi) (impl phi chi)))
8+
ax.prop.3 = Proof (impl (impl (pnot phi) (pnot psi)) (impl psi phi))
9+
10+
rule.inst a b c = rule.inst_ a b (pred c)
11+
12+
substPident pident:(Pident *) p pident = p
13+
substPident pident:(Pident *) p a:(Pident *) = a
14+
substPident pident:(Pident *) p (Impl a b) = impl (substPident pident p a) (substPident pident p b)
15+
substPident pident:(Pident *) p (Pnot a) = pnot (substPident pident p a)
16+
substPident pident:(Pident *) p (Forall a b) = forall a (substPident pident p b)
17+
substPident pident:(Pident *) p a:(Pelem * *) = a
18+
19+
substIdent ident1 ident2 (Impl a b) = impl (substIdent ident1 ident2 a) (substIdent ident1 ident2 b)
20+
substIdent ident1 ident2 (Pnot a) = pnot (substIdent ident1 ident2 a)
21+
substIdent ident1 ident2 x:(Forall ident1 b) = x
22+
substIdent ident1 ident2 (Forall a b) = forall a (substIdent ident1 ident2 b)
23+
substIdent ident1 ident2 (Pelem a b) = pelem (replaceIdent ident1 ident2 a) (replaceIdent ident1 ident2 b)
24+
25+
getFreeIdents p = getFreeIdents_ p natSet.empty
26+
getFreeIdents_ (Pident *) set = set
27+
getFreeIdents_ (Impl a b) set = getFreeIdents_ b (getFreeIdents_ a set)
28+
getFreeIdents_ (Pnot a) set = getFreeIdents_ a set
29+
getFreeIdents_ (Forall ident a) set = natSet.remove ident (getFreeIdents_ a set)
30+
getFreeIdents_ (Pelem a b) set = natSet.insert b (natSet.insert a set)
31+
32+
hasFreeIdents = dot nempty getFreeIdents
33+
34+
noFreeIdents = dot empty getFreeIdents

system/funcs/basic.txt

-9
This file was deleted.

system/funcs/list.txt

-25
This file was deleted.

0 commit comments

Comments
 (0)