Karel

Embedded 2D Karel. Coordinates start at the top left; north/east/south/west are 0/1/2/3. Worlds are immutable. Blocked moves and empty picks are no-ops. Native primitives implement the grid; program composition is ordinary Aeon code.
Table of Contents

Types

World

(type)
Embedded 2D Karel. Coordinates start at the top left; north/east/south/west are 0/1/2/3. Worlds are immutable. Blocked moves and empty picks are no-ops. Native primitives implement the grid; program composition is ordinary Aeon code.
type World

Examples

(type)
type Examples

Dataset

(type)
type Dataset

Functions

north

def north : {n : Int | n = 0}

east

def east : {n : Int | n = 1}

south

def south : {n : Int | n = 2}

west

def west : {n : Int | n = 3}

world

def world (width : Int | width > 0) (height : Int | height > 0) (x : Int | 0 ≤ x && x < width) (y : Int | 0 ≤ y && y < height) (facing : Int | 0 ≤ facing && facing < 4) : { r : World | worldWidth r = width && worldHeight r = height && markerLimit r = 10 && noWalls r && noMarkers r && robotX r = x && robotY r = y }

with_wall

def with_wall (w : World) (x : Int | 0 ≤ x && x < worldWidth w) (y : Int | 0 ≤ y && y < worldHeight w && (noMarkers w && (x ≠ robotX w || y ≠ robotY w) || wallAllowed w x y)) : { r : World | worldWidth r = worldWidth w && worldHeight r = worldHeight w && markerLimit r = markerLimit w && noMarkers r = noMarkers w && robotX r = robotX w && robotY r = robotY w }

random_world

def random_world (width : Int | width > 2) (height : Int | height > 2) (seed : Int) : {r : World | worldWidth r = width && worldHeight r = height && markerLimit r = 10}

with_markers

def with_markers (w : World) (x : Int | 0 ≤ x && x < worldWidth w) (y : Int | 0 ≤ y && y < worldHeight w) (count : Int | 0 ≤ count && count ≤ markerLimit w && (noWalls w || clearCell w x y)) : { r : World | worldWidth r = worldWidth w && worldHeight r = worldHeight w && markerLimit r = markerLimit w && noWalls r = noWalls w && robotX r = robotX w && robotY r = robotY w }

marker_count_at

def marker_count_at (w : World) (x : Int | 0 ≤ x && x < worldWidth w) (y : Int | 0 ≤ y && y < worldHeight w) : Int

front_is_clear

def front_is_clear (w : World) : Bool

left_is_clear

def left_is_clear (w : World) : Bool

right_is_clear

def right_is_clear (w : World) : Bool

markers_present

def markers_present (w : World) : Bool

move

def move (w : World) : World

turn_left

def turn_left (w : World) : World

turn_right

def turn_right (w : World) : World

pick_marker

def pick_marker (w : World) : World

put_marker

def put_marker (w : World | markerCount w < markerLimit w) : World

marker_count

def marker_count (w : World) : {n : Int | n = markerCount w && n ≥ 0}

render

def render (w : World) : String

same_world

def same_world (a : World) (b : World) : Bool

example

def example (initial : World) (expected : World) : Examples

append_examples

def append_examples (a : Examples) (b : Examples) : Examples

load_dataset

def load_dataset (path : String) : Dataset

dataset_size

def dataset_size (dataset : Dataset) : {n : Int | n ≥ 0 && n = taskCount dataset}

dataset_task

def dataset_task (dataset : Dataset) (index : Int | 0 ≤ index && index < taskCount dataset) : Examples

fitness

def fitness (program : (w : World) → World) (examples : Examples) : Float

require_finished

def require_finished (fuel : Int) (test : (w : World) → Bool) (w : World) : World

repeat_tick

def repeat_tick (w : World) : World

load_task_examples

def load_task_examples (path : String) : Examples

robot_x

def robot_x (w : World) : {n : Int | n = robotX w && 0 ≤ n && n < worldWidth w}

robot_y

def robot_y (w : World) : {n : Int | n = robotY w && 0 ≤ n && n < worldHeight w}

direction

def direction (w : World) : {n : Int | 0 ≤ n && n < 4}

width

def width (w : World) : {n : Int | n = worldWidth w && n ≥ 0}

height

def height (w : World) : {n : Int | n = worldHeight w && n ≥ 0}

no_markers_present

def no_markers_present (w : World) : Bool

not_karel

def not_karel (test : (w : World) → Bool) (w : World) : Bool

stay

def stay (w : World) : World

sequence

def sequence (first : (w : World) → World) (second : (w : World) → World) (w : World) : World

repeat

def repeat (count : Int) (step : (w : World) → World) (w : World) : World

if_karel

def if_karel (test : (w : World) → Bool) (yes : (w : World) → World) (no : (w : World) → World) (w : World) : World

when_karel

def when_karel (test : (w : World) → Bool) (step : (w : World) → World) (w : World) : World

while_karel

Exhaustion raises a runtime error when the guard remains true, never a partial success.
def while_karel (fuel : Int) (test : (w : World) → Bool) (step : (w : World) → World) (w : World) : World

marker_limit

def marker_limit (w : World) : {n : Int | n = markerLimit w && n ≥ 0}

cell_is_clear

def cell_is_clear (w : World) (x : Int) (y : Int) : {b : Bool | b = clearCell w x y}

can_add_wall

def can_add_wall (w : World) (x : Int) (y : Int) : {b : Bool | b = wallAllowed w x y}

Uninterpreted

Functions declared as def f ... = uninterpreted: only their signature is known to the verifier; they have no body.

worldWidth

uninterpreted
def worldWidth : (w : World) → Int

worldHeight

uninterpreted
def worldHeight : (w : World) → Int

markerLimit

uninterpreted
def markerLimit : (w : World) → Int

markerCount

uninterpreted
def markerCount : (w : World) → Int

taskCount

uninterpreted
def taskCount : (ds : Dataset) → Int

clearCell

uninterpreted
def clearCell : (w : World) → (x : Int) → (y : Int) → Bool

wallAllowed

uninterpreted
def wallAllowed : (w : World) → (x : Int) → (y : Int) → Bool

noWalls

uninterpreted
def noWalls : (w : World) → Bool

noMarkers

uninterpreted
def noMarkers : (w : World) → Bool

robotX

uninterpreted
def robotX : (w : World) → Int

robotY

uninterpreted
def robotY : (w : World) → Int