@@ -189,8 +189,10 @@ module type CircuitInterface = sig
189189 val circuit_uninit : env -> ty -> circuit
190190 val circuit_has_uninitialized : circuit -> bool
191191
192- (* Circuit equivalence call, should do some processing and then call some backend *)
192+ (* Logical reasoning over circuits *)
193193 val circ_equiv : ?pcond : (cbool * (cinp list )) -> circuit -> circuit -> bool
194+ val circ_sat : circuit -> bool
195+ val circ_taut : circuit -> bool
194196
195197 (* Composition of circuit functions, should deal with inputs and call some backend *)
196198 val circuit_compose : circuit -> circuit list -> circuit
@@ -248,6 +250,8 @@ module type CBackend = sig
248250 val applys : (inp -> node option ) -> reg -> reg
249251 val circuit_from_spec : Lospecs.Ast .adef -> reg list -> reg
250252 val equiv : ?inps : inp list -> pcond :node -> reg -> reg -> bool
253+ val sat : ?inps : inp list -> node -> bool
254+ val taut : ?inps : inp list -> node -> bool
251255
252256 val slice : reg -> int -> int -> reg
253257 val insert : reg -> int -> reg -> reg
@@ -395,6 +399,16 @@ module TestBack : CBackend = struct
395399 let module BWZ = (val makeBWZinterface () ) in
396400 BWZ. circ_equiv ?inps (node_list_of_reg r1) (node_list_of_reg r2) pcond
397401
402+ let sat ?(inps : inp list option ) (n : node ) : bool =
403+ let open HL in
404+ let module BWZ = (val makeBWZinterface () ) in
405+ BWZ. circ_sat ?inps n
406+
407+ let taut ?(inps : inp list option ) (n : node ) : bool =
408+ let open HL in
409+ let module BWZ = (val makeBWZinterface () ) in
410+ BWZ. circ_taut ?inps n
411+
398412 let slice (r : reg ) (idx : int ) (len : int ) : reg =
399413 Array. sub r idx len
400414
@@ -1397,7 +1411,28 @@ module MakeCircuitInterfaceFromCBackend(Backend: CBackend) : CircuitInterface =
13971411 | `CBool b1 , `CBool b2 ->
13981412 Backend. equiv ~inps ~pcond: pcc (Backend. reg_of_node b1) (Backend. reg_of_node b2)
13991413 | _ -> false
1414+
1415+ let circ_sat (c : circuit ) : bool =
1416+ let `CBool c, inps = cbool_of_circuit ~strict: false c in
1417+ let inps = List. map (function
1418+ | { type_ = `CIBool ; id } -> (id, 1 )
1419+ | { type_ = `CIBitstring w ; id } -> (id, w)
1420+ | { type_ = `CIArray (w1 , w2 ); id } -> (id, w1* w2)
1421+ | { type_ = `CITuple szs ; id } -> (id, List. sum szs)
1422+
1423+ ) inps in
1424+ Backend. sat ~inps c
14001425
1426+ let circ_taut (c : circuit ) : bool =
1427+ let `CBool c, inps = cbool_of_circuit ~strict: false c in
1428+ let inps = List. map (function
1429+ | { type_ = `CIBool ; id } -> (id, 1 )
1430+ | { type_ = `CIBitstring w ; id } -> (id, w)
1431+ | { type_ = `CIArray (w1 , w2 ); id } -> (id, w1* w2)
1432+ | { type_ = `CITuple szs ; id } -> (id, List. sum szs)
1433+
1434+ ) inps in
1435+ Backend. taut ~inps c
14011436
14021437 module CircuitSpec = struct
14031438 let circuit_from_spec env (c : [`Path of path | `Bind of EcDecl.crb_circuit ] ) : [> `CBitstring of cbitstring_type] cfun =
@@ -1788,10 +1823,8 @@ let circuit_of_form
17881823 begin match EcFol. op_kind (destr_op f_ |> fst) with
17891824 | Some `True ->
17901825 hyps, (circuit_true :> circuit )
1791- (* hyps, {circ = BWCirc([C.true_]); inps=[]}*)
17921826 | Some `False ->
17931827 hyps, (circuit_false :> circuit )
1794- (* hyps, {circ = BWCirc([C.false_]); inps=[]}*)
17951828 | _ ->
17961829 let err = Format. sprintf " Unsupported op kind%s@." (EcPath. tostring pth) in
17971830 raise (CircError err)
@@ -1848,8 +1881,8 @@ let circuit_of_form
18481881 let cache = open_circ_lambda_cache env cache binds in
18491882 let hyps, circ = doit cache hyps f in
18501883 begin match qnt with
1851- | Llambda -> hyps, close_circ_lambda env binds circ
18521884 | Lforall
1885+ | Llambda -> hyps, close_circ_lambda env binds circ
18531886 | Lexists -> raise (CircError " Universal/Existential quantification not supported " )
18541887 (* TODO: figure out how to handle quantifiers *)
18551888 end
@@ -2078,6 +2111,9 @@ let circ_equiv ?(pcond: circuit option) c1 c2 =
20782111 in
20792112 circ_equiv ?pcond c1 c2
20802113
2114+ let circ_sat = circ_sat
2115+ let circ_taut = circ_taut
2116+
20812117let circuit_permute (bsz : int ) (perm : int -> int ) (c : circuit ) : circuit =
20822118 let c = match c with
20832119 | (`CBitstring r , inps ) as c -> c
0 commit comments