Set Activity.
The Set Activity allows up to twenty sets to be defined.
These sets can either be used to investigate set notation, operatons and subsets,
or can be used as lists within the functional programming activity.
Only integer elements are allowed.
There are three methods for defining a list.
- As a list of elements.
- Using set comprehension
- As the result of a set operation on two sets.
List Representation
Lists of values should be separated by spaces. For example: "1 2 3 4".
Set Comprehension
Set comprehension includes an expression in terms of x for each element followed by a number of conditions.
For this activity, the values must be menbers of the natural numbers and the range is specified.
There is the option to defined both finite and infinite sets.
Result of a Set operation
A set can be specified as the result of an operation between two existing sets. The allowed operaitons are
- Union: A ∪ B, all elements that exist in A or B
- Intersection: A ∩ B, all elements that exist in both A and B
- Difference: A / B, all elements that exist in A but not in B
- symmetric difference: A ∆ B, all elements that exist in A or B but not both
- cartesian product: A × B, elements that consisting of all the possible pairs of elements, one from A and one from B
|
|
Function Definitions
There are a number of different types of function that can be defined. The return values
from a function can be one of the following:
- Integer.
- String
- List
- Map
- Filter
- Fold
Defining a function may require up to three different parameters: a, b and c. The input values may be an integer,
a string or a list.
Integer Functions
Integer functions take one or two integer values and return an integer value. They can also take a cateseian product as
an input corsisting of a pari of two integer values
String Functions
String functions take one or two integer or string value and return a stringvalue.
List Functions
List consist of a head (x) and a tail (xs) where the head is the first element in the list and the tail consists of the
remaining elements. The list functions take eight the head, the tail or the entire list as the input
Recursive Functions
Recursive functions take the output from the next iteration of the function as its output. A termination condition must
be specified so that the resursive function does not call itself indefinitely.
|
|
Commands.
The commands are based on the commands that can be used in functional programming
They can be defined to work with either functions, lists or both.
Lists can either be defined as integers separated by spaces, or bases on the elements in an existing set definition.
There are six types of commands that can be defined.
- Function.
- List Function
- Compound
- Map
- Filter
- Fold
Function Commands
These use the functions that require integer arguments and return an integer values.
The argument values are specified allowing the calculation to be displayed when the "Run" button is selected. The "Detail" button provides the
detail on the functional programming mapping between the domain and the codomain. For funcitons with two arguments, a Partial Function Applicaiton
can be displayed with the definition of a new intermediate function.
There is the option to specify a recursive function and the "Detail" button can be used to view the calculation after each iteration.
List Function Commands
These use the functions that require a finite list as the argument.
The function definition uses the x:xs syntax where x represents the head or first element, and xs represents the tail or the remaining elements.
There is the option to specify a recursive list function and the "Detail" button can be used to view the calculation after each iteration.
Composition Commands
This option allows for a composition of two functions to be defined
The domain of the second function must match the codomain of the first function
The new function combining both is displayed when "Run" button is selected. The "Detail" button provides the
detailed calculations at each stage for each function.
Map Command
This requires a function that required one integer argument and a finite list.
The result of applying the function to each element of the list to produced a new list is displayed when "Run" button is selected.
The "Detail" button provides the detail on the functional programming mapping between the domain and the codomain for the specified function
Filter Command
This requires a an infinite list to define the filter and a finite list to apply the filter to.
All elements in the finite list that match the filter produce a new list is displayed when "Run" button is selected.
The "Detail" button provides the detail on the functional programming mapping between the domain and the codomain for the specified function
Fold Command
This require a function requiring two arguments are a finite list.
In addition an initial result value must be specified
The "Run" buttons shows the result of recursively applying the current result to the next element in the list.
The "Detail" button provides the detail on the functional programming mapping and the result at each stage of the calculation.
|
|
Example Programs |
There are a number of example programs which can be loaded in from the Save/Load Tab to illustrate how sets and functions can be written using this application.
|