fvutils / pyvsc

Python packages providing a library for Verification Stimulus and Coverage
https://fvutils.github.io/pyvsc
Apache License 2.0
113 stars 26 forks source link

Is there a way to construct a logarithm constraint? #214

Closed kangshuo1 closed 6 months ago

kangshuo1 commented 6 months ago

Hello! I'm wondering if there is a way to construct a constraint that expresses a logarithmic relationship. Such as

@vsc.constraint def ab_c(self): self.a == vsc.clog2(self.b)

Can this function be implemented based on existing models? Looking forward to your reply

mballance commented 6 months ago

Hi @kangshuo1, clog2 as a constraint on a random variable/expression is typically implemented by the solver. We can implement a simple (likely slower) version using PyVSC's ability to generate constraints procedurally. The thing to remember is that clog2 is answering the question "how many bits is required to represent N value combinations?".

I added a small test to implement the clog2 constraint here:

https://github.com/fvutils/pyvsc/blob/6b8b9e8dc13477078c850b3408c78f7206dc2f52/ve/unit/test_constraint_functions.py#L6-L34

If you're finding that you need the clog2 constraint, please add an enhancement request for PyVSC to implement this.

-Matthew

kangshuo1 commented 6 months ago

Thanks for your reply, it's very helpful to me