Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let (%) (a,b) c = (a*b) mod c ;;
- let print_list l = print_string "["; List.iteri (fun i x -> if i+1=List.length l then print_int x else
- (print_int x; print_string "; ")) l; print_string "]";;
- let print_list_of_lists l = List.iter (fun lt -> print_list lt; print_string "; \n") l ;;
- let rec repeat n(*раз*) x = if n<=0 then [] else x :: (repeat (n-1) x) ;;
- let classes n = List.mapi (fun i z1 -> (i,List.mapi (fun j z2 -> (i*j) mod (n)) (repeat n 0))) (repeat n 0) ;;
- let rec find_i (i,l) = match l with
- | [] -> []
- | (a,lst) :: t -> if a=i then lst else find_i (i,t) ;;
- let rec find x l = match l with
- | [] -> false
- | a :: b -> if a=x then true else find x b ;;
- let rec liberty l = match l with
- | [] -> []
- | -1 :: t -> liberty t
- | a :: b -> if find a b = true then liberty b else a :: (liberty b) ;;
- let generator l = let help () = List.map (fun (i,x) -> List.map (fun y ->
- if find i (find_i (y,l))=true then y else -1) x) l in (List.map (fun l -> liberty l) (help ())) ;;
- let rec nlib lst =
- match lst with
- | [] -> []
- | a :: b -> a@(nlib b) ;;
- print_string "Введите n : " ;;
- let n = read_int () ;;
- let all_classes_by_n = (generator (classes n));;
- let associativity l = List.for_all (fun (x,y,z) -> if (x,(y,z)%n)%n=((x,y)%n,z)%n then true else false)
- (nlib (List.map (fun a -> nlib (List.map (fun b -> List.map (fun c -> (a,b,c)) l) l)) l)) ;;
- let identity_element l = if (List.map (fun x -> if (List.exists (fun y -> if (x,y)%n=y then true else false) l) = true
- then x else -1) l) <> [] then true else false ;;
- let id_element l = let lst=liberty (List.map (fun x -> if (List.exists (fun y -> if (x,y)%n=y then true else false) l) = true
- then x else -1) l) in if lst=[] then -1 else List.nth lst 0 ;;
- let closure l = List.for_all (fun (x,y) -> find ((x,y)%n) l) (nlib (List.map (fun i -> List.map (fun j -> (i,j)) l) l)) ;;
- let inverse_element l = if identity_element l then List.for_all (fun a -> List.exists
- (fun b -> if (a,b)%n=(id_element l) then true else false) l) l
- else false ;;
- List.iter (fun classes_by_n -> print_list classes_by_n;
- let p1 = associativity classes_by_n in ( let p2 = identity_element classes_by_n in ( let p3 = closure classes_by_n in (
- let p4 = inverse_element classes_by_n in (
- if p1 then print_string "\t - Есть ассоциативность; " else print_string "\t - Ассоциативности нет; ";
- if p2 then print_string "\tЕсть нейтральный; " else print_string "\tНет нейтрального; ";
- if p3 then print_string "\tЕсть замкнутось; " else print_string "\tНет замкнутости; ";
- if p4 then print_string "\tЕсть обратимость; " else print_string "\tНет обратимости; ";
- if p1 && p2 && p3 && p4 then print_string "\tЭто группа\n" else print_string "\tЭто не группа\n"
- ) )))) all_classes_by_n ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement