computer-science

Determining Floating Point Square Root

▼魔方 西西 提交于 2019-11-30 03:55:34
问题 How do I determine the square root of a floating point number? Is the Newton-Raphson method a good way? I have no hardware square root either. I also have no hardware divide (but I have implemented floating point divide). If possible, I would prefer to reduce the number of divides as much as possible since they are so expensive. Also, what should be the initial guess to reduce the total number of iterations??? Thank you so much! 回答1: When you use Newton-Raphson to compute a square-root, you

Can call-with-current-continuation be implemented only with lambdas and closures?

谁说胖子不能爱 提交于 2019-11-30 03:39:11
Does anyone know if call/cc can be implemented with just lambdas and closures? It seems that call/cc interrupts the program's flow (like an exception) but lambdas and closures can't do that. Therefore I think call/cc can't be implemented via lambdas and closures. Any more ideas? The question is not particularly clear, since what exactly does "implemented with just lambdas and closures" mean? In any case, continuations can be used in any language with closures by manually writing in continuation passing style . Then automatic translation into this form can be implemented by extending the

What does it mean for two binary trees to be isomorphic?

拜拜、爱过 提交于 2019-11-30 03:16:35
What does it mean for two binary trees to be isomorphic? I've been looking online and I can't seem to find a clear explanation. As far as I understand, two trees are isomorphic if they have the same shape. So I'm guessing two identical trees which can contain different values in the nodes. Isomorphic comes from the Greek "same shape" (like isobar is points with the same air pressure and polygon means "many sided") so your understanding is correct. But don't make the mistake of assuming shape in this case is a physical shape (like the tree has one root, one left node and one right node; see

How can I determine if a language is context free or not?

北城以北 提交于 2019-11-30 02:02:41
How can I know whether the languages are context free or not? P Shved First, you should attempt to build a context-free grammar that forms the language in subject. A grammar is context-free if left-hand sides of all productions contain exactly one non-terminal symbol. By definition, if one exists, then the language is context-free. An equivalent construct would be a pushdown automaton . It's the same as DFA, but with a stack available. It may be easier to build than a grammar. However, if you fail to build a grammar or an automaton, it doesn't mean that a language is not context-free; perhaps,

How computer multiplies 2 numbers?

让人想犯罪 __ 提交于 2019-11-30 00:30:05
问题 How does a computer perform a multiplication on 2 numbers say 100 * 55. My guess was that the computer did repeated addition to achieve multiplication. Of course this could be the case for integer numbers. However for floating point numbers there must be some other logic. Note: This was asked in an interview. 回答1: Repeated addition would be a very inefficient way to multiply numbers, imagine multiplying 1298654825 by 85324154. Much quicker to just use long multiplication using binary. 1100100

What does “level of indirection” mean in David Wheeler's aphorism?

假装没事ソ 提交于 2019-11-29 20:41:20
I've read this quote in a book: There is no problem in computer science that can't be solved using another level of indirection. Can someone explain that? What does "level of indirection" mean? From what I understood, indirection is a fancy name for using a pointer of a value instead of the value itself. Please clarify this for me. "Indirection" is using something that uses something else, in its broadest sense. So your example, using a pointer of a value instead of the value, fits this definition at one level. The pointer is the something and the value is the something else. Typically this is

Understanding Neural Network Backpropagation

浪子不回头ぞ 提交于 2019-11-29 19:51:50
Update: a better formulation of the issue. I'm trying to understand the backpropagation algorithm with an XOR neural network as an example. For this case there are 2 input neurons + 1 bias, 2 neurons in the hidden layer + 1 bias, and 1 output neuron. A B A XOR B 1 1 -1 1 -1 1 -1 1 1 -1 -1 -1 (source: wikimedia.org ) I'm using stochastic backpropagation . After reading a bit more I have found out that the error of the output unit is propagated to the hidden layers... initially this was confusing, because when you get to the input layer of the neural network, then each neuron gets an error

What are practical guidelines for evaluating a language's “Turing Completeness”?

别来无恙 提交于 2019-11-29 19:40:44
I've read "what-is-turing-complete" and the wikipedia page, but I'm less interested in a formal proof than in the practical implications of being Turing Complete. What I'm actually trying to decide is if the toy language I've just designed could be used as a general-purpose language. I know I can prove it is if I can write a Turing machine with it. But I don't want to go through that exercise until I'm fairly certain of success. Is there a minimum set of features without which Turing Completeness is impossible? Is there a set of features which virtually guarantees completeness? (My guess is

What's a Turing machine?

蓝咒 提交于 2019-11-29 19:40:44
What is a Turing machine and why do people keep mentioning it? My IBM PC is all I need to do my computation! Why does anyone care about these machines? The reason that Turing Machines are a big deal has to do with the study of classical Computing Science or Theory of Computation type stuff. It's basically about analyzing the general properties of a computer, such as what theoretical abilities and limitations a computer has, as well as what we mean when we talk about "computing" something. One example of something that one might study using Turing Machines is The Halting Problem . While this

How do I implement graphs and graph algorithms in a functional programming language?

本小妞迷上赌 提交于 2019-11-29 19:36:48
Basically, I know how to create graph data structures and use Dijkstra's algorithm in programming languages where side effects are allowed. Typically, graph algorithms use a structure to mark certain nodes as 'visited', but this has side effects, which I'm trying to avoid. I can think of one way to implement this in a functional language, but it basically requires passing around large amounts of state to different functions, and I'm wondering if there is a more space-efficient solution. Antal Spector-Zabusky You might check out how Martin Erwig's Haskell functional graph library does things.