# automatic formula finding function [duplicate]

I am curious how easy it would be to automatically find some formulas related to basic number theory OEIS sequences using some Mathematica search algorithm for a small set of OEIS sequences as a starting point. I have some formulas already that I found through trial and error over a long period of time that I will list. If the formulas I found can be duplicated automatically and/or new ones found then it would be good to consider more OEIS sequences to look for more formulas, ie adding A053144, A058250, A002110, A005867 could be a good next set to consider. Also: A112037, A236435, A236436, A072044, A072045 .

Maybe a couple basic techniques would be to use operators +,-,*,/ in different patterns and iterate with varying offsets (maybe +-2 offsets) and then compare the outputs to look for matching output.

Suggested initial OEIS sequences to check: A000040, A038110, A038111, A060753, A161527.

Some Mathematica code with some formulas listed that are already found, and an attempt to automatically find some formulas..

A000004 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
A000012 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
A000040 = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41};
A038110 = {1, 1, 1, 4, 8, 16, 192, 3072, 55296, 110592, 442368,
13271040, 477757440};
A038110offset1 = {1, 1, 4, 8, 16, 192, 3072, 55296, 110592, 442368,
13271040, 477757440, 19110297600};
A038111 = {2, 6, 15, 105, 385, 1001, 17017, 323323, 7436429, 19605131,
86822723, 3212440751, 131710070791};
A060753 = {1, 2, 3, 15, 35, 77, 1001, 17017, 323323, 676039, 2800733,
86822723, 3212440751};
A060753offset1 = {2, 3, 15, 35, 77, 1001, 17017, 323323, 676039,
2800733, 86822723, 3212440751, 131710070791};
A161527 = {1, 2, 11, 27, 61, 809, 13945, 268027, 565447, 2358365,
73551683, 2734683311, 112599773191};
A161527offset1 = {0, 1, 2, 11, 27, 61, 809, 13945, 268027, 565447,
2358365, 73551683, 2734683311};
A161527offset2 = {1, 1, 2, 11, 27, 61, 809, 13945, 268027, 565447,
2358365, 73551683, 2734683311};

A060753offset1/
A038110offset1 == (A161527offset2/
A038110)/((A161527offset2/A060753) - (A161527offset2/A038111))

A038110 + A161527offset1 == A060753

A000012 == A161527offset1/A060753 + A038110/A060753

A161527offset1/A038111 == A000012/A000040 - A038110/A038111

A038110/A038111*(A000040^2) - (A038110/
A038111*((A038110*A000040 - A060753)*
A000040/A038110)) == (A000040*A060753)/
A038111 == (A038110*A000040^2)/
A038111 - (A000040*(A038110*A000040 - A060753))/A038111 == A000012

A038111 == A000040*A060753

(A060753offset1*
A038110) + ((A038110offset1*A060753*A038111)/(A060753 -
A038111)) == A000004

A038111 == (A060753offset1*A038110*
A060753)/((A060753offset1*A038110) - (A038110offset1*A060753))

A060753offset1/
A038110offset1 == -((A060753*A038111)/(A038110*(A060753 - A038111)))

listofSequences = {A000012, A000040, A038110, A038110offset1, A038111,
A060753, A060753offset1, A161527, A161527offset1, A161527offset2};

