## Using the array result of a select statement returns ERROR: pq: operator does not exist: integer = integer[]

The query in question is the following:

SELECT * FROM options WHERE id = any(SELECT option_ids FROM workshops WHERE id=3) 
ERROR: pq: operator does not exist: integer = integer[] 

Basically the statement inside any() returns an array of ids which I want to use to get some rows on the options table.

I don’t understand why is it trying to compare an integer to the whole array, isnt any supposed to compare a single int to multiple integers in an array?

## About Fermat’s Integer Factoring algorithm

An implementation of Fermat’s algorithm that is a slight improvement on code in this book is here.

FermatFactor[n_?OddQ]:=Module[{s=Floor@Sqrt[n+01],r,u,v=1},   If[s^2==n,Return@{s,s}];   {r,u}={(s+1)^2-n,2*s+3};   While[r!=0,     While[r>0,       r-=v;v+=2     ];     If[r<0,r+=u;u+=2]   ];   (u+{-v,v-2})/2 ] 

The main improvement above is the fast implementation of Floor[Sqrt[n]] from MichaelE2. The above implementation will factor the following in less than 0.1 seconds!

SeedRandom[100]; p=10^50; n=NextPrime@RandomInteger[{p-80000,p-60000}]*NextPrime@RandomInteger[{p+80000,p+60000}]; FermatFactor[n] (*{99999999999999999999999999999999999999999999920467,100000000000000000000000000000000000000000000075667}*) 

I have Mathematica Version 12.0.0 and FactorInteger[n] takes a very long time on that example. Can FactorInteger in Mathematica 12.2 do it in a reasonable amount of time?

## How to assume a number to be a half integer?

For integer x $$\left(\cos 2\pi x\right) ^2=1$$ and I can check this as follows

Simplify[Cos[2 \[Pi] x]^2, Assumptions -> x \[Element] Integers] 

and get 1 as an output. The same holds when x is half-integer. How do I assume this in Mathematica? More generally, is there a nice way to implement assumptions of the type say $$x\in 3\mathbb{Z}+2$$ without redefining variables that I use?

## Evaluate the limit of a subsequence: Compute the limit $\lim_{n\to\infty} \cos\left( \pi \sqrt{4n^2 + 5n + 1} \right)$ Integer $n$ on Mathematica

I want to compute the limit $$\lim \limits_{n\to\infty} \cos\left( \pi \sqrt{4n^2 + 5n + 1} \right)$$for integer $$n$$. By completing the square, we can determine that this limit is equal to $$– \tfrac1{\sqrt2} \approx -0.7071$$.

But if we don’t restrict $$n$$ to an integer, then the limit is indeterminate / does not exist. And can be easily found by typing it on WolframAlpha. Or in Mathematica:

However, I do not know how to compute the limit (on Mathematica) with the original constraint that $$n$$ must be an integer.

I know that we can plot a graph on Mathematica:

The graph suggests that the limit is equal to $$-\tfrac1{\sqrt2}$$. However, this doesn’t look like a convincing result because we can’t know that the limit is exactly equal to $$-\tfrac1{\sqrt2}$$.

Question: Is there a way to compute this limit in Mathematica where it spits out a single numerical value (of $$-1/{\sqrt2}$$)?

## Determine if there is a subset of the given set with sum divisible by a given integer

I’ve been given a question to solve:

Given a set of non-negative distinct integers, and a value $$m$$, determine if there is a subset of the given set with sum divisible by $$m$$.

For this question the answer is here

I don’t understand the part after if DP[j]==True
what is actually the intuition behind this code. Please explain in detail.

## How to simplify quotient and mod in integer domain

I want to simplify (a*32 + a%32)/32, and a is integer.

So I write:

Simplify[Quotient[a*32 + Mod[a, 32], 32], Element[a, PositiveIntegers]] 

However it gives me:

Quotient[32 a + Mod[a, 32], 32] 

and I expect to see a

## Enumerating points on the integer lattice, within a sphere, sorted by angle, in O(1) space

Inspired by this StackOverflow question: https://stackoverflow.com/questions/63346135

(it was not clearly presented, and got closed)

Let’s say I wanted to enumerate all the 3D points on the integer lattice, within a sphere, in order of the angle between the vector to the point and the up vector (say z).

Could I do this in O(1) space efficiently?

All I can find is:

Remembering last point (init at (0,0,0)). (O(1) memory) while true     init best dot product to 0     going through all 3D points (three nested for's with radius range)         if this point has better dot product but least than last point             keep this point as best     if best dot product is still 0, exit      pick best point as current point (this is where the listing occurs)     update last point to best point 

Not only is this absolutely slow, it also needs the use of integer math for dot product and length so that numerical precision doesn’t mess with symmetrical points and it would also need a tweak to guarantee symmetrical points are listed in a known order.

Is there any good algorithms that would apply here?

## Integer Palindrome

I wrote the following program to calculate integer palindrome.

class Solution: # @param A : integer # @return an integer def isPalindrome(self, A):     if A<0:         return 0     return int(str(A) == reversed(str(A))) 

It’s giving the wrong output could anyone pls tell what’s going wrong.

## What factors of the integer dataset being sorted can I change, in order to compare two sorting algorithms?

I am comparing two comparison and binary data structure based sorting algorithms, the Tree Sort, and the Heap Sort. I am measuring the time taken for both algorithms to sort an increasing size of an integer dataset. However, I am wondering if there are any other variables which I can modify, for example standard deviation, in the integer dataset itself that would be of any benefit to my comparison.

## Returning random integer from interval based on last result and a seed

Suppose we have an interval of integers [a, b]. I would like to have a function that returns random members from within the interval, without repetitions. Once that all members within the interval are explored, the function would start to return the same first random sequence again, in the same order.

Example: a=1, b=5

3, 1, 4, 5, 2, 3, 1, 4, 5, 2, 3, 1, 4, 5, 2, ... 

This would be easy to achieve by shuffling an array of all elements between a and b, and repeating it once the array is finished. However, this would take too much memory space, and this is not suitable for my case (I might have millions of elements).

Instead, the function I’d like to have would be more or less like this:

f(a, b, n, seed) -> n+1 

Where:

a - start of interval b - end of interval n - last element returned from list seed - self-explanatory n+1 - next random element from list, calculated by using the seed and the last element returned (n) 

The trick is knowing some way to get a non-repeated number from the interval based only on the element returned before and the seed. In the end, it would behave like a circular list randomized at its initialization, but without using memory space.