#pragma once #include // assert #include #include #include #include #include #include #include #include #include using namespace std; // -------------- Task A -------------- // Returns arithmetic, geometric and harmonic mean for 3 values a,b,c. tuple means0(double a, double b, double c); // Returns arithmetic, geometric and harmonic mean for a vector. tuple means(const vector& v); // -------------- Task B -------------- /** This function opens the ASCII-file named @p file_name and reads the double data into the C++ vector @p v. If the file @p file_name does not exist then the code stops with an appropriate message. @param[in] file_name name of the ASCII-file @param[out] v C++ vector with double values */ void read_vector_from_file(const string& file_name, vector& v); /** This function opens the ASCII-file named @p file_name and rewrites its with the double data from the C++ vector @p v. If there are problems in opening/generating file @p file_name then the code stops with an appropriate message. @param[in] file_name name of the ASCII-file @param[in] v C++ vector with double values */ void write_vector_to_file(const string& file_name, const vector& v); /** Fills the double-vector @p v with data from an input stream @p istr until this input stream ends regularily. The vector is cleared and its memory is automatically allocated. @param[in] istr input stream @param[out] v C++ vector with double values @warning An exception is thrown in case of wrong data format or corrupted data. */ void fill_vector(istream& istr, vector& v); // -------------- Task C -------------- // Sums up all positive integers less or equal n which are multiples of 3 or of 5 (including or!) by brute force. long int sum_of_spec(int n); // Sums up all positive integers less or equal n which are multiples of 3 or of 5 (including or!) by inclusion-exclusion principle. double formula(int n); // -------------- Task E -------------- // Inserts n random numbers into sorted vector v such that v remains sorted. void insert_into_vector(vector& vec, int n); // Inserts n random numbers into sorted list such that the list remains sorted. void insert_into_list(list& lst, int n); // -------------- Task F -------------- // Counts number of possible decompositions with 2 primes that sum up to k. int single_goldbach(int k); // Counts number of possible decompositions with 2 primes that sum up to k for all even numbers k \in {4,...,n}. vector count_goldbach(int n); // Prints all decompositions of k. void print_decomps(int k); // -------------- Task G -------------- // Sigmoid function 1/(1+exp(-x)) double sigmoid(double x); class DenseMatrix { private: double sigmoid(double x); size_t rows; size_t cols; vector matrix; public: DenseMatrix(size_t n, size_t m); // Constructor vector Mult(const vector& vec) const; vector MultT(const vector& vec) const; void print() const; }; class DenseMatrix2 { private: size_t rows; size_t cols; vector u_; vector v_; public: DenseMatrix2(vector const u, vector const v); // Constructor vector Mult(const vector& vec) const; vector MultT(const vector& vec) const; };