Skip to content

Commit

Permalink
Add cmdline tool back
Browse files Browse the repository at this point in the history
  • Loading branch information
hferee committed Jun 28, 2024
1 parent bea89dd commit 9eaaa02
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 28 deletions.
9 changes: 6 additions & 3 deletions bin/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
(executables
(public_names uiml_demo benchmark)
(names uiml_demo benchmark)
(public_names uiml_demo benchmark uiml_cmdline)
(names uiml_demo benchmark uiml_cmdline)
(modes js native)
(preprocess (pps js_of_ocaml-ppx))
(libraries js_of_ocaml UIML angstrom))
(libraries js_of_ocaml UIML angstrom exenum)
)


30 changes: 30 additions & 0 deletions bin/printer.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
open UIML.Formulas
open Stringconversion
open UIML.Datatypes

let rec int_of_nat = function
| O -> 0
| S n -> 1 + int_of_nat n


let string_of_formula ?(classical = false) =
let rec string_of_formula =
function
| Var v -> camlstring_of_coqstring v
| Bot -> ""
| Implies(Bot, Bot) -> ""
(* diamond *)
| Implies(Box(Implies(f, Bot)),Bot) when classical -> "" ^ bracket f
(* double negation *)
| Implies(Implies(f, Bot), Bot) when classical -> string_of_formula f
| Box f -> "" ^ bracket f
| And (f, g) -> bracket f ^ "" ^ bracket g
| Or (f, g) -> bracket f ^ "" ^ bracket g
| Implies (f, Bot) -> "¬ " ^ bracket f (* pretty print ¬ *)
| Implies (f, g) -> bracket f ^ "" ^ bracket g
and bracket e = match e with
| Implies(Implies(f, Bot), Bot) when classical -> bracket f
| Implies(Box(Implies(f, Bot)),Bot) when classical -> "" ^ bracket f
| Var _ | Bot | Implies(_, Bot) | Box _ -> string_of_formula e
| e -> "(" ^ string_of_formula e ^ ")"
in string_of_formula
69 changes: 69 additions & 0 deletions bin/uiml_cmdline.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
open ExEnum
open Printer
open UIML.Formulas
open Sys
open Char
open UIML.UIML_extraction
open Stringconversion



(* n first variables *)
let rec n_vars n = if n <= 1 then [['p']] else [Char.chr ((Char.code 'p') + n)] :: n_vars (n - 1)

let e_vars = from_list ~name:"variables" (n_vars 4)

(* Type term is recursive, hence we need a lazy enumeration first. *)
let rec l_e_formulas = lazy
begin
let r_formulas = pay l_e_formulas in
union
[ single Bot ;
map e_vars (fun x -> Var x) ;
map (pair r_formulas r_formulas) (fun (t1, t2) -> And (t1, t2)) ;
map (pair r_formulas r_formulas) (fun (t1, t2) -> Or (t1, t2)) ;
map (pair r_formulas r_formulas) (fun (t1, t2) -> Implies (t1, t2)) ;
map r_formulas (fun x -> Box x);
]
end


(* Enumeration for formulas. *)
let e_formulas = Lazy.force l_e_formulas

(* The code below prints _num_ formulas and their existential interpolant *)

let nb_args = Array.length Sys.argv

let start = if nb_args < 2 then 0 else int_of_string Sys.argv.(1)
let num = if nb_args < 3 then 1 else int_of_string Sys.argv.(2)

let usage_string =
"Usage: propquant s n shows n example formulas φ(0), ... φ(n-1),
and computes E x0 φ(i) and A x0 φ(i) for each 0 ≤ i < n.
The formulas are chosen from an enumeration of all formulas in variables p, q, r, s, t.
The argument s determines where to start in this enumeration.
For example, try: propquant.exe 0 10, propquant.exe 5893 100.\n"

let v : variable = coqstring_of_camlstring "p"

let show_test (f: form) : string =
("φ : " ^ string_of_formula f ^ "\n" ^
"Weight: " ^ string_of_int (int_of_nat (weight f)) ^ "\n") ^
let t_start = Sys.time() in
let e_result = isl_E v f in
let run_time = Sys.time() -. t_start in
("Time: " ^ string_of_float run_time ^ "s\n") ^
("Eₚ(φ): " ^
string_of_formula e_result ^ "\n" ^
"Weight: " ^ string_of_int (int_of_nat (weight e_result)) ^ "\n") ^
let a_result = isl_A v f in
("Aₚ(φ): " ^
string_of_formula a_result ^ "\n" ^
"Weight: " ^ string_of_int (int_of_nat (weight a_result)) ^ "\n-------------------\n")

let () =
if nb_args < 2 then (print_string usage_string)
else
show e_formulas show_test start num;
24 changes: 1 addition & 23 deletions bin/uiml_demo.ml
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
open UIML.UIML_extraction
open UIML.Datatypes
open UIML.Formulas
open Js_of_ocaml
open Modal_expressions_parser
open Stringconversion

let string_of_formula ?(classical = false) =
let rec string_of_formula =
function
| Var v -> camlstring_of_coqstring v
| Bot -> ""
| Implies(Bot, Bot) -> ""
(* diamond *)
| Implies(Box(Implies(f, Bot)),Bot) when classical -> "" ^ bracket f
(* double negation *)
| Implies(Implies(f, Bot), Bot) when classical -> string_of_formula f
| Box f -> "" ^ bracket f
| And (f, g) -> bracket f ^ "" ^ bracket g
| Or (f, g) -> bracket f ^ "" ^ bracket g
| Implies (f, Bot) -> "¬ " ^ bracket f (* pretty print ¬ *)
| Implies (f, g) -> bracket f ^ "" ^ bracket g
and bracket e = match e with
| Implies(Implies(f, Bot), Bot) when classical -> bracket f
| Implies(Box(Implies(f, Bot)),Bot) when classical -> "" ^ bracket f
| Var _ | Bot | Implies(_, Bot) | Box _ -> string_of_formula e
| e -> "(" ^ string_of_formula e ^ ")"
in string_of_formula
open Printer

let catch_e f = try f() with
ParseError -> "Parse Error"
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
(synopsis "Propositional quantifiers for modal logics formalised")
(description "")
(allow_empty)
(depends ocaml dune coq-stdpp js_of_ocaml angstrom)
(depends ocaml dune coq-stdpp js_of_ocaml angstrom exenum)
(tags
(coq "intuitionistic logic" "proof theory" "propositional quantifiers" "extraction")))

Expand Down
3 changes: 2 additions & 1 deletion theories/extraction/UIML_extraction.v
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Definition isl_A v f := Af v f.
Definition isl_simplified_E v f := E_simplified v f.
Definition isl_simplified_A v f := A_simplified v f.

Separate Extraction gl_UI k_UI isl_E isl_A isl_simplified_E isl_simplified_A.
Separate Extraction gl_UI k_UI isl_E isl_A isl_simplified_E isl_simplified_A Formulas.weight.

Check warning on line 44 in theories/extraction/UIML_extraction.v

View workflow job for this annotation

GitHub Actions / Build docs

The extraction is currently set to bypass opacity, the following

Check warning on line 44 in theories/extraction/UIML_extraction.v

View workflow job for this annotation

GitHub Actions / Build docs

Setting extraction output directory by default to


Cd "..".

0 comments on commit 9eaaa02

Please sign in to comment.