
{Copyright  2003 by Cioina Alexei. All rights reserved.}

 http://www.shareit.com 
 Product id 175528

WEB URLs
 http://www-rab.larc.nasa.gov/nmp/nmpCode.htm#TCioinaEval
 http://www.delphipages.com/result.cfm?ID=3482
 http://groups.yahoo.com/group/applied_mathematics/

KEYWORDS
 Mathematica 4.2        : http://www.wolfram.com
 UCalc 2.0              : http://www.ucalc.com
 Plamen Parser 1.6      : http://members.tripod.com/plamentd
 TExParser 3.3.2        : http://www.gemini2k.com/sparksoft 
 PrExpr 1.04            : http://www.pre.demon.co.uk/delphi.htm
 TurboPower StExpr 4.03 : http://sourceforge.net/projects/tpsystools
 Parser 10.1            : http://www.datalog.ro/delphi/parser.html
 clsMathParser v.3.2.3  : http://digilander.libero.it/foxes/MathExpressionsParser.htm
                        
DESCRIPTION
 TCioinaEval v7.6.1 class can parse, evaluate and differentiate a mathematical
 expression given as a string. 

BASE CONCEPTS
 Fast parsing speed: e.g. 9-15++ times faster than UCalc 2.0,
                          9-15++ times faster than TExParser 3.3.2,
                          20++ times faster than Parser10.1.

 Fast calculating speed: e.g. 65++ times faster than TurboPower StExpr 4.03,
                              10++ times faster than clsMathParser v.3.2.3 
                              6-14 times faster than Mathematica 4.2, 
                              4++  times faster than PrExpr 1.04
                              4++  times faster than TExParser 3.3.2
                              3++  times faster than Plamen Parser 1.6
                              2++  times faster than UCalc 2.0  
                              in particular cases it is faster than Parser 10.1.

 Low dynamic memory request: e.g. 2-6 lower than Mathematica 4.2.
 High calculation stability 
 Full calculation string export to Mathematica 4.2. 

MAIN FEATURES 

	accept operators: + - * / ^ = ~
	accept user defined functions and constants (maximum 65400) 
	accept user defined functions without parameters 
       defines functions on runtime.
	space like multiplication operator.
	functions accept any number of parameters (maximum 2147483647)
	functions accept varying number of parameters  
	error handling with localizing points of failure 
	optimized calculations (constant parts of expression are calculated) 
	parsed expression can be retrieved (added parenthesis)
       can calculate x^(p/q) when x<0, p is an Integer and q is an odd Integer.  
         p and q can  be  any Integer expression : e.g. 2-6, 6/2*3.
	expression can be differentiated
	can export to Mathematica 4.2 form
	can parse an expression array
	cross-platform compilation (Windows-Linux)
	variables automatic check possibility
	check IsMathExpressionLinear
	built-in small help
	exception control

TESTS
 I have tested TCioinaEval v7.6.1 with a large math expression obtained from
 Sin(x)^Cos(x) by differentiating 5 and 6 times respectively.
 Pentium III 750 MHz processor,128 Mb, Windows 2000 Prof SP2 :
  Expression Length   Parsing Time   Evaluating Time
  40234  bytes        6   seconds    0  seconds
  276942 bytes        827 seconds    0  seconds

 Pentium III 750 MHz processor,128 Mb, Red Hat Linux 7.3  :
  Expression Length   Parsing Time   Evaluating Time
  40234  bytes        11   seconds    0  seconds
  276942 bytes        555  seconds    0  seconds


SUPPORT 
 MS VS.NET, Delphi5, Delphi6, Delphi7, Kylix2, Kylix3, CBuilder6.

VERSION 
 TCioinaEval v7.6.1 is most recent version ( 13 Oct 2003).


BUILT-IN FUNCTIONS
============================================================================================================
System Unit:
{
Abs(x),
Sign(x),
Cos(x),
Exp(x),
Frac(x),
Int(x),
Ln(x),
Pi,
Sin(x),
Sqr(x),
Sqrt(x),
}

Math Unit:
{
ArcCos(x),
ArcCosH(x),
ArcCot(x),  ?
ArcCotH(x), ?
ArcCsc(x),  ?
ArcCscH(x), ? ?!
ArcSec(x),  ?
ArcSecH(x), ?
ArcSin(x),
ArcSinH(x),
ArcTan2(y,x),
ArcTan(x),
ArcTanH(x),
Ceil(x),
CoSecant(x),
CosH(x),
Cot(x),
Cotan(x),
CotH(x),
Csc(x),
CscH(x),
DegToRad(x),
Floor(x),
Infinity,
IsNan(x),
LnXp1(x),
Log10(x),
Log2(x),
LogN(x,y),
Log(x),
Max(x,y,z,...),
Mean(x,y,z,...),
Min(x,y,z,...),
Nan,
Power(x,y),
RadToDeg(x),
Sec(x),
Secant(x),
SecH(x),
SinH(x),
Sum(x,y,z,...),
Tan(x),
TanH(x)
}

