I would like Wolfram to be able to convert an expression Ceiling[x] - Floor[x] - 1
into a function that has zero everywhere except the set of integers, where it has [the value] -1
.
There isn't such a function presently, which would be a sort of Kronecker comb, similar to a DiracComb[]
, but representing an infinite sum of Kronecker deltas instead of Dirac deltas. You could request WRI add it. It does seem to show up in some signal analysis applications, but apparently the customer base has not clamored enough for its addition to make it a priority for WRI. That said, one can construct a representation oneself and extend WL a bit — more on that later.
Another issue is dealing with infinite discrete sets. WL can represent them, but that functionality seems to have a limited extent. It is more robust if a bounded domain is given such that the infinite set becomes finite. Examples:
Sin[θ] == 0
. Solve[]
returns two classes of solutions, one where the unit-circle angle crosses the positive x-axis and one where it crosses the negative x-axis. Annoying, I haven't found a way to take the union and get a solution that represents all multiples of π.
Reduce[Ceiling[x] - Floor[x] - 1 == -1 && -5 <= x <= 5, x]
returns 11 integers.
PiecewiseExpand[Ceiling[x] - Floor[x] - 1, -5 <= x <= 5]
returns an expression representing the function you seek that is valid only when -5 <= x <= 5
.
Here are a couple of identities for your function:
Ceiling[x] - Floor[x] - 1 ==
-KroneckerDelta[Sin[Pi x]] ==
-KroneckerDelta[SawtoothWave[x]]
The one with Sin[]
has the problem mentioned in example 1 above. Luckily, Sawtooth[x] == 0
can be solved in general and yields a single solution set representing all integers.
Solve[-KroneckerDelta[SawtoothWave[x]] == -1, x, Reals]
(* {{x -> ConditionalExpression[C[1], Element[C[1], Integers]]}} *)
Here is one way to use it to simplify Ceiling[x] - Floor[x] - 1
to -KroneckerDelta[SawtoothWave[x]]
:
identities =
Solve[-KroneckerDelta[SawtoothWave[x]] == -1 + Ceiling[x] -
Floor[x], #] & /@ {Ceiling[x], Floor[x]} //
Apply@Join //
MapAt[ReplaceAll[x -> x_], {All, 1, 1}] //
ReplaceAll[Rule -> RuleDelayed]
(*
{{Ceiling[x_] :> 1 + Floor[x] - KroneckerDelta[SawtoothWave[x]]},
{Floor[x_] :> -1 + Ceiling[x] + KroneckerDelta[SawtoothWave[x]]}}
*)
(* extend Simplify's abilities with the new identities *)
Simplify[-1 + Ceiling[x] - Floor[x],
TransformationFunctions -> Prepend[ReplaceAll /@ identities, Automatic]]
(* -KroneckerDelta[SawtoothWave[x]] *)
It's maybe not as convenient a representation as you like. I would understand.