## Discuss Scratch

- savaka
- Scratcher

1000+ posts

### Power block

It's not simple. Scratch is supposed to be easy to use. Not everyone knows trigonometry. by this logic, we can remove “move (10) steps”

why not just usego to x: ((x position) + ([cos v] of ((direction)*(amt)))) y ((x position) + ([sin v] of ((direction)*(amt))))i mean jeez so simple

You could, but that would make less sense, and it's supposed to be easy to use. and while we are at it, the “wait” block is also unnecessary, as you can use the timer for it.

BTW, I remember reading somewhere that scratch's blocks are faster than a series of blocks doing the same, so (()^()) would be technically speaking faster than doing logarithms. I mean, is it that hard to add scratchteam?

- scratchisthebest
- Scratcher

1000+ posts

### Power block

Which is the entire point of our posts.

Someone suggested “hurr use 2 logarihms” which is laughably slow, hard to use, and doesn't even always work.

Also one with a repeat block, which also is very slow and takes forever to enter in.

My trig junk has the same problem, but following their logic, it should be used because we can make it with existing blocks.

Someone suggested “hurr use 2 logarihms” which is laughably slow, hard to use, and doesn't even always work.

Also one with a repeat block, which also is very slow and takes forever to enter in.

My trig junk has the same problem, but following their logic, it should be used because we can make it with existing blocks.

I am a Lava Expert

- mitchboy
- Scratcher

1000+ posts

### Power block

Why would you even need a (() ^ ()) block other than a calculator (in which you could just use the workarounds)?

Oh, and you could just check if (exponent) < (0) for negative powers to work.

Oh, and you could just check if (exponent) < (0) for negative powers to work.

*Last edited by mitchboy (Sept. 21, 2013 16:00:20)*

Capsicum annuum.

- firedrake969_test
- Scratcher

500+ posts

### Power block

Yea… Which is the entire point of our posts.

Someone suggested “hurr use 2 logarihms” which is laughably slow, hard to use, and doesn't even always work.

Also one with a repeat block, which also is very slow and takes forever to enter in.

My trig junk has the same problem, but following their logic, it should be used because we can make it with existing blocks.

Most people learn exponents before they learn logarithms. I know I did.

Support for adding.

Alt account of Firedrake969.

Rocket II: A black and white bitmap space game!

I seek not fame, but education.

;

- Poemon1_REMIX
- New to Scratch

100+ posts

### Power block

when GF clickedTry that.

set [x v] to [0]

set [y v] to [0]

repeat (y)

set [x v] to ((x) * (y))

end

I invented stuffed pizza rolls! Insert turkey into the pizza rolls, and enjoy!

- Poemon1_REMIX
- New to Scratch

100+ posts

### Power block

Didn't work, but my new project does!when GF clickedTry that.

set [x v] to [0]

set [y v] to [0]

repeat (y)

set [x v] to ((x) * (y))

end

Scratch cat knows exponents

I invented stuffed pizza rolls! Insert turkey into the pizza rolls, and enjoy!

- savaka
- Scratcher

1000+ posts

### Power block

Here it only works if y is a natural number. A block could do anything.when GF clickedTry that.

set [x v] to [0]

set [y v] to [0]

repeat (y)

set [x v] to ((x) * (y))

end

*Last edited by savaka (Sept. 21, 2013 18:55:22)*

- mitchboy
- Scratcher

1000+ posts

### Power block

If (y)<(0) thenHere it only works if y is a natural number. A block could do anything.when GF clickedTry that.

set [x v] to [0]

set [y v] to [0]

repeat (y)

set [x v] to ((x) * (y))

end

repeat (y)

set [x v] to ((x) * (y))

_

set [x v] to ((1) / (x))

Boom. It now works for negatives. And you can use (mod (1)) then the log method for non-integers.

*Last edited by mitchboy (Sept. 22, 2013 19:57:26)*

Capsicum annuum.

- savaka
- Scratcher

1000+ posts

### Power block

I understand all these work, but wouldn't a block be way easier for new Scratchers? I have no idea what logarithms are.

- Poemon1_REMIX
- New to Scratch

100+ posts

### Power block

A logarithm is like a reverse power. For example, I understand all these work, but wouldn't a block be way easier for new Scratchers? I have no idea what logarithms are.

How many 5's are in 15?just switch around power and answer.

5 ^ 3 = 15,

LOG(5)15 = 3.

Here's the format:

LOGS:

LOG(base)answer = power

POWERS:

base ^ power = answer.

I invented stuffed pizza rolls! Insert turkey into the pizza rolls, and enjoy!

- savaka
- Scratcher

1000+ posts

