diff --git a/code/drasil-example/template/app/Main.hs b/code/drasil-example/template/app/Main.hs index 704d3f8fb8a..7a6082167bf 100644 --- a/code/drasil-example/template/app/Main.hs +++ b/code/drasil-example/template/app/Main.hs @@ -1,12 +1,13 @@ module Main (main) where import GHC.IO.Encoding -import Language.Drasil.Generate (gen, DocSpec(DocSpec), DocType(SRS), - Format(..), docChoices, dumpEverything) +import Language.Drasil.Generate (gen, DocSpec(DocSpec), DocType(SRS), + Format(..), docChoices, dumpEverything, typeCheckSI) import Drasil.Template.Body (fullSI, srs, printSetting) main :: IO() main = do setLocaleEncoding utf8 dumpEverything fullSI printSetting ".drasil/" + typeCheckSI fullSI gen (DocSpec (docChoices SRS [HTML, TeX, Jupyter, MDBook]) "Template_SRS") srs printSetting diff --git a/code/drasil-example/template/lib/Drasil/Template/Body.hs b/code/drasil-example/template/lib/Drasil/Template/Body.hs index 0784c043a6b..ca550b6dbbb 100644 --- a/code/drasil-example/template/lib/Drasil/Template/Body.hs +++ b/code/drasil-example/template/lib/Drasil/Template/Body.hs @@ -7,7 +7,15 @@ module Drasil.Template.Body where import Language.Drasil import Drasil.SRSDocument -import Theory.Drasil (DataDefinition, GenDefn, InstanceModel, TheoryModel) +import Theory.Drasil + ( DataDefinition, + GenDefn, + InstanceModel, + TheoryModel, + tmNoRefs, + equationalModel', + imNoDerivNoRefs, + ddENoRefs ) import qualified Language.Drasil.Sentence.Combinators as S import Data.Drasil.Concepts.Documentation (doccon, doccon', srsDomains) import Data.Drasil.Concepts.Computation (inValue, algorithm) @@ -21,6 +29,7 @@ import Data.Drasil.TheoryConcepts import Data.Drasil.Citations import Drasil.DocumentLanguage.TraceabilityGraph import Drasil.DocLang (tunitNone) +import Language.Drasil.ShortHands (cP, lP, cS, cD, lL, lM, lB, cA) srs :: Document srs = mkDoc mkSRS (S.forGen titleize phrase) si @@ -31,6 +40,9 @@ fullSI = fillcdbSRS mkSRS si printSetting :: PrintingInformation printSetting = piSys fullSI Equational defaultConfiguration +stdFields :: Fields +stdFields = [DefiningEquation, Description Verbose IncludeUnits, Notes, Source, RefBy] + mkSRS :: SRSDecl mkSRS = [TableOfContents, RefSec $ --This creates the Reference section of the SRS @@ -63,10 +75,10 @@ mkSRS = [TableOfContents, ] -- This adds a goals section and goals input is defined for the preample of the goal. , SSDSolChSpec $ SCSProg [ Assumptions - , TMs [] [] + , TMs [] (Label : stdFields) , GDs [] [] HideDerivation - , DDs [] [] HideDerivation - , IMs [] [] HideDerivation + , DDs [] (Label : stdFields) HideDerivation + , IMs [] ([Label, Input, Output, InConstraints, OutConstraints] ++ stdFields) HideDerivation , Constraints EmptyS ([] :: [UncertQ]) , CorrSolnPpties ([] :: [UncertQ]) [] @@ -93,9 +105,9 @@ si = SI { _purpose = [], _motivation = [], _scope = [], - _quants = [] :: [QuantityDict], - _instModels = [] :: [InstanceModel], - _datadefs = [] :: [DataDefinition], + _quants = quantities, -- Odd: The Table of Symbols is mostly filled without this list!!!! Also, even though the table of symbols is being filled in, there is text "There are no symbols." placed above the table! + _instModels = instanceModels, -- Surprisingly, putting this here is not what triggers it to get rendered. + _datadefs = dataDefinitions, -- ^ _configFiles = [], _inputs = [] :: [QuantityDict], _outputs = [] :: [QuantityDict], @@ -105,13 +117,41 @@ si = SI { _usedinfodb = usedDB } +quantities :: [QuantityDict] +quantities = [ + equilibriumQ, priceQ, supplyQ, demandQ, -- abstract variables + applePriceQ, linearSupplyQ, linearDemandQ, -- concrete variables + mSQ, mDQ, bSQ, bDQ, equilibriumApplePriceLinearSDQ + ] + +dataDefinitions :: [DataDefinition] +dataDefinitions = [linearSupplyDD, linearDemandDD] + +instanceModels :: [InstanceModel] +instanceModels = [equilibriumPriceLinearSDQIM] + +theoryModels :: [TheoryModel] +theoryModels = [equilibriumTM] + +-- our theories are only rendered because they are added to this chunkDB, which is a problem. symbMap :: ChunkDB -symbMap = cdb ([] :: [QuantityDict]) (nw progName : nw inValue : [nw errMsg, - nw program] ++ map nw doccon ++ map nw doccon' ++ [nw algorithm] ++ - map nw prodtcon ++ map nw mathcon) srsDomains - ([] :: [UnitDefn]) ([] :: [DataDefinition]) ([] :: [InstanceModel]) - ([] :: [GenDefn]) ([] :: [TheoryModel]) ([] :: [ConceptInstance]) - ([] :: [LabelledContent]) ([] :: [Reference]) citations +symbMap = cdb + quantities + ideaDicts + srsDomains + ([] :: [UnitDefn]) + dataDefinitions + instanceModels + ([] :: [GenDefn]) + theoryModels + ([] :: [ConceptInstance]) + ([] :: [LabelledContent]) + ([] :: [Reference]) + citations + where + originalIdeaDicts = nw progName : nw inValue : [nw errMsg, nw program] ++ map nw doccon ++ map nw doccon' ++ [nw algorithm] ++ map nw prodtcon ++ map nw mathcon + addedIdeaDicts = map nw quantities + ideaDicts = originalIdeaDicts ++ addedIdeaDicts usedDB :: ChunkDB usedDB = cdb ([] :: [QuantityDict]) ([] :: [IdeaDict]) ([] :: [ConceptChunk]) @@ -141,3 +181,191 @@ progName = commonIdeaWithDict "progName" (pn "ProgName") "ProgName" [] -- MOVE TO DATA.PEOPLE authorName :: Person authorName = person "Author" "Name" + +{------------------------------------------------------------------------------- +- Equilibrium +-------------------------------------------------------------------------------} + +equilibrium :: IdeaDict +equilibrium = nc "equilibrium" $ nounPhrase "equilibrium" "equilibria" + +-- There is a generic copy between economics and physics, but we won't bother +-- with that. + +{------------------------------------------------------------------------------- +- Equilibrium (Economics) +-------------------------------------------------------------------------------} + +equilibriumQ :: QuantityDict +equilibriumQ = mkQuant' -- A somewhat odd variant of `mkQuant` that re-orders argument and adds staging to the `Symbol` + "inEquilibrium" + (nounPhrase "in equilibrium" "all equilibria") -- duplicates the IdeaDict + Nothing -- UnitDefn + Boolean + (autoStage $ label "inEquilibrium") + Nothing -- "abbreviation String" + +price :: IdeaDict -- I guess making this is completely unnecessary because the QuantityDict will make its own. +price = nc "price" $ cn "price" + +priceQ :: QuantityDict +priceQ = mkQuant' + "priceQuant" -- duplicates the IdeaDict + (cn "price") + Nothing -- UnitDefn // FIXME: Uh oh! There's seemingly no way we can define a new unit: $CAD.s + Real -- Not quite a "Real," more of a "dollar amount with two decimal places, or a tuple containing two integers, with the second capped at 100" + (autoStage cP) + Nothing -- Abbreviation + +supply :: IdeaDict +supply = nc "supply" $ cnIES "supply" + +supplyDemandFuncSpace :: Space +supplyDemandFuncSpace = mkFunction [Real] Integer -- Real should be Dollar, output should be strictly non-negative integers (Z^+) + +supplyQ :: QuantityDict +supplyQ = mkQuant' + "supplyQuant" + (cnIES "supply") + Nothing -- UnitDefn -- Should units be a part of expressions? Supply is a function, so it doesn't have a unit. However, the output of the function should have a unit. The input of the function should have units as well. + supplyDemandFuncSpace + (autoStage cS) + Nothing -- Abbreviation + +demand :: IdeaDict +demand = nc "demand" $ cnIES "demand" + +demandQ :: QuantityDict +demandQ = mkQuant' + "demandQuant" + (cnIES "demand") + Nothing -- UnitDefn + supplyDemandFuncSpace + (autoStage cD) + Nothing -- Abbreviation + +equilibriumQD :: QDefinition ModelExpr -- equilibrium = S(P) == D(P) +equilibriumQD = mkQuantDef equilibriumQ $ apply1 supplyQ priceQ $= apply1 demandQ priceQ + +equilibriumTM :: TheoryModel +equilibriumTM = tmNoRefs + (equationalModel' equilibriumQD) + [qw demandQ, qw supplyQ, qw priceQ] + ([] :: [ConceptChunk]) -- This looks like just a wart? IIRC, no tmNoRefs/tm constructor uses this parameter + [equilibriumQD] -- defined quantities + [] -- defined invariants + [] -- defined functions + "equilibriumTM" + [S "Equilibrium occurs when the supply and demand curves intersect at current price."] + +-- Note: In the above, the label for "equilibrium" (the QuantityDict) is only +-- assigned in the TheoryModel! + +applePriceQ :: QuantityDict +applePriceQ = mkQuant' + "applePriceQ" + (cn "apple price") + Nothing -- UnitDefn + Real -- Space + (autoStage $ sub lP cA) + Nothing -- Abbreviation + +linearSupplyQ :: QuantityDict +linearSupplyQ = mkQuant' + "linearSupplyQuant" + (pn "price-dependant apple supply") + Nothing -- UnitDefn + (mkFunction [Real] Integer) + (autoStage $ sub cS lL) + Nothing -- Abbreviation + +linearDemandQ :: QuantityDict +linearDemandQ = mkQuant' + "linearDemandQuant" + (pn "price-dependant apple demand") + Nothing -- UnitDefn + (mkFunction [Real] Integer) + (autoStage $ sub cD lL) + Nothing -- Abbreviation + +mSQ, mDQ, bSQ, bDQ :: QuantityDict +mSQ = mkQuant' + "ms" + (pn "marginal apple supply by price") -- proper noun? + Nothing -- UnitDefn + Real -- Should be UNITS/DOLLAR + (autoStage $ sub lM cS) + Nothing -- Abbreviation +mDQ = mkQuant' + "md" + (pn "marginal apple demand by price") -- proper noun? + Nothing -- UnitDefn + Real -- Should be UNITS/DOLLAR + (autoStage $ sub lM cD) + Nothing -- Abbreviation +bSQ = mkQuant' + "bs" + (pn "minimum supply of apples") -- proper noun? + Nothing -- UnitDefn + Real -- Should be UNITS + (autoStage $ sub lB cS) + Nothing -- Abbreviation +bDQ = mkQuant' + "bd" + (pn "maximum demand of apples") -- proper noun? + Nothing -- UnitDefn + Real -- Should be UNITS + (autoStage $ sub lB cD) + Nothing -- Abbreviation + +linearSupplyQD :: QDefinition Expr +-- TODO: Missing "Real -> Integer" truncation function for the below function +linearSupplyQD = mkFuncDefByQ linearSupplyQ [applePriceQ] $ sy mSQ $* sy applePriceQ $+ sy bSQ +-- ^ I'm deliberately choosing to use applePrice here because I want to use this +-- in an instance model, which (I believe) should mean that there are only +-- 'concrete' variables (i.e., problem-related variables, not the abstract ones +-- imported from the hypothetical library that would contain equilibrium) + +linearSupplyDD :: DataDefinition +linearSupplyDD = ddENoRefs + linearSupplyQD + Nothing -- Derivation + "linearSupplyDD" -- "ShortName" + [] -- Notes + +linearDemandQD :: QDefinition Expr +linearDemandQD = mkFuncDefByQ linearDemandQ [applePriceQ] $ sy mDQ $* sy applePriceQ $+ sy bDQ + +linearDemandDD :: DataDefinition +linearDemandDD = ddENoRefs + linearSupplyQD + Nothing -- Derivation + "linearDemandDD" -- "ShortName" + [] -- Notes + +equilibriumApplePriceLinearSDQ :: QuantityDict +equilibriumApplePriceLinearSDQ = mkQuant' + "equilibriumApplePriceQ" + (cn "equilibrium apple price") + Nothing -- UnitDefn + Real -- Space + (autoStage $ sub lP $ label "A,Eq") -- Hack because of lack of support for symbol "corners" in Drasil. + Nothing -- Abbreviation + +equilibriumApplePriceLinearSDQD :: QDefinition Expr +equilibriumApplePriceLinearSDQD = mkQuantDef equilibriumApplePriceLinearSDQ $ + (sy bDQ $- sy bSQ) $/ (sy mSQ $- sy mDQ) + +equilibriumPriceLinearSDQIM :: InstanceModel +equilibriumPriceLinearSDQIM = imNoDerivNoRefs + (equationalModel' equilibriumApplePriceLinearSDQD) + [] -- Inputs -- What are they? Why is this only here and not in the TM? + equilibriumApplePriceLinearSDQ -- Output -- not everything will have an output! + [UpFrom (Exc, int 0)] -- Output constraints: price > 0 -- why can't I put gtZerConstr + "equilibriumApplePriceIM" + [] -- Notes ([Sentence]) + +{------------------------------------------------------------------------------- +- Equilibrium (Physics) +-------------------------------------------------------------------------------} + diff --git a/code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs b/code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs index 093a93f8b4f..2ce2362dbb3 100644 --- a/code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs +++ b/code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs @@ -114,8 +114,14 @@ mkQDefSt u n s symb sp Nothing e = fromEqnSt' u n s symb sp e -- | Used to help make 'QDefinition's when 'UID', term, and 'Symbol' come from the same source. mkQuantDef :: (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e -mkQuantDef c = mkQDefSt (c ^. uid) (c ^. term) EmptyS (symbol c) (c ^. typ) (getUnit c) - +mkQuantDef c = mkQDefSt (c ^. uid) (c ^. term) EmptyS (symbol c) (c ^. typ) (getUnit c) -- FIXME: Always EmptyS description? Seems dubious? + +{- + DefinedQuantityDict seems like a wart. It seems like it's only necessary when + we want to assert that a quantity has an English interpretation along with a + mathematical one (i.e., a variable). +-} + -- FIXME: See #2788. -- | Used to help make 'QDefinition's when 'UID' and 'Symbol' come from the same source, with the term separate. mkQuantDef' :: (Quantity c, MayHaveUnit c) => c -> NP -> e -> QDefinition e diff --git a/code/drasil-printers/lib/Language/Drasil/HTML/Print.hs b/code/drasil-printers/lib/Language/Drasil/HTML/Print.hs index 9ca4efa2312..8f6bad1a28b 100644 --- a/code/drasil-printers/lib/Language/Drasil/HTML/Print.hs +++ b/code/drasil-printers/lib/Language/Drasil/HTML/Print.hs @@ -293,7 +293,7 @@ makeColumns = vcat . map (td . pSpec) -- | Renders definition tables (Data, General, Theory, etc.). makeDefn :: L.DType -> [(String,[LayoutObj])] -> Doc -> Doc -makeDefn _ [] _ = error "L.Empty definition" +makeDefn _ [] _ = error "Definition table has no designated rows to render!" makeDefn dt ps l = refwrap l $ table [dtag dt] (tr (th (text "Refname") $$ td (bold l)) $$ makeDRows ps) where dtag L.General = "gdefn" diff --git a/code/stable/template/SRS/HTML/Template_SRS.html b/code/stable/template/SRS/HTML/Template_SRS.html index 3644a5d0784..b0bfab44a82 100644 --- a/code/stable/template/SRS/HTML/Template_SRS.html +++ b/code/stable/template/SRS/HTML/Template_SRS.html @@ -122,7 +122,76 @@
There are no symbols.
- +| Symbol | +Description | +Units | +
|---|---|---|
| bD | +maximum demand of apples | +-- | +
| bS | +minimum supply of apples | +-- | +
| D | +Demand | +-- | +
| Dl | +price-dependant apple demand | +-- | +
| inEquilibrium | +In equilibrium | +-- | +
| mD | +marginal apple demand by price | +-- | +
| mS | +marginal apple supply by price | +-- | +
| P | +Price | +-- | +
| pA | +Apple price | +-- | +
| pA,Eq | +Equilibrium apple price | +-- | +
| S | +Supply | +-- | +
| Sl | +price-dependant apple supply | +-- | +
Table of Symbols
+There are no theoretical models.
++ This section focuses on the general equations and laws that ProgName is based on. +
+| Refname | +TM:equilibriumTM | +
|---|---|
| Label | +In equilibrium |
+
| Equation | +\[\text{inEquilibrium}=S\left(P\right)=D\left(P\right)\] | +
| Description | ++ + | +
| Notes | +
+ + Equilibrium occurs when the supply and demand curves intersect at current price. + + |
+
| Source | +-- |
+
| RefBy | ++ |
There are no data definitions.
++ This section collects and defines all the data needed to build the instance models. +
+| Refname | +DD:linearDemandDD | +
|---|---|
| Label | +price-dependant apple supply |
+
| Equation | +\[{S_{l}}\left({p_{A}}\right)={m_{S}}\,{p_{A}}+{b_{S}}\] | +
| Description | ++ + | +
| Source | +-- |
+
| RefBy | ++ |
There are no instance models.
++ This section transforms the problem defined in the problem description into one which is expressed in mathematical terms. It uses concrete symbols defined in the data definitions to replace the abstract symbols in the models identified in theoretical models and general definitions. +
+| Refname | +IM:equilibriumApplePriceIM | +
|---|---|
| Label | +Equilibrium apple price |
+
| Input | ++ |
| Output | +pA,Eq |
+
| Input Constraints | ++ |
| Output Constraints | +\[{p_{\text{A,Eq}}}\gt{}0\] | +
| Equation | ++ \[{p_{\text{A,Eq}}}=\frac{{b_{D}}-{b_{S}}}{{m_{S}}-{m_{D}}}\] + | +
| Description | ++ + | +
| Source | +-- |
+
| RefBy | ++ |
- There are no traceability matrices or traceability graphs. + The purpose of the traceability matrices is to provide easy references on what has to be additionally modified if a certain component is changed. Every time a component is changed, the items in the column of that component that are marked with an "X" should be modified as well. Tab:TraceMatRefvsRef shows the dependencies of the data definitions, theoretical models, general definitions, and instance models on each other. +
+| + | DD:linearDemandDD | +TM:equilibriumTM | ++ IM:equilibriumApplePriceIM + | +
|---|---|---|---|
| DD:linearDemandDD | ++ | + | + |
| TM:equilibriumTM | ++ | + | + |
| + IM:equilibriumApplePriceIM + | ++ | + | + |
+ Traceability Matrix Showing the Connections Between Items and Other Sections +
++ The purpose of the traceability graphs is also to provide easy references on what has to be additionally modified if a certain component is changed. The arrows in the graphs represent dependencies. The component at the tail of an arrow is depended on by the component at the head of that arrow. Therefore, if a component is changed, the components that it points to should also be changed. Fig:TraceGraphAvsA shows the dependencies of data definitions, theoretical models, general definitions, and instance models on each other. Fig:TraceGraphAvsAll shows the dependencies of dependencies of assumptions, models, definitions, requirements, goals, and changes with each other. +
++ For convenience, the following graphs can be found at the links below:
+| Refname | \n", + "\n", + "TM:equilibriumTM\n", + " | \n", + "
|---|---|
| Label | \n", + "\n", + "\n", + "In equilibrium\n", + " | \n", + "
| Equation | \n", + "\n", + "$$\\text{inEquilibrium}=S\\left(P\\right)=D\\left(P\\right)$$\n", + " | \n", + "
| Description | \n", + "\n",
+ "\n",
+ " | \n",
+ "
| Notes | \n", + "\n", + "\n", + "Equilibrium occurs when the supply and demand curves intersect at current price.\n", + " | \n", + "
| Source | \n", + "\n", + "\n", + "--\n", + " | \n", + "
| RefBy | \n", + "\n", + "\n", + "\n", + " | \n", + "
| Refname | \n", + "\n", + "DD:linearDemandDD\n", + " | \n", + "
|---|---|
| Label | \n", + "\n", + "\n", + "price-dependant apple supply\n", + " | \n", + "
| Equation | \n", + "\n", + "$${S_{l}}\\left({p_{A}}\\right)={m_{S}}\\,{p_{A}}+{b_{S}}$$\n", + " | \n", + "
| Description | \n", + "\n",
+ "\n",
+ " | \n",
+ "
| Source | \n", + "\n", + "\n", + "--\n", + " | \n", + "
| RefBy | \n", + "\n", + "\n", + "\n", + " | \n", + "
| Refname | \n", + "\n", + "IM:equilibriumApplePriceIM\n", + " | \n", + "
|---|---|
| Label | \n", + "\n", + "\n", + "Equilibrium apple price\n", + " | \n", + "
| Input | \n", + "\n", + "\n", + "\n", + " | \n", + "
| Output | \n", + "\n", + "\n", + "$p_A,Eq$\n", + " | \n", + "
| Input Constraints | \n", + "\n", + " | \n", + "
| Output Constraints | \n", + "\n", + "$${p_{\\text{A,Eq}}}\\gt{}0$$\n", + " | \n", + "
| Equation | \n", + "\n", + "$${p_{\\text{A,Eq}}}=\\frac{{b_{D}}-{b_{S}}}{{m_{S}}-{m_{D}}}$$\n", + " | \n", + "
| Description | \n", + "\n",
+ "\n",
+ " | \n",
+ "
| Source | \n", + "\n", + "\n", + "--\n", + " | \n", + "
| RefBy | \n", + "\n", + "\n", + "\n", + " | \n", + "
Table of Symbols
** diff --git a/code/stable/template/SRS/mdBook/src/SecTraceMatrices.md b/code/stable/template/SRS/mdBook/src/SecTraceMatrices.md index 7c1c62928d9..bf0ef167950 100644 --- a/code/stable/template/SRS/mdBook/src/SecTraceMatrices.md +++ b/code/stable/template/SRS/mdBook/src/SecTraceMatrices.md @@ -1,3 +1,63 @@ # Traceability Matrices and Graphs {#Sec:TraceMatrices} -There are no traceability matrices or traceability graphs. +The purpose of the traceability matrices is to provide easy references on what has to be additionally modified if a certain component is changed. Every time a component is changed, the items in the column of that component that are marked with an "X" should be modified as well. [Tab:TraceMatRefvsRef](./SecTraceMatrices.md#Table:TraceMatRefvsRef) shows the dependencies of the data definitions, theoretical models, general definitions, and instance models on each other. + + + +| |[DD:linearDemandDD](./SecDDs.md#DD:linearDemandDD)|[TM:equilibriumTM](./SecTMs.md#TM:equilibriumTM)|[IM:equilibriumApplePriceIM](./SecIMs.md#IM:equilibriumApplePriceIM)| +|:-------------------------------------------------------------------|:-------------------------------------------------|:-----------------------------------------------|:-------------------------------------------------------------------| +|[DD:linearDemandDD](./SecDDs.md#DD:linearDemandDD) | | | | +|[TM:equilibriumTM](./SecTMs.md#TM:equilibriumTM) | | | | +|[IM:equilibriumApplePriceIM](./SecIMs.md#IM:equilibriumApplePriceIM)| | | | + +**Traceability Matrix Showing the Connections Between Items and Other Sections
** + +The purpose of the traceability graphs is also to provide easy references on what has to be additionally modified if a certain component is changed. The arrows in the graphs represent dependencies. The component at the tail of an arrow is depended on by the component at the head of that arrow. Therefore, if a component is changed, the components that it points to should also be changed. [Fig:TraceGraphAvsA](./SecTraceMatrices.md#Figure:TraceGraphAvsA) shows the dependencies of data definitions, theoretical models, general definitions, and instance models on each other. [Fig:TraceGraphAvsAll](./SecTraceMatrices.md#Figure:TraceGraphAvsAll) shows the dependencies of dependencies of assumptions, models, definitions, requirements, goals, and changes with each other. + +