Linked Questions

4
votes
0answers
65 views

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 ...
23
votes
5answers
999 views

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 ...
16
votes
7answers
2k views

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 ...
56
votes
1answer
2k views

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 ...
14
votes
4answers
833 views

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 ...
9
votes
1answer
389 views

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 ...
3
votes
6answers
284 views

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 ...
6
votes
2answers
227 views

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 ...
9
votes
2answers
220 views

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 ...
6
votes
1answer
104 views

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 ...
4
votes
1answer
180 views

Sorting a list of rules

When we give several definitions for a function f, the DownValues of f are automatically ...
0
votes
0answers
212 views

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: ...
1
vote
0answers
112 views

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 ...
0
votes
0answers
82 views

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 ...
3
votes
0answers
74 views

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

15 30 50 per page