Functional Stream computer. Macro definitions of the user functions
The project of a universal computer with the main construction of language – superposition of the functions (expression) in parallel processing (functions and their arguments) flows of elements of a hierarchical structure, including expressions comes to the end begun with Sections 1-6 (see links). The Functional Stream Mashmna (FSM), unlike present computers, completely rejects von-Neumann's concepts with orientation to consecutive calculations. Here collective of a micro computer over total memory (a computer in the future!) dynamically (during calculations) creates structure of interrelations on layered also dynamically changeable design of expressions. Macrogeneration of own functions created by the user instead of normal reorganization of their macro definitions comes down to reorganization of structure of collective of a micro computer (Structures Aktivatsy in determination of the author) and their interrelations. Macro definitions of a number of common functions in calculus mathematics, including with parallel computings are brought (complete review to 15.08-2013 g)
Content
|
Links to all sections of the project:
1. Functional Stream Mashina with parallel computings. Introduction (http://tadviser.ru/a/121275)
2. Uniform data structure and programs (http://tadviser.ru/a/149691)
3. Functioning of FPM. Expressions of language of programming
(http://tadviser.ru/a/149691)
4. Flows and their processing in structure of expression
(http://tadviser.ru/a/150588)
5. Micro programming of functions
(http://tadviser.ru/a/153069)
6. The program as the managed flow of expressions
(http://tadviser.ru/a/153069)
7. Macro definitions of the user functions (http://tadviser.ru/a/157631)
As well as earlier, at the formal description of lexemes Backus Nowra metasymbolics is used here. In addition [] it is bracketed
part of the description which can be lowered (to exclude). { } any number of times (including 0) the repeated part of the description is bracketed.
Under a part of a lexeme – the structure member in brackets %% specifies its Properties according to item 2.3
7. Macro definitions of the user functions
The user enters determinations of own functions in the form of subspaces (item 3.1) of the following type:
<Имя функции>:(<макроопределение функции> %.|1% <аргумент по умолчанию>{,} (7-1) ) or for lack of arguments it is by default simpler: <Имя функции>:<макроопределение функции> <макроопределение функции>::= <выражение> <аргумент по умолчанию>::= <выражение>
Thus, macro definition is normal structure in determination of item 2.1 with access to it by name, as well as to value of any subspace (variable). According to item 3.6 in any calculated (calls can be present function of $Eval, ruble 6) expression the function determined by the user:
<Имя функции [подпространства(7-1)]><аргумент><аргумент>({,}) (7-2) <аргумент>::= <выражение>
Distinctive feature of macro definition of the function entered by the user from other expressions is an opportunity repeated uses as any (except a root!) nodes of its structure of primitives (parameters) of the setup _A, _B, …, _Z - actually links to the arguments corresponding one after another in (7-2). The function (a) of $Eval executing any expression substitutes calls (7-2) them the macro definitions searched on names of functions - to names of subspaces according to item 2.6. In the found function macro definition parameters (primitives) of the _A setup -_Z in expression – macro definition of function are substituted for the corresponding arguments expressions from her call (7-2). For lack of such argument the argument similar one after another by default is selected from a call (7-2)
from (7-1) for lack of which the value of a required argument is accepted equal # with %#% property (indefinite, item 2.3).
It is necessary to pay attention to the next moments:
1) As well as in case of the built-in macro definitions (item 3.5, item 4.1.2.2, item 4.3.2.1) physically described substitution in expressions of its function call
and links of _A -_Z in macro definition by the arguments of NE specified by it is made by macro definition! - Implicitly this substitution
occurs directly at the development of expression of macro definition in the Structure Aktivatsy (SA) implemented by collective of a micro computer
(microprocessors) where at development of SA _A specified by links - expression _Z – arguments are developed in corresponding
branches (subtrees) of SA.
Exceptions:
a) In macro definition of the link _A -_Z NOT work as generator arguments * with Lit and are perceived as normal atoms
b) The parameters specified by links <идентификатор>(_) directly are substituted instead of links in macro definitions
2) The _a parameters - _z return unary R-values of arguments of a call (7-2) or (7-1) by default. _Args primitive
returns R-value of a layer of arguments from (7-2). These primitives are usually used for the analysis of correctness of arguments of user
functions
3) As well as at normal access to a subspace on his name index (item 2.6) search of macro definition of user function in her name
(a subspace name index) from a call (7-2) it is made at first in space(s) of $Eval (item 2.6), performing expression with a call
(7-2) functions and processing its macro definition. And in the same way for lack of there this function (macro definition) it is looked for in
space (b) of $Eval, higher on a hierarchy level in SA over $Eval (a) and performing expression with $Eval (a), etc. up levels
hierarchies of a tree of SA
4) The 'transparent' arguments of $NoOut, _Out (item 4.1), _Sum (item 4.2), _Tout, _If and _Scale specified in a call (7-2) (item 4.2, item 4.3) are invisible
links of _A -_Z are also automatically inherited used) by root function of the expression described by macro definition at it
to development in SA.
5) Let's remind that the argument – a literal in (7-1) and (7-2) according to concepts of FPM (river 3) is the primitive (a micro computer in SA) generating
unary (the only element with property of % ~; %, NE flow) value
6) Root (and not only!) macro definitions $Eval (river 6), executing a flow of expressions and defining can be expression function –
own space with subspaces
7) Expression of macro definition in (7-1), as well as expressions are arguments in (7-1) and (7-2) can use the built-in macro definitions
(item 3.5, item 4.3.2.1, etc.)
8) Expression of macro definition in (7-1), as well as expressions are arguments in (7-1) and (7-2) may contain calls of macro definitions of others
the user functions, however in the sequence of such calls initial
macro definition (call) cannot repeat,
what is controlled by function of $Eval
The examples of macro definitions of some common fixed functions in different areas given further are designed to show
and possibilities of parallel computings, and as at the level of flows in the expressions of the user functions generated from macro definitions,
and at the level of their microprograms (river 5)
7.1. Calculations of factorials
Fact ([])<Количество[n]> <чет/нечет>– in absence<чет/нечет> generates a row
1!, 2!, 3!, 4!, …, n! (1, 3, 6, 24, …).
Sign<чет/нечет> (any even or odd whole!) passes on a function exit only, respectively, factorials even or odd
values of their arguments i=1.2, …. Anyway n is quantity of elements of an output flow of the Fact function.
By default arguments accept values, respectively, 1 and # (indefinite value).
Macro definition:
Fact:(*Row(From:1,All:_A,X:_B, _Par(All:{_If(%.9+~,%,`!%\.%->!`,_Go),`0->!`} X:{`All->$a`,_If(%.9+%,`All*2;++;->All`)} ), {_If(%%,_Go),`$a=$n`,_if(%=%,_Break), `$i`,_if(%.9~0%,`$i+1;*!;->!`),`X`, _if(%.92%,`$i+1`,_if(%.92%,_Go),_Skip) _if(%.9~2%,`$i+1`,_if(%.9~2%,_Go),_Skip) } ),1,# )
Comment:
Fact macro definition is based based on the generator * Row and as the All parameter (amount of the generated values of a row, item 4.1.2) here
the link _A to expression - an argument of the user Fact function is accepted. The second parameter X is absent in determination * Row and is entered
in addition that NE is forbidden according to item 3.4.1. The value of the second argument (couples/odd number) user is appropriated to this parameter
the Fact function (macro), or it is absent and is indefinite (#). According to item 3.4.1.2 the primitive of _Par will organize processing
these parameters arriving in the register '!' _Calc calculator:
The integer NOT equal 0 All value (link _A) without layer normally is accepted: atom is selected, otherwise All is accepted equal 0,
thereby excepting issue of results on a function exit. In a lyuy case the received All value remains in the register of $a the _Calc calculator.
In case of integer positive X (issue of factorials of even or odd values) the All value doubles and is added to it
(transaction ++) 1.
After processing of function parameters a number of transactions follows (in brackets {}) actually on Fact function accomplishment: In the beginning it is controlled
completion of transactions when the number of $n the values created at the exit reaches All ($a) required by original value and in this case
the transaction _Break causes completion of transactions. The formula of' $i' reads in the register'.' number of cycles of transactions and if it is other than 0,
that previous value of result'!' multiplies by ($i+1), calculating next values of a factorial (%i+1)! and placing it in the register
' !'.
If parameter X is not even or odd whole, then the calculated value of the register '!' goes to an exit. Otherwise if parity of X and
($i+1) NE match, the result received by the transaction _Skip is passed: it is not issued on an exit and $n NE increases by 1.
Examples:
Fact (6.2) generates a number sequence 2!, 4!, 6!, 8!, 10!, 12! Fact (6.1) generates a number sequence 1!, 3!, 5!, 7!, 9!, 11! Fact(6) generates a number sequence 1!, 2!, 3!, 4!, 5!, 6! Fact (6, ABC) generates a number sequence 1!, 2!, 3!, 4!, 5!, 6!
7.2. Calculations of degrees
Degree (<основание[ степени]><к-во[n]>[] <чет/нечет>[0]) – in absence<чет/нечет> and further 0 (the 4th argument) generates a number of the basis in the sequence of degrees:
1, 2, 3, 4, …, n.
Sign<чет/нечет> (any even or odd whole!) passes on a function exit only, respectively, degree with even or odd
values of their indicators n=1.2, …. In case of 0 - value of the 4th argument generation begins with 0th degree. Anyway n is quantity
elements of an output flow of the Degree function. By default arguments accept values, respectively, 1,1,# (indefinite value) and 1.
Degree:(*Row(From:1,Base:_A,All:_B,X:_C,Y:_D, _Par(All:{_If(%.9+~,%,`!%\.%->!`,_Go),`0->!`} Base:{_If((%.9~,%,%./~,%),`!%\./%->!`,_Go),_Break} X:{`All->$a`,_If(%.~9+%,_Go),`All*2;++;->All`}, Y:{_If(%.90~,%,_Go),`1->!`} ), {`$n=$a`,_if(%=%,_Break), `Y`,_if(%9~0%,`Base*!;->!`), `X`, _if(%.92%,`$i+Y`,_if(%.92%,_Go),_Skip) _if(%.9~2%,`$i+Y`,_if(%.9~2%,_Go),_Skip) } ),1,1,#,1 ) Example of generation of a flow of degrees with the basis 2: Degree(2,5) - 2, 4, 8, 16, 32 Degree(2,5,1) - 2, 8, 32, 128, 512 (odd degrees) Degree(2,5,2,0) - 1, 4, 16, 64, 256 (even degrees, since 0)
7.3. Calculations of the known functions by means of power series
Below decomposition of function in the ranks given in [1] are used.
7.3.1. Calculation of Exp (X) - exhibitors
Exp (<переменная>) – Function evaluation of exp (x) with a margin error of NE is worse than 0.0001 [1]
Macro definition:
Exp:$Sync(Degree(_A, 20),Fact(20),Sum:0.0,Err:0.0001, {_If(%%,`$S%!%->!,!++`,_Go), -1 XLIFFService: Error in XliffFile2XliffString method. } )
Comment:
1) Root function of $Sync macro definition synchronously processes generated by the user Degree functions (item 7.2) and
Fact (item 7.1), respectively, ranks of degrees 1, 2, etc. variable (link _A) and factorials 1!, 2! …. The standard Sum parameter sets
original value of the register of $S (Adder). The additional Err parameter is an error of calculations.
2) The operation _If on end of trains - flows from Degree and Fact (lack of properties at the register'!') places result of calculations
from $S in the register '!', supplementing its properties with property of %! % and increasing value of the last by 1 (transaction ++).
3) Otherwise a/b relation (an and b - nelementy of the next train from Degree and Fact) fills up the adder of $S and then is compared to Err. If a/b it is less or equally to Err, the transaction _End closes entrance flows from Degree and Fact, causing repeatedly transaction (2). Otherwise register'!' it is reset to not having properties and by that issue of its value on a function exit is blocked. The same action could be initiated transaction _Skip.
Examples: <br /> <br /> Exp(1) returns 2.71828 with rounding on last character. At this MPK processed 8 trains Exp(2) returns 7.38904 with rounding on last character. At this MPK processed 11 trains
7.3.2. Calculation of Sin (X) – a sine
Sin (<переменная>) – Function evaluation of sin (x) with a margin error is not worse than 0.0001 [1]
Macro definition:
Sin:$Sync(Degree(_A, 20,1),Fact(20,1),Sum:0.0,Err:0.0001, {_If(%%,`$S%!%->!`,_Go), `$n->!;a/b`,_If(%.92%,$S+=.),_If(%.9~2%,$S-=.), -1 XLIFFService: Error in XliffFile2XliffString method. } )
The main difference from macro definition of Exp (item 7.3.1) in generation of ranks (Degree) with odd degrees of n=1,3,5, … and odd 'n' with factorials
'n!'. In case of odd value of the register of $n (quantity of the accepted and already processed trains) from contents of register S it is subtracted
a/b relation (register‘.’). At last, the first transaction _If NOT increases contents of the register of $S by 1.
Note: Similarly without any problem it is possible to organize calculation of other trigonometric functions and also integral
sine and cosine.
7.4. Calculations of the known functions by means of chain fractions
The method [2] representations of function is used by the suitable fraction received from the corresponding chain fraction with the set number of cycles –
links. This method is more preferable the fact that the number of cycles of calculations (links of chain fraction) defines an error of calculations, poorly
depending on argument value of the calculated function. Therefore this method was used by microprograms of one of the first domestic
Computer of 'Promin'. And therefore the error as parameter, is absent in the subsequent macro definitions of functions.
7.4.1. Calculation of Exp (X) - exhibitors
The suitable fraction (expression) calculating Exp(X) from chain in 5 cycles has an appearance [2]:
(1680+840x+180x^2+20x^3+x^4) / (1680-840x+180x^2-20x^3+x^4),
where ^ - transaction of construction ‘x’ in degree.
Exp (<переменная>) – the Call of the user exp (x) function
Macro definition:
Exp:$Sync($Sync(Degree(_A,5,#,0,_Out(Dg:)), *Stream(1680, 840, 180,20,1,_Out(Str:{`$n`,_if(%.9~2%,`!%9~+%->!`)}) {_If(%%,`$S%!%->!`,_Go),`a*b;$S+=.;%%->!`} ), $Sync(Dg:Chanal,Str:Chanal,Sum:0.0, {_If(%%,`$S%!%->!`,_Go),`a*b;$S+=.;%%->!`} ), _If(%~%,`a/b;->!`) )
Comment:
1)! - I internal (argument) of $Sync by means of the arguments of Degree and * Stream create flows, respectively, degrees of X (the link _A
makoopredeleniye) from 0 to 4 and the coefficients from 1680 to 1 used as in numerator, and a denominator of suitable fraction. Therefore functions
Degree and * Stream are supplied with additional exits (_Out primitive), respectively, Dg and Str for transfer of the created flows of the second
internal (macro definition) function of $Sync on the channels (Chanal) of the same name. At the same time an exit of Str is supplied with transactions changing the sign '+'
on denying it (%9 ~+ %) the sign '-' at every second element of a flow (the requirement of a denominator of suitable fraction)
2) Transactions of both internal $Sync are identical: the elements 'a' and 'b' of the flows received synchronously peremenozhatsya (train) and the work
it is added to $S in an initial status equal 0.0 (Sum: 0.0). On the termination of flows of $S it is transported on an exit
3) External $Sync processes exits (2) of internal (arguments) $Sync - the only train, dividing an exit of 1st ('a') to an exit of second ('b'),
using for this purpose the only transaction _If (the 3rd argument)
Attention! The feature of the given macro definition is that calculation of numerator and a denominator of suitable fraction is executed in parallel
and main thing same means of Degree and * Stream.
Examples:
Exp(1) returns 2.718282 with rounding on last character. Exp(2) returns 7.3889 with rounding on last character.
7.4.2. Calculation of Tg (X) – a tangent
Here with not smaller than in item 7.4.1 accuracy achieves result by rather simple suitable fraction:
(945 *X – 105*X*3 + X^5) / (945 – 420*X^2 + 15*X^4)
Tg:$Sync($Sync(Degree(_A,3,1), *Stream(945, -105,1), {_If(%%,`$S%!%->!`,_Go),`a*b;$S+=.;%%->!`} ), $Sync(Degree(_A,3,2,0), *Stream(945,-420,15),_ {_If(%%,`$S%!%->!`,_Go),`a*b;$S+=.;%%->!`} ) _If(%~%,`a/b;->!`) )
Unlike the item 7.4.1 coefficients and degrees of polynoms in numerator and a denominator different: in numerator - odd (the 3rd argument - 1), and in
denominator even (the 3rd argument) degrees moreover, beginning with 0 (0 - the 4th argument). Therefore everyone internal has (argument) of $Sync
(inputs) own arguments * Degree and * Stream, are executed in parallel and independently of each other – asynchronously. Unlike item 7.4.1
there is no 'Sum: 0' as registers of $S are established in 0 by default of the standard Sum parameter (item 3.4.1.1)
7.5. Calculation of a tangent of values from a flow
Tgs (<поток значений [X1, X2,…]>) – returns a flow of values Tg(X1), Tg(X2), …
Macro definition:
Tgs:$Eval(Lit(Tg(!Data()),_A)
Comment:
1) the 1st function argument of $Eval (river 10) as a literal (an argument of Lit, item 3.2) defines unary (only) value – expression,
and the second argument – the link (_A) on initial (Tgs argument) a flow of the data processed by this expression
2) The Data function according to item 3.2 takes the next element of the flow specified by the link ‘_A’ and function! Form leads it to numerical atom.
3) The received numerical atom in (2) is transferred to the user Tg function (item 7.4.2) as an argument
4) The control of correctness of elements of an initial flow of $Tgs executed by function of $Eval can be insufficient. In this case it is necessary
in the given macro definition to exclude function! Form, having added $Eval function arguments with a transparent argument of a type:
b:{ }<операции по контролю потока значений [X1, X2,…]>
Attention! In the trains processed by $Eval only the value of the next element of a flow and therefore development in SA of expression – the first changes
argument of $Eval it is made only when processing the first train
Examples:
Tgs (*Stream(1,2,3) returns a flow of values Tg (1), Tg (2), Tg (3) Tgs (*Num (4.0.1, 1.1)) returns: Tg(1.1), Tg(1.2), Tg(1.3), Tg(1.4)
7.5. Generation and filling of cells of matrixes
The matrix can be considered as the hierarchical structure entered by item 2.1: a layer from lines (the first level), a line from columns (the 2nd level) and
etc. Therefore, the built-in functions and primitives entered by the previous sections are enough for generation and array processing. However
the macro definitions of the user functions entered here on creation and filling of matrixes are intended to perform these operations usual for
users at their use in calculations, and, with control of these transactions, for example matrix borders. It is at the same time shown
possibility of acceleration of these transactions by parallelization of their accomplishment.
7.5.1. Generation of matrixes
1) The one-dimensional matrix (vector) is created by the following function:
<К-во элементов><содержимое ячеек>Vector([,])
Macro definition:
Vector:$Async(*Row(All:_A,FROM:_B, _Par(All:{_If(%.9+~,%,`!%\.%->!`,_Go),`0->!`} ),Sum:(), <-!;$S+=.`,_Skip),`$S->Out:{_If(%~%,`!`} )
At the same time * Row generates a flow from identical All of structures (contents of cells), including indefinite value for lack of the second function parameter Vector. Function of $Async determines the standard Sum parameter (original value of $S) as an empty layer and therefore on the main thing Out exit the transaction '+=' the layer of $S is replenished with the copy (<-) очередного элемента с потокового входа функции $Async. По окончании this flow final $S (vector) returns to $Async exit
2) The two-dimensional array is created by the following function:
<К-во строк>Matrix2(, <К-во колонок[- ячеек в строке]> [,<содержимое ячеек>] ) Macro definition: <br /> Matrix2:(Vector(_A,Vector(_B,_C)),2,2,#)
It is possible to determine Matrix3 functions by analogy and. etc.
3) Let's consider the possibility of parallel creation and filling of parts of a big matrix with the M x N size. Let's break such matrix into two
M1 x N and M2 x N sizes so that M=M1+M2.
Expression
< M1 >< N >$Async(*Sel(Matrix2(,),Out:`!%@%->!`), < M2 >< N >*Sel(Matrix2(,),Out:`!%@%->!`), Sum:(), Out:{_If(%~%,`$S+=!`,_Skip),`$S->!`} )
by means of $Async (item 4.3.3) will organize asynchronous (parallel) filling of matrixes of M1 x N and M2 x N with indefinite # values
(by default). At the same time also in parallel from each of these matrixes at the top level of hierarchy Sel are selected with the generator * (transactions
reductions of the register'!' at Out exit) R-values (link UKA and UKS) of lines also come in random order to initially empty layer of $S
(Sum parameter).
It is easy to separate an initial matrix of M x N into bigger (than 2) quantity of the parts filled in parallel and, therefore, more effectively
as well as to construct function macro definition, all this performing.
Instead of the conclusion:
Excessive detailing of the project of a universal functional stream computer with parallel computings, perhaps, executed not by the best
in the way, it is dictated only by desire to prove real feasibility of concepts, incredibly simple and at the same time it is perfect
the offered von-Neumann differing from usual to us. And nadeyu that it worked well.
The used literature:
_1. E. Madelung. Mathematical apparatus of physics, reference guide. 'Science', 1968, p. 85-87 _2. E. Denisova, A. Kucher. Fundamentals of calculus mathematics. Sankt- IT St. Petersburg university, Mechanics and Optics, 2010, p. 24-25
The used reductions:
FPM -functional stream machine p. 5 -Section 5 of the FPM project item 2.3 -point 3 of Section 2 SA -Structure Aktivatsy – implementing expression of language (superposition functions) collective of appropriately connected micro computers, each of which implements separate function or a primitive (calculator) of _Calc DRP -dynamically distributed memory over which funkutsionirut micro EVM SA BP -the DRP block selected under atom or a layer of structure UKA -pointer (link to BP) of atom (item 2.3) UKS -pointer (link to BP) of a layer (river 2)