diff --git a/a.out b/a.out new file mode 100644 index 0000000..cbbe889 Binary files /dev/null and b/a.out differ diff --git a/addfunction.ml b/addfunction.ml new file mode 100644 index 0000000..657a939 --- /dev/null +++ b/addfunction.ml @@ -0,0 +1,496 @@ +open Printf + + + +let rec str2listchar st = match st with + | "" -> [] + | st -> (String.make 1 (String.get st 0) ) :: (str2listchar (String.sub st 1 ( (String.length st)-1) ) ) ;; + +let ch2int c = match c with + | "0" -> 0 + | "1" -> 1 + | "2" -> 2 + | "3" -> 3 + | "4" -> 4 + | "5" -> 5 + | "6" -> 6 + | "7" -> 7 + | "8" -> 8 + | "9" -> 9 + | c -> -1 ;; + + +let rec extint st = List.filter (fun x-> x>=0) (List.map ch2int (str2listchar st));; + +let rec getint l s = if List.length l > 0 then getint (List.tl l) (s*10+ List.hd l) else s;; + +let rec getintmax l s m = if (List.length l > 0)&&(s < m) then getintmax (List.tl l) (s*10+ List.hd l) m else s;; + +let getfirstint st = let lint = extint st in getint lint 0 ;; + +let getfirstintmax st = let lint = extint st in getintmax lint 0 300;; + +let read_file filename = + let lines = ref [] in + let chan = open_in filename in + try + while true; do + lines := input_line chan :: !lines + done; !lines + with End_of_file -> + close_in chan; + List.rev !lines ;; + +let rec addline strl1 strl2 seek s= + if (String.compare (List.hd strl1) seek)==0 then s@[seek]@strl2@(List.tl strl1) + else addline (List.tl strl1) strl2 seek (s@[List.hd strl1]);; + +let rec addlineall strl1 strl2 seek s= if (List.length strl1) ==0 then s else + if (String.compare (List.hd strl1) seek)==0 then addlineall (List.tl strl1) strl2 seek s@[seek]@strl2 + else addlineall (List.tl strl1) strl2 seek (s@[List.hd strl1]);; + +let rec addlinebefore strl1 strl2 seek s= + if (String.compare (List.hd strl1) seek)==0 then s@strl2@[seek]@(List.tl strl1) + else addlinebefore (List.tl strl1) strl2 seek (s@[List.hd strl1]);; + +let rec getlinebefore strl1 seek= + if (String.compare (List.hd (List.tl strl1)) seek)==0 then List.hd strl1 + else getlinebefore (List.tl strl1) seek;; + +let rec formula_to_code str = + let binop = ["+";"-";"*";"/";"^"] in + let unfun = ["-";"abs";"inv";"sqrt";"sin";"cos";"tan";"asin";"acos";"atan"] in + let binfun=["max";"min"] in + let opname st = match st with | "+" -> "add" | "-" -> "sub"| "*" -> "mul" | "/" -> "div" | "^" -> "nat_pow" in + let opval st = match st with | "+" -> 1 | "-" -> 1 | "*" -> 2 | "/" -> 2 | "^" -> 3 in + let inlist l e = List.exists (fun x -> ((String.compare x e)==0) ) l in + let rec countparen st l r= match st with + | "" -> (l,r) + | st -> if (String.compare (String.make 1 (String.get st 0) ) "(" ) ==0 then countparen (String.sub st 1 ( (String.length st)-1) ) (l+1) r + else if (String.compare (String.make 1 (String.get st 0) ) ")" ) ==0 then countparen (String.sub st 1 ( (String.length st)-1) ) l (r+1) + else countparen (String.sub st 1 ( (String.length st)-1) ) l r in + + let balance st = let (l,r) = countparen st 0 0 in (l==r) in + + let rec redundantparen st c = if c+1 == String.length st then (balance st) else let (l,r) = countparen( String.sub st 0 c ) 0 0 in + if r>=l then false else redundantparen st (c+1) in + + let lastchar st = let l = String.length st in String.sub st (l-1) 1 in + let removeparen st = if String.length st == 0 then st else if redundantparen st 1 && + ((String.compare (String.sub st 0 1) "(" ) ==0) && + ((String.compare (lastchar st) ")" )==0) then (String.sub st 1 ( (String.length st)-2) ) else st in + let rec removeallparen st = if String.compare st (removeparen st) == 0 then st else removeallparen (removeparen st) in + let rec removespace st= if (String.contains st ' ')==false then st + else let c = (String.index st ' ') in let stleft=String.sub st 0 c in let stright=String.sub st (c+1) ((String.length st)-c-1) in String.concat "" [stleft;stright] in + let rec removespaces st = if String.compare st (removespace st) == 0 then st else removeallparen (removespace st) in + let rec standard st = removeallparen (removespaces st) in + let rec find_bin_op st c m t= if ((c==((String.length st)-1)) && (m==5)) || ((String.length st)<2) then ("No","","") else + if ((c==((String.length st)-1)) && (m<5)) then t else + let stleft=String.sub st 0 c in + let stright=String.sub st (c+1) ((String.length st)-c-1) in + let op=String.make 1 (String.get st c) in + if (inlist binop op) && (balance stleft) && (balance stright) && (m>opval op) then find_bin_op st (c+1) (opval op) (op,stleft,stright) else find_bin_op st (c+1) m t in + + let rec splitexpr st c = if (c==((String.length st)-1)) || ((String.length st)<2) then ("","") else + let stleft=String.sub st 0 c in + let stright=String.sub st (c+1) ((String.length st)-c-1) in + let com=String.make 1 (String.get st c) in + if ((String.compare com ",") == 0) && (balance stleft) && (balance stright) then (stleft,stright) else splitexpr st (c+1) in + + let rec find_bin_func st = if (String.contains st '(')==false then ("No","","") else let c = (String.index st '(') in + let op = String.sub st 0 c in + let inexpr = String.sub st (c+1) ((String.length st)-c-2) in + let (lexpr,rexpr) = splitexpr inexpr 1 in + if ((String.compare lexpr "") == 0) || ((inlist binfun op)==false) then ("No","","") else (op,lexpr,rexpr) in + + let rec find_un_func st = if (String.contains st '(')==false then ("No","") else let c = (String.index st '(') in + let op = String.sub st 0 c in + let inexpr = String.sub st (c+1) ((String.length st)-c-2) in + if ((inlist unfun op)==false) then ("No","") else if (String.compare op "-") == 0 then ("neg",inexpr) else (op,inexpr) in + + + let expr = standard str in + let (op,l,r) = find_bin_op expr 1 5 ("No","","") in + if (String.compare op "No" <> 0) then String.concat "" ["(mk_"; (opname op) ; " "; formula_to_code l; " "; formula_to_code r; ")"] else + let (op,l,r) = find_bin_func expr in + if (String.compare op "No" <> 0) then String.concat "" ["(mk"; op ; " "; formula_to_code l; " " ; formula_to_code r; ")"] else + let (op,l) = find_un_func expr in + if (String.compare op "No" <> 0) then String.concat "" ["(mk_"; op ; " "; formula_to_code l; ")"] else + if String.compare expr "x" == 0 then "x" else + if String.compare expr "-x" == 0 then "(mk_neg x)" else + if String.contains expr '.' then String.concat "" ["(mk_const (Const.of_float (";expr; ")))"] else + String.concat "" ["(mk_const (Const.of_float (";expr; ".0)))"] ;; + +let write_taylor_form_ml_dev funcname first_derivative second_derivative_formula output= + let inlines = read_file "taylor_form.ml" in + let code = [ +(String.concat "" ["let "; funcname; "_form cs f ="] ); +" let x0_int = estimate_expr cs f.v0 in"; +" let x1 = abs_eval_v1 cs f.v1 in"; +" let s1 = Lib.itlist (fun (x,x_exp) s -> "; +" let eps = get_eps x_exp in"; +" let xi = {low = -. eps; high = eps} in"; +" (xi *$. x) +$ s) x1 zero_I in"; +" let m1 = make_stronger (abs_I s1).high in"; +" let d ="; +" let x ="; +" if Config.proof_flag then"; +" x0_int +$ {low = -.m1; high = m1}"; +" else"; +" x0_int +$ s1 in"; +(String.concat "" [" ";second_derivative_formula;" in"]); +" let b_high = 0.5 *^ (abs_I d).high in"; +" let b_high = make_stronger b_high in"; +" let m2, m2_exp = sum2_high x1 x1 in"; +" let m2 = make_stronger m2 in"; +" let m3 = b_high *^ m2 in"; +" let form_index = next_form_index() in"; +" let m3_err = mk_err_var (-1) m2_exp in"; +" let x = f.v0 in"; +" {"; +" form_index = form_index;"; +(String.concat "" [" v0 = mk_"; funcname; " f.v0;"]); +(String.concat "" [" v1 = List.map (fun (e, err) -> (mk_mul e "; formula_to_code first_derivative ;", err)) f.v1"]); +" @ [mk_float_const m3, m3_err];"; +" }"] in + + let codepre = "(*new function*)" in + let lines = addline inlines code codepre [] in + + let code = [String.concat "" [" | Op_";funcname; " -> "; funcname; "_form cs arg_form"] ] in + let codepre = " | Op_atanh -> atanh_form cs arg_form" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_taylor_form_ml_code funcname incode output= + let lines = read_file "taylor_form.ml" in + let code = incode in + let codepre = "(* Builds a Taylor form *)" in + let lines = addlinebefore lines code codepre [] in + + let code = [String.concat "" [" | Op_";funcname; " -> "; funcname; "_form cs arg_form"] ] in + let codepre = " | Op_atanh -> atanh_form cs arg_form" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + + +let write_expr_ml funcname output= + let lines = read_file "expr.ml" in + let code = [String.concat "" [" | Op_";funcname] ] in + let codepre = " | Op_atanh" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" mk_";funcname; " a = U_op (Op_"; funcname; ", a) and"] ] in + let codepre = " mk_atanh a = U_op (Op_atanh, a) and" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" | Op_"; funcname; " -> \"";funcname; "\""] ] in + let codepre = " | Op_atanh -> \"atanh\"" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_expr_mli funcname output= + let lines = read_file "expr.mli" in + let code = [String.concat "" [" | Op_";funcname] ] in + let codepre = " | Op_atanh" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" ["val mk_";funcname; " : expr -> expr"] ] in + let codepre = "val mk_atanh : expr -> expr" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_eval_ml funcname floatexpr numexpr intervalexpr output= + let lines = read_file "eval.ml" in + let code = [String.concat "" [" | Op_";funcname;" -> "; floatexpr] ] in + let codepre = " | Op_atanh -> Func.atanh x" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" | Op_";funcname;" -> "; numexpr] ] in + let codepre = " | Op_inv -> one // x" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" | Op_";funcname;" -> "; intervalexpr] ] in + let codepre = " | Op_atanh -> Func.atanh_I x" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_exprOut_ml funcname intervalexpr output= + let lines = read_file "exprOut.ml" in + let code = [String.concat "" [" | Op_";funcname;" -> fprintf fmt \""; funcname;"(%a)\" print arg"] ] in + let codepre = " | Op_neg -> fprintf fmt \"(-(%a))\" print arg" in + let lines = addline lines code codepre [] in + + let tok e = List.exists (fun x -> ((String.compare x e)==0) ) ["(";")";"+";"-";"*";"/";"^";" ";",";".";"~";"$"] in + let replace str = + let rec findx st c = let l = (String.length st) in if c==l then -1 else + if ((c==0) && (0==String.compare (String.sub st 0 1) "x") && (tok (String.sub st 1 1))) || + ((c==l-1) && (0==String.compare (String.sub st (l-1) 1) "x") && (tok (String.sub st (l-2) 1))) || + ((0 == String.compare (String.sub st c 1) "x") && (tok (String.sub st (c-1) 1))&& (tok (String.sub st (c+1) 1))) then c + else findx st (c+1) in + let c =findx str 0 in + if c == -1 then str else String.concat "" [(String.sub str 0 c); "(%a)"; (String.sub str (c+1) ((String.length str)-c-1) )] in + + let rec replaceall str = if 0==String.compare str (replace str) then str else replaceall (replace str) in + + + let code = [String.concat "" [" | Op_";funcname;" -> fprintf fmt \""; replaceall intervalexpr;"\" print arg"] ] in + let codepre = " | Op_atanh -> fprintf fmt \"atanh_I(%a)\" print arg" in + let lines = addline lines code codepre [] in + + + let code = [String.concat "" [" | Op_";funcname;" -> fprintf fmt \"("; funcname;" %a)\" print arg"] ] in + let codepre = " | Op_neg -> fprintf fmt \"(- %a)\" print arg" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" | Op_";funcname;" -> fprintf fmt \"(i"; funcname;" %a)\" print arg"] ] in + let codepre = " | Op_neg -> fprintf fmt \"(i- %a)\" print arg" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" | Op_";funcname;" -> fprintf fmt \""; funcname;"(%a)\" print arg"] ] in + let codepre = " | Op_neg -> fprintf fmt \"(-.(%a))\" print arg" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_input_lexer_ml funcname output= + let lines = read_file "input_lexer.ml" in + let code = [String.concat "" [" \"";funcname;"\", "; (String.uppercase funcname);";"] ] in + let codepre = " \"argtanh\", ATANH;" in + let lines = addline lines code codepre [] in + + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_input_parser_mly funcname output= + let lines = read_file "input_parser.mly" in + let code = [String.concat "" ["%token "; (String.uppercase funcname)] ] in + let codepre = "%token COS SIN TAN COSH SINH TANH" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" | ";(String.uppercase funcname);" LPAREN expr RPAREN { Raw_u_op (\""; funcname;"\", $3) }"] ] in + let codepre = " | ATANH LPAREN expr RPAREN { Raw_u_op (\"atanh\", $3) }" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_input_lexer_mll funcname output= + let lines = read_file "input_lexer.mll" in + let code = [String.concat "" [" \""; funcname ; "\", "; (String.uppercase funcname); ";"] ] in + let codepre = " \"argtanh\", ATANH;" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_input_parser_env_ml funcname output= + let lines = read_file "input_parser_env.ml" in + let code = [String.concat "" [" | \""; funcname ; "\" -> U_op (Op_"; funcname; ", e1)"] ] in + let codepre = " | \"tanh\" -> U_op (Op_tanh, e1)" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let rec cover_to_code str = + let binop = ["+";"-";"*";"/";"^"] in + let unfun = ["-";"abs";"inv";"sqrt";"sin";"cos";"tan";"asin";"acos";"atan"] in + let binfun=["max";"min"] in + let opname st = match st with | "+" -> "Op_add" | "-" -> "Op_sub"| "*" -> "Op_mul" | "/" -> "Op_div" | "^" -> "Op_nat_pow" in + let opval st = match st with | "+" -> 1 | "-" -> 1 | "*" -> 2 | "/" -> 2 | "^" -> 3 in + let inlist l e = List.exists (fun x -> ((String.compare x e)==0) ) l in + let rec countparen st l r= match st with + | "" -> (l,r) + | st -> if (String.compare (String.make 1 (String.get st 0) ) "(" ) ==0 then countparen (String.sub st 1 ( (String.length st)-1) ) (l+1) r + else if (String.compare (String.make 1 (String.get st 0) ) ")" ) ==0 then countparen (String.sub st 1 ( (String.length st)-1) ) l (r+1) + else countparen (String.sub st 1 ( (String.length st)-1) ) l r in + + let balance st = let (l,r) = countparen st 0 0 in (l==r) in + + let rec redundantparen st c = if c+1 == String.length st then (balance st) else let (l,r) = countparen( String.sub st 0 c ) 0 0 in + if r>=l then false else redundantparen st (c+1) in + + let lastchar st = let l = String.length st in String.sub st (l-1) 1 in + let removeparen st = if String.length st == 0 then st else if redundantparen st 1 && + ((String.compare (String.sub st 0 1) "(" ) ==0) && + ((String.compare (lastchar st) ")" )==0) then (String.sub st 1 ( (String.length st)-2) ) else st in + let rec removeallparen st = if String.compare st (removeparen st) == 0 then st else removeallparen (removeparen st) in + let rec removespace st= if (String.contains st ' ')==false then st + else let c = (String.index st ' ') in let stleft=String.sub st 0 c in let stright=String.sub st (c+1) ((String.length st)-c-1) in String.concat "" [stleft;stright] in + let rec removespaces st = if String.compare st (removespace st) == 0 then st else removeallparen (removespace st) in + let rec standard st = removeallparen (removespaces st) in + let rec find_bin_op st c m t= if ((c==((String.length st)-1)) && (m==5)) || ((String.length st)<2) then ("No","","") else + if ((c==((String.length st)-1)) && (m<5)) then t else + let stleft=String.sub st 0 c in + let stright=String.sub st (c+1) ((String.length st)-c-1) in + let op=String.make 1 (String.get st c) in + if (inlist binop op) && (balance stleft) && (balance stright) && (m>opval op) then find_bin_op st (c+1) (opval op) (op,stleft,stright) else find_bin_op st (c+1) m t in + + let rec splitexpr st c = if (c==((String.length st)-1)) || ((String.length st)<2) then ("","") else + let stleft=String.sub st 0 c in + let stright=String.sub st (c+1) ((String.length st)-c-1) in + let com=String.make 1 (String.get st c) in + if ((String.compare com ",") == 0) && (balance stleft) && (balance stright) then (stleft,stright) else splitexpr st (c+1) in + + let rec find_bin_func st = if (String.contains st '(')==false then ("No","","") else let c = (String.index st '(') in + let op = String.sub st 0 c in + let inexpr = String.sub st (c+1) ((String.length st)-c-2) in + let (lexpr,rexpr) = splitexpr inexpr 1 in + if ((String.compare lexpr "") == 0) || ((inlist binfun op)==false) then ("No","","") else (op,lexpr,rexpr) in + + let rec find_un_func st = if (String.contains st '(')==false then ("No","") else let c = (String.index st '(') in + let op = String.sub st 0 c in + let inexpr = String.sub st (c+1) ((String.length st)-c-2) in + if ((inlist unfun op)==false) then ("No","") else if (String.compare op "-") == 0 then ("neg",inexpr) else (op,inexpr) in + + + let expr = standard str in + let (op,l,r) = find_bin_op expr 1 5 ("No","","") in + if (String.compare op "No" <> 0) then String.concat "" ["Bin_op ("; (opname op) ; ","; cover_to_code l; ","; cover_to_code r; ")"] else + let (op,l,r) = find_bin_func expr in + if (String.compare op "No" <> 0) then String.concat "" ["Bin_op (Op_"; op ; ","; cover_to_code l; "," ; cover_to_code r; ")"] else + let (op,l) = find_un_func expr in + if (String.compare op "No" <> 0) then String.concat "" ["U_op (Op_"; op ; ","; cover_to_code l; ")"] else + if String.compare expr "x" == 0 then "e1" else + if String.compare expr "-x" == 0 then "U_op (Op_neg, e1)" else + if String.contains expr '.' then String.concat "" ["mk_const (Const.of_float ";expr; ")"] else + String.concat "" ["mk_const (Const.of_float ";expr; ".0)"] ;; + + + +let write_input_parser_env_ml_code funcname incode output= + let lines = read_file "input_parser_env.ml" in + let code = [String.concat "" [" | \""; funcname ; "\" -> "; cover_to_code incode] ] in + let codepre = " | \"tanh\" -> U_op (Op_tanh, e1)" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_rounding_simpl_ml funcname intervalexpr output= + let lines = read_file "rounding_simpl.ml" in + let code = [String.concat "" [" | Op_"; funcname ; " -> "; intervalexpr] ] in + let codepre = " | Op_atan -> atan_I x" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let rec get2int_input_parser strl a b = if List.length strl == 0 then (string_of_int (a+1), string_of_int (b+7)) else + let n = getfirstint (List.hd strl) in if (n>200)&&(n<500) then get2int_input_parser (List.tl strl) n b else + if (n>1000) then get2int_input_parser (List.tl strl) a n else + get2int_input_parser (List.tl strl) a b;; + +let write_input_parser_ml funcname output= + let lines = read_file "input_parser.ml" in + let code = [String.concat "" [" | "; (String.uppercase funcname)] ] in + let codepre = " | ATANH" in + let lines = addline lines code codepre [] in + + let codepre = " 0|]" in + let stnumber = let num = getfirstintmax (getlinebefore lines codepre) in string_of_int (num+1) in + let code = [String.concat "" [" ";stnumber; " (* "; (String.uppercase funcname); " *);"]] in + let lines = addlinebefore lines code codepre [] in + + let codepre = "(* Entry tasks *)" in + let (stnumber1, stnumber2) = get2int_input_parser lines 0 0 in + let code = [ +"; (fun __caml_parser_env ->"; +" let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in"; +" Obj.repr("; +(String.concat "" ["# "; stnumber1; " \"input_parser.mly\""]); +(String.concat "" [" ( Raw_u_op (\""; funcname; "\", _3) )"]); +(String.concat "" ["# "; stnumber2; " \"input_parser.ml\""]); +" : Input_parser_env.raw_expr))"] +in + let lines = addlinebefore lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + + +let () = let lines = read_file Sys.argv.(1) in + let mode = List.hd lines in + let funcname = List.nth lines 1 in + if (String.compare mode "Manual" == 0) then + let rec getcode strl s c = if c< List.length strl - 4 then getcode strl (s@[List.nth strl c]) (c+1) else s in + let l = List.length lines in + let code =getcode lines [""] 3 in + let floatexpr = List.nth lines (l-3) in + let numexpr = List.nth lines (l-2) in + let intervalexpr = List.nth lines (l-1) in + + write_taylor_form_ml_code funcname code "taylor_form.ml"; + write_expr_ml funcname "expr.ml"; + write_expr_mli funcname "expr.mli"; + write_eval_ml funcname floatexpr numexpr intervalexpr "eval.ml"; + write_rounding_simpl_ml funcname intervalexpr "rounding_simpl.ml"; + write_exprOut_ml funcname intervalexpr "exprOut.ml"; + write_input_lexer_ml funcname "input_lexer.ml"; + write_input_lexer_mll funcname "input_lexer.mll"; + write_input_parser_ml funcname "input_parser.ml"; + write_input_parser_mly funcname "input_parser.mly"; + write_input_parser_env_ml funcname "input_parser_env.ml"; + + + else if (String.compare mode "Derivative" == 0) then + let first_derivative = List.nth lines 2 in + let second_derivative = List.nth lines 3 in + let floatexpr = List.nth lines 4 in + let numexpr = List.nth lines 5 in + let intervalexpr = List.nth lines 6 in + + write_taylor_form_ml_dev funcname first_derivative second_derivative "taylor_form.ml"; + write_expr_ml funcname "expr.ml"; + write_expr_mli funcname "expr.mli"; + write_eval_ml funcname floatexpr numexpr intervalexpr "eval.ml"; + write_rounding_simpl_ml funcname intervalexpr "rounding_simpl.ml"; + write_exprOut_ml funcname intervalexpr "exprOut.ml"; + write_input_lexer_ml funcname "input_lexer.ml"; + write_input_lexer_mll funcname "input_lexer.mll"; + write_input_parser_ml funcname "input_parser.ml"; + write_input_parser_mly funcname "input_parser.mly"; + write_input_parser_env_ml funcname "input_parser_env.ml"; + + + else if (String.compare mode "Formula" == 0) then + let formula = List.nth lines 2 in + + write_expr_ml funcname "expr.ml"; + write_expr_mli funcname "expr.mli"; + write_exprOut_ml funcname "(%a)" "exprOut.ml"; + write_input_lexer_ml funcname "input_lexer.ml"; + write_input_lexer_mll funcname "input_lexer.mll"; + write_input_parser_ml funcname "input_parser.ml"; + write_input_parser_mly funcname "input_parser.mly"; + write_input_parser_env_ml_code funcname formula "input_parser_env.ml"; + + + else print_endline "No mode"; let i = Sys.command "make clean" in let j = Sys.command "make all" in print_endline (string_of_int j) +;; diff --git a/addfunctiontemp.ml b/addfunctiontemp.ml new file mode 100644 index 0000000..5fa983c --- /dev/null +++ b/addfunctiontemp.ml @@ -0,0 +1,495 @@ +open Printf + + + +let rec str2listchar st = match st with + | "" -> [] + | st -> (String.make 1 (String.get st 0) ) :: (str2listchar (String.sub st 1 ( (String.length st)-1) ) ) ;; + +let ch2int c = match c with + | "0" -> 0 + | "1" -> 1 + | "2" -> 2 + | "3" -> 3 + | "4" -> 4 + | "5" -> 5 + | "6" -> 6 + | "7" -> 7 + | "8" -> 8 + | "9" -> 9 + | c -> -1 ;; + + +let rec extint st = List.filter (fun x-> x>=0) (List.map ch2int (str2listchar st));; + +let rec getint l s = if List.length l > 0 then getint (List.tl l) (s*10+ List.hd l) else s;; + +let rec getintmax l s m = if (List.length l > 0)&&(s < m) then getintmax (List.tl l) (s*10+ List.hd l) m else s;; + +let getfirstint st = let lint = extint st in getint lint 0 ;; + +let getfirstintmax st = let lint = extint st in getintmax lint 0 300;; + +let read_file filename = + let lines = ref [] in + let chan = open_in filename in + try + while true; do + lines := input_line chan :: !lines + done; !lines + with End_of_file -> + close_in chan; + List.rev !lines ;; + +let rec addline strl1 strl2 seek s= + if (String.compare (List.hd strl1) seek)==0 then s@[seek]@strl2@(List.tl strl1) + else addline (List.tl strl1) strl2 seek (s@[List.hd strl1]);; + +let rec addlineall strl1 strl2 seek s= if (List.length strl1) ==0 then s else + if (String.compare (List.hd strl1) seek)==0 then addlineall (List.tl strl1) strl2 seek s@[seek]@strl2 + else addlineall (List.tl strl1) strl2 seek (s@[List.hd strl1]);; + +let rec addlinebefore strl1 strl2 seek s= + if (String.compare (List.hd strl1) seek)==0 then s@strl2@[seek]@(List.tl strl1) + else addlinebefore (List.tl strl1) strl2 seek (s@[List.hd strl1]);; + +let rec getlinebefore strl1 seek= + if (String.compare (List.hd (List.tl strl1)) seek)==0 then List.hd strl1 + else getlinebefore (List.tl strl1) seek;; + +let rec formula_to_code str = + let binop = ["+";"-";"*";"/";"^"] in + let unfun = ["-";"abs";"inv";"sqrt";"sin";"cos";"tan";"asin";"acos";"atan"] in + let binfun=["max";"min"] in + let opname st = match st with | "+" -> "add" | "-" -> "sub"| "*" -> "mul" | "/" -> "div" | "^" -> "nat_pow" in + let opval st = match st with | "+" -> 1 | "-" -> 1 | "*" -> 2 | "/" -> 2 | "^" -> 3 in + let inlist l e = List.exists (fun x -> ((String.compare x e)==0) ) l in + let rec countparen st l r= match st with + | "" -> (l,r) + | st -> if (String.compare (String.make 1 (String.get st 0) ) "(" ) ==0 then countparen (String.sub st 1 ( (String.length st)-1) ) (l+1) r + else if (String.compare (String.make 1 (String.get st 0) ) ")" ) ==0 then countparen (String.sub st 1 ( (String.length st)-1) ) l (r+1) + else countparen (String.sub st 1 ( (String.length st)-1) ) l r in + + let balance st = let (l,r) = countparen st 0 0 in (l==r) in + + let rec redundantparen st c = if c+1 == String.length st then (balance st) else let (l,r) = countparen( String.sub st 0 c ) 0 0 in + if r>=l then false else redundantparen st (c+1) in + + let lastchar st = let l = String.length st in String.sub st (l-1) 1 in + let removeparen st = if String.length st == 0 then st else if redundantparen st 1 && + ((String.compare (String.sub st 0 1) "(" ) ==0) && + ((String.compare (lastchar st) ")" )==0) then (String.sub st 1 ( (String.length st)-2) ) else st in + let rec removeallparen st = if String.compare st (removeparen st) == 0 then st else removeallparen (removeparen st) in + let rec removespace st= if (String.contains st ' ')==false then st + else let c = (String.index st ' ') in let stleft=String.sub st 0 c in let stright=String.sub st (c+1) ((String.length st)-c-1) in String.concat "" [stleft;stright] in + let rec removespaces st = if String.compare st (removespace st) == 0 then st else removeallparen (removespace st) in + let rec standard st = removeallparen (removespaces st) in + let rec find_bin_op st c m t= if ((c==((String.length st)-1)) && (m==5)) || ((String.length st)<2) then ("No","","") else + if ((c==((String.length st)-1)) && (m<5)) then t else + let stleft=String.sub st 0 c in + let stright=String.sub st (c+1) ((String.length st)-c-1) in + let op=String.make 1 (String.get st c) in + if (inlist binop op) && (balance stleft) && (balance stright) && (m>opval op) then find_bin_op st (c+1) (opval op) (op,stleft,stright) else find_bin_op st (c+1) m t in + + let rec splitexpr st c = if (c==((String.length st)-1)) || ((String.length st)<2) then ("","") else + let stleft=String.sub st 0 c in + let stright=String.sub st (c+1) ((String.length st)-c-1) in + let com=String.make 1 (String.get st c) in + if ((String.compare com ",") == 0) && (balance stleft) && (balance stright) then (stleft,stright) else splitexpr st (c+1) in + + let rec find_bin_func st = if (String.contains st '(')==false then ("No","","") else let c = (String.index st '(') in + let op = String.sub st 0 c in + let inexpr = String.sub st (c+1) ((String.length st)-c-2) in + let (lexpr,rexpr) = splitexpr inexpr 1 in + if ((String.compare lexpr "") == 0) || ((inlist binfun op)==false) then ("No","","") else (op,lexpr,rexpr) in + + let rec find_un_func st = if (String.contains st '(')==false then ("No","") else let c = (String.index st '(') in + let op = String.sub st 0 c in + let inexpr = String.sub st (c+1) ((String.length st)-c-2) in + if ((inlist unfun op)==false) then ("No","") else if (String.compare op "-") == 0 then ("neg",inexpr) else (op,inexpr) in + + + let expr = standard str in + let (op,l,r) = find_bin_op expr 1 5 ("No","","") in + if (String.compare op "No" <> 0) then String.concat "" ["(mk_"; (opname op) ; " "; formula_to_code l; " "; formula_to_code r; ")"] else + let (op,l,r) = find_bin_func expr in + if (String.compare op "No" <> 0) then String.concat "" ["(mk"; op ; " "; formula_to_code l; " " ; formula_to_code r; ")"] else + let (op,l) = find_un_func expr in + if (String.compare op "No" <> 0) then String.concat "" ["(mk_"; op ; " "; formula_to_code l; ")"] else + if String.compare expr "x" == 0 then "x" else + if String.compare expr "-x" == 0 then "(mk_neg x)" else + if String.contains expr '.' then String.concat "" ["(mk_const (Const.of_float ";expr; "))"] else + String.concat "" ["(mk_const (Const.of_float ";expr; ".0))"] ;; + +let write_taylor_form_ml_dev funcname first_derivative second_derivative_formula output= + let inlines = read_file "taylor_form.ml" in + let code = [ +(String.concat "" ["let "; funcname; "_form cs f ="] ); +" let x0_int = estimate_expr cs f.v0 in"; +" let x1 = abs_eval_v1 cs f.v1 in"; +" let s1 = Lib.itlist (fun (x,x_exp) s -> "; +" let eps = get_eps x_exp in"; +" let xi = {low = -. eps; high = eps} in"; +" (xi *$. x) +$ s) x1 zero_I in"; +" let m1 = make_stronger (abs_I s1).high in"; +" let d ="; +" let x ="; +" if Config.proof_flag then"; +" x0_int +$ {low = -.m1; high = m1}"; +" else"; +" x0_int +$ s1 in"; +(String.concat "" [" ";second_derivative_formula;" in"]); +" let b_high = 0.5 *^ (abs_I d).high in"; +" let b_high = make_stronger b_high in"; +" let m2, m2_exp = sum2_high x1 x1 in"; +" let m2 = make_stronger m2 in"; +" let m3 = b_high *^ m2 in"; +" let form_index = next_form_index() in"; +" let m3_err = mk_err_var (-1) m2_exp in"; +" let x = f.v0 in"; +" {"; +" form_index = form_index;"; +(String.concat "" [" v0 = mk_"; funcname; " f.v0;"]); +(String.concat "" [" v1 = List.map (fun (e, err) -> (mk_mul e "; formula_to_code first_derivative ;", err)) f.v1"]); +" @ [mk_float_const m3, m3_err];"; +" }"] in + + let codepre = "(*new function*)" in + let lines = addline inlines code codepre [] in + + let code = [String.concat "" [" | Op_";funcname; " -> "; funcname; "_form cs arg_form"] ] in + let codepre = " | Op_atanh -> atanh_form cs arg_form" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_taylor_form_ml_code funcname incode output= + let lines = read_file "taylor_form.ml" in + let code = incode in + let codepre = "(* Builds a Taylor form *)" in + let lines = addlinebefore lines code codepre [] in + + let code = [String.concat "" [" | Op_";funcname; " -> "; funcname; "_form cs arg_form"] ] in + let codepre = " | Op_atanh -> atanh_form cs arg_form" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + + +let write_expr_ml funcname output= + let lines = read_file "expr.ml" in + let code = [String.concat "" [" | Op_";funcname] ] in + let codepre = " | Op_atanh" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" mk_";funcname; " a = U_op (Op_"; funcname; ", a) and"] ] in + let codepre = " mk_atanh a = U_op (Op_atanh, a) and" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" | Op_"; funcname; " -> \"";funcname; "\""] ] in + let codepre = " | Op_atanh -> \"atanh\"" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_expr_mli funcname output= + let lines = read_file "expr.mli" in + let code = [String.concat "" [" | Op_";funcname] ] in + let codepre = " | Op_atanh" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" ["val mk_";funcname; " : expr -> expr"] ] in + let codepre = "val mk_atanh : expr -> expr" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_eval_ml funcname floatexpr numexpr intervalexpr output= + let lines = read_file "eval.ml" in + let code = [String.concat "" [" | Op_";funcname;" -> "; floatexpr] ] in + let codepre = " | Op_atanh -> Func.atanh x" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" | Op_";funcname;" -> "; numexpr] ] in + let codepre = " | Op_inv -> one // x" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" | Op_";funcname;" -> "; intervalexpr] ] in + let codepre = " | Op_atanh -> Func.atanh_I x" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_exprOut_ml funcname intervalexpr output= + let lines = read_file "exprOut.ml" in + let code = [String.concat "" [" | Op_";funcname;" -> fprintf fmt \""; funcname;"(%a)\" print arg"] ] in + let codepre = " | Op_neg -> fprintf fmt \"(-(%a))\" print arg" in + let lines = addline lines code codepre [] in + + let tok e = List.exists (fun x -> ((String.compare x e)==0) ) ["(";")";"+";"-";"*";"/";"^";" ";",";".";"~";"$"] in + let replace str = + let rec findx st c = if c==(String.length st)-1 then -1 else + if ((c==0) && (0==String.compare (String.sub st 0 1) "x") && (tok (String.sub st 1 1))) || + ((0 == String.compare (String.sub st c 1) "x") && (tok (String.sub st (c-1) 1))&& (tok (String.sub st (c+1) 1))) then c + else findx st (c+1) in + let c =findx str 0 in + if c == -1 then str else String.concat "" [(String.sub str 0 c); "(%a)"; (String.sub str (c+1) ((String.length str)-c-1) )] in + + let rec replaceall str = if 0==String.compare str (replace str) then str else replaceall (replace str) in + + + let code = [String.concat "" [" | Op_";funcname;" -> fprintf fmt \""; replaceall intervalexpr;"\" print arg"] ] in + let codepre = " | Op_atanh -> fprintf fmt \"atanh_I(%a)\" print arg" in + let lines = addline lines code codepre [] in + + + let code = [String.concat "" [" | Op_";funcname;" -> fprintf fmt \"("; funcname;" %a)\" print arg"] ] in + let codepre = " | Op_neg -> fprintf fmt \"(- %a)\" print arg" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" | Op_";funcname;" -> fprintf fmt \"(i"; funcname;" %a)\" print arg"] ] in + let codepre = " | Op_neg -> fprintf fmt \"(i- %a)\" print arg" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" | Op_";funcname;" -> fprintf fmt \""; funcname;"(%a)\" print arg"] ] in + let codepre = " | Op_neg -> fprintf fmt \"(-.(%a))\" print arg" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_input_lexer_ml funcname output= + let lines = read_file "input_lexer.ml" in + let code = [String.concat "" [" \"";funcname;"\", "; (String.uppercase funcname);";"] ] in + let codepre = " \"argtanh\", ATANH;" in + let lines = addline lines code codepre [] in + + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_input_parser_mly funcname output= + let lines = read_file "input_parser.mly" in + let code = [String.concat "" ["%token "; (String.uppercase funcname)] ] in + let codepre = "%token COS SIN TAN COSH SINH TANH" in + let lines = addline lines code codepre [] in + + let code = [String.concat "" [" | ";(String.uppercase funcname);" LPAREN expr RPAREN { Raw_u_op (\""; funcname;"\", $3) }"] ] in + let codepre = " | ATANH LPAREN expr RPAREN { Raw_u_op (\"atanh\", $3) }" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_input_lexer_mll funcname output= + let lines = read_file "input_lexer.mll" in + let code = [String.concat "" [" \""; funcname ; "\", "; (String.uppercase funcname); ";"] ] in + let codepre = " \"argtanh\", ATANH;" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_input_parser_env_ml funcname output= + let lines = read_file "input_parser_env.ml" in + let code = [String.concat "" [" | \""; funcname ; "\" -> U_op (Op_"; funcname; ", e1)"] ] in + let codepre = " | \"tanh\" -> U_op (Op_tanh, e1)" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let rec cover_to_code str = + let binop = ["+";"-";"*";"/";"^"] in + let unfun = ["-";"abs";"inv";"sqrt";"sin";"cos";"tan";"asin";"acos";"atan"] in + let binfun=["max";"min"] in + let opname st = match st with | "+" -> "Op_add" | "-" -> "Op_sub"| "*" -> "Op_mul" | "/" -> "Op_div" | "^" -> "Op_nat_pow" in + let opval st = match st with | "+" -> 1 | "-" -> 1 | "*" -> 2 | "/" -> 2 | "^" -> 3 in + let inlist l e = List.exists (fun x -> ((String.compare x e)==0) ) l in + let rec countparen st l r= match st with + | "" -> (l,r) + | st -> if (String.compare (String.make 1 (String.get st 0) ) "(" ) ==0 then countparen (String.sub st 1 ( (String.length st)-1) ) (l+1) r + else if (String.compare (String.make 1 (String.get st 0) ) ")" ) ==0 then countparen (String.sub st 1 ( (String.length st)-1) ) l (r+1) + else countparen (String.sub st 1 ( (String.length st)-1) ) l r in + + let balance st = let (l,r) = countparen st 0 0 in (l==r) in + + let rec redundantparen st c = if c+1 == String.length st then (balance st) else let (l,r) = countparen( String.sub st 0 c ) 0 0 in + if r>=l then false else redundantparen st (c+1) in + + let lastchar st = let l = String.length st in String.sub st (l-1) 1 in + let removeparen st = if String.length st == 0 then st else if redundantparen st 1 && + ((String.compare (String.sub st 0 1) "(" ) ==0) && + ((String.compare (lastchar st) ")" )==0) then (String.sub st 1 ( (String.length st)-2) ) else st in + let rec removeallparen st = if String.compare st (removeparen st) == 0 then st else removeallparen (removeparen st) in + let rec removespace st= if (String.contains st ' ')==false then st + else let c = (String.index st ' ') in let stleft=String.sub st 0 c in let stright=String.sub st (c+1) ((String.length st)-c-1) in String.concat "" [stleft;stright] in + let rec removespaces st = if String.compare st (removespace st) == 0 then st else removeallparen (removespace st) in + let rec standard st = removeallparen (removespaces st) in + let rec find_bin_op st c m t= if ((c==((String.length st)-1)) && (m==5)) || ((String.length st)<2) then ("No","","") else + if ((c==((String.length st)-1)) && (m<5)) then t else + let stleft=String.sub st 0 c in + let stright=String.sub st (c+1) ((String.length st)-c-1) in + let op=String.make 1 (String.get st c) in + if (inlist binop op) && (balance stleft) && (balance stright) && (m>opval op) then find_bin_op st (c+1) (opval op) (op,stleft,stright) else find_bin_op st (c+1) m t in + + let rec splitexpr st c = if (c==((String.length st)-1)) || ((String.length st)<2) then ("","") else + let stleft=String.sub st 0 c in + let stright=String.sub st (c+1) ((String.length st)-c-1) in + let com=String.make 1 (String.get st c) in + if ((String.compare com ",") == 0) && (balance stleft) && (balance stright) then (stleft,stright) else splitexpr st (c+1) in + + let rec find_bin_func st = if (String.contains st '(')==false then ("No","","") else let c = (String.index st '(') in + let op = String.sub st 0 c in + let inexpr = String.sub st (c+1) ((String.length st)-c-2) in + let (lexpr,rexpr) = splitexpr inexpr 1 in + if ((String.compare lexpr "") == 0) || ((inlist binfun op)==false) then ("No","","") else (op,lexpr,rexpr) in + + let rec find_un_func st = if (String.contains st '(')==false then ("No","") else let c = (String.index st '(') in + let op = String.sub st 0 c in + let inexpr = String.sub st (c+1) ((String.length st)-c-2) in + if ((inlist unfun op)==false) then ("No","") else if (String.compare op "-") == 0 then ("neg",inexpr) else (op,inexpr) in + + + let expr = standard str in + let (op,l,r) = find_bin_op expr 1 5 ("No","","") in + if (String.compare op "No" <> 0) then String.concat "" ["Bin_op ("; (opname op) ; ","; cover_to_code l; ","; cover_to_code r; ")"] else + let (op,l,r) = find_bin_func expr in + if (String.compare op "No" <> 0) then String.concat "" ["Bin_op (Op_"; op ; ","; cover_to_code l; "," ; cover_to_code r; ")"] else + let (op,l) = find_un_func expr in + if (String.compare op "No" <> 0) then String.concat "" ["U_op (Op_"; op ; ","; cover_to_code l; ")"] else + if String.compare expr "x" == 0 then "e1" else + if String.compare expr "-x" == 0 then "U_op (Op_neg, e1)" else + if String.contains expr '.' then String.concat "" ["mk_const (Const.of_float ";expr; ")"] else + String.concat "" ["mk_const (Const.of_float ";expr; ".0)"] ;; + + + +let write_input_parser_env_ml_code funcname incode output= + let lines = read_file "input_parser_env.ml" in + let code = [String.concat "" [" | \""; funcname ; "\" -> "; cover_to_code incode] ] in + let codepre = " | \"tanh\" -> U_op (Op_tanh, e1)" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let write_rounding_simpl_ml funcname intervalexpr output= + let lines = read_file "rounding_simpl.ml" in + let code = [String.concat "" [" | Op_"; funcname ; " -> "; intervalexpr] ] in + let codepre = " | Op_atan -> atan_I x" in + let lines = addline lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + +let rec get2int_input_parser strl a b = if List.length strl == 0 then (string_of_int (a+1), string_of_int (b+7)) else + let n = getfirstint (List.hd strl) in if (n>200)&&(n<500) then get2int_input_parser (List.tl strl) n b else + if (n>1000) then get2int_input_parser (List.tl strl) a n else + get2int_input_parser (List.tl strl) a b;; + +let write_input_parser_ml funcname output= + let lines = read_file "input_parser.ml" in + let code = [String.concat "" [" | "; (String.uppercase funcname)] ] in + let codepre = " | ATANH" in + let lines = addline lines code codepre [] in + + let codepre = " 0|]" in + let stnumber = let num = getfirstintmax (getlinebefore lines codepre) in string_of_int (num+1) in + let code = [String.concat "" [" ";stnumber; " (* "; (String.uppercase funcname); " *);"]] in + let lines = addlinebefore lines code codepre [] in + + let codepre = "(* Entry tasks *)" in + let (stnumber1, stnumber2) = get2int_input_parser lines 0 0 in + let code = [ +"; (fun __caml_parser_env ->"; +" let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in"; +" Obj.repr("; +(String.concat "" ["# "; stnumber1; " \"input_parser.mly\""]); +(String.concat "" [" ( Raw_u_op (\""; funcname; "\", _3) )"]); +(String.concat "" ["# "; stnumber2; " \"input_parser.ml\""]); +" : Input_parser_env.raw_expr))"] +in + let lines = addlinebefore lines code codepre [] in + + let chan = open_out output in + List.iter (fprintf chan "%s\n") lines; + close_out chan;; + + +let () = let lines = read_file "negpower3.txt" in + let mode = List.hd lines in + let funcname = List.nth lines 1 in + if (String.compare mode "Manual" == 0) then + let rec getcode strl s c = if c< List.length strl - 4 then getcode strl (s@[List.nth strl c]) (c+1) else s in + let l = List.length lines in + let code =getcode lines [""] 2 in + let floatexpr = List.nth lines (l-3) in + let numexpr = List.nth lines (l-2) in + let intervalexpr = List.nth lines (l-1) in + + write_taylor_form_ml_code funcname code "taylor_form.ml"; + write_expr_ml funcname "expr.ml"; + write_expr_mli funcname "expr.mli"; + write_eval_ml funcname floatexpr numexpr intervalexpr "eval.ml"; + write_rounding_simpl_ml funcname intervalexpr "rounding_simpl.ml"; + write_exprOut_ml funcname intervalexpr "exprOut.ml"; + write_input_lexer_ml funcname "input_lexer.ml"; + write_input_lexer_mll funcname "input_lexer.mll"; + write_input_parser_ml funcname "input_parser.ml"; + write_input_parser_mly funcname "input_parser.mly"; + write_input_parser_env_ml funcname "input_parser_env.ml"; + + + else if (String.compare mode "Derivative" == 0) then + let first_derivative = List.nth lines 2 in + let second_derivative = List.nth lines 3 in + let floatexpr = List.nth lines 4 in + let numexpr = List.nth lines 5 in + let intervalexpr = List.nth lines 6 in + + write_taylor_form_ml_dev funcname first_derivative second_derivative "taylor_form.ml"; + write_expr_ml funcname "expr.ml"; + write_expr_mli funcname "expr.mli"; + write_eval_ml funcname floatexpr numexpr intervalexpr "eval.ml"; + write_rounding_simpl_ml funcname intervalexpr "rounding_simpl.ml"; + write_exprOut_ml funcname intervalexpr "exprOut.ml"; + write_input_lexer_ml funcname "input_lexer.ml"; + write_input_lexer_mll funcname "input_lexer.mll"; + write_input_parser_ml funcname "input_parser.ml"; + write_input_parser_mly funcname "input_parser.mly"; + write_input_parser_env_ml funcname "input_parser_env.ml"; + + + else if (String.compare mode "Formula" == 0) then + let formula = List.nth lines 2 in + + write_expr_ml funcname "expr.ml"; + write_expr_mli funcname "expr.mli"; + write_exprOut_ml funcname "(%a)" "exprOut.ml"; + write_input_lexer_ml funcname "input_lexer.ml"; + write_input_lexer_mll funcname "input_lexer.mll"; + write_input_parser_ml funcname "input_parser.ml"; + write_input_parser_mly funcname "input_parser.mly"; + write_input_parser_env_ml_code funcname formula "input_parser_env.ml"; + + + else print_endline "No mode"; let i = Sys.command "make clean" in let j = Sys.command "make all" in print_endline (string_of_int j) +;; diff --git a/const.cmi b/const.cmi new file mode 100644 index 0000000..e39a78f Binary files /dev/null and b/const.cmi differ diff --git a/const.ml b/const.ml index 7875dbf..224eb23 100644 --- a/const.ml +++ b/const.ml @@ -13,76 +13,194 @@ open Num open Interval +(* +description: Type for constants, which can be a num (build-in of Ocaml) or interval +*) type t = Rat of num | Interval of interval +(* +input: num +output: t +description: coverts num to constant (t type) +*) let of_num n = Rat n +(* +input: int +output: t +description: coverts int to constant (t type) +*) let of_int i = Rat (Int i) +(* +input: float +output: t +description: cover float to constant (t type) +*) let of_float f = Rat (More_num.num_of_float f) +(* +input: interval +output: t +description: coverts interval to constant (t type) +*) let of_interval v = if v.low = v.high then of_float v.low else if v.low < v.high && neg_infinity < v.high && v.low < infinity then Interval v else failwith ("Const.of_interval: bad argument: " ^ sprintf_I "%.20e" v) +(* +input: t +output: bool +description: return true if the constrant is a num +*) let is_rat = function | Rat _ -> true | Interval _ -> false +(* +input: interval +output: bool +description: return true if the constant is an interval +*) let is_interval = function | Rat _ -> false | Interval _ -> true +(* +input: t +output: interval +description: cover a constant to an interval, if it is a num, return the interval of 2 64-bit floats that contains the num with smallest range +*) let to_interval = function | Interval v -> v | Rat n -> More_num.interval_of_num n +(* +input: t +output: foat +description: cover a constant to float, if it is an interval, return the mean of 2 bounds +*) let to_float = function | Interval v -> 0.5 *. (v.low +. v.high) | Rat n -> Num.float_of_num n +(* +input: t +output: num +description: cover a constant to num, if it is an interval, raise an error +*) let to_num = function | Rat n -> n | Interval _ -> failwith "Const.to_num: interval constant" +(* +input: t +output: int +description: cover a constant to integer +*) let to_int c = int_of_num (to_num c) +(* +input: t +output: num +description: coverts the lower bound of an interval constant to num, if the constant is num, just return it +*) let low_bound_to_num = function | Rat n -> n | Interval v -> More_num.num_of_float v.low +(* +input: t +output: num +description: coverts the upper bound of an interval constant to num, if the constant is num, just return it +*) let high_bound_to_num = function | Rat n -> n | Interval v -> More_num.num_of_float v.high +(* +input: (num->num,interval->interval), t +output: t +description: apply the unary function/operator over the constant and return the new constrant +*) let lift_u_ops (op_n, op_i) c = match c with | Rat n -> of_num (op_n n) | Interval v -> of_interval (op_i v) +(* +input: (num->num->num,interval->interval->interval), t +output: t +description: apply the binary function/operator over the constant and return the new constrant +*) let lift_bin_ops (op_n, op_i) c1 c2 = match (c1, c2) with | Rat n1, Rat n2 -> of_num (op_n n1 n2) | Interval _, _ | _, Interval _ -> of_interval (op_i (to_interval c1) (to_interval c2)) +(* +input: t +output: t +description: return the constant as the negative of the original one +*) let neg_c = lift_u_ops (minus_num, (~-$)) +(* +input: t +output: t +description: return the constant as the absolute value of the original one +*) let abs_c = lift_u_ops (abs_num, abs_I) +(* +input: t,t +output: t +description: return the constant as the minimum of the 2 constants +*) let min_c = lift_bin_ops (min_num, min_I_I) +(* +input: t,t +output: t +description: return the constant as the maximum of the 2 constants +*) let max_c = lift_bin_ops (max_num, max_I_I) +(* +input: t,t +output: t +description: return the constant as the addition of the 2 constants +*) let add_c = lift_bin_ops (add_num, (+$)) +(* +input: t,t +output: t +description: return the constant as the subtraction of the 2 constants +*) let sub_c = lift_bin_ops (sub_num, (-$)) +(* +input: t,t +output: t +description: return the constant as the multiplication of the 2 constants +*) let mul_c = lift_bin_ops (mult_num, ( *$ )) +(* +input: t,t +output: t +description: return the constant as the division of the 2 constants +*) let div_c = lift_bin_ops (div_num, (/$)) +(* +input: t, t +output: bool +description: return true if the 2 constants are the same +*) let eq_c c1 c2 = match (c1, c2) with | Rat n1, Rat n2 -> n1 =/ n2 diff --git a/default.cfg b/default.cfg index 4bc985f..c6a7790 100644 --- a/default.cfg +++ b/default.cfg @@ -242,4 +242,4 @@ nlopt-lib = -lnlopt -lm # Extra options #************************** -develop = false \ No newline at end of file +develop = false diff --git a/eval.ml b/eval.ml index 21646d1..745b685 100644 --- a/eval.ml +++ b/eval.ml @@ -18,6 +18,11 @@ open Expr (* Computes a floating-point value of an expression *) (* vars : string -> float is a function which associates floating-point values with variable names *) +(* +input: string->float +output: float +description: evaluate an expression and return a float value, the first argument is a function which return the value (float) of a variable's name +*) let eval_float_expr vars = let rec eval = function | Const c -> Const.to_float c @@ -74,12 +79,22 @@ let eval_float_expr vars = in eval +(* +input: expr +output: float +description: estimate a constant expression and return a float value +*) let eval_float_const_expr = eval_float_expr (fun v -> failwith ("eval_float_const_expr: Var " ^ v)) (* Computes a rational value of an expression *) (* vars : string -> num is a function which associates rational values with variable names *) +(* +input: string->num +output: num +description: estimate an expression and return a float value, the first argument is a function which return the value (num) of a variable's name +*) let eval_num_expr vars = let one = Int 1 in let rec eval = function @@ -125,12 +140,22 @@ let eval_num_expr vars = in eval +(* +input: expr +output: num +description: estimate a constant expression and return a num value +*) let eval_num_const_expr = eval_num_expr (fun v -> failwith ("eval_num_const_expr: Var " ^ v)) (* Computes an interval value of an expression *) (* vars : string -> interval is a function which associates inteval values with variable names *) +(* +input: string->interval +output: interval +description: estimate an expression and return a float value, the first argument is a function which return the value (interval) of a variable's name +*) let eval_interval_expr vars = let rec eval = function | Const c -> Const.to_interval c @@ -191,10 +216,19 @@ let eval_interval_expr vars = in eval +(* +input: expr +output: interval +description: estimate a constant expression and return an interval value +*) let eval_interval_const_expr = eval_interval_expr (fun v -> failwith ("eval_interval_const_expr: Var " ^ v)) - +(* +input: expr +output: Const.t +description: estimate a constant expression and return a constant +*) let eval_const_expr e = Log.report `Debug "eval_const_expr: %s" (ExprOut.Info.print_str e); let n = eval_num_const_expr e in diff --git a/expr.ml b/expr.ml index a958172..21f356b 100644 --- a/expr.ml +++ b/expr.ml @@ -11,6 +11,9 @@ (* -------------------------------------------------------------------------- *) (* Operations *) +(* +description: general type of unary operators and single variable functions +*) type u_op_type = | Op_neg | Op_abs @@ -30,8 +33,12 @@ type u_op_type = | Op_asinh | Op_acosh | Op_atanh + | Op_relu | Op_floor_power2 +(* +description: general type of binary operators and double variable functions +*) type bin_op_type = | Op_max | Op_min @@ -43,11 +50,17 @@ type bin_op_type = | Op_sub2 | Op_abs_err +(* +description: type of general multivariate operators and functions +*) type gen_op_type = | Op_fma | Op_ulp (* Expression *) +(* +description: type of expression +*) type expr = | Const of Const.t | Var of string @@ -56,11 +69,21 @@ type expr = | Bin_op of bin_op_type * expr * expr | Gen_op of gen_op_type * expr list +(* +input: no +output: no +description: type of formula +*) type formula = | Le of expr * expr | Lt of expr * expr | Eq of expr * expr +(* +input: +output: +description: +*) type constraints = { var_interval : string -> Interval.interval; var_rat_bounds : string -> Num.num * Num.num; @@ -68,6 +91,11 @@ type constraints = { constraints : formula list; } +(* +input: Const.t +output: expr +description: make an expression from a constant, one or two expression wrt to the meaning of the output expression +*) let mk_const c = Const c and mk_var v = Var v and mk_rounding rnd a = Rounding (rnd, a) and @@ -89,6 +117,7 @@ let mk_const c = Const c and mk_asinh a = U_op (Op_asinh, a) and mk_acosh a = U_op (Op_acosh, a) and mk_atanh a = U_op (Op_atanh, a) and + mk_relu a = U_op (Op_relu, a) and mk_max a b = Bin_op (Op_max, a, b) and mk_min a b = Bin_op (Op_min, a, b) and mk_add a b = Bin_op (Op_add, a, b) and @@ -101,18 +130,38 @@ let mk_const c = Const c and mk_abs_err t x = Bin_op (Op_abs_err, t, x) and mk_floor_power2 a = U_op (Op_floor_power2, a) +(* +input: +output: +description: +*) let mk_ulp (prec, e_min) x = let p = mk_const (Const.of_int prec) in let e = mk_const (Const.of_int e_min) in Gen_op (Op_ulp, [p; e; x]) +(* +input: variable of type int/num/float/interval +output: expr +description: make a constant expression with the given type number +*) let mk_int_const i = mk_const (Const.of_int i) and mk_num_const n = mk_const (Const.of_num n) and mk_float_const f = mk_const (Const.of_float f) and mk_interval_const v = mk_const (Const.of_interval v) +(* +input: +output: +description: +*) let mk_floor_sub2 a b = mk_floor_power2 (mk_sub2 a b) +(* +input: +output: +description: some interger constant expr +*) let const_0 = mk_int_const 0 and const_1 = mk_int_const 1 and const_2 = mk_int_const 2 and @@ -120,6 +169,11 @@ let const_0 = mk_int_const 0 and const_4 = mk_int_const 4 and const_5 = mk_int_const 5 +(* +input: u_op_type +output: string +description: return the name of the operator/function from u_op_type +*) let u_op_name = function | Op_neg -> "neg" | Op_abs -> "abs" @@ -139,8 +193,14 @@ let u_op_name = function | Op_asinh -> "asinh" | Op_acosh -> "acosh" | Op_atanh -> "atanh" + | Op_relu -> "relu" | Op_floor_power2 -> "floor_power2" +(* +input: bin_op_type +output: string +description: return the name of the operator/function from bin_op_type +*) let bin_op_name = function | Op_max -> "max" | Op_min -> "min" @@ -152,10 +212,20 @@ let bin_op_name = function | Op_sub2 -> "sub2" | Op_abs_err -> "abs_err" +(* +input: gen_op_type +output: string +description: return the name of the operator/function from gen_op_type +*) let gen_op_name = function | Op_fma -> "fma" | Op_ulp -> "ulp" +(* +input: expr,expr +output: bool +description: return true if the two expressions are the same +*) let rec eq_expr e1 e2 = match (e1, e2) with | (Const c1, Const c2) -> Const.eq_c c1 c2 @@ -170,6 +240,11 @@ let rec eq_expr e1 e2 = Lib.itlist (fun (a1, a2) x -> eq_expr a1 a2 && x) (Lib.zip as1 as2) true | _ -> false +(* +input: expr +output: expr list +description: return the list of variables in an expression +*) let rec vars_in_expr e = match e with | Var v -> [v] diff --git a/expr.mli b/expr.mli index 907a196..947b647 100644 --- a/expr.mli +++ b/expr.mli @@ -29,6 +29,7 @@ type u_op_type = | Op_asinh | Op_acosh | Op_atanh + | Op_relu | Op_floor_power2 type bin_op_type = @@ -88,6 +89,7 @@ val mk_tanh : expr -> expr val mk_asinh : expr -> expr val mk_acosh : expr -> expr val mk_atanh : expr -> expr +val mk_relu : expr -> expr val mk_max : expr -> expr -> expr val mk_min : expr -> expr -> expr diff --git a/exprOut.ml b/exprOut.ml index d8d154c..aedc26a 100644 --- a/exprOut.ml +++ b/exprOut.ml @@ -80,6 +80,7 @@ module InfoPrinter : PrinterType = struct | U_op (op, arg) -> begin match op with | Op_neg -> fprintf fmt "(-(%a))" print arg + | Op_relu -> fprintf fmt "relu(%a)" print arg | Op_abs -> fprintf fmt "abs(%a)" print arg | Op_inv -> fprintf fmt "inv(%a)" print arg | Op_sqrt -> fprintf fmt "sqrt(%a)" print arg @@ -156,6 +157,7 @@ module OCamlIntervalPrinter : PrinterType = struct | Op_asinh -> fprintf fmt "asinh_I(%a)" print arg | Op_acosh -> fprintf fmt "acosh_I(%a)" print arg | Op_atanh -> fprintf fmt "atanh_I(%a)" print arg + | Op_relu -> fprintf fmt "(%a)" print arg | Op_floor_power2 -> fprintf fmt "floor_power2_I(%a)" print arg end | Bin_op (op, arg1, arg2) -> begin @@ -209,6 +211,7 @@ module FPCorePrinter : PrinterType = struct | U_op (op, arg) -> begin match op with | Op_neg -> fprintf fmt "(- %a)" print arg + | Op_relu -> fprintf fmt "(relu %a)" print arg | Op_abs -> fprintf fmt "(fabs %a)" print arg | Op_inv -> fprintf fmt "(/ 1 %a)" print arg | Op_sqrt -> fprintf fmt "(sqrt %a)" print arg @@ -271,6 +274,7 @@ module RacketIntervalPrinter : PrinterType = struct | U_op (op, arg) -> begin match op with | Op_neg -> fprintf fmt "(i- %a)" print arg + | Op_relu -> fprintf fmt "(irelu %a)" print arg | Op_abs -> fprintf fmt "(iabs %a)" print arg | Op_inv -> fprintf fmt "(i/ %a)" print arg | Op_sqrt -> fprintf fmt "(isqrt %a)" print arg @@ -381,6 +385,7 @@ module OCamlFloatPrinter : PrinterType = struct | U_op (op, arg) -> begin match op with | Op_neg -> fprintf fmt "(-.(%a))" print arg + | Op_relu -> fprintf fmt "relu(%a)" print arg | Op_abs -> fprintf fmt "abs_float(%a)" print arg | Op_inv -> fprintf fmt "(1. /. %a)" print arg | Op_sqrt -> fprintf fmt "sqrt(%a)" print arg diff --git a/fptaylor b/fptaylor new file mode 100644 index 0000000..b78cc63 Binary files /dev/null and b/fptaylor differ diff --git a/func1.txt b/func1.txt new file mode 100644 index 0000000..967b997 --- /dev/null +++ b/func1.txt @@ -0,0 +1,4 @@ +Formula +func1 +2*(sin(x)+cos(x)) + diff --git a/functionsample b/functionsample new file mode 100644 index 0000000..150626f --- /dev/null +++ b/functionsample @@ -0,0 +1,23 @@ +Manual +relu +{ +let relu_form cs = let c=mk_const (Const.of_int 0) in let zeroexpr = const_form c in max_form cs zeroexpr +} +max (float_of_int 0) x +max_num (Int 0) x +max_I_I {low=0.0;high=0.0} x + +Derivative +negpower_3 +-3*x*x +-6.0 *.$ x +-.x*.x*.x +minus_num (x*/x*/x) +pow_I_i ~-$x 3 + + +Formula +func1 +2*(sin(x)+cos(x)) + + diff --git a/functiontest.txt b/functiontest.txt new file mode 100644 index 0000000..ee10574 --- /dev/null +++ b/functiontest.txt @@ -0,0 +1,13 @@ +Variables + + +real x in [1000,1009]; + +Expressions +exp0 rnd32 = func1(x), +exp1 rnd32 = 2*(sin(x)+cos(x)), +exp2 rnd32 = negpower_3(x), +exp3 rnd32 = -x*x*x, +exp4 rnd32 = relu(x), +exp5 rnd32 = max(0,x), + diff --git a/input_lexer.ml b/input_lexer.ml new file mode 100644 index 0000000..4674215 --- /dev/null +++ b/input_lexer.ml @@ -0,0 +1,543 @@ +# 1 "input_lexer.mll" + + open Input_parser + open Lexing + + let incr_lineno lexbuf = + let pos = lexbuf.lex_curr_p in + lexbuf.lex_curr_p <- { pos with + pos_lnum = pos.pos_lnum + 1; + pos_bol = pos.pos_cnum; + } + + let resolve_id = + let table = Hashtbl.create 100 in + let () = List.iter (fun (k, v) -> Hashtbl.add table k v) [ + "Constants", CONSTANTS; + "constants", CONSTANTS; + "Variables", VARIABLES; + "variables", VARIABLES; + "Definitions", DEFINITIONS; + "definitions", DEFINITIONS; + "Constraints", CONSTRAINTS; + "constraints", CONSTRAINTS; + "Expressions", EXPRESSIONS; + "expressions", EXPRESSIONS; + "IN", IN; + "in", IN; + "int", INT; + "real", REAL; + "float16", FLOAT(16); + "float32", FLOAT(32); + "float64", FLOAT(64); + "float128", FLOAT(128); + "rnd", RND; + "no_rnd", NO_RND; + "rnd16_ne", RND_PAR(16, "ne"); + "rnd16", RND_PAR(16, "ne"); + "rnd16_0", RND_PAR(16, "zero"); + "rnd16_down", RND_PAR(16, "down"); + "rnd16_up", RND_PAR(16, "up"); + "rnd32_ne", RND_PAR(32, "ne"); + "rnd32", RND_PAR(32, "ne"); + "rnd32_0", RND_PAR(32, "zero"); + "rnd32_down", RND_PAR(32, "down"); + "rnd32_up", RND_PAR(32, "up"); + "rnd64_ne", RND_PAR(64, "ne"); + "rnd64", RND_PAR(64, "ne"); + "rnd64_0", RND_PAR(64, "zero"); + "rnd64_down", RND_PAR(64, "down"); + "rnd64_up", RND_PAR(64, "up"); + "rnd128_ne", RND_PAR(128, "ne"); + "rnd128", RND_PAR(128, "ne"); + "rnd128_0", RND_PAR(128, "zero"); + "rnd128_down", RND_PAR(128, "down"); + "rnd128_up", RND_PAR(128, "up"); + "inv", INV; + "abs", ABS; + "fma", FMA; + "sqrt", SQRT; + "min", MIN; + "max", MAX; + "exp", EXP; + "log", LOG; + "cos", COS; + "sin", SIN; + "tan", TAN; + "cosh", COSH; + "sinh", SINH; + "tanh", TANH; + "acos", ACOS; + "asin", ASIN; + "atan", ATAN; + "atan2", ATAN2; + "arccos", ACOS; + "arcsin", ASIN; + "arctan", ATAN; + "acosh", ACOSH; + "asinh", ASINH; + "atanh", ATANH; + "arsinh", ASINH; + "arcosh", ACOSH; + "artanh", ATANH; + "arcsinh", ASINH; + "arccosh", ACOSH; + "arctanh", ATANH; + "argsinh", ASINH; + "argcosh", ACOSH; + "argtanh", ATANH; + "relu", RELU; + "sub2", SUB2; + "floor_power2", FLOOR_POWER2; + ] in + fun str -> + try Hashtbl.find table str + with Not_found -> ID str + + +# 99 "input_lexer.ml" +let __ocaml_lex_tables = { + Lexing.lex_base = + "\000\000\227\255\228\255\088\000\025\000\002\000\003\000\236\255\ + \237\255\239\255\240\255\045\000\242\255\243\255\244\255\245\255\ + \246\255\247\255\248\255\249\255\250\255\165\000\178\000\254\255\ + \255\255\049\000\001\000\252\255\253\255\193\000\251\000\011\001\ + \036\001\074\001\112\001\150\001\188\001\215\001\227\001\253\001\ + \009\002\074\002\112\002\150\002\001\000\231\255\235\255\234\255\ + \230\255"; + Lexing.lex_backtrk = + "\255\255\255\255\255\255\026\000\027\000\023\000\022\000\255\255\ + \255\255\255\255\255\255\014\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\004\000\004\000\255\255\ + \255\255\017\000\000\000\255\255\255\255\255\255\004\000\255\255\ + \004\000\004\000\003\000\002\000\004\000\255\255\004\000\004\000\ + \003\000\002\000\004\000\004\000\255\255\255\255\255\255\255\255\ + \255\255"; + Lexing.lex_default = + "\002\000\000\000\000\000\255\255\255\255\255\255\255\255\000\000\ + \000\000\000\000\000\000\255\255\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\000\ + \000\000\255\255\026\000\000\000\000\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\000\000\000\000\000\000\ + \000\000"; + Lexing.lex_trans = + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\024\000\023\000\255\255\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \024\000\000\000\000\000\000\000\003\000\004\000\000\000\000\000\ + \020\000\019\000\009\000\011\000\012\000\010\000\045\000\025\000\ + \022\000\021\000\021\000\021\000\021\000\021\000\021\000\021\000\ + \021\000\021\000\013\000\014\000\006\000\007\000\005\000\047\000\ + \046\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\018\000\044\000\017\000\008\000\003\000\ + \026\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\016\000\003\000\015\000\048\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\000\000\000\000\000\000\000\000\003\000\ + \000\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\030\000\000\000\021\000\021\000\021\000\ + \021\000\021\000\021\000\021\000\021\000\021\000\021\000\000\000\ + \030\000\000\000\021\000\021\000\021\000\021\000\021\000\021\000\ + \021\000\021\000\021\000\021\000\037\000\000\000\037\000\000\000\ + \000\000\039\000\039\000\039\000\039\000\039\000\039\000\039\000\ + \039\000\039\000\039\000\000\000\000\000\000\000\000\000\000\000\ + \001\000\255\255\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\027\000\029\000\028\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\029\000\027\000\029\000\ + \028\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\029\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\031\000\030\000\030\000\030\000\030\000\030\000\ + \030\000\030\000\030\000\030\000\030\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\032\000\032\000\032\000\032\000\032\000\ + \032\000\032\000\032\000\032\000\032\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\032\000\032\000\032\000\032\000\ + \032\000\032\000\033\000\000\000\032\000\032\000\032\000\032\000\ + \032\000\032\000\032\000\032\000\032\000\032\000\000\000\027\000\ + \029\000\028\000\000\000\000\000\000\000\032\000\032\000\032\000\ + \032\000\032\000\032\000\029\000\032\000\032\000\032\000\032\000\ + \032\000\032\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\000\000\032\000\032\000\032\000\ + \034\000\036\000\035\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\000\000\000\000\000\000\029\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\033\000\000\000\ + \032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\ + \032\000\032\000\000\000\033\000\033\000\033\000\040\000\042\000\ + \041\000\032\000\032\000\032\000\032\000\032\000\032\000\000\000\ + \000\000\000\000\029\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\033\000\000\000\032\000\032\000\ + \032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\ + \000\000\032\000\032\000\032\000\034\000\036\000\035\000\032\000\ + \032\000\032\000\032\000\032\000\032\000\000\000\000\000\000\000\ + \029\000\000\000\000\000\000\000\000\000\000\000\000\000\037\000\ + \000\000\037\000\033\000\000\000\038\000\038\000\038\000\038\000\ + \038\000\038\000\038\000\038\000\038\000\038\000\000\000\032\000\ + \032\000\032\000\034\000\036\000\035\000\032\000\032\000\032\000\ + \032\000\032\000\032\000\000\000\000\000\000\000\029\000\039\000\ + \039\000\039\000\039\000\039\000\039\000\039\000\039\000\039\000\ + \039\000\033\000\000\000\038\000\038\000\038\000\038\000\038\000\ + \038\000\038\000\038\000\038\000\038\000\032\000\032\000\032\000\ + \034\000\036\000\035\000\000\000\032\000\032\000\032\000\032\000\ + \032\000\032\000\000\000\000\000\029\000\039\000\039\000\039\000\ + \039\000\039\000\039\000\039\000\039\000\039\000\039\000\000\000\ + \000\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\000\000\032\000\032\000\032\000\034\000\ + \036\000\035\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \000\000\000\000\000\000\029\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\027\000\000\000\028\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\033\000\033\000\033\000\040\000\042\000\041\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\029\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\037\000\000\000\037\000\000\000\000\000\ + \043\000\043\000\043\000\043\000\043\000\043\000\043\000\043\000\ + \043\000\043\000\000\000\033\000\033\000\033\000\040\000\042\000\ + \041\000\033\000\033\000\033\000\033\000\033\000\033\000\000\000\ + \000\000\000\000\029\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\043\000\043\000\ + \043\000\043\000\043\000\043\000\043\000\043\000\043\000\043\000\ + \000\000\033\000\033\000\033\000\040\000\042\000\041\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\000\000\000\000\000\000\ + \029\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\033\000\ + \033\000\033\000\040\000\042\000\041\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\029\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000"; + Lexing.lex_check = + "\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\000\000\000\000\026\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \000\000\255\255\255\255\255\255\000\000\000\000\255\255\255\255\ + \000\000\000\000\000\000\000\000\000\000\000\000\044\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\005\000\ + \006\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\011\000\000\000\000\000\000\000\ + \025\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\003\000\000\000\004\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\255\255\255\255\255\255\255\255\003\000\ + \255\255\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\ + \003\000\003\000\003\000\021\000\255\255\021\000\021\000\021\000\ + \021\000\021\000\021\000\021\000\021\000\021\000\021\000\255\255\ + \022\000\255\255\022\000\022\000\022\000\022\000\022\000\022\000\ + \022\000\022\000\022\000\022\000\029\000\255\255\029\000\255\255\ + \255\255\029\000\029\000\029\000\029\000\029\000\029\000\029\000\ + \029\000\029\000\029\000\255\255\255\255\255\255\255\255\255\255\ + \000\000\026\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\021\000\021\000\021\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\021\000\022\000\022\000\ + \022\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\022\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\022\000\030\000\030\000\030\000\030\000\030\000\ + \030\000\030\000\030\000\030\000\030\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\031\000\031\000\031\000\031\000\ + \031\000\031\000\032\000\255\255\032\000\032\000\032\000\032\000\ + \032\000\032\000\032\000\032\000\032\000\032\000\255\255\030\000\ + \030\000\030\000\255\255\255\255\255\255\032\000\032\000\032\000\ + \032\000\032\000\032\000\030\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\255\255\032\000\032\000\032\000\ + \032\000\032\000\032\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\255\255\255\255\255\255\032\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\034\000\255\255\ + \034\000\034\000\034\000\034\000\034\000\034\000\034\000\034\000\ + \034\000\034\000\255\255\033\000\033\000\033\000\033\000\033\000\ + \033\000\034\000\034\000\034\000\034\000\034\000\034\000\255\255\ + \255\255\255\255\033\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\035\000\255\255\035\000\035\000\ + \035\000\035\000\035\000\035\000\035\000\035\000\035\000\035\000\ + \255\255\034\000\034\000\034\000\034\000\034\000\034\000\035\000\ + \035\000\035\000\035\000\035\000\035\000\255\255\255\255\255\255\ + \034\000\255\255\255\255\255\255\255\255\255\255\255\255\036\000\ + \255\255\036\000\036\000\255\255\036\000\036\000\036\000\036\000\ + \036\000\036\000\036\000\036\000\036\000\036\000\255\255\035\000\ + \035\000\035\000\035\000\035\000\035\000\036\000\036\000\036\000\ + \036\000\036\000\036\000\255\255\255\255\255\255\035\000\037\000\ + \037\000\037\000\037\000\037\000\037\000\037\000\037\000\037\000\ + \037\000\038\000\255\255\038\000\038\000\038\000\038\000\038\000\ + \038\000\038\000\038\000\038\000\038\000\036\000\036\000\036\000\ + \036\000\036\000\036\000\255\255\038\000\038\000\038\000\038\000\ + \038\000\038\000\255\255\255\255\036\000\039\000\039\000\039\000\ + \039\000\039\000\039\000\039\000\039\000\039\000\039\000\255\255\ + \255\255\040\000\040\000\040\000\040\000\040\000\040\000\040\000\ + \040\000\040\000\040\000\255\255\038\000\038\000\038\000\038\000\ + \038\000\038\000\040\000\040\000\040\000\040\000\040\000\040\000\ + \255\255\255\255\255\255\038\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\039\000\255\255\039\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\040\000\040\000\040\000\040\000\040\000\040\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\040\000\041\000\041\000\041\000\041\000\041\000\041\000\ + \041\000\041\000\041\000\041\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\041\000\041\000\041\000\041\000\041\000\ + \041\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\042\000\255\255\042\000\255\255\255\255\ + \042\000\042\000\042\000\042\000\042\000\042\000\042\000\042\000\ + \042\000\042\000\255\255\041\000\041\000\041\000\041\000\041\000\ + \041\000\042\000\042\000\042\000\042\000\042\000\042\000\255\255\ + \255\255\255\255\041\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\043\000\043\000\ + \043\000\043\000\043\000\043\000\043\000\043\000\043\000\043\000\ + \255\255\042\000\042\000\042\000\042\000\042\000\042\000\043\000\ + \043\000\043\000\043\000\043\000\043\000\255\255\255\255\255\255\ + \042\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\043\000\ + \043\000\043\000\043\000\043\000\043\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\043\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255"; + Lexing.lex_base_code = + ""; + Lexing.lex_backtrk_code = + ""; + Lexing.lex_default_code = + ""; + Lexing.lex_trans_code = + ""; + Lexing.lex_check_code = + ""; + Lexing.lex_code = + ""; +} + +let rec token lexbuf = + __ocaml_lex_token_rec lexbuf 0 +and __ocaml_lex_token_rec lexbuf __ocaml_lex_state = + match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with + | 0 -> +# 110 "input_lexer.mll" + ( token lexbuf ) +# 378 "input_lexer.ml" + + | 1 -> +# 111 "input_lexer.mll" + ( incr_lineno lexbuf; token lexbuf ) +# 383 "input_lexer.ml" + + | 2 -> +let +# 112 "input_lexer.mll" + str +# 389 "input_lexer.ml" += Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos lexbuf.Lexing.lex_curr_pos in +# 112 "input_lexer.mll" + ( SINGLE_NUMERAL (String.sub str 0 (String.length str - 1)) ) +# 393 "input_lexer.ml" + + | 3 -> +let +# 113 "input_lexer.mll" + str +# 399 "input_lexer.ml" += Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos lexbuf.Lexing.lex_curr_pos in +# 113 "input_lexer.mll" + ( DOUBLE_NUMERAL (String.sub str 0 (String.length str - 1)) ) +# 403 "input_lexer.ml" + + | 4 -> +let +# 114 "input_lexer.mll" + str +# 409 "input_lexer.ml" += Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos lexbuf.Lexing.lex_curr_pos in +# 114 "input_lexer.mll" + ( NUMBER str ) +# 413 "input_lexer.ml" + + | 5 -> +# 115 "input_lexer.mll" + ( LPAREN ) +# 418 "input_lexer.ml" + + | 6 -> +# 116 "input_lexer.mll" + ( RPAREN ) +# 423 "input_lexer.ml" + + | 7 -> +# 117 "input_lexer.mll" + ( LBRACKET ) +# 428 "input_lexer.ml" + + | 8 -> +# 118 "input_lexer.mll" + ( RBRACKET ) +# 433 "input_lexer.ml" + + | 9 -> +# 119 "input_lexer.mll" + ( LBRACE ) +# 438 "input_lexer.ml" + + | 10 -> +# 120 "input_lexer.mll" + ( RBRACE ) +# 443 "input_lexer.ml" + + | 11 -> +# 121 "input_lexer.mll" + ( SEMICOLON ) +# 448 "input_lexer.ml" + + | 12 -> +# 122 "input_lexer.mll" + ( COLON ) +# 453 "input_lexer.ml" + + | 13 -> +# 123 "input_lexer.mll" + ( COMMA ) +# 458 "input_lexer.ml" + + | 14 -> +# 124 "input_lexer.mll" + ( PLUS ) +# 463 "input_lexer.ml" + + | 15 -> +# 125 "input_lexer.mll" + ( MINUS ) +# 468 "input_lexer.ml" + + | 16 -> +# 126 "input_lexer.mll" + ( MULT ) +# 473 "input_lexer.ml" + + | 17 -> +# 127 "input_lexer.mll" + ( DIVIDE ) +# 478 "input_lexer.ml" + + | 18 -> +# 128 "input_lexer.mll" + ( POW ) +# 483 "input_lexer.ml" + + | 19 -> +# 129 "input_lexer.mll" + ( EQ ) +# 488 "input_lexer.ml" + + | 20 -> +# 130 "input_lexer.mll" + ( LE ) +# 493 "input_lexer.ml" + + | 21 -> +# 131 "input_lexer.mll" + ( GE ) +# 498 "input_lexer.ml" + + | 22 -> +# 132 "input_lexer.mll" + ( LT ) +# 503 "input_lexer.ml" + + | 23 -> +# 133 "input_lexer.mll" + ( GT ) +# 508 "input_lexer.ml" + + | 24 -> +# 134 "input_lexer.mll" + ( PLUS_MINUS ) +# 513 "input_lexer.ml" + + | 25 -> +# 135 "input_lexer.mll" + ( E_CONST ) +# 518 "input_lexer.ml" + + | 26 -> +let +# 136 "input_lexer.mll" + str +# 524 "input_lexer.ml" += Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos lexbuf.Lexing.lex_curr_pos in +# 136 "input_lexer.mll" + ( resolve_id str ) +# 528 "input_lexer.ml" + + | 27 -> +# 137 "input_lexer.mll" + ( token lexbuf ) +# 533 "input_lexer.ml" + + | 28 -> +# 138 "input_lexer.mll" + ( EOF ) +# 538 "input_lexer.ml" + + | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf; + __ocaml_lex_token_rec lexbuf __ocaml_lex_state + +;; + diff --git a/input_lexer.mll b/input_lexer.mll index 6c5ba83..c9ac56e 100644 --- a/input_lexer.mll +++ b/input_lexer.mll @@ -85,6 +85,7 @@ "argsinh", ASINH; "argcosh", ACOSH; "argtanh", ATANH; + "relu", RELU; "sub2", SUB2; "floor_power2", FLOOR_POWER2; ] in diff --git a/input_parser.ml b/input_parser.ml new file mode 100644 index 0000000..9bb7d22 --- /dev/null +++ b/input_parser.ml @@ -0,0 +1,1268 @@ +type token = + | EOF + | COLON + | SEMICOLON + | COMMA + | LPAREN + | RPAREN + | LBRACKET + | RBRACKET + | LBRACE + | RBRACE + | PLUS + | MINUS + | MULT + | DIVIDE + | POW + | EQ + | LE + | GE + | LT + | GT + | IN + | PLUS_MINUS + | ID of (string) + | NUMBER of (string) + | SINGLE_NUMERAL of (string) + | DOUBLE_NUMERAL of (string) + | CONSTANTS + | VARIABLES + | DEFINITIONS + | CONSTRAINTS + | EXPRESSIONS + | INT + | REAL + | FLOAT of (int) + | RND_PAR of (int * string) + | RND + | NO_RND + | E_CONST + | ABS + | INV + | SQRT + | FMA + | MIN + | MAX + | EXP + | LOG + | COS + | SIN + | TAN + | COSH + | SINH + | TANH + | RELU + | ACOS + | ASIN + | ATAN + | ACOSH + | ASINH + | ATANH + | ATAN2 + | SUB2 + | FLOOR_POWER2 + +open Parsing;; +let _ = parse_error;; +# 2 "input_parser.mly" + open Input_parser_env + open Rounding + exception TODO +# 72 "input_parser.ml" +let yytransl_const = [| + 0 (* EOF *); + 257 (* COLON *); + 258 (* SEMICOLON *); + 259 (* COMMA *); + 260 (* LPAREN *); + 261 (* RPAREN *); + 262 (* LBRACKET *); + 263 (* RBRACKET *); + 264 (* LBRACE *); + 265 (* RBRACE *); + 266 (* PLUS *); + 267 (* MINUS *); + 268 (* MULT *); + 269 (* DIVIDE *); + 270 (* POW *); + 271 (* EQ *); + 272 (* LE *); + 273 (* GE *); + 274 (* LT *); + 275 (* GT *); + 276 (* IN *); + 277 (* PLUS_MINUS *); + 282 (* CONSTANTS *); + 283 (* VARIABLES *); + 284 (* DEFINITIONS *); + 285 (* CONSTRAINTS *); + 286 (* EXPRESSIONS *); + 287 (* INT *); + 288 (* REAL *); + 291 (* RND *); + 292 (* NO_RND *); + 293 (* E_CONST *); + 294 (* ABS *); + 295 (* INV *); + 296 (* SQRT *); + 297 (* FMA *); + 298 (* MIN *); + 299 (* MAX *); + 300 (* EXP *); + 301 (* LOG *); + 302 (* COS *); + 303 (* SIN *); + 304 (* TAN *); + 305 (* COSH *); + 306 (* SINH *); + 307 (* TANH *); + 308 (* RELU *); + 309 (* ACOS *); + 310 (* ASIN *); + 311 (* ATAN *); + 312 (* ACOSH *); + 313 (* ASINH *); + 314 (* ATANH *); + 315 (* ATAN2 *); + 316 (* SUB2 *); + 317 (* FLOOR_POWER2 *); + 0|] + +let yytransl_block = [| + 278 (* ID *); + 279 (* NUMBER *); + 280 (* SINGLE_NUMERAL *); + 281 (* DOUBLE_NUMERAL *); + 289 (* FLOAT *); + 290 (* RND_PAR *); + 0|] + +let yylhs = "\255\255\ +\001\000\001\000\006\000\006\000\005\000\007\000\007\000\008\000\ +\008\000\008\000\008\000\008\000\014\000\014\000\009\000\009\000\ +\015\000\010\000\010\000\016\000\016\000\017\000\017\000\017\000\ +\017\000\011\000\011\000\018\000\018\000\012\000\012\000\019\000\ +\019\000\003\000\003\000\003\000\003\000\003\000\003\000\013\000\ +\013\000\020\000\020\000\020\000\021\000\021\000\004\000\004\000\ +\004\000\004\000\004\000\004\000\002\000\002\000\002\000\002\000\ +\002\000\002\000\002\000\002\000\002\000\002\000\002\000\002\000\ +\002\000\002\000\002\000\002\000\002\000\002\000\002\000\002\000\ +\002\000\002\000\002\000\002\000\002\000\002\000\002\000\002\000\ +\002\000\002\000\002\000\002\000\002\000\002\000\002\000\002\000\ +\002\000\002\000\002\000\000\000\000\000" + +let yylen = "\002\000\ +\001\000\004\000\000\000\004\000\001\000\000\000\002\000\002\000\ +\002\000\002\000\002\000\002\000\001\000\001\000\000\000\003\000\ +\003\000\000\000\003\000\010\000\008\000\000\000\001\000\001\000\ +\001\000\000\000\003\000\003\000\004\000\000\000\003\000\003\000\ +\004\000\003\000\003\000\003\000\003\000\003\000\003\000\000\000\ +\003\000\003\000\004\000\001\000\001\000\002\000\012\000\001\000\ +\008\000\006\000\001\000\001\000\001\000\001\000\001\000\001\000\ +\004\000\003\000\003\000\003\000\003\000\002\000\002\000\003\000\ +\003\000\006\000\003\000\004\000\004\000\008\000\004\000\004\000\ +\004\000\004\000\004\000\004\000\006\000\006\000\004\000\004\000\ +\004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ +\006\000\006\000\004\000\002\000\002\000" + +let yydefred = "\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\092\000\001\000\005\000\000\000\000\000\000\000\000\000\ +\053\000\054\000\055\000\056\000\051\000\000\000\048\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\008\000\000\000\023\000\024\000\ +\025\000\009\000\000\000\000\000\000\000\010\000\000\000\000\000\ +\011\000\000\000\000\000\000\000\012\000\000\000\007\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\014\000\013\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\067\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\065\000\000\000\000\000\002\000\000\000\016\000\ +\019\000\000\000\000\000\000\000\027\000\000\000\000\000\032\000\ +\000\000\031\000\000\000\000\000\041\000\000\000\068\000\069\000\ +\071\000\000\000\000\000\000\000\072\000\073\000\074\000\075\000\ +\076\000\079\000\080\000\081\000\088\000\082\000\083\000\084\000\ +\085\000\086\000\087\000\000\000\000\000\091\000\000\000\057\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\033\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\039\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\050\000\000\000\077\000\078\000\ +\089\000\090\000\066\000\004\000\000\000\000\000\000\000\000\000\ +\000\000\049\000\070\000\000\000\000\000\045\000\000\000\000\000\ +\046\000\000\000\000\000\000\000\047\000" + +let yydgoto = "\003\000\ +\010\000\068\000\168\000\050\000\011\000\158\000\012\000\013\000\ +\053\000\058\000\062\000\065\000\069\000\111\000\054\000\059\000\ +\060\000\063\000\066\000\070\000\247\000" + +let yysindex = "\034\000\ +\251\254\144\255\000\000\048\255\238\254\243\254\247\254\015\255\ +\202\255\000\000\000\000\000\000\048\255\144\255\144\255\144\255\ +\000\000\000\000\000\000\000\000\000\000\003\255\000\000\029\255\ +\052\255\055\255\092\255\110\255\128\255\142\255\143\255\207\255\ +\004\000\005\000\015\000\020\000\022\000\054\000\055\000\056\000\ +\057\000\058\000\059\000\069\000\071\000\072\000\077\000\087\000\ +\124\255\089\000\073\255\085\255\000\000\062\255\000\000\000\000\ +\000\000\000\000\062\255\138\255\249\254\000\000\062\255\006\255\ +\000\000\062\255\253\254\124\255\000\000\062\255\000\000\160\255\ +\104\255\104\255\186\255\144\255\144\255\144\255\144\255\144\255\ +\144\255\144\255\144\255\144\255\144\255\144\255\144\255\144\255\ +\144\255\144\255\144\255\144\255\144\255\144\255\144\255\144\255\ +\144\255\144\255\144\255\144\255\144\255\144\255\144\255\144\255\ +\011\255\144\255\063\000\144\255\000\000\000\000\238\254\243\254\ +\250\255\144\255\003\000\247\254\177\000\088\000\015\255\144\255\ +\079\000\202\255\000\000\096\000\104\255\043\000\193\000\234\000\ +\076\255\081\255\094\255\036\001\046\001\056\001\066\001\088\001\ +\101\001\131\001\146\001\156\001\166\001\176\001\186\001\196\001\ +\206\001\216\001\099\255\112\255\226\001\150\255\150\255\104\255\ +\104\255\098\000\000\000\236\001\048\255\000\000\124\255\000\000\ +\000\000\101\000\124\255\144\255\000\000\177\000\204\255\000\000\ +\177\000\000\000\124\255\144\255\000\000\090\000\000\000\000\000\ +\000\000\144\255\144\255\144\255\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\144\255\144\255\000\000\094\000\000\000\ +\102\000\144\255\124\255\034\255\120\000\144\255\144\255\144\255\ +\144\255\144\255\000\000\124\255\007\255\117\255\246\001\000\002\ +\010\002\020\002\122\000\063\000\130\255\000\000\124\255\124\255\ +\124\255\124\255\124\255\106\000\000\000\144\255\000\000\000\000\ +\000\000\000\000\000\000\000\000\144\255\023\255\030\002\221\255\ +\250\254\000\000\000\000\109\000\112\000\000\000\140\000\144\255\ +\000\000\250\254\124\255\138\000\000\000" + +let yyrindex = "\000\000\ +\147\001\000\000\000\000\144\000\006\000\001\000\011\000\016\000\ +\038\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\053\255\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\148\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\059\255\148\255\000\000\000\000\000\000\000\000\ +\067\000\085\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\161\001\000\000\000\000\000\000\006\000\001\000\ +\000\000\000\000\000\000\011\000\000\000\000\000\016\000\000\000\ +\000\000\038\000\000\000\000\000\103\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\157\000\175\000\121\000\ +\139\000\000\000\000\000\000\000\144\000\000\000\174\255\000\000\ +\000\000\000\000\227\255\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\014\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\019\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\161\001\000\000\000\000\078\255\096\255\ +\114\255\156\255\205\255\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\000\000\047\000\000\000\000\000\000\000\000\000\ +\000\000\000\000\049\000\000\000\000\000" + +let yygindex = "\000\000\ +\000\000\181\001\145\255\255\255\252\255\199\000\152\001\000\000\ +\055\001\057\001\054\001\052\001\062\001\086\000\000\000\000\000\ +\000\000\000\000\000\000\000\000\185\000" + +let yytablesize = 812 +let yytable = "\051\000\ +\018\000\006\000\004\000\052\000\245\000\015\000\117\000\114\000\ +\075\000\228\000\026\000\120\000\061\000\229\000\154\000\030\000\ +\246\000\055\000\056\000\057\000\005\000\006\000\007\000\008\000\ +\009\000\241\000\021\000\022\000\023\000\242\000\021\000\022\000\ +\023\000\155\000\001\000\002\000\064\000\040\000\123\000\021\000\ +\022\000\023\000\076\000\101\000\102\000\103\000\104\000\105\000\ +\206\000\207\000\208\000\209\000\210\000\052\000\205\000\077\000\ +\052\000\211\000\078\000\115\000\053\000\053\000\118\000\109\000\ +\110\000\121\000\063\000\052\000\053\000\053\000\053\000\053\000\ +\053\000\005\000\006\000\007\000\008\000\009\000\178\000\034\000\ +\034\000\107\000\034\000\179\000\062\000\101\000\102\000\103\000\ +\104\000\105\000\101\000\102\000\103\000\104\000\105\000\079\000\ +\180\000\035\000\035\000\108\000\035\000\196\000\064\000\101\000\ +\102\000\103\000\104\000\105\000\101\000\102\000\103\000\104\000\ +\105\000\080\000\197\000\037\000\037\000\105\000\037\000\230\000\ +\060\000\101\000\102\000\103\000\104\000\105\000\101\000\102\000\ +\103\000\104\000\105\000\081\000\237\000\101\000\102\000\103\000\ +\104\000\105\000\061\000\101\000\102\000\103\000\104\000\105\000\ +\112\000\082\000\083\000\014\000\116\000\044\000\044\000\119\000\ +\201\000\015\000\016\000\122\000\058\000\036\000\036\000\113\000\ +\036\000\103\000\104\000\105\000\123\000\017\000\018\000\019\000\ +\020\000\101\000\102\000\103\000\104\000\105\000\059\000\017\000\ +\017\000\021\000\022\000\023\000\024\000\025\000\026\000\027\000\ +\028\000\029\000\030\000\031\000\032\000\033\000\034\000\035\000\ +\036\000\037\000\038\000\039\000\040\000\041\000\042\000\043\000\ +\044\000\045\000\046\000\047\000\048\000\014\000\038\000\038\000\ +\124\000\038\000\084\000\015\000\016\000\101\000\102\000\103\000\ +\104\000\105\000\206\000\207\000\208\000\209\000\210\000\067\000\ +\018\000\019\000\020\000\244\000\028\000\028\000\101\000\102\000\ +\103\000\104\000\105\000\021\000\022\000\023\000\024\000\025\000\ +\026\000\027\000\028\000\029\000\030\000\031\000\032\000\033\000\ +\034\000\035\000\036\000\037\000\038\000\039\000\040\000\041\000\ +\042\000\043\000\044\000\045\000\046\000\047\000\048\000\085\000\ +\086\000\018\000\006\000\042\000\042\000\162\000\015\000\029\000\ +\029\000\164\000\087\000\026\000\043\000\043\000\022\000\088\000\ +\030\000\089\000\018\000\018\000\018\000\018\000\018\000\015\000\ +\015\000\015\000\015\000\015\000\026\000\026\000\026\000\026\000\ +\026\000\030\000\030\000\030\000\030\000\030\000\040\000\175\000\ +\021\000\021\000\020\000\020\000\101\000\102\000\103\000\104\000\ +\105\000\090\000\091\000\092\000\093\000\094\000\095\000\040\000\ +\040\000\040\000\040\000\040\000\063\000\063\000\157\000\063\000\ +\096\000\063\000\097\000\098\000\063\000\063\000\063\000\063\000\ +\099\000\063\000\063\000\063\000\063\000\063\000\062\000\062\000\ +\169\000\062\000\100\000\062\000\106\000\172\000\062\000\062\000\ +\062\000\062\000\174\000\062\000\062\000\062\000\062\000\062\000\ +\064\000\064\000\202\000\064\000\199\000\064\000\220\000\213\000\ +\064\000\064\000\064\000\064\000\219\000\064\000\064\000\064\000\ +\064\000\064\000\060\000\060\000\222\000\060\000\235\000\060\000\ +\238\000\248\000\060\000\060\000\060\000\060\000\249\000\060\000\ +\060\000\060\000\060\000\060\000\061\000\061\000\250\000\061\000\ +\253\000\061\000\006\000\093\000\061\000\061\000\061\000\061\000\ +\006\000\061\000\061\000\061\000\061\000\061\000\058\000\058\000\ +\003\000\058\000\236\000\058\000\071\000\160\000\058\000\058\000\ +\161\000\165\000\170\000\058\000\058\000\058\000\058\000\058\000\ +\059\000\059\000\252\000\059\000\166\000\059\000\049\000\173\000\ +\059\000\059\000\015\000\016\000\000\000\059\000\059\000\059\000\ +\059\000\059\000\072\000\073\000\074\000\176\000\017\000\018\000\ +\019\000\020\000\101\000\102\000\103\000\104\000\105\000\000\000\ +\000\000\000\000\021\000\022\000\023\000\024\000\025\000\026\000\ +\027\000\028\000\029\000\030\000\031\000\032\000\033\000\034\000\ +\035\000\036\000\037\000\038\000\039\000\040\000\041\000\042\000\ +\043\000\044\000\045\000\046\000\047\000\048\000\177\000\000\000\ +\000\000\000\000\000\000\101\000\102\000\103\000\104\000\105\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\125\000\126\000\127\000\128\000\129\000\130\000\131\000\132\000\ +\133\000\134\000\135\000\136\000\137\000\138\000\139\000\140\000\ +\141\000\142\000\143\000\144\000\145\000\146\000\147\000\148\000\ +\149\000\150\000\151\000\152\000\153\000\000\000\156\000\000\000\ +\159\000\000\000\000\000\000\000\000\000\000\000\163\000\000\000\ +\181\000\167\000\000\000\000\000\171\000\101\000\102\000\103\000\ +\104\000\105\000\182\000\000\000\000\000\000\000\000\000\101\000\ +\102\000\103\000\104\000\105\000\183\000\000\000\000\000\000\000\ +\000\000\101\000\102\000\103\000\104\000\105\000\184\000\000\000\ +\000\000\000\000\000\000\101\000\102\000\103\000\104\000\105\000\ +\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ +\203\000\000\000\204\000\000\000\185\000\167\000\000\000\000\000\ +\212\000\101\000\102\000\103\000\104\000\105\000\214\000\215\000\ +\216\000\186\000\000\000\000\000\000\000\000\000\101\000\102\000\ +\103\000\104\000\105\000\000\000\000\000\000\000\000\000\000\000\ +\217\000\218\000\000\000\000\000\000\000\000\000\221\000\000\000\ +\000\000\000\000\223\000\224\000\225\000\226\000\227\000\187\000\ +\000\000\000\000\000\000\000\000\101\000\102\000\103\000\104\000\ +\105\000\000\000\000\000\000\000\000\000\000\000\188\000\000\000\ +\000\000\000\000\239\000\101\000\102\000\103\000\104\000\105\000\ +\189\000\240\000\000\000\000\000\000\000\101\000\102\000\103\000\ +\104\000\105\000\190\000\000\000\251\000\000\000\000\000\101\000\ +\102\000\103\000\104\000\105\000\191\000\000\000\000\000\000\000\ +\000\000\101\000\102\000\103\000\104\000\105\000\192\000\000\000\ +\000\000\000\000\000\000\101\000\102\000\103\000\104\000\105\000\ +\193\000\000\000\000\000\000\000\000\000\101\000\102\000\103\000\ +\104\000\105\000\194\000\000\000\000\000\000\000\000\000\101\000\ +\102\000\103\000\104\000\105\000\195\000\000\000\000\000\000\000\ +\000\000\101\000\102\000\103\000\104\000\105\000\198\000\000\000\ +\000\000\000\000\000\000\101\000\102\000\103\000\104\000\105\000\ +\200\000\000\000\000\000\000\000\000\000\101\000\102\000\103\000\ +\104\000\105\000\231\000\000\000\000\000\000\000\000\000\101\000\ +\102\000\103\000\104\000\105\000\232\000\000\000\000\000\000\000\ +\000\000\101\000\102\000\103\000\104\000\105\000\233\000\000\000\ +\000\000\000\000\000\000\101\000\102\000\103\000\104\000\105\000\ +\234\000\000\000\000\000\000\000\000\000\101\000\102\000\103\000\ +\104\000\105\000\243\000\000\000\000\000\000\000\000\000\101\000\ +\102\000\103\000\104\000\105\000" + +let yycheck = "\004\000\ +\000\000\000\000\008\001\022\001\011\001\000\000\001\001\015\001\ +\006\001\003\001\000\000\015\001\022\001\007\001\004\001\000\000\ +\023\001\031\001\032\001\033\001\026\001\027\001\028\001\029\001\ +\030\001\003\001\034\001\035\001\036\001\007\001\034\001\035\001\ +\036\001\023\001\001\000\002\000\022\001\000\000\005\001\034\001\ +\035\001\036\001\014\001\010\001\011\001\012\001\013\001\014\001\ +\015\001\016\001\017\001\018\001\019\001\001\001\166\000\004\001\ +\004\001\169\000\004\001\061\000\002\001\003\001\064\000\002\001\ +\003\001\067\000\000\000\015\001\010\001\011\001\012\001\013\001\ +\014\001\026\001\027\001\028\001\029\001\030\001\003\001\002\001\ +\003\001\009\001\005\001\003\001\000\000\010\001\011\001\012\001\ +\013\001\014\001\010\001\011\001\012\001\013\001\014\001\004\001\ +\003\001\002\001\003\001\015\001\005\001\003\001\000\000\010\001\ +\011\001\012\001\013\001\014\001\010\001\011\001\012\001\013\001\ +\014\001\004\001\003\001\002\001\003\001\014\001\005\001\003\001\ +\000\000\010\001\011\001\012\001\013\001\014\001\010\001\011\001\ +\012\001\013\001\014\001\004\001\003\001\010\001\011\001\012\001\ +\013\001\014\001\000\000\010\001\011\001\012\001\013\001\014\001\ +\059\000\004\001\004\001\004\001\063\000\002\001\003\001\066\000\ +\157\000\010\001\011\001\070\000\000\000\002\001\003\001\022\001\ +\005\001\012\001\013\001\014\001\005\001\022\001\023\001\024\001\ +\025\001\010\001\011\001\012\001\013\001\014\001\000\000\002\001\ +\003\001\034\001\035\001\036\001\037\001\038\001\039\001\040\001\ +\041\001\042\001\043\001\044\001\045\001\046\001\047\001\048\001\ +\049\001\050\001\051\001\052\001\053\001\054\001\055\001\056\001\ +\057\001\058\001\059\001\060\001\061\001\004\001\002\001\003\001\ +\023\001\005\001\004\001\010\001\011\001\010\001\011\001\012\001\ +\013\001\014\001\015\001\016\001\017\001\018\001\019\001\022\001\ +\023\001\024\001\025\001\007\001\002\001\003\001\010\001\011\001\ +\012\001\013\001\014\001\034\001\035\001\036\001\037\001\038\001\ +\039\001\040\001\041\001\042\001\043\001\044\001\045\001\046\001\ +\047\001\048\001\049\001\050\001\051\001\052\001\053\001\054\001\ +\055\001\056\001\057\001\058\001\059\001\060\001\061\001\004\001\ +\004\001\009\001\009\001\002\001\003\001\020\001\009\001\002\001\ +\003\001\015\001\004\001\009\001\002\001\003\001\022\001\004\001\ +\009\001\004\001\026\001\027\001\028\001\029\001\030\001\026\001\ +\027\001\028\001\029\001\030\001\026\001\027\001\028\001\029\001\ +\030\001\026\001\027\001\028\001\029\001\030\001\009\001\005\001\ +\002\001\003\001\002\001\003\001\010\001\011\001\012\001\013\001\ +\014\001\004\001\004\001\004\001\004\001\004\001\004\001\026\001\ +\027\001\028\001\029\001\030\001\002\001\003\001\008\001\005\001\ +\004\001\007\001\004\001\004\001\010\001\011\001\012\001\013\001\ +\004\001\015\001\016\001\017\001\018\001\019\001\002\001\003\001\ +\001\001\005\001\004\001\007\001\004\001\015\001\010\001\011\001\ +\012\001\013\001\003\001\015\001\016\001\017\001\018\001\019\001\ +\002\001\003\001\006\001\005\001\011\001\007\001\009\001\022\001\ +\010\001\011\001\012\001\013\001\023\001\015\001\016\001\017\001\ +\018\001\019\001\002\001\003\001\005\001\005\001\005\001\007\001\ +\023\001\021\001\010\001\011\001\012\001\013\001\023\001\015\001\ +\016\001\017\001\018\001\019\001\002\001\003\001\003\001\005\001\ +\007\001\007\001\000\000\000\000\010\001\011\001\012\001\013\001\ +\009\001\015\001\016\001\017\001\018\001\019\001\002\001\003\001\ +\000\000\005\001\220\000\007\001\013\000\111\000\010\001\011\001\ +\112\000\116\000\119\000\015\001\016\001\017\001\018\001\019\001\ +\002\001\003\001\250\000\005\001\004\001\007\001\002\000\122\000\ +\010\001\011\001\010\001\011\001\255\255\015\001\016\001\017\001\ +\018\001\019\001\014\000\015\000\016\000\005\001\022\001\023\001\ +\024\001\025\001\010\001\011\001\012\001\013\001\014\001\255\255\ +\255\255\255\255\034\001\035\001\036\001\037\001\038\001\039\001\ +\040\001\041\001\042\001\043\001\044\001\045\001\046\001\047\001\ +\048\001\049\001\050\001\051\001\052\001\053\001\054\001\055\001\ +\056\001\057\001\058\001\059\001\060\001\061\001\005\001\255\255\ +\255\255\255\255\255\255\010\001\011\001\012\001\013\001\014\001\ +\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ +\076\000\077\000\078\000\079\000\080\000\081\000\082\000\083\000\ +\084\000\085\000\086\000\087\000\088\000\089\000\090\000\091\000\ +\092\000\093\000\094\000\095\000\096\000\097\000\098\000\099\000\ +\100\000\101\000\102\000\103\000\104\000\255\255\106\000\255\255\ +\108\000\255\255\255\255\255\255\255\255\255\255\114\000\255\255\ +\005\001\117\000\255\255\255\255\120\000\010\001\011\001\012\001\ +\013\001\014\001\005\001\255\255\255\255\255\255\255\255\010\001\ +\011\001\012\001\013\001\014\001\005\001\255\255\255\255\255\255\ +\255\255\010\001\011\001\012\001\013\001\014\001\005\001\255\255\ +\255\255\255\255\255\255\010\001\011\001\012\001\013\001\014\001\ +\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ +\164\000\255\255\166\000\255\255\005\001\169\000\255\255\255\255\ +\172\000\010\001\011\001\012\001\013\001\014\001\178\000\179\000\ +\180\000\005\001\255\255\255\255\255\255\255\255\010\001\011\001\ +\012\001\013\001\014\001\255\255\255\255\255\255\255\255\255\255\ +\196\000\197\000\255\255\255\255\255\255\255\255\202\000\255\255\ +\255\255\255\255\206\000\207\000\208\000\209\000\210\000\005\001\ +\255\255\255\255\255\255\255\255\010\001\011\001\012\001\013\001\ +\014\001\255\255\255\255\255\255\255\255\255\255\005\001\255\255\ +\255\255\255\255\230\000\010\001\011\001\012\001\013\001\014\001\ +\005\001\237\000\255\255\255\255\255\255\010\001\011\001\012\001\ +\013\001\014\001\005\001\255\255\248\000\255\255\255\255\010\001\ +\011\001\012\001\013\001\014\001\005\001\255\255\255\255\255\255\ +\255\255\010\001\011\001\012\001\013\001\014\001\005\001\255\255\ +\255\255\255\255\255\255\010\001\011\001\012\001\013\001\014\001\ +\005\001\255\255\255\255\255\255\255\255\010\001\011\001\012\001\ +\013\001\014\001\005\001\255\255\255\255\255\255\255\255\010\001\ +\011\001\012\001\013\001\014\001\005\001\255\255\255\255\255\255\ +\255\255\010\001\011\001\012\001\013\001\014\001\005\001\255\255\ +\255\255\255\255\255\255\010\001\011\001\012\001\013\001\014\001\ +\005\001\255\255\255\255\255\255\255\255\010\001\011\001\012\001\ +\013\001\014\001\005\001\255\255\255\255\255\255\255\255\010\001\ +\011\001\012\001\013\001\014\001\005\001\255\255\255\255\255\255\ +\255\255\010\001\011\001\012\001\013\001\014\001\005\001\255\255\ +\255\255\255\255\255\255\010\001\011\001\012\001\013\001\014\001\ +\005\001\255\255\255\255\255\255\255\255\010\001\011\001\012\001\ +\013\001\014\001\005\001\255\255\255\255\255\255\255\255\010\001\ +\011\001\012\001\013\001\014\001" + +let yynames_const = "\ + EOF\000\ + COLON\000\ + SEMICOLON\000\ + COMMA\000\ + LPAREN\000\ + RPAREN\000\ + LBRACKET\000\ + RBRACKET\000\ + LBRACE\000\ + RBRACE\000\ + PLUS\000\ + MINUS\000\ + MULT\000\ + DIVIDE\000\ + POW\000\ + EQ\000\ + LE\000\ + GE\000\ + LT\000\ + GT\000\ + IN\000\ + PLUS_MINUS\000\ + CONSTANTS\000\ + VARIABLES\000\ + DEFINITIONS\000\ + CONSTRAINTS\000\ + EXPRESSIONS\000\ + INT\000\ + REAL\000\ + RND\000\ + NO_RND\000\ + E_CONST\000\ + ABS\000\ + INV\000\ + SQRT\000\ + FMA\000\ + MIN\000\ + MAX\000\ + EXP\000\ + LOG\000\ + COS\000\ + SIN\000\ + TAN\000\ + COSH\000\ + SINH\000\ + TANH\000\ + RELU\000\ + ACOS\000\ + ASIN\000\ + ATAN\000\ + ACOSH\000\ + ASINH\000\ + ATANH\000\ + ATAN2\000\ + SUB2\000\ + FLOOR_POWER2\000\ + " + +let yynames_block = "\ + ID\000\ + NUMBER\000\ + SINGLE_NUMERAL\000\ + DOUBLE_NUMERAL\000\ + FLOAT\000\ + RND_PAR\000\ + " + +let yyact = [| + (fun _ -> failwith "parser") +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 0 : 'task) in + Obj.repr( +# 48 "input_parser.mly" + ( _1 ) +# 565 "input_parser.ml" + : Task.task list)) +; (fun __caml_parser_env -> + let _2 = (Parsing.peek_val __caml_parser_env 2 : 'task) in + let _4 = (Parsing.peek_val __caml_parser_env 0 : 'more_tasks) in + Obj.repr( +# 49 "input_parser.mly" + ( _2 @ _4 ) +# 573 "input_parser.ml" + : Task.task list)) +; (fun __caml_parser_env -> + Obj.repr( +# 53 "input_parser.mly" + ( [] ) +# 579 "input_parser.ml" + : 'more_tasks)) +; (fun __caml_parser_env -> + let _2 = (Parsing.peek_val __caml_parser_env 2 : 'task) in + let _4 = (Parsing.peek_val __caml_parser_env 0 : 'more_tasks) in + Obj.repr( +# 54 "input_parser.mly" + ( _2 @ _4 ) +# 587 "input_parser.ml" + : 'more_tasks)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 0 : 'section_list) in + Obj.repr( +# 58 "input_parser.mly" + ( + let tasks = env_to_tasks () in + reset(); + tasks + ) +# 598 "input_parser.ml" + : 'task)) +; (fun __caml_parser_env -> + Obj.repr( +# 66 "input_parser.mly" + () +# 604 "input_parser.ml" + : 'section_list)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 1 : 'section) in + let _2 = (Parsing.peek_val __caml_parser_env 0 : 'section_list) in + Obj.repr( +# 67 "input_parser.mly" + () +# 612 "input_parser.ml" + : 'section_list)) +; (fun __caml_parser_env -> + let _2 = (Parsing.peek_val __caml_parser_env 0 : 'constants_list) in + Obj.repr( +# 71 "input_parser.mly" + () +# 619 "input_parser.ml" + : 'section)) +; (fun __caml_parser_env -> + let _2 = (Parsing.peek_val __caml_parser_env 0 : 'variables_list) in + Obj.repr( +# 72 "input_parser.mly" + () +# 626 "input_parser.ml" + : 'section)) +; (fun __caml_parser_env -> + let _2 = (Parsing.peek_val __caml_parser_env 0 : 'definitions_list) in + Obj.repr( +# 73 "input_parser.mly" + () +# 633 "input_parser.ml" + : 'section)) +; (fun __caml_parser_env -> + let _2 = (Parsing.peek_val __caml_parser_env 0 : 'constraints_list) in + Obj.repr( +# 74 "input_parser.mly" + () +# 640 "input_parser.ml" + : 'section)) +; (fun __caml_parser_env -> + let _2 = (Parsing.peek_val __caml_parser_env 0 : 'expressions_list) in + Obj.repr( +# 75 "input_parser.mly" + () +# 647 "input_parser.ml" + : 'section)) +; (fun __caml_parser_env -> + Obj.repr( +# 79 "input_parser.mly" + () +# 653 "input_parser.ml" + : 'separator)) +; (fun __caml_parser_env -> + Obj.repr( +# 80 "input_parser.mly" + () +# 659 "input_parser.ml" + : 'separator)) +; (fun __caml_parser_env -> + Obj.repr( +# 84 "input_parser.mly" + () +# 665 "input_parser.ml" + : 'constants_list)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : 'constant) in + let _2 = (Parsing.peek_val __caml_parser_env 1 : 'separator) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : 'constants_list) in + Obj.repr( +# 85 "input_parser.mly" + () +# 674 "input_parser.ml" + : 'constants_list)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : string) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 89 "input_parser.mly" + ( add_constant _1 _3 ) +# 682 "input_parser.ml" + : 'constant)) +; (fun __caml_parser_env -> + Obj.repr( +# 93 "input_parser.mly" + () +# 688 "input_parser.ml" + : 'variables_list)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : 'variable) in + let _2 = (Parsing.peek_val __caml_parser_env 1 : 'separator) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : 'variables_list) in + Obj.repr( +# 94 "input_parser.mly" + () +# 697 "input_parser.ml" + : 'variables_list)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 9 : 'var_type) in + let _2 = (Parsing.peek_val __caml_parser_env 8 : string) in + let _5 = (Parsing.peek_val __caml_parser_env 5 : Input_parser_env.raw_expr) in + let _7 = (Parsing.peek_val __caml_parser_env 3 : Input_parser_env.raw_expr) in + let _10 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 99 "input_parser.mly" + ( add_variable_with_uncertainty _1 _2 _5 _7 _10 ) +# 708 "input_parser.ml" + : 'variable)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 7 : 'var_type) in + let _2 = (Parsing.peek_val __caml_parser_env 6 : string) in + let _5 = (Parsing.peek_val __caml_parser_env 3 : Input_parser_env.raw_expr) in + let _7 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 101 "input_parser.mly" + ( add_variable _1 _2 _5 _7 ) +# 718 "input_parser.ml" + : 'variable)) +; (fun __caml_parser_env -> + Obj.repr( +# 105 "input_parser.mly" + ( string_to_value_type (Config.get_string_option "default-var-type") ) +# 724 "input_parser.ml" + : 'var_type)) +; (fun __caml_parser_env -> + Obj.repr( +# 106 "input_parser.mly" + ( real_type ) +# 730 "input_parser.ml" + : 'var_type)) +; (fun __caml_parser_env -> + Obj.repr( +# 107 "input_parser.mly" + ( real_type ) +# 736 "input_parser.ml" + : 'var_type)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 0 : int) in + Obj.repr( +# 108 "input_parser.mly" + ( mk_value_type _1 ) +# 743 "input_parser.ml" + : 'var_type)) +; (fun __caml_parser_env -> + Obj.repr( +# 112 "input_parser.mly" + () +# 749 "input_parser.ml" + : 'definitions_list)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : 'definition) in + let _2 = (Parsing.peek_val __caml_parser_env 1 : 'separator) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : 'definitions_list) in + Obj.repr( +# 113 "input_parser.mly" + () +# 758 "input_parser.ml" + : 'definitions_list)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : string) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 117 "input_parser.mly" + ( add_definition _1 _3 ) +# 766 "input_parser.ml" + : 'definition)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 3 : string) in + let _2 = (Parsing.peek_val __caml_parser_env 2 : Rounding.rnd_info) in + let _4 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 118 "input_parser.mly" + ( add_definition _1 (apply_raw_rounding _2 _4) ) +# 775 "input_parser.ml" + : 'definition)) +; (fun __caml_parser_env -> + Obj.repr( +# 122 "input_parser.mly" + () +# 781 "input_parser.ml" + : 'constraints_list)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : 'constr) in + let _2 = (Parsing.peek_val __caml_parser_env 1 : 'separator) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : 'constraints_list) in + Obj.repr( +# 123 "input_parser.mly" + () +# 790 "input_parser.ml" + : 'constraints_list)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : string) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_formula) in + Obj.repr( +# 127 "input_parser.mly" + ( add_constraint _1 _3 ) +# 798 "input_parser.ml" + : 'constr)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 3 : string) in + let _2 = (Parsing.peek_val __caml_parser_env 2 : Rounding.rnd_info) in + let _4 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_formula) in + Obj.repr( +# 128 "input_parser.mly" + ( add_constraint _1 (apply_raw_rounding_to_formula _2 _4) ) +# 807 "input_parser.ml" + : 'constr)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : Input_parser_env.raw_expr) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 132 "input_parser.mly" + ( Raw_eq (_1, _3) ) +# 815 "input_parser.ml" + : Input_parser_env.raw_formula)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : Input_parser_env.raw_expr) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 133 "input_parser.mly" + ( Raw_le (_1, _3) ) +# 823 "input_parser.ml" + : Input_parser_env.raw_formula)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : Input_parser_env.raw_expr) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 134 "input_parser.mly" + ( Raw_lt (_1, _3) ) +# 831 "input_parser.ml" + : Input_parser_env.raw_formula)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : Input_parser_env.raw_expr) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 135 "input_parser.mly" + ( Raw_le (_3, _1) ) +# 839 "input_parser.ml" + : Input_parser_env.raw_formula)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : Input_parser_env.raw_expr) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 136 "input_parser.mly" + ( Raw_lt (_3, _1) ) +# 847 "input_parser.ml" + : Input_parser_env.raw_formula)) +; (fun __caml_parser_env -> + let _2 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_formula) in + Obj.repr( +# 137 "input_parser.mly" + ( _2 ) +# 854 "input_parser.ml" + : Input_parser_env.raw_formula)) +; (fun __caml_parser_env -> + Obj.repr( +# 141 "input_parser.mly" + () +# 860 "input_parser.ml" + : 'expressions_list)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expression) in + let _2 = (Parsing.peek_val __caml_parser_env 1 : 'separator) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expressions_list) in + Obj.repr( +# 142 "input_parser.mly" + () +# 869 "input_parser.ml" + : 'expressions_list)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : string) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 146 "input_parser.mly" + ( add_expression_with_name _1 _3 ) +# 877 "input_parser.ml" + : 'expression)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 3 : string) in + let _2 = (Parsing.peek_val __caml_parser_env 2 : Rounding.rnd_info) in + let _4 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 147 "input_parser.mly" + ( add_expression_with_name _1 (apply_raw_rounding _2 _4) ) +# 886 "input_parser.ml" + : 'expression)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 148 "input_parser.mly" + ( add_expression _1 ) +# 893 "input_parser.ml" + : 'expression)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 0 : string) in + Obj.repr( +# 152 "input_parser.mly" + ( _1 ) +# 900 "input_parser.ml" + : 'pos_neg_number)) +; (fun __caml_parser_env -> + let _2 = (Parsing.peek_val __caml_parser_env 0 : string) in + Obj.repr( +# 153 "input_parser.mly" + ( ("-" ^ _2) ) +# 907 "input_parser.ml" + : 'pos_neg_number)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 9 : string) in + let _5 = (Parsing.peek_val __caml_parser_env 7 : string) in + let _7 = (Parsing.peek_val __caml_parser_env 5 : string) in + let _9 = (Parsing.peek_val __caml_parser_env 3 : 'pos_neg_number) in + let _11 = (Parsing.peek_val __caml_parser_env 1 : 'pos_neg_number) in + Obj.repr( +# 158 "input_parser.mly" + ( create_explicit_rounding (int_of_string _3) (_5) + (float_of_string _7) (int_of_string _9) (int_of_string _11) ) +# 919 "input_parser.ml" + : Rounding.rnd_info)) +; (fun __caml_parser_env -> + Obj.repr( +# 160 "input_parser.mly" + ( create_rounding 0 "ne" 1.0 ) +# 925 "input_parser.ml" + : Rounding.rnd_info)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 5 : string) in + let _5 = (Parsing.peek_val __caml_parser_env 3 : string) in + let _7 = (Parsing.peek_val __caml_parser_env 1 : string) in + Obj.repr( +# 162 "input_parser.mly" + ( create_rounding (int_of_string _3) (_5) (float_of_string _7) ) +# 934 "input_parser.ml" + : Rounding.rnd_info)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 3 : string) in + let _5 = (Parsing.peek_val __caml_parser_env 1 : string) in + Obj.repr( +# 164 "input_parser.mly" + ( create_rounding (int_of_string _3) (_5) 1.0 ) +# 942 "input_parser.ml" + : Rounding.rnd_info)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 0 : int * string) in + Obj.repr( +# 166 "input_parser.mly" + ( create_rounding (fst _1) (snd _1) 1.0 ) +# 949 "input_parser.ml" + : Rounding.rnd_info)) +; (fun __caml_parser_env -> + Obj.repr( +# 168 "input_parser.mly" + ( string_to_rounding (Config.get_string_option "default-rnd") ) +# 955 "input_parser.ml" + : Rounding.rnd_info)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 0 : string) in + Obj.repr( +# 172 "input_parser.mly" + ( Identifier _1 ) +# 962 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 0 : string) in + Obj.repr( +# 173 "input_parser.mly" + ( Numeral (More_num.num_of_float_string _1) ) +# 969 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 0 : string) in + Obj.repr( +# 175 "input_parser.mly" + ( Raw_rounding (string_to_rounding "rnd32", Numeral (More_num.num_of_float_string _1)) ) +# 976 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 0 : string) in + Obj.repr( +# 177 "input_parser.mly" + ( Raw_rounding (string_to_rounding "rnd64", Numeral (More_num.num_of_float_string _1)) ) +# 983 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 3 : Rounding.rnd_info) in + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 178 "input_parser.mly" + ( Raw_rounding (_1, _3) ) +# 991 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : Input_parser_env.raw_expr) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 179 "input_parser.mly" + ( Raw_bin_op ("+", _1, _3) ) +# 999 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : Input_parser_env.raw_expr) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 180 "input_parser.mly" + ( Raw_bin_op ("-", _1, _3) ) +# 1007 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : Input_parser_env.raw_expr) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 181 "input_parser.mly" + ( Raw_bin_op ("*", _1, _3) ) +# 1015 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : Input_parser_env.raw_expr) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 182 "input_parser.mly" + ( Raw_bin_op ("/", _1, _3) ) +# 1023 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _2 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 183 "input_parser.mly" + ( Raw_u_op ("-", _2) ) +# 1030 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _2 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 184 "input_parser.mly" + ( _2 ) +# 1037 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 0 : Input_parser_env.raw_expr) in + Obj.repr( +# 185 "input_parser.mly" + ( Raw_u_op ("exp", _3) ) +# 1044 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 2 : Input_parser_env.raw_expr) in + let _3 = (Parsing.peek_val __caml_parser_env 0 : string) in + Obj.repr( +# 186 "input_parser.mly" + ( Raw_bin_op ("^", _1, Numeral (Num.num_of_string _3)) ) +# 1052 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _1 = (Parsing.peek_val __caml_parser_env 5 : Input_parser_env.raw_expr) in + let _5 = (Parsing.peek_val __caml_parser_env 1 : string) in + Obj.repr( +# 188 "input_parser.mly" + ( Raw_bin_op ("^", _1, Numeral (Num.minus_num (Num.num_of_string _5))) ) +# 1060 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _2 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 189 "input_parser.mly" + ( _2 ) +# 1067 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 190 "input_parser.mly" + ( Raw_u_op ("abs", _3) ) +# 1074 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 191 "input_parser.mly" + ( Raw_u_op ("inv", _3) ) +# 1081 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 5 : Input_parser_env.raw_expr) in + let _5 = (Parsing.peek_val __caml_parser_env 3 : Input_parser_env.raw_expr) in + let _7 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 193 "input_parser.mly" + ( Raw_gen_op ("fma", [_3; _5; _7]) ) +# 1090 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 194 "input_parser.mly" + ( Raw_u_op ("sqrt", _3) ) +# 1097 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 195 "input_parser.mly" + ( Raw_u_op ("exp", _3) ) +# 1104 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 196 "input_parser.mly" + ( Raw_u_op ("log", _3) ) +# 1111 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 197 "input_parser.mly" + ( Raw_u_op ("cos", _3) ) +# 1118 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 198 "input_parser.mly" + ( Raw_u_op ("sin", _3) ) +# 1125 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 199 "input_parser.mly" + ( Raw_u_op ("tan", _3) ) +# 1132 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 3 : Input_parser_env.raw_expr) in + let _5 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 200 "input_parser.mly" + ( Raw_bin_op ("min", _3, _5) ) +# 1140 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 3 : Input_parser_env.raw_expr) in + let _5 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 201 "input_parser.mly" + ( Raw_bin_op ("max", _3, _5) ) +# 1148 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 202 "input_parser.mly" + ( Raw_u_op ("cosh", _3) ) +# 1155 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 203 "input_parser.mly" + ( Raw_u_op ("sinh", _3) ) +# 1162 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 204 "input_parser.mly" + ( Raw_u_op ("tanh", _3) ) +# 1169 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 205 "input_parser.mly" + ( Raw_u_op ("acos", _3) ) +# 1176 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 206 "input_parser.mly" + ( Raw_u_op ("asin", _3) ) +# 1183 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 207 "input_parser.mly" + ( Raw_u_op ("atan", _3) ) +# 1190 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 208 "input_parser.mly" + ( Raw_u_op ("acosh", _3) ) +# 1197 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 209 "input_parser.mly" + ( Raw_u_op ("asinh", _3) ) +# 1204 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 210 "input_parser.mly" + ( Raw_u_op ("atanh", _3) ) +# 1211 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 211 "input_parser.mly" + ( Raw_u_op ("relu", _3) ) +# 1218 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 3 : Input_parser_env.raw_expr) in + let _5 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 212 "input_parser.mly" + ( raise TODO ) +# 1226 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 3 : Input_parser_env.raw_expr) in + let _5 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 213 "input_parser.mly" + ( Raw_bin_op ("sub2", _3, _5) ) +# 1234 "input_parser.ml" + : Input_parser_env.raw_expr)) +; (fun __caml_parser_env -> + let _3 = (Parsing.peek_val __caml_parser_env 1 : Input_parser_env.raw_expr) in + Obj.repr( +# 214 "input_parser.mly" + ( Raw_u_op ("floor_power2", _3) ) +# 1241 "input_parser.ml" + : Input_parser_env.raw_expr)) +(* Entry tasks *) +; (fun __caml_parser_env -> raise (Parsing.YYexit (Parsing.peek_val __caml_parser_env 0))) +(* Entry expr *) +; (fun __caml_parser_env -> raise (Parsing.YYexit (Parsing.peek_val __caml_parser_env 0))) +|] +let yytables = + { Parsing.actions=yyact; + Parsing.transl_const=yytransl_const; + Parsing.transl_block=yytransl_block; + Parsing.lhs=yylhs; + Parsing.len=yylen; + Parsing.defred=yydefred; + Parsing.dgoto=yydgoto; + Parsing.sindex=yysindex; + Parsing.rindex=yyrindex; + Parsing.gindex=yygindex; + Parsing.tablesize=yytablesize; + Parsing.table=yytable; + Parsing.check=yycheck; + Parsing.error_function=parse_error; + Parsing.names_const=yynames_const; + Parsing.names_block=yynames_block } +let tasks (lexfun : Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) = + (Parsing.yyparse yytables 1 lexfun lexbuf : Task.task list) +let expr (lexfun : Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) = + (Parsing.yyparse yytables 2 lexfun lexbuf : Input_parser_env.raw_expr) +;; diff --git a/input_parser.mli b/input_parser.mli new file mode 100644 index 0000000..9f1b1b1 --- /dev/null +++ b/input_parser.mli @@ -0,0 +1,68 @@ +type token = + | EOF + | COLON + | SEMICOLON + | COMMA + | LPAREN + | RPAREN + | LBRACKET + | RBRACKET + | LBRACE + | RBRACE + | PLUS + | MINUS + | MULT + | DIVIDE + | POW + | EQ + | LE + | GE + | LT + | GT + | IN + | PLUS_MINUS + | ID of (string) + | NUMBER of (string) + | SINGLE_NUMERAL of (string) + | DOUBLE_NUMERAL of (string) + | CONSTANTS + | VARIABLES + | DEFINITIONS + | CONSTRAINTS + | EXPRESSIONS + | INT + | REAL + | FLOAT of (int) + | RND_PAR of (int * string) + | RND + | NO_RND + | E_CONST + | ABS + | INV + | SQRT + | FMA + | MIN + | MAX + | EXP + | LOG + | COS + | SIN + | TAN + | COSH + | SINH + | TANH + | RELU + | ACOS + | ASIN + | ATAN + | ACOSH + | ASINH + | ATANH + | ATAN2 + | SUB2 + | FLOOR_POWER2 + +val tasks : + (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Task.task list +val expr : + (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Input_parser_env.raw_expr diff --git a/input_parser.mly b/input_parser.mly index 697d60d..19abcc5 100644 --- a/input_parser.mly +++ b/input_parser.mly @@ -24,6 +24,7 @@ %token MIN MAX %token EXP LOG %token COS SIN TAN COSH SINH TANH +%token RELU %token ACOS ASIN ATAN ACOSH ASINH ATANH ATAN2 %token SUB2 FLOOR_POWER2 @@ -207,6 +208,7 @@ expr: | ACOSH LPAREN expr RPAREN { Raw_u_op ("acosh", $3) } | ASINH LPAREN expr RPAREN { Raw_u_op ("asinh", $3) } | ATANH LPAREN expr RPAREN { Raw_u_op ("atanh", $3) } + | RELU LPAREN expr RPAREN { Raw_u_op ("relu", $3) } | ATAN2 LPAREN expr COMMA expr RPAREN { raise TODO } | SUB2 LPAREN expr COMMA expr RPAREN { Raw_bin_op ("sub2", $3, $5) } | FLOOR_POWER2 LPAREN expr RPAREN { Raw_u_op ("floor_power2", $3) } diff --git a/input_parser_env.ml b/input_parser_env.ml index 181ef41..e6471f6 100644 --- a/input_parser_env.ml +++ b/input_parser_env.ml @@ -64,6 +64,19 @@ let env = { expressions = []; } +let rec fillrnd1 rnd expr = match expr with + + | Const _ -> Rounding (rnd, expr) + | Var _ -> Rounding (rnd, expr) + | Rounding (r,e) -> Rounding (r, fillrnd1 rnd e) + | U_op (op, arg) -> Rounding (rnd, U_op (op, fillrnd1 rnd arg)) + | Bin_op (op, arg1, arg2) ->Rounding (rnd, Bin_op (op, fillrnd1 rnd arg1, fillrnd1 rnd arg2)) + | Gen_op (op, args) -> Rounding(rnd, Gen_op (op,List.map (fillrnd1 rnd) args)) + +let getfirstrnd expr = match expr with | Rounding (rnd,expr) ->rnd + +let fillrnd expr = fillrnd1 (getfirstrnd expr) expr + let reset () = let clear = Hashtbl.clear in clear env.constants; @@ -155,13 +168,14 @@ let apply_raw_rounding_to_formula rnd f = | Raw_eq (e1, e2) -> Raw_eq (apply_raw_rounding rnd e1, apply_raw_rounding rnd e2) + (* Builds an expression from a raw expression *) -let rec transform_raw_expr = function +let rec transform_raw_expr1 = function | Raw_rounding (rnd, arg) -> - let e1 = transform_raw_expr arg in + let e1 = transform_raw_expr1 arg in Rounding (rnd, e1) | Raw_u_op (str, arg) -> - let e1 = transform_raw_expr arg in + let e1 = transform_raw_expr1 arg in begin match str with | "-" -> U_op (Op_neg, e1) @@ -179,6 +193,7 @@ let rec transform_raw_expr = function | "sinh" -> U_op (Op_sinh, e1) | "cosh" -> U_op (Op_cosh, e1) | "tanh" -> U_op (Op_tanh, e1) + | "relu" -> Bin_op (Op_max,mk_const (Const.of_float 0.0),e1) | "asinh" -> U_op (Op_asinh, e1) | "acosh" -> U_op (Op_acosh, e1) | "atanh" -> U_op (Op_atanh, e1) @@ -186,8 +201,8 @@ let rec transform_raw_expr = function | _ -> failwith ("transform_raw_expr: Unknown unary operation: " ^ str) end | Raw_bin_op (str, arg1, arg2) -> - let e1 = transform_raw_expr arg1 and - e2 = transform_raw_expr arg2 in + let e1 = transform_raw_expr1 arg1 and + e2 = transform_raw_expr1 arg2 in begin match str with | "+" -> Bin_op (Op_add, e1, e2) @@ -201,7 +216,7 @@ let rec transform_raw_expr = function | _ -> failwith ("transform_raw_expr: Unknown binary operation: " ^ str) end | Raw_gen_op (str, args) -> - let es = List.map transform_raw_expr args in + let es = List.map transform_raw_expr1 args in begin match str with | "fma" -> Gen_op (Op_fma, es) @@ -215,6 +230,8 @@ let rec transform_raw_expr = function with Not_found -> let c = find_constant name in Const c.value +let transform_raw_expr re = match re with |Raw_rounding _ -> fillrnd (transform_raw_expr1 re) | _ -> transform_raw_expr1 re + (* Builds a formula from a raw formula *) let transform_raw_formula = function | Raw_le (r1, r2) -> Le (transform_raw_expr r1, transform_raw_expr r2) diff --git a/negpower3.txt b/negpower3.txt new file mode 100644 index 0000000..13e1c5e --- /dev/null +++ b/negpower3.txt @@ -0,0 +1,7 @@ +Derivative +negpower_3 +-3*x*x +-6.0 *.$ x +-.x*.x*.x +minus_num (x*/x*/x) +pow_I_i ~-$x 3 diff --git a/out_error_bounds.cmi b/out_error_bounds.cmi new file mode 100644 index 0000000..84f1c2d Binary files /dev/null and b/out_error_bounds.cmi differ diff --git a/out_error_bounds.cmo b/out_error_bounds.cmo new file mode 100644 index 0000000..16a5521 Binary files /dev/null and b/out_error_bounds.cmo differ