Herb-AI / HerbBenchmarks.jl

Benchmarks and problems for Herb.jl
https://herb-ai.github.io/
MIT License
1 stars 0 forks source link

Robot grammar adjustment #44

Open ReubenJ opened 5 months ago

ReubenJ commented 5 months ago

Some ideas regarding the robot grammar after discussing today with @pwochner.

Current Implementation

In the new robot grammar, here:

https://github.com/Herb-AI/HerbBenchmarks.jl/blob/a1a801ba5e68911b78f4c059164963bc46d72024/src/data/Robots_2020/grammar.jl#L1-L14

the resulting syntax trees are cluttered with RuleNode(3, [...]). For example, the program for grab, move up, and finally move right is written as

(grab(); (moveUp(); moveRight()))

which corresponds to the RuleNodes: 3{11,3{9,6}}.

Note that this current Sequence syntax does not allow us to write variable-length sequences. It always results in a quote block with two children, the first one being another operation and the other being either an operation or another nested quote block.

Alternative

What if we let each Transformation take the next action as an argument? We would then remove the Sequence rules and maybe add a single End() terminal operation.

The expression would become

grab(moveUp(moveRight(End())))

and the RuleNode representation: `11{9,{6,{22}}

We can keep the interpret function mostly the same, meaning that we first apply grab to the state, thenmoveUp, etc. Functionally, it would be the same, but the resulting syntax trees will contain roughly half the number of nodes.

sebdumancic commented 5 months ago

The only issue that I can spot with the proposed version is that it is quite unintuitive. I would read

grab(moveUp(moveRight(End())))

as move right, move up, and then grab rather than the other way around.

ReubenJ commented 5 months ago

Yep, I see your point. I guess this would be a tradeoff between readability of the expression, and size of the synthesized program.