Home
License
What's new
Downloads
FLL manual
Source codes
Fractal gallery
Awards
Links
Caricatures


Formulae Compilator 2.03
Formulae Compilator 2.03




Sorry for any spelling mistakes, our natural language is Russian.

Table of content:

  1.0   Acknowledgements
  2.0   Limitations
  3.0   Introduction
        3.1   What is the formula compilator ?
        3.2   Formula Files
  4.0   Formula's Anatomy
        4.1   Formula it's a program
        4.2   Formula it's a Delphi/Pascal program
        4.3   Requirements
        4.4   Simple project
        4.5   Temporarly variable declaration
        4.6   Difficult project
        4.7   The complex functions
  5.0   Functions of complex variables
        5.1   List of the functions and procedures
        5.2   Functions selector
        5.3   Changes in versions 2.03
        5.4   Examples of the new formulaes




Acknowledgements:

Bradley Beacham for FRMTUTOR.TXT AN INTRODUCTION TO THE FRACTINT FORMULA PARSER Borland Corp. for Delphi Command Line compiler

Limitations:

Our formulae compilator is not a parser. It's part of program, which calculated one step of iteration process. It can't to read formulae directly, since complex type is not standart type for Delphi.

Introduction:

3.1 What is the formula compilator ? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It is a new part of the fractal-generating program Fractal Explorer (version 1.13 and above). FE has many different fractal's formula types itself, the formula compilator allows you to add new fractals, without having to change the program. These formulae are stored in Fractal Spot files, and may be viewed and edited by the user. 3.2 Formula Files ~~~~~~~~~~~~~~~~~~~ New user formula are not saved to simple file. Formula will be stored into Fractal Spot file (*.frs), which contained internal data to generating image. Therefore, for building one image FE required one FRS file (formula already implemented into).

Furmula's anatomy:

