Group Abstract Group Abstract

Message Boards Message Boards

Converting the Mathematics in the Attatchments to Code

3 Replies

Piecewise conditions are evaluated in the given order: the first one that applies is chosen. They can overlap by design. If you really need non-overlap, you can try this:

s[4, x] //. ({foo___, {a1_?NumberQ, cond1_},
     {a2_?NumberQ, cond2_}, bar___} /;
    Reduce[cond1 && cond2] != False) :>
  {foo, {a1, cond1},
   {a2, Reduce[cond1 && cond2]}, bar}
POSTED BY: Gianluca Gorni

I would define s this way, for nicer formulas:

s[t_Integer, x_] := s[t, x] =
   PiecewiseExpand[Piecewise[{
       {q[(t - 1)/2], EvenQ[t - 1] &&
         0 <= Min[Abs[x - enumerateRationals[t - 1]]] <
          1/k[t - 1]},
       {k[t - 1]^2, OddQ[t - 1] &&
         0 <= Min[Abs[x - enumerateRationals[t - 1]]] <
          1/k[t - 1]}}, s[t - 1, x]]] /.
    {a_?NumberQ, cond_} :>
     {a, Reduce[cond, x, Reals]};

I don't know how to calculate the limit.

POSTED BY: Gianluca Gorni

For the sake of neatness, how do we replace the conditions of $y=0$, with the text "otherwise".

For example, with s[4,x], I want the following output:

$$\small{s_4(x)=\begin{cases} 65536& x\in(-\frac{257}{256},-\frac{255}{256})\cup(-\frac{1}{256},\frac{1}{256})\cup(\frac{255}{256},\frac{257}{256})\\ 16 & x \in(-\frac{1}{4},\frac{1}{4})\\ 0 & \text{otherwise} \end{cases}}$$

Even then, I don't think the output above is correct. The intervals in $y=16$ and $y=65536$ overlap.

POSTED BY: Bharath Krishnan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard