text stringlengths 0 601k |
|---|
let normalise quat = let tolerance = 0 . 00001 in let x = quat . qx and y = quat . qy and z = quat . qz and w = quat . qw in let mag2 = w . * w . + x . * x . + y . * y . + z . * z in if ( mag2 <> 0 . 0 ) && ( abs_float ( mag2 . - 1 . 0 ) > tolerance ) then begin let mag = sqrt mag2 in quat . qx <- quat . qx . / mag ; q... |
let getConjugate quat = { qx = . - quat . qx ; qy = . - quat . qy ; qz = . - quat . qz ; qw = quat . qw ; } |
let mult_quaternion q1 rq = { qx = q1 . qw . * rq . qx . + q1 . qx . * rq . qw . + q1 . qy . * rq . qz . - q1 . qz . * rq . qy ; qy = q1 . qw . * rq . qy . + q1 . qy . * rq . qw . + q1 . qz . * rq . qx . - q1 . qx . * rq . qz ; qz = q1 . qw . * rq . qz . + q1 . qz . * rq . qw . + q1 . qx . * rq . qy . - q1 . qy . * rq ... |
let normalise_vector ( x , y , z ) = let len = sqrt ( x . * x . + y . * y . + z . * z ) in ( x . / len , y . / len , z . / len ) |
let mult_quaternion_vector q vec = let vn_x , vn_y , vn_z = normalise_vector vec in let vecQuat = { qx = vn_x ; qy = vn_y ; qz = vn_z ; qw = 0 . 0 ; } in let resQuat = mult_quaternion vecQuat ( getConjugate q ) in let resQuat = mult_quaternion q resQuat in ( resQuat . qx , resQuat . qy , resQuat . qz ) ; ; |
let quaternion_of_axis vec angle = let angle = angle . * 0 . 5 in let vn_x , vn_y , vn_z = normalise_vector vec in let sinAngle = sin angle in { qx = vn_x . * sinAngle ; qy = vn_y . * sinAngle ; qz = vn_z . * sinAngle ; qw = cos angle ; } ; ; |
let piover180 = 3 . 14159265358979312 . / 180 . 0 |
let quaternion_of_euler ~ pitch ~ yaw ~ roll = let p = pitch . * piover180 . / 2 . 0 and y = yaw . * piover180 . / 2 . 0 and r = roll . * piover180 . / 2 . 0 in let sinp = sin p and siny = sin y and sinr = sin r and cosp = cos p and cosy = cos y and cosr = cos r in let q = { qx = sinr . * cosp . * cosy . - cosr . * sin... |
let matrix_of_quaternion quat = let x = quat . qx and y = quat . qy and z = quat . qz and w = quat . qw in let x2 = x * x and y2 = y * y and z2 = z * z and xy = x * y and xz = x * z and yz = y * z and wx = w * x and wy = w * y and wz = w * z in [ | 1 . 0 - 2 . 0 * ( y2 + z2 ) ; 2 . 0 * ( xy - wz ) ; 2 . 0 * ( xz + wy )... |
let axisAngle_of_quaternion quat = let x = quat . qx and y = quat . qy and z = quat . qz and w = quat . qw in let scale = sqrt ( x * x + y * y + z * z ) in let axis = ( x / scale , y / scale , z / scale ) and angle = ( acos w ) * 2 . 0 in ( axis , angle ) ; ; |
let vectors_add ( x1 , y1 , z1 ) ( x2 , y2 , z2 ) = ( x1 + x2 , y1 + y2 , z1 + z2 ) object ( s ) val mutable pos = ( 0 . 0 , 0 . 0 , 0 . 0 ) val mutable rotation = identity_quaternion ( ) val mutable xrot = 0 . 0 val mutable yrot = 0 . 0 val mutable xmov = 0 . 0 val mutable ymov = 0 . 0 val mutable zmov = 0 . 0 val mut... |
let _ = if Array . length Sys . argv <> 2 then failwith ( " usage : " ^ Sys . argv . ( 0 ) ^ " < size " ) > |
let n = match int_of_string Sys . argv . ( 1 ) with | exception _ -> failwith " size should be a number " | n when n <= 0 -> failwith " size should be greater than 0 " | n -> n |
let fold_and i j f = let rec mk k = if k > j then one else mk_and ( f k ) ( mk ( k + 1 ) ) in mk i |
let fold_or i j f = let rec mk k = if k > j then zero else mk_or ( f k ) ( mk ( k + 1 ) ) in mk i |
let fold_for i j f = let rec fold k acc = if k > j then acc else fold ( k + 1 ) ( f k acc ) in fold i |
let fold_for_rev i j f = let rec fold k acc = if k < j then acc else fold ( k - 1 ) ( f k acc ) in fold i |
let vars = Array . init n ( fun i -> Array . init n ( fun j -> mk_var ( 1 + n * i + j ) ) ) |
let var i j = vars . ( i ) . ( j ) |
let queens_s i j = let var i j = mk_var ( 1 + i * n + j ) in fold_for_rev ( n - 1 ) 0 ( fun row bdd -> if i = row then fold_for_rev ( n - 1 ) 0 ( fun col bdd -> if j = col then mk_and bdd ( var row col ) else mk_and bdd ( mk_not ( var row col ) ) ) bdd else let d = abs ( i - row ) in let bdd = if j + d < n then mk_and ... |
let queens_r i = fold_for 0 ( n - 1 ) ( fun j bdd -> mk_or bdd ( queens_s i j ) ) zero |
let bdd = fold_for 0 ( n - 1 ) ( fun i bdd -> mk_and bdd ( queens_r i ) ) one |
let ( ) = printf " There are % d solutions . " @ ( count_sat_int bdd ) |
let ( ) = exit 0 |
let ( ) = let print v ( tl , e , sum , smallest , median , biggest ) = printf " v =% d : size =% d # entries =% d sum =% d small / med / big =% d /% d /% d . " @ v tl e sum smallest median biggest in Array . iteri print ( stats ( ) ) |
let n = try int_of_string Sys . argv . ( 1 ) with _ -> 8 |
let rec safe queen diag xs = match xs with | [ ] -> true | q :: qs -> queen <> q && queen <> q + diag && queen <> q - diag && safe queen ( diag + 1 ) qs |
type _ Effect . t += Pick : int -> int Effect . t |
let rec find_solution n col : int list = if col = 0 then [ ] else begin let sol = find_solution n ( col - 1 ) in let queen = perform ( Pick n ) in if safe queen 1 sol then queen :: sol else raise Fail end |
let queens_count n = match_with ( find_solution n ) n { retc = ( fun _ -> 1 ) ; exnc = ( function Fail -> 0 | e -> raise e ) ; effc = fun ( type a ) ( e : a Effect . t ) -> match e with | Pick n -> Some ( fun ( k : ( a , _ ) continuation ) -> let rec loop i acc = if i = n then ( continue k i + acc ) else loop ( i + 1 )... |
let queens_choose n = match_with ( find_solution n ) n { retc = ( fun x -> [ x ] ) ; exnc = ( function Fail -> [ ] | e -> raise e ) ; effc = fun ( type a ) ( e : a Effect . t ) -> match e with | Pick n -> Some ( fun ( k : ( a , _ ) continuation ) -> let rec loop i acc : int list list = if i = 1 then ( continue k i @ ac... |
let print_all_solutions ( ) = let sols = queens_choose n in List . iter ( fun l -> List . iter ( fun pos -> Printf . printf " % d " pos ) l ; print_endline " " ) sols |
let _ = print_all_solutions ( ) ; Printf . printf " % d \ n " ( queens_count n ) |
type ' a lval = | Val of ' a | Delayed of ( unit -> ' a ) ; ; |
let force = function | Val v -> v | Delayed f -> f ( ) ; ; |
type ' a llist = | Nil | Cons of ' a lcell |
let ( *::* ) x y = Cons { hd = Delayed x ; tl = Delayed y } ; ; |
let ( -::* ) x y = Cons { hd = Val x ; tl = Delayed y } ; ; |
let ( -::- ) x y = Cons { hd = Val x ; tl = Val y } ; ; |
let ( --::* ) x y = Cons { hd = x ; tl = Delayed y } ; ; |
let ( --::-- ) x y = Cons { hd = x ; tl = y } ; ; |
let force_hd = function | Cons { hd = Val v } -> v | Cons ( { hd = lv } as c ) -> let v = force lv in c . hd <- Val v ; v | Nil -> failwith " force_hd " ; ; |
let force_tl = function | Cons { tl = Val v } -> v | Cons ( { tl = lv } as c ) -> let v = force lv in c . tl <- Val v ; v ; | Nil -> failwith " force_tl " ; ; |
let force_hd = function | { hd = Val v } -> v | { hd = lv } as c -> let v = force lv in c . hd <- Val v ; v ; ; |
let force_tl = function | { tl = Val v } -> v | { tl = lv } as c -> let v = force lv in c . tl <- Val v ; v ; ; |
let rec map f = function | Nil -> Nil | Cons c -> f ( force_hd c ) -::* ( fun ( ) -> map f ( force_tl c ) ) ; ; |
let rec iter f = function | Nil -> ( ) | Cons c -> f ( force_hd c ) ; iter f ( force_tl c ) ; ; |
let rec length = function | Nil -> 0 | Cons c -> 1 + length ( force_tl c ) ; ; |
let rec interval n m = if n > m then Nil else n -::* ( fun ( ) -> interval ( n + 1 ) m ) ; ; |
let rec rev_append l1 l2 = match l1 with | Nil -> l2 | Cons { hd = x ; tl = l } -> x --::* ( fun ( ) -> rev_append ( force l ) l2 ) ; ; |
let rec filter_append p l l0 = match ( l : ' a llist ) with | Nil -> l0 | Cons c -> let x = force_hd c in if p x then x -::* ( fun ( ) -> filter_append p ( force_tl c ) l0 ) else filter_append p ( force_tl c ) l0 ; ; |
let rec concmap f = function | Nil -> Nil | Cons c -> f ( force_hd c ) ( concmap f ( force_tl c ) ) ; ; |
let rec safe x d = function | Nil -> true | Cons { hd = h ; tl = t } -> let h = force h in x <> h && x <> h + d && x <> h - d && safe x ( d + 1 ) ( force t ) ; ; |
let rec ok = function | Nil -> true | Cons { hd = h ; tl = t } -> safe ( force h ) 1 ( force t ) ; ; |
let find_solutions size = let line = interval 1 size in let rec gen n size = if n = 0 then Nil -::- Nil else concmap ( fun b -> filter_append ok ( map ( fun q -> q -::- b ) line ) ) ( gen ( n - 1 ) size ) in gen size size ; ; |
let print_solutions size solutions = let sol_num = ref 1 in iter ( fun chess -> Printf . printf " \ nSolution number % i \ n " ! sol_num ; sol_num := ! sol_num + 1 ; iter ( fun line -> let count = ref 1 in while ! count <= size do if ! count = line then print_string " Q " else print_string " - " ; count := ! count + 1 ... |
let print_number_of_solutions size sols = let sol_num = length sols in Printf . printf " The % i queens problem has % i solutions . \ n " size sol_num ; ; |
let print_result size = let sols = find_solutions size in print_number_of_solutions size sols ; print_newline ( ) ; let pr = print_string " Do you want to see the solutions < n / y > ? " ; read_line ( ) in if pr = " y " then print_solutions size sols ; ; |
let queens ( ) = let size = print_string " Chess boards ' s size ? " ; read_int ( ) in print_result size ; ; let size = if Array . length Sys . argv <> 2 then 8 else ( int_of_string Sys . argv . ( 1 ) ) in let sols = find_solutions size in print_number_of_solutions size sols ; ; |
let map f l = let rec loop accu = function | [ ] -> accu | x :: l -> loop ( f x :: accu ) l in loop [ ] l ; ; |
let rec interval n m = if n > m then [ ] else n :: interval ( n + 1 ) m ; ; |
let rev_append l1 l2 = let rec loop accu = function | [ ] -> accu | h :: t -> loop ( h :: accu ) t in loop l2 l1 ; ; |
let filter_append p l l0 = let rec loop accu = function | [ ] -> accu | h :: t -> if p h then loop ( h :: accu ) t else loop accu t in let rev_res = loop [ ] l in rev_append rev_res l0 ; ; |
let concmap f l = let rec loop accu = function | [ ] -> accu | h :: t -> loop ( f h accu ) t in loop [ ] l ; ; |
let rec safe x d = function | [ ] -> true | h :: t -> x <> h && x <> h + d && x <> h - d && safe x ( d + 1 ) t ; ; |
let rec ok = function | [ ] -> true | h :: t -> safe h 1 t ; ; |
let find_solutions size = let line = interval 1 size in let rec gen n size = if n = 0 then [ [ ] ] else concmap ( fun b -> filter_append ok ( map ( fun q -> q :: b ) line ) ) ( gen ( n - 1 ) size ) in gen size size ; ; |
let print_solutions size solutions = let sol_num = ref 1 in iter ( fun chess -> Printf . printf " \ nSolution number % i \ n " ! sol_num ; sol_num := ! sol_num + 1 ; iter ( fun line -> let count = ref 1 in while ! count <= size do if ! count = line then print_string " Q " else print_string " - " ; count := ! count + 1 ... |
let print_result size = let solutions = find_solutions size in let sol_num = List . length solutions in Printf . printf " The % i queens problem has % i solutions . \ n " size sol_num ; print_newline ( ) ; let pr = print_string " Do you want to see the solutions < n / y > ? " ; read_line ( ) in if pr = " y " then print... |
let queens ( ) = let size = print_string " Chess boards ' s size ? " ; read_int ( ) in print_result size ; ; |
module ID = struct module I = IntDomain . IntDomTuple include Lattice . Lift ( I ) ( Printable . DefaultNames ) let lift op x = ` Lifted ( op x ) let unlift op x = match x with | ` Lifted x -> op x | _ -> failwith " Queries . ID . unlift " let bot_of = lift I . bot_of let top_of = lift I . top_of let of_int ik = lift (... |
module LS = SetDomain . ToppedSet ( Lval . CilLval ) ( struct let topname = " All " end ) |
module TS = SetDomain . ToppedSet ( CilType . Typ ) ( struct let topname = " All " end ) |
module ES = SetDomain . Reverse ( SetDomain . ToppedSet ( CilType . Exp ) ( struct let topname = " All " end ) ) |
module LiftedExp = Lattice . Flat ( CilType . Exp ) ( struct let top_name = " Top " let bot_name = " Unreachable " end ) |
module VI = Lattice . Flat ( Basetype . Variables ) ( struct let top_name = " Unknown line " let bot_name = " Unreachable line " end ) |
type iterprevvar = int -> ( MyCFG . node * Obj . t * int ) -> MyARG . inline_edge -> unit |
type itervar = int -> unit |
let compare_itervar _ _ = 0 |
let compare_iterprevvar _ _ = 0 |
type maybepublic = { global : CilType . Varinfo . t ; write : bool } [ @@ deriving ord , hash ] |
type maybepublicwithout = { global : CilType . Varinfo . t ; write : bool ; without_mutex : PreValueDomain . Addr . t } [ @@ deriving ord , hash ] |
type mustbeprotectedby = { mutex : PreValueDomain . Addr . t ; global : CilType . Varinfo . t ; write : bool } [ @@ deriving ord , hash ] |
type memory_access = { exp : CilType . Exp . t ; var_opt : CilType . Varinfo . t option ; kind : AccessKind . t } [ @@ deriving ord , hash ] |
type access = | Memory of memory_access | Point |
type invariant_context = { scope : CilType . Fundec . t ; lval : CilType . Lval . t option ; offset : CilType . Offset . t ; } |
type _ t = | EqualSet : exp -> ES . t t | MayPointTo : exp -> LS . t t | ReachableFrom : exp -> LS . t t | ReachableUkTypes : exp -> TS . t t | Regions : exp -> LS . t t | MayEscape : varinfo -> MayBool . t t | MayBePublic : maybepublic -> MayBool . t t | MayBePublicWithout : maybepublicwithout -> MayBool . t t | MustB... |
type ' a result = ' a |
type ask = { f : ' a . ' a t -> ' a result } |
module Result = struct let lattice ( type a ) ( q : a t ) : ( module Lattice . S with type t = a ) = match q with | EqualSet _ -> ( module ES ) | CondVars _ -> ( module ES ) | MayPointTo _ -> ( module LS ) | ReachableFrom _ -> ( module LS ) | Regions _ -> ( module LS ) | MustLockset -> ( module LS ) | EvalFunvar _ -> (... |
type any_query = Any : ' a t -> any_query |
module Any = struct type t = any_query let order = function | Any ( EqualSet _ ) -> 0 | Any ( MayPointTo _ ) -> 1 | Any ( ReachableFrom _ ) -> 2 | Any ( ReachableUkTypes _ ) -> 3 | Any ( Regions _ ) -> 4 | Any ( MayEscape _ ) -> 5 | Any ( MayBePublic _ ) -> 7 | Any ( MayBePublicWithout _ ) -> 8 | Any ( MustBeProtectedB... |
let _debug = ref false |
let ( ) = Lexer . init ( ) |
type q = | Path of out_ident | Path_type of out_ident * out_type | Type of out_type |
type t = k option * q |
let parse_as_type s = try let lexbuf = Lexing . from_string s in let core_type = Parse . core_type lexbuf in Some ( Type ( Coretype . out_of_core_type core_type ) ) with | _ -> None |
let parse_as_path_type s = try let s = " ( " ^ s ^ " ) " in let lexbuf = Lexing . from_string s in let e = Parse . expression lexbuf in match e . pexp_desc with | Pexp_constraint ( { pexp_desc = Pexp_ident { txt = lid } } , ty ) -> Some ( Path_type ( Coretype . out_of_longident lid , Coretype . out_of_core_type ty ) ) ... |
let parse_as_wildcard_colon_type s = try let s = " ( x " ^ s ^ " ) " in let lexbuf = Lexing . from_string s in let e = Parse . expression lexbuf in match e . pexp_desc with | Pexp_constraint ( { pexp_desc = Pexp_ident { txt = Lident " x_ " } } , ty ) -> Some ( Type ( Coretype . out_of_core_type ty ) ) | _ -> None with ... |
let parse_path s = let f s = try let s = " ( " ^ s ^ " : int ) " in let lexbuf = Lexing . from_string s in let e = Parse . expression lexbuf in match e . pexp_desc with | Pexp_constraint ( ( { pexp_desc } as _e ) , _ty ) -> begin match pexp_desc with | Pexp_ident { txt = lid } -> Some ( Path ( Coretype . out_of_longide... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.