Maintainer | bastiaan.heeren@ou.nl |
---|---|

Stability | provisional |

Portability | portable (depends on ghc) |

Safe Haskell | None |

Language | Haskell98 |

Here we implemented the diagnosis for the magictrick exercise

## Synopsis

- magicTrick :: MathStoryProblem
- probHigh :: [Probability]
- probMediumLow :: [Probability]
- probLow :: [Probability]
- whereDidWeGoWrong :: Evidence -> Evidence
- fillInMissedSteps :: Evidence -> Evidence
- pDiagnosis :: SEParser Diagnosis
- oTryManyBuggyPars :: Bool
- oSkipExpressions :: Bool
- pAttempts1 :: SEParser [Diagnosis]
- pAttempts :: SEParser [Diagnosis]
- guessMagicExpr :: [Expr] -> [Expr]
- pMagicExpr :: SEParser Expr
- pVars :: SEParser [String]
- pAnnounce :: [String] -> Expr -> SEParser ()
- pConclude :: [String] -> [Expr] -> Expr -> SEParser Expr
- pStdDiagnosis :: SEParser Diagnosis
- task :: Expr -> [Op]
- taskIfZero :: [Op]
- expandOps :: [Op] -> [Attribute]
- taskExpand :: Expr -> [Attribute]
- taskForget :: Expr -> [Attribute]
- pStepsFor :: Expr -> Expr -> [Op] -> SEParser (Expr, [Step])
- pStepsPhase1 :: Expr -> Expr -> [Op] -> SEParser (Either (Expr, [Step], [Op]) (Expr, [Step], [Op]))
- pStepsPhase2 :: Expr -> Expr -> SEParser (Maybe (Expr, Step))
- pStepsPhase3 :: Expr -> Expr -> [Op] -> SEParser (Maybe (Expr, Step, [Op]))
- pStepsPhase4 :: Expr -> Expr -> [Op] -> [Step] -> SEParser (Expr, [Step], [Op])
- pTask :: (Expr -> Expr -> [Op] -> SEParser (Expr, Step)) -> Expr -> Expr -> [Op] -> SEParser (Either (Expr, [Step], [Op]) (Expr, [Step], [Op]))
- pTaskSimplify :: Expr -> Expr -> SEParser (Maybe (Expr, Step))
- pTaskForget :: Expr -> Expr -> [Op] -> [Step] -> SEParser (Expr, [Step], [Op])
- pTaskErr :: Expr -> Expr -> [Op] -> SEParser (Maybe (Expr, Step, [Op]))
- pStepOperators :: Expr -> Expr -> [Op] -> SEParser (Expr, Step)
- pStepError :: Expr -> Expr -> [Op] -> SEParser (Expr, Step)
- pStepForget :: Expr -> Expr -> Op -> Op -> SEParser (Expr, Step)
- pStep :: Expr -> Expr -> [Op] -> SEParser (Expr, [Attribute])
- pStepErr :: Expr -> Expr -> [Op] -> SEParser (Expr, [Attribute])
- pBuggyStep :: Expr -> Expr -> [Op] -> SEParser (Expr, [Attribute])
- pStepSimplify :: Expr -> Expr -> SEParser (Expr, [Attribute])
- pExplicitSimplifyEq :: Expr -> Expr -> SEParser (Expr, [Attribute])
- pExplicitSimplifyExpr :: Expr -> SEParser (Expr, [Attribute])
- pStepEquation :: Expr -> Expr -> [Op] -> SEParser (Expr, [Attribute])
- pStepExpr :: Expr -> Expr -> [Op] -> SEParser (Expr, [Attribute])
- pNextStepBuggyPars :: Expr -> Expr -> SEParser (Expr, [Attribute])
- splits :: [a] -> [([a], [a])]
- pIf :: Alternative f => Bool -> f a -> f a
- noPars :: Expr -> [Expr]
- dropParensString :: String -> [String]
- pFixEqCom :: Equation Expr -> SEParser (Expr, [Attribute])
- pMatchEq :: Equation Expr -> Equation Expr -> SEParser (Expr, [Attribute])
- pFixExprCom :: Expr -> SEParser (Expr, [Attribute])
- pMatchExpr :: Expr -> Expr -> SEParser (Expr, [Attribute])
- pEqWith :: (Expr -> (Expr, [Attribute])) -> Equation Expr -> SEParser (Equation Expr, [Attribute])
- pEqWith2 :: (Expr -> (Expr, [Attribute])) -> (Expr -> (Expr, [Attribute])) -> Equation Expr -> SEParser (Equation Expr, [Attribute])
- pEqWithL :: (Expr -> (Expr, [Attribute])) -> Expr -> SEParser (Expr, [Attribute])
- hasCommonality :: [Attribute] -> [Attribute] -> Bool

