Go to the first, previous, next, last section, table of contents.


宣言の種類

宣言の型式記述部(s d コマンドの2番目のプロンプト)は、 1個の型式記号か1個の区間、あるいはそれらのベクトルです。 ベクトルの場合は、その要素を次の順に並べます。

  1. ゼロ個以上の型式記号
  2. ゼロ個以上の(変数がとりうる)区間または数値集合
[ [ a, [1, 2, 3, 4, 5] ]
  [ b, [1 .. 5]        ]
  [ c, [int, 1 .. 5]   ] ]

a には、 示された5つの整数のどれかひとつの値がストアされる、と宣言されています。 b は閉区間1〜5の範囲の(型は指定していないので実数)値です。 c は示された区間内の整数です。 従って ac の宣言はほとんど同じです(後述)。

型式記述部には、空ベクトル `[]' も指定できて、 その場合は「指定の変数に関する情報無し」という意味になります。 これはその変数について何も指定しないのと全く同じですが、 他に All 宣言がある場合にはこうしておかないと適用されてしまいます。

Decls の初期値は空ベクトル `[]' です。 Decls に何もストアされていなかったり、 そこにストアされている値が無効だったりすると、 それは無視されて、宣言は何も無いとみなされます。 (s d コマンドは、新しい宣言を書込む前に、 そのような壊れた値を初期値の空行列 `[]' に置換えます。) 認識できない型式記号は無視されます。

ある変数にどんなデータ型式がストアされるかを宣言する型式記号を、 以下にリストします。

int
整数[Integers]
numint
数値的整数[Numerical integers] :整数または整数値をとる浮動小数
frac
分数(Fractions) :整数以外の有理数
rat
有理数(Rational numbers) :整数と分数
float
浮動小数[Floating-point numbers]
real
実数[Real numbers] (整数, 分数, 浮動小数。ここでは区間型式や誤差型式も実数とみなします。)
pos
nonneg
number

Calc uses this information to determine when certain simplifications of formulas are safe. For example, `(x^y)^z' cannot be simplified to `x^(y z)' in general; for example, `((-3)^2)^1:2' is 3, but `(-3)^(2*1:2) = (-3)^1' is -3. However, this simplification is safe if z is known to be an integer, or if x is known to be a nonnegative real number. If you have given declarations that allow Calc to deduce either of these facts, Calc will perform this simplification of the formula.

Calc can apply a certain amount of logic when using declarations. For example, `(x^y)^(2n+1)' will be simplified if n has been declared int; Calc knows that an integer times an integer, plus an integer, must always be an integer. (In fact, Calc would simplify `(-x)^(2n+1)' to `-(x^(2n+1))' since it is able to determine that `2n+1' must be an odd integer.)

Similarly, `(abs(x)^y)^z' will be simplified to `abs(x)^(y z)' because Calc knows that the abs function always returns a nonnegative real. If you had a myabs function that also had this property, you could get Calc to recognize it by adding the row `[myabs(), nonneg]' to the Decls matrix.

One instance of this simplification is `sqrt(x^2)' (since the sqrt function is effectively a one-half power). Normally Calc leaves this formula alone. After the command s d x RET real RET, however, it can simplify the formula to `abs(x)'. And after s d x RET nonneg RET, Calc can simplify this formula all the way to `x'.

If there are any intervals or real numbers in the type specifier, they comprise the set of possible values that the variable or function being declared can have. In particular, the type symbol real is effectively the same as the range `[-inf .. inf]' (note that infinity is included in the range of possible values); pos is the same as `(0 .. inf]', and nonneg is the same as `[0 .. inf]'. Saying `[real, [-5 .. 5]]' is redundant because the fact that the variable is real can be deduced just from the interval, but `[int, [-5 .. 5]]' and `[rat, [-5 .. 5]]' are useful combinations.

Note that the vector of intervals or numbers is in the same format used by Calc's set-manipulation commands. Set Operations using Vectors 参照 .

The type specifier `[1, 2, 3]' is equivalent to `[numint, 1, 2, 3]', not to `[int, 1, 2, 3]'. In other words, the range of possible values means only that the variable's value must be numerically equal to a number in that range, but not that it must be equal in type as well. Calc's set operations act the same way; `in(2, [1., 2., 3.])' and `in(1.5, [1:2, 3:2, 5:2])' both report "true."

If you use a conflicting combination of type specifiers, the results are unpredictable. An example is `[pos, [0 .. 5]]', where the interval does not lie in the range described by the type symbol.

"Real" declarations mostly affect simplifications involving powers like the one described above. Another case where they are used is in the a P command which returns a list of all roots of a polynomial; if the variable has been declared real, only the real roots (if any) will be included in the list.

"Integer" declarations are used for simplifications which are valid only when certain values are integers (such as `(x^y)^z' shown above).

Another command that makes use of declarations is a s, when simplifying equations and inequalities. It will cancel x from both sides of `a x = b x' only if it is sure x is non-zero, say, because it has a pos declaration. To declare specifically that x is real and non-zero, use `[[-inf .. 0), (0 .. inf]]'. (There is no way in the current notation to say that x is nonzero but not necessarily real.) The a e command does "unsafe" simplifications, including cancelling `x' from the equation when `x' is not known to be nonzero.

Another set of type symbols distinguish between scalars and vectors.

scalar
The value is not a vector.
vector
The value is a vector.
matrix
The value is a matrix (a rectangular vector of vectors).

These type symbols can be combined with the other type symbols described above; `[int, matrix]' describes an object which is a matrix of integers.

Scalar/vector declarations are used to determine whether certain algebraic operations are safe. For example, `[a, b, c] + x' is normally not simplified to `[a + x, b + x, c + x]', but it will be if x has been declared scalar. On the other hand, multiplication is usually assumed to be commutative, but the terms in `x y' will never be exchanged if both x and y are known to be vectors or matrices. (Calc currently never distinguishes between vector and matrix declarations.)

行列モードとスカラ・モード 参照 , for a discussion of "matrix mode" and "scalar mode," which are similar to declaring `[All, matrix]' or `[All, scalar]' but much more convenient.

One more type symbol that is recognized is used with the H a d command for taking total derivatives of a formula. 微積分(Calculus) 参照 .

const
The value is a constant with respect to other variables.

Calc does not check the declarations for a variable when you store a value in it. However, storing -3.5 in a variable that has been declared pos, int, or matrix may have unexpected effects; Calc may evaluate `sqrt(x^2)' to 3.5 if it substitutes the value first, or to -3.5 if x was declared pos and the formula `sqrt(x^2)' is simplified to `x' before the value is substituted. Before using a variable for a new purpose, it is best to use s d or s D to check to make sure you don't still have an old declaration for the variable that will conflict with its new meaning.


Go to the first, previous, next, last section, table of contents.     利用度数