Implication operator constraint is not bi directional

152 views
Skip to first unread message

Raj Pednekar

unread,
Apr 3, 2022, 11:48:50 PM4/3/22
to EDA Playground
https://www.edaplayground.com/x/j7K7

My code is here wanted to test some basic randomizations. (Constraints are bi directional)
I see that even with 

constraint a_b { (a == 0) -> b == 0; }

One of the solutions/o/p I am getting on printing is 
Value of a = 1, b = 0

Can it be explained.?

EDA Playground

unread,
Apr 4, 2022, 5:45:03 AM4/4/22
to EDA Playground
I don't think implication constraints are bi-directional. I think you constraint means

    "If a is 0, then b should be 0."

It does not mean "if b is 0 then a should be 0".

Raj Pednekar

unread,
Apr 11, 2022, 11:57:18 PM4/11/22
to EDA Playground
Implication operators constraints are bi-directional.
"If a is 0, then b will be 0. and if b=0 a will be 0"
I went through the SV LRM it mentions it as well.
on pg 164 for LRM 22nov 2005
bi_directional.PNG

EDA Playground

unread,
Apr 12, 2022, 3:56:39 AM4/12/22
to EDA Playground
I' not sure I understand what is says in the LRM, because I don't think 

  constraint a_b { (a == 0) -> b == 0; }

constrains a to be 0 if b is 0. If I add this constraint, too:

  constraint b_a { (b == 0) -> a == 0; }

then 

Value of a = 1, b = 0

never occurs. I will ask my colleagues to see if they can shed any light on it. But, I think you need both constraints.

EDA Playground

unread,
Apr 12, 2022, 4:26:30 AM4/12/22
to EDA Playground
So, a colleague replied to say this:

In maths:
  •  B is bidirectional, in the sense that it is formally equivalent to !B  !A
  • ⇒ B is not bidirectional, in the sense that it is NOT equivalent to B  A
In other words, if "A is true then B must be true" is bidirectional because if B is false then A must be false.  But, you cannot also say that "if B is true then A must be true".  And the same goes for SystemVerilog syntax such as

    constraint a_b { (a == 0) -> b == 0; }

We can say 

  • if a is 0 then b is 0 and
  • if b is not 0 then a is not 0  (that is what is meant by "bidirectional" in the LRM)

but we cannot say

  • if b is 0 then a is 0

Raj Pednekar

unread,
Apr 13, 2022, 12:06:00 PM4/13/22
to EDA Playground
Oh. I cleared a major misunderstanding. Thanks
Reply all
Reply to author
Forward
0 new messages