추상 위키백과/예시/함수 합성

From Meta, a Wikimedia project coordination wiki
This page is a translated version of the page Abstract Wikipedia/Examples/Function composition and the translation is 100% complete.

메일링 리스트를 통한 추상 위키백과 IRC의 추상 위키백과 텔레그램의 위키함수 마스토돈의 위키함수 트위터의 위키함수 페이스북의 위키함수 유튜브의 위키함수 위키함수 웹사이트 Translate

이 페이지의 함수 합성 및 함수 선언의 예는 왼쪽에 영어로 표시된 Z객체의 레이블과 오른쪽에 실제 표현(ZID 사용)을 보여줍니다.

불리언 부정

단일 내장 함수(Z802/if)를 사용하는 하나의 인수.

Z12401/부정(함수)

{
  "type": "Function",
  "arguments": [{
    "type": "Argument declaration",
    "argument type": "Boolean",
    "key": "Z12401K1",
    "label": {
      "type": "Multilingual text",
      "texts": [{
        "type": "Monolingual text",
        "language": "en",
        "text": "x"
      }]
    }
  }],
  "return type": "Boolean",
  "testers": [],
  "implementations": [
    "negation implementation"
  ],
  "identity": "negation"
}
{
  "Z1K1": "Z8",
  "Z8K1": [{
    "Z1K1": "Z17",
    "Z17K1": "Z40",
    "Z17K2": "Z12401K1",
    "Z17K3": {
      "Z1K1": "Z12",
      "Z12K1": [{
        "Z1K1": "Z11",
        "Z11K1": "en",
        "Z11K2": "x"
      }]
    }
  }],
  "Z8K2": "Z40",
  "Z8K3": [],
  "Z8K4": [
    "Z12402"
  ],
  "Z8K5": "Z12401"
}

Z12402/부정 구현(구현)

{
  "type": "Implementation",
  "function": "negation",
  "composition": {
    "type": "Function call",
    "function": "if",
    "condition": {
      "type": "Argument reference",
      "argument": "x"
    },
    "consequent": "false",
    "alternative": "true"
  }
}
{
  "Z1K1": "Z14",
  "Z14K1": "Z12401",
  "Z14K2": {
    "Z1K1": "Z7",
    "Z7K1": "Z802",
    "Z802K1": {
      "Z1K1": "Z18",
      "Z18K1": "Z12401K1"
    },
    "Z802K2": "Z42",
    "Z803K3": "Z41"
  }
}

불리언 곱

두 개의 인수이지만 여전히 하나의 단일 내장 함수(Z802/if)만 사용합니다. 두 가지 다른 방식으로 인수를 반환합니다. 한 번은 직접, 한 번은 내장의 결과로 반환합니다.

Z12411/곱 (함수)

{
  "type": "Function",
  "arguments": [{
    "type": "Argument declaration",
    "argument type": "Boolean",
    "key": "Z12411K1",
    "label": {
      "type": "Multilingual text",
      "texts": [{
        "type": "Monolingual text",
        "language": "en",
        "text": "left"
      }]
    }
  }, {
    "type": "Argument declaration",
    "argument type": "Boolean",
    "key": "Z12411K2",
    "label": {
      "type": "Multilingual text",
      "texts": [{
        "type": "Monolingual text",
        "language": "en",
        "text": "right"
      }]
    }
  }],
  "return type": "Boolean",
  "testers": [],
  "implementations": [
    "and implementation"
  ],
  "identity": "and"
}
{
  "Z1K1": "Z8",
  "Z8K1": [{
    "Z1K1": "Z17",
    "Z17K1": "Z40",
    "Z17K2": "Z12411K1",
    "Z17K3": {
      "Z1K1": "Z12",
      "Z12K1": [{
        "Z1K1": "Z11",
        "Z11K1": "en",
        "Z11K2": "left"
      }]
    }
  }, {
    "Z1K1": "Z17",
    "Z17K1": "Z40",
    "Z17K2": "Z12411K2",
    "Z17K3": {
      "Z1K1": "Z12",
      "Z12K1": [{
        "Z1K1": "Z11",
        "Z11K1": "en",
        "Z11K2": "right"
      }]
    }
  }],
  "Z8K2": "Z40",
  "Z8K3": [],
  "Z8K4": [
    "Z12412"
  ],
  "Z8K5": "Z12411"
}

Z12412/곱 구현 (구현)

{
  "type": "Implementation",
  "function": "and",
  "composition": {
    "type": "Function call",
    "function": "if",
    "condition": {
      "type": "Argument reference",
      "argument": "left"
    },
    "consequent": {
      "type": "Argument reference",
      "argument": "right"
    },
    "alternative": "false"
  }
}
{
  "Z1K1": "Z14",
  "Z14K1": "Z12411",
  "Z14K2": {
    "Z1K1": "Z7",
    "Z7K1": "Z802",
    "Z802K1": {
      "Z1K1": "Z18",
      "Z18K1": "Z12411K1"
    },
    "Z802K2": {
      "Z1K1": "Z18",
      "Z18K1": "Z12411K2"
    },
    "Z803K3": "Z42"
  }
}

불리언 합

이전과 같이 두 가지 인수. 그러나 이번에는 두 가지 구현, 즉 두 가지 구성이 있으며 그 중 하나는 이전 두 함수에 대한 중첩 함수 호출을 수행합니다.

Z12421/합 (함수)

{
  "type": "Function",
  "arguments": [{
    "type": "Argument declaration",
    "argument type": "Boolean",
    "key": "Z12401K1",
    "label": {
      "type": "Multilingual text",
      "texts": [{
        "type": "Monolingual text",
        "language": "en",
        "text": "left"
      }]
    }
  }, {
    "type": "Argument declaration",
    "argument type": "Boolean",
    "key": "Z12401K2",
    "label": {
      "type": "Multilingual text",
      "texts": [{
        "type": "Monolingual text",
        "language": "en",
        "text": "right"
      }]
    }
  }],
  "return type": "Boolean",
  "testers": [],
  "implementations": [
    "or implementation",
    "or implementation with builtins"
  ],
  "identity": "or"
}
{
  "Z1K1": "Z8",
  "Z8K1": [{
    "Z1K1": "Z17",
    "Z17K1": "Z40",
    "Z17K2": "Z12421K1",
    "Z17K3": {
      "Z1K1": "Z12",
      "Z12K1": [{
        "Z1K1": "Z11",
        "Z11K1": "en",
        "Z11K2": "left"
      }]
    }
  }, {
    "Z1K1": "Z17",
    "Z17K1": "Z40",
    "Z17K2": "Z12421K2",
    "Z17K3": {
      "Z1K1": "Z12",
      "Z12K1": [{
        "Z1K1": "Z11",
        "Z11K1": "en",
        "Z11K2": "right"
      }]
    }
  }],
  "Z8K2": "Z40",
  "Z8K3": [],
  "Z8K4": [
    "Z12422",
    "Z12423"
  ],
  "Z8K5": "Z12421"
}

Z12422/합 구현 (구현)

{
  "type": "Implementation",
  "function": "or",
  "composition": {
    "type": "Function call",
    "function": "negation",
    "x": {
      "type": "Function call",
      "function": "and",
      "left": {
        "type": "Function call",
        "function": "negation",
        "x": {
          "type": "Argument reference",
          "argument": "left"
        }
      },
      "right": {
        "type": "Function call",
        "function": "negation",
        "x": {
          "type": "Argument reference",
          "argument": "right"
        }
      }
    }
  }
}
{
  "Z1K1": "Z14",
  "Z14K1": "Z12421",
  "Z14K2": {
    "Z1K1": "Z7",
    "Z7K1": "Z12401",
    "Z12401K1": {
      "Z1K1": "Z7",
      "Z7K1": "Z12411",
      "Z12411K1": {
        "Z1K1": "Z7",
        "Z7K1": "Z12401",
        "Z12401K1": {
          "Z1K1": "Z18",
          "Z18K1": "Z12421K1"
        }
      },
      "Z12411K2": {
        "Z1K1": "Z7",
        "Z7K1": "Z12401",
        "Z12401K1": {
          "Z1K1": "Z18",
          "Z18K1": "Z12421K2"
        }
      }
    }
  }
}

Z12423/합 내장으로 구현 (구현)

{
  "type": "Implementation",
  "function": "or",
  "composition": {
    "type": "Function call",
    "function": "if",
    "condition": {
      "type": "Argument reference",
      "argument": "left"
    },
    "consequent": "true",
    "alternative": {
      "type": "Argument reference",
      "argument": "right"
    }
  }
}
{
  "Z1K1": "Z14",
  "Z14K1": "Z12411",
  "Z14K2": {
    "Z1K1": "Z7",
    "Z7K1": "Z802",
    "Z802K1": {
      "Z1K1": "Z18",
      "Z18K1": "Z12411K1"
    },
    "Z802K2": "Z41",
    "Z803K3": {
      "Z1K1": "Z18",
      "Z18K1": "Z12411K2"
    }
  }
}

아이디

이것은 Z8/함수에서 작동합니다. 그것은 또한 Z1/객체, 즉 무엇이든 작동할 수 있습니다. 이것은 람다 적분학에서 타이 I 조합기와 정렬하기 위해 Z8을 사용했습니다.


Z12001/아이디 (함수)

{
  "type": "Function",
  "arguments": [
    {
      "type": "Argument declaration",
      "argument type": "Function",
      "key": "Z12001K1",
      "label": {
        "type": "Multilingual text",
        "texts": [
          {
            "type": "Monolingual text",
            "language": "en",
            "text": "f"
          }
        ]
      }
    }
  ],
  "return type": "Function",
  "testers": [],
  "implementations": [
    "identity implementation"
  ],
  "identity": "identity"
}
{
  "Z1K1": "Z8",
  "Z8K1": [
    {
      "Z1K1": "Z17",
      "Z17K1": "Z8",
      "Z17K2": "Z12001K1",
      "Z17K3": {
        "Z1K1": "Z12",
        "Z12K1": [
          {
            "Z1K1": "Z11",
            "Z11K1": "en",
            "Z11K2": "f"
          }
        ]
      }
    }
  ],
  "Z8K2": "Z8",
  "Z8K3": [],
  "Z8K4": [
    "Z12002"
  ],
  "Z8K5": "Z12001"
}

Z12002/아이디 구현 (구현)

{
  "type": "Implementation",
  "function": "identity",
  "composition": {
    "type": "Argument reference",
    "argument": "f"
  }
}
{
  "Z1K1": "Z14",
  "Z14K1": "Z12001",
  "Z14K2": {
    "Z1K1": "Z18",
    "Z18K1": "Z12001K1"
  }
}

자체 애플리케이션

이것은 함수를 받아서 그 함수를 자신에게 적용하는 함수입니다.

인수에 대한 로컬 키를 처음으로 사용합니다(구현에서 K1 참조).

확장 목표로 Z12011에 적용된 Z12011은 자체적으로 생산하므로 고정점임을 인식하고 해당 고정점을 반환해야 합니다(즉, Z12011(Z12011)의 결과는 Z12011(Z12011)여야 합니다).

Z12011/자체 애플리케이션(함수)

{
  "type": "Function",
  "arguments": [{
    "type": "Argument declaration",
    "argument type": "Function",
    "key": "Z12011K1",
    "labels": {
      "type": "Multilingual text",
      "texts": [{
        "type": "Monolingual text",
        "language": "en",
        "text": "f"
      }]
    }
  }],
  "return type": "Function",
  "testers": [],
  "implementations": [
    "self application implementation"
  ],
  "identity": "self application"
}
{
  "Z1K1": "Z8",
  "Z8K1": [{
    "Z1K1": "Z17",
    "Z17K1": "Z8",
    "Z17K2": "Z12011K1",
    "Z17K3": {
      "Z1K1": "Z12",
      "Z12K1": [{
        "Z1K1": "Z11",
        "Z11K1": "en",
        "Z11K2": "f"
      }]
    }
  }],
  "Z8K2": "Z8",
  "Z8K3": [],
  "Z8K4": [
    "Z12012"
  ],
  "Z8K5": "Z12011"
}

Z12012/자체 애플리케이션 구현(구현)

{
  "type": "Implementation",
  "function": "self application",
  "composition": {
    "type": "Function call",
    "function": {
      "type": "Argument reference",
      "argument": "f"
    },
    "K1": {
      "type": "Argument reference",
      "argument": "f"
    }
  }
}
{
  "Z1K1": "Z14",
  "Z14K1": "Z12011",
  "Z14K2": {
    "Z1K1": "Z7",
    "Z7K1": {
      "Z1K1": "Z18",
      "Z18K1": "Z12011K1"
    },
    "K1": {
      "Z1K1": "Z18",
      "Z18K1": "Z12011K1"
    }
  }
}

K 결합자

이것은 함수 x를 취하고 함수를 취하지만 입력이 무엇이든 상관없이 이전에 주어진 함수 x를 반환하는 함수를 반환하는 함수입니다. 이것을 K 결합자(K는 상수)라고 합니다. 그것은 약간의 폐쇄를 제공합니다.

알파 변환이 작동하는지 확인합니다. 결과적으로 내장 구현으로 함수를 빌드합니다.

Z12021/k 결합자(함수)

{
  "type": "Function",
  "arguments": [{
    "type": "Argument declaration",
    "argument type": "Function",
    "key": "Z12021K1",
    "labels": {
      "type": "Multilingual text",
      "texts": [{
        "type": "Monolingual text",
        "language": "en",
        "text": "f"
      }]
    }
  }],
  "return type": "Function",
  "testers": [],
  "implementations": [
    "k combinator implementation"
  ],
  "identity": "k combinator"
}
{
  "Z1K1": "Z8",
  "Z8K1": [{
    "Z1K1": "Z17",
    "Z17K1": "Z8",
    "Z17K2": "Z12021K1",
    "Z17K3": {
      "Z1K1": "Z12",
      "Z12K1": [{
        "Z1K1": "Z11",
        "Z11K1": "en",
        "Z11K2": "argument"
      }]
    }
  }],
  "Z8K2": "Z8",
  "Z8K3": [],
  "Z8K4": [
    "Z12022"
  ],
  "Z8K5": "Z12021"
}

Z12022/k 결합자 (구현)

{
  "type": "Implementation",
  "function": "k combinator",
  "composition": {
    "type": "Function",
    "arguments": [{
      "type": "Argument declaration",
      "argument type": "Function",
      "key": "K1",
      "labels": {
        "type": "Multilingual text",
        "texts": [{
          "type": "Monolingual text",
          "language": "en",
          "text": "x"
        }]
      }
    }],
    "return type": "Function",
    "testers": [],
    "implementations": [{
      "type": "Implementation",
      "function": {
        "type": "Function call",
        "function": "k combinator",
        "f": {
          "type": "Argument reference",
          "reference": "f"
        }
      },
      "composition": {
        "type": "Argument reference",
        "reference": "f"
      }
    }],
    "identity": {
      "type": "Function call",
      "function": "k combinator",
      "f": {
        "type": "Argument reference",
        "reference": "f"
      }
    }
  }
}
{
  "Z1K1": "Z14",
  "Z14K1": "Z12021",
  "Z14K2": {
    "Z1K1": "Z8",
    "Z8K1": [{
      "Z1K1": "Z17",
      "Z17K1": "Z8",
      "Z17K2": "K1",
      "Z17K3": {
        "Z1K1": "Z12",
        "Z12K1": [{
          "Z1K1": "Z11",
          "Z11K1": "en",
          "Z11K2": "argument"
        }]
      }
    }],
    "Z8K2": "Z8",
    "Z8K3": [],
    "Z8K4": [{
      "Z1K1": "Z14",
      "Z14K1": {
        "Z1K1": "Z7",
        "Z7K1": "Z12021",
        "Z12021K1": {
          "Z1K1": "Z18",
          "Z18K1": "Z12021K1"
        }
      },
      "Z14K2": {
        "Z1K1": "Z18",
        "Z18K1": "Z12021K1"
      }
    }],
    "Z8K5": {
      "Z1K1": "Z7",
      "Z7K1": "Z12021",
      "Z12021K1": {
        "Z1K1": "Z18",
        "Z18K1": "Z12021K1"
      }
    }
  }
}