Group Abstract Group Abstract

Message Boards Message Boards

0
|
427 Views
|
16 Replies
|
19 Total Likes
View groups...
Share
Share this post:

Why doesn't Wolfram compute Ceiling[x] = 1 + Floor[x]?

Posted 3 days ago

I want to understand why Wolfram doesn't compute obvious equalities.

In:  FullSimplify[Ceiling[x] == Floor[x], x \[Element] Integers]
Out: True

OK

In:  FullSimplify[Ceiling[x] == 1 + Floor[x], x \[Element] Reals]
Out: Ceiling[x] == 1 + Floor[x]

Why?

In:  FullSimplify[Ceiling[x] - Floor[x] == 1, x \[Element] Reals && x \[NotElement] Integers]
Out: Ceiling[x] == 1 + Floor[x]

Why?

POSTED BY: Sasha Mandra
16 Replies

I was going to add this from the docs of D[]:

D returns generic results that may not account for discontinuities, cusps or other special points

This is the case for Kronecker[x]. However, the following seems wrong (should be Pi*x, not 2*Pi*x, right?):

D[SawtoothWave[x], x]
(*  Piecewise[{{1, Sin[2*Pi*x] != 0}}, Indeterminate]  *)

Otherwise, we could use SawtoothWave[x] + SawtoothWave[1 - x] for Ceiling[x] - Floor[x].


Further, @Daniel may like this integral better:

Integrate[KroneckerDelta[Sin[Pi x]], {x, 0, x}]
(*  ConditionalExpression[0, x \[Element] Reals]  *)
POSTED BY: Michael Rogers
Posted 1 day ago

In Michaels smart solution DiscreteDelta works the same as KroneckerDelta. And if one wants to extend it to also include negative values of x it is needed to take the absolute value:

In:  Table[DiscreteDelta@SawtoothWave@x, {x, -2, 2, 0.5}]
Out: {0, 0, 0, 0, 1, 0, 1, 0, 1}

In:  Table[DiscreteDelta@SawtoothWave@Abs@x, {x, -2, 2, 0.5}]
Out: {1, 0, 1, 0, 1, 0, 1, 0, 1}
POSTED BY: Hans Milton

I cannot say that I like the integrals. But the derivatives make good sense to me. The Kronecker delta, unlike its Dirac analog, is not a functional. There are no plausible alternatives for the derivatives that I'm aware of.

POSTED BY: Daniel Lichtblau
Posted 1 day ago

I'm sorry, but I've lost the plot. I don't understand where you're going with this. I don't understand why my answers are confusing, and so I don't know how to improve them. Have you been able to get something to actually work? Have you tried the suggestions offered here, and have they worked or not? I'd really prefer to help you reach your specific objective rather than rathole on some quirk of Mathematica's Simplify implementation.

POSTED BY: Eric Rimbey
Posted 1 day ago

Sorry, I didn't notice your reply, so I'm replying late.

So, if it were to "solve" the problem with variables but a user wanted to use the solution with values (in particular the values I used as examples), well then they'd get very incorrect results.

And what incorrect results they will get if Wolfram computes it?

In:  FullSimplify[Ceiling[x] - Floor[x] == 1  
 x \[Element] Reals]
Out: x \[NotElement] Integers

Let's be specific!

POSTED BY: Sasha Mandra

The functions KroneckerDelta[Sin[Pi x]] and KroneckerDelta[SawtoothWave[x]] behave disappointingly with respect to derivation and integration:

D[KroneckerDelta[Sin[Pi x]], x]
D[KroneckerDelta[SawtoothWave[x]], x]
Integrate[KroneckerDelta[Sin[Pi x]], x]
Integrate[KroneckerDelta[SawtoothWave[x]], x]

The same for Boole[Element[x, Integers]], which also does not evaluate on floating point integers, such as Boole[Element[1., Integers]]

POSTED BY: Gianluca Gorni
Posted 1 day ago

You're gorgeous as always!

There isn't such a function presently

I realize that. I put it that way for brevity. You can leave Ceiling[x] - Floor[x] -1 as the definition of a function on the set of real numbers. The important thing is for Wolfram to prove that this function is -1 if x is an integer and 0 if x is a non-integer.

POSTED BY: Sasha Mandra

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:

  1. 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 π.
  2. Reduce[Ceiling[x] - Floor[x] - 1 == -1 && -5 <= x <= 5, x] returns 11 integers.
  3. 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.

POSTED BY: Michael Rogers
Posted 2 days ago

Okay, maybe my response was irrelevant, but I'm not convinced, so let me try again. I see your point about my example using concrete values while you're only interested in the abstraction provided by variables. But Mathematica doesn't want to give an untrue answer (as much as reasonable, there are in fact weird edge cases that one could consider untrue, but I don't think we need to go into that). So, if it were to "solve" the problem with variables but a user wanted to use the solution with values (in particular the values I used as examples), well then they'd get very incorrect results.

As for your questions...

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 -1.

That's easy. We can just use your expression directly:

myFunc[x_] := Ceiling[x] - Floor[x] - 1;
Table[myFunc[x], {x, -2, 2, 1/4}]
(* {-1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1} *)

There are probably many ways to define such a function, there may even be a built in function for that.

