Comment #2 on issue 3311 by [email protected]: SymPy is lacking a
expressiontree facility / creator
http://code.google.com/p/sympy/issues/detail?id=3311
Matlab with Symbolic Math Toolbox can use and execute text M-files, that
can also be variables and created runtime by Matlab code.
To create an expression tree including a subset of all functionlike
expression items (==fnq) one needs following variables:
isfnqincluded = [0,0,0,1,0,1,1,1,1,0,0]; % where 0 is not included and 1 is
included
Then isfnqincluded(nfnq) tells if fnq number nfnq is included in the
expression item handling or not. Items can be like:
Itemname Itemnumber Item value arguments arg.types
Constant 1 (value of the constant) 0 []
Variable 2 "variable name" 1 [(argtype)]
fn1 3 "function name" n
[t1,t2,t3,...,tn]
...
sin 10 "sin" 1 [(int,rat,real or
complex)]
atan2 11 "atan2" 2 [2x(int,rat,real or
complex)]
...
Diff 50 "differentiation" 4
[ta,tb,expr,diffvar]
Integrate 51 "integration" 4
[ta,tb,expr,intgvar]
...
etc. for all fnq:s
Allexpressionscanners scan through all combinations of expression items to
create on valid expression at a time. Easiest way is probably from bottom
to top.
First looping (Loop 1....Loop P+1) gives every expression item an unique
number (loop counter value common to all following loops Ifnq):
Loop 1:
Pick 0 argument expression items:
Ifnq=1
Itemnumbers: 1, type 1st
Ifnq+=1 % This is C, replace same for MATLAB Ifnq=Ifnq+1
Itemnumbers: 1, type 2nd
Ifnq+=1
Itemnumbers: 1, type 3rd
Ifnq+=1
Itemnumbers: 1, type 4th
Ifnq+=1
Itemnumbers: 1, type 5th
Ifnq+=1
...(rest with 0 arguments)
% Above loop results as an input of fnq:s with 0 arguments, certain types.
% At any expression later on these can be replaced to an argument place
% needed to be of that certain type.
Loop 2
Pick 1 argument expression items:
Ifnq+=1
Itemnumbers: 2, type 1st
Ifnq+=1
Itemnumbers: 2, type 2nd
Ifnq+=1
Itemnumbers: 2, type 3rd
Ifnq+=1
Itemnumbers: 2, type 4th
Ifnq+=1
Itemnumbers: 2, type 5th
Ifnq+=1
...
Ifnq+=1
Itemnumbers: 10, type 1st
Ifnq+=1
Itemnumbers: 10, type 2nd
Ifnq+=1
Itemnumbers: 10, type 3rd
Ifnq+=1
Itemnumbers: 10, type 4th
Ifnq+=1
Itemnumbers: 10, type 5th
Ifnq+=1
...(rest with 1 arguments)
% Above loop results as an input of fnq:s with 1 arguments, certain types.
% At any expression later on these can be replaced to an argument place
% needed to be of that certain type.
Loop 3
Pick 2 argument expression items:
Ifnq+=1
Itemnumbers: 11, type 1st
Ifnq+=1
Itemnumbers: 11, type 2nd
Ifnq+=1
Itemnumbers: 11, type 3rd
Ifnq+=1
Itemnumbers: 11, type 4th
Ifnq+=1
Itemnumbers: 11, type 5th
Ifnq+=1
...(rest with 2 arguments)
% Above loop results as an input of fnq:s with 2 arguments, certain types.
% At any expression later on these can be replaced to an argument place
% needed to be of that certain type.
Loop 4
Pick 3 argument expression items:
Ifnq+=1
Itemnumbers:...(rest with 3 arguments, certain types)
% Above loop results as an input of fnq:s with 3 arguments, certain types.
% At any expression later on these can be replaced to an argument place
% needed to be of that certain type.
...
Loop K
Pick K-1 argument expression items:
Ifnq+=1
Itemnumbers:...(rest with K-1 arguments, certain types)
% Above loop results as an input of fnq:s with K-1 arguments, certain types.
% At any expression later on these can be replaced to an argument place
% needed to be of that certain type.
If there are no expression items having more than P items, then P+1:th Loop
is the last in this list. The idea is to have a counter that gives every
loop result an unique number to identify it later on.
Next looping level starts to create "all expressions" list.
This may be easier from Top to bottom:
Starting at Expression outermost fnq, say start level is Ilevel=Ifnqtop.
% Ilevel handling is this:
Pick each Ifnq-list item having level Ilevel
For each of these items replace all arguments by Ilevel-1 loop handling
results.
When Ilevel reaches 0 replace rest argument places with 0 argument
expression...
Items
% This way all Ifnq:s will be used and all arguments will have all Ifnq:s
down to
% Ilevel 0 where rest of the argument places are replaced by constants.
% This algorithm also includes all types of arguments in all argument
places.
% Final scan could drop away all those alternatives that are not valid, or
previous
% algorithm could simply include type checking and drop away alternatives
that are
% not valid.
% In MATLAB it is then easy to replace Ifnq:s numbers with actual
expression,
% differentiate this (using Symbolic Math Toolbox) and again replace the
% expression items
% (function names etc) with Ifnq values with all types or certain types.
% Linear combinations and transformation rules can also be applied using the
% Symbolic Math Toolbox which gives alternate forms to same
differentiations.
% Reading differentiation results other way round will give an Integral
Table
% of all available expressions. Of course one then needs an
% Expression to Ifnq-expression converter which just a replace loop.
% If one handles MATLAB/Programming Language code also as fnq:s one can
% this way create
% "all available algorithms"-trees, which may be of more use in quantum
computers.
% Also some codetree optimization issues as well as
% "finding all algorithms suitable to a task" up to a certain complexity
% can be handled.
%
% One could also utilise this to handle "Mathematics world to Digital World
% relations" possibilities.
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.