0

I'm trying to compute the abstraction of the following C code fragment, with the predicate: b: { x >= 0 }

1. if( x > 5 )
2.   x = x - 2;
3. else
4.   x = abs( x ) + 6;
5. assert( x >= 0 );

so far I abstracted:

1. if( * ) // not sure if I should put if( b ) here
2.   assume( b ); b = true;
3. else
4.   assume( true ); // ? don't know how to abstract further
5. assert( b )

Any ideas how to do this ?

Maputo
  • 963
  • 1
  • 10
  • 22
  • In the second code, line 2. Shouldn't there be a block around the two statements? – Lyubomir Vasilev Aug 22 '12 at 18:59
  • @Papergay:- You forgot `true`. – perilbrain Aug 22 '12 at 19:08
  • I do not think the abstraction is C code; I think it is intended to be statements in a formal logic used to reason about programs. The question is not clear. – Eric Postpischil Aug 22 '12 at 19:11
  • @LyubomirVasilev: There should be normally, but this is abstracted code, it's not to be compiled, so I think it's irrelevant whether there are braces or not. – Maputo Aug 22 '12 at 19:11
  • Clarification: This sort of abstraction is used by the SLAM tools. The result of the abstraction of the above C code fragment should be a boolean program, and this is in turn a C program in which all variables have boolean type. – Maputo Aug 22 '12 at 19:30

1 Answers1

0

I dont know whether I am understanding you correct or not, but for the set of input predicate {x>=0} or b (used alternatively).It should be:-

{x>=0}=unknown()   //unknown function is used to generate true or false non-deterministically

if(*)
{
 assume({x>=0});
 {x>=0}=true;
}
else
{
 assume(!{x>=0});
 {x>=0}=false;
}
perilbrain
  • 7,961
  • 2
  • 27
  • 35
  • But if you compute `abs(x) + 6` under the condition that `x <= 5`, then `x >= 0`, therefore shouldn't `{x>=0} = true`? – Maputo Aug 22 '12 at 19:53
  • No, no, the condition x<=5 comes from the x>5. If !(x>5) then it has to be x<=5, right? If we then take concrete values, say x = 3, then the else branch would trigger, and x = abs(3) + 6 would satisfy x >= 0... – Maputo Aug 22 '12 at 20:08
  • I think it should go something like this: `if( * ) {` `assume( b ); b = b? * : false;` `}` `else` `b = true;` `assert( b );` What do you think ? – Maputo Aug 22 '12 at 21:22