Commit 901711d7 authored by MARCHE Claude's avatar MARCHE Claude

build maze with theories and modules

parent 76d04eaa
module M
theory UnionFind
use import int.Int use import int.Int
use import module stdlib.Ref
type uf type uf
...@@ -26,6 +26,15 @@ module M ...@@ -26,6 +26,15 @@ module M
forall u:uf. num u = 1 -> forall u:uf. num u = 1 ->
forall x y:int. 0 <= x < size u -> 0 <= y < size u -> same u x y forall x y:int. 0 <= x < size u -> 0 <= y < size u -> same u x y
end
module UnionFind_sig
use import int.Int
use import module stdlib.Ref
use export UnionFind
parameter create : parameter create :
n:int -> n:int ->
{ 0 <= n } { 0 <= n }
...@@ -56,29 +65,43 @@ parameter union : ...@@ -56,29 +65,43 @@ parameter union :
parameter get_num_classes : parameter get_num_classes :
u:ref uf -> {} int reads u { result = num u } u:ref uf -> {} int reads u { result = num u }
parameter rand : s:int -> { 0 < s } int { 0 <= result < s }
lemma Ineq1 : end
forall n x y:int. 0 <= n -> 0 <= x < n -> 0 <= y < n -> 0 <= x*n+y < n*n
theory Graph
type vertex
type graph type graph
(*clone import graph.Path with type graph = graph, type vertex = int*) inductive path graph vertex vertex =
logic path graph int int | Path_refl : forall g:graph, x:vertex. path g x x
| Path_sym : forall g:graph, x y:vertex. path g x y -> path g y x
| Path_trans:
forall g:graph, x y z:vertex. path g x y -> path g y z -> path g x z
end
theory Graph_int
axiom Path_refl : forall g:graph, x:int. path g x x clone export Graph with type vertex = int
axiom Path_sym : forall g:graph, x y:int. path g x y -> path g y x
axiom Path_trans:
forall g:graph, x y z:int. path g x y -> path g y z -> path g x z
logic select (d:int) (x y:'a) : 'a = if d = 0 then x else y end
module Graph_sig
use import int.Int
use import module stdlib.Ref
parameter graph : ref graph clone export Graph with type vertex = int
(* use export Graph *)
(* use export Graph_int*)
parameter num_edges : ref int parameter graph : ref graph
parameter add_edge : parameter num_edges : ref int
a:int -> b:int ->
parameter add_edge : a:int -> b:int ->
{ not path graph a b } { not path graph a b }
unit writes num_edges graph unit writes num_edges graph
{ num_edges = old num_edges + 1 and { num_edges = old num_edges + 1 and
...@@ -89,7 +112,22 @@ parameter add_edge : ...@@ -89,7 +112,22 @@ parameter add_edge :
path (old graph) x b and path (old graph) a y) path (old graph) x b and path (old graph) a y)
} }
let add_edge_and_union u (a:int) (b:int) = end
module BuildMaze
use import int.Int
use import module stdlib.Ref
use import module UnionFind_sig
use import module Graph_sig
parameter rand : s:int -> { 0 < s } int { 0 <= result < s }
lemma Ineq1 :
forall n x y:int. 0 <= n -> 0 <= x < n -> 0 <= y < n -> 0 <= x*n+y < n*n
let add_edge_and_union u (a:int) (b:int) =
{ 0 <= a < size u and 0 <= b < size u and { 0 <= a < size u and 0 <= b < size u and
not same u a b and not path graph a b and not same u a b and not path graph a b and
forall x y:int. forall x y:int.
......
...@@ -165,9 +165,11 @@ let create_module n = ...@@ -165,9 +165,11 @@ let create_module n =
in in
(* pervasives *) (* pervasives *)
let m = add_esymbol ls_Exit m in let m = add_esymbol ls_Exit m in
(*
let m = add_mtsymbol mt_ghost m in let m = add_mtsymbol mt_ghost m in
let m = add_psymbol ps_ghost m in let m = add_psymbol ps_ghost m in
let m = add_psymbol ps_unghost m in let m = add_psymbol ps_unghost m in
*)
m m
(** Modules *) (** Modules *)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment