ProgrammingFreak wrote:
Could I help?
Offline
ProgrammingFreak wrote:
ProgrammingFreak wrote:
Could I help?
I guess...
Offline
Hardmath123 wrote:
ProgrammingFreak wrote:
ProgrammingFreak wrote:
Could I help?
I guess...
What now?
Offline
I know a way to approximate large factorials, maybe for the ones which are starting to be written in scientific notation here, using Stirling's approximation. It doesn't have perfect precision; it's just an approximation, and anyway you can't see the units place in really large numbers. There could be a list of the first 20 or so factorials already built in, and this formula could do the larger numbers.
Offline
Cool! By the way, I think we should also include built in constants: e, π, ϕ, etc.
Offline
In addition to constants, how about the option to include user-defined functions? Or user-defined variables? We could include a set of standard equations that come with the calculator: quadratic formula, area/circumference of circle, graphing functions, etc.
Last edited by amcerbu (2011-04-08 08:56:19)
Offline
amcerbu wrote:
In addition to constants, how about the option to include user-defined functions? Or user-defined variables? We could include a set of standard equations that come with the calculator: quadratic formula, area/circumference of circle, graphing functions, etc.
That would be getting ahead of ourselves.
Offline
Test.
<script type="text/javascript" src="http://cdn.widgetserver.com/syndication/subscriber/InsertWidget.js"></script><script type="text/javascript">if (WIDGETBOX) WIDGETBOX.renderWidget('3d6fe9e4-8ec8-4d67-8029-98097a805f8f');</script><noscript>Get the <a href="http://www.widgetbox.com/widget/donkey-kong">Donkey Kong</a> widget and many other <a href="http://www.widgetbox.com/">great free widgets</a> at <a href="http://www.widgetbox.com">Widgetbox</a>! Not seeing a widget? (<a href="http://docs.widgetbox.com/using-widgets/installing-widgets/why-cant-i-see-my-widget/">More info</a>)</noscript>
Offline
I believe that I have a way to deal with the parentheses problem:
This is a rough approximation of what the code would do. We need a list for parentheses locations (p_loc) and a list for input (input). We also need three temporary variables: l_scan and l_scan2 for scanning input list and p_scan for adding to p_loc.
Tell me what you guys think of this:
Delete all of (all lists)
Set (all temporaries) to 0
Set list (numbers) to {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
Ask “Input expression.”
Set (l_scan) to 0
Repeat (length of answer)
Change (l_scan) by 1
Add letter (l_scan) to list (input)
Set (l_scan) to 0
Repeat (length of list (input)) //This part reduces numbers with 2+ digits to one location in the list//
Change (l_scan) by 1
If list (numbers) contains (item (l_scan) of list (input))
Change (l_scan) by 1
If list (numbers) contains (item (l_scan) of list (input))
Replace item (l_scan) of (input) with (join (item (l_scan-1) of (input)) with (item (l_scan) of (input)))
Delete item (l_scan) of list (input)
Change (l_scan) by -1
Set (p_scan) to 0
Set (l_scan) to 0
Set (l_scan2) to 0
Repeat (length of list (input))
Change (l_scan) by 1
If item (l_scan) of list (input) = "("
Change (p_scan) by 1
Set (l_scan2) to (l_scan)
Repeat until (p_scan = 0)
Change l_scan2 by 1
If item (l_scan2) of list (input) = ")"
Change (p_scan) by -1
Add item (l_scan) to list (p_loc)
Add item (l_scan2) to list (p_loc)When the code finishes, the locations of pairs of parentheses will be contained in p_loc in order of precedence, and then left to right. So in the expression
1+2/(4+5*(2-3))^(6*7)
The p_loc list would read: {5, 15, 10, 14, 17, 21}
The algorithm for finding the value itself would read from the end of this list and evaluate expressions inside parentheses. Notice that {10, 14} comes after {5, 15} because it is nested inside. An interpreter reading from the end would evaluate it first.
I have not tested this code myself, so if there are any errors please feel free to tell me/correct them. This project is still pretty flexible.
Last edited by amcerbu (2011-04-08 21:23:46)
Offline
Can somebody get a list of order of operations including sin/cos/tan/asin/acos/atan/mod/factorial/roots(do those count as exponents?)/any other operations you can think of?
Last edited by Hardmath123 (2011-04-10 03:10:38)
Offline
Hardmath123 wrote:
Can somebody get a list of order of operations including sin/cos/tan/asin/acos/atan/mod/factorial/roots(do those count as exponents?)/any other operations you can think of?
(...)
sin(...), cos(...)
a^b, includes sqrt
* or / from left to right, factorial
+ or - from left to right
Offline
amcerbu wrote:
Hardmath123 wrote:
Can somebody get a list of order of operations including sin/cos/tan/asin/acos/atan/mod/factorial/roots(do those count as exponents?)/any other operations you can think of?
(...)
sin(...), cos(...)
a^b, includes sqrt
* or / from left to right, factorial
+ or - from left to right
Where do factorials factor in? (pun not intended. honestly.)
Offline
Hardmath123 wrote:
amcerbu wrote:
Hardmath123 wrote:
Can somebody get a list of order of operations including sin/cos/tan/asin/acos/atan/mod/factorial/roots(do those count as exponents?)/any other operations you can think of?
(...)
sin(...), cos(...)
a^b, includes sqrt
* or / from left to right, factorial
+ or - from left to rightWhere do factorials factor in? (pun not intended. honestly.)
Modulo (mod) goes with multiplication.
Let's consult Wikipedia about factorials.
Wikipedia wrote:
An exclamation mark indicates that one should compute the factorial of the term immediately to its left, before computing any of the lower-precedence operations, unless grouping symbols dictate otherwise. But 2^3! means (2^3)! = 8! = 40320 while 2^(3!) = 2^6 = 64; a factorial in an exponent applies to the exponent, while a factorial not in the exponent applies to the entire power.
Last edited by amcerbu (2011-04-11 00:05:07)
Offline
Complex. How about factorial has highest precedence (not counting brackets)? So, sin 9! = sin (9!)
Offline
Hardmath123 wrote:
Complex. How about factorial has highest precedence (not counting brackets)? So, sin 9! = sin (9!)
After exponents.
Offline
scimonster wrote:
Hardmath123 wrote:
Complex. How about factorial has highest precedence (not counting brackets)? So, sin 9! = sin (9!)
After exponents.
Agreed. But it will make our life easier if sin, cos, tan, asin, acos, atan, mod, and sqrt use the notations sin(x), etc. instead of only sin x.
For factorials, if no brackets included, 2^5! will be evaluated as 2^(5!), as opposed to (2^5)!
Last edited by amcerbu (2011-04-11 12:47:35)
Offline
amcerbu wrote:
scimonster wrote:
Hardmath123 wrote:
Complex. How about factorial has highest precedence (not counting brackets)? So, sin 9! = sin (9!)
After exponents.
Agreed. But it will make our life easier if sin, cos, tan, asin, acos, atan, mod, and sqrt use the notations sin(x), etc. instead of only sin x.
For factorials, if no brackets included, 2^5! will be evaluated as 2^(5!), as opposed to (2^5)!
+2.
Offline
amcerbu wrote:
scimonster wrote:
Hardmath123 wrote:
Complex. How about factorial has highest precedence (not counting brackets)? So, sin 9! = sin (9!)
After exponents.
Agreed. But it will make our life easier if sin, cos, tan, asin, acos, atan, mod, and sqrt use the notations sin(x), etc. instead of only sin x.
For factorials, if no brackets included, 2^5! will be evaluated as 2^(5!), as opposed to (2^5)!
That's what I meant in the first place...
Offline
Here are the features we need in the setup engine:
•Converts the input to a list
~Keeps numbers and operation names like sin and sqrt as 1 item.
~Ex: Converts sqrt 1 + 2 into:
·sqrt
·1
·+
·2
•Ignores anything that isn't a number or an operator's symbol
•Replaces (a+b)(a-b) with (a+b)*(a-b)
•Ignores commas in numbers: 1,000 converts to 1000
•Checks for mismatched brackets
•Replaces constants' names or symbols wiht values:
pi => 3.141592653
π => 3.141592653
Let's add to this list, then start on the setup engine—we ought to finish it by next week.
Last edited by Hardmath123 (2011-04-14 08:39:54)
Offline
Hardmath123 wrote:
Here are the features we need in the setup engine:
•Converts the input to a list
~Keeps numbers and operation names like sin and sqrt as 1 item.
~Ex: Converts sqrt 1 + 2 into:
·sqrt
·1
·+
·2
•Ignores anything that isn't a number or an operator's symbol
•Replaces (a+b)(a-b) with (a+b)*(a-b)
•Ignores commas in numbers: 1,000 converts to 1000
•Checks for mismatched brackets
Let's add to this list, then start on the setup engine—we ought to finish it by next week.
OK, I'm a bit busy but I'll try to start that soon.
Offline