This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#151 2011-05-26 22:15:15

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

Just post your ideas on the forum, and the rest of the team will give you input.

Offline

 

#152 2011-05-26 22:24:40

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

Actually, I am revising my statement.  I just realized that it doesn't matter where we put the multi-letter ops, because they happen first anyway.  So, they're not really ops, they're more like numbers. 

amcerbu wrote:

scimonster wrote:

@amcerbu: Is "1" the first thing? According to OOO, it goes "PEMDAS" - Parentheses, exponents, multiplication/division, addition/subtraction. I want to put our multi-letter ops with ^s.

Sorry for being unclear.  The system I described ranks operations of higher precedence (things that happen first) with higher numbers. 

amcerbu wrote:

Code:

Operator:   ^ * / + - %
Precedence: 4 2 2 1 1 3
Operators with higher precedence happen first - exponentiation, then modulo, multiplication/division, and addition/subtraction

Since % (shortcut for modulo) has precedence 3, it will execute after exponentiation, but before multiplication.  That means that its arguments are only the numbers immediately before and after.  5 + 3 % 4 * 2 will evaluate 5 + ( 3 % 4 ) * 2.  However, 3 % 4 ^ 2 will evaluate 3 % ( 4 ^ 2 ).  I would like to say again that the user must format multi-letter operations like this: sqrt(x), sin(x).  That way, the value of the multi-letter operation is taken care of before moving on.  Think about this:

Code:

//In this representation, position up or down indicates bracket hierarchy.  
//The highest line is the innermost bracket set.  
//In our project, the program will evaluate the diagram "top to bottom."  
                                    3      
               4 + 5           log(   )    
      2 / sin(       ) + sqrt(          )
4 + (                                     )

Together, this makes:
4 + ( 2 / sin( 4 + 5 ) + sqrt( log( 3 ) ) )

I listed multi-letter operations with a precedence of 2 because, in fact, they will execute before the rest of the "line" on which the appear.  Consider 2 / sin( 4 + 5 ).  sin( 4 + 5 ) will be calculated before performing the 2 / ___ part. 

Hope that clears up what I said earlier.

EDIT:  Finished exams!  I can start helping out on this project.  I'll be free for about the next 3 weeks.

Last edited by amcerbu (2011-05-28 03:06:59)

Offline

 

#153 2011-05-28 09:06:27

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Xenon Inc. Developers' Thread

Great, I'm gonna be gone (mostly) for a while (school), so once hpotter134's done, amcerbu takes over. I described my system already. While I'm gone, scimonster, applejack, and amcerbu are in charge. Good luck!  wink


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#154 2011-05-28 09:32:15

scratcher7_13
Scratcher
Registered: 2011-02-09
Posts: 1000+

Re: Xenon Inc. Developers' Thread

I'm planning on using nested if-else blocks and a variable. Then I will repeatedly check if the character (insert variable here) is a parenthesis and the character after that is a parenthesis (or bracket). I will just be checking for implied multiplication. Should I use an item of a list instead of a variable?


♫ 90% of teens can't do math. If you are one of the 40% of teens who can, copy and paste this into your signature. ♫♪
http://dl.dropbox.com/u/6273449/BlockLibraryTitle.pnghttp://i.imgur.com/mr9Hf.gif

Offline

 

#155 2011-05-28 11:13:30

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

It doesn't really matter whether you use a variable or an item from a list.  Using an item from a list will make the code more compact, but harder to read.

Offline

 

#156 2011-05-28 21:11:55

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Xenon Inc. Developers' Thread

Have I quit, or am i just inactive on here?


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#157 2011-05-28 23:10:54

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

ssss wrote:

Have I quit, or am i just inactive on here?

Well, scratcher7_13 currently is doing the job you were assigned.  Hardmath123 leaves for a while starting June 1.  But, as he pointed out, you haven't really given us many suggestions to look at.  If you start offering ideas for the next part of the engine (computation, fixing bugs in the list interpreter), then you'll have a better chance of getting a job.  I'm not in charge, so I can't say, but it looks like you "quit."  We'll see what happens.

Offline

 

#158 2011-05-29 08:21:55

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Xenon Inc. Developers' Thread

ssss wrote:

Have I quit, or am i just inactive on here?

And, when you claimed to quit...
I think that's when you were labeled as inactive and your job given to scratcher7_13.

