Why does this SBV code stop before I set the limit?

I have this theorem (not sure if this is the right word) and I want to get all the solutions.

pairCube limit = do
    m <- natural exists "m"
    n <- natural exists "n"
    a <- natural exists "a"
    constrain $ m^3 .== n^2
    constrain $ m .< limit
    return $ m + n .== a^2

res <- allSat (pairCube 1000)

-- Run from ghci
extractModels res :: [[Integer]]

This is trying to solve the problem:

There are infinite pairs of integers (m, n) for which m ^ 3 = n ^ 2 and m + n is an ideal square. Which pair with the largest m is less than 1000?

I know the actual answer, only through crude forcing, but I want to do with SBV.

However, when I run the code, it gives only the following values โ€‹โ€‹(in the form [m, n, a]): [[9,27,6], [64,512,24], []]

However, there are several other solutions with m values โ€‹โ€‹of less than 1000 that are not included.

+4
source share
1 answer

:

{-# LANGUAGE ScopedTypeVariables #-}

import Data.SBV

pairCube :: SInteger -> Symbolic SBool
pairCube limit = do
        (m :: SInteger) <- exists "m"
        (n :: SInteger) <- exists "n"
        (a :: SInteger) <- exists "a"
        constrain $ m^(3::Integer) .== n^(2::Integer)
        constrain $ m .< limit
        return $ m + n .== a^(2::Integer)

main :: IO ()
main = print =<< allSat (pairCube 1000)

, :

Main> main
Solution #1:
  m = 0 :: Integer
  n = 0 :: Integer
  a = 0 :: Integer
Solution #2:
  m =  9 :: Integer
  n = 27 :: Integer
  a = -6 :: Integer
Solution #3:
  m =  1 :: Integer
  n = -1 :: Integer
  a =  0 :: Integer
Solution #4:
  m =  9 :: Integer
  n = 27 :: Integer
  a =  6 :: Integer
Solution #5:
  m =  64 :: Integer
  n = 512 :: Integer
  a = -24 :: Integer
Solution #6:
  m =  64 :: Integer
  n = 512 :: Integer
  a =  24 :: Integer
Unknown

Unknown.

, SBV Z3 6 ; SBV 7-, Z3 : " , ". .

(.. max m), :

constrain $ m .== limit

":"

main :: IO ()
main = loop 1000
  where loop (-1) = putStrLn "Can't find the largest m!"
        loop m    = do putStrLn $ "Trying: " ++ show m
                       mbModel <- extractModel `fmap` sat (pairCube m)
                       case mbModel of
                         Nothing -> loop (m-1)
                         Just r  -> print (r :: (Integer, Integer, Integer))

50 Z3 :

(576,13824,-120)

, , , allSat, Z3 , , m . , - /, , SMT .

+5

Source: https://habr.com/ru/post/1619085/


All Articles