4. Write a function that adds two polynomials. Ensure that the polynomial produced matches the requirements. addPoly :: (Num a, Eg a) => Poly a -> Poly a -> Poly a For example: > addPoly (P [1]) (P [-1,1]) P [0,1] > addPoly (P [17]) (P [0,0,0,1]) P [17,0,0,1] >addPoly (P [1,-1]) (P [0,1]) P [1] You may find it helpful to write addPoly using two helper functions: one to combine the lists of coefficients, and one to trim trailing zeroes. Your implementation of addPoly should have this property: addPoly p q $$ x == (p sS x) + (a Ss x)
Q: Problem 6 Note that we can actually infer the type of an texpr. If we see (x, IntLit (8)),we know x…
A: Solution:-
Q: Write a C++ fraction calculator program that adds, subtracts, multiplies, and divides fractions.…
A: Textual Code :- #include<iostream> #include<math.h> using namespace std;void…
Q: Can help in c++ for this figure write a function that finds the sum of the elements that are filled…
A: ANSWER:
Q: . Implement Euclidean Algorithm for calculating greatest common divisor First write and test a…
A: Euclidean Algorithm for calculating greatest common divisor Implementation - #include…
Q: Assume a generic recursive relation is defined as : A[i] = p*A[i-1] + q where p and q are…
A: Actually, python is a easiest programming language. It is a dynamically typed programming language.
Q: Many engineering applications require "normalizing" an n-element vector V. Each element wy of the…
A: Steps: Create a class named Vector Take integer array v of size 10. Take float array w of size 10.…
Q: def longest_unique_substring(s: str) -> str: """ Given a string , return the longest unique…
A: We need to highlight the code for desired substring in python.
Q: 1 Problem 3. Write a function `softMax (x)` to return a 1darray of softmax function values \\(f_i =…
A: Given : Given the array values. Output : Find the softmax values.
Q: A function chicken_and_egg() has been analyzed to run with 0(2") complexity to process a list of…
A: Ans:) Given, complexity = O(2n) time taken = 3 mins, list size = 10
Q: A prime that is lesser than the arithmetic mean of the primes before and after it is called weak…
A: Input - Array Output - string based on the condition logic - for(let i=1;i<=n;i++){…
Q: Assume a generic recursive relation is defined as : A[i] = p*A[i-1] + q where p and q are…
A: Here we have, A[1] = p*A[0] + q _____________________(1)A[2] = p*A[1] + q _____________________(2)…
Q: Assume a generic recursive relation is defined as : A[i] = p*A[i-1] + q where p and q are…
A: The complete code is given below with output.
Q: A matrix M with i rows, j columns can be transposed into a matrix N having j rows and i columns by…
A: //a.) Code : //Include necessary header files#include <stdio.h>// Defining a Function that…
Q: def longest_unique_substring(s: str) -> str: """ Given a string , return the longest unique…
A: the code is given below :
Q: K-1 roblem 2. Write a function loss(x, q) to return E ita max(0, x¡ – xa + 1), where x is a 1darray…
A: import numpy as np #importing numpy as np def loss(x,q):k = len(x) #finding the lenght of the…
Q: C++ only Sam and Sangu played a game. First, the Sam gives Sangu a sequence of different numbers N…
A: #include <bits/stdc++.h>using namespace std; void printPattern(int n){ int j, k = 0; for…
Q: A prime that is lesser than the arithmetic mean of the primes before and after it is called weak…
A: Input - Integer Output - string based on condition logic - for(let i=1;i<=n;i++){…
Q: Write a recursive function subset such that subset a b returns True if a Cb or False otherwise. Use…
A: ANSWER: Recursive Function: In programming terms, a recursive function can be characterized as a…
Q: Define a function named get_sorted_in_parallel(tuples1, tuples2) which takes two tuples of integers…
A: Solution - Programming Language - Python All necessary comments are included in program code.…
Q: 1. Create a function with three output (ss, ILbas) which will determine whether the vectors are…
A:
Q: We have defined the parsing function for arithmetic expressions as (define (parse sexp) (cond…
A: Please find the answer in step 2
Q: Write a program in c++ which should create a weighted graph of the values entered by the user and…
A: Depth First Search (DFS): Unlike BFS in which we explore the nodes breadthwise, in DFS we explore…
Q: def first_preceded_by_smaller(items, k=1):
A: 1. iterate for all items from k, init count variable 2. iterate for each item, in range of first. 3.…
Q: 2. (a) Write a function, called myListFn, which takes a single argument n and implements the…
A: Below find the solution !! (a) myListFn <- function(n) { xVec <- rnorm(n) xBar <-…
Q: Write a function f1 that takes the root of a binary tree as a parameter and returns the sum of the…
A: /* Program to check children sum property */ #include <bits/stdc++.h> using namespace std;…
Q: Assume a generic recursive relation is defined as : A[i] = p*A[i-1] + q where p and q are…
A: A[i] = p*A[i-1] + q where p and q are coefficients of the relation.
Q: Write a function matrix_multiply(mat1, mat2) that takes two matrices and returns the result of the…
A: import numpy as np def matrix_multiply(mat1, mat2): rows = len(mat1) cols = len(mat2[0])…
Q: We have defined the parsing function for arithmetic expressions as (define (parse sexp) (cond…
A: Hey there, I am writing the required solution based on the above given question. Please do find the…
Q: 5K-1 Problem 2. Write a function loss(x, q) to return Eita max(0, x¡ – x, + 1), where x is a 1darray…
A: ALGORITHM:- 1. Initialise the array. 2. Call the loss function with the corresponding array. 3.…
Q: Define a function named get_sorted_in_parallel (tuples1, tuples2) which takes two tuples of integers…
A: The python code for the above-given question is given below:
Q: A prime that is lesser than the arithmetic mean of the primes before and after it is called weak…
A: In this problem, we need to design the code in the js programming language. Input - Integer Output…
Q: 4. Define a polymorphic function of type: shimmy :: [a] -> a -> [a] which takes an input list and…
A: The answer is given below:-
Q: A prime that is lesser than the arithmetic mean of the primes before and after it is called weak…
A: Input - Integer Output - returns "Strong" if it is a strong prime, "Weak" if it is a weak prime,…
Q: 4. Consider the function IndexEqual(A,i.j) that returns true if there exists an index x (i sx sj)…
A: Below i have answered:
Q: 2 3 [[1,2, 3], [4, 5, 6] ] \4 5 Complete the Python function transpose () below that takes as input…
A: def transpose(M): # function to transpose a matrix T = [] #…
Q: Write a function that takes one input, a matrix X. Your function should modify X and return the…
A: NOTE - Here I have used the Python programming language. Here I have created the function named…
Q: Write a fraction calculator program that adds, subtracts, multiplies, and di- vides fractions. Your…
A: According to the information given:- We have to create fraction calculator for that we need…
Q: The set of all non-negative integers x less than 16 such that x2 is an even integer can be described…
A: The set should contain all non negative integers x less than 16 such that x2 is an even integer. The…
Q: Is the following statement TRUE or FALSE? If it is TRUE, prove it, and if it is FALSE, provide a…
A: The function is the relationship from the elements of one set S to the elements of the other set T.…
Q: 1. Write a structurally recursive function (prefix-of? 1st1 1st2) that takes two arguments, both…
A: #lang racket (require rackunit) (define (prefix-of? lst1 lst2) ; if the list1 is empty, it means…
Q: 1 Write a Racket function (is-sorted x) where x is a list of numbers. Function returns true (#t) if…
A:
Q: program is given below attachment
A: a. The returned value of fib(5) will be: 0 1 1 2 3 b. Recurrence relation for T(n): T(n - 1) + T(n -…
Q: For the following C++ code find and write the recurrence relation. You need to model the runtime of…
A: Given c++ Function: s= array L[] start index e= array L[] end index void Func(int L[], int s,…
Q: def longest_unique_substring(s: str) -> str: """ Given a string , return the longest unique…
A: According to the information given:- We have to create longest unique substring function find in the…
Q: Suppose, you are given two matrices (A and B) as input, you have to perform the following tasks: I.…
A: According to Bartleby policy, we will answer only the first 3 questions Attaching the code and…
Q: Exercise 4. DYNAMIC PROGRAMMING: COUNTING CERTAIN DNA SEQUENCES. DNA strings use the alphabet A, C,…
A: Program to print DNA sequence Given the value of n i.e, the number of lobes. Print the double-helix…
Q: Prove that the set M = {x ∈ R: x 2 = 2a3 b , a ∈ N, b ∈ N} is countably infinite. Your solution…
A: Answer:
Has to be in HASKELL
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
- Write a function in c++ is ordered that takes an integer array and its size as parameters and returns true if the array elements are ordered in nondecreasing order and returns false if not. For example, integers in {10,0,1,1,5,1009} are ordered in nondecreasing order. On the other hand, integers in {1, 2, 3, 8, 4, 19} are not since 8 > 4Write a C++ function, bool ok(int q[]), which takes an array q and returns true if the array represents a valid configuration of the eight queens and returns false otherwise.Develop a function that finds the starting index of the longest subsequence of values that is strictly increasing. For example, given the array {12, 3, 7, 5, 9, 8, 1, 4, 6}, the function would return 6, since the subsequence {1, 4, 6} is the longest that is strictly increasing. Develop a function that takes a string and a single character, then returns a list of the indexes in the string where the character occurs. For example, given the string “bookkeeper” and ‘e’, the function would return {5, 6, 8} since ‘e’ occurs at those positions. Return an empty list if the character does not appear in the string even once. Develop a function that takes two lists of integers and returns a list containing any value that appears in both parameter lists.
- Complete the below function which takes the coefficients of a polynomial P(x) as a tuple, and a list of values, and returns a list of computed values of P(x). Note that P() can be of any order. For example, P((2,-1,1), [1,2,3]) shall compute P(x) for x=1,2,3P(x)=2x^2 -x +1where x^2 denotes the square of x. Hence, the function must return [2,7,16], because P(1) is 2, P(2) is 7, and P(3) is 16.Interesting, intersecting def squares_intersect(s1, s2): A square on the two-dimensional plane can be defined as a tuple (x, y, r) where (x, y) are the coordinates of its bottom left corner and r is the length of the side of the square. Given two squares as tuples (x1, y1, r1) and (x2, y2, r2), this function should determine whether these two squares intersect, that is, their areas have at least one point in common, even if that one point is merely the shared corner point when these two squares are placed kitty corner. This function should not contain any loops or list comprehensions of any kind, but should compute the result using only integer comparisons and conditional statements. This problem showcases an idea that comes up with some problems of this nature; it is actually far easier to determine that the two squares do not intersect, and negate that answer. Two squares do not intersect if one of them ends in the horizontal direction before the other one begins, or if the same…Write the following three functions: a) The function gets an array A of length n of ints, and a boolean predicate pred. It returns the smallest index i such that pred(A[i])==true.If no such element is not found, the function returns -1.int find(int* A, int n, bool (*pred)(int)); b) The function gets an array A of length n of ints, and a function f. It applies f to each element of A.void map(int* A, int n, int (*f)(int)); c) The function gets an array A of length n of ints, and a function f. The function f gets 2 ints and works as follows: Start with accumulator = A[0] For i=1...length-1 compute accumulator=f(accumulator, A[i]) Return accumulator For example, if f computes the sum of the two inputs, then reduce() will compute the sum of the entire array.int reduce(int* A, int n, int (*f)(int,int));
- Write a C++ function using recursion that returns the Greatest Common Divisor of two integers. The greatest common divisor (gcd) of two integers, which are not zero, is the largest positive inteteger that divides each of the integers. The code should follow the exact function declaration: int GCD(int number1, int number2);I have to write the following functions using SML. Write a function concat_with that takes a separator string and a list of strings, and returns the string that consists of all the strings in the list concatenated together, separated by the separator. The separator should be only between elements, not at the beginning or end. Use ML's - operator for concatenation (e.g., "hello" - "world" evaluates to "helloworld"). Sample solution is 5 lines.Python.Write a function GCD(x,y) that returns the greatest common divisorfor x,y.
- Write a C function (only a function) that takes an array of integers called arr and the array size called s as parameters. Your function should then reverse the content of the array ( NOT print it in reverse order but actually reverse the content). for example if the array has the values 7,2,4,6,5 then the values in the array should become 5,6,4,2,7).Write a C++ function, lastLargestIndex, that takes as parameters an int array and its size and returns the index of the last occurrence of the largest element in the array. Also, write a program to test your function.In c++ Please Write the InOrder() function, which receives a vector of integers as a parameter, and returns true if the numbers are sorted (in order from low to high) or false otherwise. The program outputs "In order" if the vector is sorted, or "Not in order" if the vector is not sorted. Ex: If the vector passed to the InOrder() function is [5, 6, 7, 8, 3], then the function returns false and the program outputs: Not in order Ex: If the vector passed to the InOrder() function is [5, 6, #include <iostream>#include <vector>using namespace std; bool InOrder(vector<int> nums) { /* Type your code here */} int main() { vector<int> nums1(5); nums1.at(0) = 5; nums1.at(1) = 6; nums1.at(2) = 7; nums1.at(3) = 8; nums1.at(4) = 3; if (InOrder(nums1)) { cout << "In order" << endl; } else { cout << "Not in order" << endl; } vector<int> nums2(5); nums2.at(0) = 5; nums2.at(1) = 6;…