Version 1 of constructing a bwise graph from a formula

Updated 2004-10-25 14:33:43 by TV

by TV, of course feel free to add/comment/correct(?!) as is normal on the wiki

Starting from the ideas from constructing mathematical formulas with Bwise blocks we will look at the reverse of that idea here: to make a bwise canvas with blocks representing a certain repeated function call formula automatically.

As an example to make clear what I mean, lets consider the formula (and its arguments, the variables s and c):

 set s 2
 set c 8
 puts [expr $s / ( (2.0 * ($c) ) + $s ) ]

In this case the outcome of the expression formula is:

     0.111111111111

of course we could change either or both of the variables, and get a different outcome. Clearly the expr can be written a bit shorter when taking into consideration normal precedence rules, for instance as: $s/(2.0*$c+$s), not changing the outcome when we used the expr rules right, and when we assume accuracy of intermedeate computations aren't influenced by our formula rewriting.

For clarity as to how the outcome of this, rather random, it has no special meaning for me, formula is formed, we can prettypring the parts making up the formula, like one would in regular C language formatting conventions for instance:

 proc ourformula {s c} {
    return [expr        \
                        \
    $s                  \
    /                   \
    (                   \
       (                \
          2.0           \
  • \
          (             \
             $c         \
          )             \
       )                \
       +                \
       (                \
          $s            \
       )                \
    )                   \

    ]
 }

immedeately forging it into a procedure, which has the nature of what would classically be called a function: an outcome based on a functional description based on arguments. Simplified by reducing syntactically superfluous braces:

proc ourformula {s c} {

  return [expr          \
                        \
    $s / (              \
       2.0 * $c         \
       + $s             \
    )                   \

  ]
 }

Alternatively, we could us Maxima to render the formula in a human readable (though not typesetted) form:

 f(s,c):= s / ( (2 * (c) ) + s ) ;

                                            s
                                   f(s, C) := -------
                                         2 C + s

so that we easily know what formula we're talking about, maybe in shortest form: $s/(2.0*$c+$s) for expr. Without embellishment(the block placementis rather random), the formula can be rendered as a graph of connected function blocks, where c equals constant and s is slider:

http://82.168.209.239/Wiki/exaformula1.jpg

as can be seen on the abovementioned page.

For Tcl without complicated Expr, the rendering on that page as nested function calls is mathematically quite sound , such as in functional analysis:

 divide $s  [add [double $c  ]  $s  ]  

where divide is a function (called procedure in tcl) which returns its first argument divided by its second, add returns the numerical sum of its two arguments and double obviously returns the numerical double of its single argument. It is quite poaaiblw, but not an excercise I'll do here, to convert any expression into such nested function call equivalent. For the moment I'll convert the last formula representation, which is easily readable for humans and computers, with some practice, to a nested list representation first, because I'll use tcl list processing to tackle it's structure as the first attempt to automatically make a block structure which corresponds to it, preferably in a invertable sense.