Discuss Scratch
- Discussion Forums
- » Suggestions
- » Could we please have an exponents block? ( ) ^ ( )
- Poemon1_REMIX
-
100+ posts
Could we please have an exponents 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
- savaka
-
1000+ posts
Could we please have an exponents 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
-
1000+ posts
Could we please have an exponents 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)
- savaka
-
1000+ posts
Could we please have an exponents 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
-
100+ posts
Could we please have an exponents 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.
- savaka
-
1000+ posts
Could we please have an exponents 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
-
1000+ posts
Could we please have an exponents 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)
- Poemon1_REMIX
-
100+ posts
Could we please have an exponents 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!
- SuperNicky
-
100+ posts
Could we please have an exponents block? ( ) ^ ( )
power what do you mean power?
- Poemon1_REMIX
-
100+ posts
Could we please have an exponents block? ( ) ^ ( )
like 5^2 = 25, or 2^3 = 8. power what do you mean power?
(^ is power)
- savaka
-
1000+ posts
Could we please have an exponents 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
-
1000+ posts
Could we please have an exponents 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…

- firedrake969_test
-
500+ posts
Could we please have an exponents block? ( ) ^ ( )
The thing is that you can't do negative numbers with logs.
- DadOfMrLog
-
1000+ posts
Could we please have an exponents 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)
- Poemon1_REMIX
-
100+ posts
Could we please have an exponents 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!
- scratchisthebest
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
Even better than that huge script: this block!
(() ^ ())
- 1234abcdcba4321
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
The ^: To the power of.
I need this in my current project, and so far, the only way I can do it is by making a different variable just so my value can go up just the right amount.
Also, rename and delete functions for variables? I know delete was in 1.4, why was it deleted?
I need this in my current project, and so far, the only way I can do it is by making a different variable just so my value can go up just the right amount.
Also, rename and delete functions for variables? I know delete was in 1.4, why was it deleted?
- ErnieParke
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
The delete button wasn't deleted in Scratch 2.0; it's still there. Right click a variable in the block palette, and you can delete it and rename it.
About the ^ power, I'd just like to point out a workaround:
Showing,
ErnieParke
About the ^ power, I'd just like to point out a workaround:
([10 ^ v] of ((power) * ([log v] of (base))))
Showing,
ErnieParke
- AonymousGuy
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
I support, because sometimes I have to use it.
Or, if we could get custom reporter blocks, we could just make one of those.
Or, if we could get custom reporter blocks, we could just make one of those.
- ProdigyZeta7
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
And to prove this works:([10 ^ v] of ((power) * ([log v] of (base))))
10 ^ (b log a) = x >Setting up the equation
log 10 ^ (b log a) = log x >Property of logarithms
(b log a) log 10 = log x >Bringing the exponent down
b log a = log x >log 10 = 1
log (a ^ b) = log x >Bringing the exponent back to the base
a ^ b = x >Getting rid of log
- Discussion Forums
- » Suggestions
-
» Could we please have an exponents block? ( ) ^ ( )