Skip to content

Commit 2b502e6

Browse files
move parser and memoize implementations into Learning folder and create one Validate algorithm in Deriv
1 parent 962f967 commit 2b502e6

File tree

8 files changed

+27
-152
lines changed

8 files changed

+27
-152
lines changed

Validator.lean

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ import Validator.Deriv.Leave
2424
import Validator.Deriv.Mem
2525
import Validator.Deriv.MemEnter
2626
import Validator.Deriv.MemLeave
27-
import Validator.Deriv.ParserConcise
28-
import Validator.Deriv.ParserConciseMem
29-
import Validator.Deriv.ParserConciseMemTest
30-
import Validator.Deriv.ParserConciseCompress
31-
import Validator.Deriv.ParserConciseCompressMem
27+
import Validator.Deriv.Validate
28+
import Validator.Deriv.TestMemoize
3229

3330
import Validator.Learning.Learning

Validator/Deriv/ParserConciseCompressMem.lean

Lines changed: 0 additions & 135 deletions
This file was deleted.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ import Validator.Parser.ParseTree
33
import Validator.Deriv.Env
44
import Validator.Deriv.EnvTreeParserStateWithMem
55
import Validator.Deriv.EnvTreeParserStateWithMemTest
6-
import Validator.Deriv.ParserConcise
6+
import Validator.Deriv.Validate
77

8-
namespace ParserConciseMemTest
8+
namespace TestMemoize
99

1010
def validate {m} [Env m] (x: Expr): m Bool :=
11-
ParserConcise.validate x
11+
Validate.validate x
1212

1313
def run (x: Expr) (t: ParseTree): Except String Bool :=
1414
EnvTreeParserStateWithMem.run (validate x) t
1515

16+
-- Tests
17+
1618
def testCacheIsHitOnSecondRun (x: Expr) (t: ParseTree): Except String Bool :=
1719
match EnvTreeParserStateWithMem.run' (validate x) t with
1820
| EStateM.Result.error err _ => Except.error err

Validator/Deriv/ParserConciseCompress.lean renamed to Validator/Deriv/Validate.lean

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import Validator.Expr.IfExpr
99

1010
import Validator.Deriv.Enter
1111
import Validator.Deriv.Env
12-
import Validator.Deriv.EnvTreeParserState
12+
import Validator.Deriv.EnvTreeParserStateWithMem
1313
import Validator.Deriv.Leave
1414

1515
import Validator.Parser.ParseTree
1616
import Validator.Parser.Parser
1717
import Validator.Parser.Hint
1818

19-
namespace ParserConciseCompress
19+
namespace Validate
2020

2121
def deriveEnter [Env m] (xs: List Expr): m (List Expr) := do
2222
let token <- Parser.token
@@ -61,7 +61,9 @@ def validate {m} [Env m] (x: Expr): m Bool := do
6161
| _ => throw "expected one expression"
6262

6363
def run (x: Expr) (t: ParseTree): Except String Bool :=
64-
EnvTreeParserState.run (validate x) t
64+
EnvTreeParserStateWithMem.run (validate x) t
65+
66+
-- Tests
6567

6668
open ParseTree (node)
6769

Validator/Learning/Learning.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ import Validator.Learning.Compress
33
import Validator.Learning.ImperativeBasic
44
import Validator.Learning.ImperativeCompress
55
import Validator.Learning.ImperativeLeave
6+
import Validator.Learning.Memoize
67
import Validator.Learning.Original
8+
import Validator.Learning.Parser
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ import Validator.Parser.ParseTree
22

33
import Validator.Deriv.Env
44
import Validator.Deriv.EnvTreeParserStateWithMem
5-
import Validator.Deriv.ParserConcise
65

7-
namespace ParserConciseMem
6+
import Validator.Learning.Parser
7+
8+
namespace Memoize
89

910
def validate {m} [Env m] (x: Expr): m Bool :=
10-
ParserConcise.validate x
11+
Parser.validate x
1112

1213
def run (x: Expr) (t: ParseTree): Except String Bool :=
1314
EnvTreeParserStateWithMem.run (validate x) t
1415

16+
-- Tests
17+
1518
open ParseTree (node)
1619

1720
#guard run
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- ParserConcise is a memoizable version of the validation algorithm.
1+
-- Parser is a memoizable version of the validation algorithm.
22
-- This version of the algorithm uses a Parser instead of a ParseTree.
33
-- It is intended to be used for explanation purposes. This means that it gives up speed for readability. Thus it has no memoization implemented.
44

@@ -15,7 +15,7 @@ import Validator.Parser.Hint
1515
import Validator.Parser.Parser
1616
import Validator.Parser.ParseTree
1717

18-
namespace ParserConcise
18+
namespace Parser
1919

2020
def deriveEnter [Env m] (xs: List Expr): m (List Expr) := do
2121
let token <- Parser.token
@@ -55,6 +55,8 @@ def validate {m} [Env m] (x: Expr): m Bool := do
5555
def run (x: Expr) (t: ParseTree): Except String Bool :=
5656
EnvTreeParserState.run (validate x) t
5757

58+
-- Tests
59+
5860
open ParseTree (node)
5961

6062
#guard run

Validator/Learning/Readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ We assume a background in Lean and an understanding of derivatives for regular e
88
* [ImperativeBasic](./ImperativeBasic.lean) is the simplest version of the memoizable algorithm, which using [enter](../Deriv/Enter.lean) and [leave](../ImperativeLeave.lean). NO compression, NO monads, NO parser. NO memoization.
99
* [ImperativeCompress](./ImperativeCompress.lean) adds compression to [ImperativeBasic](./ImperativeBasic.lean) for a little extra efficiency. NO monads, NO parser, NO memoization.
1010
* [Basic](./Basic.lean) is the simplest version of the memoizable algorithm, which using [enter](../Deriv/Enter.lean) and [leave](../Deriv/Leave.lean). It uses monads to make the code more concise. NO compression, NO parser, NO memoization.
11-
* [Compress](./Compress.lean) adds compression to [Basic](./Basic.lean) for a little extra efficiency. NO parser, NO memoization.
11+
* [Compress](./Compress.lean) adds compression to [Basic](./Basic.lean) for a little extra efficiency. NO parser, NO memoization.
12+
* [Parser](./Parser.lean) adds the use of a pull-based Parser which makes it possible to only parse what is truly necessary to parse. NO memoization. NO compression.
13+
* [Memoize](./Memoize.lean) adds memoization, by simply swapping out the implementation of Env. NO compression.

0 commit comments

Comments
 (0)