9-bit subtraction using 9-bit adder - boolean

I've learnt from a CS book that
If we try to perform a 9-bit subtraction using a 9-bit full adder, it will not(always) work.
The referenced logic circuit is supposed to be an extended version of this:
8-bit adder
I was curious to know why it wouldn't work, and if there are any examples to support this statement. I've searched this topic in numerous search engines but found no resource regarding this. Could you please provide the answer to this question?

To use an adder for subtraction, you have to complement the second operand and add one:
A - B = A + ~B + 1
The increment by one can cause an overflow.
Wikipedia article.

Related

Boolean expression simplification

I am trying to simplify a Boolean expression with exactly 39 inputs, and about 500 million - 800million terms (as in that many and/not/or statements).
A perfect simplification is not needed, but a good one would be nice.
I am aware of the K-maps , Quine–McCluskey, Espresso algorithms. However I am also aware that these mechanisms would take way too long to simplify a circuit of this size based on what I have read
I would need to simplify this expression as much as possible within a 24 hour period.
After google searching, I find it difficult to find any resources for attempting to simplify a machine of quite this magnitude! Any resources out there or a library out there that can attempt to at least simplify this to some extent within a 24 time period?
A greedy heuristic Simplify is described in the somewhat dated book
Robert K. Brayton , Gary D. Hachtel , C. McMullen , Alberto Sangiovanni-Vincentelli
Logic Minimization Algorithms for VLSI Synthesis
You can find the chapter online.
Simplify is based on the unate paradigm. In divide-and-conquer style, it recursively applies Shannon's expansion theorem to split the function into smaller sub-functions. The heuristic rule is to split by the most binate variable first, i.e. the variable which separates the largest number of terms.
A second approach could be to use graph partitioning tools like METIS to split the terms into independent (or at least loosely related) subsets. But I am not aware that this has been tried sucessfully for logic synthesis tasks. My favorite search engine is sceptical and does not return any hits.
A more recent algorithm based on Binary Decision Diagrams was published in
Olivier Coudert: Doing Two-Level Logic Minimization 100 Times Faster
The paper lists examples with very high number of terms similar to your task at hand.
A somewhat related simplification technique BDD Sweeping as described in A Study of Sweeping Algorithms in the Context of Model Checking.
This is a duplicate question. See https://stackoverflow.com/a/60535990/1531728 for resources about logic optimization, or simplication of boolean expressions.

how do I convert a base ten representation to its equivalent two's complement in 7 bit?

how do I convert a base ten representation to its equivalent two's complement in 7 bit?
I am learning applications of discrete mathematics and this is one of the questions, being new to this, I just don't understand
your question lacks some details, especially concerning the environment in which you are working. Do you want to do it by hand or in a specific programming language? What steps did you take to solve the problem by yourself? If you did so, why didn't they answer your question?
Please read more about asking question at https://stackoverflow.com/help/how-to-ask
Furthermore you are asking two separable questions.
All of this contributes to your negative score.
To convert from 10-base to 2-base 2-complement, convert 10-base to 2-base 1-complement and from there to 2-base 2-complement.
From your second question I deduct you have been working on your problem. So I think you already know http://en.wikipedia.org/wiki/Two%27s_complement#From_the_ones.27_complement. There is also a nice example.
Flipping a bit means using the NOT-operation on the bit, simply said: turn a 0 into 1 and vice versa. Adding one means increasing the value of the numer by one.

how can I do a *= operator in matlab

I'm trying to do in Matlab:
X = X*-1;
this syntax is a bit annoying, is there a way to do this some other way (like in c++ : x*=-1)
Thank you
Unfortunately there are no increment and compound assignment operators in Matlab. I also remember reading posts by employees at Mathworks saying that they don't intend to add such operators to Matlab.
Steve Lord's reply to the following question illustrates the difficulties involved (way down, reply nr 10 or so): http://www.mathworks.com/matlabcentral/newsreader/view_thread/107451
There is another way! ;-)
X = -X;
Seriously though, I think it's just a matter of habit. There's nothing inherently wrong with that syntax, you are just used to do it differently.

Can linprog give an integer value of x's?

