Can you find a function $\beta(x)$ where if $a+b=n^m$ then $\beta(\frac{a}{b})$ is irrational?

Can you find a function $\beta(x)$ where if $a+b=n^m$ then $\beta(\frac{a}{b})$ is irrational but if $a+b$ isn't equal to $n^m$ then it is rational ($a$ and $b$ are co-prime)?

$n>0$ and $m>1$

$m$ and $n$ are integers

When $x$ is an irrational number, $\beta(x)$ can be either rational or irrational.

$\beta(0)=\pi$

$\beta(x)$ is differentiable everywhere.


This is only an 'almost' answer, since the function constructed may fail to be differentiable on some set of measure $0$.

It is known that any monotone increasing real-valued function is differentiable almost everywhere (see, for example, this Wikipedia link or this question on this site). Then it is quite easy to construct a monotone function satisfying your criteria:

Starting with $\beta(0) = \pi$, choose an enumeration $(q_n)$ of the remaining rationals and, one at a time, pick $\beta(q_n)$ to be rational or irrational according to the criteria and so that the resulting partial function is strictly monotone increasing. More precisely, for any $q_n$, there must be a greatest $q_j<q_n$ and a least $q_k>q_n$ such that $j,k<n$, and the interval $(q_j,q_k)$ contains infinitely many rationals and uncountably many irrationals to pick from (if you care about the axiom of choice, there's no need for it here: you can always narrow down your search to some well-orderable subset of the irrationals such as $\sqrt{2}\mathbb{Q}$).

Then, for irrrational $x$, define $\beta(x)$ to be the supremum of $\beta(q)$ for all rational $q<x$. The resulting function is (strictly) monotone increasing and is therefore differentiable almost everywhere.