Coder Social home page Coder Social logo

Comments (2)

mballance avatar mballance commented on June 11, 2024

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:

class TestConstraintFunctions(VscTestCase):
def test_clog2(self):
import vsc
def clog2(lhs, rhs, nbits):
with vsc.implies((rhs >= 0) & (rhs < 2)):
lhs == 0
for i in range(1,nbits):
with vsc.implies(((rhs-1) >= (2**(i-1))) & ((rhs-1) < (2**i))):
lhs == i
@vsc.randobj
class C(object):
def __init__(self):
self.a = vsc.rand_bit_t(8)
self.b = vsc.rand_bit_t(8)
@vsc.constraint
def clog2_c(self):
clog2(self.a, self.b, 8)
c = C()
for i in range(256):
with c.randomize_with():
c.b == i
print("a=%d b=%d" % (c.a, c.b))

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

-Matthew

from pyvsc.

kangshuo1 avatar kangshuo1 commented on June 11, 2024

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

from pyvsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.