Tradeoffs: Stability, Predictability, and Approximations
Overall Index --
Gregorian Index --
Posix Time Index
Unavoidable Trade-offs
The library does its best to provide everything a user could want, but there are certain inherent constraints that limit what any temporal library can do. Specifically, a user much choose which two of the following three capabilities are desired in any particular application:
ライブラリは、ユーザが必要とするであろうすべてを提供するために最善を尽くす。しかし、どの時間ライブラリにも、できることを制限する固有の制約がある。
特に、ユーザはある特定のアプリケーションに、次の3つの能力の内どの2つが必要かを選ぶ:
- exact agreement with wall-clock time
- accurate math, e.g. duration calculations
- ability to handle timepoints in the future
- 壁掛け時計の時刻との厳密な一致
- 正確な数学, 例: 時間長の計算
- 未来の時間位置(timepoints)を取り扱う能力
Some libraries may implicitly promise to deliver all three, but if you actually put them to the test, only two can be true at once. This limitation is not a deficiency in the design or implementation of any particular library; rather it is a consequence of the way different time systems are defined by international standards. Let's look at each of the three cases:
あるライブラリは、3つすべてを与えると暗黙のうちに約束するかもしれない。しかし、実際にテストしてみれば、同時に2つだけが本当である。
この制限は、どんな特定のライブラリでも設計や実装の欠陥ではない;もっと正確に言えば、それは国際基準によって定義される時法系が非常に異なる結果である。
3つのケースについてそれぞれ見てみよう:
If you want exact agreement with wall-clock time, you must use either UTC or local time. If you compute a duration by subtracting one UTC time from another and you want an answer accurate to the second, the two times must not be too far in the future because leap seconds affect the count but are only determined about 6 months in advance. With local times a future duration calculation could be off by an entire hour, since legislatures can and do change DST rules at will.
壁掛け時計の時刻との厳密な一致を望むなら、UTC あるいは地域時間のいずれかを使用しなければならない。
UTC 時刻同士の差を取って時間長(duration)を計算し、秒精度が必要な場合、2つの時間はあまり遠い未来にあってはならない。なぜなら、うるう秒が計算に影響するが、そればたったの約半年前に決定されるものだからである。
地域時間については、立法機関が思うままにDST規則を変えることができ、また(実際に)変えるので、未来の時間長(duration)計算は、いつでも異常になり得る。
If you want to handle wall-clock times in the future, you won't be able (in the general case) to calculate exact durations, for the same reasons described above.
壁掛け時計の未来の時間を扱いたければ、(一般的なケースで)上述と同じ理由のために、正確な時間長(durations)を計算することができないであろう。
If you want accurate calculations with future times, you will have to use TAI or an equivalent, but the mapping from TAI to UTC or local time depends on leap seconds, so you will not have exact agreement with wall-clock time.
もし未来の時間について正確な計算を必要とするなら、TAI あるいは同等の物を使わなければならないだろう。しかし、TAI から UTC あるいは地域時間への写像はうるう秒に依存すため、壁掛け時計の時間と正確には一致しないであろう。
Stability, Predictability, and Approximations
Here is some underlying theory that helps to explain what's going on.
Remember that a temporal type, like any abstract data type (ADT),
is a set of values together with operations on those values.
ここに、何が起こっているのかを説明するのに役立つある基礎理論がある。
時間型が任意の抽象的なデータ型(ADT;Abstract Data Type)のように、それらの値に対する操作と一緒に1セットの値であることを忘れないで欲しい。
Stability
The representation of a type is stable if the bit pattern associated with a given value does not change over time.
A type with an unstable representation is unlikely to be of much
use to anyone, so we will insist that any temporal library use
only stable representations.
与えられた値に関連付いたビットパターンが時間とともに変化しない場合、型の表現は安定している。
不安定な表現を備えた型は、おそらく誰の役にも立たない。したがって、我々はどんな時間ライブラリにも安定した表現だけを使用するよう要求するだろう。
An operation on a type is stable if the result of applying the operation to a particular operand(s) does not change over time.
特定のオペランドに演算を適用する結果が時間とともに変化しない場合、型に対する演算は安定している。
Predictability
Sets are most often classified into two categories: well-defined
and ill-defined. Since a type is a set, we can extend these definitions
to cover types. For any type T, there must be a predicate
is_member( x )
which determines whether a value x is a member of type T.
This predicate must return true, false, or dont_know.
集合は、よく明確(well-defined)であるか不明確(ill-defined)であるか、の 2つのカテゴリーに分類される。
型が集合であるので、型をカバーするためにこれらの定義を拡張することができる。
任意の型 T について、値 x が型 T のメンバーかどうか決める述語 is_member( x ) があるとする。
この述語は、true, false, あるいは dont_know を返すものとする。
If for all x, is_member( x ) returns either true or false, we
say the set T is well-defined.
すべての x について、is_member( x ) が true か false のどちらかを返す場合、集合 T は明確(well-defined)であるという。
If for any x, is_member( x ) returns dont_know, we say the
set T is ill-defined.
任意の x について、is_member( x ) が dont_know を返す場合、集合 T は不明確(ill-defined)であるという。
Those are the rules normally used in math. However,
because of the special characteristics of temporal
types, it is useful to refine this view and create a third category
as follows:
それらは数学で通常使われる規則である。
しかしながら、時間型に特有な特性のために、この考察を洗練し、以下のように第3のカテゴリーを作ることは有用である:
For any temporal type T, there must be a predicate is_member( x, t )
which determines whether a value x is a member of T.
The parameter t represents the time when the predicate is evaluated.
For each xi, there must be a time ti and a value v
such that:
任意の時間型 T について、値 x が T のメンバーかどうか決める述語 is_member( x, t ) があるとする。
述語が評価されるとき、パラメータ t は時間に相当する。
xi それぞれに対して、以下のような時間 ti と値 v があるとする:
- v = true or v = false, and
- for all t < ti, is_member( xi, t ) returns dont_know, and
- for all t >= ti, is_member( xi, t ) returns v.
- v = true あるいは v = false
- t < ti である全ての t について、is_member( xi, t ) は dont_know を返す
- t >= ti である全ての t について、is_member( xi, t ) は v を返す
ti is thus the time when we "find out" whether xi is a
member of T.
Now we can define three categories of temporal types:
xi が T のメンバーであるかどうか「見つけ出す」とき、ti はこのように時間である。今、我々は時間型の 3つのカテゴリーを定義することができる:
If for all xi, ti = negative infinity,
we say the type T is predictable.
全ての xi について、ti = 負の無限大 のとき、型 T は予測可能であるという。
If for some xi, ti = positive infinity,
we say the type T is ill-formed.
ある xi について、ti = 正の無限大 のとき、型 T は不明確(ill-formed)であるという。
Otherwise we say the type T is unpredictable (this
implies that for some xi, ti is finite).
それ以外のとき、型 T は予測不能であるという。
(これは、ある xi のために ti が有限であることを意味する)
Ill-formed sets are not of much practical use, so we will
not discuss them further. In plain english the above
simply says that all the values of a predictable type are
known ahead of time, but some values of an unpredictable
type are not known until some particular time.
不明確(ill-formed)な集合には実用性がほとんど無いので、これ以上は議論しない。
上記について簡単に言えば、予測可能な型は全ての値が事前に分かっているが、予測不能な型ではいくつかの値がある特定の時間になるまで分からない。
Stability of Operations
Predictable types have a couple of important properties:
予測可能な型には2つの重要な特性がある:
- there is an order-preserving mapping from their elements onto a set of consecutive integers, and
- duration operations on their values are stable
- それらの要素から連続する整数への、順序を維持する写像が有る
- それらの値に対する時間長(duration)の演算は安定している
The practical effect of this is that duration calculations
can be implemented with simple integer subtraction.
Examples of predictable types are TAI timepoints and
Gregorian dates.
この実用上の効果は時間長(duration)の計算を単純な整数の減算で実装できるということである。
予測可能な型の例は TAI timepoints およびグレゴリオ暦の日付である。
Unpredictable types have exactly the opposite properties:
予測できない型は正反対の特性を持っている:
- there is no order-preserving mapping from their elements onto a set of consecutive integers, and
- duration operations on their values are not stable.
- それらの要素から連続する整数への、順序を維持する写像が無い
- それらの値に対する時間長(duration)の演算は安定していない
Examples of unpredictable types are UTC timepoints and
Local Time timepoints.
予測できない型の例は UTC timepoints および地域時間 timepoints である。
We can refine this a little by saying that a range within
an unpredicatable type can be predictable, and operations performed
entirely on values within that range will be stable.
For example, the range of UTC timepoints from 1970-01-01
through the present is predictable, so calculations of durations within that range will be stable.
予測不能な型の中の範囲が予測可能であり得ると示すことによって、これを少し改善することができる。また、完全にその範囲内で実行された演算は安定しているであろう。
例えば、UTC timepoints において 1970-01-01 から現在までの範囲は予測可能である。したがって、その範囲内での時間長(duration)の計算は安定しているであろう。
Approximations
These limitations are problematical, because important temporal
types like UTC and Local Time are in fact unpredictable, and
therefore operations on them are sometimes unstable. Yet as a practical matter we often want to perform this kind of operation, such as computing the duration between two timepoints in the future that are specified in Local Time.
UTC と 地域時間のような重要な時間型が実際には予測不能なので、これらの制限は問題である。また、したがって、それらに対する演算は時々不安定である。しかし、実用上の問題として、地域時間で指定される将来の 2つの時間位置(timepoints)の間の時間長(duration)を計算するようなこの種の演算を実行したいことが多々ある。
The best the library can do is to provide an approximation,
which is generally possible and for most purposes will be
good enough. Of course the documentation must specify when
an answer will be approximate (and thus unstable) and how
big the error may be. In many respects calculating with unpredictable sets is analogous to the use of floating point numbers, for which results are expected to only be approximately correct. Calculating with predictable sets would then be
analagous to the user of integers, where results are expected
to be exact.
(analagous -> analogous)
ライブラリにできる最善策は、近似値(一般に可能で、大抵の用途で十分である)を提供することである。
もちろん、文書は、答えが近似値(したがって不安定である)であること、そしてエラーがどの位の大きさになり得るのか明示しなくてはならない。
多くの点で、予測不能な集合での計算は浮動小数点数の使用(結果がほぼ正確だろうと期待されるだけ)に似ている。
予測可能な集合での計算は整数の使用と似ており、そして結果が正確であると期待される。
For situations where exact answers are required or instability cannot be tolerated, the user must
be able to specify this, and then the library should throw an
exception if the user requests a computation for which an
exact, stable answer is not possible.
正確な答えが要求されたり、不安定さを許容できない状況のために、ユーザがそれを明示できなければならない。
そして、ユーザが正確で安定した答えが得られないような計算を要求すれば、ライブラリは例外を投げるべきである。
Last modified: Wed Aug 21 14:46:55 MST 2002
by Jeff Garland © 2000-2002
Japanese Translation Copyright (C) 2003 Shoji Shinohara.