Linked Questions

4 votes
0 answers

Precedence of defined functions [duplicate]

When I define functions in Mathematica like: f[x_] := 3 f[x_Integer] := 6 How is the value of f[6] determined? It seems to ...
Tom's user avatar
  • 153
25 votes
5 answers

How can one manually change the rule ordering

I have a function which has some general behavior, but that should act on some specific kinds of objects in some other way. I know that Mathematica is supposed to automatically order the rules so that ...
Lior Blech's user avatar
16 votes
7 answers

A function that accepts a pair or a list of pairs

Probably a duplicate, but it's not easy to search on "lists". I have a function that accepts a list of lists, say {{a1, b1}, {a2, b2}, {a3, b3}} and performs some ...
rogerl's user avatar
  • 4,105
58 votes
1 answer

How to generally match, unify and merge patterns?

This question was split from this one. While that question is now about how to match two particular patterns (mostly using Verbatim or ...
István Zachar's user avatar
18 votes
4 answers

When is a symbol a Symbol? Is there an easy Mathematica way to test if an object is a symbol sort of like a SymbolQ?

Yes I know there is no built-in native function called SymbolQ (but JavaScript does). However, could one be simulated to work for most cases? I often rely on ...
Jules Manson's user avatar
  • 2,347
10 votes
1 answer

Is there a defined priority for pattern matching?

If you define a function g, like so: g[x_?EvenQ] := "even" g[x_?NumberQ] := "number" why will Mathematica always return ...
wgoodall01's user avatar
3 votes
6 answers

Making strict replacements in Mathematica

My question is quite a simple one, but I have not been able to find a solution yet. Say I have terms of the form e.g 1/n1/n2/n3/n4 and ...
CAF's user avatar
  • 510
6 votes
2 answers

What makes a pattern more general?

This is a rewording of the question. The original post is below. How come that a pattern for an expression with a specific head is not more specific than a pattern for an expression with a generic ...
Hector's user avatar
  • 6,398
9 votes
2 answers

Which function definition is used to evaluate an expression that matches the lefthand side of more than one definition?

In a case like this: f[a_] := a; f[{a_, b_}] := a; I'm wondering whether I should expect f[{2, 3}] to return ...
Coolwater's user avatar
  • 19.7k
6 votes
1 answer

Counterintuitive DownValue precedence

Consider the following definitions for two symbols: foo[a] /; True := b foo[a] := a foo[a] (* a *) foo2[a_] /; True := b foo2[a_] := a foo2[a] (* b *) (The ...
Lukas Lang's user avatar
  • 32.1k
5 votes
1 answer

Sorting a list of rules

When we give several definitions for a function f, the DownValues of f are automatically ...
Fred Simons's user avatar
  • 9,949
0 votes
0 answers

On the order of rules specification [duplicate]

I wanted to understand how Mathematica parses function definitions in rules-based programming, so I started with the simple code: ...
Shredderroy's user avatar
  • 4,957
1 vote
0 answers

Upvalues and order of interpretation

I'm trying to use UpValues to improve the usability of some code, but I am running into an issue where the order of the UpValues is important, and I am not sure if it is my understanding or a ...
James Jones's user avatar
0 votes
0 answers

How does Wolfram Language implement for enabling symbols to receive various forms of parameters? [duplicate]

How does the official implement a list/tuple of parameters that can be different in type and quantity as a whole? After re-read @Szabolcs's and @MichaelE2's comments. Finally, I accepted the ...
ooo's user avatar
  • 554
3 votes
0 answers

What's the role of the lines order in defining a function?

I'm totally surprised by the finding I had never noticed before. This code works as obviously intended ...
mitochondrial's user avatar

15 30 50 per page