mirror of
https://github.com/LCPQ/quantum_package
synced 2024-12-23 12:56:14 +01:00
45 lines
519 B
OCaml
45 lines
519 B
OCaml
|
|
||
|
(*
|
||
|
Type for bits
|
||
|
==============
|
||
|
|
||
|
Zero | One
|
||
|
|
||
|
*)
|
||
|
|
||
|
type bit =
|
||
|
| One
|
||
|
| Zero
|
||
|
|
||
|
let to_string = function
|
||
|
| Zero -> "0"
|
||
|
| One -> "1"
|
||
|
;;
|
||
|
|
||
|
let and_operator a b =
|
||
|
match a, b with
|
||
|
| Zero, _ -> Zero
|
||
|
| _, Zero -> Zero
|
||
|
| _, _ -> One
|
||
|
;;
|
||
|
|
||
|
let or_operator a b =
|
||
|
match a, b with
|
||
|
| One, _ -> One
|
||
|
| _, One -> One
|
||
|
| _, _ -> Zero
|
||
|
;;
|
||
|
|
||
|
let xor_operator a b =
|
||
|
match a, b with
|
||
|
| One, Zero -> One
|
||
|
| Zero, One -> One
|
||
|
| _, _ -> Zero
|
||
|
;;
|
||
|
|
||
|
let not_operator = function
|
||
|
| One -> Zero
|
||
|
| Zero -> One
|
||
|
;;
|
||
|
|