My functions:
{
FractionalPart(x)   -> Frac(x)
IntegerPart(x)      -> Int(x)
ArcTan(x,y)         -> ArcTan2(y,x)
Ceiling(x)          -> Ceil(x)
DirectedInfinity(1) -> Infinity
DirectedInfinity(-1)-> -Infinity
False               -> 0    
True                -> 1  
Indeterminate       -> Nan
Null                -> Nan
Degree              -> Pi/180
E                   -> Exp(1) 
Random(x)           -> Random() or Random(Trunc(x))
Mod(x,y)            -> x-y*Floor(x/y)
Quotient(x,y)       -> Mod(x,y)
Div(x,y)            -> Floor(x/y) 
Eq(x,y)    -> x=y,
UnEq(x,y)  -> x<>y,
Ls(x,y)    -> x<y,
Gr(x,y)    -> x>y,
LsEq(x,y)  -> x<=y,
GrEq(x,y)  -> x>=y,
And(x,y,...),
Or(x,y,...),
Xor(x,y,...),
Not(x),
If     -> If(LsEq(x,0),x^2),
Bk     -> Bk(x1=sin(2)^2,x2=cos(2)^2,x1+x2)
While  -> Bk(s1=0,i1=0,While(Lseq(i1,9),Bk(i1=i1+1,s1=s1+i1)),s1),
Zero
}

Operators:
{
^  -> Power(x,y),
*  -> x*y,
/  -> x/y,
+  -> x+y,
-  -> x-y,
=  -> x=y
~  -> f(x)~Sin(x)^2
}