Why compilator ? Compiled program always work quickly than interpretator. 4.1 Formula it's a program ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fractal Explorer use formula's text for building Dinamic Link Library (DLL), after that load the new dll (if you interest - look to system TEMP directory - linked by strings "SET TMP=" or "SET TEMP=" in your autoexec.bat). After formula changed (or exit FE) DLL will be unloaded from memory and will deleted with the project source. 4.2 Formula it's a Delphi/Pascal program ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For compile new formula FE will be create Delphi project file (*.DPR) in the temporary directory and execute Borland Delphitm Command Line compiler to generate the DLL file. Since we using Delphi for writting Fractal Explorer, we are using Delphi for the DLL compilation. 4.3 Requirements ~~~~~~~~~~~~~~~~~~ For using the Formula Compilator FE require a lots of the files. They are listed below: dcc32 exe math dcu sharemem dcu sysinit dcu system dcu sysutils dcu windows dcu rlink32 dll sysutils inc make pif All files must be exist in the Fractal Explorer directory. FE will be check presence these files before compile new formula. If you lost one or more files - download full archive, and unzip it into FE folder. 4.4 Simple project ~~~~~~~~~~~~~~~~~~~~ Complex number are two-part number. First part - is a real part, and second part - is a imaginary part. Declaration of a complex number are: Z = X + jY, where "j" - imaginary part sign (square root from "-1"). Fractal Explorer using such format of complex number. For illustrating of the fractal formula we will take the classical Mandelbroth Set. It's listed below: z_new = z * z + c To get the copy of the Mandel-formula, you will write in the edit box: ---------Cut----Cut---------- var k: Extended; Begin k:=(x+y) * (x-y) + cr; y:=2 * x * y + ci; x:=k; End; ---------Cut----Cut---------- "x" is a real part of the "z" complex number, and "y" - imag part. "cr" is a real part of the "c" complex number, and "ci" - imag part. "z" value received in the "x" and "y" variables. New value of "z" should be returned in this variables. The "k" variable used to save of the new "x" value before calculation of the new "y" value. Press "Go" button. FE make Delphi project for this formula: ---------Cut----Cut---------- library proba; Uses ShareMem, SysUtils, Math; Procedure Formula( var x, y, cr, ci: Extended; const p1r, p1i, p2r, p2i, p3r, p3i: Extended; var cA1, cA2, cA3, cA4: TComplex const Fn1, Fn2: Integer); export; var k: Extended; Begin k:=(x+y) * (x-y) + cr; y:=2 * x * y + ci; x:=k; End; exports Formula index 1 name 'Formula'; BEGIN END. ---------Cut----Cut--------- For the people, which know the Delphi/Pascal programming language this code are not complicated. But the declaration of the Procedure Formula will be interesting to all: Procedure Formula( var x, y, cr, ci: Extended; const p1r, p1i, p2r, p2i, p3r, p3i: Extended; var cA1, cA2, cA3, cA4: TComplex const Fn1, Fn2: Integer); export; Here variables: x, y - current value of the iteration data on the every cycle; cr,ci - real and imag party Julie parameter (C); p1r..p3i - real and imag party fractal parameters P1, P2 and P3. You can modify values of cr and ci. For example: ---------Cut----Cut--------- var c1,c2: Extended; Begin c1:=x; c2:=y; k:=(x+y) * (x-y) + cr; y:=2 * x * y + ci; x:=k; cr:=c1; ci:=c2; End; ---------Cut----Cut--------- Values, received in p1r, p1i, p2r, p2i, p3r, p3i parameters are real and imag parts of P1, P2 and P3 fractal parameters (see "Select formula" dialog). They are constant for you formula. That all folks ! NOTE: do not write calculation cycle - Fractal Explorer make it self !!! 4.5 Temporarly variable declaration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Separate you formula to little parts and use temporarly variables (remembe, what it require "var" section); Sintax for a temporary variable declaration: var name1, name2, name3: [type] Type may be "Single", "Double" and "Extended". Difference: type | range | significant digits | size in bytes ---------+-----------------------------+--------------------+-------------- Single | 1.5x10^_45 .. 3.4x10^38 | 7_8 | 4 Double | 5.0x10^_324 .. 1.7x10^308 | 15_16 | 8 Extended | 3.6x10^_4951 .. 1.1x10^4932 | 19_20 | 10 "Single" work quickly, but precision is smallest; "Double" work slow, but precision is good; "Extended" work very slowly, but precision is very good. Fractal Explorer use "Double" type for calculations and we recommended it. Examles: var tmp1,tmp2: Double; Begin <>formula<> End; var h1x,h1y: Double; h2x,h2y: Double; Begin <>formula<> End; var h1x,h1y: Double; h2x,h2y: Double; f: Extended; Begin <>formula<> End; 4.6 Difficult project ~~~~~~~~~~~~~~~~~~~~~~~ Mandel/Talis formula: z_new = z*z + c; c_new = c*c/(c+P1) + z_new; Write: ---------Cut----Cut--------- var h1x,h1y, h2x,h2y, f: Extended; // -temporary variables Begin h1x:=(x+y)*(x-y)+cr; // -calculating z_new y := x*y*2 +ci; // z_new = z*z + c x := h1x; h1x:= (cr+ci)*(cr-ci); // -h1 = c*c h1y:= cr*ci * 2; h2x:= cr+p1r; // -h2 = c+P1 h2y:= ci+p1i; f := h2x*h2x+h2y*h2y+1E-10; // -c_new=h1/h2 + z_new cr :=(h2x*h1x+h2y*h1y)/f+x; ci :=(h2x*h1y-h2y*h1x)/f+y; End; ---------Cut----Cut--------- You calculate new values for "x" (real part) and "y" (imag part) of complex variable "z". Also, you change cr and ci values - real and imag parts of "c". Next step will be use z_new and c_new. 4.7 The complex functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can use any function of the complex variables in your formula, but you necessary describe them, like that (remember, that Z = X + jY and C = CR + jCI): z*z: X_new := (X-Y)*(X+Y); Y_new := 2 * X*Y; z*c: X_new := X*CR - Y*CI; Y_new := X*CI + Y*CR; z*z*z: X_new := X*(X*X-3*Y*Y); // -this is optimized formula Y_new := Y*(3*X*X-Y*Y); z*z*z*z: tmp_r := (X-Y)*(X+Y); tmp_i := 2 * X*Y; X_new := (tmp_r - tmp_i) * (tmp_r + tmp_i); Y_new := 2 * tmp_r * tmp_i; 1/z: tmp := X*X + Y*Y + 1E-10; // -without 1E-10 may by X_new := X / tmp; // divizion by zero Y_new :=-Y / tmp; 1/(z*z): tmp := X*X + Y*Y; tmp := tmp * tmp + 1E-10; // -see above X_new := (X*X - Y*Y) / tmp; Y_new := (2*X * Y ) / tmp; Sqrt(z): tmp := Sqrt(X*X + Y*Y); X_new := Sqrt(Abs((X + tmp)/2)); Y_new := Sqrt(Abs((tmp - X)/2)); Exp(z): // e^z tmp := Exp(X); X_new := tmp * Cos(Y); Y_new := tmp * Sin(Y); Exp(1/z): tmp := X*X + Y*Y + 1E-10; // -see above s1 := X/tmp; s2 :=-Y/tmp; tmp := Exp(s1); X_new := tmp * Cos(s2); Y_new := tmp * Sin(s2); Ln(z): X_new :=Log2(X*X+Y*Y)/2.7182818285; Y_new :=ArcTan2(Y,X); z^c: h1x :=Log2(X*X+Y*Y)/2.7182818285; // -Ln(z) h1y :=ArcTan2(Y,X); h2x :=h1x*CR - h1y*CI; // -Ln(z)*c h2y :=h1y*CR + h1x*CI; f :=Exp(h2x); // -Exp(Ln(z)*c) X_new :=f*Cos(h2y); Y_new :=f*Sin(h2y); Sin(z): tmp := Exp(Y)/2; // -optimized formula (!) tmp2 := 0.25/tmp; X_new := Sin(X) * (tmp+tmp2); Y_new := Cos(X) * (tmp-tmp2); Cos(z): X_new := Cos(X)*Cosh(Y); // -not optimized formula Y_new :=-Sin(X)*Sinh(Y); Tan(z): // -tangens X_new := Sin(2*X)/(Cos(2*X)+Cosh(2*Y)); Y_new := Sin(2*Y)/(Cos(2*X)+Cosh(2*Y)); Sinh(z): // -hiperbolic sinus X_new := Sinh(X)*Cos(Y); // -not optimized formula Y_new := Cosh(X)*Sin(Y); Cosh(z): // -hiperbolic cosinus X_new := Cosh(X)*Cos(Y); // -not optimized formula Y_new := Sinh(X)*Sin(Y); You must change X, Y, CR and CI variables to those, which required by you formula.

