N上の離散圏
[追記]eqObjが定義されていると仮定できるなら、SomeCat.composable(f, g)(fとgのこの順での結合可能性)は次のように書けますね。
今度からこう書こう。以前のは直さないけど。[/追記]
return SomeCat.eqObj(SomeCat.cod(f), SomeCat.dom(g));
/* DiscCat.js -- Discrete Category over N *//* 一般的にも使えそうな関数(大域関数) */
// 自然数(0を含む)かどうかを判定する
function isNaturalNumber(x) {
return (
typeof x === 'number' && Math.floor(x) === x
&&
x >= 0
);
}/* ここから圏の定義 */
// 名前空間を提供するオブジェクト
var DiscCat = {
};// この圏の対象かどうかを判定
DiscCat.isObject = function(x) {
return isNaturalNumber(x);
};// この圏の射かどうかを判定
DiscCat.isMorphism = function(x) {
return isNaturalNumber(x);
};// 射の域
DiscCat.dom = function(f) {
if (!DiscCat.isMorphism(f)) throw "not a morphism";
return f;
};// 射の余域
DiscCat.cod = function(f) {
if (!DiscCat.isMorphism(f)) throw "not a morphism";
return f;
};// fとgが結合(合成)可能かどうかを判定
DiscCat.composable = function(f, g) {
if (!DiscCat.isMorphism(f) || !DiscCat.isMorphism(g))
throw "not a morphism"; // 今回からエラーとする
return DiscCat.cod(f) === DiscCat.dom(g); // 結合可能性の条件
};// fとgを結合(合成)
DiscCat.compose = function(f, g) {
if (!DiscCat.composable(f, g)) throw "cannot compose";
return f;
};// 恒等
DiscCat.id = function(n) {
if (!DiscCat.isObject(n)) throw "not an object";
return n;
};// 対象のコンストラクタ
DiscCat.obj = function(n) {
if (!isNaturalNumber(n)) throw "invalid argument";
return n;
};// 射のコンストラクタ
DiscCat.mor = function(n) {
if (!isNaturalNumber(n)) throw "invalid argument";
return n;
};// 対象が等しいかどうかを判定
DiscCat.eqObj = function(n, m) {
if (!DiscCat.isObject(n) || !DiscCat.isObject(m))
throw "not an object";
return n === m;
};// 射が等しいかどうかを判定
DiscCat.eqMor = function(f, g) {
if (!DiscCat.isMorphism(f) || !DiscCat.isMorphism(g))
throw "not a morphism";
return f === g;
};