## Trying to contact Red Orca for permission to print an answer in a book [migrated]

I apologize in advance for breaking protocol. I’m just looking to get an official okay on rewriting and publishing Red Orca’s answer in this thread in an upcoming book about Magic Items. I looked for alternative ways to contact them but fell short. It’s an incredible answer and I’d love to make it more widely known to people out there looking to categorize their own items.

They can reach out over reddit to u/griff-mac or Discord to griffmac#9421, if that’s more appropriate. Thanks in advance, and again, I hope I’m not breaking rules too egregiously.

Cheers!

## What is the answer for this recurrence? Is there a way to solve it? How? @

Solve the recurrence $$T_n = 4T_{n+2} + n + 1$$ where $$T_1 = 0$$ for $$T_i = 1, 2 … 16$$

## Anyone know the answer to the this problem?

https://dmoj.ca/problem/ccc19j5 A substitution rule describes how to take a sequence of symbols and convert it into a different sequence of symbols. For example, ABA→BBB, is a substitution rule which means that ABA can be replaced with BBB. Using this rule, the sequence AABAA would be transformed into the sequence ABBBA (the substituted symbols are in bold).

In this task, you will be given three substitution rules, a starting sequence of symbols and a final sequence of symbols. You are to use the substitution rules to convert the starting sequence into the final sequence, using a specified number of substitutions.

For example, if the three substitution rules were:

AA→AB AB→BB B→AA we could convert the sequence AB into AAAB in 4 steps, by the following substitutions:

AB→BB→AAB→AAAA→AAAB,

where the symbols to be replaced are shown in bold. More specifically, from the initial sequence AB, substitute rule 2 starting at position 1, to get the result BB. From BB, substitute rule 3, starting at position 1, to get the result AAB. From AAB, substitute rule 3, starting at position 3, to get the result AAAA. From AAAA, substitute rule 1, starting at position 3, to get the result AAAB, which is the final sequence.

Input Specification The first three lines will contain the substitution rules. Each substitution rule will be a sequence of A’s and B’s, followed by a space following by another sequence of A’s and B’s. Both sequences will have between one and five symbols.

The next line contains three space separated values, S, I and F. The value S(1≤S≤15) is an integer specifying the number of steps that must be used, and the values I (the initial sequence) and F (the final sequence) are sequences of A’s and B’s, where there are at least one and at most 5 symbols in I and at least one and at most 50 symbols in F.

For 7 of the 15 marks available, S≤6.

For an additional 7 of the 15 available marks, S≤12.

Output Specification The output will be S lines long and describes the substitutions in order.

Line i of the output will contain three space-separated values, Ri, Pi, and Wi:

Ri is the substitution rule number (either 1, 2 or 3) that will be used. Pi is the starting position index of where the substitution rule will be applied in the sequence. Notice that the string is 1-indexed (i.e., the first character of the string is at index 1). Wi is the sequence that results from this substitution. Specifically, Wi is the sequence of symbols that results by applying substitution rule Ri starting at position Pi from the previous sequence of symbols, Wi−1, where we define W0 to be the initial sequence I. Note that WS=F, the final sequence. There will always be at least one sequence of S substitutions that will convert I into F. If there is more than one possible sequence of substitutions, any valid sequence will be accepted.

I tried using recursion but the program isn’t fast enough. Can anyone help?

## The replacement function is an integral and the double integral yields a different answer than the normal double integral

I am fairly new to Mathematica. I have a quick inquiry. The code is simple and just 3 lines. Trying to do a replacement rule as follows

ruletrr = intsl[exp_] :> Integrate[exp, {u, u, 1}] intsl[Integrate[a[u],{u,0,u}]]/.ruletrr 

So basically I want replace the expression inside the square brackets after ‘intsl’ with integrating the expression from u to 1. The expression inside the square bracket is in fact an integral as well. The integrand is a function of u. However, after the second line, the answer is as follows

(1 - u)*Integrate[a[u], {u, 0, u}] 

The answer means that Mathematica takes the expression inside the square bracker as a constant and not a function of u. Kindly copy the preceding line to see the integration symbol as I can’t do it here.

The problem is the first two line is equivalent to the following code line

Integrate[a[u], {u, u, 1}, {u, 0, u}] 

The answers are different. Can someone let me know where is the mistake here or why is the integral evaluated.

The entire code input is as follows as a summary

ruletrr = intsl[exp_] :> Integrate[exp,{u,u,1}] intsl[Integrate[a[u],{u,0,u}]]/.ruletrr Integrate[a[u], {u, u, 1}, {u, 0, u}] 

The first two lines are equivalent to the third line but the answers are different

## Is “represents” a symmetric relation in the provided answer to TAOCP exercise 1.1.9?

In exercise 1.1.9 of volume 1 of The Art of Computer Programming, the reader is asked to

formulate a set-theoretic definition for the concept “$$C_2$$ is a representation of $$C_1$$

where $$C_1$$ and $$C_2$$ are computational methods described in the previous few pages (reproduced here so the question can be answered without needing the book).

