# How to Generate Random Mathematical Equations that Equal an Integer

Looking for a way to generate random mathematical equations that equal an integer between 0 and 9, a way to rank the complexity of the equation rendered, and a method to note the mathematical concepts utilized within the equation.

My first guess is that a random integer between 0 and 9 would be selected. After that, your guess is much more likely to be better than mine.

EDIT: To be more clear, solutions should ONLY result in the following: 0,1,2,3,4,5,6,7,8,9.

-
What is the motivation behind this task? – Yuval Filmus Jun 10 '11 at 20:54
Maybe he is making capture? – Ilya Jun 10 '11 at 20:55
what kind of equations you are interested in? also, equations can not be equal to smth, are you talking about their solutions? – Ilya Jun 10 '11 at 20:56
@Gortaur: Do you have links to the meanings of capture and smth? – blunders Jun 10 '11 at 21:09
@Yuval Filmus: My motivation is a secret. Is there anything about the question and the solution it seeks that is unclear to you? – blunders Jun 10 '11 at 21:12

I am still not sure what do you want, but I guess you are talking about roots. Ok, lets consider a class of linear equations. They have only two parameters: $ax+b = 0$. Choosing randomly $\hat{x} = 0,1,...,9$ you have a condition on $a$ and $b$: $a\hat{x}+b = 0$. for this class you can only randomly choose one of the variables (preferably, $b$ not to make $a$ equal to zero).

Example. $x = 2$, then $2a+b = 0$. You make $b = rand(0,100)$ and $a = -0.5 b$. then the solution will be $x=2$ as it was desired.

You can also consider another class - but note that you would like to have a unique solution. Say, for quadratic equation you may want to say "find the positive root of an equation". Then algorithm is the following: choose $\hat{x} = 0,1,...,9$ and $x'$ to be a negative number (preferably integer also). Then any equation of the form $a(x-\hat{x})(x-x') = 0$ has desired roots. For this equation you can choose independently $a$ (any) and $x'$ (negative). To make it more tough, open the brackets after the choice of all parameters.

Example. We choose again $\hat{x} = 2$ and $a = rand(0,12)$ and $x' = -rand(0,100)$. then we have an equation $ax^2 - (2+x')x + 2x' = 0$.

-
I'm assuming, in your first example, you mean for a solution $x = 2$, then $2ax + b = 0$...? – amWhy Jun 10 '11 at 22:43
+1 @Gortaur: Thanks, stepped out, just got back. Answers looks fine, realized while I was out (looking at the question on my phone) that the question was flawed, though a good start, so I'm not going to edit the question since it's my error. Also, believe @amWhy is right, would you confirm that. Thanks! – blunders Jun 11 '11 at 2:42
@blunders: I will not confirm it. This statement doesn't make sense to what I've written – Ilya Jun 11 '11 at 13:34

Pick a positive integer n between 0 and 4 and a positive integer p between 1 and 5. Add r instances of (y+(-y)) to n+p, where r indicates a random positive integer, in other words (n+p)+(y_1+(-y)_1)+...+(y_r+(-y)_r). The complexity of the equation compared to other equations of the same type comes as the value equal to r. One could also select 4 positive integers between 0 and 2, or 5 positive integers two of which lie between 0 and 2 and three of which lie between 0 and 1, and many other possibilities exist. The partitions of 9 here work similarly.

-
+1 @Doug Spoonwood: complexity was meant to be the inclusion of concepts such as: addition, subtraction, division, multiplication, roots, fractions, powers, Decimals, percentages, etc. until as many concepts had been used that would not result in getting an answer that would not equal [0-9]. That said, your idea was creative, addressed two of the three parts of the question as far as I'm able to tell - though, to me, incremental redundant patterns produce volume, not complexity. As very possible I've misunderstood your answer, either way thank you! – blunders Jun 11 '11 at 3:05