Why are the bits inverted in one's complement? [closed] - twos-complement

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
When storing a negative number with one's complement before you add the 1 for two's complement, why are all the bits other than the sign inverted? I suppose It would just be simpler if the only thing different was the sign. The only reason I can think of is it somehow make it easier for the computer.

Because that what one's complement is defined to do. See http://en.wikipedia.org/wiki/Signed_number_representations

See, for example, http://en.wikipedia.org/wiki/One%27s_complement, or other sources a quick google can give you.
Basically, yes, it makes addition and subtraction easier to implement compared to sign magnitude numbers (though 2's complement makes maths even easier).

Related

Programs/Calculators to Minimize Regular Expressions [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I was just wondering if there is any free software out there that is able to effectively minimize regular expressions.
You see this question being asked a lot but I haven't seen an effective one anywhere. If you think though the logic required just to simplify something simple like character ranges in a character class - and the fairly low value of doing something like that I think the lack of these begins to make sense.
As another example, how do you remove unneeded groupings when you don't know how they might be used in a replacement string. I would think any simplification that could be achieved would be mostly superficial.
This guy wrote one in Haskell but didn't share: http://community.haskell.org/~ndm/resimplify/
(PS: I sort of lied - there is one effective Regex simplification tool... The mechanical turk that is Stack Overflow :)
I think I found one located here: http://regexvisualizer.apphb.com/?Regex=%28a%2Bb%2Bc%2B%29%2B%7Cabc&NfaSize=300&DfaSize=250#

Is doing a square root once slower than squaring n times? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I was just looking at some algorithms for prime numbers and came across this:
for(int i=2;i*i <= n;i++)
{/*assume no operations here*/}
I was just wondering if the above loop will be faster than the following or not?
int x=sqrt(n);
for(int i=2;i<=x;i++)
{/*nop*/}
It depends on the value of n, of course. Anyway, sqrt() is not guaranteed to give you the right result: due to rounding reasons, you might end up with a value of x which is one less than expected and ruin the algorithm. Rather than going for a micro-optimisation, I would stick to correctness here and use the original version, which is guaranteed to give correct results.

How helpful is memorizing Clojure.core [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've used Clojure for about 2 years now (having used scheme/lisp before that).
I'm getting to the point where I feel like I'm not learning more clojure "by osmosis" and am considering using a conscious effort to memorize the function names in Clojure.core
Question:
Has anyone else done this? If so, has it been a significant productivity boost?
I'm afraid that just having a function memorized is not enough to spot the need to use it when it is needed. It is better to learn in context - for example by solving the 4clojure problems and then looking at solutions by users with high scores. Once you have a function in context, then you can memorize it.

Equation Parsing Library C++ [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I'm sure there must be something like this somewhere but I can't seem to find anything useful on here or Google. I had hoped Boost might have something but alas not.
What I'm after is a lightweight library that can take a string from the user, for example "y=2x+3" and parse it returning an object or function which returns y when given x.
Can anybody recommend something for this? (Worst case I could write one myself but no point reinventing the wheel and all.)
Things which can be assumed if necessary;
Preset variable names
Number of variables fixed
MuParser is all you ever could wish for. You can even define custom operators, store and evaluate the expressions in binary form, etc... Written in C++, bindings for C and C# (and maybe even other languages).

Are There Any Good C++ Suffix Trie Libraries? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Does anyone know of a really rock solid C++ library for suffix tries? Other than the one in Mummer?
Ideally, I'd like:
Some concept of concurrency.
Good caching behavior.
Permissive license.
Support for arbitrary alphabets.
Being a bioinformatician, my pick would be SeqAn (check out the sequence index section). It implements a lazy suffix tree and an enhanced suffix array (an equivalent data structure), both of which have good cache behaviour.
Having actually used and then forgotten PATL, I'd like to tuck in a link in an answer.
http://code.google.com/p/patl/
It's got a couple really distinct features, and is generally pleasant reading as well.
Most likely this is a tutorial but IMO worth reading and with source code: http://marknelson.us/1996/08/01/suffix-trees.