[Toss-devel-svn] SF.net SVN: toss:[1719] trunk/Toss
Status: Beta
Brought to you by:
lukaszkaiser
From: <luk...@us...> - 2012-06-03 22:47:29
|
Revision: 1719 http://toss.svn.sourceforge.net/toss/?rev=1719&view=rev Author: lukaszkaiser Date: 2012-06-03 22:47:21 +0000 (Sun, 03 Jun 2012) Log Message: ----------- Adding power to real_expr, working on new examples. Modified Paths: -------------- trunk/Toss/Arena/DiscreteRule.ml trunk/Toss/Client/JsHandler.ml trunk/Toss/Client/Main.js trunk/Toss/Client/Style.css trunk/Toss/Client/index.html trunk/Toss/Formula/AuxIO.ml trunk/Toss/Formula/Formula.ml trunk/Toss/Formula/Formula.mli trunk/Toss/Formula/FormulaMap.ml trunk/Toss/Formula/FormulaMap.mli trunk/Toss/Formula/FormulaOps.ml trunk/Toss/Formula/FormulaParser.mly trunk/Toss/Formula/FormulaSubst.ml trunk/Toss/Makefile trunk/Toss/Play/Heuristic.ml trunk/Toss/Play/HeuristicTest.ml trunk/Toss/Solver/Solver.ml Added Paths: ----------- trunk/Toss/Client/img/Forces.png trunk/Toss/Client/img/Parsing.png trunk/Toss/examples/Forces.toss trunk/Toss/examples/Parsing.toss Modified: trunk/Toss/Arena/DiscreteRule.ml =================================================================== --- trunk/Toss/Arena/DiscreteRule.ml 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Arena/DiscreteRule.ml 2012-06-03 22:47:21 UTC (rev 1719) @@ -149,7 +149,7 @@ (* Encapsulate the precondition as a defined relation *) let compose_pre r body args = let lhs_args = - match r.rlmap with + match r.rlmap with | None -> (* LHS and RHS vars are the same *) args | Some rlmap -> @@ -203,7 +203,6 @@ rel_prods in let precond = match disjs with - (* | [] -> failwith ("fluent_preconds: not a fluent: "^rel) *) | [phi] -> phi | _ -> Formula.Or disjs in let precond = FormulaOps.prune_unused_quants precond in Modified: trunk/Toss/Client/JsHandler.ml =================================================================== --- trunk/Toss/Client/JsHandler.ml 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Client/JsHandler.ml 2012-06-03 22:47:21 UTC (rev 1719) @@ -71,6 +71,8 @@ ("Bounce", AuxIO.input_file "examples/Bounce.toss"); ("Cell-Cycle-Tyson-1991", AuxIO.input_file "examples/Cell-Cycle-Tyson-1991.toss"); + ("Parsing", AuxIO.input_file "examples/Parsing.toss"); + ("Forces", AuxIO.input_file "examples/Forces.toss"); ] let gSel_games = ref [compile_game_data "Tic-Tac-Toe" Modified: trunk/Toss/Client/Main.js =================================================================== --- trunk/Toss/Client/Main.js 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Client/Main.js 2012-06-03 22:47:21 UTC (rev 1719) @@ -280,10 +280,12 @@ bt.innerHTML = "Less Games"; document.getElementById ("moregames1").style.display = "block"; document.getElementById ("moregames2").style.display = "block"; + document.getElementById ("moregames3").style.display = "block"; } else { bt.innerHTML = "More Games"; document.getElementById ("moregames1").style.display = "none"; document.getElementById ("moregames2").style.display = "none"; + document.getElementById ("moregames3").style.display = "none"; } } Modified: trunk/Toss/Client/Style.css =================================================================== --- trunk/Toss/Client/Style.css 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Client/Style.css 2012-06-03 22:47:21 UTC (rev 1719) @@ -175,12 +175,9 @@ width: 100%; } -#moregames1 { +#moregames1, #moregames2, #moregames3 { display: none; } -#moregames2 { - display: none; -} .game-picdiv1 { position: relative; Added: trunk/Toss/Client/img/Forces.png =================================================================== (Binary files differ) Property changes on: trunk/Toss/Client/img/Forces.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/Toss/Client/img/Parsing.png =================================================================== (Binary files differ) Property changes on: trunk/Toss/Client/img/Parsing.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/Toss/Client/index.html =================================================================== --- trunk/Toss/Client/index.html 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Client/index.html 2012-06-03 22:47:21 UTC (rev 1719) @@ -182,6 +182,25 @@ </div> </div> +<div id="moregames3" class="game-line"> +<div class="game-picdiv1"> +<button onclick="new_play_click ('Parsing')" class="game-picbt"> + <img class="game-picimg" src="img/Parsing.png" alt="Parsing" /> + <span id="pdescParsing" class="game-picspan"> + <span class="game-pictxt">Parsing</span> + </span> +</button> +</div> +<div class="game-picdiv2"> +<button onclick="new_play_click ('Forces')" class="game-picbt"> + <img class="game-picimg" src="img/Forces.png" alt="Forces" /> + <span id="pdescForces" class="game-picspan"> + <span class="game-pictxt">Forces</span> + </span> +</button> +</div> +</div> + <ul id="welcome-list-main" class="welcome-list"> <li>Play <a href="http://en.wikipedia.org/wiki/Breakthrough_(board_game)" @@ -469,6 +488,14 @@ between cdc2 and cyclin. We use it as an example of non-linear dynamics with universal rules and parameters.</p> </div> + <div class="game-desc" id="Parsing-desc"> + <p><b>Parsing</b> is a basic example to illustrate how parsing with type + reconstruction can be represented as structure rewriting.</p> + </div> + <div class="game-desc" id="Forces-desc"> + <p><b>Forces</b> can be represented using continuous dynamics, and in this + example we show how to use them for graph drawing.</p> + </div> </div> <div id="bottom"> Modified: trunk/Toss/Formula/AuxIO.ml =================================================================== --- trunk/Toss/Formula/AuxIO.ml 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Formula/AuxIO.ml 2012-06-03 22:47:21 UTC (rev 1719) @@ -4,6 +4,8 @@ let default_debug_level = ref 0 +(* This flag, if set, makes Toss input from Resources ml even in non-JS mode. *) +let input_from_resources = ref false let gettimeofday () = IFDEF JAVASCRIPT THEN ( @@ -68,7 +70,8 @@ try Resources.get_file fn with Not_found -> failwith ("File " ^ fn ^ " not found") ) ELSE ( - try Resources.get_file fn with Not_found -> ( + let input_from_rescs()= if not !input_from_resources then raise Not_found in + try input_from_rescs(); Resources.get_file fn with Not_found -> ( let input_file_desc file = let buf = Buffer.create 256 in (try Modified: trunk/Toss/Formula/Formula.ml =================================================================== --- trunk/Toss/Formula/Formula.ml 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Formula/Formula.ml 2012-06-03 22:47:21 UTC (rev 1719) @@ -115,8 +115,9 @@ and real_expr = | RVar of string | Const of float + | Plus of real_expr * real_expr | Times of real_expr * real_expr - | Plus of real_expr * real_expr + | Pow of real_expr * real_expr | Fun of string * fo_var | Char of formula | Sum of fo_var list * formula * real_expr @@ -132,11 +133,6 @@ | f -> is_atom f -(* Helper power function, used in parser. *) -let rec pow p n = - if n = 0 then Const 1. else if n = 1 then p else Times (p, pow p (n-1)) - - (* ----------------------- PRINTING FUNCTIONS ------------------------------- *) let rec mona_str = function @@ -234,6 +230,10 @@ let lb, rb = if prec > 0 then "(", ")" else "", "" in Format.fprintf f "@[<1>%s%a@ +@ %a%s@]" lb (fprint_real_prec 0) r1 (fprint_real_prec 0) r2 rb + | Pow (r1, r2) -> + let lb, rb = if prec > 2 then "(", ")" else "", "" in + Format.fprintf f "@[<1>%s%a^%a%s@]" lb + (fprint_real_prec 4) r1 (fprint_real_prec 4) r2 rb | Fun (s, v) -> Format.fprintf f ":%s(%s)" s (var_str v) | Char phi -> Format.fprintf f "@[<1>:(@,%a@,)@]" (fprint_prec 0) phi | Sum (vl, phi, r) -> @@ -326,7 +326,7 @@ List.fold_left (fun i f -> size ~acc:i f) (acc + 1) flist and size_real ?(acc=0) = function | RVar _ | Const _ | Fun _ -> acc + 1 - | Times (r1, r2) | Plus (r1, r2) -> + | Times (r1, r2) | Plus (r1, r2) | Pow (r1, r2) -> let s1 = size_real ~acc:(acc + 1) r1 in size_real ~acc:s1 r2 | Char phi -> size ~acc phi | Sum (_, phi, re) -> @@ -473,6 +473,14 @@ | (flat1, Const 1.) -> flat1 | (flat1, flat2) -> Times (flat1, flat2) ) + | Pow (re1, re2) -> + (match flatten_re_f f_or f_and re1, flatten_re_f f_or f_and re2 with + | (Const 0., _) -> Const 0. + | (Const 1., _) -> Const 1. + | (_, Const 0.) -> Const 1. + | (flat1, Const 1.) -> flat1 + | (flat1, flat2) -> Pow (flat1, flat2) + ) | Char (phi) -> Char (flatten_f f_or f_and phi) | Sum (vl, phi, r) -> Sum (vl, flatten_f f_or f_and phi, flatten_re_f f_or f_and r) @@ -489,7 +497,7 @@ (* Helper function: delete duplicates in ordered list. *) let rec del_dupl_ord acc = function - [] -> List.rev acc + | [] -> List.rev acc | [x] -> List.rev (x :: acc) | x :: y :: xs when x = y -> del_dupl_ord acc (y :: xs) | x :: y :: xs -> del_dupl_ord (x :: acc) (y :: xs) @@ -589,7 +597,7 @@ and syntax_ok_re ?(sg=ref []) ?(fp=[]) ?(pos=true) = function | RVar _ | Const _ | Fun _ -> true - | Times (re1, re2) | Plus (re1, re2) -> + | Times (re1, re2) | Plus (re1, re2) | Pow (re1, re2) -> syntax_ok_re ~sg ~fp ~pos re1 && syntax_ok_re ~sg ~fp ~pos re2 | Char phi -> syntax_ok ~sg ~fp ~pos phi | Sum (_, phi, r) -> @@ -606,8 +614,10 @@ | Fun (f, x) -> (fun _ a -> a.(Aux.find_index (f, var_str x) eqs)) | Plus (p, q) -> (let cp, cq = compile_re tv eqs p, compile_re tv eqs q in (fun t a -> (cp t a) +. (cq t a))) - | Times (p, q) -> (let cp, cq= compile_re tv eqs p, compile_re tv eqs q in + | Times (p, q) -> (let cp, cq = compile_re tv eqs p, compile_re tv eqs q in (fun t a -> (cp t a) *. (cq t a))) + | Pow (p, q) -> (let cp, cq = compile_re tv eqs p, compile_re tv eqs q in + (fun t a -> (cp t a) ** (cq t a))) | re -> failwith ("compilation for " ^ real_str re ^ " not implemented yet") let compile tv eqs = Modified: trunk/Toss/Formula/Formula.mli =================================================================== --- trunk/Toss/Formula/Formula.mli 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Formula/Formula.mli 2012-06-03 22:47:21 UTC (rev 1719) @@ -66,15 +66,14 @@ and real_expr = | RVar of string | Const of float - | Times of real_expr * real_expr | Plus of real_expr * real_expr + | Times of real_expr * real_expr + | Pow of real_expr * real_expr | Fun of string * fo_var | Char of formula | Sum of fo_var list * formula * real_expr | RLet of string * real_expr * real_expr -val pow : real_expr -> int -> real_expr - val size : ?acc : int -> formula -> int val size_real : ?acc : int -> real_expr -> int Modified: trunk/Toss/Formula/FormulaMap.ml =================================================================== --- trunk/Toss/Formula/FormulaMap.ml 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Formula/FormulaMap.ml 2012-06-03 22:47:21 UTC (rev 1719) @@ -21,10 +21,12 @@ and map_to_literals_expr f g = function | RVar _ | Const _ | Fun _ as x -> g x + | Plus (r1, r2) -> + Plus (map_to_literals_expr f g r1, map_to_literals_expr f g r2) | Times (r1, r2) -> Times (map_to_literals_expr f g r1, map_to_literals_expr f g r2) - | Plus (r1, r2) -> - Plus (map_to_literals_expr f g r1, map_to_literals_expr f g r2) + | Pow (r1, r2) -> + Pow (map_to_literals_expr f g r1, map_to_literals_expr f g r2) | Char (phi) -> Char (map_to_literals f g phi) | Sum (vs, phi, r) -> Sum (vs, map_to_literals f g phi, map_to_literals_expr f g r) @@ -71,8 +73,9 @@ map_RVar : string -> real_expr; map_Const : float -> real_expr; + map_Plus : real_expr -> real_expr -> real_expr; map_Times : real_expr -> real_expr -> real_expr; - map_Plus : real_expr -> real_expr -> real_expr; + map_Pow : real_expr -> real_expr -> real_expr; map_Fun : string -> fo_var -> real_expr; map_Char : formula -> real_expr; map_Sum : fo_var list -> formula -> real_expr -> real_expr; @@ -96,8 +99,9 @@ map_RVar = (fun v -> RVar v); map_Const = (fun c -> Const c); + map_Plus = (fun expr1 expr2 -> Plus (expr1, expr2)); map_Times = (fun expr1 expr2 -> Times (expr1, expr2)); - map_Plus = (fun expr1 expr2 -> Plus (expr1, expr2)); + map_Pow = (fun expr1 expr2 -> Pow (expr1, expr2)); map_Fun = (fun f v -> Fun (f, v)); map_Char = (fun phi -> Char phi); map_Sum = (fun vs guard expr -> Sum (vs, guard, expr)); @@ -124,10 +128,12 @@ and map_real_expr gmap = function | RVar v -> gmap.map_RVar v | Const c -> gmap.map_Const c + | Plus (expr1, expr2) -> + gmap.map_Plus (map_real_expr gmap expr1) (map_real_expr gmap expr2) | Times (expr1, expr2) -> gmap.map_Times (map_real_expr gmap expr1) (map_real_expr gmap expr2) - | Plus (expr1, expr2) -> - gmap.map_Plus (map_real_expr gmap expr1) (map_real_expr gmap expr2) + | Pow (expr1, expr2) -> + gmap.map_Pow (map_real_expr gmap expr1) (map_real_expr gmap expr2) | Fun (f, v) -> gmap.map_Fun f v | Char phi -> gmap.map_Char (map_formula gmap phi) | Sum (vs, guard, expr) -> @@ -154,8 +160,9 @@ fold_RVar : string -> 'a; fold_Const : float -> 'a; + fold_Plus : 'a -> 'a -> 'a; fold_Times : 'a -> 'a -> 'a; - fold_Plus : 'a -> 'a -> 'a; + fold_Pow : 'a -> 'a -> 'a; fold_Fun : string -> fo_var -> 'a; fold_Char : 'a -> 'a; fold_Sum : fo_var list -> 'a -> 'a -> 'a; @@ -179,8 +186,9 @@ fold_RVar = (fun _ -> empty); fold_Const = (fun _ -> empty); + fold_Plus = union; fold_Times = union; - fold_Plus = union; + fold_Pow = union; fold_Fun = (fun _ _ -> empty); fold_Char = (fun phi -> phi); fold_Sum = (fun _ guard expr -> union guard expr); @@ -219,10 +227,12 @@ and fold_real_expr gfold = function | RVar v -> gfold.fold_RVar v | Const c -> gfold.fold_Const c + | Plus (expr1, expr2) -> + gfold.fold_Plus (fold_real_expr gfold expr1) (fold_real_expr gfold expr2) | Times (expr1, expr2) -> gfold.fold_Times (fold_real_expr gfold expr1) (fold_real_expr gfold expr2) - | Plus (expr1, expr2) -> - gfold.fold_Plus (fold_real_expr gfold expr1) (fold_real_expr gfold expr2) + | Pow (expr1, expr2) -> + gfold.fold_Pow (fold_real_expr gfold expr1) (fold_real_expr gfold expr2) | Fun (f, v) -> gfold.fold_Fun f v | Char phi -> gfold.fold_Char (fold_formula gfold phi) | Sum (vs, guard, expr) -> @@ -230,14 +240,16 @@ | RLet (f, body, scope) -> gfold.fold_RLet f (fold_real_expr gfold body) (fold_real_expr gfold scope) -(* Map [f] to top-level formulas in the real expression ([Char]s and - [Sum] guards). *) +(* Map [f] to top-level formulas in the real expression + ([Char]s and [Sum] guards). *) let rec map_to_formulas_expr f = function | RVar _ | Const _ | Fun _ as x -> x + | Plus (r1, r2) -> + Plus (map_to_formulas_expr f r1, map_to_formulas_expr f r2) | Times (r1, r2) -> Times (map_to_formulas_expr f r1, map_to_formulas_expr f r2) - | Plus (r1, r2) -> - Plus (map_to_formulas_expr f r1, map_to_formulas_expr f r2) + | Pow (r1, r2) -> + Pow (map_to_formulas_expr f r1, map_to_formulas_expr f r2) | Char (phi) -> Char (f phi) | Sum (vs, phi, r) -> Sum (vs, f phi, map_to_formulas_expr f r) @@ -247,8 +259,7 @@ let rec fold_over_formulas_expr f r acc = match r with | RVar _ | Const _ | Fun _ -> acc - | Times (r1, r2) - | Plus (r1, r2) -> + | Plus (r1, r2) | Times (r1, r2) | Pow (r1, r2) -> fold_over_formulas_expr f r1 (fold_over_formulas_expr f r2 acc) | Char (phi) -> f phi acc | Sum (vs, phi, r) -> Modified: trunk/Toss/Formula/FormulaMap.mli =================================================================== --- trunk/Toss/Formula/FormulaMap.mli 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Formula/FormulaMap.mli 2012-06-03 22:47:21 UTC (rev 1719) @@ -41,8 +41,9 @@ map_RVar : string -> real_expr; map_Const : float -> real_expr; + map_Plus : real_expr -> real_expr -> real_expr; map_Times : real_expr -> real_expr -> real_expr; - map_Plus : real_expr -> real_expr -> real_expr; + map_Pow : real_expr -> real_expr -> real_expr; map_Fun : string -> fo_var -> real_expr; map_Char : formula -> real_expr; map_Sum : fo_var list -> formula -> real_expr -> real_expr; @@ -74,8 +75,9 @@ fold_RVar : string -> 'a; fold_Const : float -> 'a; + fold_Plus : 'a -> 'a -> 'a; fold_Times : 'a -> 'a -> 'a; - fold_Plus : 'a -> 'a -> 'a; + fold_Pow : 'a -> 'a -> 'a; fold_Fun : string -> fo_var -> 'a; fold_Char : 'a -> 'a; fold_Sum : fo_var list -> 'a -> 'a -> 'a; Modified: trunk/Toss/Formula/FormulaOps.ml =================================================================== --- trunk/Toss/Formula/FormulaOps.ml 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Formula/FormulaOps.ml 2012-06-03 22:47:21 UTC (rev 1719) @@ -475,6 +475,10 @@ Times (p, q) else simplify_re ~do_pnf ~do_formula ~ni (Times (simp_p, simp_q)) + | Pow (p, q) -> + let simp_p = simplify_re ~do_pnf ~do_formula ~ni p in + let simp_q = simplify_re ~do_pnf ~do_formula ~ni q in + Pow (simp_p, simp_q) | RLet _ as re -> simplify_re ~do_pnf ~do_formula ~ni (expand_real_expr re) @@ -847,8 +851,9 @@ and tnf_re_fun = function | RVar _ | Const _ | Fun _ as x -> x + | Plus (re1, re2) -> Plus (tnf_re_fun re1, tnf_re_fun re2) | Times (re1, re2) -> Times (tnf_re_fun re1, tnf_re_fun re2) - | Plus (re1, re2) -> Plus (tnf_re_fun re1, tnf_re_fun re2) + | Pow (re1, re2) -> Pow (tnf_re_fun re1, tnf_re_fun re2) | Char (phi) -> Char (flatten_sort (tnf_fun (flatten_sort phi))) | Sum (vl, f, r) -> Sum (vl, tnf_fun f, tnf_re_fun r) | RLet _ as re -> tnf_re_fun (expand_real_expr re) Modified: trunk/Toss/Formula/FormulaParser.mly =================================================================== --- trunk/Toss/Formula/FormulaParser.mly 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Formula/FormulaParser.mly 2012-06-03 22:47:21 UTC (rev 1719) @@ -53,7 +53,11 @@ | real_expr PLUS real_expr { Plus ($1, $3) } | real_expr MINUS real_expr { Plus ($1, Times (Const (-1.), $3)) } | real_expr TIMES real_expr { Times ($1, $3) } - | real_expr POW INT { pow $1 $3 } + | real_expr DIV real_expr { Times ($1, Pow ($3, Const (-1.))) } + | real_expr POW INT { Pow ($1, Const (float $3)) } + | real_expr POW FLOAT { Pow ($1, Const ($3)) } + | INT POW real_expr { Pow (Const (float $1), $3) } + | FLOAT POW real_expr { Pow (Const ($1), $3) } | SUM OPEN fo_var_list MID formula_expr COLON real_expr CLOSE { Formula.Sum ($3, $5, $7) } | COLON OPEN formula_expr CLOSE { Char (Formula.flatten $3) } Modified: trunk/Toss/Formula/FormulaSubst.ml =================================================================== --- trunk/Toss/Formula/FormulaSubst.ml 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Formula/FormulaSubst.ml 2012-06-03 22:47:21 UTC (rev 1719) @@ -95,8 +95,9 @@ | Const _ as x -> x | Fun (s, v) -> Fun (s, fo_var_subst subst v) | RVar s -> RVar (try List.assoc s subst with Not_found -> s) + | Plus (r1, r2) -> Plus (subst_vars_expr subst r1, subst_vars_expr subst r2) | Times (r1, r2) -> Times (subst_vars_expr subst r1,subst_vars_expr subst r2) - | Plus (r1, r2) -> Plus (subst_vars_expr subst r1, subst_vars_expr subst r2) + | Pow (r1, r2) -> Pow (subst_vars_expr subst r1, subst_vars_expr subst r2) | Char (phi) -> Char (subst_vars subst phi) | Sum (vs, phi, r) -> let in_vs (s, _) = List.exists (fun v -> var_str v = s) vs in @@ -206,8 +207,9 @@ (* Substitute recursively in [r] relations defined in [defs]. *) let rec subst_rels_expr defs = function | RVar _ | Const _ | Fun _ as x -> x + | Plus (r1, r2) -> Plus (subst_rels_expr defs r1, subst_rels_expr defs r2) | Times (r1, r2) -> Times (subst_rels_expr defs r1, subst_rels_expr defs r2) - | Plus (r1, r2) -> Plus (subst_rels_expr defs r1, subst_rels_expr defs r2) + | Pow (r1, r2) -> Pow (subst_rels_expr defs r1, subst_rels_expr defs r2) | Char (phi) -> Char (subst_rels defs phi) | Sum (vs, phi, r) -> Sum (vs, subst_rels defs phi, subst_rels_expr defs r) | RLet _ -> failwith "FormulaSubst:subst_rels_expr: rlet substitution" @@ -223,8 +225,9 @@ let rec subst_rvars subst = function | Const _ | Fun _ as x -> x | RVar s -> (try List.assoc s subst with Not_found -> RVar s) + | Plus (r1, r2) -> Plus (subst_rvars subst r1, subst_rvars subst r2) | Times (r1, r2) -> Times (subst_rvars subst r1, subst_rvars subst r2) - | Plus (r1, r2) -> Plus (subst_rvars subst r1, subst_rvars subst r2) + | Pow (r1, r2) -> Pow (subst_rvars subst r1, subst_rvars subst r2) | Char (phi) -> Char (subst_rvars_f subst phi) | Sum (vs, phi, r) -> Sum (vs, subst_rvars_f subst phi, subst_rvars subst r) | RLet _ -> failwith "FormulaSubst:subst_rvars on rlet" @@ -259,8 +262,9 @@ and expand_real_expr ?(defs=[]) = function | RVar _ | Const _ | Fun _ as x -> x + | Plus (r1, r2) -> Plus (expand_real_expr ~defs r1, expand_real_expr ~defs r2) | Times (r1,r2)-> Times (expand_real_expr ~defs r1, expand_real_expr ~defs r2) - | Plus (r1, r2) -> Plus (expand_real_expr ~defs r1, expand_real_expr ~defs r2) + | Pow (r1, r2) -> Pow (expand_real_expr ~defs r1, expand_real_expr ~defs r2) | Char (phi) -> Char (expand_formula ~defs phi) | Sum (vs, phi, r) -> Sum (vs, expand_formula ~defs phi, expand_real_expr ~defs r) @@ -291,8 +295,8 @@ and all_vars_real = function | RVar s -> [s] | Const _ -> [] - | Times (r1, r2) -> List.rev_append (all_vars_real r1) (all_vars_real r2) - | Plus (r1, r2) -> List.rev_append (all_vars_real r1) (all_vars_real r2) + | Plus (r1, r2) | Times (r1, r2) | Pow (r1, r2) -> + List.rev_append (all_vars_real r1) (all_vars_real r2) | Fun (s, v) -> [var_str v] | Char phi -> List.rev_map var_str (all_vars_acc [] phi) | Sum (_, f, r) -> @@ -325,8 +329,8 @@ and free_vars_real = function | RVar s -> [s] | Const _ -> [] - | Times (r1, r2) -> List.rev_append (all_vars_real r1) (all_vars_real r2) - | Plus (r1, r2) -> List.rev_append (all_vars_real r1) (all_vars_real r2) + | Plus (r1, r2) | Times (r1, r2) | Pow (r1, r2) -> + List.rev_append (free_vars_real r1) (free_vars_real r2) | Fun (s, v) -> [var_str v] | Char phi -> List.rev_map var_str (free_vars_acc [] phi) | Sum (vl, _, r) -> Modified: trunk/Toss/Makefile =================================================================== --- trunk/Toss/Makefile 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Makefile 2012-06-03 22:47:21 UTC (rev 1719) @@ -20,7 +20,8 @@ RELEASE=0.8 -Release: TossClient Server/Server.native TossServer doc +Release: TossClient Server/Server.native doc + make TossServer rm -f *~ MenhirLib/*~ Formula/*~ Term/*~ Solver/*~ Arena/*~ Play/*~ \ GGP/*~ Learn/*~ Server/*~ www/*~ WebClient/~ make -C www/reference @@ -167,13 +168,13 @@ # ---------- TESTS -------- -%Test: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest $@ +%Test: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest $@ -%TestVerbose: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -v -fulltest $(subst TestVerbose,Test,$@) +%TestVerbose: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -v -fulltest $(subst TestVerbose,Test,$@) %TestDebug: %Test.d.byte OCAMLRUNPARAM=b; export OCAMLRUNPARAM; _build/$< @@ -183,83 +184,88 @@ gprof _build/$< > $@.log # Formula tests -FormulaTests: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Formula -FormulaTestsVerbose: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Formula -v +FormulaTests: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Formula +FormulaTestsVerbose: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Formula -v # Solver tests -SolverTests: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Solver -SolverTestsVerbose: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Solver -v +SolverTests: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Solver +SolverTestsVerbose: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Solver -v # Term tests -TermTests: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Term -TermTestsVerbose: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Term -v +TermTests: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Term +TermTestsVerbose: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Term -v # Arena tests -ArenaTests: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Arena -ArenaTestsVerbose: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Arena -v +ArenaTests: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Arena +ArenaTestsVerbose: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Arena -v # Play tests -PlayTests: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Play -PlayTestsVerbose: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Play -v +PlayTests: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Play +PlayTestsVerbose: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Play -v # GGP tests -GGPTests: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest GGP -GGPTestsVerbose: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest GGP -v +GGPTests: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest GGP +GGPTestsVerbose: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest GGP -v GGPTestsExtra: Server/Server.native TossServer OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -extratest GGP # Learn tests -LearnTests: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Learn -LearnTestsVerbose: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Learn -v +LearnTests: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Learn +LearnTestsVerbose: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Learn -v -LearnTestsExtra: Server/Server.native TossServer +LearnTestsExtra: Server/Server.native + cp _build/Server/Server.native TossServer OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -extratest Learn # Server tests -ServerTests: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Server -ServerTestsVerbose: Server/Server.native TossServer - OCAMLRUNPARAM=b; export OCAMLRUNPARAM; \ - ./TossServer -fulltest Server -v +ServerTests: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Server +ServerTestsVerbose: Server/Server.native + cp _build/Server/Server.native TossServer + OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest Server -v # All OCaml tests -TossTest: Server/Server.native TossServer +TossTest: Server/Server.native + cp _build/Server/Server.native TossServer OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -test "" -TossTestVerbose: Server/Server.native TossServer +TossTestVerbose: Server/Server.native + cp _build/Server/Server.native TossServer OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -v -test "" -TossFullTest: Server/Server.native TossServer +TossFullTest: Server/Server.native + cp _build/Server/Server.native TossServer OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -fulltest "" -TossFullTestVerbose: Server/Server.native TossServer +TossFullTestVerbose: Server/Server.native + cp _build/Server/Server.native TossServer OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ./TossServer -v -fulltest "" # Client tests Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Play/Heuristic.ml 2012-06-03 22:47:21 UTC (rev 1719) @@ -262,7 +262,7 @@ let suggest_expansion_coef = 0.5 let f_monot adv_ratio n m = - Times (Formula.pow n (int_of_float adv_ratio), + Times (Formula.Pow (n, Const (adv_ratio)), Const (1. /. float_of_int m ** adv_ratio)) let print_heur msg heur = @@ -770,12 +770,14 @@ let rec map_constants f = function | Const c -> Const (f c) + | Plus (e1, e2) -> + Plus (map_constants f e1, map_constants f e2) | Times (e1, e2) -> - Times (map_constants f e1, map_constants f e2) - | Plus (e1, e2) -> - Plus (map_constants f e1, map_constants f e2) + Times (map_constants f e1, map_constants f e2) + | Pow (e1, e2) -> + Pow (map_constants f e1, map_constants f e2) | Sum (vs, phi, es) -> - Sum (vs, phi, map_constants f es) + Sum (vs, phi, map_constants f es) | RVar _ | Fun _ | Char _ as expr -> expr | RLet _ as re -> map_constants f (FormulaSubst.expand_real_expr re) @@ -907,8 +909,9 @@ | Const _ | Fun _ as expr -> expr | RLet _ as re -> aux gds (FormulaSubst.expand_real_expr re) + | Plus (a, b) -> Plus (aux gds a, aux gds b) | Times (a, b) -> Times (aux gds a, aux gds b) - | Plus (a, b) -> Plus (aux gds a, aux gds b) + | Pow (a, b) -> Pow (aux gds a, aux gds b) | Char phi -> (match fluent_preconds with | None -> (* not monotonic *) @@ -1012,7 +1015,7 @@ let posi_frels, nega_frels, indef_frels = Arena.all_fluents game in let array_plus ar = - Array.fold_right (fun x y->Plus (x, y)) ar (Const 0.) in + Array.fold_right (fun x y -> Plus (x, y)) ar (Const 0.) in let all_payoffs = array_plus (Array.map (fun (loc, _) -> array_plus (Array.map (fun l -> l.Arena.payoff) loc)) graph) in Modified: trunk/Toss/Play/HeuristicTest.ml =================================================================== --- trunk/Toss/Play/HeuristicTest.ml 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Play/HeuristicTest.ml 2012-06-03 22:47:21 UTC (rev 1719) @@ -273,14 +273,14 @@ "[a | P:1 {}; Q:1 {} | ] -> [ | P:1 {}; Q(a) | ] emb P, Q"] in assert_eq_str - "Sum (x, y, z | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v (C(z, u) and C(y, v) and R(y, u) and R(x, v)) or ex u, v (R(y, u) and R(x, v) and C(v, y) and C(u, z))) and (P(x) or P(y) or P(z)) and (not Q(x) or P(x)) and (not Q(y) or P(y)) and (not Q(z) or P(z))) : (:(P(x)) + :(P(y)) + :(P(z))) * 0.33) - Sum (x, y, z | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v (C(z, u) and C(y, v) and R(y, u) and R(x, v)) or ex u, v (R(y, u) and R(x, v) and C(v, y) and C(u, z))) and (Q(x) or Q(y) or Q(z)) and (not P(x) or Q(x)) and (not P(y) or Q(y)) and (not P(z) or Q(z))) : (:(Q(x)) + :(Q(y)) + :(Q(z))) * 0.33)" + "Sum (x, y, z | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v (C(z, u) and C(y, v) and R(y, u) and R(x, v)) or ex u, v (R(y, u) and R(x, v) and C(v, y) and C(u, z))) and (P(x) or P(y) or P(z)) and (not Q(x) or P(x)) and (not Q(y) or P(y)) and (not Q(z) or P(z))) : (:(P(x)) + :(P(y)) + :(P(z)))^1. * 0.33) - Sum (x, y, z | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v (C(z, u) and C(y, v) and R(y, u) and R(x, v)) or ex u, v (R(y, u) and R(x, v) and C(v, y) and C(u, z))) and (Q(x) or Q(y) or Q(z)) and (not P(x) or Q(x)) and (not P(y) or Q(y)) and (not P(z) or Q(z))) : (:(Q(x)) + :(Q(y)) + :(Q(z)))^1. * 0.33)" (Formula.real_str (Heuristic.map_constants (fun c->(floor (c*.100.))/.100.) (default_heuristic 1. rules (real_of_str (":("^winPxyz^") - :("^winQxyz^")"))))); assert_eq_str - "Sum (x, y, z | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v (C(z, u) and C(y, v) and R(y, u) and R(x, v)) or ex u, v (R(y, u) and R(x, v) and C(v, y) and C(u, z))) and (P(x) or P(y) or P(z)) and (not Q(x) or P(x)) and (not Q(y) or P(y)) and (not Q(z) or P(z))) : (:(P(x)) + :(P(y)) + :(P(z))) * (:(P(x)) + :(P(y)) + :(P(z))) * 0.11) - Sum (x, y, z | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v (C(z, u) and C(y, v) and R(y, u) and R(x, v)) or ex u, v (R(y, u) and R(x, v) and C(v, y) and C(u, z))) and (Q(x) or Q(y) or Q(z)) and (not P(x) or Q(x)) and (not P(y) or Q(y)) and (not P(z) or Q(z))) : (:(Q(x)) + :(Q(y)) + :(Q(z))) * (:(Q(x)) + :(Q(y)) + :(Q(z))) * 0.11)" + "Sum (x, y, z | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v (C(z, u) and C(y, v) and R(y, u) and R(x, v)) or ex u, v (R(y, u) and R(x, v) and C(v, y) and C(u, z))) and (P(x) or P(y) or P(z)) and (not Q(x) or P(x)) and (not Q(y) or P(y)) and (not Q(z) or P(z))) : (:(P(x)) + :(P(y)) + :(P(z)))^2. * 0.11) - Sum (x, y, z | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v (C(z, u) and C(y, v) and R(y, u) and R(x, v)) or ex u, v (R(y, u) and R(x, v) and C(v, y) and C(u, z))) and (Q(x) or Q(y) or Q(z)) and (not P(x) or Q(x)) and (not P(y) or Q(y)) and (not P(z) or Q(z))) : (:(Q(x)) + :(Q(y)) + :(Q(z)))^2. * 0.11)" (Formula.real_str (Heuristic.map_constants (fun c->(floor (c*.100.))/.100.) (default_heuristic 2. rules @@ -296,14 +296,14 @@ "[a | P:1 {}; Q:1 {} | ] -> [ | P:1 {}; Q(a) | ] emb P, Q"] in assert_eq_str - "Sum (v, w, x, y, z | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u (C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r)) or ex r, s, t, u (R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w))) and (P(z) or P(y) or P(x) or P(w) or P(v)) and (not Q(z) or P(z)) and (not Q(y) or P(y)) and (not Q(x) or P(x)) and (not Q(w) or P(w)) and (not Q(v) or P(v))) : (:(P(v)) + :(P(w)) + :(P(x)) + :(P(y)) + :(P(z))) * (:(P(v)) + :(P(w)) + :(P(x)) + :(P(y)) + :(P(z))) * 0.04 ) - Sum (v, w, x, y, z | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u (C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r)) or ex r, s, t, u (R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w))) and (Q(z) or Q(y) or Q(x) or Q(w) or Q(v)) and (not P(z) or Q(z)) and (not P(y) or Q(y)) and (not P(x) or Q(x)) and (not P(w) or Q(w)) and (not P(v) or Q(v))) : (:(Q(v)) + :(Q(w)) + :(Q(x)) + :(Q(y)) + :(Q(z))) * (:(Q(v)) + :(Q(w)) + :(Q(x)) + :(Q(y)) + :(Q(z))) * 0.04 )" + "Sum (v, w, x, y, z | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u (C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r)) or ex r, s, t, u (R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w))) and (P(z) or P(y) or P(x) or P(w) or P(v)) and (not Q(z) or P(z)) and (not Q(y) or P(y)) and (not Q(x) or P(x)) and (not Q(w) or P(w)) and (not Q(v) or P(v))) : (:(P(v)) + :(P(w)) + :(P(x)) + :(P(y)) + :(P(z)))^2. * 0.04) - Sum (v, w, x, y, z | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u (C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r)) or ex r, s, t, u (R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w))) and (Q(z) or Q(y) or Q(x) or Q(w) or Q(v)) and (not P(z) or Q(z)) and (not P(y) or Q(y)) and (not P(x) or Q(x)) and (not P(w) or Q(w)) and (not P(v) or Q(v))) : (:(Q(v)) + :(Q(w)) + :(Q(x)) + :(Q(y)) + :(Q(z)))^2. * 0.04)" (Formula.real_str ((* Heuristic.map_constants (fun c->(floor (c*.100.))/.100.) *) (default_heuristic 2. rules (real_of_str (":("^winPvwxyz^") - :("^winQvwxyz^")"))))); assert_eq_str - "Sum (v, w, x, y, z | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u (C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r)) or ex r, s, t, u (R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w))) and (P(z) or P(y) or P(x) or P(w) or P(v)) and (not Q(z) or P(z)) and (not Q(y) or P(y)) and (not Q(x) or P(x)) and (not Q(w) or P(w)) and (not Q(v) or P(v))) : (:(P(v)) + :(P(w)) + :(P(x)) + :(P(y)) + :(P(z))) * (:(P(v)) + :(P(w)) + :(P(x)) + :(P(y)) + :(P(z))) * (:(P(v)) + :(P(w)) + :(P(x)) + :(P(y)) + :(P(z))) * 0.008 ) - Sum (v, w, x, y, z | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u (C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r)) or ex r, s, t, u (R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w))) and (Q(z) or Q(y) or Q(x) or Q(w) or Q(v)) and (not P(z) or Q(z)) and (not P(y) or Q(y)) and (not P(x) or Q(x)) and (not P(w) or Q(w)) and (not P(v) or Q(v))) : (:(Q(v)) + :(Q(w)) + :(Q(x)) + :(Q(y)) + :(Q(z))) * (:(Q(v)) + :(Q(w)) + :(Q(x)) + :(Q(y)) + :(Q(z))) * (:(Q(v)) + :(Q(w)) + :(Q(x)) + :(Q(y)) + :(Q(z))) * 0.008 )" + "Sum (v, w, x, y, z | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u (C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r)) or ex r, s, t, u (R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w))) and (P(z) or P(y) or P(x) or P(w) or P(v)) and (not Q(z) or P(z)) and (not Q(y) or P(y)) and (not Q(x) or P(x)) and (not Q(w) or P(w)) and (not Q(v) or P(v))) : (:(P(v)) + :(P(w)) + :(P(x)) + :(P(y)) + :(P(z)))^3. * 0.008) - Sum (v, w, x, y, z | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u (C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r)) or ex r, s, t, u (R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w))) and (Q(z) or Q(y) or Q(x) or Q(w) or Q(v)) and (not P(z) or Q(z)) and (not P(y) or Q(y)) and (not P(x) or Q(x)) and (not P(w) or Q(w)) and (not P(v) or Q(v))) : (:(Q(v)) + :(Q(w)) + :(Q(x)) + :(Q(y)) + :(Q(z)))^3. * 0.008)" (Formula.real_str ((* Heuristic.map_constants (fun c->(floor (c*.1000.))/.1000.) *) (default_heuristic 3. rules @@ -345,7 +345,7 @@ ~advr:4.0 game in assert_eq_str - "100. * (Sum (cell_a_y8__BLANK_, cell_b_y8__BLANK_, cell_c1_y8__BLANK_, cell_d_y8__BLANK_, cell_e_y8__BLANK_ | ((cell_2x(cell_a_y8__BLANK_) or cell_2x(cell_b_y8__BLANK_) or cell_2x(cell_c1_y8__BLANK_) or cell_2x(cell_d_y8__BLANK_) or cell_2x(cell_e_y8__BLANK_)) and (cell_2b(cell_a_y8__BLANK_) or cell_2x(cell_a_y8__BLANK_)) and (cell_2b(cell_b_y8__BLANK_) or cell_2x(cell_b_y8__BLANK_)) and (cell_2b(cell_c1_y8__BLANK_) or cell_2x(cell_c1_y8__BLANK_)) and (cell_2b(cell_d_y8__BLANK_) or cell_2x(cell_d_y8__BLANK_)) and (cell_2b(cell_e_y8__BLANK_) or cell_2x(cell_e_y8__BLANK_)) and R2(cell_d_y8__BLANK_, cell_e_y8__BLANK_) and R2(cell_c1_y8__BLANK_, cell_d_y8__BLANK_) and R2(cell_b_y8__BLANK_, cell_c1_y8__BLANK_) and R2(cell_a_y8__BLANK_, cell_b_y8__BLANK_)) : (:(cell_2x(cell_a_y8__BLANK_)) + :(cell_2x(cell_b_y8__BLANK_)) + :(cell_2x(cell_c1_y8__BLANK_)) + :(cell_2x(cell_d_y8__BLANK_)) + :(cell_2x(cell_e_y8__BLANK_))) * (:(cell_2x(cell_a_y8__BLANK_)) + :(cell_2x(cell_b_y8__BLANK_)) + :(cell_2x(cell_c1_y8__BLANK_)) + :(cell_2x(cell_d_y8__BLANK_)) + :(cell_2x(cell_e_y8__BLANK_))) * (:(cell_2x(cell_a_y8__BLANK_)) + :(cell_2x(cell_b_y8__BLANK_)) + :(cell_2x(cell_c1_y8__BLANK_)) + :(cell_2x(cell_d_y8__BLANK_)) + :(cell_2x(cell_e_y8__BLANK_))) * (:(cell_2x(cell_a_y8__BLANK_)) + :(cell_2x(cell_b_y8__BLANK_)) + :(cell_2x(cell_c1_y8__BLANK_)) + :(cell_2x(cell_d_y8__BLANK_)) + :(cell_2x(cell_e_y8__BLANK_))) * 0.0016 ) + Sum (cell_x14_y18__BLANK_, cell_x15_y17__BLANK_, cell_x16_y16__BLANK_, cell_x17_y15__BLANK_, cell_x18_y14__BLANK_ | ((cell_2x(cell_x14_y18__BLANK_) or cell_2x(cell_x15_y17__BLANK_) or cell_2x(cell_x16_y16__BLANK_) or cell_2x(cell_x17_y15__BLANK_) or cell_2x(cell_x18_y14__BLANK_)) and (cell_2b(cell_x14_y18__BLANK_) or cell_2x(cell_x14_y18__BLANK_)) and (cell_2b(cell_x15_y17__BLANK_) or cell_2x(cell_x15_y17__BLANK_)) and (cell_2b(cell_x16_y16__BLANK_) or cell_2x(cell_x16_y16__BLANK_)) and (cell_2b(cell_x17_y15__BLANK_) or cell_2x(cell_x17_y15__BLANK_)) and (cell_2b(cell_x18_y14__BLANK_) or cell_2x(cell_x18_y14__BLANK_)) and R1(cell_x17_y15__BLANK_, cell_x18_y14__BLANK_) and R1(cell_x16_y16__BLANK_, cell_x17_y15__BLANK_) and R1(cell_x15_y17__BLANK_, cell_x16_y16__BLANK_) and R1(cell_x14_y18__BLANK_, cell_x15_y17__BLANK_)) : (:(cell_2x(cell_x14_y18__BLANK_)) + :(cell_2x(cell_x15_y17__BLANK_)) + :(cell_2x(cell_x16_y16__BLANK_)) + :(cell_2x(cell_x17_y15__BLANK_)) + :(cell_2x(cell_x18_y14__BLANK_))) * (:(cell_2x(cell_x14_y18__BLANK_)) + :(cell_2x(cell_x15_y17__BLANK_)) + :(cell_2x(cell_x16_y16__BLANK_)) + :(cell_2x(cell_x17_y15__BLANK_)) + :(cell_2x(cell_x18_y14__BLANK_))) * (:(cell_2x(cell_x14_y18__BLANK_)) + :(cell_2x(cell_x15_y17__BLANK_)) + :(cell_2x(cell_x16_y16__BLANK_)) + :(cell_2x(cell_x17_y15__BLANK_)) + :(cell_2x(cell_x18_y14__BLANK_))) * (:(cell_2x(cell_x14_y18__BLANK_)) + :(cell_2x(cell_x15_y17__BLANK_)) + :(cell_2x(cell_x16_y16__BLANK_)) + :(cell_2x(cell_x17_y15__BLANK_)) + :(cell_2x(cell_x18_y14__BLANK_))) * 0.0016 ) + Sum (cell_x10_y10__BLANK_, cell_x11_y11__BLANK_, cell_x12_y12__BLANK_, cell_x13_y13__BLANK_, cell_x9_y9__BLANK_ | ((cell_2x(cell_x10_y10__BLANK_) or cell_2x(cell_x11_y11__BLANK_) or cell_2x(cell_x12_y12__BLANK_) or cell_2x(cell_x13_y13__BLANK_) or cell_2x(cell_x9_y9__BLANK_)) and (cell_2b(cell_x10_y10__BLANK_) or cell_2x(cell_x10_y10__BLANK_)) and (cell_2b(cell_x11_y11__BLANK_) or cell_2x(cell_x11_y11__BLANK_)) and (cell_2b(cell_x12_y12__BLANK_) or cell_2x(cell_x12_y12__BLANK_)) and (cell_2b(cell_x13_y13__BLANK_) or cell_2x(cell_x13_y13__BLANK_)) and (cell_2b(cell_x9_y9__BLANK_) or cell_2x(cell_x9_y9__BLANK_)) and R0(cell_x9_y9__BLANK_, cell_x10_y10__BLANK_) and R0(cell_x12_y12__BLANK_, cell_x13_y13__BLANK_) and R0(cell_x11_y11__BLANK_, cell_x12_y12__BLANK_) and R0(cell_x10_y10__BLANK_, cell_x11_y11__BLANK_)) : (:(cell_2x(cell_x10_y10__BLANK_)) + :(cell_2x(cell_x11_y11__BLANK_)) + :(cell_2x(cell_x12_y12__BLANK_)) + :(cell_2x(cell_x13_y13__BLANK_)) + :(cell_2x(cell_x9_y9__BLANK_))) * (:(cell_2x(cell_x10_y10__BLANK_)) + :(cell_2x(cell_x11_y11__BLANK_)) + :(cell_2x(cell_x12_y12__BLANK_)) + :(cell_2x(cell_x13_y13__BLANK_)) + :(cell_2x(cell_x9_y9__BLANK_))) * (:(cell_2x(cell_x10_y10__BLANK_)) + :(cell_2x(cell_x11_y11__BLANK_)) + :(cell_2x(cell_x12_y12__BLANK_)) + :(cell_2x(cell_x13_y13__BLANK_)) + :(cell_2x(cell_x9_y9__BLANK_))) * (:(cell_2x(cell_x10_y10__BLANK_)) + :(cell_2x(cell_x11_y11__BLANK_)) + :(cell_2x(cell_x12_y12__BLANK_)) + :(cell_2x(cell_x13_y13__BLANK_)) + :(cell_2x(cell_x9_y9__BLANK_))) * 0.0016 ) + Sum (cell_x8_a0__BLANK_, cell_x8_b0__BLANK_, cell_x8_c2__BLANK_, cell_x8_d0__BLANK_, cell_x8_e0__BLANK_ | ((cell_2x(cell_x8_a0__BLANK_) or cell_2x(cell_x8_b0__BLANK_) or cell_2x(cell_x8_c2__BLANK_) or cell_2x(cell_x8_d0__BLANK_) or cell_2x(cell_x8_e0__BLANK_)) and (cell_2b(cell_x8_a0__BLANK_) or cell_2x(cell_x8_a0__BLANK_)) and (cell_2b(cell_x8_b0__BLANK_) or cell_2x(cell_x8_b0__BLANK_)) and (cell_2b(cell_x8_c2__BLANK_) or cell_2x(cell_x8_c2__BLANK_)) and (cell_2b(cell_x8_d0__BLANK_) or cell_2x(cell_x8_d0__BLANK_)) and (cell_2b(cell_x8_e0__BLANK_) or cell_2x(cell_x8_e0__BLANK_)) and R(cell_x8_d0__BLANK_, cell_x8_e0__BLANK_) and R(cell_x8_c2__BLANK_, cell_x8_d0__BLANK_) and R(cell_x8_b0__BLANK_, cell_x8_c2__BLANK_) and R(cell_x8_a0__BLANK_, cell_x8_b0__BLANK_)) : (:(cell_2x(cell_x8_a0__BLANK_)) + :(cell_2x(cell_x8_b0__BLANK_)) + :(cell_2x(cell_x8_c2__BLANK_)) + :(cell_2x(cell_x8_d0__BLANK_)) + :(cell_2x(cell_x8_e0__BLANK_))) * (:(cell_2x(cell_x8_a0__BLANK_)) + :(cell_2x(cell_x8_b0__BLANK_)) + :(cell_2x(cell_x8_c2__BLANK_)) + :(cell_2x(cell_x8_d0__BLANK_)) + :(cell_2x(cell_x8_e0__BLANK_))) * (:(cell_2x(cell_x8_a0__BLANK_)) + :(cell_2x(cell_x8_b0__BLANK_)) + :(cell_2x(cell_x8_c2__BLANK_)) + :(cell_2x(cell_x8_d0__BLANK_)) + :(cell_2x(cell_x8_e0__BLANK_))) * (:(cell_2x(cell_x8_a0__BLANK_)) + :(cell_2x(cell_x8_b0__BLANK_)) + :(cell_2x(cell_x8_c2__BLANK_)) + :(cell_2x(cell_x8_d0__BLANK_)) + :(cell_2x(cell_x8_e0__BLANK_))) * 0.0016 )) + 50. * Sum ( | false : 0. * 0. * 0. * 0. * inf)" + "100. * (Sum (cell_a_y8__BLANK_, cell_b_y8__BLANK_, cell_c1_y8__BLANK_, cell_d_y8__BLANK_, cell_e_y8__BLANK_ | ((cell_2x(cell_a_y8__BLANK_) or cell_2x(cell_b_y8__BLANK_) or cell_2x(cell_c1_y8__BLANK_) or cell_2x(cell_d_y8__BLANK_) or cell_2x(cell_e_y8__BLANK_)) and (cell_2b(cell_a_y8__BLANK_) or cell_2x(cell_a_y8__BLANK_)) and (cell_2b(cell_b_y8__BLANK_) or cell_2x(cell_b_y8__BLANK_)) and (cell_2b(cell_c1_y8__BLANK_) or cell_2x(cell_c1_y8__BLANK_)) and (cell_2b(cell_d_y8__BLANK_) or cell_2x(cell_d_y8__BLANK_)) and (cell_2b(cell_e_y8__BLANK_) or cell_2x(cell_e_y8__BLANK_)) and R2(cell_d_y8__BLANK_, cell_e_y8__BLANK_) and R2(cell_c1_y8__BLANK_, cell_d_y8__BLANK_) and R2(cell_b_y8__BLANK_, cell_c1_y8__BLANK_) and R2(cell_a_y8__BLANK_, cell_b_y8__BLANK_)) : (:(cell_2x(cell_a_y8__BLANK_)) + :(cell_2x(cell_b_y8__BLANK_)) + :(cell_2x(cell_c1_y8__BLANK_)) + :(cell_2x(cell_d_y8__BLANK_)) + :(cell_2x(cell_e_y8__BLANK_)))^4. * 0.0016 ) + Sum (cell_x14_y18__BLANK_, cell_x15_y17__BLANK_, cell_x16_y16__BLANK_, cell_x17_y15__BLANK_, cell_x18_y14__BLANK_ | ((cell_2x(cell_x14_y18__BLANK_) or cell_2x(cell_x15_y17__BLANK_) or cell_2x(cell_x16_y16__BLANK_) or cell_2x(cell_x17_y15__BLANK_) or cell_2x(cell_x18_y14__BLANK_)) and (cell_2b(cell_x14_y18__BLANK_) or cell_2x(cell_x14_y18__BLANK_)) and (cell_2b(cell_x15_y17__BLANK_) or cell_2x(cell_x15_y17__BLANK_)) and (cell_2b(cell_x16_y16__BLANK_) or cell_2x(cell_x16_y16__BLANK_)) and (cell_2b(cell_x17_y15__BLANK_) or cell_2x(cell_x17_y15__BLANK_)) and (cell_2b(cell_x18_y14__BLANK_) or cell_2x(cell_x18_y14__BLANK_)) and R1(cell_x17_y15__BLANK_, cell_x18_y14__BLANK_) and R1(cell_x16_y16__BLANK_, cell_x17_y15__BLANK_) and R1(cell_x15_y17__BLANK_, cell_x16_y16__BLANK_) and R1(cell_x14_y18__BLANK_, cell_x15_y17__BLANK_)) : (:(cell_2x(cell_x14_y18__BLANK_)) + :(cell_2x(cell_x15_y17__BLANK_)) + :(cell_2x(cell_x16_y16__BLANK_)) + :(cell_2x(cell_x17_y15__BLANK_)) + :(cell_2x(cell_x18_y14__BLANK_)))^4. * 0.0016 ) + Sum (cell_x10_y10__BLANK_, cell_x11_y11__BLANK_, cell_x12_y12__BLANK_, cell_x13_y13__BLANK_, cell_x9_y9__BLANK_ | ((cell_2x(cell_x10_y10__BLANK_) or cell_2x(cell_x11_y11__BLANK_) or cell_2x(cell_x12_y12__BLANK_) or cell_2x(cell_x13_y13__BLANK_) or cell_2x(cell_x9_y9__BLANK_)) and (cell_2b(cell_x10_y10__BLANK_) or cell_2x(cell_x10_y10__BLANK_)) and (cell_2b(cell_x11_y11__BLANK_) or cell_2x(cell_x11_y11__BLANK_)) and (cell_2b(cell_x12_y12__BLANK_) or cell_2x(cell_x12_y12__BLANK_)) and (cell_2b(cell_x13_y13__BLANK_) or cell_2x(cell_x13_y13__BLANK_)) and (cell_2b(cell_x9_y9__BLANK_) or cell_2x(cell_x9_y9__BLANK_)) and R0(cell_x9_y9__BLANK_, cell_x10_y10__BLANK_) and R0(cell_x12_y12__BLANK_, cell_x13_y13__BLANK_) and R0(cell_x11_y11__BLANK_, cell_x12_y12__BLANK_) and R0(cell_x10_y10__BLANK_, cell_x11_y11__BLANK_)) : (:(cell_2x(cell_x10_y10__BLANK_)) + :(cell_2x(cell_x11_y11__BLANK_)) + :(cell_2x(cell_x12_y12__BLANK_)) + :(cell_2x(cell_x13_y13__BLANK_)) + :(cell_2x(cell_x9_y9__BLANK_)))^4. * 0.0016 ) + Sum (cell_x8_a0__BLANK_, cell_x8_b0__BLANK_, cell_x8_c2__BLANK_, cell_x8_d0__BLANK_, cell_x8_e0__BLANK_ | ((cell_2x(cell_x8_a0__BLANK_) or cell_2x(cell_x8_b0__BLANK_) or cell_2x(cell_x8_c2__BLANK_) or cell_2x(cell_x8_d0__BLANK_) or cell_2x(cell_x8_e0__BLANK_)) and (cell_2b(cell_x8_a0__BLANK_) or cell_2x(cell_x8_a0__BLANK_)) and (cell_2b(cell_x8_b0__BLANK_) or cell_2x(cell_x8_b0__BLANK_)) and (cell_2b(cell_x8_c2__BLANK_) or cell_2x(cell_x8_c2__BLANK_)) and (cell_2b(cell_x8_d0__BLANK_) or cell_2x(cell_x8_d0__BLANK_)) and (cell_2b(cell_x8_e0__BLANK_) or cell_2x(cell_x8_e0__BLANK_)) and R(cell_x8_d0__BLANK_, cell_x8_e0__BLANK_) and R(cell_x8_c2__BLANK_, cell_x8_d0__BLANK_) and R(cell_x8_b0__BLANK_, cell_x8_c2__BLANK_) and R(cell_x8_a0__BLANK_, cell_x8_b0__BLANK_)) : (:(cell_2x(cell_x8_a0__BLANK_)) + :(cell_2x(cell_x8_b0__BLANK_)) + :(cell_2x(cell_x8_c2__BLANK_)) + :(cell_2x(cell_x8_d0__BLANK_)) + :(cell_2x(cell_x8_e0__BLANK_)))^4. * 0.0016 )) + 50. * Sum ( | false : 0.^4. * inf)" (Formula.real_str loc_heurs.(0).(0)); ); Modified: trunk/Toss/Solver/Solver.ml =================================================================== --- trunk/Toss/Solver/Solver.ml 2012-06-02 21:13:38 UTC (rev 1718) +++ trunk/Toss/Solver/Solver.ml 2012-06-03 22:47:21 UTC (rev 1719) @@ -261,8 +261,8 @@ let rec fo_vars_r_rec = function | RVar s -> [] | Const _ -> [] - | Times (r1, r2) -> List.rev_append (fo_vars_r_rec r1) (fo_vars_r_rec r2) - | Plus (r1, r2) -> List.rev_append (fo_vars_r_rec r1) (fo_vars_r_rec r2) + | Plus (r1, r2) | Times (r1, r2) | Pow (r1, r2) -> + List.rev_append (fo_vars_r_rec r1) (fo_vars_r_rec r2) | Fun (s, v) -> [v] | Char phi -> let fv = FormulaSubst.free_vars phi in @@ -284,11 +284,16 @@ | MSO _ -> failwith "free MSO vars in real exprs and sums not supported" | Real [[(poly, _)]] -> poly | Real _ -> failwith "too many polynomials in assignement to sum over" in + let rec pow p n = + if n = 0 then Const 1. else if n = 1 then p else Times (p, pow p (n-1)) in let rec poly_of assgn = function | RVar s -> Poly.Var s | Const f -> Poly.Const f | Times (r1, r2) -> Poly.Times (poly_of assgn r1, poly_of assgn r2) | Plus (r1, r2) -> Poly.Plus (poly_of assgn r1, poly_of assgn r2) + | Pow (r, Const (f)) when let n = int_of_float f in n >= 0 && float n = f -> + let n = int_of_float f in poly_of assgn (pow r n) + | Pow (_, _) -> failwith "poly_of: powers not supported" | Fun (s, v) -> (try let e = List.assoc v assgn in @@ -465,10 +470,12 @@ match expr with | Char phi -> if check_fa phi then 1. else 0. | Const v -> v + | Plus (e1, e2) -> + (get_real_val solver asg e1 struc) +. (get_real_val solver asg e2 struc) | Times (e1, e2) -> (get_real_val solver asg e1 struc) *. (get_real_val solver asg e2 struc) - | Plus (e1, e2) -> - (get_real_val solver asg e1 struc) +. (get_real_val solver asg e2 struc) + | Pow (e1, e2) -> + (get_real_val solver asg e1 struc) ** (get_real_val solver asg e2 struc) | Fun (fname, var) when List.length (AssignmentSet.assigned_elems (var_str var) asg) = 1 -> let elem = List.hd (AssignmentSet.assigned_elems (var_str var) asg) in @@ -513,6 +520,9 @@ | Times (e1, e2) -> (get_real_val_cache ~asg solver struc e1) *. (get_real_val_cache ~asg solver struc e2) + | Pow (e1, e2) -> + (get_real_val_cache ~asg solver struc e1) ** + (get_real_val_cache ~asg solver struc e2) | re -> update_cache struc; try Added: trunk/Toss/examples/Forces.toss =================================================================== --- trunk/Toss/examples/Forces.toss (rev 0) +++ trunk/Toss/examples/Forces.toss 2012-06-03 22:47:21 UTC (rev 1719) @@ -0,0 +1,55 @@ +PLAYERS 1, 2 + +RULE Coulomb: + [ e1, e2 | | ] -> [ e1, e2 | | ] + dynamics + :vx(e1)' = :ke *(:x(e1)-:x(e2)) / ((:x(e1)-:x(e2))^2+(:y(e1)-:y(e2))^2)^1.5; + :vy(e1)' = :ke *(:y(e1)-:y(e2)) / ((:x(e1)-:x(e2))^2+(:y(e1)-:y(e2))^2)^1.5; + :vx(e2)' = :ke *(:x(e2)-:x(e1)) / ((:x(e1)-:x(e2))^2+(:y(e1)-:y(e2))^2)^1.5; + :vy(e2)' = :ke *(:y(e2)-:y(e1)) / ((:x(e1)-:x(e2))^2+(:y(e1)-:y(e2))^2)^1.5; + :x(e1)' = :vx(e1); + :y(e1)' = :vy(e1); + :x(e2)' = :vx(e2); + :y(e2)' = :vy(e2) + pre :x(e1) > :x(e2) + +RULE Hooke: + [ e1, e2 | E (e1, e2) | ] -> [ e1, e2 | E (e1, e2) | ] emb E + dynamics + :vx(e1)' = -:k*((:x(e1)-:x(e2)) / ((:x(e1)-:x(e2))^2+(:y(e1)-:y(e2))^2)^0.5) + * (((:x(e1)-:x(e2))^2+(:y(e1)-:y(e2))^2)^0.5 - 15.); + :vy(e1)' = -:k*((:y(e1)-:y(e2)) / ((:x(e1)-:x(e2))^2+(:y(e1)-:y(e2))^2)^0.5) + * (((:x(e1)-:x(e2))^2+(:y(e1)-:y(e2))^2)^0.5 - 15.); + :vx(e2)' = -:k*((:x(e2)-:x(e1)) / ((:x(e1)-:x(e2))^2+(:y(e1)-:y(e2))^2)^0.5) + * (((:x(e1)-:x(e2))^2+(:y(e1)-:y(e2))^2)^0.5 - 15.); + :vy(e2)' = -:k*((:y(e2)-:y(e1)) / ((:x(e1)-:x(e2))^2+(:y(e1)-:y(e2))^2)^0.5) + * (((:x(e1)-:x(e2))^2+(:y(e1)-:y(e2))^2)^0.5 - 15.); + :x(e1)' = 0.; + :y(e1)' = 0.; + :x(e2)' = 0.; + :y(e2)' = 0. + +RULE Friction: + [ e1 | | ] -> [ e1 | | ] + dynamics + :vx(e1)' = -:f * :vx(e1); + :vy(e1)' = -:f * :vy(e1); + :x(e1)' = 0.; + :y(e1)' = 0. + +RULE Move: + [ e1 | Start(e1) | ] -> [ e1 | Start(e1) | ] + +LOC 0 { + PLAYER 1 { PAYOFF 0. MOVES [Move, + :t : 3. -- 3., + :k : 0.1 -- 0.1, + :f : 0.1 -- 0.1, + :ke : 200. -- 200. -> 0] } + PLAYER 2 { PAYOFF 0. } + UNIVERSAL { Coulomb, Hooke, Friction } +} + +START [ e5 | Start(e1); E { (e1, e2); (e1, e3); (e1, e4) } | + vx { e1->0, e2->0, e3->0, e4->0, e5->0 }; vy { e1->0, e2->0, e3->0, e4->0,e5->0 }; + x { e1->0., e2->10., e3->10., e4->10, e5->0. }; y { e1->0., e2->9, e3->0, e4->-9, e5->0 } ] Added: trunk/Toss/examples/Parsing.toss =================================================================== --- trunk/Toss/examples/Parsing.toss (rev 0) +++ trunk/Toss/examples/Parsing.toss 2012-06-03 22:47:21 UTC (rev 1719) @@ -0,0 +1,16 @@ +PLAYERS 1, 2 +RULE NilList: + [e1 | Pnil(e1) | ] -> [a1, a2 | Pnil (a1); Tp (a1, a2); Tlist (a2) | ] + emb Pnil with [a1 <- e1] update + :x(a1) = :x(e1); + :x(a2) = :x(e1); + :y(a1) = :y(e1); + :y(a2) = :y(e1) + 1. + +LOC 0 { + PLAYER 1 { PAYOFF 0. MOVES [NilList -> 0] } + PLAYER 2 { PAYOFF 0. } +} + +START [ | Tp:2 {}; Tlist:1 {}; Pone (one); Ptrue (t); Pnil (nil); + S { (one, t); (t, nil) } | ] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |