From 173c689000146731df12cf8b6fe069b98016635e Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane <rowan.a.tl@protonmail.com> Date: Thu, 30 Jan 2025 15:01:36 -0600 Subject: [PATCH 1/8] Add TODO.md --- TODO.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 TODO.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..951a30a --- /dev/null +++ b/TODO.md @@ -0,0 +1,9 @@ +# TODO + +## Push Language TODO + +- [ ] Make all vector functions applicable to string functions and vice versa +- [ ] Implement Calculus functions as seen in propeller +- [ ] Implement Linear Algebra functions as specified in the previous papers + +## PushGP TODO \ No newline at end of file From c3dbe2b28b3d962cbe1f47a625a5b46ebcd00d05 Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane <rowan.a.tl@protonmail.com> Date: Thu, 30 Jan 2025 15:22:16 -0600 Subject: [PATCH 2/8] Add sorting a vector --- TODO.md | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO.md b/TODO.md index 951a30a..1285363 100644 --- a/TODO.md +++ b/TODO.md @@ -5,5 +5,6 @@ - [ ] Make all vector functions applicable to string functions and vice versa - [ ] Implement Calculus functions as seen in propeller - [ ] Implement Linear Algebra functions as specified in the previous papers +- [ ] Add a function to sort a vector ## PushGP TODO \ No newline at end of file From 8be14314588cfa6f0ca15ac181573a364c8d9282 Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane <rowan.a.tl@protonmail.com> Date: Fri, 31 Jan 2025 03:10:39 -0600 Subject: [PATCH 3/8] comments --- README.md | 1 + src/Push.hs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 78db742..7192751 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ worth it in the grand scheme. Would mean we could also track the functions when * [x] tests/ are just copied from make-grade, need to write for this project. * [ ] Included examples of basic assertions, QuickCheck, Hspec, hspec-quickcheck. * [x] Look at Lenses library for abstraction +* [ ] Use Plushy genomes for this project. ## Design considerations The biggest design constraint is that for the exec stack (but not data stacks) diff --git a/src/Push.hs b/src/Push.hs index 2d3ebd2..0367d59 100644 --- a/src/Push.hs +++ b/src/Push.hs @@ -64,7 +64,7 @@ interpretExec state@(State {_exec = e : es}) = (StateFunc func) -> interpretExec $ func state {_exec = es} (Block block) -> interpretExec (state {_exec = block ++ es}) (PlaceInput val) -> interpretExec (state {_exec = (view input state Map.! val) : es}) - Close -> undefined -- remove Close constructor later? + Close -> undefined interpretExec state = state -- Need to make interpretExec strict, right? From 68cc4fc2d114c91e409161ec4ee5e656253b7b1b Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane <rowan.a.tl@protonmail.com> Date: Fri, 31 Jan 2025 03:12:20 -0600 Subject: [PATCH 4/8] comment for Plushy later --- src/Push.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Push.hs b/src/Push.hs index 0367d59..035453f 100644 --- a/src/Push.hs +++ b/src/Push.hs @@ -64,7 +64,7 @@ interpretExec state@(State {_exec = e : es}) = (StateFunc func) -> interpretExec $ func state {_exec = es} (Block block) -> interpretExec (state {_exec = block ++ es}) (PlaceInput val) -> interpretExec (state {_exec = (view input state Map.! val) : es}) - Close -> undefined + Close -> undefined -- This should be removed later. Will be converted to Blocks in the Plushy -> Exec stack process interpretExec state = state -- Need to make interpretExec strict, right? From 5436914f41cf363ed1fc2345453ce74a3cdd797f Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane <rowan.a.tl@protonmail.com> Date: Fri, 31 Jan 2025 03:15:34 -0600 Subject: [PATCH 5/8] move plushy mention --- README.md | 1 - TODO.md | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7192751..78db742 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ worth it in the grand scheme. Would mean we could also track the functions when * [x] tests/ are just copied from make-grade, need to write for this project. * [ ] Included examples of basic assertions, QuickCheck, Hspec, hspec-quickcheck. * [x] Look at Lenses library for abstraction -* [ ] Use Plushy genomes for this project. ## Design considerations The biggest design constraint is that for the exec stack (but not data stacks) diff --git a/TODO.md b/TODO.md index 1285363..ee521f8 100644 --- a/TODO.md +++ b/TODO.md @@ -7,4 +7,5 @@ - [ ] Implement Linear Algebra functions as specified in the previous papers - [ ] Add a function to sort a vector -## PushGP TODO \ No newline at end of file +## PushGP TODO +- [ ] Implement a Plushy genome translator From d10df10351926b8abbb41a045b4eb6107b4a68f1 Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane <rowan.a.tl@protonmail.com> Date: Fri, 31 Jan 2025 15:42:49 -0600 Subject: [PATCH 6/8] make int instructions generic --- TODO.md | 1 + src/Instructions/GenericInstructions.hs | 29 ++++++++++----------- src/Instructions/IntInstructions.hs | 34 +++---------------------- test/Main.hs | 4 +-- 4 files changed, 21 insertions(+), 47 deletions(-) diff --git a/TODO.md b/TODO.md index ee521f8..1ff2d29 100644 --- a/TODO.md +++ b/TODO.md @@ -6,6 +6,7 @@ - [ ] Implement Calculus functions as seen in propeller - [ ] Implement Linear Algebra functions as specified in the previous papers - [ ] Add a function to sort a vector +- [x] Make int yank, shove, yankdup, and shovedup generic ## PushGP TODO - [ ] Implement a Plushy genome translator diff --git a/src/Instructions/GenericInstructions.hs b/src/Instructions/GenericInstructions.hs index e20a68d..1758e2b 100644 --- a/src/Instructions/GenericInstructions.hs +++ b/src/Instructions/GenericInstructions.hs @@ -57,6 +57,7 @@ replace fullA old new Nothing = then replace (take (findSubA fullA old) fullA <> new <> drop (findSubA fullA old + length old) fullA) old new Nothing else fullA +-- a rather inefficient search amtOccurences :: forall a. Eq a => [a] -> [a] -> Int amtOccurences fullA subA = amtOccurences' fullA subA 0 where @@ -149,39 +150,37 @@ instructionEq state accessor = instructionStackDepth :: State -> Lens' State [a] -> State instructionStackDepth state@(State {_int = is}) accessor = state{_int = length (view accessor state) : is} --- Will have a non-generic definition for the int stack instructionYankDup :: State -> Lens' State [a] -> State instructionYankDup state@(State {_int = i : is}) accessor = if notEmptyStack state accessor - then (state & accessor .~ (view accessor state !! max 0 (min i (length (view accessor state) - 1))) : view accessor state) {_int = is} + then state{_int = is} & accessor .~ (view accessor state{_int = is} !! max 0 (min i (length (view accessor state{_int = is}) - 1))) : view accessor state{_int = is} else state instructionYankDup state _ = state --- Is this optimal? Running instrucitonYankDup twice????? -- int non generic too instructionYank :: forall a. State -> Lens' State [a] -> State -instructionYank state@(State {_int = rawIndex : _}) accessor = +instructionYank state@(State {_int = i : is}) accessor = let myIndex :: Int - myIndex = max 0 (min rawIndex (length (view accessor state) - 1)) + myIndex = max 0 (min i (length (view accessor state{_int = is}) - 1)) item :: a - item = view accessor state !! myIndex + item = view accessor state{_int = is} !! myIndex deletedState :: State - deletedState = state & accessor .~ deleteAt myIndex (view accessor state) + deletedState = state{_int = is} & accessor .~ deleteAt myIndex (view accessor state{_int = is}) in - if notEmptyStack state accessor then deletedState & accessor .~ item : view accessor deletedState else state + if notEmptyStack state{_int = is} accessor then deletedState & accessor .~ item : view accessor deletedState else state instructionYank state _ = state --- int non generic :( --- Rewrite this eventually? +-- instructionShoveDup and instructionShove behave differently when indexing in such a way that +-- the duplicated index matters whether or not it's present in the stack at the moment of calculation. +-- I'm not going to keep this behavior. Check out interpysh examples for how pysh handles it. instructionShoveDup :: State -> Lens' State [a] -> State instructionShoveDup state@(State {_int = i : is}) accessor = - case uncons (view accessor state) of - Just (x,_) -> (state & accessor .~ combineTuple x (splitAt (max 0 (min i (length (view accessor state) - 1))) (view accessor state))) {_int = is} + case uncons (view accessor state{_int = is}) of + Just (x,_) -> state{_int = is} & accessor .~ combineTuple x (splitAt (max 0 (min i (length (view accessor state{_int = is}) - 1))) (view accessor state{_int = is})) _ -> state -instructionShoveDup state@(State {_int = []}) _ = state +instructionShoveDup state _ = state --- also also not int generic instructionShove :: State -> Lens' State [a] -> State instructionShove state accessor = instructionShoveDup state accessor & accessor .~ drop 1 (view accessor (instructionShoveDup state accessor)) @@ -206,7 +205,7 @@ instructionConj state primAccessor vectorAccessor = _ -> state -- v for vector, vs for vectorstack (also applicable to strings) --- Could abstract this unconsing even further +-- Could abstract this unconsing even further in all functions below instructionTakeN :: State -> Lens' State [[a]] -> State instructionTakeN state@(State {_int = i1 : is}) accessor = case uncons (view accessor state) of diff --git a/src/Instructions/IntInstructions.hs b/src/Instructions/IntInstructions.hs index a404028..a033a7f 100644 --- a/src/Instructions/IntInstructions.hs +++ b/src/Instructions/IntInstructions.hs @@ -88,43 +88,17 @@ instructionIntEq state = instructionEq state int instructionIntStackDepth :: State -> State instructionIntStackDepth state = instructionStackDepth state int --- int specific instructionIntYank :: State -> State --- instructionIntYank state = instructionYank state int -instructionIntYank state@(State {_int = rawIndex : i1 : is}) = - let - myIndex :: Int - myIndex = max 0 (min rawIndex (length is - 1)) - in - state {_int = is !! myIndex : i1 : deleteAt myIndex is} -instructionIntYank state = state +instructionIntYank state = instructionYank state int instructionIntYankDup :: State -> State -instructionIntYankDup state@(State {_int = rawIndex : item : is}) = - let - myIndex :: Int - myIndex = max 0 (min rawIndex (length is - 1)) - in - state {_int = is !! myIndex : item : is} -instructionIntYankDup state = state +instructionIntYankDup state = instructionYankDup state int instructionIntShove :: State -> State -instructionIntShove state@(State {_int = rawIndex : item : is}) = - let - myIndex :: Int - myIndex = max 0 (min rawIndex (length is - 1)) - in - state {_int = combineTuple item (splitAt myIndex is)} -instructionIntShove state = state +instructionIntShove state = instructionShove state int instructionIntShoveDup :: State -> State -instructionIntShoveDup state@(State {_int = rawIndex : item : is}) = - let - myIndex :: Int - myIndex = max 0 (min rawIndex (length is - 1)) - in - state {_int = item : combineTuple item (splitAt myIndex is)} -instructionIntShoveDup state = state +instructionIntShoveDup state = instructionShoveDup state int instructionIntIsEmpty :: State -> State instructionIntIsEmpty state = instructionIsEmpty state int diff --git a/test/Main.hs b/test/Main.hs index 6104e91..b88073e 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -68,8 +68,8 @@ main = do intTestFunc "instructionIntStackDepth" [2, 51, 52] [GeneInt 52, GeneInt 51, StateFunc instructionIntStackDepth] emptyState intTestFunc "instructionIntYank" [3, 3, 2, 1] [GeneInt 3, GeneInt 1, GeneInt 2, GeneInt 3, GeneInt 4, StateFunc instructionIntYank] emptyState intTestFunc "instructionIntYankDup" [3, 3, 2, 1, 3] [GeneInt 3, GeneInt 1, GeneInt 2, GeneInt 3, GeneInt 4, StateFunc instructionIntYankDup] emptyState - intTestFunc "instructionIntShove" [2, 1, 3, 1] [GeneInt 1, GeneInt 1, GeneInt 2, GeneInt 3, GeneInt 2, StateFunc instructionIntShove] emptyState - intTestFunc "instructionIntShoveDup" [3, 2, 1, 3, 1] [GeneInt 1, GeneInt 1, GeneInt 2, GeneInt 3, GeneInt 2, StateFunc instructionIntShoveDup] emptyState + intTestFunc "instructionIntShove" [2, 3, 1, 1] [GeneInt 1, GeneInt 1, GeneInt 2, GeneInt 3, GeneInt 2, StateFunc instructionIntShove] emptyState + intTestFunc "instructionIntShoveDup" [3, 2, 3, 1, 1] [GeneInt 1, GeneInt 1, GeneInt 2, GeneInt 3, GeneInt 2, StateFunc instructionIntShoveDup] emptyState -- Exec tests intTestFunc "instructionExecIf" [6, 5] [GeneBool True, StateFunc instructionExecIf, Block [GeneInt 5, GeneInt 6], Block [GeneInt 7, GeneInt 8]] emptyState From 1d561437124041e2c1524376bf88ba7b9f5e8daa Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane <rowan.a.tl@protonmail.com> Date: Fri, 31 Jan 2025 15:49:06 -0600 Subject: [PATCH 7/8] comment cleanup --- src/Instructions/GenericInstructions.hs | 3 +-- src/Instructions/StringInstructions.hs | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Instructions/GenericInstructions.hs b/src/Instructions/GenericInstructions.hs index 1758e2b..872fff1 100644 --- a/src/Instructions/GenericInstructions.hs +++ b/src/Instructions/GenericInstructions.hs @@ -157,7 +157,6 @@ instructionYankDup state@(State {_int = i : is}) accessor = else state instructionYankDup state _ = state --- int non generic too instructionYank :: forall a. State -> Lens' State [a] -> State instructionYank state@(State {_int = i : is}) accessor = let @@ -171,7 +170,7 @@ instructionYank state@(State {_int = i : is}) accessor = if notEmptyStack state{_int = is} accessor then deletedState & accessor .~ item : view accessor deletedState else state instructionYank state _ = state --- instructionShoveDup and instructionShove behave differently when indexing in such a way that +-- In pysh, instructionShoveDup and instructionShove behave differently when indexing in such a way that -- the duplicated index matters whether or not it's present in the stack at the moment of calculation. -- I'm not going to keep this behavior. Check out interpysh examples for how pysh handles it. instructionShoveDup :: State -> Lens' State [a] -> State diff --git a/src/Instructions/StringInstructions.hs b/src/Instructions/StringInstructions.hs index 0c7073a..c26aada 100644 --- a/src/Instructions/StringInstructions.hs +++ b/src/Instructions/StringInstructions.hs @@ -94,8 +94,6 @@ instructionStringInsertChar state@(State {_string = s1 : ss, _char = c1 : cs, _i instructionStringInsertChar state = state instructionStringContainsChar :: State -> State --- instructionStringContainsChar state@(State {_string = s1 : ss, _char = c1 : cs, _bool = bs}) = state{_string = ss, _char = cs, _bool = (findSubA s1 [c1] /= -1) : bs} --- instructionStringContainsChar state = state instructionStringContainsChar state = instructionVectorContains state char string instructionStringIndexOfChar :: State -> State From dc9e9fdb199a16c50dac071f0418bf9b33be9d6c Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane <rowan.a.tl@protonmail.com> Date: Fri, 31 Jan 2025 15:52:53 -0600 Subject: [PATCH 8/8] calculus -> all propeller instructions --- TODO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 1ff2d29..de4ec89 100644 --- a/TODO.md +++ b/TODO.md @@ -3,7 +3,7 @@ ## Push Language TODO - [ ] Make all vector functions applicable to string functions and vice versa -- [ ] Implement Calculus functions as seen in propeller +- [ ] Implement all functions as seen in propeller - [ ] Implement Linear Algebra functions as specified in the previous papers - [ ] Add a function to sort a vector - [x] Make int yank, shove, yankdup, and shovedup generic