NOTE:
     ?   means that Delphi 6 has a bug in this function (for Delphi 6 I do not resolve bugs.  Please address all your remarks to http://www.borland.com ) 
     ?!  means that Delphi 7 has a bug in this function
     for Delphi 7 I resolved this problem with the formula: ArcCscH(x)=Ln(Sqrt(1+1/Sqr(x))+1/x)

TCIOINAEVAL PUBLIC INTERFACE.
============================================================================================================
type

{.$DEFINE EXTENDEDTYPE}
{.$DEFINE FUNCOBJTYPE}
{.$DEFINE NOTIFYEVENTTYPE}
{.$DEFINE STDCALLTYPE}

 {$IFDEF EXTENDEDTYPE}
   TReal=Extended;
 {$ELSE}
   TReal=Double;
 {$ENDIF}

  PTReal=^TReal;

  PTUserVarRec=^TUserVarRec;
  TUserVarRec= packed record
    StrExpr : string;
    Value   : PTReal;
    Protect : Boolean;
  end;

{$IFDEF FUNCOBJTYPE}
  TUserFunction=function (Pv:PVectorPTReal;PvCount:Integer):TReal of object;
 {$ELSE}
  {$IFDEF STDCALLTYPE}
   TUserFunction=function (ParamCount:Integer):TReal;stdcall;
  {$ELSE}
   TUserFunction=function (Pv:PVectorPTReal;PvCount:Integer):TReal;
  {$ENDIF}
{$ENDIF}

 TUserFuncRec= packed record
   FuncName    : string;
   FuncAddress : TUserFunction;
   VarCount    : Integer;
   PvInput     : PVectorPTReal;
  end;

 
  TVarPropertyRec=packed record
   ProtectEndedWithNumber,
   ProtectEndedWithoutNumber:Boolean;
  end;


  TUserFuncArray=array of TUserFuncRec;
  TUserVarArray=array of TUserVarRec;
  TUserValuesArray=array of TReal;

type
 TCioinaEval=class
  protected
   procedure fClearMathLinkString;virtual;

  public
   OnVerifySyntaxSemanticsError:TProcedureEvent;
   OnDoMathExpressionError:TProcedureEvent;
   OnStdCallUserFunction:TStdCallUserFunction;
   class function OwnerInfo:string;
   class function VersionInfo:string;
   class function TypeInfo:string;
   class function DedicationInfo:string;

   function  IsValidIdentName(s:string):Boolean;
   function  IsExistString(var s,ss:string;flag:Boolean):Boolean;
   procedure ExpressionReplace(var s:string; const OldPattern, NewPattern:string);
   function  DoMathExpression:TReal;overload;
   function  DoMathExpression(VarValues:TUserValuesArray):TReal;overload;
   function  DoVectorOfMathExpressions:PVectorPTReal;overload;
   function  DoVectorOfMathExpressions(VarValues:TUserValuesArray):PVectorPTReal;overload;
   function  DoRunTimeFunction(i:Integer;Values:TUserValuesArray):TReal;
   function  DoUserFunction(i:Integer;Values:TUserValuesArray):TReal;

   procedure Clear;
   procedure VerifySyntaxSemantics(MathStr,VarStr:string;CheckUnknownVar:Boolean);overload;
   procedure VerifySyntaxSemantics(MathStr:string);overload;
   procedure VerifySyntaxSemantics(MathStr:string;RecordVar:TUserVarArray;CheckUnknownVar:Boolean);overload;

   procedure VerifySyntaxSemanticsAndDerivation(MathStr,VarStr,DerStr:string;CheckUnknownVar:Boolean);overload;
   procedure VerifySyntaxSemanticsAndDerivation(MathStr,DerStr:string);overload;
   procedure VerifySyntaxSemanticsAndDerivation(MathStr:string;RecordVar:TUserVarArray;DerStr:string;CheckUnknownVar:Boolean);overload;
   procedure DeleteParantheses(var s:string);
   procedure ClearMathExpressionString;
   procedure ClearDerivativeExpressionString;

   property  ProtectVariablesEndedWithNumber:Boolean read fProtectVariables.ProtectEndedWithNumber
                                                     write fProtectVariables.ProtectEndedWithNumber;
   property  ProtectVariablesEndedWithoutNumber:Boolean read fProtectVariables.ProtectEndedWithoutNumber
                                                        write fProtectVariables.ProtectEndedWithoutNumber;
   property  ProtectVariables:TVarPropertyRec    read fProtectVariables  write fProtectVariables;
   property  SpaceLikeMultiply:Boolean           read fSpaceLikeMultiply write fSpaceLikeMultiply;
   property  TotalFunctionCount:Integer          read fTotalFunctionCount;
   property  MaxIterations:Cardinal              read fMaxIterations write fMaxIterations;
   property  MaxStack:Cardinal                   read fMaxStack write fMaxStack;
   property  VariableLowIndex:Integer            read fVariableLowIndex;
   property  VariableCount:Integer               read VarCount;
   property  VariableName[i:Integer]:string      read ScoateNumeVar;
   property  VariableArray:PVector1              read ScoateVectorVar;
   property  MathExpressionCount:Integer         read MathValueCount;
   property  MathExpressionString:string index 0 read GetMath;
   property  DerivativeExpressionString:string index 0  read GetDerivative;
   property  DerivativeVariableString:string     read DerVar;
   property  MathematicaFormVariableNames:string read GetVariable;
   property  MathematicaFormMathExpressionString:string index 1 read GetMath;
   property  MathematicaFormDerivativeExpressionString:string index 1 read GetDerivative;
   property  ErrorFlag:Boolean                   read ErrorMsg;
   property  ErrorNumber:Integer                 read fErrorNumber;
   property  ErrorMessageInfo:string             read ErrorMessage;
   property  UserFunctionCount:Integer           read fUserFuncCount;
   property  UserFunctionVarCount[i:Integer]:Integer read fUserFuncVarCount;
   property  UserFunctionName[i:Integer]:string  read fUserFuncName;
   property  RunTimeFunctionCount:Integer           read fRunTimeFuncCount;
   property  RunTimeFunctionVarCount[i:Integer]:Integer read fRunTimeFuncVarCount;
   property  RunTimeFunctionName[i:Integer]:string  read fRunTimeFuncName;
   property  RunTimeFunctionDefinition[i:Integer]:string  read fRunTimeFuncDefinition;
   property  BuiltInFunctionInfo[i:Word]:string  read UsedFunc;
   property  IsMathExpressionVariable:Boolean    read fMathVariabFlag;
   property  IsMathExpressionPublic:Boolean      read fMathPublFlag;
   property  IsMathExpressionProtected:Boolean   read fMathPrFlag;
   property  IsMathExpressionLinear:Boolean      read fMathLinearFlag;
   property  MathException: Integer             read ExceptionId;
   property  ExceptionInfo[i:Integer]:string    read fExceptionInfo;
   property  SetPowerOperator:Boolean            read PowerOperator write PowerOperator;
   property  AllocDynamicMemoryInfo:Cardinal     read fDynamicMemoryInfo;
   property  OriginalMathExpressionString:Boolean read fOriginalMathExpressionString
                                                  write SetOriginalMathExpressionString;
  constructor Create;overload;
  constructor Create(FuncArray:TUserFuncArray);overload;
  destructor  Destroy;override;
 end;


============================================================================================================