Let us formally define a computational method to be a quadruple $$(Q,I,\Omega,f)$$, in which $$Q$$ is a set containing subsets $$I$$ and $$Ω$$, and $$f$$ is a function from $$Q$$ into itself. […] The four quantities $$Q$$, $$I$$, $$\Omega$$, $$f$$ are intended to represent repectively the state of the computation, the input, the output, and the computational rule.

When I looked at the answer in the back, this definition was proposed:

For example we can say $$C_2$$ represents $$C_1$$ if there is a function $$g$$ from $$I_1$$ into $$I_2$$, a function $$h$$ from $$Q_2$$ into $$Q_1$$, and a function $$j$$ from $$Q_2$$ into the positive integers, satisfying the following conditions:

• a) If $$x$$ is in $$I_1$$ then $$h(g(x)) = x$$
• b) If $$q$$ is in $$Q_2$$ then $$f_1(h(q)) = h(f_2^{[j(q)]}(q))$$, where $$f_2^{[j(q)]}$$ means that the function $$f_2$$ is to be iterated $$j(q)$$ times.
• c) If $$q$$ is in $$Q_2$$ then $$h(q)$$ is in $$\Omega_1$$ if and only if $$q$$ is in $$\Omega_2$$

Later on, discussing this definition, Knuth writes (emphasis mine):

The relation “$$C_2$$ represents $$C_1$$” generates an equivalence relation in which two computational methods apparently are equivalent if and only if they compute isomorphic functions of their inputs …

To be an equivalence relation, a relation must be symmetric. That is, for a relation $$R$$, $$(a, b) \in R$$ implies $$(b, a) \in R$$. I don’t believe this is true of the given definition.

Consider the computational methods $$C_1$$ and $$C_2$$, where

\begin{align*} C_2 &= \{Q_2, I_2, \Omega_2, f_2\}\ C_1 &= \{Q_1, I_1, \Omega_1, f_1\}\\ I_2 &= \{a_1, a_2\}\ \Omega_2 &= \{b_1, b_2\}\ Q_2 &= I_2 \cup \Omega_2\ f_2 &= \{(a_1, b_1), (a_2, b_2), (b_1, b_1), (b_2, b_2)\}\\ I_1 &= \{c\}\ \Omega_1 &= \{d\}\ Q_1 &= I_1 \cup \Omega_1\ f_1 &= \{(c, d), (d, d)\} \end{align*}

It can be shown that $$C_2$$ represents $$C_1$$ by $$g(q) = a_1$$, $$h = \{(a_1, c), (a_2, c), (b_1, d), (b_2, d)\}$$, and $$j(q) = 1$$.

However, $$C_1$$ cannot represent $$C_2$$, because for any proposed $$g: I_2 \rightarrow I_1$$ it must be the case that $$g(a_1) = g(a_2) = c$$. But $$h(c)$$ can only be either $$a_1$$ or $$a_2$$. If $$h(c) = a_1$$, then $$h(g(a_2)) = a_1 \neq a_2$$, but if $$h(c) = a_2$$, then $$h(g(a_1)) = a_2 \neq a_1$$. So in either case, the first requirement cannot be satisfied.

Has this been discussed elsewhere? So far my online searches haven’t revealed any answers on the subject. To the best of my knowledge, this hasn’t been errata’d (checked here).

Am I understanding the definition properly?

I’m uncertain about my result because of the specific wording “from $$Q_2$$ into $$Q_1$$“, which seems to have varying meanings depending on where you ask (if it means “injection”, it adds different inconsistencies). It also seems strange to me that this property would be overlooked, since Knuth also specifically mentions that “represents” is transitive, and a counterexample like this is quite easily constructed.

by: rumana91
Created: —
Viewed: 156

## How to answer multiple queries for a tree?

I encountered an interesting problem based on tree-data-structure.

We are given a tree which has N nodes, with 1≤N≤105.

Time starts from second 1 and it continues for q seconds.

At each second, the value of each internal node is transferred to all of its child nodes. This happens with all the nodes, except leaf nodes.

Sometimes, at a given time p (seconds), we are asked to return the current value of node x.

There is this O(logN) approach: just find the pth ancestor of the given node x, and output its value.

# A harder version of the same problem

Sometimes, at a given time p (seconds), we are asked to return the current value of node x, or we are said to update the value of node x to y.

How to solve this problem for q queries (seconds) efficiently, where 1≤q≤105.

## Example

### Input

N=5, q=8

Edges of the tree:-

4 3 3 1 5 2 1 2 

Values of nodes 1 to 5:-

1 10 4 9 4 

Queries:-

• 1st second:- Add(1,6). Add the value 6 to node 1.
• 2nd second:- What is the current value of node 3? (?,3)
• 3rd second:- Add(3,5)
• 4th second:- (?,3)
• 5th second:- Add(2,2)
• 6th second:- Add(5,10)
• 7th second:- (?,5)
• 8th second:- (?,4)

• 6
• 0
• 33
• 25

### Explanation

• 1st second: 6,1,1,13,14 (Values of all nodes)
• 2nd second: 0,6,6,14,15
• 3rd second: 0,0,5,20,21
• 4th second: 0,0,0,25,21
• 5th second: 0,2,0,25,21
• 6th second: 0,0,0,25,33
• 7th second: 0,0,0,25,33
• 8th second: 0,0,0,25,33

by: MAHFUJSEO
Created: —