Skip to content
Snippets Groups Projects
Commit 5b0df174 authored by Michele Alberti's avatar Michele Alberti
Browse files

Rework pyrat printer.

parent 3162e9a3
No related branches found
No related tags found
No related merge requests found
...@@ -152,10 +152,10 @@ theory ieee_float.Float64 ...@@ -152,10 +152,10 @@ theory ieee_float.Float64
syntax function (./) "(%1 / %2)" syntax function (./) "(%1 / %2)"
syntax function (.-_) "(-%1)" syntax function (.-_) "(-%1)"
syntax predicate le "(%1 <= %2)" syntax predicate le "%1 <= %2"
syntax predicate lt "(%1 < %2)" syntax predicate lt "%1 < %2"
syntax predicate ge "(%1 >= %2)" syntax predicate ge "%1 >= %2"
syntax predicate gt "(%1 > %2)" syntax predicate gt "%1 > %2"
end end
......
...@@ -24,37 +24,39 @@ let number_format = ...@@ -24,37 +24,39 @@ let number_format =
} }
let rec print_term info fmt t = let rec print_term info fmt t =
match t.Why3.Term.t_node with let open Why3 in
| Tconst c -> Why3.Constant.(print number_format unsupported_escape) fmt c match t.Term.t_node with
| Tvar _ | Tlet _ | Tif _ | Tcase _ | Tquant _ | Teps _ -> | Tbinop ((Timplies | Tiff), _, _)
Why3.Printer.unsupportedTerm t "Pyrat" | Tnot _ | Ttrue | Tfalse | Tvar _ | Tlet _ | Tif _ | Tcase _ | Tquant _
| Teps _ ->
Printer.unsupportedTerm t "Pyrat"
| Tbinop (Tand, _, _) -> assert false (* Should appear only at top-level. *)
| Tconst c -> Constant.(print number_format unsupported_escape) fmt c
| Tapp (ls, l) -> ( | Tapp (ls, l) -> (
match Why3.Printer.query_syntax info.info_syn ls.ls_name with match Printer.query_syntax info.info_syn ls.ls_name with
| Some s -> Why3.Printer.syntax_arguments s (print_term info) fmt l | Some s -> Printer.syntax_arguments s (print_term info) fmt l
| None -> ( | None -> (
match (Why3.Term.Hls.find_opt info.variables ls, l) with match (Term.Hls.find_opt info.variables ls, l) with
| Some s, [] -> Fmt.string fmt s | Some s, [] -> Fmt.string fmt s
| _ -> Why3.Printer.unsupportedTerm t "Unknown variables")) | _ -> Printer.unsupportedTerm t "Unknown variable(s)"))
| Tbinop ((Timplies | Tiff), _, _) | Tnot _ | Ttrue | Tfalse ->
Why3.Printer.unsupportedTerm t "Pyrat: Iff, Implies, not"
| Tbinop (Tand, _, _) -> Why3.Printer.unsupportedTerm t "Pyrat: Deep and"
| Tbinop (Tor, t1, t2) -> | Tbinop (Tor, t1, t2) ->
Fmt.pf fmt "%a or %a" (print_term info) t1 (print_term info) t2 Fmt.pf fmt "%a or %a" (print_term info) t1 (print_term info) t2
let print_top_term info fmt t = let print_top_level_term info fmt t =
let print_term info fmt t = let open Why3 in
(** don't print things we don't know *) (* Don't print things we don't know. *)
if Why3.Term.t_s_all (fun _ -> true) let t_is_known =
(fun ls -> Why3.Ident.Mid.mem ls.ls_name info.info_syn || Term.t_s_all
Why3.Term.Hls.mem info.variables ls) (fun _ -> true)
t then (fun ls ->
print_term info fmt t Ident.Mid.mem ls.ls_name info.info_syn || Term.Hls.mem info.variables ls)
in in
match t.Why3.Term.t_node with match t.Term.t_node with
| Tquant _ -> () | Tquant _ -> ()
| Tbinop (Tand, t1, t2) -> | Tbinop (Tand, t1, t2) ->
Fmt.pf fmt "%a@.%a" (print_term info) t1 (print_term info) t2 if t_is_known t1 && t_is_known t2
| _ -> Fmt.pf fmt "%a@." (print_term info) t then Fmt.pf fmt "%a@.%a" (print_term info) t1 (print_term info) t2
| _ -> if t_is_known t then Fmt.pf fmt "%a@." (print_term info) t
let print_decl info fmt d = let print_decl info fmt d =
let open Why3 in let open Why3 in
...@@ -65,8 +67,8 @@ let print_decl info fmt d = ...@@ -65,8 +67,8 @@ let print_decl info fmt d =
| Dlogic _ -> () | Dlogic _ -> ()
| Dind _ -> () | Dind _ -> ()
| Dprop (Decl.Plemma, _, _) -> assert false | Dprop (Decl.Plemma, _, _) -> assert false
| Dprop (Decl.Paxiom, _, f) -> print_top_term info fmt f | Dprop (Decl.Paxiom, _, f) -> print_top_level_term info fmt f
| Dprop (Decl.Pgoal, _, f) -> print_top_term info fmt f | Dprop (Decl.Pgoal, _, f) -> print_top_level_term info fmt f
let rec print_tdecl info fmt task = let rec print_tdecl info fmt task =
let open Why3 in let open Why3 in
...@@ -75,7 +77,6 @@ let rec print_tdecl info fmt task = ...@@ -75,7 +77,6 @@ let rec print_tdecl info fmt task =
| Some { Task.task_prev; task_decl; _ } -> ( | Some { Task.task_prev; task_decl; _ } -> (
print_tdecl info fmt task_prev; print_tdecl info fmt task_prev;
match task_decl.Theory.td_node with match task_decl.Theory.td_node with
| Decl d -> print_decl info fmt d
| Use _ | Clone _ -> () | Use _ | Clone _ -> ()
| Meta (meta, l) when Theory.meta_equal meta Transformations.meta_input -> ( | Meta (meta, l) when Theory.meta_equal meta Transformations.meta_input -> (
match l with match l with
...@@ -88,7 +89,8 @@ let rec print_tdecl info fmt task = ...@@ -88,7 +89,8 @@ let rec print_tdecl info fmt task =
| [ MAls ls; MAint i ] -> | [ MAls ls; MAint i ] ->
Why3.Term.Hls.add info.variables ls (Fmt.str "y%i" i) Why3.Term.Hls.add info.variables ls (Fmt.str "y%i" i)
| _ -> assert false) | _ -> assert false)
| Meta (_, _) -> ()) | Meta (_, _) -> ()
| Decl d -> print_decl info fmt d)
let print_task args ?old:_ fmt task = let print_task args ?old:_ fmt task =
let open Why3 in let open Why3 in
......
...@@ -9,17 +9,17 @@ open Base ...@@ -9,17 +9,17 @@ open Base
let meta_input = let meta_input =
Why3.Theory.( Why3.Theory.(
register_meta "caisar_input" register_meta "caisar_input"
~desc:"Indicates the position of the input in the neural network" ~desc:"Indicates the input position in the neural network"
[ MTlsymbol; MTint ]) [ MTlsymbol; MTint ])
let meta_output = let meta_output =
Why3.Theory.( Why3.Theory.(
register_meta "caisar_output" register_meta "caisar_output"
~desc:"Indicates the position of the output in the neural network" ~desc:"Indicates the output position in the neural network"
[ MTlsymbol; MTint ]) [ MTlsymbol; MTint ])
(* Retrieves the (input) variables appearing, as arguments, after an (* Retrieve the (input) variables appearing, as arguments, after an 'nnet_apply'
'nnet_apply' symbol. *) symbol. *)
let get_input_variables = let get_input_variables =
let rec aux acc (term : Why3.Term.term) = let rec aux acc (term : Why3.Term.term) =
match term.t_node with match term.t_node with
...@@ -42,7 +42,7 @@ let get_input_variables = ...@@ -42,7 +42,7 @@ let get_input_variables =
(fun decl acc -> Why3.Decl.decl_fold aux acc decl) (fun decl acc -> Why3.Decl.decl_fold aux acc decl)
Why3.Term.Mls.empty Why3.Term.Mls.empty
(* Creates logic symbols for output variables and simplifies the formula. *) (* Create logic symbols for output variables and simplify the formula. *)
(* TODO: [Reduction_engine] is probably an overkill and should be replaced. *) (* TODO: [Reduction_engine] is probably an overkill and should be replaced. *)
let simplify_goal env input_variables = let simplify_goal env input_variables =
let rec aux hls (term : Why3.Term.term) = let rec aux hls (term : Why3.Term.term) =
......
...@@ -8,7 +8,7 @@ val init : unit -> unit ...@@ -8,7 +8,7 @@ val init : unit -> unit
(** Register the transformations. *) (** Register the transformations. *)
val meta_input : Why3.Theory.meta val meta_input : Why3.Theory.meta
(** Indicates the position of the input *) (** Indicate the input position. *)
val meta_output : Why3.Theory.meta val meta_output : Why3.Theory.meta
(** Indicates the position of the output *) (** Indicate the output position. *)
Test autodetect Test autodetect
$ mkdir bin $ mkdir bin
$ cat - > bin/alt-ergo << EOF
> #!/bin/sh
> echo "2.4.0"
> EOF
$ cat - > bin/pyrat.py << EOF $ cat - > bin/pyrat.py << EOF
> #!/bin/sh > #!/bin/sh
> echo "PyRAT 1.0" > echo "PyRAT 1.0"
...@@ -11,7 +16,10 @@ Test autodetect ...@@ -11,7 +16,10 @@ Test autodetect
> echo "1.0.+" > echo "1.0.+"
> EOF > EOF
$ chmod u+x bin/pyrat.py bin/Marabou $ chmod u+x bin/alt-ergo bin/pyrat.py bin/Marabou
$ bin/alt-ergo
2.4.0
$ bin/pyrat.py $ bin/pyrat.py
PyRAT 1.0 PyRAT 1.0
......
Test verify Test verify
$ mkdir bin $ mkdir bin
$ cat - > bin/alt-ergo << EOF
> #!/bin/sh
> echo "2.4.0"
> EOF
$ cat - > bin/pyrat.py << EOF $ cat - > bin/pyrat.py << EOF
> #!/bin/sh > #!/bin/sh
> echo "PyRAT 1.0" > echo "PyRAT 1.0"
...@@ -11,7 +16,10 @@ Test verify ...@@ -11,7 +16,10 @@ Test verify
> echo "1.0.+" > echo "1.0.+"
> EOF > EOF
$ chmod u+x bin/pyrat.py bin/Marabou $ chmod u+x bin/alt-ergo bin/pyrat.py bin/Marabou
$ bin/alt-ergo
2.4.0
$ bin/pyrat.py $ bin/pyrat.py
PyRAT 1.0 PyRAT 1.0
...@@ -47,76 +55,7 @@ Test verify ...@@ -47,76 +55,7 @@ Test verify
<autodetect>Found prover PyRAT version 1.0, OK. <autodetect>Found prover PyRAT version 1.0, OK.
<autodetect>3 prover(s) added <autodetect>3 prover(s) added
(* this is the prelude for PyRAT *) (* this is the prelude for PyRAT *)
0.0 < x0
x0 < 0.5
0.0 < y0
y0 < 0.5
(0.0 < x0)
(x0 < 0.5)
(0.0 < y0)
(y0 < 0.5)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment