What is ___ vs _ in Mathematica ?

  • Mathematica
  • Thread starter Physics_rocks
  • Start date
  • Tags
    Mathematica
In summary, "lis_list" means that the variable "lis" can only match a list in the Mathematica declaration "myfunc[lis_list]". Additionally, the symbols "_" and "__" represent patterns that can match any single expression or sequence of expressions, respectively. It is recommended to consult Mathematica's help system for more information on pattern matching.
  • #1
Physics_rocks
12
0
Hi guys ,

I have the next declaration in Mathematica :

myfunc [lis_list]

and myfync [x_,y___]

what does "lis_list" means ? I know that when I want to declare a variable of a function
I must write myfunc[SomeVar_] with one _
but what are 3 times _ (meaning ___)

I hope I'm no asking a stupid question :)

thanks !
 
Physics news on Phys.org
  • #2
I don't think it does anything? Testing it, it seems to have no effect.
 
  • #3
_ is a pattern which can stand for any single expression, whereas ___ is a pattern that can stand for any sequence of 0 or more expressions. There is also __ which is a pattern that can stand for any sequence of 1 or more expressions.
 
  • #4
Physics_rocks said:
what does "lis_list" means ?
It means that "lis" is only allowed to match a list, methinks. Mathematica's help system has a section on pattern matching -- it might be useful to go read it.
 

Related to What is ___ vs _ in Mathematica ?

1. What is the difference between == and === in Mathematica?

The == (Equal) and === (SameQ) operators in Mathematica both perform comparisons between two expressions. However, the main difference is that == only compares the numerical values of the expressions, while === also takes into account the structure and type of the expressions. This means that === is a stricter equality test than ==, and will return True only if both the values and the structure of the expressions are identical.

2. What is the purpose of the function N in Mathematica?

The N function in Mathematica is used to numerically evaluate an expression. This is particularly useful for expressions that involve symbolic or exact values, as N will return a numerical approximation of the result. It is also commonly used to convert exact numbers (such as fractions) into decimal approximations.

3. What is the difference between Set and SetDelayed in Mathematica?

Both Set ( = ) and SetDelayed ( := ) are used to define values or functions in Mathematica. The main difference is that Set evaluates the right-hand side of the expression immediately, while SetDelayed only evaluates it when the expression is needed. This means that SetDelayed is often used for defining functions, as it allows the function to be evaluated with different input values.

4. What is the purpose of the function Plot in Mathematica?

The Plot function in Mathematica is used to visualize the graph of a function or expression. It takes in a mathematical expression and plots it on a coordinate system, with the x-axis representing the input values and the y-axis representing the output values. It is a useful tool for understanding the behavior of a function and identifying key features such as roots, extrema, and asymptotes.

5. What is the difference between a List and a Table in Mathematica?

A List in Mathematica is a collection of elements, similar to an array in other programming languages. It can hold any type of data and can be indexed to access specific elements. On the other hand, a Table in Mathematica is a way to generate a list of values by applying a function to a range of input values. In other words, a List is a data structure, while a Table is a tool for creating lists.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
0
Views
434
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
19
Views
581
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Back
Top