(*automatic formula finding*)
formulasAplusB = {};
formulasAminusB = {};
formulasAtimesB = {};
For[i = 1, i <= Length[listofSequences], i++,
For[j = i, j <= Length[listofSequences], j++,
For[k = 1, k <= Length[listofSequences], k++,
If[listofSequences[[i]] + listofSequences[[j]] ==
listofSequences[[k]], AppendTo[formulasAplusB, {i, j, k}]
];
If[listofSequences[[i]] - listofSequences[[j]] ==
listofSequences[[k]], AppendTo[formulasAminusB, {i, j, k}]
];
If[i != 1,(*should be listofSequences[[
i]]\[NotEqual]1 I think but didn't work*)
If[listofSequences[[i]]*listofSequences[[j]] ==
listofSequences[[k]], AppendTo[formulasAtimesB, {i, j, k}]
]
];
If[listofSequences[[j]] != 0, (*this doesn't work for some reason*)

If[listofSequences[[i]]/listofSequences[[j]] ==
]
]
]
]
]

formulasAplusB
formulasAminusB
formulasAtimesB

formulasAplusBC = {};
formulasAminusBC = {};
formulasAtimesBC = {};
For[i = 1, i <= Length[listofSequences], i++,
For[j = i, j <= Length[listofSequences], j++,
For[k = 1, k <= Length[listofSequences], k++,
For[m = 1, m <= Length[listofSequences], m++,
If[listofSequences[[i]] +
listofSequences[[j]]*listofSequences[[k]] ==
listofSequences[[m]], AppendTo[formulasAplusBC, {i, j, k, m}]
];
If[listofSequences[[i]] -
listofSequences[[j]]*listofSequences[[k]] ==
listofSequences[[m]], AppendTo[formulasAminusBC, {i, j, k, m}]
];
If[i != 1,(*should be listofSequences[[
i]]\[NotEqual]1 I think but didn't work*)
If[listofSequences[[i]]*listofSequences[[j]]*
listofSequences[[k]] == listofSequences[[m]],
AppendTo[formulasAtimesBC, {i, j, k, m}]
]
];
If[listofSequences[[j]] != 0 , (*tried to add && listofSequences[[
k]]\[NotEqual]1 but didn't work*)
If[(listofSequences[[i]]/listofSequences[[j]])*
listofSequences[[k]] == listofSequences[[m]],
]
];
If[listofSequences[[j]] != 0, (*tried to add && listofSequences[[
k]]\[NotEqual]1 but didn't work*)
If[listofSequences[[
i]]/(listofSequences[[j]]*listofSequences[[k]]) ==
listofSequences[[m]], AppendTo[formulasAdivideBC2, {i, j, k, m}]
]
]
]
]
]
]

formulasAplusBC
formulasAminusBC
formulasAtimesBC



For the input lists ie. a,b,c,d,e,f of equal length, how could a function be made that takes the set of input lists as well as a list of math operators, ie +,-,/,* and then checks many distinct algebraic formulas of the input lists to look for equality? To simplify that idea maybe just starting with two operators, ie +,- would be good, but ideally I would like to be able to use a function like this:

FindFormulas[{a,b,c,d,e,f}, {*,/,+,-}, u, v, w, x, y, z] := (*apply list of operators to input sequences and check for equality*)


That function could organize a,b,c,d,e,f into equations along with *,/,+,-.

u would specify the maximum number of terms that don't match, ie for a+b=1, for a and b being lists of length=10, if u=2, and a+b=1 8 times and a+b!=1 two times, then a+b=1 would still qualify as a formula. So after finding u=3 terms that don't match that formula would not need to be checked further.

v would specify the +- offset shift to apply to the input sequences. Ie. for v=0, the tested formulas would be for list positions of the same index only. This could be optional, as instead the input sequences could be manually offset.

w would specify how many times {a,b,c,d,e,f} can each occur in the equation.

x would specify how many of {a,b,c,d,e,f} can be used in each given equation (ie equations of max x variables).

y would specify how many times {*,/,+,-} can each occur in the equation.

z would specify how many of {*,/,+,-} can be used in each equation (ie equations with max z operators).

So for this example:

FindFormulas[{a,b,c,d,e,f}, {*,/,+,-}, 0, 0, 1, 2, 1, 2]


That would limit the equations being checked to having x=2 distinct values from a,b,c,d,e,f with z=2 distinct operators. The values and operators would be distinct as w=1 and y=1. Since u=0 all terms would have to match.

So some of the formula that should be automatically tested for equality:

a+b=1
a-b=1
a-1=b
etc..


I think this would involve something like "supersets" or some automatic generation of distinct algebraic equations to then test, but I am not sure how to do it.

This is a similar problem (very large search space) as what deep learning is good at, so I think that would be good to have deep learning select the types of equations to test rather than test all permutations. Given a list of known equations in symbol form ie a=(b*c)/d, those could be used either with deep learning or with an algorithm which makes n number of changes to manually search "the space" around the equation, ie similar to this:

https://en.wikipedia.org/wiki/Levenshtein_distance

https://www.wolfram.com/language/11/neural-networks/

Also for a=(b*c)/d for example, when substituting in sequences into that formula, the sequences sum over n values could be compared to exclude certain sequences from being substituted for one or more of a,b,c,d etc. That should be done by deep learning as well to efficiently pre-filter where substitution would be more likely to give a formula.

cheers, Jamie

• Have you seen FindFormula? Commented Sep 1, 2019 at 20:23
• Hi, thanks for the suggestion I will try to see if that can work. Commented Sep 1, 2019 at 21:00
• en.wikipedia.org/wiki/Integer_sequence Commented Sep 11, 2019 at 19:58
• The word formula is a diminutive from Latin meaning "small form". In algebra, it refers to an expression that is syntactically minimal. A list is not exactly an integer sequence. One is a mathematical object with properties the other is a programming object they both obey a very different set of constraints. So when you multiply a list you are not manipulating a formula in a mathematical sense. Integer sequences are defined recursively so the 'formula' or definition will actually be made of two statements making syntactic manipulation meaningless under conventional rules. It happens to all. Commented Sep 11, 2019 at 20:05

Clear["Global*"]


Sequence A000040 can be easily found using FindSequenceFunction

A000040 = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41};

fA000040 = FindSequenceFunction[A000040]

(* Prime *)


Verifying,

A000040 == fA000040 /@ Range[Length@A000040]

(* True *)


Or, since Prime is Listable

A000040 == fA000040@Range[Length@A000040]

(* True *)
`
• Hi, I updated the original post. Commented Sep 2, 2019 at 18:12