# Simplify of Mod in compound logical expression

It's great that

Simplify[Mod[x,2π]==0,Assumptions->{0<=x<2π}]


yields x==0. However even a slightly more complicated expression,

expr0=Mod[x,2π]==0&&y==1
Simplify[expr0,Assumptions->{0<=x<2π}]


doesn't work; the Mod is still there. It doesn't work with FullSimplify, nor if I specify FullSimplify[expr0,ComplexityFunction->(LeafCount@#+3Count[#,Mod,Infinity]&)]. The question Simplify Mod to subtraction when possible doesn't help; PiecewiseExpand does nothing when it's compound.

I can make custom rules for replacing Mod with its simplified form, but why is Simplify only working in small cases?

The expression I want it to work on is

expr1=((Mod[-π + θ, 2 π] == π && px == 1 &&
py == 1) || (Mod[θ, π] != 0 &&
py Csc[θ] <= Csc[θ] &&
1 + (-1 + py) Cot[θ] >= px)) && (px != 1 || py != 1 ||
Mod[π/2 + θ,
2 π] != π) && (Mod[π/2 + θ, π] == 0 ||
px Sec[θ] > Sec[θ] ||
1 + (-1 + px) Tan[θ] < py) && (px != 0 || py != 0 ||
Mod[-π + θ,
2 π] != π) && (Mod[θ, π] == 0 ||
py Csc[θ] > 0 || py Cot[θ] < px) && (px != 0 ||
py != 0 ||
Mod[π/2 + θ,
2 π] != π) && (Mod[π/2 + θ, π] == 0 ||
px Sec[θ] > 0 || px Tan[θ] < py)

• Idk, but this makes progress: Assuming[0 <= \[Theta] < 2 \[Pi], Simplify[expr1, TransformationFunctions -> {Automatic, Simplify}] ] Jun 4, 2022 at 5:25
• Reduce[expr0 && 0 <= x < 2 \[Pi]] does what you want. But it gets stuck for expr1, even if LogicalExpanded. Jun 4, 2022 at 6:06

Reduce does this job better.

expr0 = Mod[x, 2 \[Pi]] == 0 && y == 1;
Reduce[expr0 && 0 <= x < 2 \[Pi]]

(*   y == 1 && x == 0   *)

expr1[px_,
py_, \[Theta]_] = ((Mod[-\[Pi] + \[Theta], 2 \[Pi]] == \[Pi] &&
px == 1 && py == 1) || (Mod[\[Theta], \[Pi]] != 0 &&
py Csc[\[Theta]] <= Csc[\[Theta]] &&
1 + (-1 + py) Cot[\[Theta]] >= px)) && (px != 1 || py != 1 ||
Mod[\[Pi]/2 + \[Theta],
2 \[Pi]] != \[Pi]) && (Mod[\[Pi]/2 + \[Theta], \[Pi]] == 0 ||
px Sec[\[Theta]] > Sec[\[Theta]] ||
1 + (-1 + px) Tan[\[Theta]] < py) && (px != 0 || py != 0 ||
Mod[-\[Pi] + \[Theta],
2 \[Pi]] != \[Pi]) && (Mod[\[Theta], \[Pi]] == 0 ||
py Csc[\[Theta]] > 0 || py Cot[\[Theta]] < px) && (px != 0 ||
py != 0 ||
Mod[\[Pi]/2 + \[Theta],
2 \[Pi]] != \[Pi]) && (Mod[\[Pi]/2 + \[Theta], \[Pi]] == 0 ||
px Sec[\[Theta]] > 0 || px Tan[\[Theta]] < py);

RegionPlot3D[
expr1[px, py, \[Theta]], {px, -5, 5}, {py, -5, 5}, {\[Theta], 0,
2 Pi}, PlotPoints -> 50]


pxmax = NMaximize[{px,
expr1[px, py, \[Theta]] && 0 <= \[Theta] < 2 Pi}, {px,
py, \[Theta]}]

(*   {1., {px -> 1., py -> 1., \[Theta] -> 1.08768*10^-15}}   *)

pymax = NMaximize[{py,
expr1[px, py, \[Theta]] && 0 <= \[Theta] < 2 Pi}, {px,
py, \[Theta]}]

(*   {1., {px -> 1., py -> 1., \[Theta] -> 1.08768*10^-15}}   *)


For Theatamax NMinimize only gives right result with px <= 0. Also expr1 simplifies easily for that px range. Aborted red2, simplification for 0 < px< =1 due to my timelimit. Please try further.

\[Theta]nmax =
NMaximize[{\[Theta],
expr1[px, py, \[Theta]] &&
0 <= \[Theta] < 2 Pi && -5 <= px <= 0}, {px, py, \[Theta]}] //
Quiet

(*   {3.14159, {px -> -4.99999, py -> 0.266354, \[Theta] -> 3.14159}}   *)

red1 = Reduce[
expr1[px, py, \[Theta]] &&
0 <= \[Theta] < 2 Pi && -5 <= px <= 0 && -5 <= py <= 1, {px,
py, \[Theta]}, Reals] // FullSimplify

(*   5 + px >= 0 &&
((px <= 0 && ((2*\[Theta] < Pi && ((py == 1 && \[Theta] > 0) ||
(py > 0 && \[Theta] > 2*ArcTan[
Sqrt[1 + (-1 + px)^2/(-1 + py)^2] +
(1 - px)/(-1 + py)] && py < 1))) ||
(\[Theta] > 2*ArcTan[Sqrt[1 + px^2/py^2] - px/py] &&
py > 0 && \[Theta] < Pi && py <= 1))) ||
(py > 0 && 2*\[Theta] > Pi && px < 0 && py <= 1 &&
\[Theta] <= 2*ArcTan[Sqrt[1 + px^2/py^2] - px/py]))   *)

red2 = Reduce[
expr1[px, py, \[Theta]] && 0 <= \[Theta] <= Pi &&
0 < px <= 1 && -5 <= py <= 1, {px, py, \[Theta]}, Reals] //
FullSimplify

(*   \$Aborted   *)