3
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?

bios
  • 401
  • 2
  • 9

2 Answers2

7

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.

wuyingddg
  • 1,943
  • 10
  • 14
  • Ref: http://mathematica.stackexchange.com/questions/41247/behavior-of-reduce-with-variables-as-domain, and its linked questions. – Michael E2 Jul 24 '16 at 03:53
3

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})
Wjx
  • 9,558
  • 1
  • 34
  • 70