I have been reading about how symbolic languages works, focusing more on Mathematica. As far as I could understand, to evaluate is to apply a sequence of transformation rules to the input until no more matching transformations rule could be found and call the result of it "output".

But then comes the problem: what to do when more than one of those transformation rule match a given expression? I tried this first example:

```
A[x_, 3] := 0;
A[x_, y_] := 1;
A[a, b]
=> 1
A[k, 3]
=> 0
```

I believe I can explain this by saying `3`

matches `3`

"better" than `y`

. Then my second experiment:

```
B[x_, 3] := 0;
B[4, y_] := 1;
B[4, 3]
=> 0
```

Why is this? I expected to see some kind of error.

The precidnece is simply by the order in which the functions were defined.

```
ClearAll[B]
B[x_, 3] := 0;
B[4, y_] := 1;
B[4, 3]
(* 0 *)
ClearAll[B]
B[4, y_] := 1;
B[x_, 3] := 0;
B[4, 3]
(* 1 *)
```

Watch out, things get confusing if you re-define functions..

```
ClearAll[B]
B[x_, 3] := 0;
B[4, y_] := 1;
B[4, y_] := 2;
B[x_, 3] := 3;
B[4, 3]
(* 3 *)
```

Notice the definitons are correctly changed but the order goes according to the original sequence. (hence liberal use of ClearAll while working with these sorts of things)

to see the order use:

```
??B
```

Similar Questions

c:\wxwidgets-2.8.11\include\wx\filename.h(497): error C2668: 'wxGetTranslation' : ambiguous call to overloaded function c:\bitcoin\src\util.h(191): could be 'const char *wxGetTranslation(const char *)

Does anyone know how to access a secure website using Mathematica? I am trying to login using Mathematica's built-in browser and access certain webpages which require a user to be logged in to access

Here are two statements from my Mathematica program. Print[ExpandAll[Chop[Integrate[Resi*Cos[7*1*\[Theta]]*Sin[(1*Pi*x)/L], {\[Theta], 0,2*Pi},{x,0, L}], 10^-6]]]; This line gives me the output 1043.

I need to read the bean definitions from a Spring context file, practically reading what is inside the XML. I do not want to instantiate beans, I just want to read the content of the file. While I can

I am trying to normalize a database I am building. One part of it is that I have many different tests that each can have many different tags. How would you deal with this? Would you have a table with

Why does the following style of code work: BroadcastReceiver receiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { //do something based on the intent's action }

I know what is going on, but I don't know how to fix this: main.cpp #include Win32.h int main () { return 0; } Win32.h #include <windows.h> #include <map> #ifndef WIN32_H_ #define WIN32

Any pattern&practise here for documentation in Haskell? Are there anything as elegant/handy as what Python does below? >>> help([].count) Help on built-in function count: count(...) L.cou

The mathematica documentation on Evaluate at possible issues says: Evaluate works only on the first level, directly inside a held function Why does Mathematica have this limitation? So if I have an

How does Mathematica handle double-buffering for Graphics display? Is it done automatically? The reason I am asking, is that when I do some animation, depending on the animation rate, I notice annoyin

How do I tell mathematica to do this replacement smartly? (or how do I get smarter at telling mathematica to do what i want) expr = b + c d + ec + 2 a; expr /. a + b :> 1 Out = 2 a + b + c d + ec

I think I am starting to understand how to link functions written in C/C++ to Mathematica. The problem I'm facing is that I don't know how to send error messages from my C wrapper to Mathematica. Afte

I am working on toy problems to help me assimilate the idea of pattern matching in Mathematica. The following code does not behave as I expected, and I could not figure out what is wrong with my under

There is a problem that gpio_request need a GPIO number, but in the kernel it needs a address to deal with the gpio, how does the Linux achieve this? Alway in the chip spec, such as MSM8x60 or whateve

It seems like gcov does not report inline definitions of class methods as executable lines. Example: #include <iostream> struct Foo { void bar() {} void baz() {} }; int main() { Foo foo; foo.bar

I was wondering how to deal with large and complex files in a XmlReader. In my case it's a pretty complex structure and I'm not okay with handling all of this inside a single-method. This is just too

Does FSI deal well with multi module/file F# projects? Consider the following project: module.fs: module Xyz let add x y = x + y Program.fs: module Program open Xyz let result = add 1 2 selecting an

It's easy to get a list unused functions and variables with linker feedback, but how can I detect those unused macro definitions & typedefs? Do I have to browse the code line by line and git grep

I am getting 3 camera input to MATLAB with Infinite Trigger. But after minutes, cameras fill up my memory, and I have to restart MATLAB. How can I deal with this memory problem?

How does one create and perform differentiation on tuple valued functions in Mathematica. More specifically, I have the following functions, where R denotes the real line f:R^2 -> R^3 g:R^3 ->

Can somebody tell me how to extract my table definitions using SQL? I want to extract the datatypes of all my tables and other information from my Oracle schema. I have about 100 tables. I need the co

In Mathematica, how do you plot a horizontal line at a given number? How do you plot a vertical line at a given number?

Can someone tell me why my application crashes here ? and why it does not crash when i replace the YES objects with NSString values ? all i want to do is to store boolean data into array and to modify

How does CouchDb deal with growing documents that run out of contiguous disk space at the end? And moreover what is CouchDb's strategy for allocating disk space for documents where it has no idea how

Does anybody know of, or have, a reasonable implementation of SOMs in Mathematica?

I'm not sure how to deal with wcag's 2.0 success criterion 1.2.5. It says: Audio description is provided for all prerecorded video content in synchronized media Do i have to provide an audio descrip

I have an ambiguous type variable error on the definition of trial below, I am wondering if there is anything that can be done to make this situation work? I want to really just deal with instances

is there a correct or accepted way to deal with assert failure in debug / release mode? For instance: let's say I have a function that returns a std::vector I expect the length of the returned vector

I've just begun learning about ColdFusion ORM and persistent cfcs and how it can improve application performance. I'm still working on gaining a full understanding before trying to implement anything

Im not sure how i should deal with a HTTP_STATUS of 302 in my response to an API request? Im trying to write a small Node.js script and i have a feeling this is to do with the HTTPS upgrade of the req

In Mathematica, the documentation for ClearAll states: ClearAll[symb1, symb2, ...] clears values, definitions, attributes, messages, and defaults with symbols. It also supports a similar format wher

How can I do Mathematica-style a = Table[2^(2 k) + 1, {k, 1, 3}] Last[a], First[a] Append[a,3] in Octave?

Good day, I thought earlier that Mathematica creates new symbols in the current $Context at the stage of converting of the input string (that is assigned to InString) to input expression (that is assi

How can I replace all occurrence of user defined latex macros with their definitions? For example, given this file old.tex \newcommand{\blah}[2]{#1 \to #2} ... foo \blah{egg}{spam} bar ... how to gen

I'm curious if someone can point me to (or just describe) how, given that an Android application has an extremely limited memory space to play with (I think it's around 20 megs), a video player can lo

I'd like to know how can I call Mathematica functions from Python. I appreciate a example, for example, using the Mathematica function Prime. I had search about MathLink but how to use it in Python is

I am looking for the prototypical 'Hello World' program that creates a Mathematica Notebook file. I have this working program. package graphica; import com.wolfram.jlink.*; /** * * @author Nilo */ pu

I have a few database servers and few developers. I have set up database connection definitions on my PC for each servers and now I want to share with other developers but I was not sure how to export

Run the following code In Mathematica: r=6197/3122; p[k_,w_]:=Sqrt[w^2/r^2-k^2];q[k_,w_]:=Sqrt[w^2-k^2]; a[k_,w_,p_,q_]:=(k^2-q^2)^2 Sin[p]Cos[q]+4k^2 p q Cos[p]Sin[q] a[k_,w_]:=a[k,w,p[k,w],q[k,w]];

Using Solve function in Mathematica, we may get several solutions, e.g. In[1]:= Solve[x == 1 && 2 >= y >= 1, {x, y}, Integers] Out[1]= {{x -> 1, y -> 1}, {x -> 1, y -> 2}}

I want to write a block of C code and send it to every processor to execute it Is that possible using mathematica? using gateway to link C with mathematica or what ever thank you all .. :)

While trying to overlay a new line to a existing ggplot I am getting the following error: Error: ggplot2 doesn't know how to deal with data of class uneval The first part of my code works fine. Belo

I was messing around to see what I could and could not do with regards to generics. I have this situation and as far as I'm concerned the compiler should throw an error with regards to ambiguous metho

How do you put additional information into a Mathematica package file, like parameter specification doctests/example usage? Up to now, I only found the ::usage string and some information on how to

This is a high-level question and I am sure there is no universally correct answer but I really would like to learn more about the different ways of doing this: How does one best deal with parameters

How do you deal with source control management and automated deployment (configuration management) of database tables. I work in a SQL Server environment and it's pretty easy to script out drop and cr

I had tried the code below in Mathematica 8: f[z_] := (5 + 1/(z-a)) / ( 8 + 1/(z-a)) f[a] and surprisingly I got following warnings: Power::infy: Infinite expression 1/0 encountered. >> Power::

I did not understand how a unambiguous grammar is derived from a ambiguous grammar? Consider the example on site: Example. How was the grammar derived is confusing to me. Can anyone please guide me ?

I'm trying to solve a rather large linear programming problem in Mathematica, but for some reason the bottleneck is setting up the array of linear constraints. My code for initializing the matrix look

How to get the code of all replication definitions of a Sybase server? If possible and since I'm new to this, give me a little explanation on them as well.