Module Derivate (.ml)

module Derivate: sig .. end

How to formally differentiate a function

This small program shows how differentiation can be seen as a purely formal and automatic procedure.

Program in OCaml v4+ by Lilian Besson (ENS Cachan) for MA 101 at Mahindra École Centrale, (C) 2014.

GPLv3 Licenced.
Author(s): Lilian BESSON



Define the data type.


type funct = 
| Id of string
| Lambda of float
| Sin of funct
| Cos of funct
| Exp of funct
| Ln of funct
| Prod of funct * funct
| Inv of funct
| Sum of funct * funct
| Power of funct * int
| Comp of funct * funct
| Unknown of string
A function is an expression depending on some variables. We choose to work only with sin, cos, exp and ln as basic functions.

Examples.


val x : funct
val fsin : funct
val fcos : funct
val fexp : funct
val fln : funct
val y : funct
val fpi : funct
val fpoly1 : funct
val fcossin : funct
val fexpln : funct
val finv : funct
val fsqsq : funct
val fh : funct

Simplify as much as possible.


exception Not_defined
Expression returned if the function is not valid (some basic check, not sophiscated ones).
val canonic : funct -> funct
Recursively put in canonic form.

Pretty printing a function.


val print : ('a, Format.formatter, unit) Pervasives.format -> 'a
val sprint : ('a, unit, string) Pervasives.format -> 'a
val fprint : Pervasives.out_channel ->
('a, Pervasives.out_channel, unit) Pervasives.format -> 'a
val string_of_funct_novar : funct -> string
To a string without the variable name.
val string_of_funct : funct -> string
To a string with the variable name.
val print_funct_novar : funct -> unit
Printing.
val print_funct : funct -> unit
Printing.
val print_funct_fancy : string -> string -> funct -> unit

Examples.



Differentiate with formal rules.


val differentiate_aux : funct -> funct
val differentiate : funct -> funct
Final value, when we put in simplify f as much as possible before differentiating.

Examples.


GA|Analytics