## How to ‘memoize’ this recursive solution?

I was doing this problem:

A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y).  Given a starting point (sx, sy) and a target point (tx, ty), return True if and only if a sequence of moves exists to transform the point (sx, sy) to (tx, ty). Otherwise, return False.      Examples:     Input: sx = 1, sy = 1, tx = 3, ty = 5     Output: True     Explanation:     One series of moves that transforms the starting point to the target is:     (1, 1) -> (1, 2)     (1, 2) -> (3, 2)     (3, 2) -> (3, 5)      Input: sx = 1, sy = 1, tx = 2, ty = 2     Output: False      Input: sx = 1, sy = 1, tx = 1, ty = 1     Output: True      Note:      sx, sy, tx, ty will all be integers in the range [1, 10^9]. 

I know the solution where you split it up into the ty-tx case, or tx-ty case, and solve it recursively, but I was wondering if there is a DP solution to this. Here is my recursive solution:

public boolean reachingPoints(int sx, int sy, int tx, int ty) {     return help(sx,sy,tx,ty); }  public boolean help(int sx, int sy, int tx, int ty){     if(sx==tx && sy == ty){         return true;     }     if(sx>tx || sy>ty){         return false;     }     if(sx==tx){         if(ty-sy%sx==0){             return true;         }     }     if(ty==sy){         if(tx-sx%sy==0){             return true;         }     }     return(help(sx, sy, tx%ty, ty) || help(sx, sy+sx, tx, ty)); } 

How would I put this into an array? I have trouble in the memoization part of DP, and I cannot figure this one out.

Any help would greatly be appreciated.

Thank you!

## Use the Rice’s theorem to prove that the following property of a Recursive Enumerable language L is undecidable

This exercise was taken from the book “Languages and Machines: An Introduction to the Theory of Computation” by Thomas Sudkamp. It refers to exercise 12 (b) chapter 12. Given a language L which is recursive enumerable, I have to prove that the following property is undecidable:

• L is finite

The text says that it is sufficient to prove that it is a non trivial property.

I tried to solve the exercise as follow:

Consider the empty language $$\emptyset$$, which contains only the empty string λ, in other words $$\emptyset$$ = {$$\lambda$$}. Then $$\emptyset^-$$ which is the negation of the empty set, will contains some string which is not $$\lambda$$. By doing this, I’ve found a language which is finite and does satisfy the property, but I’ve also found another language which doesn’t satisfy the property because $$\emptyset^-$$ it is not finite. In conclusion the property it is not trivial, and by the Rice’s theorem it is impossible to decide that property.

I’m not sure if I’m doing the right thing here and I haven’t found any solution to this exercise… Can anyone help or at least tell me if I’m doing it right?

Thank you very much.

## Pseudo code of recursive method of printing all permutations of $n$ given integers

I really don’t understand this pseudo code. The function prints all permutations of $$n$$ given integers, assuming that all numbers are different.

Is there a way to explain this code more easily as I really don’t get the purpose of the swapping.

PERMUTATE(A, start, end)    if start == end return A    else       PERMUTATE(A,start+1,end)       for i = start+1 to end          SWAP(A[i],A[start])          PERMUTATE(A,start+1,end)          SWAP(A[start],A[i]) 

## Showing that the quotient function is primitive recursive

I’m asked to show that the quotient function is primitive recursive. I know that the operation of integer division $$div$$ is not total, as it is not defined when the denominator is zero, and a recursive function has to be total by definition.

So I could give a function $$div’$$ and define a value for the case that the denominator is zero: $$div'(x,y) = 0$$ if $$y = 0$$, otherwise $$div'(x,y) = div(x,y)$$. But this is still not primitive recursive because of $$div$$. How can I go about proving that the quotient function is actually primitive recursive? Should it somehow be built from scratch? Any help would be appreciated.

## Recursive Coroutine crashes unity

I want the bounds (left wall and right wall) to follow the player’s y position, a couple of times. however when I use this code as soon as it runs unity crashes. any idea why?

