键盘快捷键

使用 跳转章节

使用 S/ 在本书内搜索

使用 ? 显示帮助页面

使用 Esc 隐藏帮助页面

Abs

Abs[n]

Returns the absolute value of a number n.

  • Returns a non-negative Number.
Abs[3.0];   (* => 3 *)
Abs[-3.2];  (* => 3.2 *)
Abs[0];     (* => 0 *)

Add

Add[n1, n2, ...]

Computes the sum of one or more numbers. If only one argument is provided, that argument is returned unchanged.

  • Returns a Number.
Add[1, 2, 3];               (* => 6 *)
Add[1.5, 2.4, -0.2];        (* => 3.7 *)
Add[42];                    (* => 42 *)
Add[1, 2, Add[3, 2], 7];    (* => 15 *)

All

All[list, predicate]

Tests whether predicate returns #t for every element in list. Evaluation short-circuits: the function returns #f immediately upon encountering the first element for which predicate evaluates to #f.

  • Returns #t if predicate holds for all elements, or if list is empty.
  • Returns #f otherwise.
Let[v, { 1, 2, 3, 4 }];

All[v, Fun[{ x }, Less[x, 5]]];    (* => #t *)
All[v, Fun[{ x }, Greater[x, 2]]]; (* => #f *)
All[{ }, Fun[{ x }, Less[x, 0]]];   (* => #t *)

And

And[condition, expression]

Short-circuiting logical AND. Evaluates expression only if condition is #t.

  • Returns #f immediately if condition is #f.
  • Otherwise returns the result of evaluating expression (any type).
And[Greater[1, 2], #any];        (* => #f *)
And[Less[3, 5], Greater[9, 11]]; (* => #f *)
And[Less[3, 5], #val];           (* => #val *)
And[Less[3, 5], "test"];         (* => "test" *)

Any

Any[list, predicate]

Tests whether predicate returns #t for at least one element in list. Evaluation short-circuits: the function returns #t immediately upon finding the first satisfying element.

  • Returns #t if predicate holds for any element.
  • Returns #f if predicate returns #f for all elements, or if list is empty.
Let[v, { 1, 2, 3, 4 }];

Any[v, Fun[{ x }, Greater[x, 3]]]; (* => #t *)
Any[v, Fun[{ x }, Less[x, 0]]];    (* => #f *)
Any[{ }, Fun[{ x }, Greater[x, 0]]];(* => #f *)

Append

Append[list, element]

Returns a new list consisting of all elements of list followed by element. The original list is not modified.

Append[{ 1, 2, 3, 4 }, #five];  (* => {1, 2, 3, 4, #five} *)

Let[v, { 1, 2, 3, 4 }];
Append[v, 5];   (* => {1, 2, 3, 4, 5} *)
Print[v];       (* => {1, 2, 3, 4} *)

Update[v, Append[v, 5]];
Print[v];       (* => {1, 2, 3, 4, 5} *)

ArcCos

ArcCos[n]

Computes the arc-cosine (inverse cosine) of n. The input should be in the range $\left[-1, 1\right]$; values outside this range return nan.

  • Returns a Number in radians within $\left[0, \pi\right]$.
ArcCos[1];    (* => 0 *)
ArcCos[-1];   (* => 3.14159265358979 *)
ArcCos[0.5];  (* => 1.0471975511966 *)
ArcCos[2];    (* => nan *)

ArcSin

ArcSin[n]

Computes the arc-sine (inverse sine) of n. The input should be in the range $\left[-1, 1\right]$; values outside this range return nan.

  • Returns a Number in radians within $\left[-\dfrac{\pi}{2}, \dfrac{\pi}{2}\right]$.
ArcSin[1];    (* => 1.57079632679489 *)
ArcSin[-1];   (* => -1.57079632679489 *)
ArcSin[0];    (* => 0.0 *)
ArcSin[2];    (* => nan *)

ArcTan

ArcTan[n]

Computes the arc-tangent (inverse tangent) of n.

  • Returns a Number in radians within $\left(-\dfrac{\pi}{2}, \dfrac{\pi}{2}\right)$.
ArcTan[1];     (* => 0.785398163397448 *)
ArcTan[0];     (* => 0 *)
ArcTan[-100];  (* => -1.56079666010823 *)

ArcTan2

ArcTan2[x, y]

Computes the arc-tangent of y / x in radians, using the signs of both arguments to determine the correct quadrant.

  • Parameter order: (x, y) corresponds directly to mathematical coordinates. This is the reverse of the atan2(y, x) convention found in many other languages.
  • Returns a Number in radians within $\left(-\pi, \pi\right]$.
ArcTan2[1, 1];   (* => 0.785398163397448   (Quadrant 1) *)
ArcTan2[-1, 1];  (* => 2.35619449019234    (Quadrant 2) *)
ArcTan2[-1, -1]; (* => -2.35619449019234   (Quadrant 3) *)
ArcTan2[0, 1];   (* => 1.5707963267949     (positive y-axis) *)
ArcTan2[1, 0];   (* => 0                   (positive x-axis) *)