Eval optimization! Tests for demos
This commit is contained in:
		| @ -1,19 +1,19 @@ | ||||
| -- We represent `false` with a Leaf and `true` with a Stem Leaf | ||||
| false = t | ||||
| true  = t t | ||||
| demo_false = t | ||||
| demo_true  = t t | ||||
|  | ||||
| -- Tree Calculus representation of the Boolean `not` function | ||||
| not_TC?     = t (t (t t) (t t t)) (t t (t t t)) | ||||
|  | ||||
| -- /demos/toSource.tri contains an explanation of `triage` | ||||
| triage = (\a b c : t (t a b) c) | ||||
| matchBool = (\ot of : triage | ||||
| demo_triage = (\a b c : t (t a b) c) | ||||
| demo_matchBool = (\ot of : demo_triage | ||||
|   of | ||||
|   (\_ : ot) | ||||
|   (\_ _ : ot) | ||||
| ) | ||||
| -- Lambda representation of the Boolean `not` function | ||||
| not_Lambda? = matchBool false true | ||||
| not_Lambda? = demo_matchBool demo_false demo_true | ||||
|  | ||||
| -- Since tricu eliminates Lambda terms to SKI combinators, the tree form of many | ||||
| -- functions defined via Lambda terms are larger than the most efficient TC | ||||
| @ -25,11 +25,11 @@ not_Lambda? = matchBool false true | ||||
| lambdaEqualsTC = equal? not_TC? not_Lambda? | ||||
|  | ||||
| -- Here are some checks to verify their extensional behavior is the same: | ||||
| true_TC?  = not_TC? false | ||||
| false_TC? = not_TC? true | ||||
| true_TC?  = not_TC? demo_false | ||||
| false_TC? = not_TC? demo_true | ||||
|  | ||||
| true_Lambda?  = not_Lambda? false | ||||
| false_Lambda? = not_Lambda? true | ||||
| true_Lambda?  = not_Lambda? demo_false | ||||
| false_Lambda? = not_Lambda? demo_true | ||||
|  | ||||
| bothTrueEqual?  = equal? true_TC?  true_Lambda? | ||||
| bothFalseEqual? = equal? false_TC? false_Lambda? | ||||
|  | ||||
| @ -4,7 +4,7 @@ | ||||
| -- NOTICE: This demo relies on tricu base library functions | ||||
| --  | ||||
| -- We model labelled binary trees as sublists where values act as labels. We | ||||
| -- require explicit notation of empty nodes. Empty nodes can be represented  | ||||
| -- require explicit not?ation of empty nodes. Empty nodes can be represented  | ||||
| -- with an empty list, `[]`, which is equivalent to a single node `t`.  | ||||
| -- | ||||
| -- Example tree inputs: | ||||
| @ -19,33 +19,33 @@ | ||||
|  | ||||
| label = (\node : head node) | ||||
|  | ||||
| left  = (\node : if (emptyList node)  | ||||
| left  = (\node : if (emptyList? node)  | ||||
|   []  | ||||
|   (if (emptyList (tail node))  | ||||
|   (if (emptyList? (tail node))  | ||||
|     []  | ||||
|     (head (tail node)))) | ||||
|  | ||||
| right = (\node : if (emptyList node)  | ||||
| right = (\node : if (emptyList? node)  | ||||
|   []  | ||||
|   (if (emptyList (tail node))  | ||||
|   (if (emptyList? (tail node))  | ||||
|     []  | ||||
|     (if (emptyList (tail (tail node)))  | ||||
|     (if (emptyList? (tail (tail node)))  | ||||
|       []  | ||||
|       (head (tail (tail node)))))) | ||||
|  | ||||
| processLevel = y (\self queue : if (emptyList queue)  | ||||
| processLevel = y (\self queue : if (emptyList? queue)  | ||||
|   []  | ||||
|   (pair (map label queue) (self (filter  | ||||
|     (\node : not (emptyList node))  | ||||
|     (\node : not? (emptyList? node))  | ||||
|       (lconcat (map left queue) (map right queue)))))) | ||||
|  | ||||
| levelOrderTraversal_ = (\a : processLevel (t a t)) | ||||
|  | ||||
| toLineString = y (\self levels : if (emptyList levels)  | ||||
| toLineString = y (\self levels : if (emptyList? levels)  | ||||
|   ""  | ||||
|   (lconcat  | ||||
|     (lconcat (map (\x : lconcat x " ") (head levels)) "")  | ||||
|     (if (emptyList (tail levels)) "" (lconcat (t (t 10 t) t) (self (tail levels)))))) | ||||
|     (if (emptyList? (tail levels)) "" (lconcat (t (t 10 t) t) (self (tail levels)))))) | ||||
|  | ||||
| levelOrderToString = (\s : toLineString (levelOrderTraversal_ s)) | ||||
|  | ||||
|  | ||||
| @ -17,3 +17,5 @@ size = (\x : | ||||
|         self  | ||||
|         (\x y : compose (self x) (self y))  | ||||
|         x)) x 0)) | ||||
|  | ||||
| size size | ||||
|  | ||||
| @ -8,7 +8,7 @@ | ||||
| -- the Tree Calculus term, `triage` enables branching logic based on the term's  | ||||
| -- shape, making it possible to perform structure-specific operations such as | ||||
| -- reconstructing the terms' source code representation. | ||||
| triage = (\leaf stem fork : t (t leaf stem) fork) | ||||
| -- triage = (\leaf stem fork : t (t leaf stem) fork) | ||||
|  | ||||
| -- Base case of a single Leaf | ||||
| sourceLeaf = t (head "t") | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 James Eversole
						James Eversole