Question

Define the function $\operatorname{rev}_s:$ string $\rightarrow$ string by $$ \begin{aligned} \operatorname{rev}_s(\sigma)= & {[\text { if length }} \\ & \text { else } \operatorname{append}_s(\sigma)=1 \text { then } \sigma \\ & \left.\left.\operatorname{rev}_s\left(\operatorname{tail}_s(\sigma)\right), \operatorname{head}_s(\sigma)\right)\right] . \end{aligned} $$ 1. Compute $r e v_s\left({ }^{\prime} a b c d\right.$ '). 2. Let $\alpha_1 \alpha_2 \cdots \alpha_k$ be an informal description of an arbitrary string, where the $\alpha_i$ are elements of char. Using this kind of informal description, say what $\operatorname{rev}_s\left(\alpha_1 \alpha_2 \cdots \alpha_k\right)$ is. 3. What is $\operatorname{rev}_s\left(\right.$ append $_s\left(' a b c^{\prime}\right.$, ' $\left.\left.x y '\right)\right)$ ? 4. Theorem. For any strings $\sigma, \gamma$, $$ \operatorname{rev}_s\left(\operatorname{append}_s(\sigma, \gamma)\right)=\operatorname{append}_s\left(\operatorname{rev}_s(\gamma), \operatorname{rev}_s(\sigma)\right) . $$ [Remarks. The text has already proved that append ${ }_s$ is associative. Although it is easy to program the reversing function according to the above definition, the resulting procedure is computationally inefficient, and for this reason is often called naive reverse. There are faster ways to reverse strings.]

   Define the function $\operatorname{rev}_s:$ string $\rightarrow$ string by
$$
\begin{aligned}
\operatorname{rev}_s(\sigma)= & {[\text { if length }} \\
& \text { else } \operatorname{append}_s(\sigma)=1 \text { then } \sigma \\
& \left.\left.\operatorname{rev}_s\left(\operatorname{tail}_s(\sigma)\right), \operatorname{head}_s(\sigma)\right)\right] .
\end{aligned}
$$
1. Compute $r e v_s\left({ }^{\prime} a b c d\right.$ ').
2. Let $\alpha_1 \alpha_2 \cdots \alpha_k$ be an informal description of an arbitrary string, where the $\alpha_i$ are elements of char. Using this kind of informal description, say what $\operatorname{rev}_s\left(\alpha_1 \alpha_2 \cdots \alpha_k\right)$ is.
3. What is $\operatorname{rev}_s\left(\right.$ append $_s\left(' a b c^{\prime}\right.$, ' $\left.\left.x y '\right)\right)$ ?
4. Theorem. For any strings $\sigma, \gamma$,
$$
\operatorname{rev}_s\left(\operatorname{append}_s(\sigma, \gamma)\right)=\operatorname{append}_s\left(\operatorname{rev}_s(\gamma), \operatorname{rev}_s(\sigma)\right) .
$$ [Remarks. The text has already proved that append ${ }_s$ is associative. Although it is easy to program the reversing function according to the above definition, the resulting procedure is computationally inefficient, and for this reason is often called naive reverse. There are faster ways to reverse strings.]

Show more…
Logic, sets, and recursion
Logic, sets, and recursion
Robert L. Causey 1st Edition
Chapter 3, Problem 42 ↓

Instant Answer

verified

Step 1

To compute $rev_s('abcd')$, we can follow the definition of the function: - The length of the string 'abcd' is not 1, so we move to the next step. - We call $rev_s(tail_s('abcd'))$, which is equivalent to $rev_s('bcd')$. - Again, the length of 'bcd' is not 1, so  Show more…

Show all steps

lock
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
Define the function $\operatorname{rev}_s:$ string $\rightarrow$ string by $$ \begin{aligned} \operatorname{rev}_s(\sigma)= & {[\text { if length }} \\ & \text { else } \operatorname{append}_s(\sigma)=1 \text { then } \sigma \\ & \left.\left.\operatorname{rev}_s\left(\operatorname{tail}_s(\sigma)\right), \operatorname{head}_s(\sigma)\right)\right] . \end{aligned} $$ 1. Compute $r e v_s\left({ }^{\prime} a b c d\right.$ '). 2. Let $\alpha_1 \alpha_2 \cdots \alpha_k$ be an informal description of an arbitrary string, where the $\alpha_i$ are elements of char. Using this kind of informal description, say what $\operatorname{rev}_s\left(\alpha_1 \alpha_2 \cdots \alpha_k\right)$ is. 3. What is $\operatorname{rev}_s\left(\right.$ append $_s\left(' a b c^{\prime}\right.$, ' $\left.\left.x y '\right)\right)$ ? 4. Theorem. For any strings $\sigma, \gamma$, $$ \operatorname{rev}_s\left(\operatorname{append}_s(\sigma, \gamma)\right)=\operatorname{append}_s\left(\operatorname{rev}_s(\gamma), \operatorname{rev}_s(\sigma)\right) . $$ [Remarks. The text has already proved that append ${ }_s$ is associative. Although it is easy to program the reversing function according to the above definition, the resulting procedure is computationally inefficient, and for this reason is often called naive reverse. There are faster ways to reverse strings.]
Close icon
Play audio
Feedback
Powered by NumerAI
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever