Group Abstract Group Abstract

Message Boards Message Boards

3
|
182 Views
|
8 Replies
|
8 Total Likes
View groups...
Share
Share this post:

Extending FindInstance

POSTED BY: Frank Kampas
8 Replies

POSTED BY: Frank Kampas

POSTED BY: Frank Kampas

A completely different algorithm would be the exhaustive search over a custom range with FindClosedForm, but unfortunately seems to have a bug for this case. I should fix it and come back answering this later. Meanwhile I leave this example from the documentation.

ResourceFunction["FindClosedForm"][19/18, Det[{{#1, #2}, {#3, #4}}] &,
   30, "OutputArguments" -> True, "AlgebraicAdd" -> False, 
  "AlgebraicFactor" -> False] // AbsoluteTiming

   (* {11.8572, <|{-3, -(2/3), -(2/3), -(1/2)} -> 19/
       18, {-3, 2/3, 2/3, -(1/2)} -> 19/18, {-(3/2), -(2/3), -(2/3), -1} ->
        19/18, {-(3/2), 2/3, 2/3, -1} -> 19/
       18, {-1, -(2/3), -(2/3), -(3/2)} -> 19/18, {-1, 2/3, 2/3, -(3/2)} ->
        19/18, {-(2/3), -3, 1/2, 2/3} -> 19/18, {-(2/3), -(3/2), 1, 2/3} ->
        19/18, {-(2/3), -1, 3/2, 2/3} -> 19/18, {-(2/3), -(1/2), 3, 2/3} ->
        19/18, {-(2/3), 1/2, -3, 2/3} -> 19/18, {-(2/3), 1, -(3/2), 2/3} ->
        19/18, {-(2/3), 3/2, -1, 2/3} -> 19/18, {-(2/3), 3, -(1/2), 2/3} ->
        19/18, {-(1/2), -(2/3), -(2/3), -3} -> 19/
       18, {-(1/2), 2/3, 2/3, -3} -> 19/18, {1/2, -(2/3), -(2/3), 3} -> 
       19/18, {1/2, 2/3, 2/3, 3} -> 19/18, {2/3, -3, 1/2, -(2/3)} -> 19/
       18, {2/3, -(3/2), 1, -(2/3)} -> 19/18, {2/3, -1, 3/2, -(2/3)} -> 
       19/18, {2/3, -(1/2), 3, -(2/3)} -> 19/18, {2/3, 1/2, -3, -(2/3)} ->
        19/18, {2/3, 1, -(3/2), -(2/3)} -> 19/18, {2/3, 3/2, -1, -(2/3)} ->
        19/18, {2/3, 3, -(1/2), -(2/3)} -> 19/
       18, {1, -(2/3), -(2/3), 3/2} -> 19/18, {1, 2/3, 2/3, 3/2} -> 19/
       18, {3/2, -(2/3), -(2/3), 1} -> 19/18, {3/2, 2/3, 2/3, 1} -> 19/18|>}*)

Det[{{#1, #2}, {#3, #4}}] &[Sequence @@ Keys[%[[2]]][[1]]]

(*19/18*)
POSTED BY: Daniele Gregori

Find the smallest survey sample size so that the responses to a 3-category survey item are 23%, 53%, 23%, correctly rounded.

Extending FindInstance[] to a solution:

FixedPoint[
  Join[#,
     FindInstance[{2 a + b == n,
       200 RealAbs[a/n - 23/100] <= 1,
       200 RealAbs[b/n - 53/100] <= 1,
       (n /. Last@#) > n, (* descend *)
       n >= a >= 0, n >= b >= 0},
      {n, a, b}, Integers]
     ]~Part~{-1} &,
  {{n -> Infinity}}
  ] // Last
{a, b, a}/n /. % // N
(*
{n -> 30, a -> 7, b -> 16}
{0.233333, 0.533333, 0.233333}
*)
POSTED BY: Michael Rogers

POSTED BY: Frank Kampas
FindInstance[{(1 + 1/x) (1 + 1/y) (1 + 1/z) == 3, 
   0 < x < 10, 0 < y < 10, 0 < z < 10}
  , {x, y, z}, PositiveIntegers, 100] // AbsoluteTiming
(*
{0.00499`, {
  {x -> 1, y -> 3, z -> 8}, {x -> 1, y -> 4, z -> 5},
  {x -> 1, y -> 5, z -> 4}, {x -> 1, y -> 8, z -> 3},
  {x -> 2, y -> 2, z -> 3}, {x -> 2, y -> 3, z -> 2},
  {x -> 3, y -> 1, z -> 8}, {x -> 3, y -> 2, z -> 2},
  {x -> 3, y -> 8, z -> 1}, {x -> 4, y -> 1, z -> 5},
  {x -> 4, y -> 5, z -> 1}, {x -> 5, y -> 1, z -> 4},
  {x -> 5, y -> 4, z -> 1}, {x -> 8, y -> 1, z -> 3},
  {x -> 8, y -> 3, z -> 1}}
 }
*)

FindInstance[{(1 + 1/x) (1 + 1/y) (1 + 1/z) == 3, 
   10 <= x || 10 <= y || 10 <= z}, {x, y, z}, PositiveIntegers, 
  100] // AbsoluteTiming

(*  {0.234198, {}}  *)
POSTED BY: Michael Rogers

Dimensionality, boundedness, searching for a solution versus all solutions: algorithms, not mathematics, make such differences affect performance.

I can't really guess what response you're looking for, or even if you want a response.

Reduce the 14 to 8 or less, if you want it to end in after a few seconds:

FixedPoint[
 Join[#, 
   FindInstance[{5 (a + b + c + d) + 10 == 2*a*b*c*d, 
      And @@ Or @@@ (# /. Rule -> Unequal)}, {a, b, c, d}, 
     PositiveIntegers] /. _FindInstance -> {}] &,
 {},
 14]
(*
{{a -> 5, b -> 9, c -> 1, d -> 1}, {a -> 9, b -> 5, c -> 1, d -> 1},
 {a -> 1, b -> 5, c -> 9, d -> 1}, {a -> 5, b -> 1, c -> 1, d -> 9},
 {a -> 5, b -> 1, c -> 9, d -> 1}, {a -> 9, b -> 1, c -> 5, d -> 1},
 {a -> 1, b -> 9, c -> 5, d -> 1}, {a -> 1, b -> 1, c -> 5, d -> 9},
 {a -> 9, b -> 1, c -> 1, d -> 5}, {a -> 3, b -> 1, c -> 1, d -> 35},
 {a -> 1, b -> 1, c -> 9, d -> 5}, {a -> 1, b -> 1, c -> 3, d -> 35},
 {a -> 1, b -> 3, c -> 1, d -> 35}, {a -> 1, b -> 5, c -> 1, d -> 9}}
*)

I was going to go for all 24 solutions, but each step gets slower and slower and slower.

POSTED BY: Michael Rogers
Posted 7 days ago

I find this a bit bizarre.

POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard