## Discuss Scratch

### Power block

scratchisthebest wrote:

by this logic, we can remove “move (10) steps”

why not just use
`go to x: ((x position) + ([cos v] of ((direction)*(amt)))) y ((x position) + ([sin v] of ((direction)*(amt))))`
i mean jeez so simple
It's not simple. Scratch is supposed to be easy to use. Not everyone knows trigonometry.

xlk wrote:

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?
You could, but that would make less sense, and it's supposed to be easy to use.

### 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.

I am a Lava Expert

### 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.

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

Capsicum annuum.

### Power block

scratchisthebest wrote:

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.
Yea…

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

Alt account of Firedrake969.

Rocket II: A black and white bitmap space game!

I seek not fame, but education.

;

### Power block

`when GF clickedset [x v] to set [y v] to repeat (y)set [x v] to ((x) * (y))end`
Try that.

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

Poemon1_REMIX wrote:

`when GF clickedset [x v] to set [y v] to repeat (y)set [x v] to ((x) * (y))end`
Try that.
Didn't work, but my new project does!

Scratch cat knows exponents

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

Poemon1_REMIX wrote:

`when GF clickedset [x v] to set [y v] to repeat (y)set [x v] to ((x) * (y))end`
Try that.
Here it only works if y is a natural number. A block could do anything.

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

### Power block

savaka wrote:

Poemon1_REMIX wrote:

`when GF clickedset [x v] to set [y v] to repeat (y)set [x v] to ((x) * (y))end`
Try that.
Here it only works if y is a natural number. A block could do anything.
If (y)<(0) then
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.

### 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.

### Power block

savaka wrote:

I understand all these work, but wouldn't a block be way easier for new Scratchers? I have no idea what logarithms are.
A logarithm is like a reverse power. For example,
How many 5's are in 15?
5 ^ 3 = 15,
LOG(5)15 = 3.

Here's the format:
LOGS:

POWERS:
just switch around power and answer.

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

Poemon1_REMIX wrote:

savaka wrote:

I understand all these work, but wouldn't a block be way easier for new Scratchers? I have no idea what logarithms are.
A logarithm is like a reverse power. For example,
How many 5's are in 15?
5 ^ 3 = 15,
LOG(5)15 = 3.

Here's the format:
LOGS:

POWERS:
just switch around power and answer.
Log seems to take 2 parameters. Scratch's advanced math block only takes 1!

### Power block

savaka wrote:

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)

### Power block

savaka wrote:

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!
Ya, I was going to get on to that next. Also, LOG(x) is equivalent to LOG(x)^y, right?

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

power what do you mean power? ### Power block

SuperNicky wrote:

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

(^ is power)

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

savaka wrote:

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!
Oh, I get it. You use multiplication.

### Power block

savaka wrote:

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!
Oh, I get it. You use multiplication.
Yes, if you know about how things multiply (and divide) within logs, you'll know the following identities:

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… ### 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.

;

### Power block

firedrake969_test wrote:

The thing is that you can't do negative numbers with logs.
OK, so here's my definitive x^y custom block…
`define result = (x) ^ (y)if <(y) = > then  set [result v] to  // yes, we also include 0^0=1  :Oelse  if <(x) = > then    set [result v] to   // 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) < > 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)) = > 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) > > 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  endend`
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).

Hope I've got that all right!

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

### Power block

firedrake969_test wrote:

The thing is that you can't do negative numbers with logs.
OK, so here's my definitive x^y custom block…
`define result = (x) ^ (y)if <(y) = > then  set [result v] to  // yes, we also include 0^0=1  :Oelse  if <(x) = > then    set [result v] to   // 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) < > 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)) = > 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) > > 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  endend`
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).

Hope I've got that all right!
Ooh. Pretty big script! Let me rephrase that. really big script!

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