### Power block

Log seems to take 2 parameters. Scratch's advanced math block only takes 1!A logarithm is like a reverse power. For example, I understand all these work, but wouldn't a block be way easier for new Scratchers? I have no idea what logarithms are.How many 5's are in 15?just switch around power and answer.

5 ^ 3 = 15,

LOG(5)15 = 3.

Here's the format:

LOGS:

LOG(base)answer = power

POWERS:

base ^ power = answer.

- DadOfMrLog
- Scratcher

1000+ posts

### Power block

Log seems to take 2 parameters. Scratch's advanced math block only takes 1!Logarithm of a number (say a) for a particular base (say b) is usually written as logb a - where the small b is the closest I could write to a subscript using BBCode.

But there are certain bases for which the notation is normally simplified. One of these is base 10, in which case the subscript b is usually dropped (unless there's a reason to show it explicitly, to avoid confusion, or to make it really clear what is meant). So the “log” in Scratch's drop-down means base 10 logarithm.

The other is the so called "natural logarithm", which is logarithm to base e (=2.718281828459045…)

In that case it is written as “ln” (lower case L and N). This is also in the Scratch maths drop-down.

You can think of “log” as being the ‘opposite’ of “10 to the power” - so that log(10^n)=n.

Similarly, you can think of “ln” as being the ‘opposite’ of "e to the power" - hence ln(e^n)=n.

That's why the two methods for x^y that I outlined earlier using those blocks are identical:

([10^ v] of ((y) * ([log v] of (x))) // = x^y

([e^ v] of ((y) * ([ln v] of (x))) // = x^y

Hope that make sense!

*Last edited by DadOfMrLog (Sept. 23, 2013 13:10:29)*

Alternate account: TheLogFather –– HowTos and useful custom blocks (see studio). Examples below…

- String manipulation - - - X to power of Y - - - Clone point to clone - Detect New Scratcher - Speed tests studio -

- Poemon1_REMIX
- New to Scratch

100+ posts

### Power block

Ya, I was going to get on to that next. Also, LOG(x) is equivalent to LOG(x)^y, right?Log seems to take 2 parameters. Scratch's advanced math block only takes 1!Logarithm of a number (say a) for a particular base (say b) is usually written as logb a - where the small b is the closest I could write to a subscript using BBCode.

But there are certain bases for which the notation is normally simplified. One of these is base 10, in which case the subscript b is usually dropped (unless there's a reason to show it explicitly, to avoid confusion, or to make it really clear what is meant). So the “log” in Scratch's drop-down means base 10 logarithm.

The other is the so called "natural logarithm", which is logarithm to base e (=2.718281828459045…)

In that case it is written as “ln” (lower case L and N). This is also in the Scratch maths drop-down.

You can think of “log” as being the ‘opposite’ of “10 to the power” - so that log(10^n)=n.

Similarly, you can think of “ln” as being the ‘opposite’ of "e to the power" - hence ln(e^n)=n.

That's why the two methods for x^y that I outlined earlier using those blocks are identical:([10^ v] of ((y) * ([log v] of (x))) // = x^y

([e^ v] of ((y) * ([ln v] of (x))) // = x^y

Hope that make sense!

I invented stuffed pizza rolls! Insert turkey into the pizza rolls, and enjoy!

- Poemon1_REMIX
- New to Scratch

100+ posts

### Power block

like 5^2 = 25, or 2^3 = 8. power what do you mean power?

(^ is power)

I invented stuffed pizza rolls! Insert turkey into the pizza rolls, and enjoy!

- savaka
- Scratcher

1000+ posts

### Power block

Oh, I get it. You use multiplication.Log seems to take 2 parameters. Scratch's advanced math block only takes 1!Logarithm of a number (say a) for a particular base (say b) is usually written as logb a - where the small b is the closest I could write to a subscript using BBCode.

But there are certain bases for which the notation is normally simplified. One of these is base 10, in which case the subscript b is usually dropped (unless there's a reason to show it explicitly, to avoid confusion, or to make it really clear what is meant). So the “log” in Scratch's drop-down means base 10 logarithm.

The other is the so called "natural logarithm", which is logarithm to base e (=2.718281828459045…)

In that case it is written as “ln” (lower case L and N). This is also in the Scratch maths drop-down.

You can think of “log” as being the ‘opposite’ of “10 to the power” - so that log(10^n)=n.

Similarly, you can think of “ln” as being the ‘opposite’ of "e to the power" - hence ln(e^n)=n.

That's why the two methods for x^y that I outlined earlier using those blocks are identical:([10^ v] of ((y) * ([log v] of (x))) // = x^y

([e^ v] of ((y) * ([ln v] of (x))) // = x^y

Hope that make sense!

- DadOfMrLog
- Scratcher

1000+ posts

### Power block

Yes, if you know about how things multiply (and divide) within logs, you'll know the following identities:Oh, I get it. You use multiplication. That's why the two methods for x^y that I outlined earlier using those blocks are identical:([10^ v] of ((y) * ([log v] of (x))) // = x^y

([e^ v] of ((y) * ([ln v] of (x))) // = x^y

Hope that make sense!

log(x*y) = log(x) + log(y)

log(x/y) = log(x) - log(y)

Above is true for any base logarithm, but let's just stick with base 10 to avoid having lots of subscripts.

Now, if you take that first one and do something like log(x^4) = log(x*x*x*x), you see it's just log(x)+log(x)+log(x)+log(x), i.e. 4*log(x).

It's not hard to see the generalisation of that: log(x^y) = y*log(x).

That one is particularly important for us here, because it contains the x^y that we want to calculate.

We know that 10^ and log are ‘opposites’, which means that log(10^n) = n.

…and also: 10^(log n) = n.

If you put n = x^y into that, and use the identity above, guess what you find…

Alternate account: TheLogFather –– HowTos and useful custom blocks (see studio). Examples below…

- String manipulation - - - X to power of Y - - - Clone point to clone - Detect New Scratcher - Speed tests studio -

- firedrake969_test
- Scratcher

500+ posts

### Power block

The thing is that you can't do negative numbers with logs.

Alt account of Firedrake969.

Rocket II: A black and white bitmap space game!

I seek not fame, but education.

;

- DadOfMrLog
- Scratcher

1000+ posts

### Power block

OK, so here's my definitive x^y custom block… The thing is that you can't do negative numbers with logs.

define result = (x) ^ (y)That should cover everything but non-integer powers of negative numbers (which gets a bit hairy…), and it makes sure that integer raised to integer gives exactly an integer (in case you assume you'll get an integer, perhaps because you check for equality with an integer at some point).

if <(y) = [0]> then

set [result v] to [1] // yes, we also include 0^0=1 :O

else

if <(x) = [0]> then

set [result v] to [0] // 0^y=0 for any y except zero (see above)

else

set [result v] to ([e^ v] of ((y)*([ln v] of ([abs v] of (x)))) // no negative x for now

if <(x) < [0]> then // now deal with power of negative number

if <(round(y)) = (y)> then // we can do integer powers of negative numbers

if <((y) mod (2)) = [1]> then

set [result v] to ((0) - (result)) // odd powers will be negative

end

else

set [result v] to [NaN] // but let's not go there at this stage...

end

end

if <<(y) > [0]> and <<(round(x)) = (x)> and <(round(y)) = (y)>>> then

set [result v] to (round (result)) // ensure we get exactly an integer if both x & y were ints

end

end

end

Hope I've got that all right!

*Last edited by DadOfMrLog (Sept. 23, 2013 23:03:00)*

Alternate account: TheLogFather –– HowTos and useful custom blocks (see studio). Examples below…

- String manipulation - - - X to power of Y - - - Clone point to clone - Detect New Scratcher - Speed tests studio -

- Poemon1_REMIX
- New to Scratch

100+ posts

### Power block

Ooh. Pretty big script! Let me rephrase that. really big script!OK, so here's my definitive x^y custom block… The thing is that you can't do negative numbers with logs.define result = (x) ^ (y)That should cover everything but non-integer powers of negative numbers (which gets a bit hairy…), and it makes sure that integer raised to integer gives exactly an integer (in case you assume you'll get an integer, perhaps because you check for equality with an integer at some point).

if <(y) = [0]> then

set [result v] to [1] // yes, we also include 0^0=1 :O

else

if <(x) = [0]> then

set [result v] to [0] // 0^y=0 for any y except zero (see above)

else

set [result v] to ([e^ v] of ((y)*([ln v] of ([abs v] of (x)))) // no negative x for now

if <(x) < [0]> then // now deal with power of negative number

if <(round(y)) = (y)> then // we can do integer powers of negative numbers

if <((y) mod (2)) = [1]> then

set [result v] to ((0) - (result)) // odd powers will be negative

end

else

set [result v] to [NaN] // but let's not go there at this stage...

end

end

if <<(y) > [0]> and <<(round(x)) = (x)> and <(round(y)) = (y)>>> then

set [result v] to (round (result)) // ensure we get exactly an integer if both x & y were ints

end

end

end

Hope I've got that all right!

I invented stuffed pizza rolls! Insert turkey into the pizza rolls, and enjoy!