Functions of complex variables:

5.1 List of the functions and procedures ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ First of all, we want to describe the type of the complex values. This type are declared in Complex.pas as listed below: Type TComplex = record real: Extended; imag: Extended; end; All of the functions which listed below will use this type for their operations. It's a very important part of the new version Formulae Compilator. List of the functions and procedures I. Function MakeComplex(real, imag: Extended): TComplex; This function makes TComplex value from the two variables, which contains the real and imag parts of the complex value. Use this function for translate the input values (x,y, cr,ci and p1r..p3i) to the complex data type. After translation you can use result in another functions and procedures. Also, you can use this function for make TComplex value from constant, for example: tmp:=MakeComplex(3,0) - make real numeric "3" as TComplex. II. Procedure SetResult(var x,y: Extended; const complex: TComplex); This procedure makes final results accessible for Formulae Compilator. As described in [4.4] part of this manual, the result values must be returned in the "X" and "Y" variables. You can use two operations for it: x:=Z.real; y:=Z.imag; but now you can use the SetResult procedure for this. Below are listed functions and procedures for mathematical operations. Every operations has two release. First - as procedure with no result returning and second - as function, which return the result of the operation as TComplex value. Any procedure keep the result complex value in the variable, which passed as the first parameter. III. Sum of the two complex: Result := Cmp1 + Cmp2; Procedure CAddV(var Cmp1: TComplex; const Cmp2: TComplex); Function CAdd (const Cmp1, Cmp2: TComplex): TComplex; Add real value to complex: Result := Cmp1 + t; Function CAddR (const Cmp1: TComplex; t: Extended): TComplex; IV. Subtraction of the two complex: Result := Cmp1 - Cmp2; Procedure CSubV(var Cmp1: TComplex; const Cmp2: TComplex); Function CSub (const Cmp1, Cmp2: TComplex): TComplex; Subtract real value from complex: Result := Cmp1 - t; Function CSubR (const Cmp1: TComplex; t: Extended): TComplex; V. Multiplication of the two complex: Result := Cmp1 * Cmp2; Procedure CMulV(var Cmp1: TComplex; const Cmp2: TComplex); Function CMul (const Cmp1, Cmp2: TComplex): TComplex; Multiplicate complex to real value: Result := Cmp1 * t; Function CMulR (const Cmp1: TComplex; t: Extended): TComplex; VI. Division of the two complex: Result := Cmp1 / Cmp2; Procedure CDivV(var Cmp1: TComplex; const Cmp2: TComplex); Function CDiv (const Cmp1, Cmp2: TComplex): TComplex; Division of the complex to real value: Result := Cmp1 / t; Function CDivR (const Cmp1: TComplex; t: Extended): TComplex; Next set of the functions realize the optimized functions VII. Square of the complex: Result := Cmp1^2; Procedure CSqrV(var Cmp1: TComplex); Function CSqr (Cmp1: TComplex): TComplex; VIII. Third power of the complex: Result := Cmp1^3; Procedure CTripleV(var Cmp1: TComplex); Function CTriple (Cmp1: TComplex): TComplex; IX. Fourth power of the complex: Result := Cmp1^4; Procedure CFourV(var Cmp1: TComplex); Function CFour (Cmp1: TComplex): TComplex; X. Flip of the complex: Result.real := Cmp1.imag Result.imag := Cmp1.real Procedure CFlipV(var Cmp1: TComplex); Function CFlip (Cmp1: TComplex): TComplex; XI. Reversing of the complex value: Result := 1 / Cmp1; Procedure CRevV (var Cmp1: TComplex); Function CRev (const Cmp1: TComplex): TComplex; XII. Another reversing: Result := 1 / (Cmp1 - Cmp2); Procedure CRev2V(var Cmp1: TComplex; Cmp2: TComplex); Function CRev2 (Cmp1,Cmp2: TComplex): TComplex; XIII. Squre root of the complex: Procedure CSqrtV(var Cmp1: TComplex); Function CSqrt (Cmp1: TComplex): TComplex; XIV. Exponent of the complex: Procedure CExpV (var Cmp1: TComplex); Function CExp (Cmp1: TComplex): TComplex; XV. Logorithm of the complex: Procedure CLnV (var Cmp1: TComplex); Function CLn (Cmp1: TComplex): TComplex; XVI. Raise complex to real power Result := Cmp1^t; Procedure CPowerRV(var Cmp1: TComplex; t: Extended); Function CPowerR (const Cmp1:TComplex;t: Extended): TComplex; XVII. Raise complex value to complex power: Result := Cmp1^Cmp2; Procedure CPowerV(var Cmp1: TComplex; Cmp2: TComplex); Function CPower (Cmp1,Cmp2: TComplex): TComplex; Trigonometric functions XVIII. Sinus of the complex: Procedure CSinV (var Cmp1: TComplex); Function CSin (Cmp1: TComplex): TComplex; XIX. Cosinus of the complex: Procedure CCosV (var Cmp1: TComplex); Function CCos (Cmp1: TComplex): TComplex; XX. Tangens of the complex: Procedure CTanV (var Cmp1: TComplex); Function CTan (Cmp1: TComplex): TComplex; XXI. CoTangens of the complex: Procedure CCotanV (var Cmp1: TComplex); Function CCotan (Cmp1: TComplex): TComplex; XXII. Hiperbolic sinus of the complex: Procedure CSinhV(var Cmp1: TComplex); Function CSinh (Cmp1: TComplex): TComplex; XXIII. Hiperbolic cosinus of the complex: Procedure CConhV(var Cmp1: TComplex); Function CCosh (Cmp1: TComplex): TComplex; XXIV. ArcSinus of the complex: Procedure CASinV (var Cmp1: TComplex); Function CASin (const Cmp1: TComplex): TComplex; XXV. ArcCosinus of the complex: Procedure CACosV (var Cmp1: TComplex); Function CACos (const Cmp1: TComplex): TComplex; XXVI. ArcTangens of the complex: Procedure CATanV (var Cmp1: TComplex); Function CATan (const Cmp1: TComplex): TComplex; XXVII. ArcSinus hyperbolic of the complex: Procedure CASinhV (var Cmp1: TComplex); Function CASinh (const Cmp1: TComplex): TComplex; XXVIII. ArcCosinus hyperbolic of the complex: Procedure CACoshV (var Cmp1: TComplex); Function CACosh (const Cmp1: TComplex): TComplex; XXIX. ArcTangens hyperbolic of the complex: Procedure CATanhV (var Cmp1: TComplex); Function CATanh (const Cmp1: TComplex): TComplex; Additional functions XXX. Changes sign of imaginary part of the complex value Result.real := Cmp1.real; Result.imag :=-Cmp1.imag; Procedure CConjV (var Cmp1: TComplex); Function CConj (const Cmp1: TComplex): TComplex; 5.2 Function Selector ~~~~~~~~~~~~~~~~~~~~~~~ From the "Select fractal" dialog the two functions can be changed. Such change does not require additional compilation of the formula. You can use in your formula one or two functions and change fractal directly from the "Select fractal" window. To support Function Selections the procedure FuncDisp implemented: Procedure FuncDisp(const Fn: Integer; var Cmp1: TComplex); In the procedure listed above the Fn parameter is Fn1 or Fn2 variables, which passed to formula from the outside. For example, write in your formula: FuncDisp(Fn1, Z); and you can change first function to get changes in the formula. Examples by the Mandelbrot-set with Function Selector: var Z,Z0: TComplex; Begin Z :=MakeComplex(x,y); // make complex from [x] and [y] variables Z0:=MakeComplex(cr,ci); // make complex from [cr] and [ci] variables FuncDisp(Fn1, Z); // change source value of the Z variable Z :=CAdd( CSqr(Z), Z0); // calculate the Mandel SetResult(x,y, Z); // store result to [x] and [y] variables End; 5.3 Changes in versions 2.03 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [+] speed improvements; [+] little bug fixes; [+] added new procedures and functions: Procedure CConjV(Cmp1: TComplex); Function CConj(Cmp1: TComplex): TComplex; 5.4 Examples of the new formulaes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I. Mandelbrot furmula: var Z,Z0: TComplex; Begin Z :=MakeComplex(x,y); // make complex from [x] and [y] variables Z0:=MakeComplex(cr,ci); // make complex from [cr] and [ci] variables Z :=CAdd( CSqr(Z), Z0); // calculate the Mandel SetResult(x,y, Z); // store result to [x] and [y] variables End; II. Mandel/Talis formula: z_new = z*z + c; c_new = c*c/(c+P1) + z_new; Write: ---------Cut----Cut--------- var Z,Z0,P1: TComplex; Begin Z :=MakeComplex(x,y); // make complex from [x] and [y] variables Z0:=MakeComplex(cr,ci); // make complex from [cr] and [ci] variables P1:=MakeComplex(p1r,p1i); // make complex from [p1r] and [p1i] variables Z :=CAdd( CSqr(Z), Z0); // calculate Z_NEW Z0:=CDiv(CSqr(Z0), CAdd(Z0,P1)) // Z' = C*C/(C+P1) Z0:=CAdd(Z0,Z); // C_NEW = Z'+Z_NEW SetResult(cr,ci, Z0); // store C_NEW to [cr] and [ci] variables SetResult(x,y, Z); // store Z_NEW to [x] and [y] variables End; Others, more difficult, examples can be found in the FE.ZIP archive. It placed in the "Formulas" folder.

 


[ Home ]   [ License ]   [ What's new ? ]  
[ Downloads ]   [ FLL manual ]   [ Source codes ]  
[ Fractal gallery ]   [ Awards ]   [ Links ]   [ Caricatures ]  

Copyright © 1999-2001
Sirotinsky A.A. and Fedorenko O.V.
Kiev, Ukraine.
Last update: May 15, 2001