1

I have a CSV file with values and I am currently formulating a propositional formulae.

Here is a sample:

 x=6,y=-5,z=4.
 6 = 110
-5 = 1101 
 4 = 100

My formulae:

( (x2 and x1 and not (x0)) and (y3 and y2 and not(y1) and y0) and (z2 and not(z1) and not(z0)) )

Now I generate a BDD with the same. If I want a human/embedded system to understand from my diagram 1101 could be represented as 13 or -5. Any negative number can have 2 representations. Is there any way that I can make it only to one?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Satarupa
  • 66
  • 8
  • "Any negative number can have 2 representations."... This part is not clear. Which two representations do you expect for -5? – meolic Dec 02 '20 at 14:54
  • what I meant is -5 and 13 represents the same in binary and suppose I provide the bdd to an embedded system and it reads all the bits, how it should concur it is -5 or 13 . – Satarupa Dec 02 '20 at 14:57
  • (a) That doesn't look like a CSV file to me. (b) You haven't tagged this with any languages. What language are you using? Even with that information, this isn't very clear. Please read [ask]. – ChrisGPT was on strike Dec 03 '20 at 15:49
  • Yes, I haven't tagged CSV(since it is huge and thought an example is sufficient for the relevancy of the question). I wanted to keep it language agnostic as programming language doesn't matter! but anyway thanks for the link – Satarupa Dec 03 '20 at 15:58
  • "as programming language doesn't matter!"—then your question is off-topic as too broad. We're here to answer _specific_ programming questions. – ChrisGPT was on strike Dec 03 '20 at 23:32
  • 1
    Considering this link https://stackoverflow.com/help/on-topic, my topic is related to bullet point 4 and not to specific programming languages. – Satarupa Dec 04 '20 at 00:07
  • 1
    An example of encoding signed integer arithmetic in two's complement representation: https://github.com/tulip-control/omega/blob/master/omega/logic/bitvector.py and the conversion of the resulting formulas to BDDs: https://github.com/tulip-control/omega/blob/master/omega/symbolic/bdd.py – 0 _ Dec 12 '20 at 20:40

1 Answers1

0

You have various possibilities. In the following, I mainly repeat the motivaton for two's complement representation of negative numbers (https://en.wikipedia.org/wiki/Two%27s_complement).

  1. use the same number of bits for all numbers, e.g. write all numbers with 8 bits and then use the first bit for the sign

     6 = 00000110
    -5 = 10000101 
     4 = 00000100
    

Number zero will have two representations: 00000000 and 10000000 (+0 and -0). If you use ZDDs (zero-suppressed BDDs) instead of ordinary ROBDDs you will get very compact representation.

  1. use the last bit for the sign, this would be very tricky for performing arithmetic, but not a problem for the representation.

     6 = 1100 (110 + 0)
    -5 = 1011 (101 + 1) 
     4 = 1000 (100 + 0)
    

You can set the rule, that the first (the left-most) bit must be always 1. In this case, number zero is uniquely represented as 1. ROBDDs will make this a compact representation.

  1. use two's complement, please note, that this requires fixing the number of bits, the same as in the first proposal
meolic
  • 1,177
  • 2
  • 15
  • 41
  • Fixing the number of bits is not necessary for arithmetic in two's complement. The padding can always be extended dynamically. – 0 _ Dec 12 '20 at 20:46