Derive operations from an arbitrary number I don't really know how to phrase this question, so I'll just mention the idea. This is partially reminiscent (at least in spirit to white box crypto): Can one derive arithmetic operations from a number? Is there a formula to do that?

So, the simplest example would be:

a = 4
ops = get_operations(a)
print(ops)

/* output:
*
* b = 2
* c = 2
* return b + c
*/


The idea is to simply have a way to "derive" a mathematical operation from a value. There are obviously more than "one" operation that could be derived from the above example. The system does not have to be complete.

The flow of such a "derivation" algorithm in my head is as such:


Get input (k)
Randomly choose an arithmetic operand (P) where y = k (P) x and store the operand (P)
Pick a random number (x) and store its value
Solve for (y) and store its value
Now, we have a combination of (P), (x), and (y) that, when solved, would yield the correct input (k).


My question is this: did someone research this and make a way better algorithm that what I could muster up here?
Is there a formula to do that?

Your example looks like a problem about Partitions to me. A partition is a way of representing a positive number as a sum of $n$ positive integers, for example:

The partitions of the number $5$ are:


$5 \space (+0)$
$4 + 1$
$3 + 2$
$3 + 1 + 1$
$2 + 2 + 1$
$2 + 1 + 1 + 1$
$1 + 1 + 1 + 1 + 1$


Since partitions consider every possibility valid, the number for possible ways of any integer $n$ can grow very fast, i.e. the number of possible partitions of the number $100$ is $190,569,292$.

There exist some formulas (some more complicated or faster than others and some are only approximations).

In your example you only have an operator once, so here $4 + 1$ and $3 + 2$ would be a possiblity.



Since you mentioned "more than one operation", a possibility would also be to represent numbers as their prime factors, for example:

The prime factorization of the number 22 is:


$2 \times 11$


There's always only one possiblity to represent a number as it's prime factors (if you don't care about the way you write it ($2 \times 11$ is the same as $11 \times 2$)).

There are a lot of factoring algorithms, since this is still a unsolved problem (Does P = NP ?) and this problem is important for cryptography.



I assume that a problem occurs if you'd try to do this with the operators of division and subtraction, for example:

There are infinite possibilities to represent a number as a subtraction, for example:

For the number $5$:


$6 - 1$
$7 - 2$
$8 - 3$
$9 - 4$
$\ldots$