A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Maths Questions Engine

  1. #1
    Member
    Join Date
    Sep 2005
    Posts
    50

    Maths Questions Engine

    Hi all,

    I'm trying to build a question/answer maths programme for 13 year olds. The sort of questions being asked include multiplication/division, simple algebra (eg factorise: 2a + 2b = ?) and fractions.

    The current method I have for checking answers is a straightforward text comparison of the students answer to what is saved. However, where there is more than one right answer - (eg 2a + 2b can be factorised as either 2(a+b) or 2(b+a)) this won't always work and so I'm left with having to store all the different possible correct answers and then check the students against each...

    Has anyone got any better ideas how to approach this? I've been trying to research code/ideas for building an algebra based engine which can 'do' the maths itself, but as yet I can't find anything (not to mention this seems like a daunting task...)

    Any ideas would be greatly received.

    Cheers

    John

  2. #2
    Unregistered User dnalogic's Avatar
    Join Date
    Feb 2001
    Location
    UK
    Posts
    146
    pass the string to javascript and use an "eval" function.

  3. #3
    madskool.wordpress.com brutfood's Avatar
    Join Date
    Apr 2002
    Posts
    469
    dnalogic: I don't think evaluating the expression is the issue.... and I would write a recursive descent parser to do that, rather than the javascript short-cut.

    The issue, as I understand it is to recognise a factorised expression as being a re-arrangement of a non-factorised expression (no parenthesis) - and not something different.

    But that doesn't seem too daunting to me (avoid division). A variation on a parser. A bit of tokenization and string-handling to effectively multiply something out, eliminating all the parenthesis. Then compare with the right answer.

    Perhaps keep everything arranged in power order and alphabetical order - to make it faster to compare two (multiplied out) expressions.
    AIR, ActionScript 3, Flex and Flash expert and freelance developer

  4. #4
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    You could cheat and just plug a few numbers into the variables, and chances are if you get the same answer, it's the right factorization.

    Example:

    2a + 2b = 2(a+b) = 2(b+a)
    Let a = 2 and b = 3
    2(2) + 2(3) = 2(2+3) = 2(3+2)
    10 = 10 = 10

  5. #5
    Viral tick lordofduct's Avatar
    Join Date
    May 2008
    Location
    South Florida
    Posts
    159
    I've been watching this thread for a while, but haven't posted yet. I started writing a post about the theory behind 'solving & simplifying' algebraic equations, but then stopped as... well... it's not easy for me to explain, especially if the person listening isn't well informed on the topic. **** I probably couldn't explain it fully to myself, and that's it... I only get the theory of it, not the actual implementation of it!

    Either way, it isn't all that simple! With some hard work you might get some basic core ideas up an running, but your engine would be extremely handicapped for what you want to do.

    What you might want to look into is Mathematica, from Wolfram Math. I know it has some type of interface that lets it work with Flash, I haven't really looked into it all to much, but it might be worth your time to look at.

  6. #6
    madskool.wordpress.com brutfood's Avatar
    Join Date
    Apr 2002
    Posts
    469
    I've found that teaching or explaining something to someone else is the best way to thoroughly understand it yourself. That's the way I learnt Flash originally - I had to teach a course on it.

    So, if you have the time and inclination - I'd be receptive to your explanation. Although my maths ability has declined since university.

    If I had the time and inclination, I'd write and post example code for the kind of parser I described - but no time - so busy on my own projects.

    As I said before, the problem here doesn't seem to be solving equations. Just multiplying out expressions, collecting together terms that can be combined, and comparing if two expressions are equivalent. String handling.
    AIR, ActionScript 3, Flex and Flash expert and freelance developer

  7. #7
    Viral tick lordofduct's Avatar
    Join Date
    May 2008
    Location
    South Florida
    Posts
    159
    I agree that is some of the best ways to getting a better understanding of things.

    But it isn't that easy... an entire school course could be held on it... and is! Check out any Analytical Theory of Algebraic Numbers class.

    Like I said, I only know some of the theory behind it and never actually witnessed any of the code behind it. Also, for anyone reading this, there is certainly the possibility there are more modern concepts behind it that make it more simple.

    Here's a VERY basic construct of it in my own head... keep in mind the way I perform math is very different from a lot of people and I was commonly instructed by my professors that I was doing it all wrong even though I got to the correct answer. It was very aggrivating all through out my educational career! But then you should see their faces when I could solve Differential Equations in my head in a matter of seconds... eat that teacher.

    Anyways, the lay out in my mind:

    All arithmetic can be related to a series of Sums. Subtraction is the addition of negative values, Multiplication is a series of sums, Division is the inverse and can be easily converted to multiplication, Powers are a series of multiples which again is a series of sums. So on and so forth. Even derivatives and series and everything can be 'simplified' into sums. These sums are arithmetically simple, not simplified in the traditional sense. They are the most basic form of math as opposed to the most readable form of math.

    The pleasent side here is we no longer have to worry about any laws, order of operations, or any odd parts in math anymore. There are no even roots of negative values, or quotients of 0. Limits of functions that don't exist are staring you right in the face.

    It's basically like taking the entire contents of your filing cabinet and laying it out on the floor... from here you can sort it any way you want with ease and destroy any repeating values easily. Let's look at it in numeral form and you will see what I mean:

    2 * 3(1 - 2) + 2 * 6
    1 - 2 + 1 - 2 + 1 - 2 + 1 - 2 + 1 - 2 + 1 - 2 + 2 + 2 + 2 + 2 + 2 + 2
    there are 6 -2s and 6 +2s... gone the equation simplifies:
    1 + 1 + 1 + 1 + 1 + 1
    6*1
    6

    and yes, this is how I do math in my head!

    As you can tell we can easily group values by counting them up.

    3+3+3+3+3+3+3+3+3
    2*3 + 3+3+3+3+3+3+3
    2*3 + 2*3 +3+3+3+3+3
    ...
    2*3 + 2*3 + 2*3 + 2*3 + 3
    work it like you do binary numbers... increasing by ones
    3*3 + 2*3 + 2*3 + 2*3
    3*3 + 3*3 + 2*3 + 3
    3*3 + 3*3 + 3*3
    bang, algorithm halt, we see three like values!
    3^3


    ok... yeah that seems weird, I know, and it is only numerals. How would you represent a*b? That's a little more abstract! Oh, I know...

    You can visualize the idea of a added together b times in your head... but how do you represent that programmatically? So a little back story there.

    CAS, Computer Algebra Systems, were first dreamt up when working with AI engines. Yep, the stuff they were messing with in AI back in the 70's were abstract value representation. We can now show a computer what a*b looked like by giving it this abstract value. It is a unique value of infinity, no infinity is equal, but all infinity is infinite.

    WHAT? No infinity is equal because as you approach infinity one method may get there faster then another. For instance take these two functions:
    f(x) = x
    f(x) = 2x

    as x increases towards infinity, f(x) reaches infinity. But at the same value of infinity x, f(x) = 2x is twice as large as f(x) = x. Two values of infinity, one larger then the other... ? That's abstract values. No longer do we care about if it is infinity, because a*b has infinite amount of results. But we care about the difference between different abstract values...

    a*b*2 is twice as large as a*b. a*b is b as large as a. b*2 is twice as large as b. etc, etc... until we can create a proportional representation of a compared to b. Using this we can create a sum series of a's and b's, and compare the proportions to figure out how to reduce the number of a's in comparison to b's and vice versa retracting all unneccessary values of a or b, just like we did the -2s and +2s in my previous example.

    So let's look at this:
    A(B - 1)

    let's simplify
    There are A number of (B - 1)s to sum. and there are (B - 1) number of As to sum. So if A and B approached infinity at the same rate, infB would be smaller then infA by A... or infB = infA - A. Why? Because if there were 7 number of (B-1)s, then there would be (7-1) number of As. Or 6 As. a difference of 1 A. So the proportion of As to Bs is for every A number of Bs you lose 1 A. How do you right A number of Bs? A*B, and for every A number of Bs you lose A?

    A*B - A


    uhmmm, yeah, I'm gonna stop there. I'm tired and really, I'm getting myself wrapped up into this little world in my head trying to make logical sense of what I'm thinking and attempting to vomit it into this thread.

    Now I'm concerned some other math nerd is gonna come along and say the same thing my professors would says,

    "DUDE, you're doing it allll wrong!"

    And yeah I can be, why? Because there are short cuts, there are rules to math for a reason. We memorize quadratic formulas and p-series and everything to make the task of doing math faster for us in our heads and on paper. We forget by the time we hit adolescence that math is just counting on our fingers and we fill out brains with thousands of algorithms and techniques to make life easier. But the further you get along, explaining and proving these techniques gets harder and harder. To translate to any logical proof takes lists of sub algorithms to test and check... when if we just break it all down into counting with sums, we need ONE basic law of math... COUNTING. You wanna tell me I'm wrong? Then why did I sleep through Calc3 and scream out answers in my drowsy disobedient and narcoleptic state?
    Last edited by lordofduct; 09-01-2008 at 07:43 AM.

  8. #8
    Member
    Join Date
    Sep 2005
    Posts
    50
    Wow! thanks for this guys, I'll look into it - its taking me a while to take it all in!

  9. #9
    madskool.wordpress.com brutfood's Avatar
    Join Date
    Apr 2002
    Posts
    469
    lordofduct: That was interesting. I never studied this area. Trying to make connections with what I knew before... The way you reduce everything to additions takes me back to undergraduate Peanos Axioms. I read a book by Simon Singh - I thinks that's where I heard about different infinities.

    CAS in the 70s... Years ago I read a paper by a guy called D. Lenat on something called "AM". It was later than the 70s - was it a development of these ideas?
    Last edited by brutfood; 09-15-2008 at 06:45 PM.
    AIR, ActionScript 3, Flex and Flash expert and freelance developer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center