How to prove that "Total" is not recursive (decidable) [closed] - recursion

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Halt = { f,x | f(x)↓ } is re (semi-decidable) but undecidable
Total = { f | ∀x f(x)↓ } is non-re (not even semi-decidable)
I need some help in proving that the Total problem is not recursive (decidable).
I know the diagonalization proof for the Halting problem, I just need the same kind of proof for the Total problem. I'm posting the Halting Problem Proof for reference:
Halting Problem Proof
Assume we can decide the halting problem. Then there exists some total function Halt such
that
1 if [x] (y) is defined
Halt(x,y) =
0 if [x] (y) is not defined
Here, we have numbered all programs and [x] refers to the x-th program in this ordering. We
can view Halt as a mapping from ℵ into ℵ by treating its input as a single number
representing the pairing of two numbers via the one-one onto function
pair(x,y) = <x,y> = 2^x (2y + 1) – 1
with inverses
<z>1 = exp(z+1,1)
<z>2 = ((( z + 1 ) // 2^<z>1) – 1 ) // 2
Now if Halt exist, then so does Disagree, where
0 if Halt(x,x) = 0, i.e, if Φx (x) is not defined
Disagree(x) =
µy (y == y+1) if Halt(x,x) = 1, i.e, if Φx (x) is defined
Since Disagree is a program from ℵ into ℵ , Disagree can be reasoned about by Halt. Let d
be such that Disagree = Φd, then
Disagree(d) is defined ⇔ Halt(d,d) = 0 ⇔ Φd (d) is undefined ⇔ Disagree(d) is undefined
But this means that Disagree contradicts its own existence. Since every step we took was
constructive, except for the original assumption, we must presume that the original assumption was in error. Thus, the Halting Problem is not solvable.

Related

Formula to find square root of a natural number using only addition and subtraction [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
How to use only addition and subtraction to find out square root of a natural number?
Thanks.
[I have looked over the internet but i didn't find any content related to this problem.]
Explanation to my problem: I want to create a c function which will receive only a natural number and return square root of it.
You may say to use the "sqrt" function but i just thought of creating one which will utilize addition and subtraction operator to create the square root.
You don't have to write the program, just writing the formula for it will be just fine. Thanks.
Update: This question is not specifically about coding rather about mathematics.(I tagged "c" as it had some link but this question is NOT about coding.)
n2 is the equivalent of the sum of the n first odd numbers.
You can iterate over the n (consequently adding only the next odd number to the previously calculated sum) until the square is equal or exceeds your number.
k = 0
sum = 0
while sum < target:
k += 1
sum += 2k-1
if sum > target:
the target doesn't have integer root
else:
k is the square root
We can use the fact that (n+1)² = n² + 2n + 1.
def sqrt(n):
k = 0
s = 0
while s <= n:
s = s+k+k+1
k = k+1
return k-1
print (sqrt(0)) # 0^2
print (sqrt(1)) # 1^2
print (sqrt(2)) # (1.4142135623730951...)^2
print (sqrt(144)) # 12^2
print (sqrt(169)) # 13^2
print (sqrt(196)) # 14^2
print (sqrt(255)) # 15^2
print (sqrt(1000)) # (31.622776601683793...)^2
print (sqrt(2000)) # (44.721359549995796...)^2
UPD
Sorry, I thought you were asking for code :)

Can every recursion be converted to trees? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I wanted to know if there if any formal way of arguing in favor this. To be honest, I am not sure this is a good question but my purpose for asking is to know if we can always use trees as a mental model while thinking of recursion.
To paraphrase better, I want to know "Does every recursion formula correspond to a tree traversal?". Also, see my comments on Dirk's answer
The suggested duplicate question does not answer my question. My question has nothing to do with iteration.
When explaining recursion, tree traversal is a typical example. But, I would argue that not every recursion corresponds to a tree traversal:
In certain languages (lisp being one of them) recursion is used to realize iterations. There, you also have to express infinite loops with recursion, which I would assume does not fit your notion of "tree as mental model for recursion". (If you wonder how to implement an infinite loop with recursion and not run into stack overflows: There is a mechanism called tail call elimination which solves that problem.)
Below is recursive function which operates on integers, a non-tree-like input
const add = (x, y) =>
x + y
const sumTo = (x = 0) =>
x === 0
? x
: add (x, sumTo (x - 1))
console.log (sumTo ()) // 0
console.log (sumTo (1)) // 1
console.log (sumTo (2)) // 3
console.log (sumTo (4)) // 10
Yet it evolves a tree-like (recursive) computation – sumTo (4)...
add ( 4
, add ( 3
, add ( 2
, add ( 1
, 0
)
)
)
)
// => 10
A tail-recursive version has a different computational process, though. This is distinction is the same made by Dirk Herrmann (another answer here)
const add = (x, y) =>
x + y
const sumTo = (x = 0, acc = 0) =>
x === 0
? acc
: sumTo (x - 1, acc + x)
console.log (sumTo ()) // 0
console.log (sumTo (1)) // 1
console.log (sumTo (2)) // 3
console.log (sumTo (4)) // 10
In this case, when tail call elimination is available, sumTo (4) evolves an iterative computation
sumTo (3, 4)
sumTo (2, 7)
sumTo (1, 9)
sumTo (0, 10)
// => 10
So to answer your question, no. Recursive procedures (functions that reference themselves by their own name) may or may not evolve recursive processes.
This topic is talked about in Structure and Interpretation of Computer Programs, section 1.2.1

Fibonacci sequence in solving an equation

Im trying to figure out an equation. This is f(n)=f(n-1) + 3n^2 - n. I also have the values to use as f(1), f(2), f(3). How would i go about solving this??
You would usually use recursion but, whether you do that or an iterative solution, you're missing (or simply haven't shown us) a vital bit of information, the terminating condition such as f(1) = 1 (for example).
With that extra piece of information, you could code up a recursive solution relatively easily, such as the following pseudo-code:
define f(n):
if n == 1:
return 1
return f(n-1) + (3 * n * n) - n
As an aside, that's not actually Fibonacci, which is the specific 1, 1, 2, 3, 5, 8, 13, ... sequence.
It can be said to be Fibonacci-like but it's actually more efficient to do this one recursively since it only involves one self-referential call per level whereas Fibonacci needs two:
define f(n):
if n <= 2:
return 1
return f(n-2) + f(n-1)
And if you're one of those paranoid types who doesn't like recursion (and I'll admit freely it can have its problems in the real world of limited stack depths), you could opt for the iterative version.
define f(n):
if n == 1:
return 1
parent = 1
for num = 2 to n inclusive:
result = parent + (3 * num * num) - num
parent = result
return result
If you ask this question on a programming site such as Stack Overflow, you can expect to get code as an answer.
On the other hand, if you are looking for a closed formula for f(n), then you should direct your question to a specialised StackExchange site such as Computer Science.
Note: what you are looking for is called the repertoire method. It can be used to solve your problem (the closed formula is very simple).

Write logic gates from logic gate circuit [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Could someone please show me how to write the logic from this logic circuit?
Following you guys' explanation, I have these results, am I right:
The question is which one of a, b, c, d produces the same ouput as the first circuit. I don't see any similar results here, please illuminate me !
Start from the inputs:
The AND gate gets A and B as inputs, and the NOT gate gets B as its input. The outputs of these 2 are the inputs to the OR Gate.
Therefore let
Y = A AND B
and Z = (NOT B)
=> X = Y OR Z
=> X = (A AND B) OR (NOT B)
UPDATE
I think b is the right answer.
If you give names to the intermediate terms, e.g. S and T, where S is the output of the AND gate and T is the output of the inverter (NOT gate), then you can break it down as follows:
X = S | T ; final OR gate
S = A & B ; output of AND gate
T = ~B ; output of inverter (NOT gate)
X = (A & B) | ~B ; substitute above
Note that this is a poor example as the expression can be reduced to:
X = ~(~A & B)
which can be implemented with just two gates (a NAND and a NOT), or
X = A | ~B
which can also be implemented with two gates (an OR and a NOT).

What is the meaning of ∃? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Reading a book on algorithms. Can someone explain the meaning of the mathematical symbol ∃?
It is called a quantifier. It means "there exists".
When used in an expression such as
∃x s.t. x > 0
It means "There exists a number x such that x is greater than 0."
Its counterpart is ∀, which means "for all". It's used like this:
∀x, x > 0
Which means "For any number x, it is greater than 0."
It is the "existential quantifier" as opposed to the upside-down A (∀) which means "universal quantifier." It should be read as "there exists" or "for some". It is a predication that means that some relation or property holds true for at least one object in the domain.
Examples:
An integer n is composite if ∃ integer m such that m > 1 and m < n with n divisible by m.
An integer n is prime if ∀ integer m such that m > 1 and m < n it is true that n is not divisible by m.
A function f is continuous on a metric space (X, d) if ∀x∀ε>0∃δ>0 | ∀y d(x, y) < δ => d(f(x), f(y)) < ε
More Info on Predicate Logic
It is called existential quantifier and being followed by x, it means there exists at least one x
For future reference, wikipedia has a table of mathematical symbols, with an explanation of the meaning(s) of each one.

Resources