I have a linprog code that has x1,x2,x3 and x4 in the objective function.
The results I get give me values in the form:
x =
6.6667
0.0420
0
0
Which in the case I am trying to model doesn't make physical sense because the x's represent the number of units of a specific technology, and therefore for example 0.0420 doesn't in fact exist. Is there anyway to "force" linprog to find the optimum integer value of x?
Thank you
That's called integer programming and in general is NP-hard. It's not covered by linprog as it's a completely different and much harder problem.
Here's a related question (but not a duplicate) from Stack Overflow about Integer Programming.
You should consider using mixed-integer programming (you would get one when adding "integer constraints" like "x integer" to the linear program in linprog).
Straight forward I would recommend using Scip as it is "free" or Gams which is a commercial product but offers a free trial version for smaller instances.
A more detailed post on mixed integer programming and the correspondign solvers can be found at [scicomp][3]
[3]: https://scicomp.stackexchange.com/questions/2679/objects-in-buckets-assignment-optimization-problem "scicomp".

redundant encoding?

This is more of a computer science / information theory question than a straightforward programming one, so if anyone knows of a better site to post this, please let me know.
Let's say I have an N-bit piece of data that will be sent redundantly in M messages, where at least M-1 of those messages will be received successfully. I am interested in different ways of encoding the N-bit piece of data in fewer bits per message. (this is similar to RAID but at a much smaller level, where N = 8 or 16 or 32)
Example: suppose N = 16 and M = 4. Then I could use the following algorithm:
1st and 3rd message: send "0" + bits 0-7
2nd and 4th message: send "1" + bits 8-15
If I can guarantee that 3 messages of the 4 will get through, then at least one message from each group will get through. Thus I can make this work with 9 bits or less, there's probably a way to do this with fewer total bits but I'm not sure how.
Are there some simple encoding/decoding algorithms to do this kind of thing? Does this problem have a name? (if I know what it's called, I can google it!)
note: in my particular case, the messages either arrive correctly or do not arrive at all (no messages arrive with errors).
(edit: moved 2nd part to a separate question)
(Incomplete answer follows. I may add more later.)
The term you may be interested in is channel coding: adding redundancy to a source in order to make it robust during transmission over a noisy channel. In information theory, the complementary problem to channel coding is source coding: reducing the redundancy in a source to represent it using fewer bits. (The combination of these two problems is called joint source-channel coding.)
Your first question asks to find a channel code. The simple example you give is similar to a repetition code, i.e., you send the same message more than twice (usually an odd number of times), and then the message which is received most often is accepted as the original message.
This code is inefficient. To use standard notation, let k = number of bits in original message, and n = number of bits in the transmitted message. For your example, k = 16 and n = 36. A measure of coding efficiency is k/n, where higher means more efficient. In your case, k/n = 0.44. This is low.
The repetition code is a simple kind of block code, i.e., redundancy is added to each block of k bits to create a codeword of n bits. So are the Hamming and Reed-Solomon codes as others mentioned. Hamming codes are relatively easy to understand with some basic linear algebra.
These should be enough terms for you to search on your own. Good luck.
I'm not sure if I understood all the details of your question correctly, but your problem is definitely aboud designing some kind of error correcting code. This is a vast area of computer science and thick tomes have been written about it. Start with wikipedia and see if you can get any simple schemes (like Hamming or Reed-Solomon codes) to work in your case.
If you want to deal not only with symbol corruption, but also deletion of symbols, you should look at erasure codes, this is definitely a more difficult task but good methods exist in many cases.
EDIT: This material from hackersdelight.org seems a nice introduction.
See erasure codes.
You're looking for a packet erasure code. There are only two useful packet erasure codes that are not totally encumbered by patents, and there's only one open-source library to implement those. Find it here: http://planete-bcast.inrialpes.fr/rubrique.php3?id_rubrique=5
Here's a trivially simple scheme that's almost twice as efficient as your example.
You chopped the message into blocks of (N/M)*2 bits. Instead, chop it into N/(M-1)-bit blocks. (Round it up if necessary.) The first block, src[0], encodes as itself: enc[0]=src[0]. The same for the last block: enc[M-1]=src[M-1]. Each of the other blocks gets XORed with its left neighbor: enc[i]=src[i-1]^src[i].
Prefix each encoded block with a log(M)-bit sequence number, essentially as you did, so the receiver can tell which was dropped. (If you can be sure that whichever blocks arrive will arrive in order, then a 1-bit sequence number will do. Just alternate 0 and 1.)
To decode, successively XOR from the left and the right until you hit the dropped block. E.g. src[1] == enc[0]^enc[1]. (Dropping one of the endpoint blocks isn't a special case -- e.g. if the first block is dropped, the scan from the right recovers it, and the scan from the left is of length 0.)