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

You are not logged in.

- Topics: Active | Unanswered

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

Do you understand what a pure function is?

**In mathematics, you don't understand things. You just get used to them.Of course that result can be rigorously obtained, but who cares?Combinatorics is Algebra and Algebra is Combinatorics.**

Offline

Do LISP programmers call it a lambda function? It is an anonymous function

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

Yes, that is exactly correct. It is borrowed from the Lambda Calculus.

M uses a slot # and a & to make one.

**In mathematics, you don't understand things. You just get used to them.Of course that result can be rigorously obtained, but who cares?Combinatorics is Algebra and Algebra is Combinatorics.**

Offline

Lambda Calculus?

I do not understand the # and & part, it looks very creepy. Please illustrate

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

It is used right here:

```
FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},
Integers, RandomSeed -> #]& /@ Range[20];
```

But there is one more thing before we get to it...

**In mathematics, you don't understand things. You just get used to them.Of course that result can be rigorously obtained, but who cares?Combinatorics is Algebra and Algebra is Combinatorics.**

Offline

yes?

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

M uses options to enhance the commands. They are put in like this

(Name of the option) -> value, usually at the end of the command.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

Yes, I have seen that. There are a lot of options in the commands that do Interactive things

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

```
FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},
Integers, RandomSeed -> #]& /@ Range[20];
```

FindInstance uses random methods to arrive at answers as well as all known math methods. Because it sometimes has to use random numbers it requires a seed. Do you know what a random seed?

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

I think it is a number which is used to intiatalise a PRNG

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

That is correct so instead of doing

FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},Integers, RandomSeed -> 1]

FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},Integers, RandomSeed -> 2]

FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},Integers, RandomSeed -> 3]

.

.

.

FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},Integers, RandomSeed -> 20]

to get 20 different seeds ( remember we want 20 different answers and hope that if he starts from different seeds he will get a different answer). We map the slot operator # to {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20} which does the above but without all the work of writing that.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

Why do you have to supply the seed manually?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

Because the seed could be anything, how can M know which one I want?

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

What is this?

ans = Union[Flatten[ans, 1]];

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

Flatten removes all dimensionality and returns a list. Union is the same as the mathematical set command.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

What would the output look like without that command?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

Quite confusing. Generally the Flatten command does this,

Flatten[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}]

{1, 2, 3, 4, 5, 6, 7, 8, 9}

notice all list brackets were destroyed and the matrix is flattened into a list.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

WHy did you use it in that code?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

I wanted to make sure the Union command and the Length command would work correctly.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

Can we do this instead?

```
square4[n_] :=
Block[{ans},
ans = FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},
Integers, RandomSeed -> #]& /@ Range[200,220];
ans = Union[Flatten[ans, 1]];
If[Length[ans] == 20, {a, b, c, d} /. ans]]
```

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

We sure could but is it anymore correct then what I have done? I mean, we are still gambling that 20 different seeds will coax FindInstance to get the 20 different answers we require.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

I was just asking.

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

It will run if that is what you mean and get the correct answer.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

Okay, May I ask you a question that you'll not enjoy answering?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,249

Hmmm, I am afraid to ask. What is the question?

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline