0
$\begingroup$

For instance,

qq = FindIntegerNullVector[{-9169.\
4529910449317529836685049212402940180640301948607925084807104675274205\
5034435184341092392543267646373701515968690891229074851663678405807145\
17622686786232514867447817140964`142., 1, EulerGamma, Pi^2, Log[2], 
Log[3]}]

gives

{-15044151968404805667153532191301833940133467621984038322223374816777\
2631007211100415129341007449731149059410554213978135216603240705107570\
58969, 0, 0, \
-139769172763599387675364620092226606423643480124197140593288493451413\
4179078124750307338440232001550774823705698830319337392850837300787936\
4436992, 0, 0}

which is the "wrong" answer.

On the other hand,

qq = FindIntegerNullVector[{-9169.\
4529910449317529836685049212402940180640301948607925084807104675274205\
5034435184341092392543267646373701515968690891229074851663678405807145\
17622686786232514867447817140964`142., 1, Pi^2, Log[2], Log[3], 
EulerGamma}]

gives

{-633004359680000, -5919486889313637261, 43840739895598800, \
-134027404823687760, -134027404823687760, -134027404823687760}

which is the answer I'm looking for.

Is there any way to force Mathematica to give me the second answer, regardless of the order of the input? I tried the extra "norm" argument, but it didn't do anything (just told me Mathematica couldn't find an answer for the first ordering).

$\endgroup$
4
  • 1
    $\begingroup$ Check the examples in the doc page of LatticeReduce, especially under applications. With that function you can get more than one solution. FindIntegerNullVector also calls LatticeReduce. $\endgroup$
    – Szabolcs
    May 14, 2017 at 18:57
  • 1
    $\begingroup$ Actually FindIntegerNullVector uses PSLQ rather than LatticeReduce. $\endgroup$ May 15, 2017 at 17:48
  • $\begingroup$ I'm voting to close this question as off-topic because it is too localized; i.e, it applies only to the local situation and needs of its poster. Answers will not benefit others. $\endgroup$
    – m_goldberg
    Sep 23, 2018 at 23:24
  • $\begingroup$ I'm voting to close this question as off-topic because there is no point in talking about "wrong" solutions as FindIntegerNullVector is supposed to return only one of many solutions. $\endgroup$ Sep 25, 2018 at 7:03

1 Answer 1

1
$\begingroup$

Using SortBy on the argument works in this case.

list = {-9169.\
452991044931752983668504921240294018064030194860792508480710467527420550344351\
843410923925432676463737015159686908912290748516636784058071451762268678623251\
4867447817140964`142., 1, EulerGamma, Pi^2, Log[2], Log[3]};

list2 = list // SortBy[#, N] &

(*  {-9169.452991044931752983668504921240294018064030194860792508480710467\
5274205503443518434109239254326764637370151596869089122907485166367840\
58071, EulerGamma, Log[2], 1, Log[3], π^2}  *)

qq = FindIntegerNullVector[list2]

(*  {-633004359680000, -134027404823687760, -134027404823687760, \
-5919486889313637261, -134027404823687760, 43840739895598800}  *)

list2.qq

(*  0.*10^-124  *)

EDIT: Testing the performance of FindIntegerNullVector with random data:

validQ[list_?VectorQ, eps_: 10^-15] :=
  Module[{qq = FindIntegerNullVector[list]},
   Abs[list.qq] < eps];

SeedRandom[0]

data = RandomReal[{-10^4, 10^4}, {10000, 4},
   WorkingPrecision -> 50];

Select[data, Not@validQ@# &] // Length

(*  0  *)

FindIntegerNullVector did not fail for any of the 10,000 random vectors even without sorting the input. You will need to test your data yourself and determine whether sorting the input helps with whatever data is causing problems.

$\endgroup$
1
  • $\begingroup$ I should note that this was only one particular example -- my code has to run through 100s like this (though most of them work without need for a special order). Is there any guarantee that the "SortBy" form is the optimal form for this task? Or do you have any idea why this is happening? $\endgroup$
    – cmm0052
    May 14, 2017 at 18:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.