(************************************************** ** expression.mli *** ** Formal calcul module *** ** POUSSARD PA march 2000 *** **************************************************) open Algebra open Format (* this is a subtype of both Field and Vectorial_Space *) module type Expression = sig (* include Field *) type scalar type trans = (* transantes function, like sin() or cos() *) { (* the name *) name : string; (* the function that computes the value *) calcul : scalar -> scalar; (* the derivate *) deriv : elem; (* the name of the variable you used to write the derivate *) name_var: string } (* the internal type used to represent expressions *) and elem = Add of elem * elem | Sub of elem * elem | Div of elem * elem | Mul of elem * elem | Pow of elem * int | Tra of trans * elem | Cst of scalar | Var of string (* environment used to store values of variables *) type 'a environment = (string * 'a) list (*** field struct ***) val zero : elem (* zero ! *) val one : elem (* one ! *) val t_of_int : int -> elem (* the standard mapping from integer *) val (++) : elem -> elem -> elem val (--) : elem -> elem -> elem val ( ** ) : elem -> elem -> elem val ( @ ) : scalar -> elem -> elem val (==) : elem -> elem -> bool val opp : elem -> elem val inv : elem -> elem val (//) : elem -> elem -> elem val cst : scalar -> elem val var : string -> elem val trans : trans -> elem -> elem val print : elem -> unit val write : formatter -> elem -> unit val parse : char Stream.t -> elem val read : in_channel -> elem val write_bin : out_channel -> elem -> unit val read_bin : in_channel -> elem val simplify : elem -> elem val derive : elem -> string -> elem (* derive n times *) val sder : elem -> string -> int -> elem val eval : elem -> scalar environment -> scalar (* conjugate all constant in the expression, live the variable unchanged !*) val conjugate : elem -> elem end module Expression (R:Field) : Expression with type scalar = R.elem