From d1b1a90fbe6cfb7270de165ba0060b888c1e2201 Mon Sep 17 00:00:00 2001 From: acondolu Date: Tue, 29 May 2018 11:03:13 +0200 Subject: [PATCH] Clean-up to examples. Removed tests. --- ocaml/andrea.ml | 74 ++++++++++++------------------------------------- 1 file changed, 18 insertions(+), 56 deletions(-) diff --git a/ocaml/andrea.ml b/ocaml/andrea.ml index f1cfc01..8066a3d 100644 --- a/ocaml/andrea.ml +++ b/ocaml/andrea.ml @@ -327,79 +327,41 @@ let rec conv_join = function | x::xs -> conv_join xs ^ " ("^ x ^")" ;; -let _ = exec +let auto' a b = auto (problem_of a (conv_join b));; + +(* Example usage of exec, interactive: + +exec "x x" (conv_join["x y"; "y y"; "y x"]) [ step 0 0; eat ] ;; -auto (problem_of "x x" "@ (x y) (y y) (y x)");; -auto (problem_of "x y" "@ (x (_. x)) (y z) (y x)");; -auto (problem_of "a (x. x b) (x. x c)" "@ (a (x. b b) @) (a @ c) (a (x. x x) a) (a (a a a) (a c c))");; - interactive "x y" -"@ (x x) (y x) (y z)" [step 0 0; step 0 1; eat] ;; + "@ (x x) (y x) (y z)" [step 0 0; step 0 1; eat] +;; + +*) -auto (problem_of "x (y. x y y)" "x (y. x y x)");; +auto' "x x" ["x y"; "y y"; "y x"] ;; +auto' "x y" ["x (_. x)"; "y z"; "y x"] ;; +auto' "a (x. x b) (x. x c)" ["a (x. b b) @"; "a @ c"; "a (x. x x) a"; "a (a a a) (a c c)"] ;; -auto (problem_of "x a a a a" (conv_join[ +auto' "x (y. x y y)" ["x (y. x y x)"] ;; + +auto' "x a a a a" [ "x b a a a"; "x a b a a"; "x a a b a"; "x a a a b"; -])); +] ;; (* Controesempio ad usare un conto dei lambda che non considere le permutazioni *) -auto (problem_of "x a a a a (x (x. x x) @ @ (_._.x. x x) x) b b b" (conv_join[ +auto' "x a a a a (x (x. x x) @ @ (_._.x. x x) x) b b b" [ "x a a a a (_. a) b b b"; "x a a a a (_. _. _. _. x. y. x y)"; -])); +] ;; print_hline(); print_endline "ALL DONE. " - -(* TEMPORARY TESTING FACILITY BELOW HERE *) - -let acaso l = - let n = Random.int (List.length l) in - List.nth l n -;; - -let acaso2 l1 l2 = - let n1 = List.length l1 in - let n = Random.int (n1 + List.length l2) in - if n >= n1 then List.nth l2 (n - n1) else List.nth l1 n -;; - -let gen n vars = - let rec aux n inerts lams = - if n = 0 then List.hd inerts, List.hd (Util.sort_uniq (List.tl inerts)) - else let inerts, lams = if Random.int 2 = 0 - then inerts, ("(" ^ acaso vars ^ ". " ^ acaso2 inerts lams ^ ")") :: lams - else ("(" ^ acaso inerts ^ " " ^ acaso2 inerts lams^ ")") :: inerts, lams - in aux (n-1) inerts lams - in aux (2*n) vars [] -;; - -let f () = - let complex = 200 in - let vars = ["x"; "y"; "z"; "v" ; "w"; "a"; "b"; "c"] in - gen complex vars - - let rec repeat f n = - prerr_endline "\n########################### NEW TEST ###########################"; - f () ; - if n > 0 then repeat f (n-1) - ;; - - -let main () = - Random.self_init (); - repeat (fun _ -> - let div, conv = f () in - auto (problem_of div conv) - ) 100; -;; - -(* main ();; *) -- 2.39.2