MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

doing things on a procedural way and doing them on a functional way

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46952] doing things on a procedural way and doing them on a functional way
  • From: Pedrito <pedrito6 at softhome.net>
  • Date: Wed, 17 Mar 2004 02:29:06 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hello Mathgroup!


I wanted to figure how to obtain all the possible combinations of five
numbers and four non-conmutative non-asociative operations.

This means:
if we have numbers: a b c d e
and the non-conmutative non-asociative operation:  ?

it's possible to make the following (different) expressions:
a ? (b ? (c ? (d ? e)))
a ? (b ? (c ? d) ? e))
...
(a ? b) ? (c ? d) ? e


For practical reasons you can think that the operation ? is ^ (power).



I have already obtained (by hand) all the possible combinations:
     lst={{a, {b, {c, {d, e}}}}, {a, {b, {{c, d}, e}}}, {a, {{b, c}, {d,
e}}}, {a, {{b, {c, d}}, e}}, {a, {{{b, c}, d}, e}}, {{a, b}, {c, {d, e}}},
{{a, b}, {{c, d}, e}}, {{a, {b, c}}, {d, e}}, {{{a, b}, c}, {d, e}}, {{a,
{b, {c, d}}}, e}, {{a, {{b, c}, d}}, e}, {{{a, b}, {c, d}}, e}, {{{a, {b,
c}}, d}, e}, {{{{a, b}, c}, d}, e}}

    And then I transformed them into an expressions by:
Module[{x = 1}, 
      ToExpression[
        StringReplace[
          ToString[#1], {"{" -> "(", "}" -> ")", 
            "," :> {"^", "^", "^", "^"}\[LeftDoubleBracket]
                x++\[RightDoubleBracket]}]]] & /@ lst


If you can help me to do it better...


Pedro L.


  • Prev by Date: Re: Mathematica 5: Integration bug in quadratic found by the GEMM machine
  • Next by Date: Re: How to read a string from a file?
  • Previous by thread: Exporting data and comments
  • Next by thread: Re: doing things on a procedural way and doing them on a functional way