Offline

 

#159 2011-05-29 18:09:03

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

Also, scratcher7_13, you need to make sure that negative signs (-x) are converted to "-1*x".  So, -4 will become "-1*4".  That will clear up some problems later in the execution.

Last edited by amcerbu (2011-05-30 01:27:29)

Offline

 

#160 2011-05-29 18:12:20

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

@Hardmath123:

Your code previously was correct, that the program will scan the sub-expression from left to right and evaluate as it goes.  However, there is one problem.

Exponents have right-to-left association, meaning that

Code:

a^b^c = a^(b^c) ≠ (a^b)^c

So, for the exponents only, the program will have to scan right-to-left, not left-to-right.

Last edited by amcerbu (2011-05-29 18:13:27)

Offline

 

#161 2011-05-29 23:11:26

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Xenon Inc. Developers' Thread

amcerbu wrote:

@Hardmath123:

Your code previously was correct, that the program will scan the sub-expression from left to right and evaluate as it goes.  However, there is one problem.

Exponents have right-to-left association, meaning that

Code:

a^b^c = a^(b^c) ≠ (a^b)^c

So, for the exponents only, the program will have to scan right-to-left, not left-to-right.

Incorrect.
Math principle states exponents go left to right.

Wait never mind. I see what your saying.


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#162 2011-05-30 01:25:44

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

So, the correct form is

Code:

a^(b^c)

I just wanted to make sure that was made clear before someone started on the computation part.

Offline

 

#163 2011-05-30 23:29:08

applejack
Scratcher
Registered: 2010-03-23
Posts: 100+

Re: Xenon Inc. Developers' Thread

Hmm... I'm in charge!  big_smile  I just got back from a backpacking trip, you will see more of me now!  smile

Hardmath123 wrote:

Great, I'm gonna be gone (mostly) for a while (school), so once hpotter134's done, amcerbu takes over. I described my system already. While I'm gone, scimonster, applejack, and amcerbu are in charge. Good luck!  wink


http://i.imgur.com/zKzps.png
http://blocks.scratchr.org/API.php?action=onlineStatus&type=square&user=applejack -I'm http://blocks.scratchr.org/API.php?action=onlineStatus&type=text&user=applejack

Offline

 

#164 2011-05-30 23:44:26

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Xenon Inc. Developers' Thread

amcerbu wrote:

So, the correct form is

Code:

a^(b^c)

I just wanted to make sure that was made clear before someone started on the computation part.

Okay, I want to help make the computation part, but the issue is, where is the base?


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#165 2011-05-30 23:47:29

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

scratcher7_13, how is it coming?

Offline

 

#166 2011-05-31 00:46:02

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

bbbeb wrote:

amcerbu wrote:

So, the correct form is

Code:

a^(b^c)

I just wanted to make sure that was made clear before someone started on the computation part.

Okay, I want to help make the computation part, but the issue is, where is the base?

Well, technically, the base is b, and then a.  The evaluator would do the following for something like 2^3^4

Code:

2^3^4
Start at end, scan until find ^
     Check terms before and after ^ 
          Return 3, 4 
     Perform 3^4
          Return 81
          Replace 3^4 in 2^3^4 with 81
     
Start at end, scan until find ^
     Check terms before and after ^
          Return 2, 81
     Perform 2^81
          Return 2.417e24
          Replace 2^81 with 2.417e24

Move on...

Better?

EDIT: For a sub-expression not containing any brackets (so, lowest possible level), the number of necessary repetitions for any given operator is the number of that operator.  Consider the following:

Code:

1 + 4 * 3 / 2 ^ 2

Since it contains no sub-expressions (brackets), we can evaluate it immediately. 

First, we scan right to left and find there to be 1 exponentiation.  So, we repeat the exponentiation sequence above 1 time. 

Code:

1 + 4 * 3 / 4

Then, we scan for multiplication or division; there are two.  We scan left to right this time, first simplifying 4 * 3 to 12.  On the second repetition, we perform 12 / 4 and simplify the expression further.

Code:

1 + 3

Now, there is only one addition or subtraction operation, so we complete the simplification process, and are left with...

Code:

4

Last edited by amcerbu (2011-05-31 00:56:47)

Offline

 

#167 2011-05-31 01:55:22

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

Here is my proposal for the evaluation code:

For this example, I will not include modulo (%). 

