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

• To: mathgroup at smc.vnet.net
• Subject: [mg47006] Re: [mg47001] Re: doing things on a procedural way and doing them on a functional way
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Sat, 20 Mar 2004 03:50:20 -0500 (EST)
• References: <200403170729.CAA16380@smc.vnet.net> <c3bgd8\$7q2\$1@smc.vnet.net> <200403190635.BAA27086@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```You are right, you need to add:

DeleteCases[%, _?(Not[FreeQ[#, g[x__ /; Length[{x}] ³ 3]]] &), 1]

This is indeed done in the article later on, although I just noticed a
"bug": I have

Union[Flatten[ DeleteCases[%, _?(Not[FreeQ[#, g[x__ /; Length[{x}] ³
3]]] &), 1]]]

where Flatten and Union are quite unnecessary. (They somehow survived
form a previous version of the code in which they were needed).

Andrzej

On 19 Mar 2004, at 07:35, Bobby R. Treat wrote:

> There are a lot of really good ideas in the AlgebraicProgramming
> notebook. Thanks for sharing! However...
>
> I think you mean your answer to "Suppose g is a nonassociative
> noncommutative product..." to be a solution to the posted problem.
>
> ClearAll[f]; SetAttributes[f, {Flat, OneIdentity}]
> FixedPoint[Union[Flatten[ReplaceAllList[#1, f[a_, b_] -> g[a, b]]]] &
> ,
>    f[a, b, c, d]];
> Union[% /. f -> g]
> {g[a, g[b, g[c, d]]],
>   g[a, g[g[b, c], d]],
>   g[a, g[b, c, d]],
>   g[g[a, b], g[c, d]],
>   g[g[a, g[b, c]], d],
>   g[g[g[a, b], c], d],
>   g[g[a, b, c], d]}
>
> But this result includes g[a,b,c] and g[b,c,d] which are not binary
> products. Do you mean us to remove elements that include more than
> binary products?
>
> Bobby
>
> Andrzej Kozlowski <akoz at mimuw.edu.pl> wrote in message
> news:<c3bgd8\$7q2\$1 at smc.vnet.net>...
>> I guess a little self-advertisement is not a major offence on this
>> list, so I suggest looking at my article in the forthcoming
>> Mathematica
>> Journal. If you can't wait you or don't have a subscription you can
>>
>> <http://www.mimuw.edu.pl/~akoz/Mathematica/AlgebraicProgramming.nb>
>>
>> Andrzej Kozlowski
>>
>> On 17 Mar 2004, at 08:29, Pedrito wrote:
>>
>>> 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: RE: Re: doing things on a procedural way and doing them on a functional way
• Next by Date: Re: doing things on a procedural way and doing them on a functional way
• Previous by thread: Re: doing things on a procedural way and doing them on a functional way
• Next by thread: Re: doing things on a procedural way and doing them on a functional way