# Documentation

probHigh :: [Probability] Source #

probMediumLow :: [Probability] Source #

probLow :: [Probability] Source #

whereDidWeGoWrong :: Evidence -> Evidence Source #

Postprocessing step on the found evidence: When there is no final answer, but there are intermediate steps, we boldly assume that the step after the last intermediate step was the culprit and we set its evidence to negative. If there were no intermediate steps, we set the first step of each strategy to negative.

fillInMissedSteps :: Evidence -> Evidence Source #

Postprocessing steps on the found evidence. When all the nodes on the LHS are present in the evidence but none on the RHS are, we set evidence to the nodes on the RHS. Note that it is evaluated left-to-right, so later steps should appear first.

pAttempts1 :: SEParser [Diagnosis] Source #

pAttempts :: SEParser [Diagnosis] Source #

Tries to parse many attempts. If one fails then skip one input and try again until no input is left.

guessMagicExpr :: [Expr] -> [Expr] Source #

pStdDiagnosis :: SEParser Diagnosis Source #

Main diagnosis function.

First we guess some magic expression and then try to recognize the formula

taskIfZero :: [Op] Source #

taskExpand :: Expr -> [Attribute] Source #

taskForget :: Expr -> [Attribute] Source #

pStepsFor :: Expr -> Expr -> [Op] -> SEParser (Expr, [Step]) Source #

Pipeline for recognition

The pipeline consists of 4 phases:

- Parse correct steps
- Parse a simplification step
- Forget a step
- A mistake was made. Try fixing the step

These phases are passed through linearly, but a phase may go back to phase 1 before reaching the latter phases.

pStepsPhase1 :: Expr -> Expr -> [Op] -> SEParser (Either (Expr, [Step], [Op]) (Expr, [Step], [Op])) Source #

:: (Expr -> Expr -> [Op] -> SEParser (Expr, Step)) | to use recognition strategy |

-> Expr | magic expression |

-> Expr | current expression |

-> [Op] | remaining operators |

-> SEParser (Either (Expr, [Step], [Op]) (Expr, [Step], [Op])) |

Expands the current formula with a different number of operators.

Then attempts are made to recognize this formula.

pTaskSimplify :: Expr -> Expr -> SEParser (Maybe (Expr, Step)) Source #

tries to match the current formula to some simplified form of that formula

pTaskForget :: Expr -> Expr -> [Op] -> [Step] -> SEParser (Expr, [Step], [Op]) Source #

It's possible some operation was forgotten to be added

pTaskErr :: Expr -> Expr -> [Op] -> SEParser (Maybe (Expr, Step, [Op])) Source #

See if an error was made given the next operation

:: Expr | magic expression |

-> Expr | the current expression |

-> [Op] | list of operators to be added |

-> SEParser (Expr, [Attribute]) |

Parse a step

Equation step, expression step or some erronuous step

:: Expr | magic expression |

-> Expr | the current expression |

-> [Op] | list of operators to be added |

-> SEParser (Expr, [Attribute]) |

pStepExpr probeert een expressie te parsen
probeer eerst zonder normaliseren (maar modulo comm*assoc*distr)
probeer dan met normaliseren (dan telt de stap/berekening als impliciet)
probeer dan met fout correctie.

pIf :: Alternative f => Bool -> f a -> f a Source #

dropParensString :: String -> [String] Source #

pEqWith :: (Expr -> (Expr, [Attribute])) -> Equation Expr -> SEParser (Equation Expr, [Attribute]) Source #

pEqWith2 :: (Expr -> (Expr, [Attribute])) -> (Expr -> (Expr, [Attribute])) -> Equation Expr -> SEParser (Equation Expr, [Attribute]) Source #