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: 83,251

Do you understand what a pure function is?

**In mathematics, you don't understand things. You just get used to them.I have the result, but I do not yet know how to get it.All physicists, and a good many quite respectable mathematicians are contemptuous about proof.**

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'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 83,251

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.I have the result, but I do not yet know how to get it.All physicists, and a good many quite respectable mathematicians are contemptuous about proof.**

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'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 83,251

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.I have the result, but I do not yet know how to get it.All physicists, and a good many quite respectable mathematicians are contemptuous about proof.**

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'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 83,251

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.

I have the result, but I do not yet know how to get it.

All physicists, and a good many quite respectable mathematicians are contemptuous about proof.

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'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 83,251

```
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?

I have the result, but I do not yet know how to get it.

All physicists, and a good many quite respectable mathematicians are contemptuous about proof.

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'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 83,251

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.

I have the result, but I do not yet know how to get it.

All physicists, and a good many quite respectable mathematicians are contemptuous about proof.

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'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 83,251

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

I have the result, but I do not yet know how to get it.

All physicists, and a good many quite respectable mathematicians are contemptuous about proof.

Offline

What is this?

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

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

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 83,251

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

I have the result, but I do not yet know how to get it.

All physicists, and a good many quite respectable mathematicians are contemptuous about proof.

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'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 83,251

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.

I have the result, but I do not yet know how to get it.

All physicists, and a good many quite respectable mathematicians are contemptuous about proof.

Offline

WHy did you use it in that code?

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

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 83,251

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

I have the result, but I do not yet know how to get it.

All physicists, and a good many quite respectable mathematicians are contemptuous about proof.

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'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 83,251

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.

I have the result, but I do not yet know how to get it.

All physicists, and a good many quite respectable mathematicians are contemptuous about proof.

Offline

I was just asking.

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

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 83,251

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

I have the result, but I do not yet know how to get it.

All physicists, and a good many quite respectable mathematicians are contemptuous about proof.

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'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 83,251

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

I have the result, but I do not yet know how to get it.

All physicists, and a good many quite respectable mathematicians are contemptuous about proof.

Offline