2
$\begingroup$
Reduce[x*y > 50 && x*y < 100 && x < 100 && x > 1 && y > 1 && 
 y < 50, {x, y}, Integers]

what if I want to get the production of x*y instead of (x == 2 && y == 26) || (x == 2 && y == 27)...

Can I define a function for multiplication, then use the output of the Reduce as an input to my multiplication?

$\endgroup$
6
$\begingroup$

You can add a new variable in Reduce do get your multiplication, just like this

In[13]:= Reduce[
 ans == x y && x*y > 50 && x*y < 100 && x < 100 && x > 1 && y > 1 && 
  y < 50, ans, {x, y}, Integers]

Out[13]= ans == 51 || ans == 52 || ans == 54 || ans == 55 || 
 ans == 56 || ans == 57 || ans == 58 || ans == 60 || ans == 62 || 
 ans == 63 || ans == 64 || ans == 65 || ans == 66 || ans == 68 || 
 ans == 69 || ans == 70 || ans == 72 || ans == 74 || ans == 75 || 
 ans == 76 || ans == 77 || ans == 78 || ans == 80 || ans == 81 || 
 ans == 82 || ans == 84 || ans == 85 || ans == 86 || ans == 87 || 
 ans == 88 || ans == 90 || ans == 91 || ans == 92 || ans == 93 || 
 ans == 94 || ans == 95 || ans == 96 || ans == 98 || ans == 99

This is an undocumented usage of Reduce, which can eliminate some variables in the equations.

$\endgroup$
2
$\begingroup$

EDIT

Using to rules will be better:

x y/.{ToRules@Reduce[x*y > 50 && x*y < 100 && x < 100 && x > 1 && y > 1 && y < 50, {x, y}, Integers]}

@Michael thanks!

in your situation, the result will be in the form x==2&&y==26||x==2&&y==27...... so we can use replacement rules to make it into {{x->2,y->26},{x->2,y->27},......} Then let ReplaceAll do the job.

The code is as follows:

x y /. 
(Reduce[x*y > 50 && x*y < 100 && x < 100 && x > 1 && y > 1 && y < 50, {x, y}, Integers] 
/. {Equal -> Rule, And -> List, Or -> List})
$\endgroup$
  • $\begingroup$ Have you seen ToRules[]? $\endgroup$ – Michael E2 Jul 24 '16 at 0:34
  • $\begingroup$ @MichaelE2 well then, seemingly this alone will do the job......thanks! $\endgroup$ – Wjx Jul 24 '16 at 1:49

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.