diff --git a/code/drasil-code/lib/Data/Drasil/ExternalLibraries/ODELibraries.hs b/code/drasil-code/lib/Data/Drasil/ExternalLibraries/ODELibraries.hs index 8cdc9da0a8a..579a6cc2e76 100644 --- a/code/drasil-code/lib/Data/Drasil/ExternalLibraries/ODELibraries.hs +++ b/code/drasil-code/lib/Data/Drasil/ExternalLibraries/ODELibraries.hs @@ -11,9 +11,9 @@ module Data.Drasil.ExternalLibraries.ODELibraries ( ) where import Language.Drasil (HasSymbol(symbol), HasUID(uid), MayHaveUnit(getUnit), - QuantityDict, HasSpace(typ), Space (Actor, Natural, Real, Void, Boolean, String, Array, Vect), implVar, + QuantityDict, HasSpace(typ), Space (Actor, Natural, Real, Void, Boolean, String, Array, ClifS), implVar, implVarUID, implVarUID', qw, compoundPhrase, nounPhrase, nounPhraseSP, label, - sub, Idea(getA), NamedIdea(term), Stage(..), (+++)) + sub, Idea(getA), NamedIdea(term), Stage(..), (+++), vectNDS) import Language.Drasil.Display (Symbol(Label, Concat)) import Language.Drasil.Code (Lang(..), ExternalLibrary, Step, Argument, @@ -443,7 +443,7 @@ odeint = externalLib [ customObjArg [] "Class representing an ODE system" ode odeCtor (customClass [constructorInfo odeCtor [] [], methodInfoNoReturn odeOp "function representation of ODE system" - [unnamedParam (Vect Real), unnamedParam (Vect Real), lockedParam t] + [unnamedParam (vectNDS "n" Real), unnamedParam (vectNDS "n" Real), lockedParam t] -- TODO: what do we put here? We need specific dimensions now. [assignArrayIndex]]), -- Need to declare variable holding initial value because odeint will update this variable at each step preDefinedArg odeintCurrVals, @@ -451,7 +451,7 @@ odeint = externalLib [ customObjArg [] "Class for populating a list during an ODE solution process" pop popCtor (customClass [ - constructorInfo popCtor [unnamedParam (Vect Real)] [], + constructorInfo popCtor [unnamedParam (vectNDS "n" Real)] [], -- TODO: Same as above TODO methodInfoNoReturn popOp "appends solution point for current ODE solution step" [lockedParam y, lockedParam t] [appendCurrSol (sy y)]])]] @@ -496,7 +496,7 @@ odeintCurrVals, rk, stepper, pop :: CodeVarChunk odeintCurrVals = quantvar $ implVar "currVals_odeint" (nounPhrase "vector holding ODE solution values for the current step" "vectors holding ODE solution values for the current step") - (Vect Real) (label "currVals") + (vectNDS "n" Real) (label "currVals") -- TODO: Same as above, what do we fill in here? rk = quantvar $ implVar "rk_odeint" (nounPhrase "stepper for solving ODE system using Runge-Kutta-Dopri5 method" "steppers for solving ODE system using Runge-Kutta-Dopri5 method") @@ -555,7 +555,7 @@ t = quantvar $ implVar "t_ode" (nounPhrase y = quantvar $ implVar "y_ode" (nounPhrase "current dependent variable value in ODE solution" "current dependent variable value in ODE solution") - (Vect Real) (label "y") + (vectNDS "n" Real) (label "y") -- TODO: Same as above - what dimension do we use here? -- | ODE object constructor. odeCtor :: CodeFuncChunk @@ -599,8 +599,8 @@ modifiedODESyst sufx info = map replaceDepVar (odeSyst info) replaceDepVar (Matrix es) = Matrix $ map (map replaceDepVar) es replaceDepVar (UnaryOp u e) = UnaryOp u $ replaceDepVar e replaceDepVar (UnaryOpB u e) = UnaryOpB u $ replaceDepVar e - replaceDepVar (UnaryOpVV u e) = UnaryOpVV u $ replaceDepVar e - replaceDepVar (UnaryOpVN u e) = UnaryOpVN u $ replaceDepVar e + replaceDepVar (UnaryOpCC u e) = UnaryOpCC u $ replaceDepVar e + replaceDepVar (UnaryOpCN u e) = UnaryOpCN u $ replaceDepVar e replaceDepVar (ArithBinaryOp b e1 e2) = ArithBinaryOp b (replaceDepVar e1) (replaceDepVar e2) replaceDepVar (BoolBinaryOp b e1 e2) = BoolBinaryOp b @@ -611,9 +611,9 @@ modifiedODESyst sufx info = map replaceDepVar (odeSyst info) (replaceDepVar e1) (replaceDepVar e2) replaceDepVar (OrdBinaryOp b e1 e2) = OrdBinaryOp b (replaceDepVar e1) (replaceDepVar e2) - replaceDepVar (VVNBinaryOp b e1 e2) = VVNBinaryOp b + replaceDepVar (CCNBinaryOp b e1 e2) = CCNBinaryOp b (replaceDepVar e1) (replaceDepVar e2) - replaceDepVar (VVVBinaryOp b e1 e2) = VVVBinaryOp b + replaceDepVar (CCCBinaryOp b e1 e2) = CCCBinaryOp b (replaceDepVar e1) (replaceDepVar e2) replaceDepVar (Operator ao dd e) = Operator ao dd $ replaceDepVar e replaceDepVar e = e diff --git a/code/drasil-code/lib/Language/Drasil/Chunk/Parameter.hs b/code/drasil-code/lib/Language/Drasil/Chunk/Parameter.hs index 12ed8d98a9c..b49e40b7f3d 100644 --- a/code/drasil-code/lib/Language/Drasil/Chunk/Parameter.hs +++ b/code/drasil-code/lib/Language/Drasil/Chunk/Parameter.hs @@ -37,11 +37,11 @@ instance Eq ParameterChunk where c1 == c2 = (c1 ^. uid) == (c2 ^. uid) -- | Finds the units of the 'CodeChunk' used to make the 'ParameterChunk'. instance MayHaveUnit ParameterChunk where getUnit = getUnit . view pcc --- | Automatically chooses 'PassBy' based on 'Space' ('Vect'ors and 'Actor's passed by reference). +-- | Automatically chooses 'PassBy' based on 'Space' ('Clif's and 'Actor's passed by reference). pcAuto :: (CodeIdea c) => c -> ParameterChunk pcAuto c = PC cdch (choosePB $ cdch ^. typ) where cdch = codeChunk c - choosePB (Vect _) = Ref + choosePB (ClifS _ _) = Ref choosePB (Actor _) = Ref choosePB _ = Val diff --git a/code/drasil-code/lib/Language/Drasil/Code/Code.hs b/code/drasil-code/lib/Language/Drasil/Code/Code.hs index db13e1af54d..91a87a6ce7e 100644 --- a/code/drasil-code/lib/Language/Drasil/Code/Code.hs +++ b/code/drasil-code/lib/Language/Drasil/Code/Code.hs @@ -23,7 +23,7 @@ spaceToCodeType S.Rational = [Double, Float] spaceToCodeType S.Boolean = [Boolean] spaceToCodeType S.Char = [Char] spaceToCodeType S.String = [String] -spaceToCodeType (S.Vect s) = map List (spaceToCodeType s) +spaceToCodeType (S.ClifS _ s) = map List (spaceToCodeType s) spaceToCodeType (S.Matrix _ _ s) = map (List . List) (spaceToCodeType s) spaceToCodeType (S.Set s) = map List (spaceToCodeType s) spaceToCodeType (S.Array s) = map Array (spaceToCodeType s) diff --git a/code/drasil-code/lib/Language/Drasil/Code/Imperative/Import.hs b/code/drasil-code/lib/Language/Drasil/Code/Imperative/Import.hs index 0b111ed5f6b..a41d517e1bf 100644 --- a/code/drasil-code/lib/Language/Drasil/Code/Imperative/Import.hs +++ b/code/drasil-code/lib/Language/Drasil/Code/Imperative/Import.hs @@ -15,8 +15,8 @@ import Language.Drasil.CodeExpr (sy, ($<), ($>), ($<=), ($>=), ($&&), in') import qualified Language.Drasil.CodeExpr.Development as S (CodeExpr(..)) import Language.Drasil.CodeExpr.Development (CodeExpr(..), ArithBinOp(..), AssocArithOper(..), AssocBoolOper(..), AssocConcatOper(..), BoolBinOp(..), EqBinOp(..), - LABinOp(..), OrdBinOp(..), UFunc(..), UFuncB(..), UFuncVV(..), UFuncVN(..), - VVNBinOp(..), VVVBinOp(..), NVVBinOp(..), ESSBinOp(..), ESBBinOp(..)) + LABinOp(..), OrdBinOp(..), UFunc(..), UFuncB(..), UFuncCC(..), UFuncCN(..), + CCNBinOp(..), CCCBinOp(..), NCCBinOp(..), ESSBinOp(..), ESBBinOp(..)) import Language.Drasil.Code.Imperative.Comments (getComment) import Language.Drasil.Code.Imperative.ConceptMatch (conceptToGOOL) import Language.Drasil.Code.Imperative.GenerateGOOL (auxClass, fApp, fAppProc, @@ -337,8 +337,8 @@ convExpr (Field o f) = do return $ valueOf v convExpr (UnaryOp o u) = fmap (unop o) (convExpr u) convExpr (UnaryOpB o u) = fmap (unopB o) (convExpr u) -convExpr (UnaryOpVV o u) = fmap (unopVV o) (convExpr u) -convExpr (UnaryOpVN o u) = fmap (unopVN o) (convExpr u) +convExpr (UnaryOpCC o u) = fmap (unopCC o) (convExpr u) +convExpr (UnaryOpCN o u) = fmap (unopCN o) (convExpr u) convExpr (ArithBinaryOp Frac (Lit (Int a)) (Lit (Int b))) = do -- hack to deal with integer division sm <- spaceCodeType Rational let getLiteral Double = litDouble (fromIntegral a) #/ litDouble (fromIntegral b) @@ -350,9 +350,9 @@ convExpr (BoolBinaryOp o a b) = liftM2 (boolBfunc o) (convExpr a) (convExpr b) convExpr (LABinaryOp o a b) = liftM2 (laBfunc o) (convExpr a) (convExpr b) convExpr (EqBinaryOp o a b) = liftM2 (eqBfunc o) (convExpr a) (convExpr b) convExpr (OrdBinaryOp o a b) = liftM2 (ordBfunc o) (convExpr a) (convExpr b) -convExpr (VVVBinaryOp o a b) = liftM2 (vecVecVecBfunc o) (convExpr a) (convExpr b) -convExpr (VVNBinaryOp o a b) = liftM2 (vecVecNumBfunc o) (convExpr a) (convExpr b) -convExpr (NVVBinaryOp o a b) = liftM2 (numVecVecBfunc o) (convExpr a) (convExpr b) +convExpr (CCCBinaryOp o a b) = liftM2 (clfClfClfBfunc o) (convExpr a) (convExpr b) +convExpr (CCNBinaryOp o a b) = liftM2 (clfClfNumBfunc o) (convExpr a) (convExpr b) +convExpr (NCCBinaryOp o a b) = liftM2 (numClfClfBfunc o) (convExpr a) (convExpr b) convExpr (ESSBinaryOp o a b) = liftM2 (elementSetSetBfunc o) (convExpr a) (convExpr b) convExpr (ESBBinaryOp o a b) = liftM2 (elementSetBoolBfunc o) (convExpr a) (convExpr b) convExpr (Case c l) = doit l -- FIXME this is sub-optimal @@ -447,13 +447,13 @@ unopB :: (SharedProg r) => UFuncB -> (SValue r -> SValue r) unopB Not = (?!) -- | Similar to 'unop', but for vectors. -unopVN :: (SharedProg r) => UFuncVN -> (SValue r -> SValue r) -unopVN Dim = listSize -unopVN Norm = error "unop: Norm not implemented" -- TODO +unopCN :: (SharedProg r) => UFuncCN -> (SValue r -> SValue r) +unopCN Dim = listSize +unopCN Norm = error "unop: Norm not implemented" -- TODO -- | Similar to 'unop', but for vectors. -unopVV :: (SharedProg r) => UFuncVV -> (SValue r -> SValue r) -unopVV NegV = error "unop: Negation on Vectors not implemented" -- TODO +unopCC :: (SharedProg r) => UFuncCC -> (SValue r -> SValue r) +unopCC NegC = error "unop: Negation on Clifs not implemented" -- TODO -- Maps an 'ArithBinOp' to it's corresponding GOOL binary function. arithBfunc :: (SharedProg r) => ArithBinOp -> (SValue r -> SValue r -> SValue r) @@ -483,19 +483,19 @@ ordBfunc Lt = (?<) ordBfunc LEq = (?<=) ordBfunc GEq = (?>=) --- Maps a 'VVVBinOp' to it's corresponding GOOL binary function. -vecVecVecBfunc :: VVVBinOp -> (SValue r -> SValue r -> SValue r) -vecVecVecBfunc Cross = error "bfunc: Cross not implemented" -vecVecVecBfunc VAdd = error "bfunc: Vector addition not implemented" -vecVecVecBfunc VSub = error "bfunc: Vector subtraction not implemented" +-- Maps a 'CCCBinOp' to it's corresponding GOOL binary function. +clfClfClfBfunc :: CCCBinOp -> (SValue r -> SValue r -> SValue r) +clfClfClfBfunc Cross = error "bfunc: Cross not implemented" +clfClfClfBfunc CAdd = error "bfunc: Clif addition not implemented" +clfClfClfBfunc CSub = error "bfunc: Clif subtraction not implemented" --- Maps a 'VVNBinOp' to it's corresponding GOOL binary function. -vecVecNumBfunc :: VVNBinOp -> (SValue r -> SValue r -> SValue r) -vecVecNumBfunc Dot = error "convExpr DotProduct" +-- Maps a 'CCNBinOp' to it's corresponding GOOL binary function. +clfClfNumBfunc :: CCNBinOp -> (SValue r -> SValue r -> SValue r) +clfClfNumBfunc Dot = error "convExpr DotProduct" --- Maps a 'NVVBinOp' to it's corresponding GOOL binary function. -numVecVecBfunc :: NVVBinOp -> (SValue r -> SValue r -> SValue r) -numVecVecBfunc Scale = error "convExpr Scaling of Vectors" +-- Maps a 'NCCBinOp' to it's corresponding GOOL binary function. +numClfClfBfunc :: NCCBinOp -> (SValue r -> SValue r -> SValue r) +numClfClfBfunc Scale = error "convExpr Scaling of Vectors" -- Maps a 'ESSBinOp' to its corresponding GOOL binary function. elementSetSetBfunc :: (SharedProg r) => ESSBinOp -> (SValue r -> SValue r -> SValue r) @@ -1038,8 +1038,8 @@ convExprProc (Message {}) = error "convExprProc: Procedural renderers do not sup convExprProc (Field _ _) = error "convExprProc: Procedural renderers do not support object field access" convExprProc (UnaryOp o u) = fmap (unop o) (convExprProc u) convExprProc (UnaryOpB o u) = fmap (unopB o) (convExprProc u) -convExprProc (UnaryOpVV o u) = fmap (unopVV o) (convExprProc u) -convExprProc (UnaryOpVN o u) = fmap (unopVN o) (convExprProc u) +convExprProc (UnaryOpCC o u) = fmap (unopCC o) (convExprProc u) +convExprProc (UnaryOpCN o u) = fmap (unopCN o) (convExprProc u) convExprProc (ArithBinaryOp Frac (Lit (Int a)) (Lit (Int b))) = do -- hack to deal with integer division sm <- spaceCodeType Rational let getLiteral Double = litDouble (fromIntegral a) #/ litDouble (fromIntegral b) @@ -1051,9 +1051,9 @@ convExprProc (BoolBinaryOp o a b) = liftM2 (boolBfunc o) (convExprProc a) (conv convExprProc (LABinaryOp o a b) = liftM2 (laBfunc o) (convExprProc a) (convExprProc b) convExprProc (EqBinaryOp o a b) = liftM2 (eqBfunc o) (convExprProc a) (convExprProc b) convExprProc (OrdBinaryOp o a b) = liftM2 (ordBfunc o) (convExprProc a) (convExprProc b) -convExprProc (VVVBinaryOp o a b) = liftM2 (vecVecVecBfunc o) (convExprProc a) (convExprProc b) -convExprProc (VVNBinaryOp o a b) = liftM2 (vecVecNumBfunc o) (convExprProc a) (convExprProc b) -convExprProc (NVVBinaryOp o a b) = liftM2 (numVecVecBfunc o) (convExprProc a) (convExprProc b) +convExprProc (CCCBinaryOp o a b) = liftM2 (clfClfClfBfunc o) (convExprProc a) (convExprProc b) +convExprProc (CCNBinaryOp o a b) = liftM2 (clfClfNumBfunc o) (convExprProc a) (convExprProc b) +convExprProc (NCCBinaryOp o a b) = liftM2 (numClfClfBfunc o) (convExprProc a) (convExprProc b) convExprProc (ESSBinaryOp o a b) = liftM2 (elementSetSetBfunc o) (convExprProc a) (convExprProc b) convExprProc (ESBBinaryOp o a b) = liftM2 (elementSetBoolBfunc o) (convExprProc a) (convExprProc b) convExprProc (Case c l) = doit l -- FIXME this is sub-optimal diff --git a/code/drasil-code/lib/Language/Drasil/Code/Imperative/ReadInput.hs b/code/drasil-code/lib/Language/Drasil/Code/Imperative/ReadInput.hs index 3f3fe7b6629..c40ee7671dc 100644 --- a/code/drasil-code/lib/Language/Drasil/Code/Imperative/ReadInput.hs +++ b/code/drasil-code/lib/Language/Drasil/Code/Imperative/ReadInput.hs @@ -7,7 +7,7 @@ import Language.Drasil hiding (Data, Matrix, CodeVarChunk) import Language.Drasil.Code.DataDesc (DataDesc'(..), Data'(..), DataItem'(..), Delimiter, dataDesc, junk, list, singleton') import Language.Drasil.Chunk.Code (CodeVarChunk) -import Language.Drasil.Expr.Development (Expr(Matrix)) +import Language.Drasil.Expr.Development (Expr(Matrix)) -- TODO: remove Matrix entirely import Control.Lens ((^.)) import Data.List (intersperse, isPrefixOf, transpose) @@ -66,7 +66,7 @@ readWithDataDesc fp ddsc = do sampleInputDD :: [CodeVarChunk] -> DataDesc' sampleInputDD ds = dataDesc (junk : intersperse junk (map toData ds)) "\n" where toData d = toData' (d ^. typ) d - toData' t@(Vect _) d = list d + toData' t@(ClifS _ _) d = list d (take (getDimension t) ([", ", "; "] ++ iterate (':':) ":")) toData' _ d = singleton' d @@ -82,8 +82,9 @@ strAsExpr String s = str s strAsExpr _ _ = error "strAsExpr should only be numeric space or string" -- | Gets the dimension of a 'Space'. +-- TODO: investigate getting rid of the need for this getDimension :: Space -> Int -getDimension (Vect t) = 1 + getDimension t +getDimension (ClifS _ s) = 1 + getDimension s -- TODO: Does this make sense? Maybe we're overloading the term "dimension" now. getDimension _ = 0 -- | Splits a string at the first (and only the first) occurrence of a delimiter. @@ -98,12 +99,12 @@ splitAtFirst = splitAtFirst' [] dropDelim [] s = s dropDelim _ [] = error "impossible" --- | Converts a list of 'String's to a Matrix 'Expr' of a given 'Space'. +-- | Converts a list of 'String's to a Clif 'Expr' of a given 'Space'. strListAsExpr :: Space -> [String] -> Expr -strListAsExpr (Vect t) ss = Matrix [map (strAsExpr t) ss] +strListAsExpr (ClifS _ _) _ = undefined -- TODO: fill this in strListAsExpr _ _ = error "strListsAsExpr called on non-vector space" --- | Converts a 2D list of 'String's to a Matrix 'Expr' of a given 'Space'. +-- | Converts a 2D list of 'String's to a Clif 'Expr' of a given 'Space'. strList2DAsExpr :: Space -> [[String]] -> Expr -strList2DAsExpr (Vect (Vect t)) sss = Matrix $ map (map (strAsExpr t)) sss +strList2DAsExpr (ClifS _ (ClifS _ _)) _ = undefined -- TODO: fill this in strList2DAsExpr _ _ = error "strLists2DAsExprs called on non-2D-vector space" diff --git a/code/drasil-data/lib/Data/Drasil/Quantities/Physics.hs b/code/drasil-data/lib/Data/Drasil/Quantities/Physics.hs index 276b8b7db30..81e019f63c6 100644 --- a/code/drasil-data/lib/Data/Drasil/Quantities/Physics.hs +++ b/code/drasil-data/lib/Data/Drasil/Quantities/Physics.hs @@ -44,46 +44,47 @@ acceleration, angularAccel, angularDisplacement, angularVelocity, chgInVelocity, yVel, momentum, moment, moment2D, fOfGravity, positionVec, tension, angularFrequency, period, frequency, chgMomentum :: UnitalChunk -acceleration = uc CP.acceleration (Concat [vec lA, label "(", lT, label ")"]) (Vect Real) accelU +-- TODO: what should the type here be? +acceleration = uc CP.acceleration (Concat [vec lA, label "(", lT, label ")"]) (vectNDS "n" Real) accelU angularAccel = uc CP.angAccel lAlpha Real angAccelU angularDisplacement = uc CP.angDisp lTheta Real radian angularFrequency = uc CP.angFreq cOmega Real second angularVelocity = uc CP.angVelo lOmega Real angVelU chgInVelocity = uc CP.chgInVelocity (Atop Delta $ vec lV) Real velU constAccel = uc CP.constAccel (sup lA lC) Real accelU -displacement = uc CP.displacement (vec lU) Real metre +displacement = uc CP.displacement (vec lU) (vectNDS "n" Real) metre distance = uc CP.distance lD Real metre energy = uc CP.energy cE Real joule -force = uc CP.force (vec cF) Real newton +force = uc CP.force (vec cF) (vectNDS "n" Real) newton frequency = uc CP.frequency lF Real hertz -gravitationalAccel = uc CP.gravitationalAccel (vec lG) Real accelU +gravitationalAccel = uc CP.gravitationalAccel (vec lG) (vectNDS "n" Real) accelU gravitationalConst = uc CP.gravitationalConst cG Real gravConstU gravitationalMagnitude = uc CP.gravitationalMagnitude lG Real accelU height = uc CP.height lH Real metre impulseS = uc CP.impulseS lJ Real impulseU -impulseV = uc CP.impulseV (vec cJ) Real impulseU +impulseV = uc CP.impulseV (vec cJ) (vectNDS "n" Real) impulseU kEnergy = uc CP.kEnergy (Concat [cK, cE]) Real joule linearAccel = uc CP.linAccel (Concat [lA, label "(", lT, label ")"]) Real accelU linearDisplacement = uc CP.linDisp (Concat [lU, label "(", lT, label ")"]) Real metre linearVelocity = uc CP.linVelo (Concat [lV, label "(", lT, label ")"]) Real velU -momentOfInertia = uc CP.momentOfInertia (vec cI) Real momtInertU +momentOfInertia = uc CP.momentOfInertia (vec cI) (vectNDS "n" Real) momtInertU chgMomentum = uc CP.chgMomentum (Concat [cDelta,vec cP]) Real impulseU -momentum = uc CP.momentum (vec cP) Real impulseU -moment = uc CP.moment (vec cM) Real torqueU +momentum = uc CP.momentum (vec cP) (vectNDS "n" Real) impulseU +moment = uc CP.moment (vec cM) (vectNDS "n" Real) torqueU moment2D = uc CP.moment cM Real torqueU -- FIXME: moment2D should eventually be a specialization of moment, not separately defined period = uc CP.period cT Real second position = uc CP.position (Concat [vec lP, label "(", lT, label ")"]) Real metre -positionVec = uc CP.positionVec (vec lR) Real metre +positionVec = uc CP.positionVec (vec lR) (vectNDS "n" Real) metre potEnergy = uc CP.potEnergy (Concat [cP, cE]) Real joule pressure = uc CP.pressure lP Real pascal speed = uc CP.speed lV Real velU scalarAccel = uc CP.scalarAccel lA Real accelU scalarPos = uc CP.scalarPos lP Real metre -tension = uc CP.tension (vec cT) Real newton +tension = uc CP.tension (vec cT) (vectNDS "n" Real) newton time = uc CP.time lT Real second -torque = uc CP.torque (vec lTau) Real torqueU -velocity = uc CP.velocity (Concat [vec lV, label "(", lT, label ")"]) Real velU +torque = uc CP.torque (vec lTau) (vectNDS "n" Real) torqueU +velocity = uc CP.velocity (Concat [vec lV, label "(", lT, label ")"]) (vectNDS "n" Real) velU weight = uc CP.weight cW Real newton fOfGravity = uc CP.fOfGravity (sub (vec cF) (vec lG)) Real newton diff --git a/code/drasil-example/dblpend/lib/Drasil/DblPend/Unitals.hs b/code/drasil-example/dblpend/lib/Drasil/DblPend/Unitals.hs index d87f6836ba6..d5cb522ba3f 100644 --- a/code/drasil-example/dblpend/lib/Drasil/DblPend/Unitals.hs +++ b/code/drasil-example/dblpend/lib/Drasil/DblPend/Unitals.hs @@ -186,5 +186,5 @@ pendDisAngle :: ConstrConcept pendDisAngle = cuc' "pendDisAngle" (nounPhraseSP "dependent variables") "column vector of displacement of rods with its derivatives" - lTheta' radian (Vect Real) + lTheta' radian (vectNDS "n" Real) [physRange $ UpFrom (Inc, exactDbl 0)] (exactDbl 0) diff --git a/code/drasil-example/gamephysics/lib/Drasil/GamePhysics/DesignDec/Vector.hs b/code/drasil-example/gamephysics/lib/Drasil/GamePhysics/DesignDec/Vector.hs index fa76678b762..ef3325860f1 100644 --- a/code/drasil-example/gamephysics/lib/Drasil/GamePhysics/DesignDec/Vector.hs +++ b/code/drasil-example/gamephysics/lib/Drasil/GamePhysics/DesignDec/Vector.hs @@ -32,7 +32,7 @@ vectEqual = funcDef "vectEqual" [vV1, vV2] Boolean ) ] -vectAdd = funcDef "vectAdd" [vV1, vV2] (Vect Real) +vectAdd = funcDef "vectAdd" [vV1, vV2] (vectND "n" Real) [ FRet (FCall (funcUID vect) [ @@ -42,7 +42,7 @@ vectAdd = funcDef "vectAdd" [vV1, vV2] (Vect Real) ) ] -vectSub = funcDef "vectSub" [vV1, vV2] (Vect Real) +vectSub = funcDef "vectSub" [vV1, vV2] (vectND "n" Real) [ FRet (FCall (funcUID vect) [ @@ -52,7 +52,7 @@ vectSub = funcDef "vectSub" [vV1, vV2] (Vect Real) ) ] -vectMult = funcDef "vectMult" [vV1, vV2] (Vect Real) +vectMult = funcDef "vectMult" [vV1, vV2] (vectND "n" Real) [ FRet (FCall (funcUID vect) [ @@ -62,7 +62,7 @@ vectMult = funcDef "vectMult" [vV1, vV2] (Vect Real) ) ] -vectNeg = funcDef "vectNeg" [v_v] (Vect Real) +vectNeg = funcDef "vectNeg" [v_v] (vectND "n" Real) [ FRet (FCall (funcUID vect) $ map Neg [ @@ -92,7 +92,7 @@ vectCross = funcDef "vectCross" [vV1, vV2] Real ) ] -vectPerp = funcDef "vectPerp" [v_v] (Vect Real) +vectPerp = funcDef "vectPerp" [v_v] (vectND "n" Real) [ FRet (FCall (funcUID vect) [ @@ -102,7 +102,7 @@ vectPerp = funcDef "vectPerp" [v_v] (Vect Real) ) ] -vectRPerp = funcDef "vectRPerp" [v_v] (Vect Real) +vectRPerp = funcDef "vectRPerp" [v_v] (vectND "n" Real) [ FRet (FCall (funcUID vect) [ @@ -112,7 +112,7 @@ vectRPerp = funcDef "vectRPerp" [v_v] (Vect Real) ) ] -vectProject = funcDef "vectProject" [vV1, vV2] (Vect Real) +vectProject = funcDef "vectProject" [vV1, vV2] (vectND "n" Real) [ FRet (FCall (funcUID vectMult) [ @@ -122,7 +122,7 @@ vectProject = funcDef "vectProject" [vV1, vV2] (Vect Real) ) ] -vectForAngle = funcDef "vectForAngle" [rad] (Vect Real) +vectForAngle = funcDef "vectForAngle" [rad] (vectND "n" Real) [ FRet (FCall (funcUID vect) [ @@ -142,7 +142,7 @@ vectToAngle = funcDef "vectToAngle" [v_v] Real ) ] -vectRotate = funcDef "vectRotate" [vV1, vV2] (Vect Real) +vectRotate = funcDef "vectRotate" [vV1, vV2] (vectND "n" Real) [ FRet (FCall (funcUID vect) [ @@ -154,7 +154,7 @@ vectRotate = funcDef "vectRotate" [vV1, vV2] (Vect Real) ) ] -vectUnrotate = funcDef "vectUnrotate" [vV1, vV2] (Vect Real) +vectUnrotate = funcDef "vectUnrotate" [vV1, vV2] (vectND "n" Real) [ FRet (FCall (funcUID vect) [ @@ -176,7 +176,7 @@ vectLength = funcDef "vectLength" [v_v] Real FRet (Sqrt (FCall (funcUID vectLengthSq) [v_v])) ] -vectClamp = funcDef "vectClamp" [v_v, length] (Vect Real) +vectClamp = funcDef "vectClamp" [v_v, length] (vectND "n" Real) [ (FCond (FCall (funcUID vectLength) [v_v]) :< length) [FRet v_v] @@ -185,7 +185,7 @@ vectClamp = funcDef "vectClamp" [v_v, length] (Vect Real) ] ] -vectLerp = funcDef "vectLerp" [vV1, vV2, t] (Vect Real) +vectLerp = funcDef "vectLerp" [vV1, vV2, t] (vectND "n" Real) [ FRet (FCall (funcUID vectAdd) [ @@ -194,7 +194,7 @@ vectLerp = funcDef "vectLerp" [vV1, vV2, t] (Vect Real) ]) ] -vectNormalize = funcDef "vectNormalize" [v_v] (Vect Real) +vectNormalize = funcDef "vectNormalize" [v_v] (vectND "n" Real) [ FRet (FCall (funcUID vectMult) [v_v, 1.0 / FCall (funcUID vectLength) [v_v] + DBL_MIN] diff --git a/code/drasil-example/gamephysics/lib/Drasil/GamePhysics/Unitals.hs b/code/drasil-example/gamephysics/lib/Drasil/GamePhysics/Unitals.hs index 220ae8aeb8d..44fe943afaf 100644 --- a/code/drasil-example/gamephysics/lib/Drasil/GamePhysics/Unitals.hs +++ b/code/drasil-example/gamephysics/lib/Drasil/GamePhysics/Unitals.hs @@ -147,7 +147,7 @@ jVect = uc (dccWDS "unitVectJ" (compoundPhrase' (cn "vertical") (QM.unitVect ^. term)) (phrase QM.unitVect)) (vec $ hat lJ) Real metre normalVect = uc (dccWDS "normalVect" (nounPhraseSent (S "collision" +:+ phrase QM.normalVect)) (phrase QM.normalVect)) - (eqSymb QM.normalVect) (Vect Real) metre + (eqSymb QM.normalVect) (vectNDS "n" Real) metre dVect = uc (dccWDS "unitVectD" (cn "unit vector directed from the center of the large mass to the center of the smaller mass") @@ -214,12 +214,12 @@ timeC = uc (dccWDS "timeC" (cn "denotes the time at collision") initRelVel = uc (dccWDS "v_i^AB" (compoundPhrase' (compoundPhrase' (cn "initial relative") (QP.velocity ^. term)) (cn "between rigid bodies of A and B")) (phrase QP.velocity)) - (sup (sub (eqSymb QP.velocity) QP.initial) (Concat [lBodyA, lBodyB])) (Vect Real) velU + (sup (sub (eqSymb QP.velocity) QP.initial) (Concat [lBodyA, lBodyB])) (vectNDS "n" Real) velU finRelVel = uc (dccWDS "v_f^AB" (compoundPhrase' (compoundPhrase' (cn "final relative") (QP.velocity ^. term)) (cn "between rigid bodies of A and B")) (phrase QP.velocity)) - (sup (sub (eqSymb QP.velocity) QP.final) (Concat [lBodyA, lBodyB])) (Vect Real) velU + (sup (sub (eqSymb QP.velocity) QP.final) (Concat [lBodyA, lBodyB])) (vectNDS "n" Real) velU massIRigidBody = uc (dccWDS "massj" (compoundPhrase' (QPP.mass ^. term) (cn "of the j-th rigid body")) (phrase QPP.mass)) @@ -253,11 +253,11 @@ forcej = uc (dccWDS "forcej" (compoundPhrase' velAP = uc (dccWDS "v^AP" (compoundPhrase' (QP.velocity ^. term) (cn "of the point of collision P in body A")) (phrase QP.velocity)) (sup (eqSymb QP.velocity)(Concat [lBodyA, lPoint])) - (Vect Real) velU + (vectNDS "n" Real) velU velBP = uc (dccWDS "v^BP" (compoundPhrase' (QP.velocity ^. term) (cn "of the point of collision P in body B")) (phrase QP.velocity)) (sup (eqSymb QP.velocity)(Concat [lBodyB, lPoint])) - (Vect Real) velU + (vectNDS "n" Real) velU force_1 = forceParam "1" "first" label1 force_2 = forceParam "2" "second" label2 diff --git a/code/drasil-example/glassbr/lib/Drasil/GlassBR/ModuleDefs.hs b/code/drasil-example/glassbr/lib/Drasil/GlassBR/ModuleDefs.hs index 385e07caeff..4213c84927f 100644 --- a/code/drasil-example/glassbr/lib/Drasil/GlassBR/ModuleDefs.hs +++ b/code/drasil-example/glassbr/lib/Drasil/GlassBR/ModuleDefs.hs @@ -4,7 +4,7 @@ module Drasil.GlassBR.ModuleDefs (allMods, implVars, interpY, interpZ) where -import Language.Drasil (QuantityDict, Space(..), implVar, nounPhraseSP, +import Language.Drasil (QuantityDict, Space(..), vect3DS, implVar, nounPhraseSP, label, sub, HasSymbol(..), HasUID, Symbol) import Language.Drasil.Display (Symbol(..)) import Language.Drasil.ShortHands @@ -64,25 +64,25 @@ y = var "y" "y-coordinate to interpolate at" lY Real z = var "z" "z-coordinate to interpolate at" lZ Real zVector = var "zVector" "list of z values" - (sub lZ (label "vector")) (Vect Real) + (sub lZ (label "vector")) (vect3DS Real) yMatrix = var "yMatrix" "lists of y values at different z values" - (sub lY (label "matrix")) (Vect $ Vect Real) + (sub lY (label "matrix")) (vect3DS $ vect3DS Real) -- TODO: Yuck! Fix this! xMatrix = var "xMatrix" "lists of x values at different z values" - (sub lX (label "matrix")) (Vect $ Vect Real) + (sub lX (label "matrix")) (vect3DS $ vect3DS Real) arr = var "arr" "array in which value should be found" - (label "arr") (Vect Real) --FIXME: temporary variable for findCT? + (label "arr") (vect3DS Real) --FIXME: temporary variable for findCT? x_z_1 = var "x_z_1" "list of x values at a specific z value" - (sub lX (sub lZ one)) (Vect Real) + (sub lX (sub lZ one)) (vect3DS Real) y_z_1 = var "y_z_1" "list of y values at a specific z value" - (sub lY (sub lZ one)) (Vect Real) + (sub lY (sub lZ one)) (vect3DS Real) x_z_2 = var "x_z_2" "list of x values at a specific z value" - (sub lX (sub lZ two)) (Vect Real) + (sub lX (sub lZ two)) (vect3DS Real) y_z_2 = var "y_z_2" "list of y values at a specific z value" - (sub lY (sub lZ two)) (Vect Real) + (sub lY (sub lZ two)) (vect3DS Real) mat = var "mat" "matrix from which column will be extracted" - (label "mat") (Vect $ Vect Real) + (label "mat") (vect3DS $ vect3DS Real) col = var "col" "extracted column" - (label "col") (Vect Real) + (label "col") (vect3DS Real) filename = var "filename" "name of file with x y and z data" (label "filename") String @@ -152,7 +152,7 @@ findCT = funcDef "find" extractColumnCT :: Func extractColumnCT = funcDef "extractColumn" "Extracts a column from a 2D matrix" - [mat, j] (Vect Real) (Just "column of the given matrix at the given index") + [mat, j] (vect3DS Real) (Just "column of the given matrix at the given index") -- TODO: is this correct? [ fDecDef col (matrix [[]]), -- diff --git a/code/drasil-example/pdcontroller/lib/Drasil/PDController/Unitals.hs b/code/drasil-example/pdcontroller/lib/Drasil/PDController/Unitals.hs index 15e85477aac..57ee941484a 100644 --- a/code/drasil-example/pdcontroller/lib/Drasil/PDController/Unitals.hs +++ b/code/drasil-example/pdcontroller/lib/Drasil/PDController/Unitals.hs @@ -119,7 +119,7 @@ odeAbsTolConst = mkQuantDef dqdAbsTol (dbl 1.0e-10) odeRelTolConst = mkQuantDef dqdRelTol (dbl 1.0e-10) opProcessVariable - = constrained' (dqdNoUnit processVariable symYT (Vect Real)) + = constrained' (dqdNoUnit processVariable symYT (vectNDS "n" Real)) [gtZeroConstr] (exactDbl 1) qdProcessVariableTD = qw opProcessVariable diff --git a/code/drasil-example/ssp/lib/Drasil/SSP/Unitals.hs b/code/drasil-example/ssp/lib/Drasil/SSP/Unitals.hs index 217315c393e..d32c644ca0f 100644 --- a/code/drasil-example/ssp/lib/Drasil/SSP/Unitals.hs +++ b/code/drasil-example/ssp/lib/Drasil/SSP/Unitals.hs @@ -100,20 +100,20 @@ slopeDist, slopeHght, waterDist, waterHght, xMaxExtSlip, xMaxEtrSlip, slopeDist = uq (constrained' (uc' "x_slope,i" (nounPhraseSent $ plural xCoord `S.of_` S "the slope") (plural xCoord `S.of_` S "points on the soil slope") - (sub (vec lX) lSlope) (Vect Real) metre) [] (exactDbl 0)) defaultUncrt + (sub (vec lX) lSlope) (vectNDS "n" Real) metre) [] (exactDbl 0)) defaultUncrt slopeHght = uq (constrained' (uc' "y_slope,i" (nounPhraseSent $ plural yCoord `S.of_` S "the slope") (plural yCoord `S.of_` S "points on the soil slope") - (sub (vec lY) lSlope) (Vect Real) metre) [] (exactDbl 0)) defaultUncrt + (sub (vec lY) lSlope) (vectNDS "n" Real) metre) [] (exactDbl 0)) defaultUncrt waterDist = uqc "x_wt,i" (nounPhraseSent $ plural xCoord `S.of_` S "the water table") "x-positions of the water table" - (sub (vec lX) lWatTab) metre (Vect Real) [] (exactDbl 0) defaultUncrt + (sub (vec lX) lWatTab) metre (vectNDS "n" Real) [] (exactDbl 0) defaultUncrt waterHght = uqc "y_wt,i" (nounPhraseSent $ plural yCoord `S.of_` S "the water table") "heights of the water table" - (sub (vec lY) lWatTab) metre (Vect Real) [] (exactDbl 0) defaultUncrt + (sub (vec lY) lWatTab) metre (vectNDS "n" Real) [] (exactDbl 0) defaultUncrt xMaxExtSlip = uq (constrained' (uc' "x_slip^maxExt" (nounPhraseSent $ S "maximum exit" +:+ phrase xCoord) @@ -225,15 +225,15 @@ accel, genericMass, genericF, genericA, genericM, genericV, genericW, intNormForce = uc' "G_i" (cn "interslice normal forces") (S "the forces per meter" `S.inThe` phrase zDir +:+ S "exerted between each pair" `S.of_` S "adjacent slices") - (vec cG) (Vect Real) forcePerMeterU + (vec cG) (vectNDS "n" Real) forcePerMeterU slipHght = uc' "y_slip,i" (nounPhraseSent $ plural yCoord `S.ofThe` S "slip surface") (S "heights of the slip surface") - (sub (vec lY) lSlip) (Vect Real) metre + (sub (vec lY) lSlip) (vectNDS "n" Real) metre slipDist = uc' "x_slip,i" (nounPhraseSent $ plural xCoord `S.ofThe` S "slip surface") (plural xCoord `S.of_` S "points on the slip surface") - (sub (vec lX) lSlip) (Vect Real) metre + (sub (vec lX) lSlip) (vectNDS "n" Real) metre xi = uc' "x_i" (nounPhraseSent $ phrase xCoord) (phraseNP (NP.the (xCoord `inThe` cartesian))) lX Real metre @@ -279,79 +279,79 @@ shrResI = uc' "shrRes" (cn "resistive shear forces") shearFNoIntsl = uc' "T_i" (cn ("mobilized shear forces " ++ wiif)) (pluralNP (the mobilizedShear) +:+ S "per meter" +:+ S wiif `S.inThe` phrase zDir `S.for` S "each slice") - (vec cT) (Vect Real) forcePerMeterU + (vec cT) (vectNDS "n" Real) forcePerMeterU shearRNoIntsl = uc' "R_i" (cn ("resistive shear forces " ++ wiif)) (pluralNP (the resistiveShear) +:+ S "per meter" +:+ S wiif `S.inThe` phrase zDir `S.for` S "each slice") - (vec cR) (Vect Real) forcePerMeterU + (vec cR) (vectNDS "n" Real) forcePerMeterU slcWght = uc' "W_i" (cn "weights") (S "the downward force per meter" `S.inThe` phrase zDir +:+ S "on each slice caused by" +:+ phrase gravity) - (vec cW) (Vect Real) forcePerMeterU + (vec cW) (vectNDS "n" Real) forcePerMeterU watrForce = uc' "H_i" (cn "interslice normal water forces") (S "the normal water forces per meter" `S.inThe` phrase zDir +:+ S "exerted" `S.inThe` phrase xDir +:+ S "between each pair" `S.of_` S "adjacent slices") - (vec cH) (Vect Real) forcePerMeterU + (vec cH) (vectNDS "n" Real) forcePerMeterU intShrForce = uc' "X_i" (cn "interslice shear forces") (S "the shear forces per meter" `S.inThe` phrase zDir +:+ S "exerted between adjacent slices") - (vec cX) (Vect Real)forcePerMeterU + (vec cX) (vectNDS "n" Real)forcePerMeterU baseHydroForce = uc' "U_b,i" (cn "base hydrostatic forces") (S "the forces per meter" `S.inThe` phrase zDir +:+ S "from water pressure within each slice") - (sub (vec cU) lBase) (Vect Real) forcePerMeterU + (sub (vec cU) lBase) (vectNDS "n" Real) forcePerMeterU surfHydroForce = uc' "U_t,i" (cn "surface hydrostatic forces") (S "the forces per meter" `S.inThe` phrase zDir +:+ S "from water pressure acting" +:+ S "into each slice from standing water" `S.onThe` S "slope surface") - (sub (vec cU) lSurface) (Vect Real) forcePerMeterU + (sub (vec cU) lSurface) (vectNDS "n" Real) forcePerMeterU totNrmForce = uc' "N_i" (cn "normal forces") (S "the total reactive forces per meter" `S.inThe` phrase zDir +:+ S "for each slice" `S.ofA` S "soil surface subject to a body resting on it") - (vec cN) (Vect Real) forcePerMeterU + (vec cN) (vectNDS "n" Real) forcePerMeterU nrmFSubWat = uc' "N'_i" (cn "effective normal forces") (S "the forces per meter" `S.inThe` phrase zDir `S.for` S "each slice" `S.ofA` S "soil surface" `sC` S "subtracting pore water reactive force from total reactive force") - (vec (prime $ variable "N")) (Vect Real) forcePerMeterU + (vec (prime $ variable "N")) (vectNDS "n" Real) forcePerMeterU surfLoad = uc' "Q_i" (cn "external forces") (S "the forces per meter" `S.inThe` phrase zDir +:+ S "acting into the surface from the midpoint" `S.of_` S "each slice") - (vec cQ) (Vect Real) forcePerMeterU + (vec cQ) (vectNDS "n" Real) forcePerMeterU baseAngle = uc' "alpha_i" (cn "base angles") (S "the angles between the base" `S.of_` S "each slice and the horizontal") - (vec lAlpha) (Vect Real) degree + (vec lAlpha) (vectNDS "n" Real) degree surfAngle = uc' "beta_i" (cn "surface angles") (S "the angles between the surface" `S.of_` S "each slice and the horizontal") - (vec lBeta) (Vect Real) degree + (vec lBeta) (vectNDS "n" Real) degree impLoadAngle = uc' "omega_i" (cn "imposed load angles") (S "the angles between the external force acting into the surface" `S.of_` S "each slice and the vertical") - (vec lOmega) (Vect Real) degree + (vec lOmega) (vectNDS "n" Real) degree baseWthX = uc' "b_i" (cn "base width of slices") (S "the width" `S.of_` S "each slice" `S.inThe` phrase xDir) - (vec lB) (Vect Real) metre + (vec lB) (vectNDS "n" Real) metre baseLngth = uc' "l_b,i" (cn "total base lengths of slices") (S "the lengths of each slice in the direction parallel to the slope of the base") - (sub (vec cL) lB) (Vect Real) metre + (sub (vec cL) lB) (vectNDS "n" Real) metre surfLngth = uc' "l_s,i" (cn "surface lengths of slices") (S "the lengths" `S.of_` S "each slice" `S.inThe` S "direction parallel" `S.toThe` S "slope" `S.ofThe` S "surface") - (sub (vec cL) lS) (Vect Real) metre + (sub (vec cL) lS) (vectNDS "n" Real) metre midpntHght = uc' "h_i" (nounPhraseSent $ phrase yDir +:+ S "heights" `S.of_` S "slices") (S "the heights" `S.inThe` phrase yDir +:+ S "from the base" `S.of_` S "each slice" `S.toThe` S "slope surface" `sC` S "at the" +:+ phrase xDir +:+ S "midpoint" `S.ofThe` S "slice") - (vec lH) (Vect Real) metre + (vec lH) (vectNDS "n" Real) metre porePressure = uc' "u" (cn "pore pressure") (S "the pressure that comes from water within the soil") lU Real pascal @@ -370,12 +370,12 @@ sliceHghtW = uc' "h_z,w,i" (cn "heights of the water table") nrmShearNum = uc' "C_num,i" (cn "proportionality constant numerator") (S $ "values for each slice that sum together to form the numerator of the " ++ "interslice normal to shear force proportionality constant") - (sub (vec cC) lNum) (Vect Real) newton + (sub (vec cC) lNum) (vectNDS "n" Real) newton nrmShearDen = uc' "C_den,i" (cn "proportionality constant denominator") (S $ "values for each slice that sum together to form the denominator of the " ++ "interslice normal to shear force proportionality constant") - (sub (vec cC) lDen) (Vect Real) newton + (sub (vec cC) lDen) (vectNDS "n" Real) newton fx = uc' "fx" (nounPhraseSent $ phrase xCoord `S.ofThe` S "force") (S "the force acting" `S.inThe` phrase xDir) (subX cF) Real newton @@ -399,11 +399,11 @@ watForceSum = uc' "F_x^H" (cn "sums of the interslice normal water forces") sliceHghtRight = uc' "h^R" (cn "heights of the right side of slices") (S "the heights" `S.ofThe` S "right side" `S.of_` S "each slice" `sC` S "assuming slice surfaces have negative slope") - (sup (vec lH) lRight) (Vect Real) metre + (sup (vec lH) lRight) (vectNDS "n" Real) metre sliceHghtLeft = uc' "h^L" (cn "heights of the left side of slices") (S "the heights" `S.ofThe` S "left side" `S.of_` S "each slice" `sC` S "assuming slice surfaces have negative slope") - (sup (vec lH) lLeft) (Vect Real) metre + (sup (vec lH) lLeft) (vectNDS "n" Real) metre totNormStress = uc' "sigma" (cn' "total normal stress") (S "the total force per area acting" `S.onThe` S "soil mass") lSigma Real pascal @@ -477,13 +477,13 @@ mobShrC = dqd' (dcc "Psi" (nounPhraseSP "second function for incorporating interslice forces into shear force") ("the function for converting mobile shear " ++ wiif ++ ", to a calculation considering the interslice forces")) - (const (vec cPsi)) (Vect Real) Nothing + (const (vec cPsi)) (vectNDS "n" Real) Nothing shrResC = dqd' (dcc "Phi" (nounPhraseSP "first function for incorporating interslice forces into shear force") ("the function for converting resistive shear " ++ wiif ++ ", to a calculation considering the interslice forces")) - (const (vec cPhi)) (Vect Real) Nothing + (const (vec cPhi)) (vectNDS "n" Real) Nothing -------------------- -- Index Function -- diff --git a/code/drasil-example/swhs/lib/Drasil/SWHS/Unitals.hs b/code/drasil-example/swhs/lib/Drasil/SWHS/Unitals.hs index 8201bfe7496..10348306d6d 100644 --- a/code/drasil-example/swhs/lib/Drasil/SWHS/Unitals.hs +++ b/code/drasil-example/swhs/lib/Drasil/SWHS/Unitals.hs @@ -415,7 +415,7 @@ outputs = [tempW, tempPCM, watE, pcmE] tempW = cuc' "tempW" (nounPhraseSP "temperature of the water") "the average kinetic energy of the particles within the water" - (sub (eqSymb temp) lWater) centigrade (Vect Real) + (sub (eqSymb temp) lWater) centigrade (vectNDS "n" Real) -- TODO: investigate if this is right [physRange $ Bounded (Inc, sy tempInit) (Inc, sy tempC)] (exactDbl 0) -- Constraint 19 diff --git a/code/drasil-gool/lib/Drasil/GOOL/LanguageRenderer/Macros.hs b/code/drasil-gool/lib/Drasil/GOOL/LanguageRenderer/Macros.hs index b20c9728f42..2f06540bc59 100644 --- a/code/drasil-gool/lib/Drasil/GOOL/LanguageRenderer/Macros.hs +++ b/code/drasil-gool/lib/Drasil/GOOL/LanguageRenderer/Macros.hs @@ -157,8 +157,8 @@ stringListLists lsts sl = do "Value passed to stringListLists must be a list of strings" listVals [] = loop listVals (List _:vs) = listVals vs - listVals _ = error - "All values passed to stringListLists must have list types" + listVals x = error $ + "All values passed to stringListLists must have list types. Received " ++ show x loop = IC.forRange var_i (IC.litInt 0) (IC.listSize sl #/ numLists) (IC.litInt 1) (bodyStatements $ appendLists (map IC.valueOf lsts) 0) appendLists [] _ = [] diff --git a/code/drasil-lang/lib/Language/Drasil.hs b/code/drasil-lang/lib/Language/Drasil.hs index 3a87785c253..91e0e34636a 100644 --- a/code/drasil-lang/lib/Language/Drasil.hs +++ b/code/drasil-lang/lib/Language/Drasil.hs @@ -16,7 +16,8 @@ module Language.Drasil ( , oneHalf, oneThird , apply1, apply2 , m2x2, vec2D, dgnl2x2, rowVec, columnVec, mkSet - , Completeness, Relation + , vScale, vAdd, vSub + , Completeness, Relation, BasisBlades -- ** Literals Language , Literal @@ -269,7 +270,8 @@ module Language.Drasil ( -- | Used for rendering mathematical symbols in Drasil. -- Language.Drasil.Space - , Space(..) + , Space(..), Dimension(..) + , vect2DS, vect3DS, vectS, vectNDS , RealInterval(..), Inclusive(..) , DomainDesc(..), RTopology(..), ContinuousDomainDesc, DiscreteDomainDesc , getActorName, getInnerSpace @@ -305,8 +307,10 @@ import Language.Drasil.WellTyped (RequiresChecking(..), Typed(..), TypingContext import Language.Drasil.Expr.Class (ExprC(..), frac, recip_, square, half, oneHalf, oneThird, apply1, apply2, - m2x2, vec2D, dgnl2x2, rowVec, columnVec, mkSet) -import Language.Drasil.Expr.Lang (Expr, Completeness, Relation) + m2x2, vec2D, dgnl2x2, rowVec, columnVec, mkSet, + vScale, vAdd, vSub + ) +import Language.Drasil.Expr.Lang (Expr, Completeness, Relation, BasisBlades) import Language.Drasil.Literal.Class (LiteralC(..)) import Language.Drasil.Literal.Lang (Literal) import Language.Drasil.ModelExpr.Class (ModelExprC(..)) @@ -375,7 +379,7 @@ import Language.Drasil.Data.Citation (CiteField(..), HP(..), CitationKind(..) , compareAuthYearTitle) import Language.Drasil.NounPhrase import Language.Drasil.ShortName (ShortName, shortname', getSentSN, HasShortName(..)) -import Language.Drasil.Space (Space(..), RealInterval(..), Inclusive(..), +import Language.Drasil.Space (Space(..), vect2DS, vect3DS, vectS, vectNDS, Dimension(..), RealInterval(..), Inclusive(..), RTopology(..), DomainDesc(..), ContinuousDomainDesc, DiscreteDomainDesc, getActorName, getInnerSpace, HasSpace(..), mkFunction, Primitive) import Language.Drasil.Sentence (Sentence(..), SentenceStyle(..), TermCapitalization(..), RefInfo(..), (+:+), diff --git a/code/drasil-lang/lib/Language/Drasil/Chunk/CodeVar.hs b/code/drasil-lang/lib/Language/Drasil/Chunk/CodeVar.hs index 75da587a917..b5c9ddf4a5a 100644 --- a/code/drasil-lang/lib/Language/Drasil/Chunk/CodeVar.hs +++ b/code/drasil-lang/lib/Language/Drasil/Chunk/CodeVar.hs @@ -120,7 +120,7 @@ instance MayHaveUnit CodeFuncChunk where getUnit = getUnit . view ccf -- Changes a 'CodeVarChunk'\'s space from 'Vect' to 'Array'. listToArray :: CodeVarChunk -> CodeVarChunk listToArray c = newSpc (c ^. typ) - where newSpc (Vect t) = CodeVC (CodeC (implVar' (show $ c +++ "_array") + where newSpc (ClifS d t) = CodeVC (CodeC (implVar' (show $ c +++ "_array") (c ^. term) (getA c) (Array t) (symbol c Implementation) (getUnit c)) Var) (c ^. obv) newSpc _ = c diff --git a/code/drasil-lang/lib/Language/Drasil/CodeExpr/Convert.hs b/code/drasil-lang/lib/Language/Drasil/CodeExpr/Convert.hs index 7a8a506f8c2..cd82874a236 100644 --- a/code/drasil-lang/lib/Language/Drasil/CodeExpr/Convert.hs +++ b/code/drasil-lang/lib/Language/Drasil/CodeExpr/Convert.hs @@ -37,16 +37,16 @@ expr (LD.Set e es) = Set e $ map expr es expr (E.Variable s e) = Variable s $ expr e expr (LD.UnaryOp uo e) = UnaryOp (uFunc uo) (expr e) expr (LD.UnaryOpB uo e) = UnaryOpB (uFuncB uo) (expr e) -expr (LD.UnaryOpVV uo e) = UnaryOpVV (uFuncVV uo) (expr e) -expr (LD.UnaryOpVN uo e) = UnaryOpVN (uFuncVN uo) (expr e) +expr (LD.UnaryOpCC uo e) = UnaryOpCC (uFuncCC uo) (expr e) +expr (LD.UnaryOpCN uo e) = UnaryOpCN (uFuncCN uo) (expr e) expr (LD.ArithBinaryOp bo l r) = ArithBinaryOp (arithBinOp bo) (expr l) (expr r) expr (LD.BoolBinaryOp bo l r) = BoolBinaryOp (boolBinOp bo) (expr l) (expr r) expr (LD.EqBinaryOp bo l r) = EqBinaryOp (eqBinOp bo) (expr l) (expr r) expr (LD.LABinaryOp bo l r) = LABinaryOp (laBinOp bo) (expr l) (expr r) expr (LD.OrdBinaryOp bo l r) = OrdBinaryOp (ordBinOp bo) (expr l) (expr r) -expr (LD.VVVBinaryOp bo l r) = VVVBinaryOp (vvvBinOp bo) (expr l) (expr r) -expr (LD.VVNBinaryOp bo l r) = VVNBinaryOp (vvnBinOp bo) (expr l) (expr r) -expr (LD.NVVBinaryOp bo l r) = NVVBinaryOp (nvvBinOp bo) (expr l) (expr r) +expr (LD.CCCBinaryOp bo l r) = CCCBinaryOp (cccBinOp bo) (expr l) (expr r) +expr (LD.CCNBinaryOp bo l r) = CCNBinaryOp (ccnBinOp bo) (expr l) (expr r) +expr (LD.NCCBinaryOp bo l r) = NCCBinaryOp (nccBinOp bo) (expr l) (expr r) expr (LD.ESSBinaryOp bo l r) = ESSBinaryOp (essBinOp bo) (expr l) (expr r) expr (LD.ESBBinaryOp bo l r) = ESBBinaryOp (esbBinOp bo) (expr l) (expr r) expr (LD.Operator aao dd e) = Operator (assocArithOp aao) (renderDomainDesc dd) (expr e) @@ -93,16 +93,16 @@ ordBinOp LD.Gt = Gt ordBinOp LD.LEq = LEq ordBinOp LD.GEq = GEq -vvvBinOp :: LD.VVVBinOp -> VVVBinOp -vvvBinOp LD.Cross = Cross -vvvBinOp LD.VAdd = VAdd -vvvBinOp LD.VSub = VSub +cccBinOp :: LD.CCCBinOp -> CCCBinOp +cccBinOp LD.Cross = Cross +cccBinOp LD.CAdd = CAdd +cccBinOp LD.CSub = CSub -vvnBinOp :: LD.VVNBinOp -> VVNBinOp -vvnBinOp LD.Dot = Dot +ccnBinOp :: LD.CCNBinOp -> CCNBinOp +ccnBinOp LD.Dot = Dot -nvvBinOp :: LD.NVVBinOp -> NVVBinOp -nvvBinOp LD.Scale = Scale +nccBinOp :: LD.NCCBinOp -> NCCBinOp +nccBinOp LD.Scale = Scale essBinOp :: LD.ESSBinOp -> ESSBinOp essBinOp LD.SAdd = SAdd @@ -142,9 +142,9 @@ uFunc LD.Neg = Neg uFuncB :: LD.UFuncB -> UFuncB uFuncB LD.Not = Not -uFuncVV :: LD.UFuncVV -> UFuncVV -uFuncVV LD.NegV = NegV +uFuncCC :: LD.UFuncCC -> UFuncCC +uFuncCC LD.NegC = NegC -uFuncVN :: LD.UFuncVN -> UFuncVN -uFuncVN LD.Norm = Norm -uFuncVN LD.Dim = Dim +uFuncCN :: LD.UFuncCN -> UFuncCN +uFuncCN LD.Norm = Norm +uFuncCN LD.Dim = Dim diff --git a/code/drasil-lang/lib/Language/Drasil/CodeExpr/Development.hs b/code/drasil-lang/lib/Language/Drasil/CodeExpr/Development.hs index 00248e5fb0f..5c92207244c 100644 --- a/code/drasil-lang/lib/Language/Drasil/CodeExpr/Development.hs +++ b/code/drasil-lang/lib/Language/Drasil/CodeExpr/Development.hs @@ -3,8 +3,8 @@ module Language.Drasil.CodeExpr.Development ( -- CodeExpr CodeExpr(..), ArithBinOp(..), EqBinOp(..), BoolBinOp(..), LABinOp(..), OrdBinOp(..), - VVVBinOp(..), VVNBinOp(..), NVVBinOp(..), ESSBinOp(..), ESBBinOp(..), AssocArithOper(..), AssocBoolOper(..), AssocConcatOper(..), - UFunc(..), UFuncB(..), UFuncVV(..), UFuncVN(..), + CCCBinOp(..), CCNBinOp(..), NCCBinOp(..), ESSBinOp(..), ESBBinOp(..), AssocArithOper(..), AssocBoolOper(..), AssocConcatOper(..), + UFunc(..), UFuncB(..), UFuncCC(..), UFuncCN(..), -- Class CodeExprC(..), -- Extract @@ -17,9 +17,9 @@ module Language.Drasil.CodeExpr.Development ( ) where import Language.Drasil.CodeExpr.Lang (CodeExpr(..), - UFuncVV(..), UFuncVN(..), UFuncB(..), UFunc(..), - AssocBoolOper(..), AssocArithOper(..), AssocConcatOper(..),VVNBinOp(..), NVVBinOp(..), ESSBinOp(..), ESBBinOp(..), - VVVBinOp(..), OrdBinOp(..), LABinOp(..), BoolBinOp(..), EqBinOp(..), + UFuncCC(..), UFuncCN(..), UFuncB(..), UFunc(..), + AssocBoolOper(..), AssocArithOper(..), AssocConcatOper(..),CCNBinOp(..), NCCBinOp(..), ESSBinOp(..), ESBBinOp(..), + CCCBinOp(..), OrdBinOp(..), LABinOp(..), BoolBinOp(..), EqBinOp(..), ArithBinOp(..)) import Language.Drasil.CodeExpr.Class (CodeExprC(..)) import Language.Drasil.CodeExpr.Extract (eDep, eDep', eNamesRI, eNamesRI') diff --git a/code/drasil-lang/lib/Language/Drasil/CodeExpr/Extract.hs b/code/drasil-lang/lib/Language/Drasil/CodeExpr/Extract.hs index d9f39db8468..6ae576cb00b 100644 --- a/code/drasil-lang/lib/Language/Drasil/CodeExpr/Extract.hs +++ b/code/drasil-lang/lib/Language/Drasil/CodeExpr/Extract.hs @@ -27,16 +27,16 @@ eNames (Field o f) = [o, f] eNames (Case _ ls) = concatMap (eNames . fst) ls ++ concatMap (eNames . snd) ls eNames (UnaryOp _ u) = eNames u eNames (UnaryOpB _ u) = eNames u -eNames (UnaryOpVV _ u) = eNames u -eNames (UnaryOpVN _ u) = eNames u +eNames (UnaryOpCC _ u) = eNames u +eNames (UnaryOpCN _ u) = eNames u eNames (ArithBinaryOp _ a b) = eNames a ++ eNames b eNames (BoolBinaryOp _ a b) = eNames a ++ eNames b eNames (EqBinaryOp _ a b) = eNames a ++ eNames b eNames (LABinaryOp _ a b) = eNames a ++ eNames b eNames (OrdBinaryOp _ a b) = eNames a ++ eNames b -eNames (VVVBinaryOp _ a b) = eNames a ++ eNames b -eNames (VVNBinaryOp _ a b) = eNames a ++ eNames b -eNames (NVVBinaryOp _ a b) = eNames a ++ eNames b +eNames (CCCBinaryOp _ a b) = eNames a ++ eNames b +eNames (CCNBinaryOp _ a b) = eNames a ++ eNames b +eNames (NCCBinaryOp _ a b) = eNames a ++ eNames b eNames (ESSBinaryOp _ _ s) = eNames s eNames (ESBBinaryOp _ _ s) = eNames s eNames (Operator _ _ e) = eNames e @@ -71,16 +71,16 @@ eNames' (Case _ ls) = concatMap (eNames' . fst) ls ++ concatMap (eNames' . snd) ls eNames' (UnaryOp _ u) = eNames' u eNames' (UnaryOpB _ u) = eNames' u -eNames' (UnaryOpVV _ u) = eNames' u -eNames' (UnaryOpVN _ u) = eNames' u +eNames' (UnaryOpCC _ u) = eNames' u +eNames' (UnaryOpCN _ u) = eNames' u eNames' (ArithBinaryOp _ a b) = eNames' a ++ eNames' b eNames' (BoolBinaryOp _ a b) = eNames' a ++ eNames' b eNames' (EqBinaryOp _ a b) = eNames' a ++ eNames' b eNames' (LABinaryOp _ a b) = eNames' a ++ eNames' b eNames' (OrdBinaryOp _ a b) = eNames' a ++ eNames' b -eNames' (VVVBinaryOp _ a b) = eNames' a ++ eNames' b -eNames' (VVNBinaryOp _ a b) = eNames' a ++ eNames' b -eNames' (NVVBinaryOp _ a b) = eNames' a ++ eNames' b +eNames' (CCCBinaryOp _ a b) = eNames' a ++ eNames' b +eNames' (CCNBinaryOp _ a b) = eNames' a ++ eNames' b +eNames' (NCCBinaryOp _ a b) = eNames' a ++ eNames' b eNames' (ESSBinaryOp _ _ s) = eNames' s eNames' (ESBBinaryOp _ _ s) = eNames' s eNames' (Operator _ _ e) = eNames' e diff --git a/code/drasil-lang/lib/Language/Drasil/CodeExpr/Lang.hs b/code/drasil-lang/lib/Language/Drasil/CodeExpr/Lang.hs index b45f23b75b4..1fea7628a5c 100644 --- a/code/drasil-lang/lib/Language/Drasil/CodeExpr/Lang.hs +++ b/code/drasil-lang/lib/Language/Drasil/CodeExpr/Lang.hs @@ -3,10 +3,12 @@ module Language.Drasil.CodeExpr.Lang where import Prelude hiding (sqrt) +import Numeric.Natural -import Language.Drasil.Expr.Lang (Completeness) +import Language.Drasil.Expr.Lang (Completeness, BasisBlades(..)) import Language.Drasil.Literal.Class (LiteralC(..)) import Language.Drasil.Literal.Lang (Literal(..)) +import qualified Language.Drasil.Space as S import Language.Drasil.Space (Space, RealInterval, DiscreteDomainDesc) import Drasil.Database.UID (UID) @@ -33,16 +35,20 @@ data LABinOp = Index | IndexOf data OrdBinOp = Lt | Gt | LEq | GEq deriving Eq --- | @Vector x Vector -> Vector@ binary operations (cross product, vector addition, vector sub). -data VVVBinOp = Cross | VAdd | VSub +-- | @Clif x Clif -> Clif@ binary operations (cross product, clif addition, clif sub, wedge product, geometric product). +data CCCBinOp = Cross | CAdd | CSub | WedgeProd | GeometricProd deriving Eq --- | @Vector x Vector -> Number@ binary operations (dot product). -data VVNBinOp = Dot +-- | @Clif x Clif -> Number@ binary operations (dot product). +data CCNBinOp = Dot deriving Eq --- | @Number x Vector -> Vector@ binary operations (scaling). -data NVVBinOp = Scale +-- | @Number x Clif -> Clif@ binary operations (scaling). +data NCCBinOp = Scale + deriving Eq + +-- | @Natural x Clif -> Clif@ binary operations (grade selection). +data NatCCBinOp = GradeSelect deriving Eq -- | Element + Set -> Set @@ -72,12 +78,12 @@ data UFunc = Abs | Log | Ln | Sin | Cos | Tan | Sec | Csc | Cot | Arcsin data UFuncB = Not deriving Eq --- | @Vector -> Vector@ operators. -data UFuncVV = NegV +-- | @Clif -> Clif@ operators. +data UFuncCC = NegC deriving Eq --- | @Vector -> Number@ operators. -data UFuncVN = Norm | Dim +-- | @Clif -> Number@ operators (norm, dim, grade). +data UFuncCN = Norm | Dim | Grade deriving Eq -- * CodeExpr @@ -128,10 +134,10 @@ data CodeExpr where UnaryOp :: UFunc -> CodeExpr -> CodeExpr -- | Unary operation for @Bool -> Bool@ operations. UnaryOpB :: UFuncB -> CodeExpr -> CodeExpr - -- | Unary operation for @Vector -> Vector@ operations. - UnaryOpVV :: UFuncVV -> CodeExpr -> CodeExpr - -- | Unary operation for @Vector -> Number@ operations. - UnaryOpVN :: UFuncVN -> CodeExpr -> CodeExpr + -- | Unary operation for @Clif -> Clif@ operations. + UnaryOpCC :: UFuncCC -> CodeExpr -> CodeExpr + -- | Unary operation for @Clif -> Number@ operations. + UnaryOpCN :: UFuncCN -> CodeExpr -> CodeExpr -- | Binary operator for arithmetic between expressions (fractional, power, and subtraction). ArithBinaryOp :: ArithBinOp -> CodeExpr -> CodeExpr -> CodeExpr @@ -143,12 +149,14 @@ data CodeExpr where LABinaryOp :: LABinOp -> CodeExpr -> CodeExpr -> CodeExpr -- | Binary operator for ordering expressions (less than, greater than, etc.). OrdBinaryOp :: OrdBinOp -> CodeExpr -> CodeExpr -> CodeExpr - -- | Binary operator for @Vector x Vector -> Vector@ operations (cross product). - VVVBinaryOp :: VVVBinOp -> CodeExpr -> CodeExpr -> CodeExpr - -- | Binary operator for @Vector x Vector -> Number@ operations (dot product). - VVNBinaryOp :: VVNBinOp -> CodeExpr -> CodeExpr -> CodeExpr - -- | Binary operator for @Number x Vector -> Vector@ operations (scaling). - NVVBinaryOp :: NVVBinOp -> CodeExpr -> CodeExpr -> CodeExpr + -- | Binary operator for @Clif x Clif -> Clif@ operations (cross product). + CCCBinaryOp :: CCCBinOp -> CodeExpr -> CodeExpr -> CodeExpr + -- | Binary operator for @Clif x Clif -> Number@ operations (dot product). + CCNBinaryOp :: CCNBinOp -> CodeExpr -> CodeExpr -> CodeExpr + -- | Binary operator for @Number x Clif -> Clif@ operations (scaling). + NCCBinaryOp :: NCCBinOp -> CodeExpr -> CodeExpr -> CodeExpr + -- | Binary operator for @Natural x Clif -> Clif@ operations (grade selection). + NatCCBinaryOp :: NatCCBinOp -> Natural -> CodeExpr -> CodeExpr -- | Set operator for Set + Set -> Set ESSBinaryOp :: ESSBinOp -> CodeExpr -> CodeExpr -> CodeExpr -- | Set operator for Element + Set -> Bool @@ -163,6 +171,8 @@ data CodeExpr where -- | A different kind of 'IsIn'. A 'UID' is an element of an interval. RealI :: UID -> RealInterval CodeExpr CodeExpr -> CodeExpr + Clif :: S.Dimension -> BasisBlades CodeExpr -> CodeExpr + instance LiteralC CodeExpr where str = Lit . str int = Lit . int diff --git a/code/drasil-lang/lib/Language/Drasil/CodeExpr/Precedence.hs b/code/drasil-lang/lib/Language/Drasil/CodeExpr/Precedence.hs index 6b0c667cbd3..53285180b26 100644 --- a/code/drasil-lang/lib/Language/Drasil/CodeExpr/Precedence.hs +++ b/code/drasil-lang/lib/Language/Drasil/CodeExpr/Precedence.hs @@ -1,8 +1,8 @@ module Language.Drasil.CodeExpr.Precedence (precA, precB, eprec) where -import Language.Drasil.CodeExpr.Lang (CodeExpr(..), UFuncVV, UFuncVN, UFuncB(..), - UFunc(..), AssocBoolOper(..), AssocArithOper(..), VVNBinOp, NVVBinOp, - VVVBinOp, OrdBinOp, LABinOp, BoolBinOp, EqBinOp, ArithBinOp(..), AssocConcatOper(..), ESSBinOp, ESBBinOp) +import Language.Drasil.CodeExpr.Lang (CodeExpr(..), UFuncCC, UFuncCN, UFuncB(..), + UFunc(..), AssocBoolOper(..), AssocArithOper(..), CCNBinOp, NCCBinOp, + CCCBinOp, OrdBinOp, LABinOp, BoolBinOp, EqBinOp, ArithBinOp(..), AssocConcatOper(..), ESSBinOp, ESBBinOp) -- These precedences are inspired from Haskell/F# -- as documented at http://kevincantu.org/code/operators.html @@ -30,17 +30,17 @@ prec2LA _ = 250 prec2Ord :: OrdBinOp -> Int prec2Ord _ = 130 --- | prec2VVV - precedence for Vec->Vec->Vec-related binary operations. -prec2VVV :: VVVBinOp -> Int -prec2VVV _ = 190 +-- | prec2CCC - precedence for Clif->Clif->Clif-related binary operations. +prec2CCC :: CCCBinOp -> Int +prec2CCC _ = 190 --- | prec2VVN - precedence for Vec->Vec->Num-related binary operations. -prec2VVN :: VVNBinOp -> Int -prec2VVN _ = 190 +-- | prec2CCN - precedence for Clif->Clif->Num-related binary operations. +prec2CCN :: CCNBinOp -> Int +prec2CCN _ = 190 --- | prec2NVV - precedence for Num->Vec->Vec-related binary operations. -prec2NVV :: NVVBinOp -> Int -prec2NVV _ = 190 +-- | prec2NCC - precedence for Num->Clif->Clif-related binary operations. +prec2NCC :: NCCBinOp -> Int +prec2NCC _ = 190 -- | prec2ESS - precedence for Element->Set->Set-related binary operations. prec2ESS :: ESSBinOp -> Int @@ -74,12 +74,12 @@ prec1B :: UFuncB -> Int prec1B Not = 230 -- | prec1VV - precedence of vector-vector-related unary operators. -prec1VV :: UFuncVV -> Int -prec1VV _ = 250 +prec1CC :: UFuncCC -> Int +prec1CC _ = 250 -- | prec1VN - precedence of vector-number-related unary operators. -prec1VN :: UFuncVN -> Int -prec1VN _ = 230 +prec1CN :: UFuncCN -> Int +prec1CN _ = 230 -- | eprec - "Expression" precedence. eprec :: CodeExpr -> Int @@ -98,17 +98,17 @@ eprec Set{} = 220 eprec (Variable _ _) = 220 eprec (UnaryOp fn _) = prec1 fn eprec (UnaryOpB fn _) = prec1B fn -eprec (UnaryOpVV fn _) = prec1VV fn -eprec (UnaryOpVN fn _) = prec1VN fn +eprec (UnaryOpCC fn _) = prec1CC fn +eprec (UnaryOpCN fn _) = prec1CN fn eprec (Operator o _ _) = precA o eprec (ArithBinaryOp bo _ _) = prec2Arith bo eprec (BoolBinaryOp bo _ _) = prec2Bool bo eprec (EqBinaryOp bo _ _) = prec2Eq bo eprec (LABinaryOp bo _ _) = prec2LA bo eprec (OrdBinaryOp bo _ _) = prec2Ord bo -eprec (VVVBinaryOp bo _ _) = prec2VVV bo -eprec (VVNBinaryOp bo _ _) = prec2VVN bo -eprec (NVVBinaryOp bo _ _) = prec2NVV bo +eprec (CCCBinaryOp bo _ _) = prec2CCC bo +eprec (CCNBinaryOp bo _ _) = prec2CCN bo +eprec (NCCBinaryOp bo _ _) = prec2NCC bo eprec (ESSBinaryOp bo _ _) = prec2ESS bo eprec (ESBBinaryOp bo _ _) = prec2ESB bo eprec RealI{} = 170 diff --git a/code/drasil-lang/lib/Language/Drasil/Expr/Class.hs b/code/drasil-lang/lib/Language/Drasil/Expr/Class.hs index 08f06a4d594..b4cc2790792 100644 --- a/code/drasil-lang/lib/Language/Drasil/Expr/Class.hs +++ b/code/drasil-lang/lib/Language/Drasil/Expr/Class.hs @@ -5,7 +5,8 @@ module Language.Drasil.Expr.Class ( square, half, oneHalf, oneThird, apply1, apply2, - m2x2, vec2D, dgnl2x2, rowVec, columnVec, mkSet + m2x2, vec2D, dgnl2x2, rowVec, columnVec, mkSet, + vScale, vAdd, vSub ) where import Prelude hiding (sqrt, log, sin, cos, tan, exp) @@ -20,6 +21,9 @@ import qualified Language.Drasil.ModelExpr.Lang as M import qualified Language.Drasil.CodeExpr.Lang as C import Language.Drasil.Literal.Class (LiteralC(..)) import Drasil.Database.UID (HasUID(..)) +import qualified Language.Drasil.Space as S +import Numeric.Natural (Natural) +import qualified Data.Map.Ordered as OM import Utils.Drasil (toColumn) @@ -52,7 +56,7 @@ apply1 :: (ExprC r, HasUID f, HasSymbol f, HasUID a, HasSymbol a) => f -> a -> r apply1 f a = apply f [sy a] -- | Similar to 'apply', but the applied function takes two parameters (which are both 'Symbol's). -apply2 :: (ExprC r, HasUID f, HasSymbol f, HasUID a, HasSymbol a, HasUID b, HasSymbol b) +apply2 :: (ExprC r, HasUID f, HasSymbol f, HasUID a, HasSymbol a, HasUID b, HasSymbol b) => f -> a -> b -> r apply2 f a b = apply f [sy a, sy b] @@ -69,7 +73,7 @@ mkSet = set' -- | Create a 2D vector (a matrix with two rows, one column). First argument is placed above the second. vec2D :: ExprC r => r -> r -> r -vec2D a b = matrix [[a],[b]] +vec2D a b = vect [a, b] -- | Creates a diagonal two-by-two matrix. For example: -- @@ -87,6 +91,18 @@ rowVec a = matrix [a] columnVec :: ExprC r => [r] -> r columnVec a = matrix $ toColumn a +-- | Alias for `cScale` +vScale :: (ExprC r) => r -> r -> r +vScale = cScale + +-- | Alias for `cAdd` +vAdd :: (ExprC r) => r -> r -> r +vAdd = cAdd + +-- | Alias for `cSub` +vSub :: (ExprC r) => r -> r -> r +vSub = cSub + class ExprC r where infixr 8 $^ infixl 7 $/ @@ -96,25 +112,25 @@ class ExprC r where lit :: Literal -> r -- * Binary Operators - + ($=), ($!=) :: r -> r -> r - + -- | Smart constructor for ordering two equations. ($<), ($>), ($<=), ($>=) :: r -> r -> r - + -- | Smart constructor for the dot product of two equations. ($.) :: r -> r -> r - + -- | Add two expressions. ($+) :: r -> r -> r - + -- | Multiply two expressions. ($*) :: r -> r -> r ($-), ($/), ($^) :: r -> r -> r - + ($=>), ($<=>) :: r -> r -> r - + ($&&), ($||) :: r -> r -> r -- | Smart constructor for set-theoretic membership relation. Added ' to avoid conflict. @@ -122,61 +138,61 @@ class ExprC r where -- | Smart constructor for taking the absolute value of an expression. abs_ :: r -> r - + -- | Smart constructor for negating an expression. - neg :: r -> r - + neg :: r -> r + -- | Smart constructor to take the log of an expression. log :: r -> r - + -- | Smart constructor to take the ln of an expression. ln :: r -> r - + -- | Smart constructor to take the square root of an expression. sqrt :: r -> r - + -- | Smart constructor to apply sin to an expression. sin :: r -> r - + -- | Smart constructor to apply cos to an expression. - cos :: r -> r - + cos :: r -> r + -- | Smart constructor to apply tan to an expression. tan :: r -> r - + -- | Smart constructor to apply sec to an expression. - sec :: r -> r - + sec :: r -> r + -- | Smart constructor to apply csc to an expression. csc :: r -> r - + -- | Smart constructor to apply cot to an expression. - cot :: r -> r - + cot :: r -> r + -- | Smart constructor to apply arcsin to an expression. - arcsin :: r -> r - + arcsin :: r -> r + -- | Smart constructor to apply arccos to an expression. - arccos :: r -> r - + arccos :: r -> r + -- | Smart constructor to apply arctan to an expression. - arctan :: r -> r - + arctan :: r -> r + -- | Smart constructor for the exponential (base e) function. exp :: r -> r - - -- | Smart constructor for calculating the dimension of a vector. + + -- | Smart constructor for calculating the dimension of a vector (or general clif). dim :: r -> r - - -- | Smart constructor for calculating the normal form of a vector. + + -- | Smart constructor for calculating the normal form of a vector (or general clif). norm :: r -> r - - -- | Smart constructor for negating vectors. + + -- | Smart constructor for negating vectors (or general clifs). negVec :: r -> r - + -- | Smart constructor for applying logical negation to an expression. not_ :: r -> r - + -- | Smart constructor for indexing. idx :: r -> r -> r @@ -185,31 +201,31 @@ class ExprC r where -- | Smart constructor for the summation, product, and integral functions over an interval. defint, defsum, defprod :: Symbol -> r -> r -> r -> r - + -- | Smart constructor for 'real interval' membership. realInterval :: HasUID c => c -> RealInterval r r -> r -- | Euclidean function : takes a vector and returns the sqrt of the sum-of-squares. euclidean :: [r] -> r - + -- | Smart constructor to cross product two expressions. cross :: r -> r -> r - - -- | Smart constructor for vector scaling - vScale :: r -> r -> r - -- | Vector Addition - vAdd :: r -> r -> r + -- | Smart constructor for clif scaling + cScale :: r -> r -> r + + -- | Smart constructor for clif addition + cAdd :: r -> r -> r - -- | Vector Subtraction - vSub :: r -> r -> r + -- | Smart constructor for clif subtraction + cSub :: r -> r -> r -- | Smart constructor for case statements with a complete set of cases. completeCase :: [(r, r)] -> r - + -- | Smart constructor for case statements with an incomplete set of cases. incompleteCase :: [(r, r)] -> r - + -- | Create a matrix. matrix :: [[r]] -> r @@ -218,11 +234,14 @@ class ExprC r where -- | Applies a given function with a list of parameters. apply :: (HasUID f, HasSymbol f) => f -> [r] -> r - + -- Note how |sy| 'enforces' having a symbol -- | Create an 'Expr' from a 'Symbol'ic Chunk. sy :: (HasUID c, HasSymbol c) => c -> r + -- | Vectors with fixed components, of a given fixed dimension + vect :: [r] -> r + instance ExprC Expr where lit = Lit @@ -230,7 +249,7 @@ instance ExprC Expr where ($=) = EqBinaryOp Eq -- | Smart constructor for showing that two expressions are not equal. ($!=) = EqBinaryOp NEq - + -- | Smart constructor for ordering two equations. -- | Less than. ($<) = OrdBinaryOp Lt @@ -240,10 +259,10 @@ instance ExprC Expr where ($<=) = OrdBinaryOp LEq -- | Greater than or equal to. ($>=) = OrdBinaryOp GEq - + -- | Smart constructor for the dot product of two equations. - ($.) = VVNBinaryOp Dot - + ($.) = CCNBinaryOp Dot + -- | Add two expressions. ($+) (Lit (Int 0)) r = r ($+) l (Lit (Int 0)) = l @@ -274,12 +293,12 @@ instance ExprC Expr where ($/) = ArithBinaryOp Frac -- | Smart constructor for rasing the first expression to the power of the second. ($^) = ArithBinaryOp Pow - + -- | Smart constructor to show that one expression implies the other (conditional operator). ($=>) = BoolBinaryOp Impl -- | Smart constructor to show that an expression exists if and only if another expression exists (biconditional operator). ($<=>) = BoolBinaryOp Iff - + -- | Smart constructor for the boolean /and/ operator. a $&& b = AssocB And [a, b] -- | Smart constructor for the boolean /or/ operator. @@ -289,106 +308,122 @@ instance ExprC Expr where -- | Smart constructor for taking the absolute value of an expression. abs_ = UnaryOp Abs - + -- | Smart constructor for negating an expression. neg = UnaryOp Neg - + -- | Smart constructor to take the log of an expression. log = UnaryOp Log - + -- | Smart constructor to take the ln of an expression. ln = UnaryOp Ln - + -- | Smart constructor to take the square root of an expression. sqrt = UnaryOp Sqrt - + -- | Smart constructor to apply sin to an expression. sin = UnaryOp Sin - + -- | Smart constructor to apply cos to an expression. cos = UnaryOp Cos - + -- | Smart constructor to apply tan to an expression. tan = UnaryOp Tan - + -- | Smart constructor to apply sec to an expression. sec = UnaryOp Sec - + -- | Smart constructor to apply csc to an expression. csc = UnaryOp Csc - + -- | Smart constructor to apply cot to an expression. cot = UnaryOp Cot - + -- | Smart constructor to apply arcsin to an expression. arcsin = UnaryOp Arcsin - + -- | Smart constructor to apply arccos to an expression. arccos = UnaryOp Arccos - + -- | Smart constructor to apply arctan to an expression. arctan = UnaryOp Arctan - + -- | Smart constructor for the exponential (base e) function. exp = UnaryOp Exp - - -- | Smart constructor for calculating the dimension of a vector. - dim = UnaryOpVN Dim - - -- | Smart constructor for calculating the normal form of a vector. - norm = UnaryOpVN Norm - + + -- | Smart constructor for calculating the dimension of a clif. + dim = UnaryOpCN Dim + + -- | Smart constructor for calculating the normal form of a clif. + norm = UnaryOpCN Norm + -- | Smart constructor for negating vectors. - negVec = UnaryOpVV NegV + negVec = UnaryOpCC NegC + -- | And more general scaling - vScale = NVVBinaryOp Scale - + cScale = NCCBinaryOp Scale + -- | Smart constructor for applying logical negation to an expression. not_ = UnaryOpB Not - + -- | Smart constructor for indexing. idx = LABinaryOp Index - + idxOf = LABinaryOp IndexOf -- | Integrate over some expression with bounds (∫). defint v low high = Operator Add (BoundedDD v Continuous low high) - + -- | Sum over some expression with bounds (∑). defsum v low high = Operator Add (BoundedDD v Discrete low high) - + -- | Product over some expression with bounds (∏). defprod v low high = Operator Mul (BoundedDD v Discrete low high) - + -- | Smart constructor for 'real interval' membership. realInterval c = RealI (c ^. uid) - + -- TODO: Move euclidean to smart constructor -- | Euclidean function : takes a vector and returns the sqrt of the sum-of-squares. euclidean = sqrt . foldr1 ($+) . map square - + -- | Smart constructor to cross product two expressions. - cross = VVVBinaryOp Cross + cross = CCCBinaryOp Cross -- | Adding vectors - vAdd = VVVBinaryOp VAdd + cAdd = CCCBinaryOp CAdd -- | Subtracting vectors - vSub = VVVBinaryOp VSub - + cSub = CCCBinaryOp CSub + -- | Smart constructor for case statements with a complete set of cases. completeCase = Case Complete - + -- | Smart constructor for case statements with an incomplete set of cases. incompleteCase = Case Incomplete - + matrix = Matrix set' = Set -- | Applies a given function with a list of parameters. apply f [] = sy f apply f ps = FCall (f ^. uid) ps - + -- | Create an 'Expr' from a 'Symbol'ic Chunk. sy x = C (x ^. uid) - + + -- | Vectors with known components + -- This will create a Clifford space with dimension equal to the length of the list + vect es = + let + d = fromIntegral $ length es + vectComp n e = (vectorKey n d, e) + in + Clif (S.Fixed d) $ OM.fromList $ mapWithIndex vectComp es + +mapWithIndex :: (Natural -> a -> b) -> [a] -> [b] +mapWithIndex f = go 0 + where + go _ [] = [] + go n (x:xs) = f n x : go (n+1) xs + instance ExprC M.ModelExpr where lit = M.Lit @@ -408,7 +443,7 @@ instance ExprC M.ModelExpr where ($>=) = M.OrdBinaryOp M.GEq -- | Smart constructor for the dot product of two equations. - ($.) = M.VVNBinaryOp M.Dot + ($.) = M.CCNBinaryOp M.Dot -- | Add two expressions. ($+) (M.Lit (Int 0)) r = r @@ -497,16 +532,17 @@ instance ExprC M.ModelExpr where -- | Smart constructor for the exponential (base e) function. exp = M.UnaryOp M.Exp - -- | Smart constructor for calculating the dimension of a vector. - dim = M.UnaryOpVN M.Dim + -- | Smart constructor for calculating the dimension of a clif. + dim = M.UnaryOpCN M.Dim - -- | Smart constructor for calculating the normal form of a vector. - norm = M.UnaryOpVN M.Norm + -- | Smart constructor for calculating the normal form of a clif. + norm = M.UnaryOpCN M.Norm -- | Smart constructor for negating vectors. - negVec = M.UnaryOpVV M.NegV + negVec = M.UnaryOpCC M.NegC + -- | More general scaling - vScale = M.NVVBinaryOp M.Scale + cScale = M.NCCBinaryOp M.Scale -- | Smart constructor for applying logical negation to an expression. not_ = M.UnaryOpB M.Not @@ -533,13 +569,13 @@ instance ExprC M.ModelExpr where euclidean = sqrt . foldr1 ($+) . map square -- | Smart constructor to cross product two expressions. - cross = M.VVVBinaryOp M.Cross + cross = M.CCCBinaryOp M.Cross -- | Adding vectors - vAdd = M.VVVBinaryOp M.VAdd + cAdd = M.CCCBinaryOp M.CAdd -- | Subtracting vectors - vSub = M.VVVBinaryOp M.VSub - + cSub = M.CCCBinaryOp M.CSub + -- | Smart constructor for case statements with a complete set of cases. completeCase = M.Case Complete @@ -557,6 +593,16 @@ instance ExprC M.ModelExpr where -- | Create an 'Expr' from a 'Symbol'ic Chunk. sy x = M.C (x ^. uid) + -- | Vectors with known components + -- This will create a Clifford space with dimension equal to the length of the list + -- TODO: does this have to change in ModelExpr? + vect es = + let + d = fromIntegral $ length es + vectComp n e = (vectorKey n d, e) + in + M.Clif (S.Fixed d) $ OM.fromList $ mapWithIndex vectComp es + instance ExprC C.CodeExpr where lit = C.Lit @@ -564,7 +610,7 @@ instance ExprC C.CodeExpr where ($=) = C.EqBinaryOp C.Eq -- | Smart constructor for showing that two expressions are not equal. ($!=) = C.EqBinaryOp C.NEq - + -- | Smart constructor for ordering two equations. -- | Less than. ($<) = C.OrdBinaryOp C.Lt @@ -574,10 +620,10 @@ instance ExprC C.CodeExpr where ($<=) = C.OrdBinaryOp C.LEq -- | Greater than or equal to. ($>=) = C.OrdBinaryOp C.GEq - + -- | Smart constructor for the dot product of two equations. - ($.) = C.VVNBinaryOp C.Dot - + ($.) = C.CCNBinaryOp C.Dot + -- | Add two expressions. ($+) (C.Lit (Int 0)) r = r ($+) l (C.Lit (Int 0)) = l @@ -601,126 +647,137 @@ instance ExprC C.CodeExpr where ($*) (C.AssocA C.Mul l) r = C.AssocA C.Mul (l ++ [r]) ($*) l (C.AssocA C.Mul r) = C.AssocA C.Mul (l : r) ($*) l r = C.AssocA C.Mul [l,r] - + -- | Smart constructor for subtracting two expressions. ($-) = C.ArithBinaryOp C.Subt -- | Smart constructor for dividing two expressions. ($/) = C.ArithBinaryOp C.Frac -- | Smart constructor for rasing the first expression to the power of the second. ($^) = C.ArithBinaryOp C.Pow - + -- | Smart constructor to show that one expression implies the other (conditional operator). ($=>) = C.BoolBinaryOp C.Impl -- | Smart constructor to show that an expression exists if and only if another expression exists (biconditional operator). ($<=>) = C.BoolBinaryOp C.Iff - + -- | Smart constructor for the boolean /and/ operator. a $&& b = C.AssocB C.And [a, b] -- | Smart constructor for the boolean /or/ operator. a $|| b = C.AssocB C.Or [a, b] - + in' = C.ESBBinaryOp C.SContains -- | Smart constructor for taking the absolute value of an expression. abs_ = C.UnaryOp C.Abs - + -- | Smart constructor for negating an expression. neg = C.UnaryOp C.Neg - + -- | Smart constructor to take the log of an expression. log = C.UnaryOp C.Log - + -- | Smart constructor to take the ln of an expression. ln = C.UnaryOp C.Ln - + -- | Smart constructor to take the square root of an expression. sqrt = C.UnaryOp C.Sqrt - + -- | Smart constructor to apply sin to an expression. sin = C.UnaryOp C.Sin - + -- | Smart constructor to apply cos to an expression. cos = C.UnaryOp C.Cos - + -- | Smart constructor to apply tan to an expression. tan = C.UnaryOp C.Tan - + -- | Smart constructor to apply sec to an expression. sec = C.UnaryOp C.Sec - + -- | Smart constructor to apply csc to an expression. csc = C.UnaryOp C.Csc - + -- | Smart constructor to apply cot to an expression. cot = C.UnaryOp C.Cot - + -- | Smart constructor to apply arcsin to an expression. arcsin = C.UnaryOp C.Arcsin - + -- | Smart constructor to apply arccos to an expression. arccos = C.UnaryOp C.Arccos - + -- | Smart constructor to apply arctan to an expression. arctan = C.UnaryOp C.Arctan - + -- | Smart constructor for the exponential (base e) function. exp = C.UnaryOp C.Exp - + -- | Smart constructor for calculating the dimension of a vector. - dim = C.UnaryOpVN C.Dim - + dim = C.UnaryOpCN C.Dim + -- | Smart constructor for calculating the normal form of a vector. - norm = C.UnaryOpVN C.Norm - + norm = C.UnaryOpCN C.Norm + -- | Smart constructor for negating vectors. - negVec = C.UnaryOpVV C.NegV + negVec = C.UnaryOpCC C.NegC + -- | And more general scaling - vScale = C.NVVBinaryOp C.Scale - + cScale = C.NCCBinaryOp C.Scale + -- | Smart constructor for applying logical negation to an expression. not_ = C.UnaryOpB C.Not - + -- | Smart constructor for indexing. idx = C.LABinaryOp C.Index - + idxOf = C.LABinaryOp C.IndexOf -- | Integrate over some expression with bounds (∫). defint v low high = C.Operator C.Add (BoundedDD v Continuous low high) - + -- | Sum over some expression with bounds (∑). defsum v low high = C.Operator C.Add (BoundedDD v Discrete low high) - + -- | Product over some expression with bounds (∏). defprod v low high = C.Operator C.Mul (BoundedDD v Discrete low high) - + -- | Smart constructor for 'real interval' membership. realInterval c = C.RealI (c ^. uid) - + -- | Euclidean function : takes a vector and returns the sqrt of the sum-of-squares. euclidean = sqrt . foldr1 ($+) . map square - + -- | Smart constructor to cross product two expressions. - cross = C.VVVBinaryOp C.Cross - - -- | Adding vectors - vAdd = C.VVVBinaryOp C.VAdd - -- | Subtracting vectors - vSub = C.VVVBinaryOp C.VSub + cross = C.CCCBinaryOp C.Cross + + -- | Adding clifs + cAdd = C.CCCBinaryOp C.CAdd + + -- | Subtracting clifs + cSub = C.CCCBinaryOp C.CSub -- | Smart constructor for case statements with a complete set of cases. completeCase = C.Case Complete - + -- | Smart constructor for case statements with an incomplete set of cases. incompleteCase = C.Case Incomplete - + matrix = C.Matrix set' = C.Set -- | Applies a given function with a list of parameters. apply f [] = sy f apply f ps = C.FCall (f ^. uid) ps [] - + -- Note how |sy| 'enforces' having a symbol -- | Create an 'Expr' from a 'Symbol'ic Chunk. sy x = C.C (x ^. uid) + -- | Vectors with known components + -- This will create a Clifford space with dimension equal to the length of the list + -- TODO: does this have to change in CodeExpr? + vect es = + let + d = fromIntegral $ length es + vectComp n e = (vectorKey n d, e) + in + C.Clif (S.Fixed d) $ OM.fromList $ mapWithIndex vectComp es \ No newline at end of file diff --git a/code/drasil-lang/lib/Language/Drasil/Expr/Development.hs b/code/drasil-lang/lib/Language/Drasil/Expr/Development.hs index 13f2787731f..7a9913289ab 100644 --- a/code/drasil-lang/lib/Language/Drasil/Expr/Development.hs +++ b/code/drasil-lang/lib/Language/Drasil/Expr/Development.hs @@ -1,8 +1,8 @@ module Language.Drasil.Expr.Development ( -- Expr - Expr(..), UFunc(..), UFuncB(..), UFuncVV(..), UFuncVN(..) + Expr(..), UFunc(..), UFuncB(..), UFuncCC(..), UFuncCN(..) , ArithBinOp(..), BoolBinOp(..), EqBinOp(..), LABinOp(..), OrdBinOp(..) - , VVVBinOp(..), VVNBinOp(..), NVVBinOp(..), ESSBinOp(..), ESBBinOp(..) + , CCCBinOp(..), CCNBinOp(..), NCCBinOp(..), ESSBinOp(..), ESBBinOp(..) , AssocArithOper(..), AssocBoolOper(..), AssocConcatOper(..) , Completeness(..), Relation -- Expr.Extract diff --git a/code/drasil-lang/lib/Language/Drasil/Expr/Extract.hs b/code/drasil-lang/lib/Language/Drasil/Expr/Extract.hs index b60d1ce261f..001932c15d9 100644 --- a/code/drasil-lang/lib/Language/Drasil/Expr/Extract.hs +++ b/code/drasil-lang/lib/Language/Drasil/Expr/Extract.hs @@ -19,16 +19,16 @@ eNames (Case _ ls) = concatMap (eNames . fst) ls ++ concatMap (eNames . snd) ls eNames (UnaryOp _ u) = eNames u eNames (UnaryOpB _ u) = eNames u -eNames (UnaryOpVV _ u) = eNames u -eNames (UnaryOpVN _ u) = eNames u +eNames (UnaryOpCC _ u) = eNames u +eNames (UnaryOpCN _ u) = eNames u eNames (ArithBinaryOp _ a b) = eNames a ++ eNames b eNames (BoolBinaryOp _ a b) = eNames a ++ eNames b eNames (EqBinaryOp _ a b) = eNames a ++ eNames b eNames (LABinaryOp _ a b) = eNames a ++ eNames b eNames (OrdBinaryOp _ a b) = eNames a ++ eNames b -eNames (VVVBinaryOp _ a b) = eNames a ++ eNames b -eNames (VVNBinaryOp _ a b) = eNames a ++ eNames b -eNames (NVVBinaryOp _ a b) = eNames a ++ eNames b +eNames (CCCBinaryOp _ a b) = eNames a ++ eNames b +eNames (CCNBinaryOp _ a b) = eNames a ++ eNames b +eNames (NCCBinaryOp _ a b) = eNames a ++ eNames b eNames (ESSBinaryOp _ _ s) = eNames s eNames (ESBBinaryOp _ _ s) = eNames s eNames (Operator _ _ e) = eNames e @@ -57,16 +57,16 @@ eNames' (Case _ ls) = concatMap (eNames' . fst) ls ++ concatMap (eNames' . snd) ls eNames' (UnaryOp _ u) = eNames' u eNames' (UnaryOpB _ u) = eNames' u -eNames' (UnaryOpVV _ u) = eNames' u -eNames' (UnaryOpVN _ u) = eNames' u +eNames' (UnaryOpCC _ u) = eNames' u +eNames' (UnaryOpCN _ u) = eNames' u eNames' (ArithBinaryOp _ a b) = eNames' a ++ eNames' b eNames' (BoolBinaryOp _ a b) = eNames' a ++ eNames' b eNames' (EqBinaryOp _ a b) = eNames' a ++ eNames' b eNames' (LABinaryOp _ a b) = eNames' a ++ eNames' b eNames' (OrdBinaryOp _ a b) = eNames' a ++ eNames' b -eNames' (VVVBinaryOp _ a b) = eNames' a ++ eNames' b -eNames' (VVNBinaryOp _ a b) = eNames' a ++ eNames' b -eNames' (NVVBinaryOp _ a b) = eNames' a ++ eNames' b +eNames' (CCCBinaryOp _ a b) = eNames' a ++ eNames' b +eNames' (CCNBinaryOp _ a b) = eNames' a ++ eNames' b +eNames' (NCCBinaryOp _ a b) = eNames' a ++ eNames' b eNames' (ESSBinaryOp _ _ s) = eNames' s eNames' (ESBBinaryOp _ _ s) = eNames' s eNames' (Operator _ _ e) = eNames' e diff --git a/code/drasil-lang/lib/Language/Drasil/Expr/Lang.hs b/code/drasil-lang/lib/Language/Drasil/Expr/Lang.hs index f450438b73a..6aa10bac231 100644 --- a/code/drasil-lang/lib/Language/Drasil/Expr/Lang.hs +++ b/code/drasil-lang/lib/Language/Drasil/Expr/Lang.hs @@ -15,6 +15,12 @@ import Language.Drasil.WellTyped import Data.Either (lefts, fromLeft) import qualified Data.Foldable as NE +import Numeric.Natural (Natural) +import Data.Map.Ordered (OrderedMap) + +import qualified Data.Map as Map +import qualified Data.Map.Ordered as OM + -- * Expression Types -- | A relation is just an expression ('Expr'). @@ -46,16 +52,20 @@ data LABinOp = Index | IndexOf data OrdBinOp = Lt | Gt | LEq | GEq deriving Eq --- | @Vector x Vector -> Vector@ binary operations (cross product, addition, subtraction). -data VVVBinOp = Cross | VAdd | VSub +-- | @Clif x Clif -> Clif@ binary operations (cross product, addition, subtraction). +data CCCBinOp = Cross | CAdd | CSub | WedgeProd | GeometricProd + deriving Eq + +-- | @Clif x Clif -> Number@ binary operations (dot product). +data CCNBinOp = Dot deriving Eq --- | @Vector x Vector -> Number@ binary operations (dot product). -data VVNBinOp = Dot +-- | @Number x Clif -> Clif@ binary operations (scaling). +data NCCBinOp = Scale deriving Eq --- | @Number x Vector -> Vector@ binary operations (scaling). -data NVVBinOp = Scale +-- | @Natural x Clif -> Clif@ binary operations (grade selection). +data NatCCBinOp = GradeSelect deriving Eq -- | Element + Set -> Set @@ -86,12 +96,12 @@ data UFunc = Abs | Log | Ln | Sin | Cos | Tan | Sec | Csc | Cot | Arcsin data UFuncB = Not deriving Eq --- | @Vector -> Vector@ operators. -data UFuncVV = NegV +-- | @Clif -> Clif@ operators. +data UFuncCC = NegC deriving Eq --- | @Vector -> Number@ operators. -data UFuncVN = Norm | Dim +-- | @Clif -> Number@ operators (norm, dim, grade). +data UFuncCN = Norm | Dim | Grade deriving Eq -- | For case expressions (either complete or incomplete). @@ -129,10 +139,10 @@ data Expr where UnaryOp :: UFunc -> Expr -> Expr -- | Unary operation for @Bool -> Bool@ operations. UnaryOpB :: UFuncB -> Expr -> Expr - -- | Unary operation for @Vector -> Vector@ operations. - UnaryOpVV :: UFuncVV -> Expr -> Expr - -- | Unary operation for @Vector -> Number@ operations. - UnaryOpVN :: UFuncVN -> Expr -> Expr + -- | Unary operation for @Clif -> Clif@ operations. + UnaryOpCC :: UFuncCC -> Expr -> Expr + -- | Unary operation for @Clif -> Clif@ operations. + UnaryOpCN :: UFuncCN -> Expr -> Expr -- | Binary operator for arithmetic between expressions (fractional, power, and subtraction). ArithBinaryOp :: ArithBinOp -> Expr -> Expr -> Expr @@ -144,12 +154,14 @@ data Expr where LABinaryOp :: LABinOp -> Expr -> Expr -> Expr -- | Binary operator for ordering expressions (less than, greater than, etc.). OrdBinaryOp :: OrdBinOp -> Expr -> Expr -> Expr - -- | Binary operator for @Vector x Vector -> Vector@ operations (cross product). - VVVBinaryOp :: VVVBinOp -> Expr -> Expr -> Expr - -- | Binary operator for @Vector x Vector -> Number@ operations (dot product). - VVNBinaryOp :: VVNBinOp -> Expr -> Expr -> Expr - -- | Binary operator for @Expr x Vector -> Vector@ operations (scaling). - NVVBinaryOp :: NVVBinOp -> Expr -> Expr -> Expr + -- | Binary operator for @Clif x Clif -> Clif@ operations (cross product). + CCCBinaryOp :: CCCBinOp -> Expr -> Expr -> Expr + -- | Binary operator for @Clif x Clif -> Number@ operations (dot product). + CCNBinaryOp :: CCNBinOp -> Expr -> Expr -> Expr + -- | Binary operator for @Expr x Clif -> Clif@ operations (scaling). + NCCBinaryOp :: NCCBinOp -> Expr -> Expr -> Expr + -- | Binary operator for @Natural x Clif -> Clif@ operations (grade selection). + NatCCBinaryOp :: NatCCBinOp -> Natural -> Expr -> Expr -- | Set operator for Element + Set -> Set ESSBinaryOp :: ESSBinOp -> Expr -> Expr -> Expr -- | Set operator for Element + Set -> Bool @@ -160,6 +172,84 @@ data Expr where Operator :: AssocArithOper -> DiscreteDomainDesc Expr Expr -> Expr -> Expr -- | A different kind of 'IsIn'. A 'UID' is an element of an interval. RealI :: UID -> RealInterval Expr Expr -> Expr + -- | A clif of arbitrary dimension. The Maybe [Expr] determines the + -- components of the clif projected in a basis. If this is `Nothing`, + -- then the clif has not been projected into a particular basis. + -- If this `isJust`, the number of components must be 2 ^ d where + -- d is the dimension of the clifford space. + -- All Clifs are currently assumed to be embedded in a space defined by spacelike + -- basis vectors (e.g. Euclidean space) for now. + Clif :: S.Dimension -> BasisBlades Expr -> Expr + -- | Indexing into an expression (clifs only for now) + -- The list of indexes correspond to the index in each grade + -- SubSup determines if it is a superscript or a subscript + -- The Expression must be a clif with the right grade and where the indexes are ≤ the dimension +-- IndexC :: [Index] -> SubSup -> Expr -> Expr + +-- -- | An index will use the same definition as dimension for now, renamed for clarity +-- type Index = S.Dimension + +-- -- | Whether an index is a superscript or a subscript +-- data SubSup = +-- Super | Sub +-- deriving (Eq) + +-- TODO: Move this -- where? +-- | Basis Keys are represented by binary numbers (per Roefls, 2025) +-- Basis elements are ordered by grade, then sorted lexiographically +-- Y means basis vector is included +-- N means basis vector is not included +-- C is for concatenation +-- E is for empty +-- Example: in dimension 3, the basis vectors are e0, e1, and e2 +-- Here are some examples for `BasisKey`: +-- - e0 : N (N (Y E)) +-- - e2 : Y (N (N E)) +-- - e1e2 : Y (Y (N E)) +-- - 1 : N (N (N E)) +-- - e0e1e2 : Y (Y (Y E)) +data BasisKey = + Y BasisKey + | N BasisKey + | E + deriving (Eq, Ord, Show) + +-- | A mapping from basis blades to their expressions +type BasisBlades e = OrderedMap BasisKey e + +-- | A scalar key. E.g., for d=2: `scalarKey 2 = N (N E)` +scalarKey :: Natural -> BasisKey +scalarKey = elemKey [] + +-- | A vector key. E.g., for d=2, basis element e1: `vectorKey 1 2 = Y (N E)` +vectorKey :: Natural -> Natural -> BasisKey +vectorKey n = elemKey [n] + +-- | A bivector key. E.g., for d=3, basis element e0e1: `bivectorKey 0 1 3 = N (Y (Y E))` +bivectorKey :: Natural -> Natural -> Natural -> BasisKey +bivectorKey m n = elemKey [m,n] + +-- | A bivector key. E.g., for d=3, basis element e0e1: `bivectorKey 0 1 2 3 = Y (Y (Y E))` +trivectorKey :: Natural -> Natural -> Natural -> Natural -> BasisKey +trivectorKey m n p = elemKey [m,n,p] + +-- | Create a general element key. E.g. for d=4, basis element e0e2e3: `elemKey [0,2,3] 4 = (Y (Y (N (Y E))))` +-- This function does not care about the order or cardinlaity of the objects in the Foldable +-- value. That is, it is treated as "set-like". Consider using Data.Set if you're interested +-- in enforcing these properties yourself. +-- If you give it numbers that are "out of scope", i.e. n >= d, or duplicates, they will be ignored +elemKey :: Foldable t => t Natural -> Natural -> BasisKey +elemKey _ 0 = E +elemKey ns d + | d - 1 `elem` ns = Y (elemKey ns $ d-1) + | otherwise = N (elemKey ns $ d-1) + + +-- | The basis in which to project clifs +-- TODO: Generalize this to other cliff spaces +data Basis where + -- | ℝⁿ + Rn :: Natural -> Basis -- | Expressions are equal if their constructors and contents are equal. instance Eq Expr where @@ -171,18 +261,20 @@ instance Eq Expr where Case a b == Case c d = a == c && b == d UnaryOp a b == UnaryOp c d = a == c && b == d UnaryOpB a b == UnaryOpB c d = a == c && b == d - UnaryOpVV a b == UnaryOpVV c d = a == c && b == d - UnaryOpVN a b == UnaryOpVN c d = a == c && b == d + UnaryOpCC a b == UnaryOpCC c d = a == c && b == d + UnaryOpCN a b == UnaryOpCN c d = a == c && b == d ArithBinaryOp o a b == ArithBinaryOp p c d = o == p && a == c && b == d BoolBinaryOp o a b == BoolBinaryOp p c d = o == p && a == c && b == d EqBinaryOp o a b == EqBinaryOp p c d = o == p && a == c && b == d OrdBinaryOp o a b == OrdBinaryOp p c d = o == p && a == c && b == d LABinaryOp o a b == LABinaryOp p c d = o == p && a == c && b == d - VVVBinaryOp o a b == VVVBinaryOp p c d = o == p && a == c && b == d - VVNBinaryOp o a b == VVNBinaryOp p c d = o == p && a == c && b == d - NVVBinaryOp o a b == NVVBinaryOp p c d = o == p && a == c && b == d + CCCBinaryOp o a b == CCCBinaryOp p c d = o == p && a == c && b == d + CCNBinaryOp o a b == CCNBinaryOp p c d = o == p && a == c && b == d + NCCBinaryOp o a b == NCCBinaryOp p c d = o == p && a == c && b == d ESSBinaryOp o a b == ESSBinaryOp p c d = o == p && a == c && b == d ESBBinaryOp o a b == ESBBinaryOp p c d = o == p && a == c && b == d + Clif a b == Clif c d = a == c && b == d + -- IndexC a b c == IndexC d e f = a == d && b == e && c == f _ == _ = False -- ^ TODO: This needs to add more equality checks @@ -218,10 +310,12 @@ instance Eq Expr where class Pretty p where pretty :: p -> String -instance Pretty VVVBinOp where - pretty Cross = "cross product" - pretty VAdd = "vector addition" - pretty VSub = "vector subtraction" +instance Pretty CCCBinOp where + pretty Cross = "cross product" + pretty CAdd = "clif addition" + pretty CSub = "clif subtraction" + pretty WedgeProd = "clif wedge" + pretty GeometricProd = "clif geometric product" instance LiteralC Expr where int = Lit . int @@ -232,15 +326,18 @@ instance LiteralC Expr where -- helper function for typechecking to help reduce duplication -vvvInfer :: TypingContext Space -> VVVBinOp -> Expr -> Expr -> Either Space TypeError -vvvInfer ctx op l r = case (infer ctx l, infer ctx r) of - (Left lt@(S.Vect lsp), Left (S.Vect rsp)) -> - if lsp == rsp && S.isBasicNumSpace lsp then - if op == VSub && (lsp == S.Natural || rsp == S.Natural) then - Right $ "Vector subtraction expects both operands to be vectors of non-natural numbers. Received `" ++ show lsp ++ "` and `" ++ show rsp ++ "`." - else Left lt - else Right $ "Vector " ++ pretty op ++ " expects both operands to be vectors of non-natural numbers. Received `" ++ show lsp ++ "` and `" ++ show rsp ++ "`." - (Left lsp, Left rsp) -> Right $ "Vector operation " ++ pretty op ++ " expects vector operands. Received `" ++ show lsp ++ "` and `" ++ show rsp ++ "`." +-- TODO: refactor these if expressions so they're more readable (the else is too far from the if) +cccInfer :: TypingContext Space -> CCCBinOp -> Expr -> Expr -> Either Space TypeError +cccInfer ctx op l r = case (infer ctx l, infer ctx r) of + (Left lt@(S.ClifS lD lsp), Left (S.ClifS rD rsp)) -> + if lD == rD then -- The dimension in which the clif is embedded must match + if lsp == rsp && S.isBasicNumSpace lsp then + if op == CSub && (lsp == S.Natural || rsp == S.Natural) then + Right $ "Clif subtraction expects both operands to be clifs of non-natural numbers. Received `" ++ show lsp ++ "` and `" ++ show rsp ++ "`." + else Left lt + else Right $ "Clif " ++ pretty op ++ " expects both operands to be clifs of non-natural numbers. Received `" ++ show lsp ++ "` and `" ++ show rsp ++ "`." + else Right $ "Clif " ++ pretty op ++ " expects both Clifs to be of the same dimension. Received `" ++ show lD ++ "` and `" ++ show rD ++ "`." + (Left lsp, Left rsp) -> Right $ "Vector operation " ++ pretty op ++ " expects clif operands. Received `" ++ show lsp ++ "` and `" ++ show rsp ++ "`." (_ , Right re) -> Right re (Right le, _ ) -> Right le @@ -252,11 +349,11 @@ instance Typed Expr Space where infer :: TypingContext Space -> Expr -> Either Space TypeError infer cxt (Lit lit) = infer cxt lit - infer cxt (AssocA _ (e:exs)) = + infer cxt (AssocA _ (e:exs)) = case infer cxt e of - Left spaceValue | S.isBasicNumSpace spaceValue -> + Left spaceValue | S.isBasicNumSpace spaceValue -> -- If the inferred type of e is a valid Space, call allOfType with spaceValue - allOfType cxt exs spaceValue spaceValue + allOfType cxt exs spaceValue spaceValue "Associative arithmetic operation expects all operands to be of the same expected type." Left l -> -- Handle the case when sp is a Left value but spaceValue is invalid @@ -270,11 +367,11 @@ instance Typed Expr Space where infer cxt (AssocB _ exs) = allOfType cxt exs S.Boolean S.Boolean $ "Associative boolean operation expects all operands to be of the same type (" ++ show S.Boolean ++ ")." - infer cxt (AssocC _ (e:exs)) = + infer cxt (AssocC _ (e:exs)) = case infer cxt e of - Left spaceValue | spaceValue /= S.Void -> + Left spaceValue | spaceValue /= S.Void -> -- If the inferred type of e is a valid Space, call allOfType with spaceValue - allOfType cxt exs spaceValue spaceValue + allOfType cxt exs spaceValue spaceValue "Associative arithmetic operation expects all operands to be of the same expected type." Left l -> -- Handle the case when sp is a Left value but spaceValue is invalid @@ -283,7 +380,7 @@ instance Typed Expr Space where -- If sp is a Right value containing a TypeError Right r infer _ (AssocC SUnion _) = Right "Associative addition requires at least one operand." - + infer cxt (C uid) = inferFromContext cxt uid infer cxt (Variable _ n) = infer cxt n @@ -340,22 +437,28 @@ instance Typed Expr Space where Left sp -> Right $ "¬ on non-boolean operand, " ++ show sp ++ "." x -> x - infer cxt (UnaryOpVV NegV e) = case infer cxt e of - Left (S.Vect sp) -> if S.isBasicNumSpace sp && sp /= S.Natural - then Left $ S.Vect sp - else Right $ "Vector negation only applies to, non-natural, numbered vectors. Received `" ++ show sp ++ "`." - Left sp -> Right $ "Vector negation should only be applied to numeric vectors. Received `" ++ show sp ++ "`." + infer cxt (UnaryOpCC NegC e) = case infer cxt e of + Left c@(S.ClifS _ sp) -> if S.isBasicNumSpace sp && sp /= S.Natural + then Left c + else Right $ "Clif negation only applies to, non-natural, numbered clifs. Received `" ++ show sp ++ "`." + Left sp -> Right $ "Clif negation should only be applied to numeric clifs. Received `" ++ show sp ++ "`." x -> x - infer cxt (UnaryOpVN Norm e) = case infer cxt e of - Left (S.Vect S.Real) -> Left S.Real - Left sp -> Right $ "Vector norm only applies to vectors of real numbers. Received `" ++ show sp ++ "`." + -- TODO: support generalized clif norm + infer cxt (UnaryOpCN Norm e) = case infer cxt e of + Left (S.ClifS _ S.Real) -> Left S.Real + Left sp -> Right $ "Vector norm only applies to vectors (or clifs) of real numbers. Received `" ++ show sp ++ "`." x -> x - infer cxt (UnaryOpVN Dim e) = case infer cxt e of - Left (S.Vect _) -> Left S.Integer -- FIXME: I feel like Integer would be more usable, but S.Natural is the 'real' expectation here + infer cxt (UnaryOpCN Dim e) = case infer cxt e of + Left (S.ClifS _ _) -> Left S.Integer -- FIXME: I feel like Integer would be more usable, but S.Natural is the 'real' expectation here Left sp -> Right $ "Vector 'dim' only applies to vectors. Received `" ++ show sp ++ "`." x -> x + + infer cxt (UnaryOpCN Grade e) = case infer cxt e of + Left (S.ClifS _ _) -> Left S.Integer -- FIXME: I feel like Integer would be more usable, but S.Natural is the 'real' expectation here + Left sp -> Right $ "Vector 'grade' only applies to vectors. Received `" ++ show sp ++ "`." + x -> x infer cxt (ArithBinaryOp Frac l r) = case (infer cxt l, infer cxt r) of (Left lt, Left rt) -> if S.isBasicNumSpace lt && lt == rt @@ -393,7 +496,7 @@ instance Typed Expr Space where (Right le, _) -> Right le infer cxt (LABinaryOp Index l n) = case (infer cxt l, infer cxt n) of - (Left (S.Vect lt), Left nt) -> if nt == S.Integer || nt == S.Natural -- I guess we should only want it to be natural numbers, but integers or naturals is fine for now + (Left (S.ClifS _ lt), Left nt) -> if nt == S.Integer || nt == S.Natural -- I guess we should only want it to be natural numbers, but integers or naturals is fine for now then Left lt else Right $ "List accessor not of type Integer nor Natural, but of type `" ++ show nt ++ "`" (Left lt , Left _) -> Right $ "List accessor expects a list/vector, but received `" ++ show lt ++ "`." @@ -413,8 +516,8 @@ instance Typed Expr Space where (_, Right re) -> Right re (Right le, _) -> Right le - infer cxt (NVVBinaryOp Scale l r) = case (infer cxt l, infer cxt r) of - (Left lt, Left (S.Vect rsp)) -> if S.isBasicNumSpace lt && lt == rsp + infer cxt (NCCBinaryOp Scale l r) = case (infer cxt l, infer cxt r) of + (Left lt, Left (S.ClifS _ rsp)) -> if S.isBasicNumSpace lt && lt == rsp then Left rsp else if lt /= rsp then Right $ "Vector scaling expects a scaling by the same kind as the vector's but found scaling by`" ++ show lt ++ "` over vectors of type `" ++ show rsp ++ "`." @@ -424,7 +527,13 @@ instance Typed Expr Space where (_, Right rx) -> Right rx (Right lx, _) -> Right lx - infer cxt (VVVBinaryOp o l r) = vvvInfer cxt o l r + -- If you select grade N of a Clif, you get a Clif of grade N + infer cxt (NatCCBinaryOp GradeSelect n c) = case infer cxt c of + Left (S.ClifS _ sp) -> Left $ S.ClifS (S.Fixed n) sp + Left rsp -> Right $ "Grade selection expects clif as second operand. Received `" ++ show rsp ++ "`." + Right x -> Right x + + infer cxt (CCCBinaryOp o l r) = cccInfer cxt o l r {- case (infer cxt l, infer cxt r) of (Left lTy, Left rTy) -> if lTy == rTy && S.isBasicNumSpace lTy && lTy /= S.Natural then Left lTy @@ -433,10 +542,13 @@ instance Typed Expr Space where (Right le, _ ) -> Right le -} - infer cxt (VVNBinaryOp Dot l r) = case (infer cxt l, infer cxt r) of - (Left lt@(S.Vect lsp), Left rt@(S.Vect rsp)) -> if lsp == rsp && S.isBasicNumSpace lsp - then Left lsp - else Right $ "Vector dot product expects same numeric vector types, but found `" ++ show lt ++ "` · `" ++ show rt ++ "`." + infer cxt (CCNBinaryOp Dot l r) = case (infer cxt l, infer cxt r) of + (Left lt@(S.ClifS lD lsp), Left rt@(S.ClifS rD rsp)) -> + if lD == rD then + if lsp == rsp && S.isBasicNumSpace lsp + then Left lsp + else Right $ "Vector dot product expects same numeric vector types, but found `" ++ show lt ++ "` · `" ++ show rt ++ "`." + else Right $ "Clif dot product expects both Clifs to be of the same dimension. Received `" ++ show lD ++ "` and `" ++ show rD ++ "`." (Left lsp, Left rsp) -> Right $ "Vector dot product expects vector operands. Received `" ++ show lsp ++ "` · `" ++ show rsp ++ "`." (_, Right rx) -> Right rx (Right lx, _) -> Right lx @@ -491,4 +603,40 @@ instance Typed Expr Space where (_ , Right x) -> Right x (Right x, _ ) -> Right x riTy (S.UpTo (_, x)) = infer cxt x - riTy (S.UpFrom (_, x)) = infer cxt x \ No newline at end of file + riTy (S.UpFrom (_, x)) = infer cxt x + + -- For a clif to be well-typed it must: + -- 1. Contain only basic numeric types inside it + -- 2. Have a dimension of at least the grade (a 0-dimensional vector makes no sense) + infer ctx (Clif d es) = + -- A clif with no explicit compile/"specification"-time expressions in the components + if OM.null es then Left $ S.ClifS d S.Real + else + case eitherLists (infer ctx <$> OM.elems es) of + Left _ -> + let + -- Check the dimensions of a clif to ensure it makes sense + isValidDim = + case d of + -- If it's a fixed dimension, the number of expressions must be dimension ^ 2 + S.Fixed fD -> OM.size es == fromIntegral ((2 :: Integer) ^ fD) + -- We don't know enough to say for sure + S.VDim _ -> True + in + -- `Clif`s must store a basic number space, not things like other clifs + -- if S.isBasicNumSpace t then + if isValidDim then + Left $ S.ClifS d S.Real + else Right $ "The number of components in a clif of dimension " ++ show d ++ " must be 2 ^ " ++ show d + -- else Right $ "Clifs must contain basic number spaces. Received " ++ show t + Right x -> Right x + + +eitherLists :: [Either a b] -> Either [a] b +eitherLists = eitherLists' (Left []) + where + eitherLists' :: Either [a] b -> [Either a b] -> Either [a] b + eitherLists' (Left ls) (Left l : es') = eitherLists' (Left $ l : ls) es' + eitherLists' _ (Right r : _) = Right r + eitherLists' _ (Left _ : _) = error "eitherLists impl. non-exhaustive pattern: _ [Left, ...]" + eitherLists' ls [] = ls diff --git a/code/drasil-lang/lib/Language/Drasil/Expr/Precedence.hs b/code/drasil-lang/lib/Language/Drasil/Expr/Precedence.hs index c600072b996..d0feca869ef 100644 --- a/code/drasil-lang/lib/Language/Drasil/Expr/Precedence.hs +++ b/code/drasil-lang/lib/Language/Drasil/Expr/Precedence.hs @@ -2,9 +2,9 @@ module Language.Drasil.Expr.Precedence where import Language.Drasil.Expr.Lang (Expr(..), - ArithBinOp(..), BoolBinOp, EqBinOp(..), LABinOp, OrdBinOp, VVNBinOp, - UFunc(..), UFuncB(..), UFuncVV(..), UFuncVN(..), - AssocBoolOper(..), AssocArithOper(..), VVVBinOp, NVVBinOp, ESSBinOp, ESBBinOp, AssocConcatOper(..)) + ArithBinOp(..), BoolBinOp, EqBinOp(..), LABinOp, OrdBinOp, CCNBinOp, + UFunc(..), UFuncB(..), UFuncCC(..), UFuncCN(..), + AssocBoolOper(..), AssocArithOper(..), CCCBinOp, NCCBinOp, ESSBinOp, ESBBinOp, AssocConcatOper(..)) -- These precedences are inspired from Haskell/F# -- as documented at http://kevincantu.org/code/operators.html @@ -33,16 +33,16 @@ prec2Ord :: OrdBinOp -> Int prec2Ord _ = 130 -- | prec2VVV - precedence for Vec->Vec->Vec-related binary operations. -prec2VVV :: VVVBinOp -> Int -prec2VVV _ = 190 +prec2CCC :: CCCBinOp -> Int +prec2CCC _ = 190 -- | prec2VVN - precedence for Vec->Vec->Num-related binary operations. -prec2VVN :: VVNBinOp -> Int -prec2VVN _ = 190 +prec2CCN :: CCNBinOp -> Int +prec2CCN _ = 190 -- | prec2NVV - precedence for Num->Vec->Vec-related binary operations. -prec2NVV :: NVVBinOp -> Int -prec2NVV _ = 190 +prec2NCC :: NCCBinOp -> Int +prec2NCC _ = 190 -- | prec2ESS - precedence for Element->Set->Set-related binary operations. prec2ESS :: ESSBinOp -> Int @@ -76,13 +76,13 @@ prec1 _ = 250 prec1B :: UFuncB -> Int prec1B Not = 230 --- | prec1VV - precedence of vector-vector-related unary operators. -prec1VV :: UFuncVV -> Int -prec1VV _ = 250 +-- | prec1VV - precedence of clif-clif-related unary operators. +prec1CC :: UFuncCC -> Int +prec1CC _ = 250 -- | prec1Vec - precedence of vector-number-related unary operators. -prec1VN :: UFuncVN -> Int -prec1VN _ = 230 +prec1CN :: UFuncCN -> Int +prec1CN _ = 230 -- | eprec - "Expression" precedence. eprec :: Expr -> Int @@ -98,17 +98,17 @@ eprec Set{} = 220 eprec (Variable _ _) = 220 eprec (UnaryOp fn _) = prec1 fn eprec (UnaryOpB fn _) = prec1B fn -eprec (UnaryOpVV fn _) = prec1VV fn -eprec (UnaryOpVN fn _) = prec1VN fn +eprec (UnaryOpCC fn _) = prec1CC fn +eprec (UnaryOpCN fn _) = prec1CN fn eprec (Operator o _ _) = precA o eprec (ArithBinaryOp bo _ _) = prec2Arith bo eprec (BoolBinaryOp bo _ _) = prec2Bool bo eprec (EqBinaryOp bo _ _) = prec2Eq bo eprec (LABinaryOp bo _ _) = prec2LA bo eprec (OrdBinaryOp bo _ _) = prec2Ord bo -eprec (VVVBinaryOp bo _ _) = prec2VVV bo -eprec (VVNBinaryOp bo _ _) = prec2VVN bo -eprec (NVVBinaryOp bo _ _) = prec2NVV bo +eprec (CCCBinaryOp bo _ _) = prec2CCC bo +eprec (CCNBinaryOp bo _ _) = prec2CCN bo +eprec (NCCBinaryOp bo _ _) = prec2NCC bo eprec (ESSBinaryOp bo _ _) = prec2ESS bo eprec (ESBBinaryOp bo _ _) = prec2ESB bo eprec RealI{} = 170 diff --git a/code/drasil-lang/lib/Language/Drasil/ModelExpr/Convert.hs b/code/drasil-lang/lib/Language/Drasil/ModelExpr/Convert.hs index 60a97ed4e2b..2fc0dbcba84 100644 --- a/code/drasil-lang/lib/Language/Drasil/ModelExpr/Convert.hs +++ b/code/drasil-lang/lib/Language/Drasil/ModelExpr/Convert.hs @@ -40,12 +40,12 @@ uFunc E.Neg = Neg uFuncB :: E.UFuncB -> UFuncB uFuncB E.Not = Not -uFuncVV :: E.UFuncVV -> UFuncVV -uFuncVV E.NegV = NegV +uFuncCC :: E.UFuncCC -> UFuncCC +uFuncCC E.NegC = NegC -uFuncVN :: E.UFuncVN -> UFuncVN -uFuncVN E.Norm = Norm -uFuncVN E.Dim = Dim +uFuncCN :: E.UFuncCN -> UFuncCN +uFuncCN E.Norm = Norm +uFuncCN E.Dim = Dim arithBinOp :: E.ArithBinOp -> ArithBinOp arithBinOp E.Frac = Frac @@ -70,16 +70,16 @@ ordBinOp E.Gt = Gt ordBinOp E.LEq = LEq ordBinOp E.GEq = GEq -vvvBinOp :: E.VVVBinOp -> VVVBinOp -vvvBinOp E.Cross = Cross -vvvBinOp E.VAdd = VAdd -vvvBinOp E.VSub = VSub +cccBinOp :: E.CCCBinOp -> CCCBinOp +cccBinOp E.Cross = Cross +cccBinOp E.CAdd = CAdd +cccBinOp E.CSub = CSub -vvnBinOp :: E.VVNBinOp -> VVNBinOp -vvnBinOp E.Dot = Dot +ccnBinOp :: E.CCNBinOp -> CCNBinOp +ccnBinOp E.Dot = Dot -nvvBinOp :: E.NVVBinOp -> NVVBinOp -nvvBinOp E.Scale = Scale +nccBinOp :: E.NCCBinOp -> NCCBinOp +nccBinOp E.Scale = Scale essBinOp :: E.ESSBinOp -> ESSBinOp essBinOp E.SAdd = SAdd @@ -101,16 +101,16 @@ expr (E.Set s e) = Set s $ map expr e expr (E.Variable s e) = Variable s $ expr e expr (E.UnaryOp u e) = UnaryOp (uFunc u) (expr e) expr (E.UnaryOpB u e) = UnaryOpB (uFuncB u) (expr e) -expr (E.UnaryOpVV u e) = UnaryOpVV (uFuncVV u) (expr e) -expr (E.UnaryOpVN u e) = UnaryOpVN (uFuncVN u) (expr e) +expr (E.UnaryOpCC u e) = UnaryOpCC (uFuncCC u) (expr e) +expr (E.UnaryOpCN u e) = UnaryOpCN (uFuncCN u) (expr e) expr (E.ArithBinaryOp a l r) = ArithBinaryOp (arithBinOp a) (expr l) (expr r) expr (E.BoolBinaryOp b l r) = BoolBinaryOp (boolBinOp b) (expr l) (expr r) expr (E.EqBinaryOp e l r) = EqBinaryOp (eqBinOp e) (expr l) (expr r) expr (E.LABinaryOp la l r) = LABinaryOp (laBinOp la) (expr l) (expr r) expr (E.OrdBinaryOp o l r) = OrdBinaryOp (ordBinOp o) (expr l) (expr r) -expr (E.VVVBinaryOp v l r) = VVVBinaryOp (vvvBinOp v) (expr l) (expr r) -expr (E.VVNBinaryOp v l r) = VVNBinaryOp (vvnBinOp v) (expr l) (expr r) -expr (E.NVVBinaryOp v l r) = NVVBinaryOp (nvvBinOp v) (expr l) (expr r) +expr (E.CCCBinaryOp v l r) = CCCBinaryOp (cccBinOp v) (expr l) (expr r) +expr (E.CCNBinaryOp v l r) = CCNBinaryOp (ccnBinOp v) (expr l) (expr r) +expr (E.NCCBinaryOp v l r) = NCCBinaryOp (nccBinOp v) (expr l) (expr r) expr (E.ESSBinaryOp o l r) = ESSBinaryOp (essBinOp o) (expr l) (expr r) expr (E.ESBBinaryOp o l r) = ESBBinaryOp (esbBinOp o) (expr l) (expr r) expr (E.Operator ao dd e) = Operator (assocArithOper ao) (domainDesc dd) (expr e) diff --git a/code/drasil-lang/lib/Language/Drasil/ModelExpr/Development.hs b/code/drasil-lang/lib/Language/Drasil/ModelExpr/Development.hs index 920ce3c11d6..50590969a8b 100644 --- a/code/drasil-lang/lib/Language/Drasil/ModelExpr/Development.hs +++ b/code/drasil-lang/lib/Language/Drasil/ModelExpr/Development.hs @@ -3,9 +3,9 @@ module Language.Drasil.ModelExpr.Development ( -- * Types -- ModelExpr - ModelExpr(..), UFunc(..), UFuncB(..), UFuncVV(..), UFuncVN(..) + ModelExpr(..), UFunc(..), UFuncB(..), UFuncCC(..), UFuncCN(..) , ArithBinOp(..), BoolBinOp(..), EqBinOp(..), LABinOp(..), OrdBinOp(..) - , SpaceBinOp(..), StatBinOp(..), VVVBinOp(..), VVNBinOp(..), NVVBinOp(..), ESSBinOp(..), ESBBinOp(..) + , SpaceBinOp(..), StatBinOp(..), CCCBinOp(..), CCNBinOp(..), NCCBinOp(..), ESSBinOp(..), ESBBinOp(..) , AssocArithOper(..), AssocBoolOper(..), AssocConcatOper(..) , DerivType(..), Completeness(..) -- * Functions diff --git a/code/drasil-lang/lib/Language/Drasil/ModelExpr/Extract.hs b/code/drasil-lang/lib/Language/Drasil/ModelExpr/Extract.hs index ad93345a6cc..fd455d37fd6 100644 --- a/code/drasil-lang/lib/Language/Drasil/ModelExpr/Extract.hs +++ b/code/drasil-lang/lib/Language/Drasil/ModelExpr/Extract.hs @@ -4,8 +4,10 @@ module Language.Drasil.ModelExpr.Extract where import Data.Containers.ListUtils (nubOrd) import Language.Drasil.ModelExpr.Lang (ModelExpr(..)) -import Language.Drasil.Space (RealInterval(..)) -import Drasil.Database.UID (UID) +import Language.Drasil.Space (RealInterval(..)) +import Drasil.Database.UID (UID) +import qualified Data.Map.Ordered as OM + -- | Generic traverse of all expressions that could lead to names. meNames :: ModelExpr -> [UID] @@ -21,8 +23,8 @@ meNames (Case _ ls) = concatMap (meNames . fst) ls ++ concatMap (meNames . snd) ls meNames (UnaryOp _ u) = meNames u meNames (UnaryOpB _ u) = meNames u -meNames (UnaryOpVV _ u) = meNames u -meNames (UnaryOpVN _ u) = meNames u +meNames (UnaryOpCC _ u) = meNames u +meNames (UnaryOpCN _ u) = meNames u meNames (ArithBinaryOp _ a b) = meNames a ++ meNames b meNames (BoolBinaryOp _ a b) = meNames a ++ meNames b meNames (EqBinaryOp _ a b) = meNames a ++ meNames b @@ -30,9 +32,9 @@ meNames (LABinaryOp _ a b) = meNames a ++ meNames b meNames (SpaceBinaryOp _ a b) = meNames a ++ meNames b meNames (StatBinaryOp _ a b) = meNames a ++ meNames b meNames (OrdBinaryOp _ a b) = meNames a ++ meNames b -meNames (VVVBinaryOp _ a b) = meNames a ++ meNames b -meNames (VVNBinaryOp _ a b) = meNames a ++ meNames b -meNames (NVVBinaryOp _ a b) = meNames a ++ meNames b +meNames (CCCBinaryOp _ a b) = meNames a ++ meNames b +meNames (CCNBinaryOp _ a b) = meNames a ++ meNames b +meNames (NCCBinaryOp _ a b) = meNames a ++ meNames b meNames (ESSBinaryOp _ _ s) = meNames s meNames (ESBBinaryOp _ _ s) = meNames s meNames (Operator _ _ e) = meNames e @@ -41,6 +43,7 @@ meNames (Set _ a) = concatMap meNames a meNames (Variable _ e) = meNames e meNames (RealI c b) = c : meNamesRI b meNames (ForAll _ _ de) = meNames de +meNames (Clif _ es) = concatMap meNames $ OM.elems es -- | Generic traversal of everything that could come from an interval to names (similar to 'meNames'). meNamesRI :: RealInterval ModelExpr ModelExpr -> [UID] @@ -64,8 +67,8 @@ meNames' (Case _ ls) = concatMap (meNames' . fst) ls ++ concatMap (meNames' . snd) ls meNames' (UnaryOp _ u) = meNames' u meNames' (UnaryOpB _ u) = meNames' u -meNames' (UnaryOpVV _ u) = meNames' u -meNames' (UnaryOpVN _ u) = meNames' u +meNames' (UnaryOpCC _ u) = meNames' u +meNames' (UnaryOpCN _ u) = meNames' u meNames' (ArithBinaryOp _ a b) = meNames' a ++ meNames' b meNames' (BoolBinaryOp _ a b) = meNames' a ++ meNames' b meNames' (EqBinaryOp _ a b) = meNames' a ++ meNames' b @@ -73,9 +76,9 @@ meNames' (LABinaryOp _ a b) = meNames' a ++ meNames' b meNames' (OrdBinaryOp _ a b) = meNames' a ++ meNames' b meNames' (SpaceBinaryOp _ a b) = meNames' a ++ meNames' b meNames' (StatBinaryOp _ a b) = meNames' a ++ meNames' b -meNames' (VVVBinaryOp _ a b) = meNames' a ++ meNames' b -meNames' (VVNBinaryOp _ a b) = meNames' a ++ meNames' b -meNames' (NVVBinaryOp _ a b) = meNames' a ++ meNames' b +meNames' (CCCBinaryOp _ a b) = meNames' a ++ meNames' b +meNames' (CCNBinaryOp _ a b) = meNames' a ++ meNames' b +meNames' (NCCBinaryOp _ a b) = meNames' a ++ meNames' b meNames' (ESSBinaryOp _ _ s) = meNames' s meNames' (ESBBinaryOp _ _ s) = meNames' s meNames' (Operator _ _ e) = meNames' e diff --git a/code/drasil-lang/lib/Language/Drasil/ModelExpr/Lang.hs b/code/drasil-lang/lib/Language/Drasil/ModelExpr/Lang.hs index f8bcbace066..c925cf81630 100644 --- a/code/drasil-lang/lib/Language/Drasil/ModelExpr/Lang.hs +++ b/code/drasil-lang/lib/Language/Drasil/ModelExpr/Lang.hs @@ -4,9 +4,11 @@ module Language.Drasil.ModelExpr.Lang where import Prelude hiding (sqrt) +import Numeric.Natural -import Language.Drasil.Expr.Lang (Completeness) +import Language.Drasil.Expr.Lang (Completeness, BasisBlades(..)) import Language.Drasil.Literal.Lang (Literal(..)) +import qualified Language.Drasil.Space as S import Language.Drasil.Space (Space, DomainDesc, RealInterval) import Drasil.Database.UID (UID) import Language.Drasil.Literal.Class (LiteralC(..)) @@ -34,16 +36,20 @@ data LABinOp = Index | IndexOf data OrdBinOp = Lt | Gt | LEq | GEq deriving Eq --- | @Vector x Vector -> Vector@ binary operations (cross product, vector addition, subtraction). -data VVVBinOp = Cross | VAdd | VSub +-- | @Clif x Clif -> Clif@ binary operations (cross product, clif addition, subtraction). +data CCCBinOp = Cross | CAdd | CSub | WedgeProd | GeometricProd deriving Eq --- | @Vector x Vector -> Number@ binary operations (dot product). -data VVNBinOp = Dot +-- | @Clif x Clif -> Number@ binary operations (dot product). +data CCNBinOp = Dot deriving Eq --- | @Number x Vector -> Vector@ binary operations (scaling). -data NVVBinOp = Scale +-- | @Number x Clif -> Clif@ binary operations (scaling). +data NCCBinOp = Scale + deriving Eq + +-- | @Natural x Clif -> Clif@ binary operations (grade selection). +data NatCCBinOp = GradeSelect deriving Eq -- | Element + Set -> Set @@ -74,12 +80,12 @@ data UFunc = Abs | Log | Ln | Sin | Cos | Tan | Sec | Csc | Cot | Arcsin data UFuncB = Not deriving Eq --- | @Vector -> Vector@ operators. -data UFuncVV = NegV +-- | @Clif -> Clif@ operators. +data UFuncCC = NegC deriving Eq --- | @Vector -> Number@ operators. -data UFuncVN = Norm | Dim +-- | @Clif -> Number@ operators (norm, dim, grade). +data UFuncCN = Norm | Dim | Grade deriving Eq -- | Statements involving 2 arguments. @@ -131,10 +137,10 @@ data ModelExpr where UnaryOp :: UFunc -> ModelExpr -> ModelExpr -- | Unary operation for @Bool -> Bool@ operations. UnaryOpB :: UFuncB -> ModelExpr -> ModelExpr - -- | Unary operation for @Vector -> Vector@ operations. - UnaryOpVV :: UFuncVV -> ModelExpr -> ModelExpr - -- | Unary operation for @Vector -> Number@ operations. - UnaryOpVN :: UFuncVN -> ModelExpr -> ModelExpr + -- | Unary operation for @Clif -> Clif@ operations. + UnaryOpCC :: UFuncCC -> ModelExpr -> ModelExpr + -- | Unary operation for @Clif -> Number@ operations. + UnaryOpCN :: UFuncCN -> ModelExpr -> ModelExpr -- | Binary operator for arithmetic between expressions (fractional, power, and subtraction). ArithBinaryOp :: ArithBinOp -> ModelExpr -> ModelExpr -> ModelExpr @@ -150,12 +156,14 @@ data ModelExpr where SpaceBinaryOp :: SpaceBinOp -> ModelExpr -> ModelExpr -> ModelExpr -- | Statement-related binary operations. StatBinaryOp :: StatBinOp -> ModelExpr -> ModelExpr -> ModelExpr - -- | Binary operator for @Vector x Vector -> Vector@ operations (cross product). - VVVBinaryOp :: VVVBinOp -> ModelExpr -> ModelExpr -> ModelExpr - -- | Binary operator for @Vector x Vector -> Number@ operations (dot product). - VVNBinaryOp :: VVNBinOp -> ModelExpr -> ModelExpr -> ModelExpr - -- | Binary operator for @Number x Vector -> Vector@ operations (scaling). - NVVBinaryOp :: NVVBinOp -> ModelExpr -> ModelExpr -> ModelExpr + -- | Binary operator for @Clif x Clif -> Clif@ operations (cross product). + CCCBinaryOp :: CCCBinOp -> ModelExpr -> ModelExpr -> ModelExpr + -- | Binary operator for @Clif x Clif -> Number@ operations (dot product). + CCNBinaryOp :: CCNBinOp -> ModelExpr -> ModelExpr -> ModelExpr + -- | Binary operator for @Number x Clif -> Clif@ operations (scaling). + NCCBinaryOp :: NCCBinOp -> ModelExpr -> ModelExpr -> ModelExpr + -- | Binary operator for @Natural x Clif -> Clif@ operations (grade selection). + NatCCBinaryOp :: NatCCBinOp -> Natural -> ModelExpr -> ModelExpr -- | Set operator for Element + Set -> Set ESSBinaryOp :: ESSBinOp -> ModelExpr -> ModelExpr -> ModelExpr -- | Set operator for Element + Set -> Bool @@ -171,6 +179,15 @@ data ModelExpr where -- | Universal quantification ForAll :: UID -> Space -> ModelExpr -> ModelExpr + -- | A clif of arbitrary dimension. The Maybe [Expr] determines the + -- components of the clif projected in a basis. If this is `Nothing`, + -- then the clif has not been projected into a particular basis. + -- If this `isJust`, the number of components must be 2 ^ d where + -- d is the dimension of the clifford space. + -- All Clifs are currently assumed to be embedded in a space defined by spacelike + -- basis vectors (e.g. Euclidean space) for now. + Clif :: S.Dimension -> BasisBlades ModelExpr -> ModelExpr + -- | The variable type is just a renamed 'String'. type Variable = String @@ -207,8 +224,8 @@ instance Eq ModelExpr where Case a b == Case c d = a == c && b == d UnaryOp a b == UnaryOp c d = a == c && b == d UnaryOpB a b == UnaryOpB c d = a == c && b == d - UnaryOpVV a b == UnaryOpVV c d = a == c && b == d - UnaryOpVN a b == UnaryOpVN c d = a == c && b == d + UnaryOpCC a b == UnaryOpCC c d = a == c && b == d + UnaryOpCN a b == UnaryOpCN c d = a == c && b == d ArithBinaryOp o a b == ArithBinaryOp p c d = o == p && a == c && b == d BoolBinaryOp o a b == BoolBinaryOp p c d = o == p && a == c && b == d EqBinaryOp o a b == EqBinaryOp p c d = o == p && a == c && b == d @@ -216,8 +233,8 @@ instance Eq ModelExpr where SpaceBinaryOp o a b == SpaceBinaryOp p c d = o == p && a == c && b == d StatBinaryOp o a b == StatBinaryOp p c d = o == p && a == c && b == d LABinaryOp o a b == LABinaryOp p c d = o == p && a == c && b == d - VVVBinaryOp o a b == VVVBinaryOp p c d = o == p && a == c && b == d - VVNBinaryOp o a b == VVNBinaryOp p c d = o == p && a == c && b == d + CCCBinaryOp o a b == CCCBinaryOp p c d = o == p && a == c && b == d + CCNBinaryOp o a b == CCNBinaryOp p c d = o == p && a == c && b == d ESSBinaryOp o a b == ESSBinaryOp p c d = o == p && a == c && b == d ESBBinaryOp o a b == ESBBinaryOp p c d = o == p && a == c && b == d _ == _ = False diff --git a/code/drasil-lang/lib/Language/Drasil/ModelExpr/Precedence.hs b/code/drasil-lang/lib/Language/Drasil/ModelExpr/Precedence.hs index 30d026ab4d2..73de0efddd2 100644 --- a/code/drasil-lang/lib/Language/Drasil/ModelExpr/Precedence.hs +++ b/code/drasil-lang/lib/Language/Drasil/ModelExpr/Precedence.hs @@ -35,17 +35,17 @@ prec2Spc _ = 170 prec2Stat :: StatBinOp -> Int prec2Stat _ = 130 --- | prec2VVV - precedence for Vec->Vec->Vec-related binary operations. -prec2VVV :: VVVBinOp -> Int -prec2VVV _ = 190 +-- | prec2CCC - precedence for Clif->Clif->Clif-related binary operations. +prec2CCC :: CCCBinOp -> Int +prec2CCC _ = 190 --- | prec2VVN - precedence for Vec->Vec->Num-related binary operations. -prec2VVN :: VVNBinOp -> Int -prec2VVN _ = 190 +-- | prec2VVN - precedence for Clif->Clif->Num-related binary operations. +prec2CCN :: CCNBinOp -> Int +prec2CCN _ = 190 --- | prec2NVV - precedence for Num->Vec->Vec-related binary operations. -prec2NVV :: NVVBinOp -> Int -prec2NVV _ = 190 +-- | prec2NCC - precedence for Num->Clif->Clif-related binary operations. +prec2NCC :: NCCBinOp -> Int +prec2NCC _ = 190 prec2ESS :: ESSBinOp -> Int prec2ESS _ = 190 @@ -78,12 +78,12 @@ prec1B :: UFuncB -> Int prec1B Not = 230 -- | prec1VV - precedence of vector-vector-related unary operators. -prec1VV :: UFuncVV -> Int -prec1VV _ = 250 +prec1CC :: UFuncCC -> Int +prec1CC _ = 250 -- | prec1Vec - precedence of vector-number-related unary operators. -prec1VN :: UFuncVN -> Int -prec1VN _ = 230 +prec1CN :: UFuncCN -> Int +prec1CN _ = 230 -- | eprec - `ModelExpr` precedence. mePrec :: ModelExpr -> Int @@ -101,8 +101,8 @@ mePrec Set{} = 220 mePrec (Variable _ _) = 220 mePrec (UnaryOp fn _) = prec1 fn mePrec (UnaryOpB fn _) = prec1B fn -mePrec (UnaryOpVV fn _) = prec1VV fn -mePrec (UnaryOpVN fn _) = prec1VN fn +mePrec (UnaryOpCC fn _) = prec1CC fn +mePrec (UnaryOpCN fn _) = prec1CN fn mePrec (Operator o _ _) = precA o mePrec (ArithBinaryOp bo _ _) = prec2Arith bo mePrec (BoolBinaryOp bo _ _) = prec2Bool bo @@ -111,9 +111,9 @@ mePrec (LABinaryOp bo _ _) = prec2LA bo mePrec (SpaceBinaryOp bo _ _) = prec2Spc bo mePrec (StatBinaryOp bo _ _) = prec2Stat bo mePrec (OrdBinaryOp bo _ _) = prec2Ord bo -mePrec (VVVBinaryOp bo _ _) = prec2VVV bo -mePrec (VVNBinaryOp bo _ _) = prec2VVN bo -mePrec (NVVBinaryOp bo _ _) = prec2NVV bo +mePrec (CCCBinaryOp bo _ _) = prec2CCC bo +mePrec (CCNBinaryOp bo _ _) = prec2CCN bo +mePrec (NCCBinaryOp bo _ _) = prec2NCC bo mePrec (ESSBinaryOp bo _ _) = prec2ESS bo mePrec (ESBBinaryOp bo _ _) = prec2ESB bo mePrec RealI{} = 170 diff --git a/code/drasil-lang/lib/Language/Drasil/Space.hs b/code/drasil-lang/lib/Language/Drasil/Space.hs index 620eac55ea5..380d397a3ec 100644 --- a/code/drasil-lang/lib/Language/Drasil/Space.hs +++ b/code/drasil-lang/lib/Language/Drasil/Space.hs @@ -14,13 +14,16 @@ module Language.Drasil.Space ( -- * Class HasSpace(..), -- * Functions - getActorName, getInnerSpace, mkFunction, isBasicNumSpace + getActorName, getInnerSpace, mkFunction, isBasicNumSpace, + Dimension(..), vect2DS, vect3DS, vectS, vectNDS ) where import qualified Data.List.NonEmpty as NE import Control.Lens (Getter) import Language.Drasil.Symbol (Symbol) +import Numeric.Natural (Natural) + -- FIXME: These need to be spaces and not just types. @@ -28,23 +31,53 @@ import Language.Drasil.Symbol (Symbol) -- numerical spaces (such as the set of integers, rationals, etc.), -- a space for booleans, a space for characters, dimensional spaces (vectors, arrays, etc.), -- a space for Actors, discrete sets (both for numbers and strings), and a void space. -data Space = - Integer - | Rational - | Real - | Natural - | Boolean - | Char - | String - | Vect Space -- TODO: Length for vectors? - | Set Space - | Matrix Int Int Space - | Array Space - | Actor String - | Function (NE.NonEmpty Primitive) Primitive - | Void +data Space where + Integer :: Space + Rational :: Space + Real :: Space + Natural :: Space + Boolean :: Space + Char :: Space + String :: Space + -- | Vect Space -- TODO: Length for vectors? + Set :: Space -> Space + Matrix :: Int -> Int -> Space -> Space + Array :: Space -> Space + Actor :: String -> Space + Function :: (NE.NonEmpty Primitive) -> Primitive -> Space + Void :: Space + -- | Clifford algebra objects (Clifs) with a dimension + -- TODO: Can this be just called `Clif`, depsite shadowing the binding in `*Expr`, since we `import qualified Space as S` usually? + ClifS :: Dimension -> Space -> Space deriving (Eq, Show) +-- TODO: check if non-real numbers in Clifs make any sense; allowing for now to avoid errors in offending examples +-- as we figure out matrices +checkClifSpace :: Space -> Bool +checkClifSpace Real = True +checkClifSpace _ = True --error $ "Non-real clif spaces unsupported" + +vect2DS :: Space -> Space +vect2DS s | checkClifSpace s = ClifS (Fixed 2) s + +vect3DS :: Space -> Space +vect3DS s | checkClifSpace s = ClifS (Fixed 3) s + +vectS :: Natural -> Space -> Space +vectS n s | checkClifSpace s = ClifS (Fixed n) s + +vectNDS :: String -> Space -> Space +vectNDS x s | checkClifSpace s = ClifS (VDim x) s + +-- | The dimension of a clif +data Dimension where + -- | Fixed dimension + Fixed :: Natural -> Dimension + -- | Variable dimension + VDim :: String -> Dimension + deriving (Eq, Show) + + -- | HasSpace is anything which has a 'Space'. class HasSpace c where -- | Provides a 'Getter' to the 'Space'. @@ -87,8 +120,8 @@ getActorName _ = error "getActorName called on non-actor space" -- | Gets the inner 'Space' of a vector or set. getInnerSpace :: Space -> Space -getInnerSpace (Vect s) = s getInnerSpace (Set s) = s +getInnerSpace (ClifS _ s) = s getInnerSpace _ = error "getInnerSpace called on non-vector space" -- | Is this Space a basic numeric space? @@ -101,9 +134,9 @@ isBasicNumSpace Boolean = False isBasicNumSpace Char = False isBasicNumSpace String = False isBasicNumSpace Set {} = False -isBasicNumSpace Vect {} = False isBasicNumSpace Matrix {} = False isBasicNumSpace Array {} = False isBasicNumSpace Actor {} = False isBasicNumSpace Function {} = False isBasicNumSpace Void = False +isBasicNumSpace ClifS {} = False diff --git a/code/drasil-printers/lib/Language/Drasil/HTML/Print.hs b/code/drasil-printers/lib/Language/Drasil/HTML/Print.hs index aa60f899027..f7312a754c6 100644 --- a/code/drasil-printers/lib/Language/Drasil/HTML/Print.hs +++ b/code/drasil-printers/lib/Language/Drasil/HTML/Print.hs @@ -215,8 +215,8 @@ pOps Dim = "dim" pOps Exp = "e" pOps Neg = "−" pOps Cross = "⨯" -pOps VAdd = "+" -pOps VSub = "−" +pOps CAdd = "+" +pOps CSub = "−" pOps Dot = "⋅" pOps Scale = " " -- same as Mul pOps Eq = " = " -- with spaces? diff --git a/code/drasil-printers/lib/Language/Drasil/JSON/Print.hs b/code/drasil-printers/lib/Language/Drasil/JSON/Print.hs index 771c5ce54db..e8144e65c8e 100644 --- a/code/drasil-printers/lib/Language/Drasil/JSON/Print.hs +++ b/code/drasil-printers/lib/Language/Drasil/JSON/Print.hs @@ -190,8 +190,8 @@ pOps Dim = "dim" pOps Exp = "e" pOps Neg = "-" pOps Cross = "⨯" -pOps VAdd = " + " -pOps VSub = " - " +pOps CAdd = " + " +pOps CSub = " - " pOps Dot = "⋅" pOps Scale = "" -- same as Mul pOps Eq = " = " -- with spaces? diff --git a/code/drasil-printers/lib/Language/Drasil/Plain/Print.hs b/code/drasil-printers/lib/Language/Drasil/Plain/Print.hs index 9746c8ecc67..b845065105f 100644 --- a/code/drasil-printers/lib/Language/Drasil/Plain/Print.hs +++ b/code/drasil-printers/lib/Language/Drasil/Plain/Print.hs @@ -146,8 +146,8 @@ opsDoc Dim = text "dim" opsDoc Exp = text "exp" opsDoc Neg = text "-" opsDoc Cross = text " cross " -opsDoc VAdd = text " + " -opsDoc VSub = text " - " +opsDoc CAdd = text " + " +opsDoc CSub = text " - " opsDoc Dot = text " dot " opsDoc Scale = text " * " opsDoc Eq = text " == " diff --git a/code/drasil-printers/lib/Language/Drasil/Printing/AST.hs b/code/drasil-printers/lib/Language/Drasil/Printing/AST.hs index ac583589d0d..b3dce256175 100644 --- a/code/drasil-printers/lib/Language/Drasil/Printing/AST.hs +++ b/code/drasil-printers/lib/Language/Drasil/Printing/AST.hs @@ -1,7 +1,8 @@ -- | Defines types similar to those in "Drasil.Language", but better suited to printing. module Language.Drasil.Printing.AST where -import Language.Drasil (Special) +import Language.Drasil (Special, BasisBlades, Dimension) + -- | Different types of links for referencing. May be internal, a citation, or external. -- A citation may also hold additional reference information. @@ -12,7 +13,7 @@ data Ops = IsIn | Integer | Real | Rational | Natural | Boolean | Comma | Prime | Ln | Sin | Cos | Tan | Sec | Csc | Cot | Arcsin | Arccos | Arctan | Not | Dim | Exp | Neg | Cross | Dot | Scale | Eq | NEq | Lt | Gt | LEq | GEq | Impl | Iff | Subt | And | Or | Add | Mul | Summ | Inte | Prod | Point | Perc | LArrow | RArrow | ForAll - | VAdd | VSub | Partial | SAdd | SRemove | SUnion | SContains deriving Eq + | CAdd | CSub | Partial | SAdd | SRemove | SUnion | SContains deriving Eq -- | Holds the type of "text fencing" ("(), {}, |, ||"). data Fence = Paren | Curly | Norm | Abs @@ -45,6 +46,7 @@ data Expr = Dbl Double | Div Expr Expr -- ^ Fractions are a layout thing. | Sqrt Expr -- ^ Roots are also a layout thing. Just sqrt for now. | Spc Spacing -- ^ Holds the 'Spacing'. + | Clif Dimension (BasisBlades Expr) infixr 5 :+: diff --git a/code/drasil-printers/lib/Language/Drasil/Printing/Import/CodeExpr.hs b/code/drasil-printers/lib/Language/Drasil/Printing/Import/CodeExpr.hs index 6188ddf2e19..d95caea0684 100644 --- a/code/drasil-printers/lib/Language/Drasil/Printing/Import/CodeExpr.hs +++ b/code/drasil-printers/lib/Language/Drasil/Printing/Import/CodeExpr.hs @@ -44,7 +44,7 @@ neg' (AssocA Mul _) = True neg' (LABinaryOp Index _ _) = True neg' (UnaryOp _ _) = True neg' (UnaryOpB _ _) = True -neg' (UnaryOpVV _ _) = True +neg' (UnaryOpCC _ _) = True neg' (C _) = True neg' _ = False @@ -141,11 +141,11 @@ codeExpr (UnaryOp Arctan u) sm = mkCall sm P.Arctan u codeExpr (UnaryOp Exp u) sm = P.Row [P.MO P.Exp, P.Sup $ codeExpr u sm] codeExpr (UnaryOp Abs u) sm = P.Fenced P.Abs P.Abs $ codeExpr u sm codeExpr (UnaryOpB Not u) sm = P.Row [P.MO P.Not, codeExpr u sm] -codeExpr (UnaryOpVN Norm u) sm = P.Fenced P.Norm P.Norm $ codeExpr u sm -codeExpr (UnaryOpVN Dim u) sm = mkCall sm P.Dim u +codeExpr (UnaryOpCN Norm u) sm = P.Fenced P.Norm P.Norm $ codeExpr u sm +codeExpr (UnaryOpCN Dim u) sm = mkCall sm P.Dim u codeExpr (UnaryOp Sqrt u) sm = P.Sqrt $ codeExpr u sm codeExpr (UnaryOp Neg u) sm = neg sm u -codeExpr (UnaryOpVV NegV u) sm = neg sm u +codeExpr (UnaryOpCC NegC u) sm = neg sm u codeExpr (ArithBinaryOp Frac a b) sm = P.Div (codeExpr a sm) (codeExpr b sm) codeExpr (ArithBinaryOp Pow a b) sm = pow sm a b codeExpr (ArithBinaryOp Subt a b) sm = P.Row [codeExpr a sm, P.MO P.Subt, codeExpr b sm] @@ -159,11 +159,11 @@ codeExpr (OrdBinaryOp Lt a b) sm = mkBOp sm P.Lt a b codeExpr (OrdBinaryOp Gt a b) sm = mkBOp sm P.Gt a b codeExpr (OrdBinaryOp LEq a b) sm = mkBOp sm P.LEq a b codeExpr (OrdBinaryOp GEq a b) sm = mkBOp sm P.GEq a b -codeExpr (VVNBinaryOp Dot a b) sm = mkBOp sm P.Dot a b -codeExpr (VVVBinaryOp Cross a b) sm = mkBOp sm P.Cross a b -codeExpr (VVVBinaryOp VAdd a b) sm = mkBOp sm P.VAdd a b -codeExpr (VVVBinaryOp VSub a b) sm = mkBOp sm P.VSub a b -codeExpr (NVVBinaryOp Scale a b) sm = mkBOp sm P.Scale a b +codeExpr (CCNBinaryOp Dot a b) sm = mkBOp sm P.Dot a b +codeExpr (CCCBinaryOp Cross a b) sm = mkBOp sm P.Cross a b +codeExpr (CCCBinaryOp CAdd a b) sm = mkBOp sm P.CAdd a b +codeExpr (CCCBinaryOp CSub a b) sm = mkBOp sm P.CSub a b +codeExpr (NCCBinaryOp Scale a b) sm = mkBOp sm P.Scale a b codeExpr (ESSBinaryOp SAdd a b) sm = mkBOp sm P.SAdd a b codeExpr (ESSBinaryOp SRemove a b) sm = mkBOp sm P.SRemove a b codeExpr (ESBBinaryOp SContains a b) sm = mkBOp sm P.SContains a b diff --git a/code/drasil-printers/lib/Language/Drasil/Printing/Import/Expr.hs b/code/drasil-printers/lib/Language/Drasil/Printing/Import/Expr.hs index 0340ccd3007..fd0c3d8a227 100644 --- a/code/drasil-printers/lib/Language/Drasil/Printing/Import/Expr.hs +++ b/code/drasil-printers/lib/Language/Drasil/Printing/Import/Expr.hs @@ -7,8 +7,8 @@ import Language.Drasil hiding (neg, sec, symbol, isIn, Matrix, Set) import qualified Language.Drasil.Display as S (Symbol(..)) import Language.Drasil.Expr.Development (ArithBinOp(..), AssocArithOper(..), AssocBoolOper(..), BoolBinOp(..), EqBinOp(..), Expr(..), - LABinOp(..), OrdBinOp(..), UFunc(..), UFuncB(..), UFuncVN(..), UFuncVV(..), - VVNBinOp(..), VVVBinOp(..), NVVBinOp(..), ESSBinOp(..), ESBBinOp(..), AssocConcatOper(..), eprec, precA, precB, precC) + LABinOp(..), OrdBinOp(..), UFunc(..), UFuncB(..), UFuncCN(..), UFuncCC(..), + CCNBinOp(..), CCCBinOp(..), NCCBinOp(..), ESSBinOp(..), ESBBinOp(..), AssocConcatOper(..), eprec, precA, precB, precC) import Language.Drasil.Literal.Development (Literal(..)) import qualified Language.Drasil.Printing.AST as P @@ -45,7 +45,7 @@ neg' (AssocA Mul _) = True neg' (LABinaryOp Index _ _) = True neg' (UnaryOp _ _) = True neg' (UnaryOpB _ _) = True -neg' (UnaryOpVV _ _) = True +neg' (UnaryOpCC _ _) = True neg' (C _) = True neg' _ = False @@ -138,11 +138,11 @@ expr (UnaryOp Arctan u) sm = mkCall sm P.Arctan u expr (UnaryOp Exp u) sm = P.Row [P.MO P.Exp, P.Sup $ expr u sm] expr (UnaryOp Abs u) sm = P.Fenced P.Abs P.Abs $ expr u sm expr (UnaryOpB Not u) sm = P.Row [P.MO P.Not, expr u sm] -expr (UnaryOpVN Norm u) sm = P.Fenced P.Norm P.Norm $ expr u sm -expr (UnaryOpVN Dim u) sm = mkCall sm P.Dim u +expr (UnaryOpCN Norm u) sm = P.Fenced P.Norm P.Norm $ expr u sm +expr (UnaryOpCN Dim u) sm = mkCall sm P.Dim u expr (UnaryOp Sqrt u) sm = P.Sqrt $ expr u sm expr (UnaryOp Neg u) sm = neg sm u -expr (UnaryOpVV NegV u) sm = neg sm u +expr (UnaryOpCC NegC u) sm = neg sm u expr (ArithBinaryOp Frac a b) sm = P.Div (expr a sm) (expr b sm) expr (ArithBinaryOp Pow a b) sm = pow sm a b expr (ArithBinaryOp Subt a b) sm = P.Row [expr a sm, P.MO P.Subt, expr b sm] @@ -156,11 +156,11 @@ expr (OrdBinaryOp Lt a b) sm = mkBOp sm P.Lt a b expr (OrdBinaryOp Gt a b) sm = mkBOp sm P.Gt a b expr (OrdBinaryOp LEq a b) sm = mkBOp sm P.LEq a b expr (OrdBinaryOp GEq a b) sm = mkBOp sm P.GEq a b -expr (VVVBinaryOp Cross a b) sm = mkBOp sm P.Cross a b -expr (VVVBinaryOp VAdd a b) sm = mkBOp sm P.VAdd a b -expr (VVVBinaryOp VSub a b) sm = mkBOp sm P.VSub a b -expr (VVNBinaryOp Dot a b) sm = mkBOp sm P.Dot a b -expr (NVVBinaryOp Scale a b) sm = mkBOp sm P.Scale a b +expr (CCCBinaryOp Cross a b) sm = mkBOp sm P.Cross a b +expr (CCCBinaryOp CAdd a b) sm = mkBOp sm P.CAdd a b +expr (CCCBinaryOp CSub a b) sm = mkBOp sm P.CSub a b +expr (CCNBinaryOp Dot a b) sm = mkBOp sm P.Dot a b +expr (NCCBinaryOp Scale a b) sm = mkBOp sm P.Scale a b expr (ESSBinaryOp SAdd a b) sm = mkBOp sm P.SAdd a b expr (ESSBinaryOp SRemove a b) sm = mkBOp sm P.SRemove a b expr (ESBBinaryOp SContains a b) sm = mkBOp sm P.SContains a b diff --git a/code/drasil-printers/lib/Language/Drasil/Printing/Import/ModelExpr.hs b/code/drasil-printers/lib/Language/Drasil/Printing/Import/ModelExpr.hs index d4f98141334..07226859adc 100644 --- a/code/drasil-printers/lib/Language/Drasil/Printing/Import/ModelExpr.hs +++ b/code/drasil-printers/lib/Language/Drasil/Printing/Import/ModelExpr.hs @@ -15,6 +15,8 @@ import Language.Drasil.Printing.PrintingInformation (PrintingInformation, ckdb, import Control.Lens ((^.)) import Data.List (intersperse) +import qualified Data.Map as Map +import qualified Data.Map.Ordered as OM import Language.Drasil.Printing.Import.Literal (literal) import Language.Drasil.Printing.Import.Space (space) @@ -44,7 +46,7 @@ neg' (AssocA Mul _) = True neg' (LABinaryOp Index _ _) = True neg' (UnaryOp _ _) = True neg' (UnaryOpB _ _) = True -neg' (UnaryOpVV _ _) = True +neg' (UnaryOpCC _ _) = True neg' (C _) = True neg' _ = False @@ -153,11 +155,11 @@ modelExpr (UnaryOp Arctan u) sm = mkCall sm P.Arctan u modelExpr (UnaryOp Exp u) sm = P.Row [P.MO P.Exp, P.Sup $ modelExpr u sm] modelExpr (UnaryOp Abs u) sm = P.Fenced P.Abs P.Abs $ modelExpr u sm modelExpr (UnaryOpB Not u) sm = P.Row [P.MO P.Not, modelExpr u sm] -modelExpr (UnaryOpVN Norm u) sm = P.Fenced P.Norm P.Norm $ modelExpr u sm -modelExpr (UnaryOpVN Dim u) sm = mkCall sm P.Dim u +modelExpr (UnaryOpCN Norm u) sm = P.Fenced P.Norm P.Norm $ modelExpr u sm +modelExpr (UnaryOpCN Dim u) sm = mkCall sm P.Dim u modelExpr (UnaryOp Sqrt u) sm = P.Sqrt $ modelExpr u sm modelExpr (UnaryOp Neg u) sm = neg sm u -modelExpr (UnaryOpVV NegV u) sm = neg sm u +modelExpr (UnaryOpCC NegC u) sm = neg sm u modelExpr (ArithBinaryOp Frac a b) sm = P.Div (modelExpr a sm) (modelExpr b sm) modelExpr (ArithBinaryOp Pow a b) sm = pow sm a b modelExpr (ArithBinaryOp Subt a b) sm = P.Row [modelExpr a sm, P.MO P.Subt, modelExpr b sm] @@ -171,11 +173,11 @@ modelExpr (OrdBinaryOp Lt a b) sm = mkBOp sm P.Lt a b modelExpr (OrdBinaryOp Gt a b) sm = mkBOp sm P.Gt a b modelExpr (OrdBinaryOp LEq a b) sm = mkBOp sm P.LEq a b modelExpr (OrdBinaryOp GEq a b) sm = mkBOp sm P.GEq a b -modelExpr (VVNBinaryOp Dot a b) sm = mkBOp sm P.Dot a b -modelExpr (VVVBinaryOp Cross a b) sm = mkBOp sm P.Cross a b -modelExpr (VVVBinaryOp VAdd a b) sm = mkBOp sm P.VAdd a b -modelExpr (VVVBinaryOp VSub a b) sm = mkBOp sm P.VSub a b -modelExpr (NVVBinaryOp Scale a b) sm = mkBOp sm P.Scale a b +modelExpr (CCNBinaryOp Dot a b) sm = mkBOp sm P.Dot a b +modelExpr (CCCBinaryOp Cross a b) sm = mkBOp sm P.Cross a b +modelExpr (CCCBinaryOp CAdd a b) sm = mkBOp sm P.CAdd a b +modelExpr (CCCBinaryOp CSub a b) sm = mkBOp sm P.CSub a b +modelExpr (NCCBinaryOp Scale a b) sm = mkBOp sm P.Scale a b modelExpr (ESSBinaryOp SAdd a b) sm = mkBOp sm P.SAdd a b modelExpr (ESSBinaryOp SRemove a b) sm = mkBOp sm P.SRemove a b modelExpr (ESBBinaryOp SContains a b) sm = mkBOp sm P.SContains a b @@ -189,6 +191,10 @@ modelExpr (ForAll c s de) sm = P.Row [ P.MO P.ForAll, symbol $ lookupC (sm ^. stg) (sm ^. ckdb) c, P.MO P.IsIn, space sm s, P.MO P.Dot, modelExpr de sm ] +-- TODO: Fix this to be more specific to Clifs +-- TODO: How do we control whether to print all the components or just a subset (e.g. only the vector components)? +modelExpr (Clif _ es) sm = P.Mtx $ map ((:[]) . (`modelExpr` sm)) $ OM.elems es +modelExpr _ _ = error "Printing/Import.hs: modelExpr: unhandled ModelExpr type" -- | Common method of converting associative operations into printable layout AST. assocExpr :: P.Ops -> Int -> [ModelExpr] -> PrintingInformation -> P.Expr diff --git a/code/drasil-printers/lib/Language/Drasil/Printing/Import/Space.hs b/code/drasil-printers/lib/Language/Drasil/Printing/Import/Space.hs index 707f7048343..a762ccd5757 100644 --- a/code/drasil-printers/lib/Language/Drasil/Printing/Import/Space.hs +++ b/code/drasil-printers/lib/Language/Drasil/Printing/Import/Space.hs @@ -18,7 +18,7 @@ space _ Natural = P.MO P.Natural space _ Boolean = P.MO P.Boolean space _ Char = P.Ident "Char" space _ String = P.Ident "String" -space _ (Vect _) = error "Vector space not translated" +space _ (ClifS d _) = error "Clif space not translated" space _ Matrix {} = error "Matrix space not translated" space _ (Array _) = error "Array space not translated" space _ (Actor s) = P.Ident s diff --git a/code/drasil-printers/lib/Language/Drasil/TeX/Print.hs b/code/drasil-printers/lib/Language/Drasil/TeX/Print.hs index dfa95b0e1e1..2eb52df5a95 100644 --- a/code/drasil-printers/lib/Language/Drasil/TeX/Print.hs +++ b/code/drasil-printers/lib/Language/Drasil/TeX/Print.hs @@ -151,8 +151,8 @@ pOps Dim = command "mathsf" "dim" pOps Exp = pure $ text "e" pOps Neg = pure hyph pOps Cross = texSym "times" -pOps VAdd = pure pls -pOps VSub = pure hyph -- unfortunately, hyphen and - are the same +pOps CAdd = pure pls +pOps CSub = pure hyph -- unfortunately, hyphen and - are the same pOps Dot = commandD "cdot" empty pOps Scale = pure $ text " " pOps Eq = pure assign diff --git a/code/drasil-utils/lib/Data/Map/Ordered.hs b/code/drasil-utils/lib/Data/Map/Ordered.hs new file mode 100644 index 00000000000..ae3c9129286 --- /dev/null +++ b/code/drasil-utils/lib/Data/Map/Ordered.hs @@ -0,0 +1,39 @@ +module Data.Map.Ordered (OrderedMap, + null, size, empty, singleton, + insert, lookup, elems, fromList) where + +import Prelude hiding (lookup, null) + +import qualified Data.Map as M +import Data.List (sortOn) +import Data.Foldable (Foldable(foldl')) + +-- | Simple ordered map. Based on 'container's 'Data.Map'. Note: Deletions are +-- unsupported. +newtype OrderedMap k v = OM { im :: M.Map k (Int, v) } + deriving (Show, Eq) + +null :: OrderedMap k v -> Bool +null (OM m) = M.null m + +size :: OrderedMap k v -> Int +size (OM m) = M.size m + +empty :: OrderedMap k v +empty = OM M.empty + +singleton :: k -> v -> OrderedMap k v +singleton k v = OM $ M.singleton k (0, v) -- Using 0 as the initial index + +insert :: Ord k => k -> v -> OrderedMap k v -> OrderedMap k v +insert k v (OM m) = OM $ M.insert k (M.size m, v) m -- Using M.size means that we need to be careful with deletions!! + +lookup :: Ord k => k -> OrderedMap k v -> Maybe v +lookup k (OM m) = snd <$> M.lookup k m + +elems :: OrderedMap k v -> [v] +elems (OM m) = map snd $ sortOn fst $ M.elems m + +fromList :: Ord k => [(k, v)] -> OrderedMap k v +fromList [] = empty +fromList ((k, v):kvs) = foldl'(\acc (k', v') -> insert k' v' acc) (singleton k v) kvs -- Outermost entry is inserted first diff --git a/code/drasil-utils/package.yaml b/code/drasil-utils/package.yaml index 37762d6e869..4009c37c016 100644 --- a/code/drasil-utils/package.yaml +++ b/code/drasil-utils/package.yaml @@ -27,6 +27,7 @@ library: source-dirs: lib exposed-modules: - Utils.Drasil + - Data.Map.Ordered when: - condition: false other-modules: Paths_drasil_utils diff --git a/code/stable/dblpend/src/cpp/designLog.txt b/code/stable/dblpend/src/cpp/designLog.txt index 99ff55a53b0..bc44523c3c5 100644 --- a/code/stable/dblpend/src/cpp/designLog.txt +++ b/code/stable/dblpend/src/cpp/designLog.txt @@ -20,7 +20,7 @@ Successfully matched String with String. Successfully matched Actor "Constants" with Object "Constants". Successfully matched Actor "InputParameters" with Object "InputParameters". Successfully matched Real with Double. -Successfully matched Vect Real with List Double. +Successfully matched ClifS (VDim "n") Real with List Double. Successfully matched Actor "ODE" with Object "ODE". Successfully matched Actor "Populate" with Object "Populate". Successfully matched Actor "boost::numeric::odeint::runge_kutta_dopri5>" with Object "boost::numeric::odeint::runge_kutta_dopri5>". diff --git a/code/stable/dblpend/src/csharp/designLog.txt b/code/stable/dblpend/src/csharp/designLog.txt index 3edbe44e101..d6ddc121393 100644 --- a/code/stable/dblpend/src/csharp/designLog.txt +++ b/code/stable/dblpend/src/csharp/designLog.txt @@ -18,7 +18,7 @@ Successfully matched String with String. Successfully matched Actor "Constants" with Object "Constants". Successfully matched Actor "InputParameters" with Object "InputParameters". Successfully matched Real with Double. -Successfully matched Vect Real with List Double. +Successfully matched ClifS (VDim "n") Real with List Double. Successfully matched Actor "Vector" with Object "Vector". Successfully matched Array Real with Array Double. Successfully matched Actor "Options" with Object "Options". diff --git a/code/stable/dblpend/src/java/designLog.txt b/code/stable/dblpend/src/java/designLog.txt index 617827175f5..b3d62e8487d 100644 --- a/code/stable/dblpend/src/java/designLog.txt +++ b/code/stable/dblpend/src/java/designLog.txt @@ -19,7 +19,7 @@ Successfully matched String with String. Successfully matched Actor "Constants" with Object "Constants". Successfully matched Actor "InputParameters" with Object "InputParameters". Successfully matched Real with Double. -Successfully matched Vect Real with List Double. +Successfully matched ClifS (VDim "n") Real with List Double. Successfully matched Actor "ODEStepHandler" with Object "ODEStepHandler". Successfully matched Actor "ODE" with Object "ODE". Successfully matched Array Real with Array Double. diff --git a/code/stable/dblpend/src/python/designLog.txt b/code/stable/dblpend/src/python/designLog.txt index d241e2a17ba..6a5c96929cf 100644 --- a/code/stable/dblpend/src/python/designLog.txt +++ b/code/stable/dblpend/src/python/designLog.txt @@ -17,7 +17,7 @@ Successfully matched String with String. Successfully matched Actor "Constants" with Object "Constants". Successfully matched Actor "InputParameters" with Object "InputParameters". Successfully matched Real with Double. -Successfully matched Vect Real with List Double. +Successfully matched ClifS (VDim "n") Real with List Double. Successfully matched Array Real with Array Double. Successfully matched Actor "ode" with Object "ode". Successfully matched Void with Void. diff --git a/code/stable/glassbr/src/cpp/designLog.txt b/code/stable/glassbr/src/cpp/designLog.txt index ecba458e378..1fb0e8b0ba7 100644 --- a/code/stable/glassbr/src/cpp/designLog.txt +++ b/code/stable/glassbr/src/cpp/designLog.txt @@ -20,6 +20,6 @@ Successfully matched Boolean with Boolean. Successfully matched Rational with Double. Successfully matched Integer with Integer. Successfully matched Function (String :| [Real,Real]) Real with Func [String] Double. -Successfully matched Vect Real with List Double. -Successfully matched Vect (Vect Real) with List (List Double). +Successfully matched ClifS (Fixed 3) Real with List Double. +Successfully matched ClifS (Fixed 3) (ClifS (Fixed 3) Real) with List (List Double). Successfully matched Natural with Integer. diff --git a/code/stable/glassbr/src/csharp/designLog.txt b/code/stable/glassbr/src/csharp/designLog.txt index ecba458e378..1fb0e8b0ba7 100644 --- a/code/stable/glassbr/src/csharp/designLog.txt +++ b/code/stable/glassbr/src/csharp/designLog.txt @@ -20,6 +20,6 @@ Successfully matched Boolean with Boolean. Successfully matched Rational with Double. Successfully matched Integer with Integer. Successfully matched Function (String :| [Real,Real]) Real with Func [String] Double. -Successfully matched Vect Real with List Double. -Successfully matched Vect (Vect Real) with List (List Double). +Successfully matched ClifS (Fixed 3) Real with List Double. +Successfully matched ClifS (Fixed 3) (ClifS (Fixed 3) Real) with List (List Double). Successfully matched Natural with Integer. diff --git a/code/stable/glassbr/src/java/designLog.txt b/code/stable/glassbr/src/java/designLog.txt index ecba458e378..1fb0e8b0ba7 100644 --- a/code/stable/glassbr/src/java/designLog.txt +++ b/code/stable/glassbr/src/java/designLog.txt @@ -20,6 +20,6 @@ Successfully matched Boolean with Boolean. Successfully matched Rational with Double. Successfully matched Integer with Integer. Successfully matched Function (String :| [Real,Real]) Real with Func [String] Double. -Successfully matched Vect Real with List Double. -Successfully matched Vect (Vect Real) with List (List Double). +Successfully matched ClifS (Fixed 3) Real with List Double. +Successfully matched ClifS (Fixed 3) (ClifS (Fixed 3) Real) with List (List Double). Successfully matched Natural with Integer. diff --git a/code/stable/glassbr/src/python/designLog.txt b/code/stable/glassbr/src/python/designLog.txt index ecba458e378..1fb0e8b0ba7 100644 --- a/code/stable/glassbr/src/python/designLog.txt +++ b/code/stable/glassbr/src/python/designLog.txt @@ -20,6 +20,6 @@ Successfully matched Boolean with Boolean. Successfully matched Rational with Double. Successfully matched Integer with Integer. Successfully matched Function (String :| [Real,Real]) Real with Func [String] Double. -Successfully matched Vect Real with List Double. -Successfully matched Vect (Vect Real) with List (List Double). +Successfully matched ClifS (Fixed 3) Real with List Double. +Successfully matched ClifS (Fixed 3) (ClifS (Fixed 3) Real) with List (List Double). Successfully matched Natural with Integer. diff --git a/code/stable/glassbr/src/swift/designLog.txt b/code/stable/glassbr/src/swift/designLog.txt index ecba458e378..1fb0e8b0ba7 100644 --- a/code/stable/glassbr/src/swift/designLog.txt +++ b/code/stable/glassbr/src/swift/designLog.txt @@ -20,6 +20,6 @@ Successfully matched Boolean with Boolean. Successfully matched Rational with Double. Successfully matched Integer with Integer. Successfully matched Function (String :| [Real,Real]) Real with Func [String] Double. -Successfully matched Vect Real with List Double. -Successfully matched Vect (Vect Real) with List (List Double). +Successfully matched ClifS (Fixed 3) Real with List Double. +Successfully matched ClifS (Fixed 3) (ClifS (Fixed 3) Real) with List (List Double). Successfully matched Natural with Integer. diff --git a/code/stable/pdcontroller/src/cpp/designLog.txt b/code/stable/pdcontroller/src/cpp/designLog.txt index 4ae19325e71..a79e031456c 100644 --- a/code/stable/pdcontroller/src/cpp/designLog.txt +++ b/code/stable/pdcontroller/src/cpp/designLog.txt @@ -20,7 +20,7 @@ Successfully matched String with String. Successfully matched Actor "Constants" with Object "Constants". Successfully matched Actor "InputParameters" with Object "InputParameters". Successfully matched Real with Double. -Successfully matched Vect Real with List Double. +Successfully matched ClifS (VDim "n") Real with List Double. Successfully matched Actor "ODE" with Object "ODE". Successfully matched Actor "Populate" with Object "Populate". Successfully matched Actor "boost::numeric::odeint::runge_kutta_dopri5>" with Object "boost::numeric::odeint::runge_kutta_dopri5>". diff --git a/code/stable/pdcontroller/src/csharp/designLog.txt b/code/stable/pdcontroller/src/csharp/designLog.txt index 470c53c4e08..6ac9dee2c43 100644 --- a/code/stable/pdcontroller/src/csharp/designLog.txt +++ b/code/stable/pdcontroller/src/csharp/designLog.txt @@ -18,7 +18,7 @@ Successfully matched String with String. Successfully matched Actor "Constants" with Object "Constants". Successfully matched Actor "InputParameters" with Object "InputParameters". Successfully matched Real with Double. -Successfully matched Vect Real with List Double. +Successfully matched ClifS (VDim "n") Real with List Double. Successfully matched Actor "Vector" with Object "Vector". Successfully matched Array Real with Array Double. Successfully matched Actor "Options" with Object "Options". diff --git a/code/stable/pdcontroller/src/java/designLog.txt b/code/stable/pdcontroller/src/java/designLog.txt index 2f89f57e411..0f3bab97d8c 100644 --- a/code/stable/pdcontroller/src/java/designLog.txt +++ b/code/stable/pdcontroller/src/java/designLog.txt @@ -19,7 +19,7 @@ Successfully matched String with String. Successfully matched Actor "Constants" with Object "Constants". Successfully matched Actor "InputParameters" with Object "InputParameters". Successfully matched Real with Double. -Successfully matched Vect Real with List Double. +Successfully matched ClifS (VDim "n") Real with List Double. Successfully matched Actor "ODEStepHandler" with Object "ODEStepHandler". Successfully matched Actor "ODE" with Object "ODE". Successfully matched Array Real with Array Double. diff --git a/code/stable/pdcontroller/src/python/designLog.txt b/code/stable/pdcontroller/src/python/designLog.txt index 96e6b48797f..b5260581458 100644 --- a/code/stable/pdcontroller/src/python/designLog.txt +++ b/code/stable/pdcontroller/src/python/designLog.txt @@ -17,7 +17,7 @@ Successfully matched String with String. Successfully matched Actor "Constants" with Object "Constants". Successfully matched Actor "InputParameters" with Object "InputParameters". Successfully matched Real with Double. -Successfully matched Vect Real with List Double. +Successfully matched ClifS (VDim "n") Real with List Double. Successfully matched Array Real with Array Double. Successfully matched Actor "ode" with Object "ode". Successfully matched Void with Void. diff --git a/code/stable/swhsnopcm/src/cpp/designLog.txt b/code/stable/swhsnopcm/src/cpp/designLog.txt index f7b6cffff31..ccacf3a0f2c 100644 --- a/code/stable/swhsnopcm/src/cpp/designLog.txt +++ b/code/stable/swhsnopcm/src/cpp/designLog.txt @@ -20,7 +20,7 @@ Successfully matched String with String. Successfully matched Actor "Constants" with Object "Constants". Successfully matched Actor "InputParameters" with Object "InputParameters". Successfully matched Real with Double. -Successfully matched Vect Real with List Double. +Successfully matched ClifS (VDim "n") Real with List Double. Successfully matched Actor "ODE" with Object "ODE". Successfully matched Actor "Populate" with Object "Populate". Successfully matched Actor "boost::numeric::odeint::runge_kutta_dopri5>" with Object "boost::numeric::odeint::runge_kutta_dopri5>". diff --git a/code/stable/swhsnopcm/src/csharp/designLog.txt b/code/stable/swhsnopcm/src/csharp/designLog.txt index 660a3330359..0587824b33f 100644 --- a/code/stable/swhsnopcm/src/csharp/designLog.txt +++ b/code/stable/swhsnopcm/src/csharp/designLog.txt @@ -18,7 +18,7 @@ Successfully matched String with String. Successfully matched Actor "Constants" with Object "Constants". Successfully matched Actor "InputParameters" with Object "InputParameters". Successfully matched Real with Double. -Successfully matched Vect Real with List Double. +Successfully matched ClifS (VDim "n") Real with List Double. Successfully matched Actor "Vector" with Object "Vector". Successfully matched Array Real with Array Double. Successfully matched Actor "Options" with Object "Options". diff --git a/code/stable/swhsnopcm/src/java/designLog.txt b/code/stable/swhsnopcm/src/java/designLog.txt index c51b1684417..fe3581834c4 100644 --- a/code/stable/swhsnopcm/src/java/designLog.txt +++ b/code/stable/swhsnopcm/src/java/designLog.txt @@ -19,7 +19,7 @@ Successfully matched String with String. Successfully matched Actor "Constants" with Object "Constants". Successfully matched Actor "InputParameters" with Object "InputParameters". Successfully matched Real with Double. -Successfully matched Vect Real with List Double. +Successfully matched ClifS (VDim "n") Real with List Double. Successfully matched Actor "ODEStepHandler" with Object "ODEStepHandler". Successfully matched Actor "ODE" with Object "ODE". Successfully matched Array Real with Array Double. diff --git a/code/stable/swhsnopcm/src/python/designLog.txt b/code/stable/swhsnopcm/src/python/designLog.txt index c6a4fe30acf..4661eb24730 100644 --- a/code/stable/swhsnopcm/src/python/designLog.txt +++ b/code/stable/swhsnopcm/src/python/designLog.txt @@ -17,7 +17,7 @@ Successfully matched String with String. Successfully matched Actor "Constants" with Object "Constants". Successfully matched Actor "InputParameters" with Object "InputParameters". Successfully matched Real with Double. -Successfully matched Vect Real with List Double. +Successfully matched ClifS (VDim "n") Real with List Double. Successfully matched Array Real with Array Double. Successfully matched Actor "ode" with Object "ode". Successfully matched Void with Void.