Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,725 Location: Italy Was thanked: 1393 time(s) in 909 post(s)
|
Originally Posted by: omorr Maybe foreach(2) if it is not too long unfortunately this is a popular statement too, like do/while... Originally Posted by: mkraska I see two different issues:
1. mapping functions or expressions to structures by element vec(expr) - identify the variables in expression (without preprocessing - get variable values (structures) from context - iterate over the elements replacing the element values for the structure variable names in expr and building a result of the same structure as the variables. This would require the variables in expression to be either of the same structure or scalars. You might relax that condition to variables being of identical length, if linear adressing is unique and well defined. Then you would return a vector of corresponding length. I think, the right over-arrow just like in Mathcad would be appropriate, even if I'd rather like arrows, overbars or the like to be available as decorations for variable names. This is essentally what your function do() does already, except that perhaps the function could find out by itself, which variable to iterate over.
2. Implicit loops to generate matrix or vector results. Input is the index equation or it's parts (result name, expression, index names). I failed to provide a working example, the definitions might illustrate, what I mean.
apply(res,expr,i1,i2):line(expr1:at(expr,sys(i1≡ii1,i2≡ii2,2,1)),for(ii1,i1,for(ii2,i2,el(res,ii1,ii2):expr1)),res,3,1)
apply(res,expr,i1,i2):line(ii1:i1,ii2:i2,for(i1,ii1,for(i2,ii2,el(res,i1,i2):expr)),res,4,1)
The input
el(M,i,j):i+j
would be translated to
apply(M,i+j,i,j)
But that would require your function decorating to cover both sides of an assignment.
The names in my examples are arbitrary, I would stick, however to something like vectorize(), vector() or vec(), as this would be consistent with Mathcad speech and with the decoration symbol. The function was thinked to handle functions with scalar single unknown; I think could be extendeded to other cases using (implicitly) at(2) when there are more than a single unknown, limiting the evaluation at the first nesting level (or maybe not, looking from the deepest level and going up, but this is another step...). As for the "dress" I don't like a LHS+RHS approach, because in this case it would seem an assignment instead of a function (and if you place a function on the canvas without an evaluation, nothing happens); as first approach I've thinked to a modified version of at(2) or el(2), with some bracket [#] <#> or symbol @# near the subscript (BTW apply is not a bad idea...). Edited by user 09 May 2014 01:13:11(UTC)
| Reason: Not specified |
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects |