Solving a system of 18 polynomial equations in sagemath

I'm trying to solve a system of 18 polynomial equations in sage. The system is for sure solvable since I already solved it in Maple and got ALL the possible solutions (only real solutions). In most cases I got between 10 to 25 solutions. But since Maple is not an open source I cannot really use it. I'm trying to solve the same equations in sage. but so far I did not succeed.

Since it's the first time I write here, I'm not allowed to attach the Maple and Sage code (two files) that I wanted to attach. Instead, I copied them bellow. It took Maple 25 minutes to solve the equations (in the code bellow). and it found 22 solutions to the equations (I wrote below all the 22 solutions that Maple found). I used the command 'Isolate' in Maple to solve the equations (this command is used for solving polynomial equations). Unfortunately I cannot know how the 'Isolate' command is implemented (I can use the command 'showstat' in Maple and see partial implementation of 'Isolate' since some of the commands that are used inside 'Isolate' are compiled). But I could see that 'Isolate' uses 'Groebner basis' in order to solve the equations. Therefore I tried to convert the 18 polynomial equations in sage to groebner basis but the command I.groebner_basis() never finishes (in the example below). Is there maybe another way of getting the groebner basis of the 18 equations? or any other way of solving the problem (I wrote below) so that the solution is for sure correct?

I'm attaching bellow both Maple's code (that succeeded to solve the equations) and Sage's code (that did not succeed). I'd appreciate any idea of how to solve the equations.

If it helps, here's the mathematical problem that I'm trying to solve: given a set of n 3D points P={p_1,p_2,...,p_n} and another set of n 3D lines H={h_1,h_2,...,h_n} (each line h_i is represented by a 3D point and a 3D unit vector). I'm trying to find the rotation matrix R=[r1,r2,r3;r4,r5,r6;r7,r8,r9] and a translation vector T=[t1,t2,t3] such that rotating the set P by R and then translating it by T will result in a new set of points PT={pt_1,...,pt_n} such that the sum of square distances between H and PT (sum_{i=1 to n}(dist(h_i,pt_i)^2)) will be minimal. So this is an optimization problem with constraints (the constraints are RR^T=I). so there are 12 variables in R and T. Using Lagrange Multipliers algorithm I added 6 more variables b1,...,b6 (the number of constraints from RR^T=I) and created a new function 'h' with 18 variables. the 18 equations are the derivation of 'h' by all the 18 variables (equal to zero). it is gurantee that one of the solutions to the 18 equations is the (global) minimum for R and T. but for that I have to find ALL the solutions to the equations (22 solutions in this example) just like Maple did.

Thanks

Here is Maple code: (and below sage's code)

restart;
g1:=r1^2+r4^2+r7^2-1;
g2:=r1*r2+r4*r5+r7*r8;
g3:=r1*r3+r4*r6+r7*r9;
g4:=r2^2+r5^2+r8^2-1;
g5:=r2*r3+r5*r6+r8*r9;
g6:=r3^2+r6^2+r9^2-1;
sum_sqr_distances:=(-34.5792590705286*r1+17.0635530183776*r4-2.30671047587914*r7+.533429751140582*t1-18.2777571201152+5.34368522421251*r2-2.6369060119417*r5+.356466130795291*r8-.0824332491501039*t2+31.8951297362284*r3-15.7390369840122*r6+2.12765778880161*r9-.492023587996135*t3)^2+(-63.880273658711*r2+31.5224925463221*r5-4.26132023642126*r8+.98543576110074*t2+5.20415366982094+5.34368522429473*r1-2.63690601164137*r4+.356466130730839*r7-.0824332491771907*t1+5.63520538121055*r3-2.78076015494726*r6+.375912834341308*r9-.0869303242748373*t3)^2+(-31.1892504431195*r3+15.3907123123387*r6-2.08057004842228*r9+.481134487803446*t3+16.460313265992+31.8951297380977*r1-15.7390369788429*r4+2.12765778852522*r7-.492023588007365*t1+5.63520538145412*r2-2.78076015435067*r5+.375912834360444*r8-.086930324248257*t2)^2+(-20.1477543311821*r1+7.55350991666248*r4+20.8920429846501*r7+.506802937949341*t1-13.5125935907312+7.82881106057577*r2-2.9350666574299*r5-8.1180192368411*r8-.19692837123503*t2+18.2686582928059*r3-6.84902591482382*r6-18.9435302828672*r9-.459535566231505*t3)^2+(-36.6286508786965*r2+13.7322935856179*r5+37.9817688885839*r8+.921368583909397*t2-34.3325081149272+7.82881105959312*r1-2.93506665641182*r4-8.11801923407865*r7-.196928371252735*t1+7.29448206284227*r3-2.7347436184352*r6-7.56395131161327*r9-.183487691946913*t3)^2+(-22.7328194787774*r3+8.52266582628087*r6+23.5726043680174*r9+.5718284781815*t3+29.2151845257836+18.2686582944502*r1-6.84902591329222*r4-18.9435302865599*r7-.459535566194367*t1+7.2944820644144*r2-2.73474361877224*r5-7.56395131566163*r8-.183487691915587*t2)^2+(-33.7370053449296*r1+38.9258336170637*r4-60.1132663033064*r7+.996042632734926*t1-4.98803179031169+1.08999592941726*r2-1.25763978603382*r5+1.94217639880877*r8-.0321807583045741*t2+1.8259306385537*r3-2.10676292990297*r6+3.25347948355056*r9-.0539083045951421*t3)^2+(-25.0073507347857*r2+28.8535382444551*r5-44.5585943124607*r8+.738310564652533*t2+4.93804814541239+1.08999592907818*r1-1.25763978578301*r4+1.94217639918338*r7-.0321807583046471*t1+14.8482131236429*r3-17.1319021236029*r6+26.4568411007238*r9-.438374809459876*t3)^2+(-8.9977349393474*r3+10.3816070715198*r6-16.0323428536159*r9+.265646802616713*t3-2.58161819993127+1.82593063830369*r1-2.1067629296129*r4+3.25347948341273*r7-.0539083045952243*t1+14.8482131262288*r2-17.1319021246606*r5+26.4568410945*r8-.438374809459549*t2)^2+(-56.6725654800191*r1-43.1813795970078*r4-58.3887310201578*r7+.980525398272198*t1+49.0916863573367+5.78296846451955*r2+4.40630407967054*r5+5.95808902028457*r8-.100054539766321*t2+5.50887455808305*r3+4.19745958942679*r6+5.67569496876523*r9-.0953122798368383*t3)^2+(-28.0870406673401*r2-21.400781038534*r5-28.937575861748*r8+.48595041543225*t2+19.4018945247715+5.78296846409823*r1+4.40630407900952*r4+5.95808902050728*r7-.100054539765808*t1+28.302910438969*r3+21.5652619383799*r6+29.1599826218892*r9-.489685305322089*t3)^2+(-30.836717169852*r3-23.4958833859599*r6-31.7705184032215*r9+.533524186319051*t3-30.3978529558191+5.50887455772671*r1+4.19745958933706*r4+5.67569496903033*r7-.0953122798304703*t1+28.3029104392002*r2+21.5652619411541*r5+29.1599826221612*r8-.489685305291881*t2)^2+(-57.8205382202822*r1-33.3924384768228*r4-34.894277849845*r7+.850839830317679*t1-12.5672620764049+10.7191476042258*r2+6.19050752309509*r5+6.46892827657879*r8-.157734223996209*t2+21.7070640341081*r3+12.5362340547815*r6+13.1000566054682*r9-.319423430626817*t3)^2+(-56.6217108878986*r2-32.7000933511969*r5-34.1707942023208*r8+.833198866184046*t2-1.62153141633832+10.7191476020505*r1+6.19050752434099*r4+6.46892827744991*r7-.15773422401843*t1+22.9548337765416*r3+13.2568443369017*r6+13.8530766468144*r9-.337784591359295*t3)^2+(-21.4717881919623*r3-12.4003578706288*r6-12.9580693345224*r9+.315961303486945*t3+6.66922254237138+21.7070640313443*r1+12.5362340557455*r4+13.1000566039334*r7-.319423430651098*t1+22.9548337782773*r2+13.2568443352531*r5+13.8530766433259*r8-.337784591337385*t2)^2+(-65.9377723150761*r1-12.678533244879*r4-65.0293030974106*r7+.955841723390729*t1+11.5835324790697+7.68982596884022*r2+1.47860188124137*r5+7.5838780437921*r8-.111472624096221*t2+11.9049207597142*r3+2.28908148248606*r6+11.7408986260292*r9-.17257513524552*t3)^2+(-49.571881779333*r2-9.53169524975009*r5-48.8888964859373*r8+.718599844159693*t2+14.0432100287845+7.6898259693682*r1+1.47860188123288*r4+7.58387804187672*r7-.111472624065637*t1+30.0526392395535*r3+5.77852985094098*r6+29.6385837317152*r9-.435646602436962*t3)^2+(-22.4583184276267*r3-4.31829173040524*r6-22.1488950108346*r9+.32555843242268*t3-12.0350031966363+11.904920759546*r1+2.28908148261245*r4+11.7408986234862*r7-.172575135204147*t1+30.0526392370654*r2+5.77852985129325*r5+29.6385837327811*r8-.435646602452044*t2)^2+(-40.2818933934206*r1+37.3415461911863*r4-17.5121421408269*r7+.688992135032061*t1+41.1079956272437+18.3480006638221*r2-17.0087018409058*r5+7.97660607993154*r8-.313829045441664*t2+19.8946971640516*r3-18.4424983689296*r6+8.64901659965967*r9-.340284150555745*t3)^2+(-39.9505168284587*r2+37.0343582140755*r5-17.3680795584234*r8+.68332418286889*t2-19.0229410779165+18.3480006624515*r1-17.0087018386759*r4+7.97660607742464*r7-.313829045473842*t1+20.0751637635565*r3-18.6097919416627*r6+8.72747261243189*r9-.343370898899277*t3)^2+(-36.6974975173012*r3+34.0187906543919*r6-15.9538626068613*r9+.627683682093741*t3-20.0272581058992+19.8946971612448*r1-18.4424983632605*r4+8.64901659883117*r7-.340284150571336*t1+20.0751637622239*r2-18.609791938382*r5+8.72747261433876*r8-.343370898879803*t2)^2+(-19.9003018252227*r1+2.10723968998899*r4-5.99083386660634*r7+.268355364500816*t1-6.36217996635187+32.4452671740533*r2-3.43562400998522*r5+9.76739986562233*r8-.437524092703596*t2+5.19806634264006*r3-.550422390906632*r6+1.56483817002714*r9-.0700958709468267*t3)^2+(-54.7542305404035*r2+5.79791647536792*r5-16.4833428943737*r8+.738360233327084*t2+12.3293109763825+32.4452671726755*r1-3.43562401018043*r4+9.76739986673756*r7-.437524092757061*t1+3.1084479408544*r3-.329153041695288*r6+.935774510511675*r9-.0419173883795401*t3)^2+(-73.6585215390464*r3+7.79968874305612*r6-22.1743353083965*r9+.99328440217389*t3-10.5500615738974+5.19806634229016*r1-.550422390946524*r4+1.5648381697327*r7-.0700958709446797*t1+3.10844794077716*r2-.329153041700441*r5+.935774510228754*r8-.041917388373134*t2)^2;
h:=sum_sqr_distances+g1*b1+g2*b2+g3*b3+g4*b4+g5*b5+g6*b6;
diff_t1:=diff(h,t1);
diff_t2:=diff(h,t2);
diff_t3:=diff(h,t3);
diff_r1:=diff(h,r1);
diff_r2:=diff(h,r2);
diff_r3:=diff(h,r3);
diff_r4:=diff(h,r4);
diff_r5:=diff(h,r5);
diff_r6:=diff(h,r6);
diff_r7:=diff(h,r7);
diff_r8:=diff(h,r8);
diff_r9:=diff(h,r9);
diff_b1:=diff(h,b1);
diff_b2:=diff(h,b2);
diff_b3:=diff(h,b3);
diff_b4:=diff(h,b4);
diff_b5:=diff(h,b5);
diff_b6:=diff(h,b6);
vars := [op(indets(h, And(name, Non(constant))))];
polysys:={diff_t1,diff_t2,diff_t3,diff_r1,diff_r4,diff_r7,diff_r2,diff_r5,diff_r8,diff_r3,diff_r6,diff_r9,diff_b1,diff_b2,diff_b3,diff_b4,diff_b5,diff_b6};
sols := CodeTools:-Usage(RootFinding:-Isolate(polysys, vars, output = numeric, method = RS));


And this is sage code (that couldn't find the groebner basis):

P.<r1,r2,r3,r4,r5,r6,r7,r8,r9,t1,t2,t3,b1,b2,b3,b4,b5,b6>=PolynomialRing(QQ,order='degrevlex')
g1=r1^2+r4^2+r7^2-1
g2=r1*r2+r4*r5+r7*r8
g3=r1*r3+r4*r6+r7*r9
g4=r2^2+r5^2+r8^2-1
g5=r2*r3+r5*r6+r8*r9
g6=r3^2+r6^2+r9^2-1
sum_sqr_distances=(-34.5792590705286*r1+17.0635530183776*r4-2.30671047587914*r7+.533429751140582*t1-18.2777571201152+5.34368522421251*r2-2.6369060119417*r5+.356466130795291*r8-.0824332491501039*t2+31.8951297362284*r3-15.7390369840122*r6+2.12765778880161*r9-.492023587996135*t3)^2+(-63.880273658711*r2+31.5224925463221*r5-4.26132023642126*r8+.98543576110074*t2+5.20415366982094+5.34368522429473*r1-2.63690601164137*r4+.356466130730839*r7-.0824332491771907*t1+5.63520538121055*r3-2.78076015494726*r6+.375912834341308*r9-.0869303242748373*t3)^2+(-31.1892504431195*r3+15.3907123123387*r6-2.08057004842228*r9+.481134487803446*t3+16.460313265992+31.8951297380977*r1-15.7390369788429*r4+2.12765778852522*r7-.492023588007365*t1+5.63520538145412*r2-2.78076015435067*r5+.375912834360444*r8-.086930324248257*t2)^2+(-20.1477543311821*r1+7.55350991666248*r4+20.8920429846501*r7+.506802937949341*t1-13.5125935907312+7.82881106057577*r2-2.9350666574299*r5-8.1180192368411*r8-.19692837123503*t2+18.2686582928059*r3-6.84902591482382*r6-18.9435302828672*r9-.459535566231505*t3)^2+(-36.6286508786965*r2+13.7322935856179*r5+37.9817688885839*r8+.921368583909397*t2-34.3325081149272+7.82881105959312*r1-2.93506665641182*r4-8.11801923407865*r7-.196928371252735*t1+7.29448206284227*r3-2.7347436184352*r6-7.56395131161327*r9-.183487691946913*t3)^2+(-22.7328194787774*r3+8.52266582628087*r6+23.5726043680174*r9+.5718284781815*t3+29.2151845257836+18.2686582944502*r1-6.84902591329222*r4-18.9435302865599*r7-.459535566194367*t1+7.2944820644144*r2-2.73474361877224*r5-7.56395131566163*r8-.183487691915587*t2)^2+(-33.7370053449296*r1+38.9258336170637*r4-60.1132663033064*r7+.996042632734926*t1-4.98803179031169+1.08999592941726*r2-1.25763978603382*r5+1.94217639880877*r8-.0321807583045741*t2+1.8259306385537*r3-2.10676292990297*r6+3.25347948355056*r9-.0539083045951421*t3)^2+(-25.0073507347857*r2+28.8535382444551*r5-44.5585943124607*r8+.738310564652533*t2+4.93804814541239+1.08999592907818*r1-1.25763978578301*r4+1.94217639918338*r7-.0321807583046471*t1+14.8482131236429*r3-17.1319021236029*r6+26.4568411007238*r9-.438374809459876*t3)^2+(-8.9977349393474*r3+10.3816070715198*r6-16.0323428536159*r9+.265646802616713*t3-2.58161819993127+1.82593063830369*r1-2.1067629296129*r4+3.25347948341273*r7-.0539083045952243*t1+14.8482131262288*r2-17.1319021246606*r5+26.4568410945*r8-.438374809459549*t2)^2+(-56.6725654800191*r1-43.1813795970078*r4-58.3887310201578*r7+.980525398272198*t1+49.0916863573367+5.78296846451955*r2+4.40630407967054*r5+5.95808902028457*r8-.100054539766321*t2+5.50887455808305*r3+4.19745958942679*r6+5.67569496876523*r9-.0953122798368383*t3)^2+(-28.0870406673401*r2-21.400781038534*r5-28.937575861748*r8+.48595041543225*t2+19.4018945247715+5.78296846409823*r1+4.40630407900952*r4+5.95808902050728*r7-.100054539765808*t1+28.302910438969*r3+21.5652619383799*r6+29.1599826218892*r9-.489685305322089*t3)^2+(-30.836717169852*r3-23.4958833859599*r6-31.7705184032215*r9+.533524186319051*t3-30.3978529558191+5.50887455772671*r1+4.19745958933706*r4+5.67569496903033*r7-.0953122798304703*t1+28.3029104392002*r2+21.5652619411541*r5+29.1599826221612*r8-.489685305291881*t2)^2+(-57.8205382202822*r1-33.3924384768228*r4-34.894277849845*r7+.850839830317679*t1-12.5672620764049+10.7191476042258*r2+6.19050752309509*r5+6.46892827657879*r8-.157734223996209*t2+21.7070640341081*r3+12.5362340547815*r6+13.1000566054682*r9-.319423430626817*t3)^2+(-56.6217108878986*r2-32.7000933511969*r5-34.1707942023208*r8+.833198866184046*t2-1.62153141633832+10.7191476020505*r1+6.19050752434099*r4+6.46892827744991*r7-.15773422401843*t1+22.9548337765416*r3+13.2568443369017*r6+13.8530766468144*r9-.337784591359295*t3)^2+(-21.4717881919623*r3-12.4003578706288*r6-12.9580693345224*r9+.315961303486945*t3+6.66922254237138+21.7070640313443*r1+12.5362340557455*r4+13.1000566039334*r7-.319423430651098*t1+22.9548337782773*r2+13.2568443352531*r5+13.8530766433259*r8-.337784591337385*t2)^2+(-65.9377723150761*r1-12.678533244879*r4-65.0293030974106*r7+.955841723390729*t1+11.5835324790697+7.68982596884022*r2+1.47860188124137*r5+7.5838780437921*r8-.111472624096221*t2+11.9049207597142*r3+2.28908148248606*r6+11.7408986260292*r9-.17257513524552*t3)^2+(-49.571881779333*r2-9.53169524975009*r5-48.8888964859373*r8+.718599844159693*t2+14.0432100287845+7.6898259693682*r1+1.47860188123288*r4+7.58387804187672*r7-.111472624065637*t1+30.0526392395535*r3+5.77852985094098*r6+29.6385837317152*r9-.435646602436962*t3)^2+(-22.4583184276267*r3-4.31829173040524*r6-22.1488950108346*r9+.32555843242268*t3-12.0350031966363+11.904920759546*r1+2.28908148261245*r4+11.7408986234862*r7-.172575135204147*t1+30.0526392370654*r2+5.77852985129325*r5+29.6385837327811*r8-.435646602452044*t2)^2+(-40.2818933934206*r1+37.3415461911863*r4-17.5121421408269*r7+.688992135032061*t1+41.1079956272437+18.3480006638221*r2-17.0087018409058*r5+7.97660607993154*r8-.313829045441664*t2+19.8946971640516*r3-18.4424983689296*r6+8.64901659965967*r9-.340284150555745*t3)^2+(-39.9505168284587*r2+37.0343582140755*r5-17.3680795584234*r8+.68332418286889*t2-19.0229410779165+18.3480006624515*r1-17.0087018386759*r4+7.97660607742464*r7-.313829045473842*t1+20.0751637635565*r3-18.6097919416627*r6+8.72747261243189*r9-.343370898899277*t3)^2+(-36.6974975173012*r3+34.0187906543919*r6-15.9538626068613*r9+.627683682093741*t3-20.0272581058992+19.8946971612448*r1-18.4424983632605*r4+8.64901659883117*r7-.340284150571336*t1+20.0751637622239*r2-18.609791938382*r5+8.72747261433876*r8-.343370898879803*t2)^2+(-19.9003018252227*r1+2.10723968998899*r4-5.99083386660634*r7+.268355364500816*t1-6.36217996635187+32.4452671740533*r2-3.43562400998522*r5+9.76739986562233*r8-.437524092703596*t2+5.19806634264006*r3-.550422390906632*r6+1.56483817002714*r9-.0700958709468267*t3)^2+(-54.7542305404035*r2+5.79791647536792*r5-16.4833428943737*r8+.738360233327084*t2+12.3293109763825+32.4452671726755*r1-3.43562401018043*r4+9.76739986673756*r7-.437524092757061*t1+3.1084479408544*r3-.329153041695288*r6+.935774510511675*r9-.0419173883795401*t3)^2+(-73.6585215390464*r3+7.79968874305612*r6-22.1743353083965*r9+.99328440217389*t3-10.5500615738974+5.19806634229016*r1-.550422390946524*r4+1.5648381697327*r7-.0700958709446797*t1+3.10844794077716*r2-.329153041700441*r5+.935774510228754*r8-.041917388373134*t2)^2
sum_sqr_distances=P(sum_sqr_distances)
h=sum_sqr_distances+g1*b1+g2*b2+g3*b3+g4*b4+g5*b5+g6*b6
diff_t1=diff(h,t1)
diff_t2=diff(h,t2)
diff_t3=diff(h,t3)
diff_r1=diff(h,r1)
diff_r2=diff(h,r2)
diff_r3=diff(h,r3)
diff_r4=diff(h,r4)
diff_r5=diff(h,r5)
diff_r6=diff(h,r6)
diff_r7=diff(h,r7)
diff_r8=diff(h,r8)
diff_r9=diff(h,r9)
diff_b1=diff(h,b1)
diff_b2=diff(h,b2)
diff_b3=diff(h,b3)
diff_b4=diff(h,b4)
diff_b5=diff(h,b5)
diff_b6=diff(h,b6)
I=Ideal(diff_t1,diff_t2,diff_t3,diff_r1,diff_r2,diff_r3,diff_r4,diff_r5,diff_r6,diff_r7,diff_r8,diff_r9,diff_b1,diff_b2,diff_b3,diff_b4,diff_b5,diff_b6)
I.groebner_basis()
I.variety(RR)


And these are the 22 solutions the Maple found (all the real solutions that solve the equations): The goal is to get the same solutions from sage.

[[b1 = -6405.651236, b2 = 1097.011411, b3 = 6432.603484, b4 = -3486.767199, b5 = 2786.505511, b6 = -2066.461540, r1 = -.2735272365, r2 = -.4584555697, r3 = -.8455775195, r4 = .9594115168, r5 = -0.6729917007e-1, r6 = -.2738619418, r7 = -0.6864686727e-1, r8 = .8861655107, r9 = -.4582557095, t1 = -31.53181188, t2 = -3.035192389, t3 = -64.33835896],

[b1 = -663.0587184, b2 = 1206.645590, b3 = -935.8274112, b4 = -2827.613858, b5 = 1260.996624, b6 = -676.9562322, r1 = .8750945364, r2 = -.1796187040, r3 = -.4493847723, r4 = -.4474525861, r5 = -.6540696330, r6 = -.6099008922, r7 = -.1843793253, r8 = .7347993170, r9 = -.6527436159, t1 = 24.66279957, t2 = 6.035593829, t3 = -55.14919482],

[b1 = -5334.007938, b2 = -147.4788994, b3 = 6381.507728, b4 = -1654.278431, b5 = 3038.269718, b6 = -2677.888758, r1 = 0.1140465611e-1, r2 = -.8980265159, r3 = -.4397934863, r4 = .8207951804, r5 = .2596099997, r6 = -.5088201253, r7 = -.5711087512, r8 = .3551774554, r9 = -.7400565989, t1 = -38.50311082, t2 = -47.94244185, t3 = -52.00642291],

[b1 = -3711.964527, b2 = 3878.643381, b3 = -871.0350173, b4 = -4720.758037, b5 = 5739.216423, b6 = -3328.445679, r1 = -.3452025304, r2 = -.5900255619, r3 = -.7298664599, r4 = -.5720856277, r5 = .7487785844, r6 = -.3347367116, r7 = .7440115910, r8 = .3019941520, r9 = -.5960254060, t1 = 4.420063381, t2 = -25.83338983, t3 = -49.39760950],

[b1 = -6771.196603, b2 = 3126.930183, b3 = 3836.296676, b4 = -2119.174006, b5 = -1053.266216, b6 = -647.0603393, r1 = -0.5288779601e-1, r2 = .2948075346, r3 = -.9540919235, r4 = .9579998211, r5 = -.2546859938, r6 = -.1318005592, r7 = .2818496477, r8 = .9209905331, r9 = .2689557845, t1 = -1.568329794, t2 = 41.81946440, t3 = -47.91552928],

[b1 = -426.4877331, b2 = 1777.234977, b3 = -1396.594665, b4 = -4704.976941, b5 = 6548.202362, b6 = -2797.527674, r1 = .6772160397, r2 = -.2551001296, r3 = -.6901466217, r4 = -.3808728417, r5 = .6809888166, r6 = -.6254519247, r7 = .6295349982, r8 = .6864241804, r9 = .3640158382, t1 = 51.90734298, t2 = -10.61796786, t3 = -36.65155778],

[b1 = -8345.957097, b2 = -5992.141964, b3 = 9771.580880, b4 = -9281.942970, b5 = 14067.10170, b6 = -7238.069438, r1 = -.4112595863, r2 = -.5902847582, r3 = -.6945714196, r4 = -.9059223617, r5 = .1803855392, r6 = .3831001589, r7 = .1008475446, r8 = -.7867813937, r9 = .6089374444, t1 = -25.97531493, t2 = -66.23689116, t3 = -31.46159720],

[b1 = -5343.147703, b2 = 183.2763579, b3 = 5426.240402, b4 = -11788.39198, b5 = 16609.81042, b6 = -7181.846374, r1 = -.2988639430, r2 = -.6827291572, r3 = -.6667542587, r4 = .7307518828, r5 = -.6130817579, r6 = .3002206588, r7 = -.6137442703, r8 = -.3975068000, r9 = .6821336486, t1 = -51.64655336, t2 = -55.45375783, t3 = -29.08482105],

[b1 = -4075.023103, b2 = 6883.346857, b3 = -1945.068213, b4 = -3311.752332, b5 = 3039.918275, b6 = -921.4062369, r1 = .5825663050, r2 = .8122102291, r3 = 0.3051301418e-1, r4 = -.8079724338, r5 = .5827884450, r6 = -0.8682266235e-1, r7 = 0.8830088656e-1, r8 = -0.2592628327e-1, r9 = -.9957563865, t1 = 23.77615250, t2 = 40.91304243, t3 = -28.03945694],

[b1 = -6187.757714, b2 = 838.7708899, b3 = 6066.514065, b4 = -441.1250637, b5 = -851.5589307, b6 = -1128.553632, r1 = .2065219306, r2 = .9631666887, r3 = -.1722167877, r4 = .8113374284, r5 = -.2669555392, r6 = -.5200637629, r7 = -.5468823178, r8 = -0.3232135326e-1, r9 = -.8365853576, t1 = -21.72396020, t2 = 62.90274148, t3 = -22.56105906],

[b1 = -3971.638517, b2 = 5211.591913, b3 = -2909.389068, b4 = -3415.632999, b5 = 2348.040874, b6 = -1624.438321, r1 = -.6376325216, r2 = -.7577247398, r3 = -.1388451874, r4 = -.6573617358, r5 = .6291742407, r6 = -.4147473004, r7 = .4016221056, r8 = -.1731848536, r9 = -.8992812078, t1 = -24.08083201, t2 = -42.77528618, t3 = -16.88667732],

[b1 = -1107.397052, b2 = -1352.354473, b3 = 559.8732630, b4 = -682.7595891, b5 = 1919.821403, b6 = -459.8284277, r1 = -.5540008534, r2 = .8147846552, r3 = -.1709064659, r4 = .3838720628, r5 = .4321713781, r6 = .8160086638, r7 = .7387322206, r8 = .3864632785, r9 = -.5521963786, t1 = -3.462811975, t2 = 66.31134317, t3 = -11.39008932],

[b1 = -1858.210974, b2 = -1443.942073, b3 = -117.7029385, b4 = -541.5565807, b5 = 635.7869277, b6 = -1292.459322, r1 = -.6056473654, r2 = .7430910328, r3 = -.2846172619, r4 = -.4570833521, r5 = -.6176622647, r6 = -.6399751058, r7 = .6513571049, r8 = .2575054246, r9 = -.7137400635, t1 = -8.170594439, t2 = 73.18220544, t3 = -5.574473809],

[b1 = -2879.955409, b2 = -7247.457464, b3 = 7603.360417, b4 = -10386.60081, b5 = 15680.46439, b6 = -7326.146084, r1 = .8898800024, r2 = -.3777475308, r3 = .2557740885, r4 = -.2159488982, r5 = .1450669474, r6 = .9655680474, r7 = -.4018453119, r8 = -.9144738289, r9 = 0.4751801242e-1, t1 = 25.17284844, t2 = -56.81452504, t3 = 4.483386705],

[b1 = -2594.500775, b2 = -8451.746216, b3 = 8378.142403, b4 = -8445.314669, b5 = 16539.21636, b6 = -7726.257147, r1 = -.8887915121, r2 = .4283658935, r3 = .1629487933, r4 = .2014992422, r5 = 0.4589445400e-1, r6 = .9784128753, r7 = -.4116402597, r8 = -.9024391172, r9 = .1271060041, t1 = -72.41708628, t2 = -1.180372243, t3 = 11.62696253],

[b1 = -3386.721976, b2 = -9232.755155, b3 = 8735.844228, b4 = -8449.692294, b5 = 14675.00399, b6 = -7470.241638, r1 = .7020126763, r2 = -.7115667558, r3 = -0.2917112402e-1, r4 = -.6916841933, r5 = -.6714995329, r6 = -.2658220344, r7 = -.1695617265, r8 = -.2067876432, r9 = .9635806617, t1 = 22.56779868, t2 = -57.27997094, t3 = 12.66120812],

[b1 = -2344.035915, b2 = 3947.708934, b3 = -879.5603548, b4 = -4851.200663, b5 = 7270.443175, b6 = -2742.299953, r1 = .4417879292, r2 = .7119951524, r3 = .5457896376, r4 = -.5754568251, r5 = .6916351055, r6 = -.4364519713, r7 = .6882389614, r8 = .1212591594, r9 = -.7152785110, t1 = 49.50818048, t2 = 50.77308450, t3 = 32.05737927],

[b1 = -4793.592445, b2 = -9508.057512, b3 = 9867.840732, b4 = -7363.405470, b5 = 13671.66420, b6 = -8641.244153, r1 = -.8607833310, r2 = .4979577238, r3 = .1053098401, r4 = -.5071531704, r5 = -.8216734210, r6 = -.2600931582, r7 = -0.4298510042e-1, r8 = -.2772920743, r9 = .9598236227, t1 = -55.37291300, t2 = 22.92886207, t3 = 35.86152727],

[b1 = -1143.596369, b2 = 1527.374908, b3 = 1286.733075, b4 = -1246.223196, b5 = 880.0474364, b6 = -176.7812153, r1 = .5096005566, r2 = -.5301666308, r3 = .6776655638, r4 = -0.1872847237e-1, r5 = .7805852008, r6 = .6247687481, r7 = .8602072524, r8 = .3310741426, r9 = -.3878574417, t1 = 62.72704338, t2 = -19.19220727, t3 = 40.08281887],

[b1 = -6277.680746, b2 = -547.8928701, b3 = 6669.122409, b4 = -11168.08424, b5 = 15793.41027, b6 = -8033.605502, r1 = .4599469977, r2 = .3665077232, r3 = .8087773786, r4 = .5464600340, r5 = -.8347594860, r6 = 0.6751319714e-1, r7 = -.6998786970, r8 = -.4109120215, r9 = .5842269422, t1 = -10.38583601, t2 = 10.41107518, t3 = 61.92902662],

[b1 = -9151.429703, b2 = -6008.117168, b3 = 11049.83952, b4 = -7190.606039, b5 = 13545.27447, b6 = -7223.768017, r1 = 0.7425420274e-1, r2 = .5809660735, r3 = .8105336112, r4 = -.9944330906, r5 = .1040687725, r6 = 0.1650814969e-1, r7 = -0.7476056307e-1, r8 = -.8072472434, r9 = .5854594317, t1 = -4.663325049, t2 = 4.554915592, t3 = 62.58462359],

[b1 = -1226.728760, b2 = 1147.011945, b3 = -400.7753802, b4 = -4507.321778, b5 = 8005.881456, b6 = -3241.483736, r1 = -0.9032875350e-2, r2 = .7488743127, r3 = .6626504893, r4 = -.2759411564, r5 = .6350798638, r6 = -.7214776814, r7 = .9611320853, r8 = .1893695603, r9 = -.2009086466, t1 = 40.46849908, t2 = 60.56033489, t3 = 65.08406719]]

edit retag close merge delete

Please format the (sage) code so that it can be copied and pasted without effort and without errors. To "markdown" the code as code, mark it after pasting it, then either press Control+K (as i did here, in line) or alternatively press the button with 101 and 010 , while the text is marked again.

Please insert explicitly the multiplication sign.

The ring P is the following one?!

J = [1,2,3]
names = ( [ 'b1__%s_%s' % (k,n) for k in J for n in J if k <= n ] +
[ 'r1__%s_%s' % (k,n) for k in J for n in J           ] +
[ 't1%s'      %  k    for k in J                      ] )
P = PolynomialRing( QQ, order='degrevlex', names=names )


(Just print names and print P to get the information on the two objects.)

( 2017-12-07 18:54:25 -0600 )edit

Sorry I didn't notice that it didn't copy the sage code properly (I could see the correct code in the edit mode but on the preview mode the P ring was not defined properly). Anyway, I fixed it and used the ctrl+k as you said. I don't see any problem with multiplication signs (maybe that was again only in the preview mode before I pressed the ctrl+k). you can just copy the code as is, save it in as a sage file and then load the file in sagemath. it works only until the command I.groebner_basis().

( 2017-12-07 19:25:12 -0600 )edit

Welcome to Ask Sage, thanks for asking a question and for editing it to get the formatting right!

Ideally, could you simplify the example while still illustrating the problem?

( 2017-12-08 09:23:42 -0600 )edit

I'm not sure what you meant by simplifying the example. All I did in the code examples (in both maple and sage) was to define the 18 polynomial equations and then calling the commands that solve them (solved successfully in Maple but not in sage). Let me know what you meant and I'll change my post accordingly.

( 2017-12-08 09:57:04 -0600 )edit

Is there a way to illustrate the same problem with less variables? With simpler values of coefficients? Maybe use simpler variable names? Just to make it easier to play with the example. See http://www.sscce.org/ or https://stackoverflow.com/help/mcve for more on this idea.

( 2017-12-09 01:02:00 -0600 )edit

Sort by » oldest newest most voted

First, it makes sense that you will get the coinstant polynomial 1.0 as the only element of the Groebner basis since, as the polynomial sum_sqr_distances has coefficients in the inexact ring RR, it is likely that the given polynomials generate the whole polynomial ring.

Indeed, when you add a polynomial with coefifients in RR with polynomials with coefficients in QQ, the result will belong to a polynomial ring with coefficients in RR. You can check it by typing:

sage: I
..... over Real Field with 53 bits of precision


You can replace QQ with RDF in the definition of the polynomial ring. Then the coercion will be done towards RDF which consist of low-level floating-point numbers, hence the computation will finish, while it might take longer with RR.

However, i guess that having [1.0] as the only element of the Groebner basis due to working in an inexact ring is quite unsatisfactory.

So, if you want to work on an exact ring, since the name sum_sqr_distances seems to indicate that the coefficients are quadratic numbers, you should define them either in QQbar or in some number field. It is likely that the computation of a Groebner basis will be even slower.

Of course, you can convert sum_sqr_distances into a polynomial with rational coefficients as follows:

sage: sum_sqr_distances = P(sum_sqr_distances)


But regarding the "sqr" name of the polynomial, it is likely not to be the way to go.

Now, regarding your initial problem, perhaps should you forget about polynomial equations, instead, look at the optimization features of Sage, in particular, you can have a look at:

sage: minimize?


You can also have a look at this question

more

I tried to replace QQ with both RDF and RR. with both ways I still got a single groebner basis=1.0. Define what in QQbar? I'm not sure I understand

( 2017-12-10 10:19:20 -0600 )edit

Since your inexact polynomial is made of square roots (i guess of integers, but i do not have the complete input of your problem), i was suggesting to work in the (exact) field of algrbraic numbers QQbar.

I edited my answer to let you have a look towards optimization since you might actually not be interested in algebraic stuff.

( 2017-12-10 10:23:28 -0600 )edit

Is there a way to replace the expressions to be with rational coefficients?

( 2017-12-10 10:24:43 -0600 )edit
1

Yes, as i explained at the end of my answer:

sage: sum_sqr_distances = P(sum_sqr_distances)

( 2017-12-10 10:26:36 -0600 )edit

Thanks. I didn't notice that. so my code now is exactly the same as in the original question (still defined P with QQ). just added after the definition of sum_sqr_distances the line: "sum_sqr_distances=P(sum_sqr_distances)". Now the command I.groebner_basis() is running for almost 2 hours (didn't return [1.0] this time). but I'm not sure it will ever finish..

( 2017-12-10 13:14:10 -0600 )edit

The complete input of my problem is just n random points and n random lines. each line consists of a random point and a random unit vector. the random points (and also the points on the lines) are random real numbers (no square roots). but since the vectors are unit vectors, I divide a random vector by its size so obviously I use square root to define a random unit vector ((vx,vy,vz)/sqrt(vx^2+vy^2+vz^2)). Why should I forget about polynomial equations? it worked in Maple. can you tell me which function you were talking about in the link you sent? because I tried many optimization functions in Maple and none of them guranteed to return the global minimum. finding all the solutions of the polynomial equations guarantees that (and that was the only way I could solve the problem in Maple).

( 2017-12-10 13:19:54 -0600 )edit

I updated the original question with the updated code (just changed sum_sqr_distances to be rational). Unfortunately it seems that I.groebner_basis() is not finishing. Is there any other way that I can try to calculate the groebner basis of the 18 equations? about the link that you gave me for optimizations, it seems that I need to give some guesses to the function so it will look for the local minimum around these values (or interval in another function). This is definitely not what I want. I need a global minimum for the problem that is guarantees to be the global minimum (with no guesses).

( 2017-12-10 16:13:06 -0600 )edit

If you want the Groebner basis over QQ, you can try different proposed algorithms, see:

sage: I.groebner_basis?


You will see a list of various algorithms to be tested, for example, you can try:

sage: I.groebner_basis(algorithm='giac:gbasis')


You can also try to change the monomial order degrevlex to something else, see:

sage: PolynomialRing?

( 2017-12-11 04:31:27 -0600 )edit

I already tried a few different algorithms of groebner. I tried ‘singular:groebner’, ‘singular:std’, ‘singular:stdhilb’, ‘singular:stdfglm’ and some more from this link: http://doc.sagemath.org/html/en/refer.... None of them worked. They all never finished. for the specific algorithm you wrote 'giac:gbasis' I couldn't run. I got this error: "One of the optional packages giac or giacpy_sage is missing". I don't know how to install the missing package. I also tried 'lex' instead of 'degrevlex'. also didn't work. Is there any other idea? perhaps not using QQ? it doesn't matter for me if it's rational numbers or real numbers. whatever works.

( 2017-12-11 04:51:08 -0600 )edit

Regarding giacpy_sage, you can do, from within a shell:

sage -i giacpy_sage

( 2017-12-11 08:02:40 -0600 )edit

Also, you may try to multiply each polynomial by the lcm of the denominators of its coefficients, and convert everything in a polynomial ring defined over ZZ, maybe some algorithms only work in that context.

( 2017-12-11 08:04:07 -0600 )edit

Do you mean that I should make the coefficients integer numbers? doesn't it mean that it will find only the integer solutions (which most likely means empty set)? if some groebner algorithms work only with ZZ shouldn't I have gotten an error message? If it can find real solutions with ZZ ring, can you show me how to convert the expression to expression with integer coefficients? I'm very new with sagemath so I don't know how to collect all the denominators of the coefficients of an expression so I can compute their LCM. Thanks.

( 2017-12-11 08:29:26 -0600 )edit