public Transform bounds;  //in another function StartCoroutine(Follow_Bounds(0));  IEnumerator Follow_Bounds(int a) {     yield return new WaitForSeconds(1f);     while(a < 3)     {         StartCoroutine(Follow_Bounds(a + 1));     }    bounds.position = new Vector2(bounds.position.x, transform.position.y); } 

## There exist two language $L_1$ and $L_2$ such that $L_1$ and $L_2$ are recursive, but $L_1L_2$ is non-recursive

Statements True or False.

There exist two language $$L_1$$ and $$L_2$$ such that $$L_1$$ and $$L_2$$ are recurvise, but $$L_1L_2$$ is non-recursive.

For me the statements is True because I can describe a non-recursive (I have understood recursively enumerable) procedure from two recurvise languages.

Proof:

Suppose that $$L_1$$ and $$L_2$$ are recursive languages. Then there is a Turing machine M1 that accepts any input in $$L_1$$ and rejects any input not in $$L_1$$. Similarly, there is a Turing machine M2 that accepts any input in $$L_2$$ and rejects any input not in $$L_2$$. To determine if $$w ∈ L_1L_2$$, we nondeterministically guess where to break the string into $$w_1w_2$$, and run M1 on $$w_1$$ and M2 on $$w_2$$. Then if w is in the language, M1 and M2 will both eventually accept.

## Can a subset of indexes of a partial recursive function be recursively enumerable but not recursive?

Consider an admissible numbering of partial recursive functions. Consider the set of indexes corresponding to some function $$\phi$$. It may be seen that this set is not recursively enumerable. Does this set contain a recursively enumerable non-recursive subset?

## Predecessor function with recursive types

I am defining the type Nat of natural numbers a recursive sum type:

$$Nat = \mu X. Unit \oplus X$$

Now, I have defined zero as the term:

zero : Nat zero = fold Nat (Inl tmUnit tyNat tyUnit) 

and successor as

succ : Nat -> Nat succ n = fold Nat (tmInr n tyNat tyUnit) 

Please note, that I am not completely sure of these two implementations; they might be wrong – I accept comments on them too.

Now, my question: I want to implement a predecessor function. I have both an isZero function and an if-then-else construct. How could I to this?

## Deriving recursive definition from function specification

Given this function specification, where name xs is bound to a list, # denotes its cardinality and . is the list index operator…

$$\left( \sum i: 0 \leq i < \#xs: xs.i * (i + 1) \right)$$

I need to derive a recursive function using induction.

Base case: []

\begin{align} \left( \sum i: 0 \leq i < \#[]: xs.i * (i + 1) \right) && \text{(Textual substitution – xs is free)} \ \left( \sum i: 0 \leq i < 0: xs.i * (i + 1) \right) && \text{(Def. of #)} \ \left( \sum i: False: xs.i * (i + 1) \right) && \text{(Algebra)} \ \left( \sum i: 0 \leq i < \#xs: xs.i * (i + 1) \right) && \text{(Empty range)} \end{align}

Inductive case: (x:xs)

\begin{align} \left( \sum i: 0 \leq i < \#(x:xs): (x:xs).i * (i + 1) \right) && \text{(Textual substitution – xs is free)} \ \left( \sum i: 0 \leq i < 1 + \#xs: (x:xs).i * (i + 1) \right) && \text{(Def. of #)} \end{align}

How can I proceed from here ?

## How to write grammar production rules to describe recursive structures?

I’m trying to describe a data structure by production rules. The structure is recursive; say a list of type $$A$$ made of elements of type $$A$$ or $$B$$.

Writing the grammar, I build this:

$$(S \rightarrow AS|ε)$$ $$(A \rightarrow AA|bA|ε)$$

where $$b$$ is a terminal representing element $$B$$ of my list.

The production $$A \rightarrow AA$$ got me a little baffled… is there something right? Thank you.