
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Define these functions in SML Language with using the standard functions abs and length, and the Int.toString function, Predefined functions: real, floor, ceil,
round, trunc, ord, chr, str, hd, tl,
explode, implode, and null
dont use pattern matching to solve the function
![1. Define a function called pow (val pow = fn: int * int -> int) that takes two integers as arguments and that returns the result of raising the first integer to the power of the
second. You may assume that the power is not negative. For our purposes, we will assume that every integer to the 0 power is 1 (this isn't true of 00, but that's okay).
2. Define a function called sumTo (val sumTo = fn : int -> real) that accepts an integer n and that computes the sum of the first n reciprocals. For example, sumTo(3) should
return (1 + 1/2 + 1/3) = 1.83333333.... The function should return 0.0 if n is 0. You may assume that the function is not passed a negative value of n.
3. Define a function called repeat (val repeat = fn : string * int -> string) that takes a string and an integer (>= 0) as arguments and that returns a string composed of the
given number of occurrences of the string. For example, repeat("hello", 3) returns "hellohellohello", repeat("hello", 0) returns "". You may assume that the function is not
passed a negative value for the second argument.
4. Define a function called binary (val binary = fn: int -> string) that takes an integer n as an argument and returns a string corresponding to the 16-bit binary
representation of that integer. For example, binary 17 returns "0000000000010001". You need not account for numbers whose binary representation requires more than
16 bits. Note: If needed, you can use the Int.toString function to convert integers to corresponding strings. You may find it helpful to write a helper function for this
problem.
5. Define a function called countNegative (val countNegative = fn : int list -> int) that takes a list of integers as an argument and that returns a count of the number of
negative integers in the list. For example, countNegative([3,17,-9,34,-7,2]) should return 2.
6. Define a function called absList (val absList = fn : (int * int) list -> (int * int) list) that takes a list of int * int tuples and that returns a new list of int * int tuples where every
integer is replaced by its absolute value. For example, absList([(~38,47), (983,~14), (~17,~92), (0,34)]) should return [(38,47), (983,14), (17,92), (0,34)]. HINT: This is
easier to solve if you write a helper function to process one tuple.
7. Define a function called split (val split = fn : int list -> (int * int) list) that takes a list of integers as an argument and that returns a list of the tuples obtained by splitting each
integer in the list. Each integer should be split into a pair of integers whose sum equals the integer and which are each half of the original. For odd numbers, the second
value should be one higher than the first. For example, split([5,6,8,17,93,0]) should return [(2,3), (3,3), (4,4), (8,9), (46,47), (0,0)]. You may assume that all of the integers
in the list passed to the function are greater than or equal to 0.
8. Define a function called is Sorted (val isSorted = fn : int list -> bool) that takes a list of integers and that returns whether or not the list is in sorted (nondecreasing) order
(true if it is, false if it is not). By definition, the empty list and a list of one element are considered to be sorted.](https://content.bartleby.com/qna-images/question/36fd9238-414f-4e5e-b00a-4398e187562f/bd00c7fe-a046-45e8-9775-ebc316c0ba52/13fleks_thumbnail.png)
Transcribed Image Text:1. Define a function called pow (val pow = fn: int * int -> int) that takes two integers as arguments and that returns the result of raising the first integer to the power of the
second. You may assume that the power is not negative. For our purposes, we will assume that every integer to the 0 power is 1 (this isn't true of 00, but that's okay).
2. Define a function called sumTo (val sumTo = fn : int -> real) that accepts an integer n and that computes the sum of the first n reciprocals. For example, sumTo(3) should
return (1 + 1/2 + 1/3) = 1.83333333.... The function should return 0.0 if n is 0. You may assume that the function is not passed a negative value of n.
3. Define a function called repeat (val repeat = fn : string * int -> string) that takes a string and an integer (>= 0) as arguments and that returns a string composed of the
given number of occurrences of the string. For example, repeat("hello", 3) returns "hellohellohello", repeat("hello", 0) returns "". You may assume that the function is not
passed a negative value for the second argument.
4. Define a function called binary (val binary = fn: int -> string) that takes an integer n as an argument and returns a string corresponding to the 16-bit binary
representation of that integer. For example, binary 17 returns "0000000000010001". You need not account for numbers whose binary representation requires more than
16 bits. Note: If needed, you can use the Int.toString function to convert integers to corresponding strings. You may find it helpful to write a helper function for this
problem.
5. Define a function called countNegative (val countNegative = fn : int list -> int) that takes a list of integers as an argument and that returns a count of the number of
negative integers in the list. For example, countNegative([3,17,-9,34,-7,2]) should return 2.
6. Define a function called absList (val absList = fn : (int * int) list -> (int * int) list) that takes a list of int * int tuples and that returns a new list of int * int tuples where every
integer is replaced by its absolute value. For example, absList([(~38,47), (983,~14), (~17,~92), (0,34)]) should return [(38,47), (983,14), (17,92), (0,34)]. HINT: This is
easier to solve if you write a helper function to process one tuple.
7. Define a function called split (val split = fn : int list -> (int * int) list) that takes a list of integers as an argument and that returns a list of the tuples obtained by splitting each
integer in the list. Each integer should be split into a pair of integers whose sum equals the integer and which are each half of the original. For odd numbers, the second
value should be one higher than the first. For example, split([5,6,8,17,93,0]) should return [(2,3), (3,3), (4,4), (8,9), (46,47), (0,0)]. You may assume that all of the integers
in the list passed to the function are greater than or equal to 0.
8. Define a function called is Sorted (val isSorted = fn : int list -> bool) that takes a list of integers and that returns whether or not the list is in sorted (nondecreasing) order
(true if it is, false if it is not). By definition, the empty list and a list of one element are considered to be sorted.
![de il it is, raise II TU
ol). By de nition, the empty list and a list of one element are considered to be sorted.
9. Define a function called collapse (val collapse = fn : int list -> int list) that takes a list of integers as an argument and that returns the list obtained by collapsing successive
pairs in the original list by replacing each pair with its sum. For example, collapse([1,3,5,19,7,4]) should return [4,24,11] because the first pair (1 and 3) is collapsed into its
sum (4), the second pair (5 and 19) is collapsed into its sum (24) and the third pair (7 and 4) is collapsed into its sum (11). If the list has an odd length, the final number in
the list is not collapsed. For example, collapse([1,2,3,4,5]) should return [3,7,5].
10. Define a function called insert (val insert = fn : int * int list -> int list) that takes an integer and a sorted (nondecreasing) integer list as parameters and that returns the list
obtained by inserting the integer into the list so as to preserve sorted order. For example, insert(8,[1,3,7,9,22,38]) should return [1,3,7,8,9,22,38].
11. Define a function called decimal (val decimal = fn: string -> int) that takes a bit string corresponding to an integer and returns the decimal value of that integer. For
example, decimal "10001" returns 17, decimal "001101" returns 13.](https://content.bartleby.com/qna-images/question/36fd9238-414f-4e5e-b00a-4398e187562f/bd00c7fe-a046-45e8-9775-ebc316c0ba52/uux4zwcq_thumbnail.png)
Transcribed Image Text:de il it is, raise II TU
ol). By de nition, the empty list and a list of one element are considered to be sorted.
9. Define a function called collapse (val collapse = fn : int list -> int list) that takes a list of integers as an argument and that returns the list obtained by collapsing successive
pairs in the original list by replacing each pair with its sum. For example, collapse([1,3,5,19,7,4]) should return [4,24,11] because the first pair (1 and 3) is collapsed into its
sum (4), the second pair (5 and 19) is collapsed into its sum (24) and the third pair (7 and 4) is collapsed into its sum (11). If the list has an odd length, the final number in
the list is not collapsed. For example, collapse([1,2,3,4,5]) should return [3,7,5].
10. Define a function called insert (val insert = fn : int * int list -> int list) that takes an integer and a sorted (nondecreasing) integer list as parameters and that returns the list
obtained by inserting the integer into the list so as to preserve sorted order. For example, insert(8,[1,3,7,9,22,38]) should return [1,3,7,8,9,22,38].
11. Define a function called decimal (val decimal = fn: string -> int) that takes a bit string corresponding to an integer and returns the decimal value of that integer. For
example, decimal "10001" returns 17, decimal "001101" returns 13.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 12. Find the Laplace transform of the function t*e-2tcos(3t) using MATLAB and print it in the command window.arrow_forwardIn Kotlin, Write and call a function with an expression body that takes three doubles, a, b, and c, and returns True if a, b, and c are a Pythagorean triple (ie if they are possible lengths for the sides of a right triangle), otherwise False. The function must return True if the parameters are a Pythagorean triple, irrespective of the order in which they are given; for example, it must return True for 3.0 4.0 5.0 as well as for 3.0 5.0 4.0, etc. Use the || logical or operator to string together the cases in which you should return True, which you should evaluate using the function you wrote in the last question.arrow_forwardHow do high-order functions differ from pure functions?arrow_forward
- I'm curious as to why pure functions would be useful.arrow_forwardSelect all answers that are an incorrect description of "minterm": a product term with only a single function literal, in true or complemented form. a product term with every function literal appearing exactly once, in true or complemented form. *** a product term with every function literal appearing exactly once, and only in true form. a product term with at least one function literal appearing once, in true or complemented form.arrow_forwardFor each of the following expressions, write functions f1, f2, f3, and f4 such that the evaluation of each expression succeeds, without causing an error. Be sure to use lambdas in your function definition instead of nested def statements. Each function should have a one line solution. f1 takes in nothing and returns 3. f2 takes in nothing and returns a function that takes in nothing and returns 3. f3 takes in nothing and returns a function that takes in 1 value and returns that same value. f4 takes in nothing and returns a function. This function takes in nothing and returns another function. This next function takes in a value and returns yet another function. This final function takes in nothing and returns the value passed into the previous function (if this explanation is confusing, have a look at the doctest, and it might be more clear). def f1(): >>> f1() 3 |||||| "*** YOUR CODE HERE ***" def f2(): |||||| >>> f2() () 3 |||||| "*** YOUR CODE HERE ***" def f3(): |||||| >>> f3() (3)…arrow_forward
- Redesign the solution using functions. For this lab: 1. You will define a function named main() (LO 1) 2. You will get input in the main function and pass it to the following functions: (LO 2) a. milesToKm() b. FahToCel() c. GalToLit() d. PoundsToKg() e. InchesToCm() 3. Each function will require that you have a local variable to store the result of the calculation. This result will then be displayed using the print statement from within the functionarrow_forwardWrite a function inside rust programming langauge that takes a string parameter as input and prints the string in output followed by " is printed from the helper function".arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education