Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Model Strengthening #379
Adding domain attributes; adding, modifying and removing constraints; changing types.
Adds the new
Compilation warns about variables
Added the Conjure.UI.StrengthenVariables module which at the moment does nothing. Its function is called on Essence code, so it is ready to be implemented.
Adding functions that fetch references to a variable: - the variable's definition or declaration - constraints involving the variable - other declarations involving the variable Implemented finding a variable's definition or declaration.
Moved the variable strengthening code to the correct place in Process and added it as a command-line option for acting purely on the essence class.
Added a function to work with function attributes, which does nothing at the moment other than print the domain. The function can notify the caller of whether or not it modified the domain, which is passed to the top level to decide when to stop making passes.
As a test, making function attributes (total, bijective) if it is surjective and its domain is equal to its codomain. This is a proof of concept for attribute computing and rewriting.
Refactored the framework for strengthening variables so that the functions only deal with single statements and the model for context. The Modified data type is now used better and with better functions to correctly propagate modification of values.
Removed the use of Modified from StrengthenVariables and now comparing Models when deciding whether to loop again or not. This simplifies the code and allows it to be made monadic so that helper functions which themselves are monadic can be used.
All functions in StrengthenVariables are now monadic, in the sense that they return a `m a` where m is at least a MonadFail.
Comparing function domains by size when determining whether they should be transformed from surjective to total and bijective. If the domainSizeOf calculation results in an error, it is logged for development purposes but otherwise ignored for transformation.
Finding variables with integer domains so that they can have them reduced by analysing their relations to other variables in the `such that` part of the model.
Fetching the list of expressions in the such that section of the model by recursing down the expression tree and writing up the expressions that contain a reference to the variable.
Using the method described by Finlay Marno in his dissertation for domain reduction, which requires expressions to be converted to arithmetic relations.
Simplified the use of Writer to extract the expressions that refer to a variable. Now using execWriter and no longer using two functions for varInExpr.
Simplified the `findCallingExpressions` function and added more explanatory comments to the `varInExp` function.
Rewriting the ArithRelation tree of an expression to place the variable of interest alone on the right of the equality, which allows the left side to be used in constraining the domain.
ArithRef has been changed to hold the reference expression, instead of only the name, so that domainOf can be used on it when performing domain arithmetic for possible reduction.
Bijective functions for which the domain and codomain are of equal size are now also marked as being total.
Combining two domains into more constrained domains, by using min and max expressions when both bounds are set, or by taking a bound when one is set but not the other. Single domain ranges ignore the other domain, even if it is another single value. Non-overlapping domains are not found and should be an error.
Finished a first effort at arithmetic domain reduction which on the surface appears to correctly follow the theory, but still appears to be incorrect.
Combining values in OpMin and OpMax in the same matrix, instead of creating deeply (in fact infinitely due to repeated transformations) nested min and max expressions. If an expression being added to the min or the max expression is already contained within it, then it is not added, as there is no need to compare it to itself.
Added a FIXME comment identifying the source of an error in the transferBranchRL when the right side is a non-commutative operation.
Fixed the arithmetic relation tree transformations when applying a subtraction or a division to both sides to isolate the variable in question. Unfortunately the theory that is applied does not appear to be correct.
Simplified the handling of subtraction and division special cases when transforming the tree to bring the variable of interest onto the right side. Also extracted 'where' functions from liftEqual to the top level.
Thanks @Druid-of-Luhn -- I want to look into the code a bit more before merging, but this looks very nicely structured so my job there will be easy.
Did you try running any of the tests? We will see what travis thinks soon, but I will also run the whole test suite (with --limit-time 0, to run all tests, travis doesn't do that) before merging.
One of the tests failed (GHC 8.0.2, help text files differ or something) but the others errored during compilation:
Conflicting definitions for 'v' Bound at: src/Conjure/Process/ModelStrengthening.hs:818:23-62 src/Conjure/Process/ModelStrengthening.hs:818:23-62 In a case alternative [essence| forAll &x, &y in &v, &x' != &y' . &_ |]
From running tests locally:
Last two are
Oh, I see what it is!
See the repeated v's. The parser expands
The two tests that fail are different help texts (fixed I think, but running local tests without limit takes a while), and
If you run
If you run
Could it be from me uncommenting this code in