Message Boards Message Boards

0
|
10651 Views
|
10 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Defining my own Dirichlet like function

Posted 10 years ago
piecewise[{{0, for x rational}, {x, for x irrational}}]

I've tried this one. but with no success. can someone help me?
POSTED BY: pavel rogovoy
10 Replies
Posted 10 years ago
1. In Mathematica is there an example where Head === Rational and Element[x, Rationals] differ?

We might be able to guess the implementation of the first, but the second might be more open to question.
Are they actually identical or not?

2. I tried an assortment of ways to get WolframAlpha to plot or even define your function and failed repeatedly.

In my experience, one of the differences between MMA and WA is that MMA allows function definitions and WA doesn't,
but you can sometimes just insert the "body" of the function into your WA query and get around this.

If there is a recipe for how to efficiently discover the syntax to understand a particular WA query I'd love to learn that.

Note: I did accidentally stumble onto appending "last 10 years" onto the end of a WA query and found it is possible
to get the history of some statistic instead of just the latest value, I had long since given up and assumed that
this just could not be done.  I still have not found a way to get an inflation adjusted history though.
POSTED BY: Bill Simpson
Posted 10 years ago
@Bill

1. It is not known whether E + Pi is rational or not, hence 
In[1]:= Element[E + Pi, Rationals]
Out[1]= E + \[Pi] \[Element] Rationals
However
In[2]:= Head[E + Pi] === Rationals
Out[2]= False
POSTED BY: Greg Hurst
Posted 10 years ago
First of all thank you all for replying to my question in such a short time.
I guess I wasn't clear enough. My goal is to define this function in wolframalpha.com site and not in Mathematica.
How do I type this formula in the "calculate" field. I just need to see its graph. 
POSTED BY: pavel rogovoy
Its graph looks like the constant 0 function, or 1 function, depending on how you look at it. It could look like both superimposed, if you look at it like that. Both sets are dense in [0,1], so there aren't any gaps - just both the lines.
POSTED BY: Patrick Stevens
Posted 10 years ago
but how do I define this in wolframalpha.com?
POSTED BY: pavel rogovoy
Posted 10 years ago
@BillSimpson

My version doesn't recognize complexes even if Re and Im parts are rational. I'm not certain if original poster was interested of that, either.

Also, my version leaves function for Real numbers (in the Mathematica sense; that is, approximate numbers) unevaluated. This is understandable from the viewpoint that all such finite and well-defined numbers are non-point intervals, and all such intervals contain both rational and irrational numbers. Since Mathematica can't say that all or none of them are on Rationals, it leaves the case unevaluated.

Third case is probably some non-closed-form values or arguments to exotic built-in functions that Mathematica is unable to reason to get exact value, or even the strictest domain it is in. In case of these, result would once again be left unevaluated, although more forciful FullSimplify often helps.

I guess whatever you referred to as "at least one additional" class was not yet mentioned by me...
POSTED BY: Jari Kirma
Posted 10 years ago
That was the easy obvious one which I hoped the hint would be sufficient for the original poster to recognize.

Are there more? I think I can see at least one additional class, and perhaps more which neither of these are sufficient to deal with.

Being more or less amenable to symbolic analysis by Mathematica was well beyond what I guessed the original poster, or most, might be able to address.
POSTED BY: Bill Simpson
Posted 10 years ago
@BillSimpson Hmm... let's see... how about d[1] ? Your code returns 1 for it. emoticon

In addition to treating integers as rationals, following might be more amenable to symbolic analysis by Mathematica:
d[x_] := Piecewise[{{0, Element[x, Rationals]}}, x];
POSTED BY: Jari Kirma
Posted 10 years ago
First of all thank you all for replying to my question in such a short time.
I guess I wasn't clear enough. My goal is to define this function in wolframalpha.com site and not in Mathematica.
How do I type this formula in the "calculate" field. I just need to see its graph. 
POSTED BY: pavel rogovoy
Posted 10 years ago
In[1]:= d[x_] := Piecewise[{{0, Head[x] === Rational}}, x];
d[3/4]
d[E]

Out[2]= 0

Out[3]= E

I urge you to try to find ways that this doesn't work.
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract