Question

Here is an abstract data type for lists: $\square$ Constants: { } , the empty list $\square$ Selectors: First [list], the first element of the list Rest [list], the rest of the list without its first element $\square$ Constructors: Prepend[list, elem], gives a new list whose first element is elem and whose rest is list $\square$ Predicates: ListQ [list], returns True, if list is a list Define the following functions on lists, using rules (no loops or branches, but conditional rules if necessary). Lists may be accessed only with the given selectors and predicates. 1. join $\left[l_1, l_2\right]$ : this function joins two lists 2. flatten[list ]: this function turns a nested list into a linear list 3. count $[l, e]$ : counts how often the element $c$ occurs in the linear list $l$ (Use $===$ for testing equality) Examples: These two lists are simply spliced together. Make sure to treat special cases correctly. All inner parentheses are removed. An empty list is removed completely The element a occurs twice. $$ \begin{aligned} & \operatorname{In}[1]:=\operatorname{join}[\{a, b, c\},\{x, y\}] \\ & \text { Out }[1]=\{a, b, c, x, y\} \\ & \operatorname{In}[2]:=j o i n[\{\},\{x,\{y, z\}\}] \\ & \text { Out }[2]=\{x,\{y, z\}\} \\ & \operatorname{In}[3]:=\{1 \operatorname{atten}[\{\{a\},\{b, c\}, d\}] \\ & \text { Out }[3]=\{a, b, c, d\} \\ & \operatorname{In}[4]:=\{1 \text { atten }[\{\{\},\{\{1\}, 2\}\}] \\ & \text { Out }[4]=\{1,2\} \\ & \operatorname{In}[5]:=\operatorname{count}[\{a, b, a, x\}, a] \\ & \text { Out }[5]=2 \end{aligned} $$ In this list it occurs only once because the $\operatorname{In}[6]:=\operatorname{count}[\{(a\}, a, b\}, a]$ list $\{a\}$ is not the same as the symbol a. Out $[6]=1$

   Here is an abstract data type for lists:
$\square$ Constants: { } , the empty list
$\square$ Selectors:
First [list], the first element of the list
Rest [list], the rest of the list without its first element
$\square$ Constructors:
Prepend[list, elem], gives a new list whose first element is elem and whose rest is list
$\square$ Predicates:
ListQ [list], returns True, if list is a list
Define the following functions on lists, using rules (no loops or branches, but conditional rules if necessary). Lists may be accessed only with the given selectors and predicates.
1. join $\left[l_1, l_2\right]$ : this function joins two lists
2. flatten[list ]: this function turns a nested list into a linear list
3. count $[l, e]$ : counts how often the element $c$ occurs in the linear list $l$ (Use $===$ for testing equality)
Examples:
These two lists are simply spliced together.
Make sure to treat special cases correctly.
All inner parentheses are removed.
An empty list is removed completely
The element a occurs twice.
$$
\begin{aligned}
& \operatorname{In}[1]:=\operatorname{join}[\{a, b, c\},\{x, y\}] \\
& \text { Out }[1]=\{a, b, c, x, y\} \\
& \operatorname{In}[2]:=j o i n[\{\},\{x,\{y, z\}\}] \\
& \text { Out }[2]=\{x,\{y, z\}\} \\
& \operatorname{In}[3]:=\{1 \operatorname{atten}[\{\{a\},\{b, c\}, d\}] \\
& \text { Out }[3]=\{a, b, c, d\} \\
& \operatorname{In}[4]:=\{1 \text { atten }[\{\{\},\{\{1\}, 2\}\}] \\
& \text { Out }[4]=\{1,2\} \\
& \operatorname{In}[5]:=\operatorname{count}[\{a, b, a, x\}, a] \\
& \text { Out }[5]=2
\end{aligned}
$$
In this list it occurs only once because the $\operatorname{In}[6]:=\operatorname{count}[\{(a\}, a, b\}, a]$ list $\{a\}$ is not the same as the symbol a. Out $[6]=1$
Show more…
Computer science with Mathematica: theory and practice for science, mathematics, and engineering
Computer science with Mathematica: theory and practice for science, mathematics, and engineering
Roman Maeder 1st Edition
Chapter 9, Problem 1 ↓

Instant Answer

verified

Step 1

###  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
Here is an abstract data type for lists: $\square$ Constants: { } , the empty list $\square$ Selectors: First [list], the first element of the list Rest [list], the rest of the list without its first element $\square$ Constructors: Prepend[list, elem], gives a new list whose first element is elem and whose rest is list $\square$ Predicates: ListQ [list], returns True, if list is a list Define the following functions on lists, using rules (no loops or branches, but conditional rules if necessary). Lists may be accessed only with the given selectors and predicates. 1. join $\left[l_1, l_2\right]$ : this function joins two lists 2. flatten[list ]: this function turns a nested list into a linear list 3. count $[l, e]$ : counts how often the element $c$ occurs in the linear list $l$ (Use $===$ for testing equality) Examples: These two lists are simply spliced together. Make sure to treat special cases correctly. All inner parentheses are removed. An empty list is removed completely The element a occurs twice. $$ \begin{aligned} & \operatorname{In}[1]:=\operatorname{join}[\{a, b, c\},\{x, y\}] \\ & \text { Out }[1]=\{a, b, c, x, y\} \\ & \operatorname{In}[2]:=j o i n[\{\},\{x,\{y, z\}\}] \\ & \text { Out }[2]=\{x,\{y, z\}\} \\ & \operatorname{In}[3]:=\{1 \operatorname{atten}[\{\{a\},\{b, c\}, d\}] \\ & \text { Out }[3]=\{a, b, c, d\} \\ & \operatorname{In}[4]:=\{1 \text { atten }[\{\{\},\{\{1\}, 2\}\}] \\ & \text { Out }[4]=\{1,2\} \\ & \operatorname{In}[5]:=\operatorname{count}[\{a, b, a, x\}, a] \\ & \text { Out }[5]=2 \end{aligned} $$ In this list it occurs only once because the $\operatorname{In}[6]:=\operatorname{count}[\{(a\}, a, b\}, a]$ list $\{a\}$ is not the same as the symbol a. Out $[6]=1$
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