Primality is difficult to check as it requires a statement like "there don't exist two natural numbers $a,b>1$ such that $n=a\cdot b$" which for flexible a $n$ require quantifiers to express. Quantified Mixed Integer (Linear) programming exists as a concept but I am not really aware of any solvers that can solve such problems.
This means we need to somehow "unroll" all possibilities such an quantifier would cover. Let $N$ be the upper bound of $n$ a naive one would be $\prod_{x \in \mathbb{P}} (n-x) = 0$ or some other polynomial. Other primality tests such as the Wilson test $(n-1)!\ \equiv\; -1 \pmod n$ can also be expressed but would result in even higher order polynomials.
Another alternative not using products of variables is to use the absolute value $\forall_{x\in\mathbb{P}\leq N} |n-x| \leq N b_p$ and $\sum_{x\in \mathbb{P}} b_p = 1$ and $b_p$ is a boolean. One could cut the number of equations almost in half by checking divisibility by 2.
There are more compact is prime checks and one could systematically search those for some fixed $N$. This would likely be possible using a two level Mixed Integer Quadratic problem where you try to find an constraint matrix $A \in \mathbb{R}^{n+2\times n+2}$ and a constraint vector $b \in \mathbb{R}^{n}$ that satisfies
$$\forall m\in\mathbb{N}\leq N: A x \leq \begin{bmatrix}
m \\
\text{isprime}(m) \\
b_1
\vdots \\
b_{n}
\end{bmatrix}$$
where the parent tries to find a such a matrix $A$ and an assignment $x \in \mathbb{R}^a \times \mathbb{B}^{N-a}$ that satisfies this and the $N$ sub problems (each has it's own $m$) try to find counter examples $x$ such that for the $A,b$ from the parent problem
$$A x \leq \begin{bmatrix}
m \\
1-\text{isprime}(m) \\
b_1
\vdots \\
b_{n}
\end{bmatrix}$$
This counter example can then be used to add a new constraint to the parent problem. If the parent problem becomes unfeasible a bigger $n$ for the dimensions needs to be chosen. Note that only the parent problem is quadratic. If all subproblems are infeasible you found a constraint which encodes is prime. Depending how you chose $n$ and whether the parent problem has an appropriate objective it might also be the smallest $n$, a sparse $A$ or have other properties you want and can express in quadratic programming.
Note that Mixed Integer solvers are generally not great in finding feasible solutions a more different approach would be to pick a binary encoding of $n$ to be tested and do a similar find counter example make more constraints loop with a Pseudo boolean or a SAT solver. This will result in binary constraints which can then also be used in a MILP problem. Quantified boolean solvers also exist and there might be a way to "coax" them into finding a solution without bouncing back and forth. Another alternative on that front are Binary Decision Diagrams which are also use to reduce logic in computer chips.
Getting good results using either method with some analysis of the result would probably be worth publishing a paper about. There might be some other way to derive such a look up table however i am not aware of any.