ivy/notebooks/client_server_demo.ipynb

481 строка
8.9 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from proof import AnalysisSession\n",
"from widget_analysis_session import AnalysisSessionWidget\n",
"from tactics_api import *\n",
"from tactics import RecalculateFacts, RefineOrReverse\n",
"from ivy_logic_utils import true_clauses, false_clauses"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"w = AnalysisSessionWidget()\n",
"session = AnalysisSession('../examples/ivy/client_server_sorted.ivy', w)\n",
"set_context(session)\n",
"w"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"refine_or_reverse = RefineOrReverse()\n",
"recalculate_facts = RecalculateFacts()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"w._concept.concept_session.split('server', 's')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"init = arg_add_initial_node()\n",
"step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"e0 = arg_add_action_node(init, get_action('error'))\n",
"recalculate_facts(e0, [false_clauses()])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"a1 = arg_add_action_node(init, get_action('connect'))\n",
"recalculate_facts(a1, [false_clauses()])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"e1 = arg_add_action_node(a1, get_action('error'))\n",
"recalculate_facts(e1, [false_clauses()])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"g1 = goal_at_arg_node(true_clauses(), e1)\n",
"push_goal(g1)\n",
"step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"refine_or_reverse(g1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"push_goal(get_diagram(top_goal()))\n",
"step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"refine_or_reverse(top_goal())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"while top_goal() is not None and refuted_goal(top_goal()):\n",
" remove_goal(top_goal())\n",
" step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"recalculate_facts(e1, [false_clauses()])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"while top_goal() is not None and refuted_goal(top_goal()):\n",
" remove_goal(top_goal())\n",
" step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"a2 = arg_add_action_node(a1, get_action('connect'))\n",
"recalculate_facts(a1, [false_clauses()])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"recalculate_facts(a2, arg_get_conjuncts(arg_get_pred(a2)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"e2 = arg_add_action_node(a2, get_action('error'))\n",
"recalculate_facts(e2, [false_clauses()])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"g2 = goal_at_arg_node(true_clauses(), e2)\n",
"push_goal(g2)\n",
"step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"push_goal(get_diagram(top_goal()))\n",
"step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"refine_or_reverse(top_goal())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"push_goal(get_diagram(top_goal()))\n",
"step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"refine_or_reverse(top_goal())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"push_goal(get_diagram(top_goal()))\n",
"step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"refine_or_reverse(top_goal())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"while top_goal() is not None and refuted_goal(top_goal()):\n",
" remove_goal(top_goal())\n",
" step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"recalculate_facts(a2, arg_get_conjuncts(arg_get_pred(a2)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"while top_goal() is not None and refuted_goal(top_goal()):\n",
" remove_goal(top_goal())\n",
" step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"n = top_goal().node\n",
"recalculate_facts(n, arg_get_conjuncts(arg_get_pred(n)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"recalculate_facts(e2, [false_clauses()])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"while top_goal() is not None and refuted_goal(top_goal()):\n",
" remove_goal(top_goal())\n",
" step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"arg_is_covered(a2, a1)\n",
"step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"a3 = arg_add_action_node(a1, get_action('disconnect'))\n",
"recalculate_facts(a3, [false_clauses()])\n",
"recalculate_facts(a3, arg_get_conjuncts(arg_get_pred(a3)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"e3 = arg_add_action_node(a3, get_action('error'))\n",
"recalculate_facts(e3, [false_clauses()])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"arg_is_covered(a3, a1)\n",
"step()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"refuted_goal(top_goal())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"w.render()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"session.analysis_state.ivy_ag.states[2]"
]
}
],
"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
}