3
$\begingroup$

I have a kind of dumb question I'm afraid.

Given two complicated expressions, is there a fast check to see whether one is a rational multiple of the other. I mean given expressions expr1, expr2 something like NumberQ[expr1/expr2]. However NumberQ[Simplify[expr1/expr2]] does exactly what I need but might take forever! Is there a faster way?

By the way I have no idea how to tag this question...

$\endgroup$
3
  • $\begingroup$ If Simplify is too slow I think you need to do it approximately like Rationalize[expr1/expr2, 10^(-tol)] === Rationalize[expr1/expr2, 10^(-2*tol)] with e.g. tol = 100 $\endgroup$
    – Coolwater
    Sep 30 '16 at 9:48
  • $\begingroup$ Could you add a "typical" example of expr1 and expr2? $\endgroup$
    – jkuczm
    Sep 30 '16 at 10:20
  • $\begingroup$ Both expressions are polynomials with a lot of terms adding up in n variables with integer coefficients here. They are found themselves from certain types of graphs which I input. Sometimes two completely different graphs yield proportional polynomials although you can only see it after a lot of algebraic simplifications $\endgroup$
    – Hamed
    Sep 30 '16 at 14:34
3
$\begingroup$

My approach is to evaluate the polynomials with random integers assigned to the variables. This is likely to be very fast.

For test purposes, let us define 3 polynomials in 7 variables

expr1a = (-2 + a[1]) (-5 + a[2]) (5 + a[3]) (4 + a[4]) (1 + a[5]) a[6] (-4 + a[7]);
expr1b = Expand[13/7 expr1a];
expr2 = expr1b + 1;

Define functions

randominstance[x_] := Block[{a},
  Do[a[i] = RandomInteger[{-1000, 1000}], {i, 7}];
  x]
ratiocheck[x1_, x2_] := SameQ[randominstance[x1/x2], randominstance[x1/x2]]

Test that the functions give the expected results on our test polynomials

ratiocheck[expr1a, expr1b]
(* True *)

ratiocheck[expr1a, expr2]
(* False *)

There is a risk of concluding that two polynomials have a constant ratio, when in fact they do not, but you can do multiple checks.

$\endgroup$
1
  • $\begingroup$ Thanks this works beautifully... I guess a triple check is quite safe... $\endgroup$
    – Hamed
    Sep 30 '16 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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