# Find natural numbers>0 divisible by 37 using FindInstance?

Posted 5 years ago
3981 Views
|
13 Replies
|
7 Total Likes
|
 As part of a larger Problem I have to find natural numbers>0 that are divisible by 37, which is a trival Problem. I write: b1[n_] := Divisible[n, 37] FindInstance[{n > 0, b1[n]}, n, Integers] I get: FindInstance::naqs: n>0&&Divisible[n,37] is not a quantified system of equations and inequalities. >> The same happens wit Solve. What is wrong with that Code?Actually I have to find numbers which respect a lot of logical conditions, some of them quite complex. That is why I put the conditions into seperate functions.But even if I write: FindInstance[{n > 0, Divisible[n, 37]}, n, Integers] I get the same error.
13 Replies
Sort By:
Posted 5 years ago
 Divisible is somehow not 'recognized' but you can circumvent it by using a code like: FindInstance[{n > 0, n == 37 m}, {n, m}, Integers] 
Posted 5 years ago
 In[1]:= b1[n_] := Mod[n, 37] == 0 FindInstance[{n > 0, b1[n]}, n, Integers] Out[2]= {{n -> 37}} 
Posted 5 years ago
 Thanks Sander and Veleriu.Of course I can test divisibility by other means than Divisible[n,m]. But what is special with the built-in function Divisible that it does not work?
Posted 5 years ago
 Another example ist In[151]:= FindInstance[Apply[Times, IntegerDigits[n]] == 23, n, Integers] Out[151]= {{n -> 23}} which looks for numbers with a product 23 of their digits. There are none of course since 23 ist prime. But FindInstance delivers 23, which is wrong.
Posted 5 years ago
 I think FindInstance is designed for geometry, polynomials, and booleans. I don't think they had in mind applying those kind of operations for this function...The one you mention seems to be a bug? Please report it.
Posted 5 years ago
 I am not sure, but it seems that the problem  FindInstance[Apply[Times, IntegerDigits[n]] == 23, n, Integers] or in mathematical notation: $x_1 * x_2 * \dots * x_n = a$ $x_i \in \{0, \dots, 9 \}, i =1, \dots, n$may be related to knapsack problem, one of the very known NP-complete problems. The essential difference is operation * instead of +. If so, the problem is very difficult by itself.
Posted 5 years ago
 It might be that the Problem is not solvable by FindInstance. But it should not deliver wrong results
Posted 5 years ago
 You're absolutely right!
Posted 5 years ago
 Hmm, Sander, very strange.Two questions since I am new to Wolfram Language: Can I report bugs directly from the community threads? Or only via email out of the language environments? I cannot find any settings for the community language Settings. Since my location is Germany, it uses German spelling always. Which is annoying.
Posted 5 years ago
 The spell check is (i guess) your browser. I'm in France, but I have everything in English since I'm Dutch my French is limited. Bugs are submitted here: category: "Product feedback"http://www.wolfram.com/support/contact/email/
Posted 5 years ago
 Thanks, Sander. I was using Edge which seams to have no settings for languages. Now I tried IE and could install the language English (US). But I still have no spelling correction. I will find it some day :-)
 Thanks, Frank for that hint. At first I thought this explains my mistake. I was misleaded by the documentation which tells: FindInstance[expr,vars] finds an instance of vars that makes the statement expr be True. But within the details-section they explain that expr has to be equations, etc. But within the examples there are some with pure logical expressions, not equations. Anyway. If I write it as an equation, I get another error and ridiculous results: In[206]:= FindInstance[{n > 0, Divisible[n, 37] = True}, n, Integers, 5] During evaluation of In[206]:= Set::write: Tag Divisible in Divisible[n,37] is Protected. >> Out[206]= {{n -> 31}, {n -> 33}, {n -> 267}, {n -> 335}, {n -> 400}} If I write it with "==" instead of "=" I get: In[205]:= FindInstance[{n > 0, Divisible[n, 37] == True}, n, Integers, 5] During evaluation of In[205]:= FindInstance::exvar: The system contains a nonconstant expression True independent of variables {n}. >> Out[205]= FindInstance[{n > 0, Divisible[n, 37] == True}, n, Integers,5] I'm afraid, I still have some basic misunderstandings of the Wolfram Language.