
Circuit optimization
In my computer science class, I learned about boolean circuit. I know how two onedigit inputs add or subtract and get one output or borrow or carry.But if you add two numbers that contain N binary digits rather than just one, what do you do? output is the sum. In order to use any boolean algebra identities, like distributive law, I have to first know their general formulas, For example, a=0,b=1,c=0, sum is 1, the sum of product is then not'a'*b*not'0'+.... etc. But I don't know the case here for N. Thank you.

My memory is dated, and I certainly don't want to give a full tutorial. Briefly, what you have been taught is probably a half adder. This circuit will sum two operands, yielding a sum and a carry.
You can make a full adder with two half adders. This circuit will have a carry input and a carry output that can be cascaded into another full adder.
This creates what is called a ripple adder, that is, the output isn't valid until the carrys all propagate to the last cell. But a look ahead adder can speed up this propagation. This is beyond the scope of your question
Do a search for half adders and full adders. Wikipedia has a reasonably comprehensive article.