键盘快捷键

使用 跳转章节

使用 S/ 在本书内搜索

使用 ? 显示帮助页面

使用 Esc 隐藏帮助页面

Abs

The Abs function calculates the absolute value of a number.

Parameters

The Abs function accepts only one numeric parameter.

Return Value

The Abs function returns the absolute value of the input number.

Examples

Abs[-3]; (* => 3 *)
Abs[3.7]; (* => 3.7 *)
Abs[0]; (* => 0 *)
Abs[-4.2]; (* => 4.2 *)

Add

The Add function calculates the sum of a series of numbers, equivalent to the mathematical calculation of for Add[a, b, c].

Parameters

The Add function requires at least one parameter, and all parameters must be numeric values.

Return Value

The Add function returns a numeric value.

If the parameter types do not match, the Add function will throw an error and will not return any value.

Examples

Add[1, 2, 3]; (* => 6 *)
Add[1]; (* => 1 *)
Add["a"]; (* Error! *)
Add[]; (* Error! *)

All

The All function is used to check if all elements in a list satisfy a specific condition.

Parameters

The All function takes two parameters: the first is the list to be checked, and the second is the condition to be checked, which can be either a built-in function, a plugin function, or a Lambda.

Return Value

If all elements in the list satisfy the condition, the function returns #t; otherwise, it returns #f.

Examples

Let[v, {1, 2, 3, 4}];
Let[p1, All[v, Fun[{x}, Less[x, 5]]]];
Print[p1]; (* => #t *)
Let[p2, All[v, Fun[{x}, Greater[x, 2]]]];
Print[p2]; (* => #f *)

And

The And function is used to evaluate the first condition.

Parameters

The And function takes two parameters: the first parameter must be a boolean value, and the second parameter can be any value.

Return Value

The And function is short-circuited, meaning that if the first parameter returns #t, the And function will return the value of the second parameter. Otherwise, it will return #f, and the second parameter will not be evaluated.

Examples

And[#t, 2]; (* => 2 *)
And[#f, Div[1, 0]]; (* => #f *)

Any

The Any function is used to check if at least one element in a list satisfies a specific condition.

Parameters

The Any function takes two parameters: the first parameter is the list to be checked, and the second parameter is the condition to be checked.

Return Value

The Any function returns #t if there exists an element in the list that satisfies the condition, and #f otherwise.

Examples

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

Append

The Append function is used to add an element to the end of a list.

Parameters

The Append function takes two parameters: the first parameter is a list, and the second parameter is the element to be added.

Return Value

The Append function returns the modified list.

Note that in KSL, all elements are immutable and can only be shadowed, not modified in place.

Examples

Let[v, {1, 2, 3}];
Append[v, 5]; (* => {1, 2, 3, 5} *)
Eq[v, {1, 2, 3}]; (* => #t *)

Apply

The Apply function is used to apply a value that can be applied, including Lambdas, built-in functions, and plugin functions.

Parameters

The Apply function takes at least one parameter, where the first parameter is the value to be applied, and the subsequent parameters are the arguments that the value needs to accept.

Return Value

The Apply function returns the result of applying the value.

Examples

Apply[Fun[{x}, Add[x, 1]], 3]; (* => 4 *)
Apply[Append, {1, 2, 3}, 9]; (* => {1, 2, 3, 9} *)

ArcCos

The ArcCos function calculates the inverse cosine of a number.

Parameters

The ArcCos function accepts only one numeric parameter, which must be between -1 and 1.

Return Value

The ArcCos function returns the arccosine value of the input number in radians.

Examples

ArcCos[0.5]; (* => 1.0471975511965979 *)
ArcCos[-1]; (* => 3.141592653589793 *)
ArcCos[1]; (* => 0 *)

ArcSin

The ArcSin function calculates the inverse sine of a number.

Parameters

The ArcSin function accepts only one numeric parameter, which must be between -1 and 1.

Return Value

The ArcSin function returns the arcsine value of the input number in radians.

Examples

ArcSin[0.5]; (* => 0.5235987755982989 *)
ArcSin[-1]; (* => -1.5707963267948966 *)
ArcSin[1]; (* => 1.5707963267948966 *)

ArcTan

The ArcTan function calculates the inverse tangent of a number.

Parameters

The ArcTan function accepts only one numeric parameter.

Return Value

The ArcTan function returns the arctangent value of the input number in radians.

Examples

ArcTan[1]; (* => 0.7853981633974483 *)
ArcTan[-1]; (* => -0.7853981633974483 *)
ArcTan[0]; (* => 0 *)

ArcTan2

The ArcTan2 function calculates the inverse tangent of two numbers, considering the signs of both numbers to determine the quadrant.

Parameters

The ArcTan2 function accepts two numeric parameters, x and y.

Return Value

The ArcTan2 function returns the arctangent value of in radians, taking into account the signs of x and y to determine the quadrant.

Examples

ArcTan2[1, 1]; (* => 0.7853981633974483 *)
ArcTan2[1, -1]; (* => -0.7853981633974483 *)
ArcTan2[-1, 1]; (* => 2.356194490192345 *)
ArcTan2[0, 1]; (* => 1.5707963267948966 *)
ArcTan2[1, 0]; (* => 0 *)