# Tag Info

Accepted

### 2D random walk within a bounded area

To answer your question: I don't think it's a bad or good idea to use If. It depends on how you do it. To demonstrate I'll use If...
Accepted

### Quick way to use conditioned patterns when defining multi-argument function?

Ramblings Arguments of the left-hand-side head are evaluated in the course of function definition, therefore you can use a utility function that constructs the patterns that you want. For example: <...

### 2D random walk within a bounded area

I suggest using Mod - a natural thing for looped boundary conditions on a torus. Finite torus surface area is your bounded region. 2D random walk generally is ...
Accepted

### Double Sum Involving Condition

A story of incremental improvement Let's look at the OP's original expression again, for reference: $$\sum_{m=1}^{c}\frac{1}{m}\sum_{d \mid m}\mu(d)n^{m/d}$$ Most people here are familiar with <...

### Difference between Piecewise, Which, If?

The main difference is their intended use. Which is a "programming function". It is meant for flow control. It is an equivalent of ...
Accepted

### Question about Rules and Pattern (The operator patt/;test)

When using Set rather than SetDelayed you will need to hang the Condition on the left-hand-...
Accepted

### Generating Tuples with restrictions

Select[ IntegerPartitions[24, {8}, Range], #.# == 86 & ] ...

### Flatten not working

f[...] := Module[{...}, ... /; condition] is a very special syntax (documented in the Details section of Module). It only works ...

### Arrange a list in ascending order by deleting list elements

You can use DeleteDuplicates with Greater as the second argument: ...
Accepted

### Multiple lines in an If statement

It seems this question is now purely about style and will probably be closed. However I think you may be looking for this: ...
Accepted

### How to define conditional function with Mathematica?

I think it's easier just to define this straight up, rather than compute something procedurally. f[1, 0] = 77; f[0, 1] = 66; f[_, _] = 0; Mathematica is ...

### 2D random walk within a bounded area

Here's my implement of a random walk within a circle using If and FoldList. Please see @Pickett's answer for more thorough ...
Accepted

### Can one compile the Switch function?

A drawback of the Which command is that it evaluates x repeatedly until one of the conditions of Which is satisfied. This is time consuming when x is a complicated expression or/and when the set of ...
Accepted

### How to optimize the following function?

Using Ramp and vectorized operations: y = -.02 Range[0, 4 10^5]; Total @ Sqrt[Ramp[1 - 2 Exp[y]]] //AbsoluteTiming {0....
Accepted

### Weird behavior of conditions when using OptionsPattern and OptionValue

Note: This is an incomplete analysis and leads to the wrong conclusion about the cause of the difficulty. Mr.W's answer below correctly identifies the culprit as ...
Accepted

### Checking what a function depends on

Perhaps InternalDependsOnQ: h = f[x, g[y]]; InternalDependsOnQ[h, #] & /@ {x, y, g[y], w} {True, True, True, False}

### Add assumptions to Solve command

The ConditionalExpression output by Solve in your case does not really depend on the whole argument of the ...
Accepted

### How to restrict the domain of a function

I think the easiest way is to use Condition which has the operator form /;. ...
Accepted

### conditional probability of dependent random variables

As @BobHanlon points out that the probability is zero for a specific value. But probabilities are not (necessarily) 0 in intervals. So we can get a probability statement for an interval and then ...
Accepted

### Switch inside Manipulate controls statement

Perhaps this? ...
Accepted

### Why does pattern test work only with pure functions?

The two ways of attaching a test to a pattern, Condition and PatternTest, have fundamentally different semantics. Your mistake ...

### Generating Tuples with restrictions

A slightly different approach with Reduce (or Solve) We define: matC = Range; (* the list of the integers from which we build a list *) Let us use a vector ...
Accepted

### Generate "nice" random matrix

You can create random matrices until the eigenvalues do not have a Root form: ...

### How to avoid applying Cross to a single argument?

If it is only for displaying purposes you can use Row: ...

### Flatten not working

Put Flatten inside Module: ...

### Need four random values in a range which total unity

Because you have very tight constraints, the number of allowed points is not very large, so you can generate all of them and then sample. ...
Accepted

### Can someone tell me what's wrong with this nested IF?

Change it to === and not == (examples at end) ...
Accepted

### DeleteCases does not work with EvenQ? While Select works fine

For the selection criterion, Select uses a (pure) function, while *Cases uses a pattern. Code below works. ...
You can use RegionWithin in Mathematica $11.1$ ...