Correct-by-Construction G-Code Generation: A Neuro-Symbolic Approach via Separation Logic

This paper presents a neuro-symbolic framework that integrates a GLLM generator with a Separation Logic verifier to enable the self-correcting, collision-free production of G-code by translating logical proof failures into precise spatial directives for iterative refinement.

Original authors: Yeonseok Lee

Published 2026-05-13✓ Author reviewed
📖 5 min read🧠 Deep dive

Original authors: Yeonseok Lee

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are trying to teach a very creative, imaginative artist (an AI) how to carve a statue out of a block of marble using a robotic arm. The artist is great at understanding your description ("Make a bird") and can write down the instructions for the robot. However, this artist has never actually seen the workshop. They don't know where the heavy clamps holding the marble are, or how big the robot's arm is. They might write instructions that look perfect on paper but would cause the robot to smash right into a clamp, breaking the machine.

This paper proposes a solution to that problem by teaming up the creative artist with a strict, mathematically perfect safety inspector.

Here is how their partnership works, broken down into simple steps:

1. The Two Partners

  • The Artist (the AI): This is a Large Language Model called GLLM, brought in from earlier work. The GLLM is great at taking your natural-language request ("Carve a bird") and turning it into a list of robotic instructions (G-code). It handles the Retrieval-Augmented Generation (pulling in context about the machine and the task) and checks that the code is syntactically and semantically reasonable. What it does NOT do, and was never designed to do, is keep the robot from physically smashing into things — it has no built-in collision avoidance.
  • The Inspector (the Safety Prover): This is a Separation Logic prover that the authors brought in from their own earlier work — specifically the paper Separation Logic for Verifying Physical Collisions of CNC Programs (arXiv:2605.10437), where the Spatial Heap model and the prover were first introduced. The Inspector's ONE job is to detect physical collisions — situations where the tool and an obstacle would try to occupy the same space at the same time. It is not a general-purpose code reviewer; it is not checking whether the code is "wrong" in some broad sense; it is purely a crash detector.

What this paper actually contributes is the wiring between these two existing tools — a neuro-symbolic feedback loop in which the Inspector's collision findings are translated back into structured guidance for the Artist.

2. The "Digital Sandbox" (The Spatial Heap)

To make the math work, the system turns the physical workshop into a giant 3D grid of tiny cubes (like a 3D version of Minecraft).

  • Some cubes are marked as "Marble" (the material to be cut).
  • Some are marked as "Clamps" (obstacles).
  • Some are marked as "Empty Air" (safe space).
  • The robot's tool is also a specific shape of cubes.

Importantly, the Inspector never actually watches the robot move and never runs a geometric simulation. It reads the G-code script directly, line by line, and works out which cubes each tool move would need to occupy. The rule it enforces is simple: the cubes claimed by the tool must not be already claimed by a clamp or any other obstacle.

3. The Safety Buffer (The "Fluffy Coat")

Robots aren't perfect. They might wobble slightly, or the tool might bend a tiny bit. To account for this, the system doesn't just check the tool's exact size. It gives the tool a "fluffy coat" (a mathematical safety margin) around it.

  • If the tool is 5mm wide, the system pretends it is 7mm wide to be safe.
  • The Inspector checks if this "fluffy tool" hits anything. If it does, the move is forbidden.

4. The "Data Race" (The Crash Alarm)

In computer science, a "data race" happens when two programs try to use the same memory at the same time. The authors call a physical crash a "Spatial Data Race."

When the Artist writes a move that would cause a crash:

  1. The Inspector looks at the 3D grid.
  2. It sees the "Tool Cubes" overlapping with the "Clamp Cubes."
  3. The math proof fails. The Inspector screams, "STOP! You are trying to occupy the same space!"

5. The Feedback Loop (The "Don't Go There" Note)

In the past, if an AI made a mistake, you might just tell it, "Try again," and hope it gets lucky. That's inefficient.

This system is smarter. When the Inspector finds a crash, it doesn't just say "No." It pinpoints the exact location of the crash and draws a tiny, precise box around it.

  • The Message: "You tried to move to coordinates X, Y, Z. There is a clamp inside this specific box. Do not go in this box."
  • The Correction: This note is sent back to the Artist. The Artist reads the note, realizes the mistake, and rewrites the instructions to go around the box.

6. The Result: "Correct-by-Construction"

They keep doing this loop — Artist writes, Inspector checks, Inspector points out the crash, Artist fixes it — until the Inspector can mathematically prove that the tool is highly likely not to collide with anything in the current workspace as described to the prover.

Because the system only stops when this proof goes through, the final set of instructions is "Correct-by-Construction" for that workspace and that description of the obstacles. The guarantee is that, under the spatial model the Inspector was given, the toolpath does not produce a physical collision. (No proof can rule out collisions caused by changes to the workspace AFTER the code is generated — moved fixtures, new stock, an operator leaving a tool inside the cell — so this is a workspace-conditional guarantee, not an unconditional one.)

Summary

The paper describes a way to make AI-generated robot instructions safe by pairing a creative AI with a strict math-based safety checker. The checker turns the physical world into a grid, checks for overlaps (crashes), and sends precise "do not enter" warnings back to the AI until the instructions are mathematically verified against the current spatial model.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →