ivy/notebooks/ivy12.ipynb

238 строки
5.2 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A basic test of using ivy1 with ivy2\n",
"\n",
"This notebook should be run when both ivy2/ivy and ivy2/src/ivy are in PYTHONPATH. Later we should change this to use packages."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from os.path import dirname, join\n",
"\n",
"import ivy # ivy1\n",
"from z3_utils import z3_implies # ivy2\n",
"\n",
"ag = ivy.ivy_new()\n",
"fn = join(dirname(ivy.__file__), '../../examples/ivy/client_server_sorted.ivy')\n",
"ivy.ivy_load_file(open(fn), ag)\n",
"s = ag.execute_action('connect')\n",
"f = s.to_formula()\n",
"\n",
"z3_implies(f, f)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from IPython.display import display\n",
"from IPython.html.widgets import Textarea\n",
"from widget_ivy_concept_graph import IvyConceptGraphWidget\n",
"from concept_interactive_session import ConceptInteractiveSession"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from collections import OrderedDict\n",
"from concept import Concept, ConceptDomain, get_standard_combiners, get_standard_combinations\n",
"from logic import *"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"client_sort = UninterpretedSort('client')\n",
"server_sort = UninterpretedSort('server')\n",
"\n",
"c = Const('c', FunctionSort(client_sort, server_sort, Boolean))\n",
"s = Const('s', FunctionSort(server_sort, Boolean))\n",
"\n",
"X = Var('X', client_sort)\n",
"Y = Var('Y', server_sort)\n",
"A0 = Var('A0', client_sort)\n",
"B0 = Var('B0', server_sort)\n",
"C0 = Var('C0', c.sort)\n",
"S0 = Var('S0', s.sort)\n",
"\n",
"concepts = OrderedDict()\n",
"concepts['client'] = Concept([X], Eq(X,X))\n",
"concepts['server'] = Concept([Y], Eq(Y,Y))\n",
"concepts['s'] = Concept([Y], s(Y))\n",
"concepts['c'] = Concept([X,Y], c(X,Y))\n",
"concepts['nodes'] = ['client', 'server']\n",
"concepts['edges'] = ['c']\n",
"concepts['node_labels'] = ['s']\n",
"\n",
"\n",
"cd = ConceptDomain(concepts, get_standard_combiners(), get_standard_combinations())\n",
"cd.output()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"cd.get_facts()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"w = IvyConceptGraphWidget()\n",
"w.label_box = Textarea()\n",
"session = ConceptInteractiveSession(cd, f, [], w)\n",
"display(w)\n",
"display(w.label_box)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"session.split('server', 's')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"a = Const('a', client_sort)\n",
"b = Const('b', server_sort)\n",
"c = And(Not(s(b)), c(a,b))\n",
"session.push()\n",
"session.constrains.append(c)\n",
"session.recompute()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from IPython.html.widgets import HBox\n",
"w1, w2 = IvyConceptGraphWidget(), IvyConceptGraphWidget()\n",
"w1.width = '200px'\n",
"w2.width = '200px'\n",
"h = HBox([w1, w2])\n",
"display(h)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"w1.background_color = 'red'\n",
"w1.margin = w2.margin = h.margin = '10px'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"c1 = (w1, w2)\n",
"w3, w4 = IvyConceptGraphWidget(), IvyConceptGraphWidget()\n",
"w3.width = '200px'\n",
"w4.width = '200px'\n",
"w3.background_color = 'blue'\n",
"w4.background_color = 'yellow'\n",
"c2 = (w3, w4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"h.children = c1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"h.children = c2"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}