Linked Questions
18 questions linked to/from How is pattern specificity decided?
4
votes
0
answers
66
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 ...
0
votes
0
answers
43
views
Is this behaviour of pattern ordering of OptionsPattern stable and documented? [duplicate]
My version is 13.2. This behaviour of OptionsPattern together with `` is extracted from some complicated functions.
Motivation
<...
25
votes
5
answers
1k
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 ...
60
votes
1
answer
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 ...
16
votes
7
answers
3k
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 ...
18
votes
4
answers
1k
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 ...
11
votes
1
answer
549
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 ...
7
votes
2
answers
271
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 ...
3
votes
6
answers
305
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
...
9
votes
2
answers
233
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
1
answer
128
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 ...
5
votes
1
answer
292
views
Sorting a list of rules
When we give several definitions for a function f, the DownValues of f are automatically ...
1
vote
2
answers
113
views
Are these tacit functions? [closed]
I am new to Mathematica and am reading the primer document by Peter Young. Early on, before even introducing functions, he introduces constructions like
...
0
votes
0
answers
252
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
0
answers
135
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
0
answers
87
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
0
answers
79
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
...
1
vote
0
answers
65
views
How conflicting patterns are resolved?
I often find myself doing something like this (probably poor example, sorry)
f[x_] := 0
f[x_Plus] := 1
In the back of my mind generally ...