computation-theory

Left recursion elimination

一世执手 提交于 2019-12-02 08:35:30
I have this grammar S->S+S|SS|(S)|S*|a I want to know how to eliminate the left recursion from this grammar because the S+S is really confusing... Let's see if we can simplify the given grammar. S -> S*|S+S|SS|(S)|a We can write it as; S -> S*|SQ|SS|B|a Q -> +S B -> (S) Now, you can eliminate left recursion in familiar territory. S -> BS'|aS' S' -> *S'|QS'|SS'|e Q -> +S B -> (S) Note that e is epsilon/lambda. We have removed the left recursion, so we no longer have need of Q and B. S -> (S)S'|aS' S' -> *S'|+SS'|SS'|e You'll find this useful when dealing with left recursion elimination . My

Time complexity of a program which involves multiple variables

假如想象 提交于 2019-12-02 04:20:46
问题 I was recently asked to create a program to find best matches in text fragment. I have successfully written this program but I do have a question about its time complexity. Problem is defined as following. given a query, find occurrences of the query words in document and highlight the best tokens. The time that my program takes O(m + n + p) here m = length of the document in characters n = length of the query in characters p = number of total matches in the document In this case the biggest

What does the phrase “binds stronger” mean?

不羁的心 提交于 2019-12-02 00:19:07
I know this might be a newbie question, but I'm trying to make sense of this sentence(from a paper on a meta language that uses EBNF): Logical and (&) binds stronger than logical or (|). Before that it says: Conditions are: condition ::= condition (`&´ | `|´ ) condition | `!´ condition | relation relation ::= expression ( `=´ | `#´ | `<´ | `<=´ | `>´ | `>=´ ) expression thanks This refers to precedence . In other words, if you have A & B | C , you really have (A & B) | C . Operations with higher precedence/that bind stronger are evaluated first. 来源: https://stackoverflow.com/questions/16876455

Are GPU shaders Turing complete

北城以北 提交于 2019-12-01 15:42:53
I understand that complete GPUs are behemoths of computing - including every step of calculation, and memory. So obviously a GPU can compute whatever we want - it's Turing complete. My question is in regard to a single shader on various GPUs ("Stream Processor"/"CUDA Core"): Is it Turing complete? Can I (in theory) compute an arbitrary function over arbitrary inputs by using a single shader? I'm trying to understand at what "scale" of computation shaders live. Kamil Czerski Did You mean shader as a program used to compute shading? On wiki talk I found: (...)Shader models 1.x and 2.0 are indeed

Are GPU shaders Turing complete

爱⌒轻易说出口 提交于 2019-12-01 15:21:01
问题 I understand that complete GPUs are behemoths of computing - including every step of calculation, and memory. So obviously a GPU can compute whatever we want - it's Turing complete. My question is in regard to a single shader on various GPUs ("Stream Processor"/"CUDA Core"): Is it Turing complete? Can I (in theory) compute an arbitrary function over arbitrary inputs by using a single shader? I'm trying to understand at what "scale" of computation shaders live. 回答1: Did You mean shader as a

Is constexpr-based computation Turing complete?

淺唱寂寞╮ 提交于 2019-11-30 10:44:24
问题 We know that C++ template metaprogramming is Turing complete, but preprocessor metaprogramming is not. C++11 gives us a new form of metaprogramming: computation of constexpr functions. Is this form of computation Turing-complete? I am thinking that since recursion and the conditional operator (?:) are allowed in constexpr functions, it would be, but I would like someone with more expertise to confirm. 回答1: tl;dr: constexpr in C++11 was not Turing-complete, due to a bug in the specification of

Is C# 4.0 compile-time turing complete?

梦想与她 提交于 2019-11-30 09:34:19
There is a well-known fact that C++ templates are turing-complete , CSS is turing-complete (!) and that the C# overload resolution is NP-hard (even without generics). But is C# 4.0 (with co/contravariance, generics etc) compile-time turing complete ? Terrance Unlike templates in C++, generics in C# (and other .net lang) are a runtime generated feature. The compiler does do some checking as to verify the types use but, actual substitution happens at runtime. Same goes for Co and contravariance if I'm not mistaken as well as even the preprocessor directives . Lots of CLR magic. (At the

Construct grammar given the following language {a^n b^m | n,m = 0,1,2,…,n <= 2m} [closed]

我的未来我决定 提交于 2019-11-30 07:46:13
I just took my midterm but couldn't answer this question. Can someone please give a couple of examples of the language and construct a grammar for the language or at least show me how i will go about it? Also how to write grammar for L : L = {a n b m | n,m = 0,1,2,..., n <= 2m } ? Thanks in advance. Grijesh Chauhan How to write grammar for formal language? Before read my this answer you should read first: Tips for creating Context free grammars . Grammar for {a n b m | n,m = 0,1,2,..., n <= 2m } What is you language L = {a n b m | n,m = 0,1,2,..., n <= 2m } description? Language description :

Is constexpr-based computation Turing complete?

半城伤御伤魂 提交于 2019-11-29 22:08:56
We know that C++ template metaprogramming is Turing complete , but preprocessor metaprogramming is not . C++11 gives us a new form of metaprogramming: computation of constexpr functions. Is this form of computation Turing-complete? I am thinking that since recursion and the conditional operator (?:) are allowed in constexpr functions, it would be, but I would like someone with more expertise to confirm. Richard Smith tl;dr: constexpr in C++11 was not Turing-complete, due to a bug in the specification of the language, but that bug has been addressed in later drafts of the standard, and clang

Is C# 4.0 compile-time turing complete?

那年仲夏 提交于 2019-11-29 14:37:27
问题 There is a well-known fact that C++ templates are turing-complete, CSS is turing-complete (!) and that the C# overload resolution is NP-hard (even without generics). But is C# 4.0 (with co/contravariance, generics etc) compile-time turing complete ? 回答1: Unlike templates in C++, generics in C# (and other .net lang) are a runtime generated feature. The compiler does do some checking as to verify the types use but, actual substitution happens at runtime. Same goes for Co and contravariance if I