Results 1 to 14 of 14

Thread: algebraic equation generator

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Question algebraic equation generator

    starting with a random number, how can i convert it to 2 (equal) equations?

  2. #2

  3. #3

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: algebraic equation generator

    something like this:

    Code:
    2x = -10x + 150 - x
    5           10

  4. #4

  5. #5

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: algebraic equation generator

    i'm not sure how they work exactly, which is why i'm asking.
    in my example the random number was 4

  6. #6

  7. #7
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: algebraic equation generator

    Your problem isn't very well defined, but I can guess a bit and make an algorithm that'll reproduce your result:

    1. Start with a target number, call it a. In the example, a=4.
    2. Add a single variable to the mix to make things look more complicated. Call it x. Note that, if you solve the example equation for x, you get x=10, which makes the left hand side [2x/5] = 4, and similarly the right hand side [(-10x + 150 - x)/10] = 4.
    3. Pick a value for x, randomly. In the example, x was chosen to be 10. Find the "multiplier", m, to get from x to a. In the example, m= a/x = 4/10 = 2/5, since x*2/5 = 10*2/5 = 4 = a. For simplicity, make sure neither x nor a is zero.
    4. Start with an expression involving x that evaluates to a. For example, you could use [mx]. Take this to be your left hand side.
    5. Apply equivalences to your expression in (4) several times. Take the result to be your right hand side.
    6. Set the result of 4 and 5 equal to each other; you have your equation.


    Example:
    1. Pick a=4.
    3. Pick x=10. Thus m=a/x=2/5.
    4. Start with [2/5*x] on the left hand side.
    5. Do the following manipulations:
    2/5*x = 2/5*x + (x - x) = 2/5*10 + (x - 10) = 4 + x - 10 = x - 6 = (x-6)*x/x = (x-6)*10 / x = (10x - 60)/x
    6. Setting (4) and (5) equal, we have the randomly generated equation

    2/5*x = (10x-60)/x


    Correctness check:
    2/5*x = (10x-60)/x
    2/5*x^2 = 10x-60
    x^2 = 25x-150
    x^2-25x+150 = 0
    (x-10)(x-15) = 0
    x=10 or x=15

    Thus 2/5*x = a = 4 or 6


    This example shows that, depending on the manipulations we do in generating the right hand side in step (5), we might get more solutions than just our original x--however, we'll have at least our original x as a solution, and thus one of the possible answers will be the a we chose. We can get around this by making sure we make only linear equations in our manipulation step.



    Anywho, as this example shows, your question may be complex. Really we need more constraints; I can see several different things that could answer the question that's been posed. Also, one possible path to generate your example is the following:

    2/5*x = 4/10*x = 4/10*x - x + x = 4/10*x - x + 10 = 4/10*10 - x + 10 = 4 - x + 10 = 14 - x = 14 - x + 1 - 1 = 15 - x - 1 = 15 - x - 10/x = 150/10 - 10*x/10 - x/10 = (150-10*x-x)/10 = (-10x+150-x)/10.

    Perhaps you can imagine an "equation" object (which is really a parse tree) that you mutate at each step using certain basic operations. That's all you're doing with my algorithm.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  8. #8

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: algebraic equation generator

    thanks jemidiah. i've only just got back to this today.
    i got as far as step 3. i'm not sure how to get the equivalences of the expression?

    i tried step 5 in a msgbox + it returned false, whereas i thought it'd show an equation

  9. #9
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: algebraic equation generator

    I'll flesh out Step 5 a bit more.

    Perhaps you're familiar with language grammars. For example, the C++ grammar is Appendix A of the C++ standard. Here's the grammar for an "equation":

    Eqn = e | ((Eqn) BinOp (Eqn)) | (UnOp (Eqn)) | Var | Const
    BinOp = + | - | * | /
    UnOp = -
    Var = "x"
    Const = any numerical constant

    The | means "or"; the e stands for "nothing". This basically gives a recursive definition for an equation object. The parentheses are there to allow us to ignore the order of operations. Given an Eqn, you can construct a parse tree of that object. For instance, (((1)+(x))*(3)) is a valid Eqn. The major grouping symbol is the multiplication. The tree is

    Code:
          *
        +   3
      1   x
    (where there are lines connecting the * and the +, the + and the 1, the + and the x, and the * and the 3). You can start with the Eqn specified in step 4, (([m])*([x])) where m and x are pre-computed numerical constants; that is, in your actual tree m and x would not variables, but a floating point numbers. I'll write such numbers in brackets. Note that [x] and x are therefore quite different concepts. This has an easy parse tree,

    Code:
          *
      [m]  [x]
    You can then apply mutating operations to this parse tree to get new equations. For instance, we can always multiply a value by x/x (since we assumed in my previous post that x is non-zero). Note that this x is a variable. So, we can replace m by m*x/x, giving the Eqn ((([m])*((x)/(x)))*([x])), which has tree

    Code:
          *
       *    [x]
    [m]  /
        x x
    (Note that the / is connected to the * above it and not to the [x]; similarly, the last two x's are connected to the /, and not the [m].)

    You can imagine applying various mutating operations to this tree (I listed 3 or 4 implicitly in my last post). After you mutate your tree a few times, you can print out the expression corresponding to it (you'll probably have to have a routine that culls some of the parenthesis for readability's sake). From there, you'll have an equation object that can be solved for x using the left hand side and algebraic manipulations which amount to the reverse of all the operations you've performed. This problem is not simple, but this general solution should be able to reproduce your example algorithmically.
    Last edited by jemidiah; Oct 13th, 2009 at 03:09 PM.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  10. #10

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: algebraic equation generator

    Quote Originally Posted by jemidiah View Post
    This problem is not simple, but this general solution should be able to reproduce your example algorithmically.
    thanks again jemidiah. you're a mathematical wizard.
    it'll take me a while to put this into practice, but i'll work at it.

  11. #11
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: algebraic equation generator

    I'm curious as to how this turns out. If you get a working equation generator, lemme know.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  12. #12

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: algebraic equation generator

    i got a working equation generator. i've uploaded it with this post.
    i want to improve it so i can have a negative multiplier (i.e. -10x), but i'm still working on that. any suggestions would be appreciated.
    Attached Files Attached Files

  13. #13
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: algebraic equation generator

    I don't have VB2008; would you mind posting some sample output, again for my curiosity?
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  14. #14

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: algebraic equation generator

    its still in the development stages, but heres some examples:
    Attached Images Attached Images    

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