0

I have no idea how or where to start, I need to have some vocabulary or terms to get going and researching so let's ask the community.

Problem: I have a value X that is the final answer of the equation. I have a range of values, let's say 10 (A-J), that will be used in the equation. Using simple calculations (+, -, *, /, (), ^) to form an equation that uses some or all of the values A-J to solve the equation to the value X.

Example: A^2+B*C+(D+E+F+G)*J+30 = X

Input: final value X, the values used in the equation, max number of values to be used in the equation meaning I want to use at least Z number of given values in the equation (in the example Z = 8)

Output: the equation that solves it with the given values

Can this be turned into a python script for example? Is it possible at all to calculate this way? What are the terms that describe this kind of calculations?

  • A=1 B=2 and so on .... and the use it .Is that what you want to say – Zesty Dragon Aug 04 '20 at 22:09
  • Can you explain and simplify it more – Zesty Dragon Aug 04 '20 at 22:10
  • Do you mean to say you want to use default values when arguments are not supplied? If so you can simply define a function like `def myfunc(arg = default):` – Kvothe Aug 04 '20 at 22:12
  • @Prune He doesn't have an equation. It seems he has some input numbers (for example: 48, 252, 3, 1874,...) and an output number (14824), and wants an equation to equate a subset of input numbers to the output number. – Jakub Aug 04 '20 at 22:27
  • Ah ... thanks @Jakub. I see where I read too quickly. – Prune Aug 04 '20 at 22:30
  • This is a common enough problem, although often requiring you to use *all* the given values and the "basic four" operations. You need to do some research into combinatorics -- how to methodically go through the various choices of operations and numbers. The question is not focused enough for Stack Overflow. – Prune Aug 04 '20 at 22:34
  • Are you trying to find an expression/formula for `X` that is made up of other variables such that the equation `X=f(A, B, ...)` fits the data? You can represent any expression made up of the simple ops (+, -, *, /, (), ^) as a binary expression tree (https://en.wikipedia.org/wiki/Binary_expression_tree). Finding the right expression tree that fits your data can be done in many ways (brute force search for example) but an old-school method is genetic programming https://en.wikipedia.org/wiki/Genetic_programming. – Ankur Aug 04 '20 at 22:42
  • Thanks for all the comments. Upon quick googling, the binary expression tree approach maybe the one I am looking for. Now I have something to grab on to. Thanks. –  Aug 07 '20 at 07:01

1 Answers1

0

If I understand the question correctly:

The algorithm you are looking for outputs a mathematical function, along with the specific values that, when applied to the function, give you the input value x, for an arbitrary value x.

In general I believe this is not possible. It may be possible from a non-deterministic point of view, where you try and guess values but that usually isn't feasible from an algorithmic or computational standpoint.

  1. Let's first limit the function to one variable. Finding a function that gives you a value x, for some value a, i.e. f(a) = x, is the same as asking for f(a) - x = 0.

  2. Limiting the operations to +,-,*, we see that f(a) is a polynomial.

  3. Limiting the problem in this way relates the solution to algebraic numbers and constructible numbers. The more general mathematical theory that explain properties of these numbers and functions is called Galois Theory.

  4. It is possible to find the polynomial of a given the input value x IF and only IF the input value x is algebraic. You can produce a simple algorithm that takes powers of x until that power of x is an integer (or a rational number).

  5. You can produce a simple algorithm that takes powers of the irrational part of x until that power of x is an integer (or a rational number). Note that even in this algorithm you would need to take into account some sort of measurement error, because sqrt(2) = 1.41421356237... for an infinite number of decimal places, and the computer can only keep track of some finite amount of decimal places. For example:

def sqrt(x):
    return x**(1/2)

if __name__ == "__main__":
    num = sqrt(2)
    print(num)
    print(num**2)

Will output:

1.4142135623730951
2.0000000000000004
  1. So the output of such a simple algorithm will never be 100% correct. It is possible for a human to do, but not a computer. You may want to look into the field of symbolic computation, but the algorithm for solving even part of your problem will not be easy to turn into a script.
  2. If you are okay with not solving this problem 100% of the time, you may want to look into linear approximations and non-linear approximations.

The reason why even without measurement errror, I believe this is not possible in general is that adding the operations (^,/) may not result in a polynomial ring. Which is the basis of solving problems relating to algebraic numbers.

Introducing extra variables b,c,....,n,.. to f, such that f(a,b,c,...,n,...) = x would also restrict what functions would satisfy the properties of a ring.

Regardless, this problem is difficult, even when only considering polynomials of one variable. Googling the terms in bold may help provide additional insight into your problem. Sorry if some of this was already obvious for you and in any case I hope this helps!

  • Thanks for your answer. I will reseach more and review your answer's terms if they are the methods I am looking for. –  Aug 07 '20 at 07:03