Code:

Inpt: 3 + 4 * 2 / 4 ^ 2 ^ 3

Pseudo Code:

Set t1 to (length of Inpt) //t1 is our input scanner.  Right-to-left for ^
Repeat until t1 = 0
     If item t1 of list Inpt = (^)
          Set t2 to item (t1-1) of Inpt //t2 is our "left value"
          Set t3 to item (t1+1) of Inpt //t3 is our "right value"
          Replace item (t1-1) of Inpt with (10^(t2*log(t1)))
          Delete item (t1) of Inpt
          Delete item (t1) of Inpt
     Change t1 by -1
Set t1 to 0
Repeat until t1 = (length of Inpt)
     If item t1 of list Inpt = (*)
          Set t2 to item (t1-1) of Inpt
          Set t3 to item (t1+1) of Inpt
          Replace item (t1-1) of Inpt with t2*t3
          Delete item (t1) of Inpt
          Delete item (t1) of Inpt
     If item t1 of list Inpt = (/)
          Set t2 to item (t1-1) of Inpt
          Set t3 to item (t1+1) of Inpt
          Replace item (t1-1) of Inpt with t2/t3
          Delete item (t1) of Inpt
          Delete item (t1) of Inpt
     Change t1 by 1
Set t1 to 0
Repeat until t1 = (length of Inpt)
     If item t1 of list Inpt = (+)
          Set t2 to item (t1-1) of Inpt
          Set t3 to item (t1+1) of Inpt
          Replace item (t1-1) of Inpt with t2+t3
          Delete item (t1) of Inpt
          Delete item (t1) of Inpt
     If item t1 of list Inpt = (-)
          Set t2 to item (t1-1) of Inpt
          Set t3 to item (t1+1) of Inpt
          Replace item (t1-1) of Inpt with t2-t3
          Delete item (t1) of Inpt
          Delete item (t1) of Inpt
     Change t1 by 1
Proceed to next bracket set.

Last edited by amcerbu (2011-05-31 17:08:28)

Offline

 

#168 2011-05-31 05:55:39

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Xenon Inc. Developers' Thread

That could work for after we get all the special forms.
Do you program Squeak? XD
When you wrote "t" did you mean "t1"?

Offline

 

#169 2011-05-31 17:07:12

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

scimonster wrote:

That could work for after we get all the special forms.
Do you program Squeak? XD
When you wrote "t" did you mean "t1"?

Yep, t1, not t, thanks for telling me.  I went a head and fixed it up.  And no, I don't know any Squeak.  Currently, C++, TI BASIC, and a tiny bit of Python.

Last edited by amcerbu (2011-05-31 17:10:07)

Offline

 

#170 2011-05-31 17:19:20

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

By the way, the script above could easily be simplified, but I'm too lazy.

Offline

 

#171 2011-06-01 08:03:14

scratcher7_13
Scratcher
Registered: 2011-02-09
Posts: 1000+

Re: Xenon Inc. Developers' Thread

I'm sorry, but I won't be able to do anything with Scratch for the next month. I'll be too busy. Maybe ssss can do this job anyway.


♫ 90% of teens can't do math. If you are one of the 40% of teens who can, copy and paste this into your signature. ♫♪
http://dl.dropbox.com/u/6273449/BlockLibraryTitle.pnghttp://i.imgur.com/mr9Hf.gif

Offline

 

#172 2011-06-01 08:19:03

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Xenon Inc. Developers' Thread

Or, amcerbu's free, he can do it.
amcerbu, job for you!!!


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#173 2011-06-01 22:51:13

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

Alright.  I'll see what I can do.  Implied multiplication, right?  I'll try to post my ideas tomorrow (it's about 11 at night right now on my time).

Offline

 

#174 2011-06-02 02:42:59

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Xenon Inc. Developers' Thread

scratcher7_13 wrote:

I'm sorry, but I won't be able to do anything with Scratch for the next month. I'll be too busy. Maybe ssss can do this job anyway.

So, what were you attempting to do?


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#175 2011-06-02 15:41:14

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

ssss wrote:

scratcher7_13 wrote:

I'm sorry, but I won't be able to do anything with Scratch for the next month. I'll be too busy. Maybe ssss can do this job anyway.

So, what were you attempting to do?

His job was implied multiplication- adding a * between two terms.

Offline

 

Board footer