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/subtractionSince % (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
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!
Offline
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?
Offline
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
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
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
@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
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
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 thatCode:
a^b^c = a^(b^c) ≠ (a^b)^cSo, 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.
Offline
Hmm... I'm in charge!
I just got back from a backpacking trip, you will see more of me now!
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!
![]()
Offline
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?
Offline
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
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:
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.
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.
1 + 3
Now, there is only one addition or subtraction operation, so we complete the simplification process, and are left with...
4
Last edited by amcerbu (2011-05-31 00:56:47)
Offline
Here is my proposal for the evaluation code:
For this example, I will not include modulo (%).
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
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
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
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.
Offline
Or, amcerbu's free, he can do it.
amcerbu, job for you!!!
Offline
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?
Offline
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