Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Procedural form?

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,355

Loops and such.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

There is no other way.At least not that I know of.But Maxima allows while loops.

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,355

While loops are procedural. Why are you not using math commands to do math?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

What would you to sum those terms then?

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,355

Sum[x^k,k,1,6] yields

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

```
CombGF(list) := block([i, a, m, s],
i = 1,
m = 1,
while i <= length(list) do
[
a = get(list,i),
s=sum(x^k/k!,k,1,i),
m = m * s,
delete(a,list,1),
i = i + 1
],
print(m)
);
```

*Last edited by anonimnystefy (2012-04-30 02:11:39)*

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,355

You do not need the while loop and you are jumping ahead. Let's get the OGF's down first.

To have the probability gf for 2 die:

Sum[x^k/6,k,1,6]^2 yields

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

I want the function to do everything for me.I just have to input 6,6 instead of just 6 to get probability for 2 dice.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,355

I want the function to do everything for me.I just have to input 6,6 instead of just 6 to get probability for 2 dice.

That is overkill. You make functions that do the minimum and use other commands on them. You do not try to make functions to do everything.

You make a function that inputs the parameters you need and then you use the series inside the function.

Here is pseudocode:

gf(a,b,d)

Begin:

Sum[x^k/d,k,a,b]

End:

Now when you call gf(1,6,6) you get:

Congratulations you just threw a die!

To throw 2 you just go

gf(1,6,6)^2

Simple, no need to make a function throw n die when you just have to square or cube or raise to the 10th power...

I want you to work on creating a function gf that inputs the 3 parameters as I have indicated.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

This code both compiles and runs,but doesn't give a good output:

```
CombGF(list) := block([i, a, m, s],
i : 1,
m : 1,
while i <= length(list) do
[
a : first(list),
print(a),
s : sum(x^k, k, 0, a),
m : m * s,
list:rest(list),
i : i + 1
],
print(m)
);
```

and the output for:

list:[1,1,2,3];

CombGF(list);

is:

[1,1,2,3]

1

1

(x+1)^2

*Last edited by anonimnystefy (2012-04-30 03:51:46)*

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Done it! Could you do a little test on the code:

Exp GF:

```
CombEGF(list) := block([i, a, m, s],
i : 1,
m : 1,
l : length(list),
while i <= l do
[
a : first(list),
s : sum(x^k/k!, k, 0, a),
m : m * s,
list : rest(list),
i : i + 1
],
m
);
©anonimnystefy 2012
```

Ordinary GF:

```
CombOGF(list) := block([i, a, m, s],
i : 1,
m : 1,
l : length(list),
while i <= l do
[
a : first(list),
s : sum(x^k, k, 0, a),
m : m * s,
list : rest(list),
i : i + 1
],
m
);
©anonimnystefy 2012
```

The coefficient of OGF:

```
OGFcoeff(list,n) := ratcoeff(CombOGF(list),x^n);
©anonimnystefy 2012
```

The coefficient of EGF:

```
EGFcoeff(list,n) := ratcoeff(CombEGF(list),x^n)*n!;
©anonimnystefy 2012
```

Notice that I multiply by n! in the EGFcoeff function to get the final result immediately.

*Last edited by anonimnystefy (2012-04-30 04:50:58)*

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,355

Hi;

Please look at my hidden text message in post 110.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

I did even more than that.The function CombOGF can create those generating functions.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,355

You missed alot of what I am trying to say by sticking to the procedural

approach. It is not uncommon for people being introduced into new

fields to try to keep what they already know.

While this is usually a good idea in the case of programming it can

be disastrous. I wanted you to tear down your Pascal or Basic famework

and learn another one.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

But this solution works.It is applicable in many situations.

*Last edited by anonimnystefy (2012-04-30 05:42:59)*

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,355

I understand that it is tough to do what I ask. Of the two people I taught neither could accomplish it. Perhaps you remember this:

Yibka: Once you start down the path of procedural programming forever will it

dominate your destiny, consume you it will as it did Bit One's apprentice.

Lukky: Is the procedural paradigm stronger?

Yibka: No, no no! Easier! More seductive...

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

I do not remember that.Where is that from?

But,I am willing to try if you have the patience.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,355

I do not remember that.Where is that from?

I think we have been lied to on every level by our masters. I was assured many times that that was standard knowledge.

But,I am willing to try if you have the patience.

I have the patience but do have I have the lifespan of several millenia?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Well you have already live hundreds of millenia,so that won't be the problem.Let's get started if you want.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,355

Show me a full output of your best and most complicated example using your function.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Hi bobbym

Inout:

```
list : [1,2,3,4,5,6,7,8,9,10,11,12,13];
CombOGF(list);
```

Output;

```
[1,2,3,4,5,6,7,8,9,10,11,12,13]
(%o74) (x+1)*(x^2+x+1)*(x^3+x^2+x+1)*(x^4+x^3+x^2+x+1)*(x^5+x^4+x^3+x^2+x+1)*(x^6+x^5+x^4+x^3+x^2+x+1)*
(x^7+x^6+x^5+x^4+x^3+x^2+x+1)*(x^8+x^7+x^6+x^5+x^4+x^3+x^2+x+1)*(x^9+x^8+x^7+x^6+x^5+x^4+x^3+x^2+x+1)*
(x^10+x^9+x^8+x^7+x^6+x^5+x^4+x^3+x^2+x+1)*(x^11+x^10+x^9+x^8+x^7+x^6+x^5+x^4+x^3+x^2+x+1)*
(x^12+x^11+x^10+x^9+x^8+x^7+x^6+x^5+x^4+x^3+x^2+x+1)*
(x^13+x^12+x^11+x^10+x^9+x^8+x^7+x^6+x^5+x^4+x^3+x^2+x+1)
```

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,355

Okay, how do you throw a die 4 times and get the probability of having the

sum of them equal 20?

Taking a break, be back in a while.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Hi bobbym

35/1296?

Okay,see you later!

*Last edited by anonimnystefy (2012-04-30 06:51:12)*

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,355

That is correct! Okay, then use yours.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline