Created
March 8, 2018 21:19
-
-
Save dunossauro/98064a94c7d446fa6fcac0c416934ada to your computer and use it in GitHub Desktop.
Revisão teoria dos conjuntos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "source": [ | |
| "# Revisão dos axiomas usando Python" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "source": [ | |
| "### a) Axioma da existência do conjunto vazio\n", | |
| "\n", | |
| "# ∃B∀x(x ∉ B) ⇒ ∅\n", | |
| "\n", | |
| "* Para a definição de 'para todo (∀)' usarei um iterador[for] (uma maneira de percorrer todos os itens de um determinado conjunto)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "metadata": { | |
| "collapsed": false, | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "set()\n", | |
| "{1}\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "B = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}\n", | |
| "\n", | |
| "print({x for x in {11, 12, 13} if x in B}) # Um conjunto vazio\n", | |
| "print({x for x in {1, 11, 12, 13} if x in B}) # Um conjunto com elementos" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "source": [ | |
| "### b) Axioma da extencionalidade\n", | |
| "\n", | |
| "Se dois conjuntos tem os mesmos elementos, então, são o mesmo conjunto\n", | |
| "\n", | |
| "# ∀A∀B[∀x (x ∈ A x ∈ B) ⇒ A = B]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 10, | |
| "metadata": { | |
| "collapsed": false, | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "[True, True, True, True]\n", | |
| "True\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "A = {1, 2, 3, 4}\n", | |
| "B = {1, 2, 3, 4}\n", | |
| "\n", | |
| "print(list(map(lambda x: x in A and x in B, A))) # verifica elemento a elemento (∀)\n", | |
| "print(all(list(map(lambda x: x in A and x in B, A)))) # verifica se todas as condições são verdadeiras\n", | |
| "\n", | |
| "assert A == B # Logo, se todos os elementos são iguais, representam o mesmo conjunto" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 12, | |
| "metadata": { | |
| "collapsed": false, | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "[False, True, True, True]\n" | |
| ] | |
| }, | |
| { | |
| "ename": "AssertionError", | |
| "evalue": "", | |
| "output_type": "error", | |
| "traceback": [ | |
| "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
| "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", | |
| "\u001b[0;32m<ipython-input-12-4e75e69b00b3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mC\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mB\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mA\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# verifica se todas as condições são verdadeiras\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0mC\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mB\u001b[0m \u001b[0;31m# Logo, se todos os elementos são iguais, representam o mesmo conjunto\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
| "\u001b[0;31mAssertionError\u001b[0m: " | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "# Um contra exemplo:\n", | |
| "C = {2, 3, 4, 5}\n", | |
| "print(list(map(lambda x: x in C and x in B, B))) # verifica elemento a elemento (∀)\n", | |
| "all(list(map(lambda x: x in C and x in B, A))) # verifica se todas as condições são verdadeiras\n", | |
| "\n", | |
| "assert C == B # Logo, se todos os elementos são iguais, representam o mesmo conjunto" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "source": [ | |
| "### c) Esquema do Ax. da compreensão\n", | |
| "\n", | |
| "\n", | |
| "# ∀A∃B(x ∈ A ⇔ x ∈ B ∧ P(x))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 16, | |
| "metadata": { | |
| "collapsed": false, | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "{2, 4}" | |
| ] | |
| }, | |
| "execution_count": 16, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "A = {1, 2, 3, 4}\n", | |
| "B = {1, 2, 3, 4}\n", | |
| "\n", | |
| "{x for x in B if x % 2 == 0 and x in A and x in B} # forma um novo conjunto baseado na condição p(x) -> x mod 2 == 0" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "source": [ | |
| "### d) Ax. do par\n", | |
| "\n", | |
| "\n", | |
| "# ∀A∀B∃C(x ∈ C ⇔ x ∈ A ∨ x ∈ B)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 23, | |
| "metadata": { | |
| "collapsed": false, | |
| "deletable": true, | |
| "editable": true, | |
| "scrolled": false | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "[{1, 2, 3, 4}, {8, 5, 6, 7}]\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "A = {1 ,2, 3, 4}\n", | |
| "B = {5, 6, 7, 8}\n", | |
| "\n", | |
| "C = [{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}]\n", | |
| "\n", | |
| "print([x for x in C if x == A or x == B])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "source": [ | |
| "### e) Ax. da união\n", | |
| "\n", | |
| "\n", | |
| "# ∀A∀B∃C∀x(x ∈ C ⇔ x ∈ A ∨ x ∈ B)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 27, | |
| "metadata": { | |
| "collapsed": false, | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "{1, 2, 3, 4, 5, 6, 7, 8}\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "A = {1 ,2, 3, 4}\n", | |
| "B = {5, 6, 7, 8}\n", | |
| "\n", | |
| "C = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}\n", | |
| "\n", | |
| "print({x for x in C if x in A or x in B})" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "source": [ | |
| "### f) Ax. da união generalizada\n", | |
| "\n", | |
| "# ∀x[x ∈ B ⇔ ∃b ∈ A (x ∈ B)]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "source": [ | |
| "### g) Ax. do subconjunto\n", | |
| "\n", | |
| "# ∀A∀B∀x(x ∈ B ⇔ x ∈ A ∧ P(x)]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "source": [ | |
| "### h) Ax. power set\n", | |
| "\n", | |
| "# ∀A∃B∀x(x ∈ B ⇔ x ⊆ A)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.5.2" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment