Skip to content

Feature/polya #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion dialoghelper/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,21 @@
'dialoghelper.core.read_msg': ('core.html#read_msg', 'dialoghelper/core.py'),
'dialoghelper.core.read_msg_ids': ('core.html#read_msg_ids', 'dialoghelper/core.py'),
'dialoghelper.core.update_msg': ('core.html#update_msg', 'dialoghelper/core.py')},
'dialoghelper.db_dc': {}}}
'dialoghelper.db_dc': {},
'dialoghelper.polya': { 'dialoghelper.polya.PolyaAct': ('polya.html#polyaact', 'dialoghelper/polya.py'),
'dialoghelper.polya.PolyaAct.__init__': ('polya.html#polyaact.__init__', 'dialoghelper/polya.py'),
'dialoghelper.polya.PolyaPlan': ('polya.html#polyaplan', 'dialoghelper/polya.py'),
'dialoghelper.polya.PolyaPlan.__init__': ('polya.html#polyaplan.__init__', 'dialoghelper/polya.py'),
'dialoghelper.polya.PolyaReview': ('polya.html#polyareview', 'dialoghelper/polya.py'),
'dialoghelper.polya.PolyaReview.__init__': ('polya.html#polyareview.__init__', 'dialoghelper/polya.py'),
'dialoghelper.polya.PolyaUnderstand': ('polya.html#polyaunderstand', 'dialoghelper/polya.py'),
'dialoghelper.polya.PolyaUnderstand.__init__': ( 'polya.html#polyaunderstand.__init__',
'dialoghelper/polya.py'),
'dialoghelper.polya.QQ': ('polya.html#qq', 'dialoghelper/polya.py'),
'dialoghelper.polya.QQ.__call__': ('polya.html#qq.__call__', 'dialoghelper/polya.py'),
'dialoghelper.polya.QQ.__init__': ('polya.html#qq.__init__', 'dialoghelper/polya.py'),
'dialoghelper.polya.QQ.__repr__': ('polya.html#qq.__repr__', 'dialoghelper/polya.py'),
'dialoghelper.polya.Step': ('polya.html#step', 'dialoghelper/polya.py'),
'dialoghelper.polya.Step.__iter__': ('polya.html#step.__iter__', 'dialoghelper/polya.py'),
'dialoghelper.polya.Step.__repr__': ('polya.html#step.__repr__', 'dialoghelper/polya.py'),
'dialoghelper.polya.Step._children': ('polya.html#step._children', 'dialoghelper/polya.py')}}}
98 changes: 98 additions & 0 deletions dialoghelper/polya.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""Implement Polya questions as SolveIt prompt messages"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_polya.ipynb.

# %% auto 0
__all__ = ['understand', 'plan', 'act', 'review', 'Step', 'QQ', 'PolyaUnderstand', 'PolyaPlan', 'PolyaAct', 'PolyaReview']

# %% ../nbs/01_polya.ipynb
from .core import *

# %% ../nbs/01_polya.ipynb
# Step: inspired by contextpack.Topic
class Step:
def _children(self):
return [c for c in dir(self) if not c.startswith('_') or c in ('get','getter','docs')]
def __iter__(self):
yield from (getattr(self, name) for name in self._children()
if isinstance(getattr(self, name),QQ))
def __repr__(self):
s = ''
if self.__doc__: s += f"doc: {self.__doc__}\n"
if (cs := self._children()): s += "\n".join([c + ": " + repr(getattr(self, c)) for c in cs])
return s

# QQ replaces the SolveIt cell with its given question/prompt/note
class QQ:
def __init__(self, content, msg_type="prompt"):
self.content = content
self.msg_type = msg_type

def __call__(self):
update_msg(content=self.content, msg_type=self.msg_type, sid=read_msg(0).sid)

def __repr__(self):
return f"({self.msg_type}) \"{self.content}\""


# %% ../nbs/01_polya.ipynb
class PolyaUnderstand(Step):
def __init__(self):
self.summary = QQ("Could you please give a concise summary of the problem?")
self.info = QQ("What information do we have? What information do we not have? What might change as we learn more?")
self.similar = QQ("Have you seen a similar problem before?")
self.lateral = QQ("Can you relate this problem to a more general or a more specific problem?")
self.related = QQ("Can you think of a related problem that we can solve? It could even be a simpler one we could solve first to help understand this one.")
self.viz = QQ("Can we create a figure or diagram to represent of the problem?")
self.notation = QQ("Can we pick a suitable notation (e.g. symbols for quantities/data, states, and transitions)?")
self.simplest = QQ("What might be the simplest way to look at this problem?")
self.simplify = QQ("Can we separate the various parts of the problem (e.g. break down complex conditions into simpler ones)?")


# %% ../nbs/01_polya.ipynb
class PolyaPlan(Step):
def __init__(self):
self.chunks = QQ("Could you please break down the problem into smaller sub-problems?")
self.partial = QQ("Is there a smaller part or representation of the problem we could solve?")
self.known_approach = QQ("Could we use a known algorithm or library to solve the problem, or some of it?")
self.verifiable = QQ("How would we verify if our solution is consistent and correct?")
self.backward = QQ("Can we work backward from the desired result?")
self.aux = QQ("Could we use an auxiliary element (e.g., a variable, diagram, or example) to clarify the path?")
self.analogy = QQ("Can you use analogy or similarity to relate the problem to a known solution?")


# %% ../nbs/01_polya.ipynb
class PolyaAct(Step):
def __init__(self):
self.review = QQ("Could you please critique the plan of attack? Be frank, do not be afraid to be critical.")
self.doubt = QQ("Are we using the right approach?")
self.other = QQ("Is there another way to look at this?")
self.partial = QQ("Are there any intermediate results or milestones that we can aim for?")
self.symmetry = QQ("Are there any symmetries or patterns in the problem that we can exploit?")
self.next = QQ("What is next?")
self.valid = QQ("Does this step seem to have been a valid step?")
self.check = QQ("Does this step seem correct?")
self.simpler = QQ("Was there a simpler way we could have done this step?")
self.all = QQ("Did we cover all of the data or examples for this step?")


# %% ../nbs/01_polya.ipynb
class PolyaReview(Step):
def __init__(self):
self.all = QQ("Did we cover all of the data or examples for this problem?")
self.sanity = QQ("Does the result make sense? Can we verify by substition or another method?")
self.grok = QQ("**To consider:** Can I understand the solution without having to perform all the steps?", "note")
self.learned = QQ("What lessons have I learned from this?")
self.general = QQ("Can we generalize the solution to other similar problems?")
self.alter = QQ("Can you think of alternative solutions or approaches that might be more efficient or effective?")
self.other = QQ("Can we derive the result differently?")
self.simpler = QQ("Can we derive the result in a simpler way?")
self.principles = QQ("Can you identify any underlying principles or patterns that emerged during the solution process?")
self.test = QQ("What are some different ways we can test this?")


# %% ../nbs/01_polya.ipynb
understand = PolyaUnderstand()
plan = PolyaPlan()
act = PolyaAct()
review = PolyaReview()
18 changes: 15 additions & 3 deletions nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"outputs": [],
"source": [
"db = get_db(globals())\n",
"dlg = db.t.dialog.selectone()\n",
"dlg = db.t.dialog.fetchone()\n",
"dlg"
]
},
Expand Down Expand Up @@ -713,7 +713,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -732,9 +732,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "python3",
"display_name": "Python 3 (ipykernel)",
"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.11.7"
}
},
"nbformat": 4,
Expand Down
Loading