Recent

Author Topic: ArtFormula - expression evaluation, symbolical differentiation, scripting engine  (Read 9647 times)

Art

  • Newbie
  • Posts: 1
ArtFormula package contains two nonvisual Delphi and Lazarus componenst for symbolic expression parsing and evaluation. Provides runtime scripting engine for automating your programs.

Provides:
  • 7 arithmetic operations
  • 10 logical operations
  • 6 bitwise operations
  • string concatenation (@) and like (==) operator
  • 24 arithmetic functions
  • 10 statistical functions
  • 2 logical functions
  • 17 string functions
  • 13 date functions
  • 14 programming functions
  • User defined constant
  • User defined variables
  • User defined functions (modules)
  • Subroutines, global vars and constants
  • Symbolical differentiation of functions with basic simplification of resulting derivatives

Arithmetic operation:
x + y, x - y, x * y, x / y, x % y (Mod), x ^ y (power), x\ y (Div)

Logical operation (true=1, false=0):
x > y, x < y, x >= y, x <= y, x = y, x <> y, ! x (not), x & y (and), x | y (or), x xor y

Bitwise operations:
x && y (band), x || y (bor), !!x (bnot), x bxor y, x >> y (shr), x << y (shl)

Predefined constants:
Pi = 3.1415926535897932385
True = 1
False = 0

Functions:
sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, asinh, acosh, atanh, sqrt, exp, log, lg (log base 10), int (integer part of a number), frac (fractional part of a number), abs, sign, rnd, randomize, trunc (truncates value to a specified number of digits), round (rounds value to a specified number of digits)
max(x,y...), min(x,y,...), count(x,y,...), sum(x,y,...), sumofsquares(x,y,...), avg(x,y,...), variance(x,y,...), variancep(x,y,...), stddev(x,y,...), stddevp(x,y,...)
iff(cond,x,y) (if cond = true then result = x else result = y),
isnumber(x)
chr(x), length(s), trim(s), trimleft(s), trimright(s) lowercase(s), uppercase(s), midstr(s,x,y), leftstr(s,x), rightstr(s,x), pos(s,t), code(s), format(s,x), formatf(s,x), stringofchar(c,n), concat(s1,s2,...), hex(s)
date(s), now, formatdate(s,d), year(d), month(d), day(d), hour(d), minute(d), second(d), millisecond(d), isleapyear(n), dayofweek(d), encodedate(y,m,d)

Programming:

TArtFormula provides two styles of programming: formula style and scripting style. The first style assumes that all statements have the form of function call. The second style imply that you use common program language notation.

For example:

 
Code: [Select]
   block(defines('i','n'), set('n',1),
          series(set('i',1), val('i')<=5, inc('i'), set('n',val('n')*val('i'))),
          msg('5! = '+val('n'),'result',0))

Is equal to:

Code: [Select]
   begin
     var 'i', 'n' end;
     $n:=1;
     for $i:=1;  $i<=5;  $i++ do
       $n := $n*$i;
     next;
     msg('5! = '+val('n'),'result',0);
   end
You can mix two styles in one program.

TArtFormula programming language supports:

  • Variables definitions
  • Assigmnent statement
  • Increment and Decrement operations
  • Return function
  • Compound statement (BEGIN... END)
  • IF statement
  • WHILE loop
  • UNTIL loop
  • FOR loop
  • Interface functions: msg('text','caption',props), input('caption', 'text', defvalue)
  • Subroutines, global vars and global constants (with extended syntax)

Spreadsheet applicatiuon:

TArtFormula can be used in spreadsheet application. E.g. using GetVarsCount and GetVarValue event handlers one can implement calculation of sum(a1:b4), avg(c1:c99) and similar function calls, where a1:b4 and c1:c99 are range of sheet cells.

Hope it can be usefull for somebody...

Link: http://artsoft.nm.ru/download.html
« Last Edit: August 28, 2012, 02:04:18 pm by Art »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Nice, thanks!

So now we have an expression evaluator supplied with fpc (see a post from marcov from a while ago), this one and the one used in fpspreadsheet.

A lot of choice ;)

Regards,
BigChimp
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

drsbiker

  • Newbie
  • Posts: 1
Been working tieh ArtFormula.   Rather easy to implement.    Thanks.   :)

BUT

I am working in both Win32 and WinCE....
ArtFormula works correctly and sends me back the proper result in win32..

But when I complile the EXACT same code in the winCE for ARM I get a totally different answer.
Always the same value call after call....

I am having a thought that is might be associated to  missalignment and have added "unaligned" to the pointers but no change.

Anyone have any corrections? or suggstions for super simple expressions in winCe
here is one that I am having issues calculating. 
"(48 * 256 + 273) * 79.99 / 65535"         Win32=15.14             WinCe ARM=25.39

« Last Edit: February 18, 2013, 04:30:16 am by drsbiker »

 

TinyPortal © 2005-2018