to what extent can Wolfram help in theoretical mathematics?

I'm not the right person to answer that, but as far as I can tell there are many people doing sophisticated mathematics with Wolfram.

POSTED BY: Eric Rimbey
Posted 2 days ago

Thank you for your response. I apologize if you got the impression that I have any prejudice against you. I just don't think your answer answers my question.

As for 2. [Element] Integers, there is no problem here. Wolfram simply does not attribute any truth value to this expression: neither true nor false.

In:  {2. \[Element] Integers, 2. \[NotElement] Integers} // FullSimplify
Out: {2. \[Element] Integers, 2. \[NotElement] Integers}

But this is irrelevant to my question, since only variables are involved. And there is nothing wrong with variables in Wolfram.

As for my interest, it is pure curiosity: to what extent can Wolfram help in theoretical mathematics? 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 -1. From a theoretical point of view, this is elementary.

POSTED BY: Sasha Mandra
Posted 3 days ago

Okay, let me first emphasize that I sympathize with you. I'm not arguing with you. It's perfectly reasonable for you to expect there to be a natural expression that gets you to where you want. But what you've got to remember is that Mathematica is not a logic system. We can quibble about things around the edges, but in the main, all Mathematica is doing is evaluating expressions. So, when you are trying to assert something like x \[NotElement] Integers that is first an foremost just an expression, it's not an assertion. You're not registering an assertion into a logic framework.

If I understand you, you want Mathematica to "solve" Ceiling[x] - Floor[x] == 1 by telling you the domain in which it holds true. Logically, that domain should be x \[Element] Reals && x \[NotElement] Integers. Unfortunately, that expression simply doesn't resolve for all x. I don't have any knowledge about the inner workings of Mathematica's code, but I believe that the reason this is failing is because this expression isn't guaranteed to resolve for all of the relevant numeric values. For example,

With[
 {x = 2.0},
 x \[Element] Reals && x \[NotElement] Integers]
(* 2. \[NotElement] Integers *)

So, Mathematica was not able to determine the truth/falsity of that second term. Now, you may be thinking, "yes, but that value isn't in the domain of the solution", and I totally sympathize, but I still think that the underlying ambiguity of that expression is interfering. I could be totally wrong--we'd probably need someone more familiar with the underlying code to confirm.

I am sure that FullSimplify has a bunch of ad hoc rules that it knows how to apply, and maybe this particular case should be added to those rules, but for now it appears that it simply isn't. Maybe there's a very good reason for this, I don't know. But you're just beating your head against a wall here. Which leads me to ask what your real objective is. This looks more like some sort of test case for Mathematica itself than a computational problem that you need help with. What is it that you're actually trying to achieve? If this is just for curiosity's sake, then I think we've gone as far as we can. If this particular computation is interfering with some actual computational goal you're working toward, then maybe we can explore workarounds.

POSTED BY: Eric Rimbey
Posted 3 days ago

Unfortunately, I don't understand you either.

In:  Reduce[Ceiling[x] + Floor[x] == 1, x, Reals]
Out: 0 < x < 1

ОК

In:  Reduce[Ceiling[x] - Floor[x] == 1, x, Reals]
Out: This system cannot be solved with the methods available to Reduce

Why? I'm expecting this response or a similar one:

x \[Element] Reals && x \[NotElement] Integers
POSTED BY: Sasha Mandra
Posted 3 days ago

I think Hans Milton provided a good example, and your reply to that doesn't seem relevant. Here's another way to look at it:

FullSimplify[Ceiling[x] == Floor[x], x \[Element] Integers]
(* True *)

FullSimplify[Ceiling[x] == Floor[x], x \[Element] Reals]
(* Ceiling[x] == Floor[x] *)

So, you can interpret that as meaning, "when x is real, Mathematica cannot find a simplification that resolves the equality to true or false". And of course, like Hans showed, one example is 2.0. Indeed, we have

2 \[Element] Reals
(* True *)

So, we don't even need an expression with Real as its Head. Furthermore, consider this

2. \[Element] Integers
(* 2. \[Element] Integers *)

2. \[NotElement] Integers
(* 2. \[NotElement] Integers *)

meaning that Mathematica withholds commitment about the integer-valued-ness for a value that you expect to satisfy your assumptions. I think the answer to your original question depends upon the reason for that.

POSTED BY: Eric Rimbey
Posted 3 days ago

From the documentation of Rationals, under Details:

The domain of integers is taken to be a subset of the domain of rationals.

In:  Element[2, Rationals]
Out: True
POSTED BY: Hans Milton
Posted 3 days ago

What do you mean? Here's another example:

In:  1 \[Element] Rationals
Out: True

In:  Ceiling[x] == 1 + Floor[x] /. x -> 12/5
Out: True

In:  FullSimplify[Ceiling[x] == 1 + Floor[x], x \[Element] Rationals]
Out: Ceiling[x] == 1 + Floor[x]
POSTED BY: Sasha Mandra
Posted 3 days ago

This is why:

In:  Ceiling[x] - Floor[x] /. x -> 2.
Out: 0

In:  IntegerQ[x] /. x -> 2.
Out: False

In:  Head[2.]
Out: Real
POSTED BY: Hans Milton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard