Linguagens e Ambientes de Programação (2016/2017) [Eng.Inf. - DI/FCT/UNL]

Enunciado do 1º Projeto Prático (OCaml)

Artur Miguel Dias


Datas

  • 31/mar (12:00) - Divulgação da versão inicial do enunciado
  • 08/abr (24:00) - Data e hora limite de entrega do 1º projeto. [Atenção, o prazo foi adiado para as 24:00.]
  • 10/abr (24:00) - Data e hora limite de entrega com atraso. Um valor de penalização por cada dia de atraso.


    Changelog


    Submission rules

    Express yourself!

    This project is about symbolic processing of algebraic expressions with a single variable.

    A representation of expressions is introduced and you are asked to write in OCaml several function that perform symbolic evaluation, differentiation, simplification, zero finding, etc.


    Module "Expressions"

    The aim of this project is to write a closed module named "Expressions" containing a data representation for algebraic expressions and containing the implementation of some functions over expressions.

    The module interface has already been fully written and you are not allowed to change it: Expressions.mli. As you can see, the representation of expressions is public and there is also a small number of public functions declared. All the other entities you define in the module body will be private.

    Use this file as starting point to write your module body: Expressions.ml.


    Evaluation and grades

    You will submit the file "Expressions.mli" via Mooshak.

    Around 80% of the grade of your group is automatically assigned by Mooshak. The remaining 20% is assigned manually by the teacher, who analyzes the quality of your code.

    A special case: In case of code of extremely bad quality, or code that uses the forbidden imperative mechanisms of OCaml, or code that constantly simulates imperative mechanisms and concepts, a special rule will be used so that the grade will be always below 50%, even if the program works well.

    To compile your module, Mooshak uses the following command

    After the compilation, Mooshak tests the module in the interpreter like this:

    It is not mandatory to develop this project in Linux. However, you should test the final version of your module in the laboratories because the official environmental for this project is the Linux version installed in the laboratories.

    It is also recommended you develop the project in Eclipse but, of course, this is also not mandatory.


    Data representation

    The algebraic expressions of this project contain float constants, occurrences of a single variable, occurrences of the four basic arithmetic operations, and there is also a special representation for polynomials. This is the OCaml type to use:

    In the case of a polynomial Poly l, the list l contains a sequence of coefficients of powers starting with power 0, meaning that the coefficients are in the reverse order. This is to allow inductive reasoning; the other way round does not work so well. For example, Poly [1.0; 2.0; 3.0] is our representation of 3x²+2x+1.

    To exemplify, here is an algebraic expression in conventional mathematical syntax:

    The previous expression can be written in our representation like this: It can also be written, using polynomials, as follows:

    Note that, in our representation, the variable is always expressed by the term V.


    Special constants

    You must use the following two global constants and, please, do not change their values:

    The constant epsilon is useful for checking if two floats are the same. As you know, performing calculations with floats causes some small inaccuracies. In the context of this work, you must never demand exact equality for floats. Instead, you must use the following function to check if two floats are equal:

    As for the constant step, it is used to navigate across the domain of an expression in small increments. The introdution of this constant spares one argument in some functions that are already a bit complicated.


    The functions of the module

    There are 8 public functions to implement. Please, write the functions using the inductive method. You can also take advantage of the predefined functions of the
    module List. Furthermore, in case you use other modules from the OCaml library, please make sure you never employ functions with side effects.
    pcount : float list -> int * int
    let pcount l = ...
    
    size : exp -> int
    let size e = ...
    
    eval : float -> exp -> float
    let eval v e = ...
    
    deriv : exp -> exp
    let deriv e = ...
    
    alike : float -> int -> exp -> exp -> bool
    let alike a n e1 e2 = ...
    
    newton : float -> exp -> float
    let newton s e = ...
    
    simpl : exp -> exp
    let simpl e = ...
    
    graph : int -> int -> float -> exp -> string list
    let graph nx ny s e = ...
    

    Regras principais


    Regras de entrega


    Outras regras


    Avaliação

    O docente responsável pela gestão e pela avaliação deste trabalho é o Professor Artur Miguel Dias.

    A nota do projeto será em grande parte determinada por meios automáticos, através do Mooshak. Portanto é essencial respeitar a especificação contida neste enunciado, em todos os seus detalhes.

    Mas, relativamente a programas que funcionem minimamente, também haverá uma apreciação mais subjetiva da qualidade, tendo em conta aspetos, tais como:

    Obviamente não é obrigatório fazer o trabalho todo para obter nota positiva. Mas, claro, vale a pena trabalhar para produzir uma solução bastante completa e com a melhor qualidade possível.


    Observações


    Final

    Bom trabalho! Esperamos que goste.