PDA

Click to See Complete Forum and Search --> : algebraic equation generator


.paul.
Oct 9th, 2009, 01:57 PM
starting with a random number, how can i convert it to 2 (equal) equations?

NickThissen
Oct 9th, 2009, 02:01 PM
What do you mean by 2 equal equations..? Can't you give an example of what you want?

.paul.
Oct 9th, 2009, 02:09 PM
something like this:

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

NickThissen
Oct 9th, 2009, 02:17 PM
And what is the random number you mentioned? How does the x come into play?

.paul.
Oct 9th, 2009, 02:27 PM
i'm not sure how they work exactly, which is why i'm asking.
in my example the random number was 4

NickThissen
Oct 9th, 2009, 02:50 PM
Sorry... I've no idea what you're asking, or how anything could generate that equation starting from "4"..

jemidiah
Oct 9th, 2009, 11:36 PM
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.

.paul.
Oct 13th, 2009, 10:21 AM
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:D

jemidiah
Oct 13th, 2009, 03:06 PM
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 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf). 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


*
+ 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,


*
[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


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

.paul.
Oct 13th, 2009, 03:23 PM
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.

jemidiah
Oct 15th, 2009, 04:43 AM
I'm curious as to how this turns out. If you get a working equation generator, lemme know.

.paul.
Oct 21st, 2009, 01:22 PM
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.

jemidiah
Oct 21st, 2009, 11:36 PM
I don't have VB2008; would you mind posting some sample output, again for my curiosity?

.paul.
Oct 22nd, 2009, 01:03 PM
its still in the development stages, but heres some examples: