Case statement inside constraint

Hi, I want to use case statement inside a constraint, in my TB environment.
Can anyone say whether it works or not?

If not, then what are the alternative ways, other than if…else and implication operators?

In reply to venkata-srikanth:

This is a typical XY problem. A constraint is not procedural code, it is an equation. You need to show us your situation that makes you think you need a case statement and an implication is not adequate. Note that if/else is just an alternative syntax for an implication.

In reply to dave_59:

Hi Dave,
I will try explaining the situation.
I have two rand bits a and b with widths 3 and 8 respectively.
b value depends on a such that
constraint a_b
{
case(a)
0: b=8;
1: b=7;
2: b=6;
3: b=5;
4: b=4;
5: b=3;
6: b=2;
7: b=1;
8: b=0;
endcase
;
}

I want to implement this. When I try to run, this gave me a Syntax Error.

If using a case inside constraint is possible, can you please correct the error?

In reply to venkata-srikanth:

Can you think how you could express this with a one-line algebraic equation? No case, if/else, or implication needed.

In reply to dave_59:

Let me try,
when a is 0-8, length of b would be 8 bits - 0 bit.

Can you help me with this?

In reply to venkata-srikanth:

( 8 - a ) == b;

Note you need ‘a’ to be 4 bits wide to have the value ‘8’.