Skip to content

Commit

Permalink
Fix: no leading zeros in CALC_GRAMMAR
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-zeller committed Jan 6, 2025
1 parent b832418 commit b3f6fd1
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions notebooks/Alhazen.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,6 @@
"Additional test inputs are generated and executed to refine or refute the hypothesis, eventually obtaining a prediction model of the circumstances of why the behavior in question takes place."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- _Alhazen_ is a tool that automatically learns the circumstances of program failure by associating syntactical features of sample inputs with the execution outcome. The produced explanations (in the form of a decision tree) help developers focus on the input space's relevant aspects. -->"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -167,11 +160,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In a nutshell, this is how Alhazen works.\n",
"Let us give a high-level description of how Alhazen works, illustrated above.\n",
"\n",
"Alhazen is given an _input grammar_ and a number of _input files_ (whose format is given by the grammar),\n",
"and produces a _decision tree_ – a machine learning model that explains under which circumstances the program fails.\n",
"\n",
"Alhazen determines and refines these decision trees in five steps, illustrated above.\n",
"Alhazen determines and refines these decision trees in five steps:\n",
"\n",
"1. For each input file, Alhazen extracts a number of _input features_ that apply.\n",
" These input features are predicates over the individual elements of the input grammar, such as `<expr> > 0` (an `<expr>` element is larger than zero) or `exists(<minus-sign>)` (the input contains a minus sign).\n",
Expand Down Expand Up @@ -277,29 +271,37 @@
" \"<term>\": [\"-<value>\", \"<value>\"],\n",
"\n",
" \"<value>\":\n",
" [\"<integer>.<integer>\",\n",
" [\"<integer>.<digits>\",\n",
" \"<integer>\"],\n",
"\n",
" \"<integer>\":\n",
" [\"<digit><integer>\", \"<digit>\"],\n",
" [\"<lead-digit><digits>\", \"<digit>\"],\n",
"\n",
" \"<digits>\":\n",
" [\"<digit><digits>\", \"<digit>\"],\n",
"\n",
" \"<lead-digit>\": # First digit cannot be zero\n",
" [\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"],\n",
"\n",
" \"<digit>\":\n",
" [\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"]\n",
" [\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"],\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We see that the `CALCULATOR` Grammar consists of several production rules. The calculator subject will only accept inputs that conform to this grammar definition."
"We see that the `CALC_GRAMMAR` consists of several production rules. The calculator subject will only accept inputs that conform to this grammar definition."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, lets load two initial input samples:"
"Now, let us load two initial input samples:\n",
"- `sqrt(-16)`\n",
"- `sqrt(4)`"
]
},
{
Expand All @@ -312,17 +314,6 @@
"initial_sample_list = ['sqrt(-16)', 'sqrt(4)']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The two initial input samples for our calculator should be:\n",
"- _sqrt(-16)_\n",
"- _sqrt(4)_\n",
"\n",
"Let's check if this is true with python's `assert` function. The condition is True, if no Assertion is thrown."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down

0 comments on commit b3f6fd1

Please sign in to comment.