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

#151 2011-04-07 07:10:40

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Calling all math lovers and good programmers

ProgrammingFreak wrote:

Could I help?

Offline

 

#152 2011-04-07 10:07:08

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

Re: Calling all math lovers and good programmers

ProgrammingFreak wrote:

ProgrammingFreak wrote:

Could I help?

I guess...


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

Offline

 

#153 2011-04-07 10:59:43

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Calling all math lovers and good programmers

Hardmath123 wrote:

ProgrammingFreak wrote:

ProgrammingFreak wrote:

Could I help?

I guess...

What now?

Offline

 

#154 2011-04-07 17:06:06

lemonpretzel
Scratcher
Registered: 2008-10-23
Posts: 100+

Re: Calling all math lovers and good programmers

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

 

#155 2011-04-08 07:28:31

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

Re: Calling all math lovers and good programmers

Cool! By the way, I think we should also include built in constants: e, π, ϕ, etc.


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

Offline

 

#156 2011-04-08 08:55:03

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

Re: Calling all math lovers and good programmers

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

 

#157 2011-04-08 12:27:44

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

Re: Calling all math lovers and good programmers

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.


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

Offline

 

#158 2011-04-08 17:53:41

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

Re: Calling all math lovers and good programmers

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>


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

Offline

 

#159 2011-04-08 20:25:23

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

Re: Calling all math lovers and good programmers

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:

Code:

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

Code:

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

 

#160 2011-04-09 15:26:49

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

Re: Calling all math lovers and good programmers

Never mind.  It won't work.

Offline

 

#161 2011-04-09 22:54:34

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

Re: Calling all math lovers and good programmers

why not?


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

Offline

 

#162 2011-04-10 03:10:08

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

Re: Calling all math lovers and good programmers

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)


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

Offline

 

#163 2011-04-10 20:14:51

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

Re: Calling all math lovers and good programmers

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

 

#164 2011-04-10 20:15:53

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

Re: Calling all math lovers and good programmers

applejack wrote:

why not?

I tried it out in Scratch.  Something's wrong.

Offline

 

#165 2011-04-10 22:57:05

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

Re: Calling all math lovers and good programmers

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


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

Offline

 

#166 2011-04-11 00:02:04

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

Re: Calling all math lovers and good programmers

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 right

Where 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

 

#167 2011-04-11 06:43:21

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

Re: Calling all math lovers and good programmers

Complex. How about factorial has highest precedence (not counting brackets)? So, sin 9! = sin (9!)


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

Offline

 

#168 2011-04-11 07:11:39

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

Re: Calling all math lovers and good programmers

Hardmath123 wrote:

Complex. How about factorial has highest precedence (not counting brackets)? So, sin 9! = sin (9!)

After exponents.

Offline

 

#169 2011-04-11 12:44:33

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

Re: Calling all math lovers and good programmers

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

 

#170 2011-04-11 12:49:13

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

Re: Calling all math lovers and good programmers

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

 

#171 2011-04-12 02:17:44

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

Re: Calling all math lovers and good programmers

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


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

Offline

 

#172 2011-04-12 05:35:18

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

Re: Calling all math lovers and good programmers

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)


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

Offline

 

#173 2011-04-12 06:48:01

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

Re: Calling all math lovers and good programmers

add me as programmer (and advertiser)


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

Offline

 

#174 2011-04-12 12:43:40

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

Re: Calling all math lovers and good programmers

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

Offline

 

#175 2011-04-13 00:22:38

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

Re: Calling all math lovers and good programmers

I got a kirby!!!


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

Offline

 

Board footer