/* Pi Data from https://github.com/celinehocquette/magicpopper/blob/main/magicpopper/examples/magic-pi/exs.pl which has the following solution """ f(A,B):- square(A,D),mult(D,3.142,B). """ (MagicPopper recovers both the formula as well as the constant 3.142.) * Using math.pi as constant [program = X * (X * 3.141592653589793),res = 3.141592653589793,count = 9] [program = X * (3.141592653589793 * X),res = 3.141592653589793,count = 9] * Without math.pi as constant [program = (X / -2.112341463618139 + X) * 5.968800669521466 * X,res = 3.143120838715247,count = 1] Another run [program = X - (X * -7.30000000000001 / (2.899999999999983 / X) + X) + X * X / 1.599999999999982,res = 3.142241379310371,count = 1] [program = (X / -9.200000000000003 - X * 9.199999999999966) * X * ((3.099999999999983 - 2.899999999999983 + 2.499999999999982) / -8.000000000000007),res = 3.141684782608661,count = 1] This simplifies to 2 Out[1]= 3.14168 X This solution is a little strange: [program = (8.232947158735687 - (X / 8.232947158735687 + X / X + X)) / -4.444505783936244 + (-4.444505783936244 + (5.36459189623808 - (X - X))) + X * X * ((-3.29554488570222 + -3.29554488570222) / -2.112341463618139),res = 2.665297858597132,count = 1] This simplifies to 2 Out[2]= 0.920086 - 0.224997 (7.23295 - 1.12146 X) + 3.12028 X Using only integer 1..10 + Pi (In general integer seems to be better than than using random floats for these kind of problem.) [program = (X + (X - X)) * (3.14159 * X),res = 3.14159,count = 7] [program = X * (3.14159 * X),res = 3.14159,count = 7] [program = X * X * 3.14159,res = 3.14159,count = 6] [program = 3.14159 * X * X,res = 3.14159,count = 6] */ import util. data(puzzle2,Data,Vars,Unknown,Ops,Constants,MaxSize,Params) :- Data = [ [[X], Y] : [X,Y] in chunks_of([ 3.974,49.621, 6.068,115.69, 7.524,177.87, 3.633,41.47, 6.478,131.852, 7.068,156.964, 6.98,153.079, 7.384,171.313, 4.068,51.996, 4.093,52.637 ],2)], % Checking the data % foreach([[X],Y] in Data) % Z = X*X*math.pi, % Diff = Y-Z, % println([x=X,y=Y,z=Z,diff=Diff]) % end, Ops = [+,/,*,-,pow2,pow3,pow4], Constants = [math.pi] ++ [frand(-10,10) : _ in 1..10], % Constants = [frand(0,10) : _ in 1..10], % without Pi % Constants = 1..10, % ++ [math.pi], Unknown = [1], Vars = ['X'], MaxSize = 11, Params = new_map([ total_approx=0.15, remove_dups=true % stop_criteria=generations, % num_gens=1800 ]).