module Drasil.GamePhysics.DataDefs (dataDefs, ctrOfMassDD,
  linDispDD, linVelDD, linAccDD, angDispDD, angVelDD, angAccelDD, torqueDD,
  kEnergyDD, coeffRestitutionDD, reVelInCollDD, impulseVDD, momentOfInertiaDD,
  collisionAssump, rightHandAssump, rigidTwoDAssump, potEnergyDD,) where

import Language.Drasil

import Theory.Drasil
import Utils.Drasil (weave)
import Language.Drasil.Chunk.Concept.NamedCombinators
import qualified Language.Drasil.Sentence.Combinators as S
import Control.Lens ((^.))

import Drasil.GamePhysics.Assumptions (assumpOT, assumpOD, assumpAD, assumpCT, assumpDI)
import Drasil.GamePhysics.Derivations (impulseVDerivEqns)
import Drasil.GamePhysics.References (chaslesWiki)
import Drasil.GamePhysics.Unitals (finRelVel, initRelVel, mTot, massj,
  normalVect, posCM, posj, rOB, rRot, velAP, velB, velBP, velO)

import Data.Drasil.Concepts.Math (rightHand)
import Data.Drasil.Concepts.Physics (rigidBody, twoD)

import qualified Data.Drasil.Quantities.Math as QM (orientation)
import qualified Data.Drasil.Quantities.Physics as QP

import qualified Data.Drasil.Quantities.PhysicalProperties as QPP (mass)

import Data.Drasil.Theories.Physics (torqueDD)
----- Data Definitions -----

dataDefs :: [DataDefinition]
dataDefs :: [DataDefinition]
dataDefs = [DataDefinition
ctrOfMassDD, DataDefinition
linDispDD, DataDefinition
linVelDD, DataDefinition
linAccDD, DataDefinition
angDispDD,
 DataDefinition
angVelDD, DataDefinition
angAccelDD, DataDefinition
chaslesDD, DataDefinition
torqueDD, DataDefinition
kEnergyDD, DataDefinition
coeffRestitutionDD,
 DataDefinition
reVelInCollDD, DataDefinition
impulseVDD, DataDefinition
potEnergyDD, DataDefinition
momentOfInertiaDD]

-- DD1 : Centre of mass --

ctrOfMassDD :: DataDefinition
ctrOfMassDD :: DataDefinition
ctrOfMassDD = ModelQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddMENoRefs ModelQDef
ctrOfMass Maybe Derivation
forall a. Maybe a
Nothing String
"ctrOfMass" [Sentence
rigidBodyAssump]

ctrOfMass :: ModelQDef
ctrOfMass :: ModelQDef
ctrOfMass = UnitalChunk -> ModelExpr -> ModelQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
posCM ModelExpr
ctrOfMassEqn

-- FIXME (variable "i") is a horrible hack
ctrOfMassEqn :: ModelExpr
ctrOfMassEqn :: ModelExpr
ctrOfMassEqn = Symbol -> ModelExpr -> ModelExpr
forall r. ModelExprC r => Symbol -> r -> r
sumAll (String -> Symbol
variable String
"j") (UnitalChunk -> ModelExpr
forall c. (HasUID c, HasSymbol c) => c -> ModelExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
massj ModelExpr -> ModelExpr -> ModelExpr
forall r. ExprC r => r -> r -> r
$* UnitalChunk -> ModelExpr
forall c. (HasUID c, HasSymbol c) => c -> ModelExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
posj) ModelExpr -> ModelExpr -> ModelExpr
forall r. ExprC r => r -> r -> r
$/ UnitalChunk -> ModelExpr
forall c. (HasUID c, HasSymbol c) => c -> ModelExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
mTot

-- DD2 : Linear displacement --

--FIXME: Why do QDefinitions only have term and not defn? They should have both!
--FIXME: HACK - Adding fixme defn for now, since NP can't (currently) incorporate sentence.
--fixme :: NP
--fixme = nounPhraseSP $ "FIXME: THIS HACK NEEDS TO BE UPDATED TO A NOUNPHRASE, " ++
--  "SEE Drasil.GamePhysics.DataDefs for more info"
{-
linDispQDef :: Sentence
linDispQDef = foldl (+:+) (EmptyS) def
  where def = [phrase $ QP.linearDisplacement ^. term, S "of a",
              phrase $ rigidBody ^. term, S "as a function of",
              phrase $ QP.time ^. term, ch QP.time,
              S "also equal to the derivate of its linear",
              phrase $ QP.velocity ^. term, S "with respect to",
              phrase $ QP.time ^. term, ch QP.time]
-}

linDispDD :: DataDefinition
linDispDD :: DataDefinition
linDispDD = ModelQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddMENoRefs ModelQDef
linDisp Maybe Derivation
forall a. Maybe a
Nothing String
"linDisp" [Sentence
rigidBodyAssump]

linDisp :: ModelQDef
linDisp :: ModelQDef
linDisp = UnitalChunk -> ModelExpr -> ModelQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
QP.linearDisplacement ModelExpr
dispEqn

dispEqn :: ModelExpr
dispEqn :: ModelExpr
dispEqn = ModelExpr -> UnitalChunk -> ModelExpr
forall c. (HasUID c, HasSymbol c) => ModelExpr -> c -> ModelExpr
forall r c. (ModelExprC r, HasUID c, HasSymbol c) => r -> c -> r
deriv (UnitalChunk -> UnitalChunk -> ModelExpr
forall r f a.
(ExprC r, HasUID f, HasSymbol f, HasUID a, HasSymbol a) =>
f -> a -> r
apply1 UnitalChunk
QP.position UnitalChunk
QP.time) UnitalChunk
QP.time
{-
dd2descr :: Sentence
dd2descr = S "linear" +:+ (QP.displacement ^. term) +:+ S "of a" +:+
  ( rigidBody ^. term) +:+ S "as a function of" +:+ (QP.time ^. term) +:+ 
  ch QP.time +:+ sParen (Sy (unit_symb QP.time)) `sC`
  S "also equal to the derivative of its linear" +:+ (QP.position ^. term) +:+ 
  S "with respect to" +:+ (QP.time ^. term) +:+ ch QP.time
-}
-- DD3 : Linear velocity --

{-
linVelQDef :: Sentence
linVelQDef = foldl (+:+) (EmptyS) def
  where def = [phrase $ QP.linearVelocity ^. term, S "of a",
              phrase $ rigidBody ^. term, S "as a function of" ,
              phrase $ QP.time ^. term, QP.time,
              S "also equal to the derivative of its linear",
              phrase $ QP.velocity ^. term, S "with respect to",
              phrase $ QP.time ^. term, ch QP.time]
-}

linVelDD :: DataDefinition
linVelDD :: DataDefinition
linVelDD = ModelQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddMENoRefs ModelQDef
linVel Maybe Derivation
forall a. Maybe a
Nothing String
"linVel" [Sentence
rigidBodyAssump]

linVel :: ModelQDef
linVel :: ModelQDef
linVel = UnitalChunk -> ModelExpr -> ModelQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
QP.linearVelocity ModelExpr
velEqn

velEqn :: ModelExpr
velEqn :: ModelExpr
velEqn = ModelExpr -> UnitalChunk -> ModelExpr
forall c. (HasUID c, HasSymbol c) => ModelExpr -> c -> ModelExpr
forall r c. (ModelExprC r, HasUID c, HasSymbol c) => r -> c -> r
deriv (UnitalChunk -> UnitalChunk -> ModelExpr
forall r f a.
(ExprC r, HasUID f, HasSymbol f, HasUID a, HasSymbol a) =>
f -> a -> r
apply1 UnitalChunk
QP.displacement UnitalChunk
QP.time) UnitalChunk
QP.time
{-
dd3descr :: Sentence
dd3descr = S "linear" +:+ (QP.velocity ^. term) +:+ S "of a" +:+
  (rigidBody ^. term) +:+ S "as a function of" +:+ (QP.time ^. term) +:+ 
  ch QP.time +:+ sParen (Sy (unit_symb QP.time)) `sC`
  S "also equal to the derivative of its linear" +:+ (QP.velocity ^. term) +:+
  S "with respect to" +:+ (QP.time ^. term) +:+ ch QP.time
-}
-- DD4 : Linear acceleration --

linAccDD :: DataDefinition
linAccDD :: DataDefinition
linAccDD = ModelQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddMENoRefs ModelQDef
linAcc Maybe Derivation
forall a. Maybe a
Nothing String
"linAcc" [Sentence
rigidBodyAssump]

linAcc :: ModelQDef
linAcc :: ModelQDef
linAcc = UnitalChunk -> ModelExpr -> ModelQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
QP.linearAccel ModelExpr
accelEqn

accelEqn :: ModelExpr
accelEqn :: ModelExpr
accelEqn = ModelExpr -> UnitalChunk -> ModelExpr
forall c. (HasUID c, HasSymbol c) => ModelExpr -> c -> ModelExpr
forall r c. (ModelExprC r, HasUID c, HasSymbol c) => r -> c -> r
deriv (UnitalChunk -> UnitalChunk -> ModelExpr
forall r f a.
(ExprC r, HasUID f, HasSymbol f, HasUID a, HasSymbol a) =>
f -> a -> r
apply1 UnitalChunk
QP.velocity UnitalChunk
QP.time) UnitalChunk
QP.time
{-
dd4descr :: Sentence
dd4descr = S "linear" +:+ (accel ^. term) +:+ S "of a" +:+
  (rigidBody ^. term) +:+ S "as a function of" +:+ (QP.time ^. term) +:+ 
  ch QP.time +:+ sParen (Sy (unit_symb QP.time)) `sC`
  S "also equal to the derivative of its linear" +:+ (accel ^. term) +:+
  S "with respect to" +:+ (QP.time ^. term) +:+ ch QP.time
-}
-- DD5 : Angular displacement --

angDispDD :: DataDefinition
angDispDD :: DataDefinition
angDispDD = ModelQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddMENoRefs ModelQDef
angDisp Maybe Derivation
forall a. Maybe a
Nothing String
"angDisp" [Sentence
rigidTwoDAssump]

angDisp :: ModelQDef
angDisp :: ModelQDef
angDisp = UnitalChunk -> ModelExpr -> ModelQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
QP.angularDisplacement ModelExpr
angDispEqn

angDispEqn :: ModelExpr
angDispEqn :: ModelExpr
angDispEqn = ModelExpr -> UnitalChunk -> ModelExpr
forall c. (HasUID c, HasSymbol c) => ModelExpr -> c -> ModelExpr
forall r c. (ModelExprC r, HasUID c, HasSymbol c) => r -> c -> r
deriv (UnitalChunk -> UnitalChunk -> ModelExpr
forall r f a.
(ExprC r, HasUID f, HasSymbol f, HasUID a, HasSymbol a) =>
f -> a -> r
apply1 UnitalChunk
QM.orientation UnitalChunk
QP.time) UnitalChunk
QP.time
{-
dd5descr :: Sentence
dd5descr = (QP.angularDisplacement ^. term) +:+ S "of a" +:+
  (rigidBody ^. term) +:+ S "as a function of" +:+ (QP.time ^. term) +:+ 
  ch QP.time +:+ sParen (Sy (unit_symb QP.time)) `sC`
  S "also equal to the derivative of its" +:+ (QM.orientation ^. term) +:+
  S "with respect to" +:+ (QP.time ^. term) +:+ ch QP.time
-}
-- DD6 : Angular velocity --

angVelDD :: DataDefinition
angVelDD :: DataDefinition
angVelDD = ModelQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddMENoRefs ModelQDef
angVel Maybe Derivation
forall a. Maybe a
Nothing String
"angVel" [Sentence
rigidTwoDAssump]

angVel :: ModelQDef
angVel :: ModelQDef
angVel = UnitalChunk -> ModelExpr -> ModelQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
QP.angularVelocity ModelExpr
angVelEqn

angVelEqn :: ModelExpr
angVelEqn :: ModelExpr
angVelEqn = ModelExpr -> UnitalChunk -> ModelExpr
forall c. (HasUID c, HasSymbol c) => ModelExpr -> c -> ModelExpr
forall r c. (ModelExprC r, HasUID c, HasSymbol c) => r -> c -> r
deriv (UnitalChunk -> UnitalChunk -> ModelExpr
forall r f a.
(ExprC r, HasUID f, HasSymbol f, HasUID a, HasSymbol a) =>
f -> a -> r
apply1 UnitalChunk
QP.angularDisplacement UnitalChunk
QP.time) UnitalChunk
QP.time
{-
dd6descr :: Sentence
dd6descr = ((QP.angularVelocity ^. term)) +:+ S "of a" +:+
  (rigidBody ^. term) +:+ S "as a function of" +:+ (QP.time ^. term) +:+ 
  ch QP.time +:+ sParen (Sy (unit_symb QP.time)) `sC`
  S "also equal to the derivative of its" +:+ (QP.angularDisplacement ^. term) +:+
  S "with respect to" +:+ (QP.time ^. term) +:+ ch QP.time
-}
-- DD7 : Angular acceleration --
-----------------------------------DD8 Angular Acceleration-------------------
angAccelDD :: DataDefinition
angAccelDD :: DataDefinition
angAccelDD = ModelQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddMENoRefs ModelQDef
angAccel Maybe Derivation
forall a. Maybe a
Nothing String
"angAccel" [Sentence
rigidTwoDAssump]

angAccel :: ModelQDef
angAccel :: ModelQDef
angAccel = UnitalChunk -> ModelExpr -> ModelQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
QP.angularAccel ModelExpr
angAccelEqn

angAccelEqn :: ModelExpr
angAccelEqn :: ModelExpr
angAccelEqn = ModelExpr -> UnitalChunk -> ModelExpr
forall c. (HasUID c, HasSymbol c) => ModelExpr -> c -> ModelExpr
forall r c. (ModelExprC r, HasUID c, HasSymbol c) => r -> c -> r
deriv (UnitalChunk -> UnitalChunk -> ModelExpr
forall r f a.
(ExprC r, HasUID f, HasSymbol f, HasUID a, HasSymbol a) =>
f -> a -> r
apply1 UnitalChunk
QP.angularVelocity UnitalChunk
QP.time) UnitalChunk
QP.time

{-
dd7descr :: Sentence
dd7descr = (QP.angularAccel ^. term) +:+ S "of a" +:+
  (rigidBody ^. term) +:+ S "as a function of" +:+ (QP.time ^. term) +:+
  ch QP.time +:+ sParen (Sy (unit_symb QP.time)) `sC`
  S "also equal to the derivative of its" +:+ ((QP.angularVelocity ^. term)) +:+
  S "with respect to" +:+ (QP.time ^. term) +:+ ch QP.time
-}
-- DD8 : Impulse for collision response --

-- Currently a super crude implementation requiring lots of custom chunks;
-- need norms and cross products

-------------------------DD8 Impulse for Collision-------------------------------
--moved to GenDefs.hs

------------------------DD9 Chasles Theorem----------------------------------
chaslesDD :: DataDefinition
chaslesDD :: DataDefinition
chaslesDD = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
chasles [Citation -> DecRef
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
chaslesWiki] Maybe Derivation
forall a. Maybe a
Nothing String
"chaslesThm" 
  [Sentence
chaslesThmNote, Sentence
rigidBodyAssump]

chasles :: SimpleQDef
chasles :: SimpleQDef
chasles = UnitalChunk -> NP -> Expr -> SimpleQDef
forall c e.
(Quantity c, MayHaveUnit c) =>
c -> NP -> e -> QDefinition e
mkQuantDef' UnitalChunk
velB (String -> NP
nounPhraseSP String
"Chasles' theorem") Expr
chaslesEqn

-- The last two terms in the denominator should be cross products.
chaslesEqn :: Expr
chaslesEqn :: Expr
chaslesEqn = UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
velO Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$+ Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
cross (UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy  UnitalChunk
QP.angularVelocity) (UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
rOB)

chaslesThmNote :: Sentence
chaslesThmNote :: Sentence
chaslesThmNote = [Sentence] -> Sentence
foldlSent [NP -> Sentence
forall n. NounPhrase n => n -> Sentence
atStartNP (UnitalChunk -> NP
forall t. NamedIdea t => t -> NP
the UnitalChunk
QP.linearVelocity),
  UnitalChunk -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
velB Sentence -> Sentence -> Sentence
`S.of_` String -> Sentence
S String
"any point B in a", ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
rigidBody Sentence -> Sentence -> Sentence
`S.isThe` String -> Sentence
S String
"sum" Sentence -> Sentence -> Sentence
`S.ofThe`
  UnitalChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
QP.linearVelocity Sentence -> Sentence -> Sentence
+:+ UnitalChunk -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
velO Sentence -> Sentence -> Sentence
`S.ofThe` ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
rigidBody,
  String -> Sentence
S String
"at the origin (axis of rotation)" Sentence -> Sentence -> Sentence
`S.andThe` String -> Sentence
S String
"resultant vector from",
  String -> Sentence
S String
"cross product" Sentence -> Sentence -> Sentence
`S.the_ofThe` ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrasePoss ConceptChunk
rigidBody,
  UnitalChunk -> Sentence
forall a. Quantity a => a -> Sentence
getTandS UnitalChunk
QP.angularVelocity Sentence -> Sentence -> Sentence
`S.andThe` UnitalChunk -> Sentence
forall a. Quantity a => a -> Sentence
getTandS UnitalChunk
rOB]

---------------DD10 Impulse(Vector)-----------------------------------------------------------------------
impulseVDD :: DataDefinition
impulseVDD :: DataDefinition
impulseVDD = SimpleQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddENoRefs SimpleQDef
impulseV (Derivation -> Maybe Derivation
forall a. a -> Maybe a
Just Derivation
impulseVDeriv) String
"impulseV"
  [Sentence
impulseVDesc, Sentence
rigidBodyAssump]

impulseV :: SimpleQDef
impulseV :: SimpleQDef
impulseV = UnitalChunk -> Expr -> SimpleQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
QP.impulseV Expr
impulseVEqn

impulseVEqn :: Expr
impulseVEqn :: Expr
impulseVEqn = UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QPP.mass Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$* UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.chgInVelocity

impulseVDesc :: Sentence
impulseVDesc :: Sentence
impulseVDesc = [Sentence] -> Sentence
foldlSent [String -> Sentence
S String
"An", UnitalChunk -> Sentence
forall a. Quantity a => a -> Sentence
getTandS UnitalChunk
QP.impulseV, String -> Sentence
S String
"occurs when a",
  UnitalChunk -> Sentence
forall a. Quantity a => a -> Sentence
getTandS UnitalChunk
QP.force, String -> Sentence
S String
"acts over a body over an interval" Sentence -> Sentence -> Sentence
`S.of_` UnitalChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
QP.time]

impulseVDeriv :: Derivation
impulseVDeriv :: Derivation
impulseVDeriv = Sentence -> [Sentence] -> Derivation
mkDerivName (UnitalChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
QP.impulseV) ([[Sentence]] -> [Sentence]
forall a. [[a]] -> [a]
weave [[Sentence]
impulseVDerivSentences, (ModelExpr -> Sentence) -> [ModelExpr] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map ModelExpr -> Sentence
eS [ModelExpr]
impulseVDerivEqns])

impulseVDerivSentences :: [Sentence]
impulseVDerivSentences :: [Sentence]
impulseVDerivSentences = ([Sentence] -> Sentence) -> [[Sentence]] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map [Sentence] -> Sentence
foldlSentCol [[Sentence]
impulseVDerivSentence1, 
 [Sentence]
impulseVDerivSentence2, [Sentence]
impulseVDerivSentence3]  

impulseVDerivSentence1 :: [Sentence]
impulseVDerivSentence1 :: [Sentence]
impulseVDerivSentence1 = [String -> Sentence
S String
"Newton's second law of motion states"]

impulseVDerivSentence2 :: [Sentence]
impulseVDerivSentence2 :: [Sentence]
impulseVDerivSentence2 = [String -> Sentence
S String
"Rearranging"] 

impulseVDerivSentence3 :: [Sentence]
impulseVDerivSentence3 :: [Sentence]
impulseVDerivSentence3 = [String -> Sentence
S String
"Integrating the right hand side"]

-----------------DD11 Relative Velocity in Collision------------------------------------------------------- 
reVelInCollDD :: DataDefinition
reVelInCollDD :: DataDefinition
reVelInCollDD = SimpleQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddENoRefs SimpleQDef
reVelInColl Maybe Derivation
forall a. Maybe a
Nothing String
"reVeInColl"
  [Sentence
reVelInCollDesc, Sentence
rigidBodyAssump]

reVelInColl :: SimpleQDef
reVelInColl :: SimpleQDef
reVelInColl = UnitalChunk -> Expr -> SimpleQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
initRelVel Expr
reVelInCollEqn

reVelInCollEqn :: Expr
reVelInCollEqn :: Expr
reVelInCollEqn = UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
velAP Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
`vSub` UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
velBP

reVelInCollDesc :: Sentence
reVelInCollDesc :: Sentence
reVelInCollDesc = [Sentence] -> Sentence
foldlSent [String -> Sentence
S String
"In a collision, the", NP -> Sentence
forall n. NounPhrase n => n -> Sentence
phraseNP (UnitalChunk
QP.velocity
  UnitalChunk -> ConceptChunk -> NP
forall c d. (NamedIdea c, NamedIdea d) => c -> d -> NP
`ofA` ConceptChunk
rigidBody), String -> Sentence
S String
"A colliding with another", ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
rigidBody,
  String -> Sentence
S String
"B relative to that body", UnitalChunk -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
initRelVel Sentence -> Sentence -> Sentence
`S.isThe` String -> Sentence
S String
"difference between the",
  UnitalChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
plural UnitalChunk
QP.velocity, String -> Sentence
S String
"of A and B at point P"]
-----------------DD13 Torque-------------------------------------------------------------------------------

-- Imported from Theories.Physics

----------------------DD14 Coefficient of Restitution--------------------------
coeffRestitutionDD :: DataDefinition
coeffRestitutionDD :: DataDefinition
coeffRestitutionDD = SimpleQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddENoRefs SimpleQDef
coeffRestitution Maybe Derivation
forall a. Maybe a
Nothing String
"coeffRestitution"
 [Sentence
coeffRestitutionDesc]

coeffRestitution :: SimpleQDef
coeffRestitution :: SimpleQDef
coeffRestitution = DefinedQuantityDict -> Expr -> SimpleQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef DefinedQuantityDict
QP.restitutionCoef Expr
coeffRestitutionEqn

coeffRestitutionEqn :: Expr
coeffRestitutionEqn :: Expr
coeffRestitutionEqn = Expr -> Expr
forall r. ExprC r => r -> r
neg (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
finRelVel Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$.
  UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
normalVect Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$/ UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
initRelVel Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$.
  UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
normalVect

coeffRestitutionDesc :: Sentence
coeffRestitutionDesc :: Sentence
coeffRestitutionDesc = [Sentence] -> Sentence
foldlSent [String -> Sentence
S String
"The", DefinedQuantityDict -> Sentence
forall a. Quantity a => a -> Sentence
getTandS DefinedQuantityDict
QP.restitutionCoef,
  String -> Sentence
S String
"determines the elasticity" Sentence -> Sentence -> Sentence
`S.ofA` String -> Sentence
S String
"collision between two" Sentence -> Sentence -> Sentence
+:+. ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
plural ConceptChunk
rigidBody,
  SepType -> FoldType -> [Sentence] -> Sentence
foldlList SepType
Comma FoldType
List [
  ModelExpr -> Sentence
eS (DefinedQuantityDict -> ModelExpr
forall c. (HasUID c, HasSymbol c) => c -> ModelExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy DefinedQuantityDict
QP.restitutionCoef ModelExpr -> ModelExpr -> ModelExpr
forall r. ExprC r => r -> r -> r
$= Integer -> ModelExpr
forall r. LiteralC r => Integer -> r
exactDbl Integer
1) Sentence -> Sentence -> Sentence
+:+ String -> Sentence
S String
"results" Sentence -> Sentence -> Sentence
`S.in_` String -> Sentence
S String
"an elastic collision",
  ModelExpr -> Sentence
eS (DefinedQuantityDict -> ModelExpr
forall c. (HasUID c, HasSymbol c) => c -> ModelExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy DefinedQuantityDict
QP.restitutionCoef ModelExpr -> ModelExpr -> ModelExpr
forall r. ExprC r => r -> r -> r
$< Integer -> ModelExpr
forall r. LiteralC r => Integer -> r
exactDbl Integer
1) Sentence -> Sentence -> Sentence
+:+ String -> Sentence
S String
"results" Sentence -> Sentence -> Sentence
`S.in_` String -> Sentence
S String
"an inelastic collision",
  ModelExpr -> Sentence
eS (DefinedQuantityDict -> ModelExpr
forall c. (HasUID c, HasSymbol c) => c -> ModelExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy DefinedQuantityDict
QP.restitutionCoef ModelExpr -> ModelExpr -> ModelExpr
forall r. ExprC r => r -> r -> r
$= Integer -> ModelExpr
forall r. LiteralC r => Integer -> r
exactDbl Integer
0) Sentence -> Sentence -> Sentence
+:+ String -> Sentence
S String
"results" Sentence -> Sentence -> Sentence
`S.in_` String -> Sentence
S String
"a totally inelastic collision"]]
-----------------------DD15 Kinetic Energy--------------------------------  
kEnergyDD :: DataDefinition
kEnergyDD :: DataDefinition
kEnergyDD = SimpleQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddENoRefs SimpleQDef
kEnergy Maybe Derivation
forall a. Maybe a
Nothing String
"kEnergy"
 [Sentence
kEnergyDesc, Sentence
rigidTwoDAssump, Sentence
noDampingAssump] 

kEnergy :: SimpleQDef
kEnergy :: SimpleQDef
kEnergy = UnitalChunk -> Expr -> SimpleQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
QP.kEnergy Expr
kEnergyEqn

kEnergyEqn :: Expr
kEnergyEqn :: Expr
kEnergyEqn = UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QPP.mass Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$* Expr -> Expr
forall r. (ExprC r, LiteralC r) => r -> r
half (Expr -> Expr
forall r. (ExprC r, LiteralC r) => r -> r
square (Expr -> Expr
forall r. ExprC r => r -> r
norm (UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.velocity)))

kEnergyDesc :: Sentence
kEnergyDesc :: Sentence
kEnergyDesc = [Sentence] -> Sentence
foldlSent [UnitalChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
atStart UnitalChunk
QP.kEnergy Sentence -> Sentence -> Sentence
`S.is` (UnitalChunk
QP.kEnergy UnitalChunk -> Getting Sentence UnitalChunk Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence UnitalChunk Sentence
forall c. Definition c => Lens' c Sentence
Lens' UnitalChunk Sentence
defn)]
-----------------------DD16 Moment Of Inertia--------------------------------------------------------

momentOfInertiaDD :: DataDefinition
momentOfInertiaDD :: DataDefinition
momentOfInertiaDD = ModelQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddMENoRefs ModelQDef
momentOfInertia Maybe Derivation
forall a. Maybe a
Nothing String
"momentOfInertia"
 [Sentence
momentOfInertiaDesc, Sentence
rigidBodyAssump] 

momentOfInertia :: ModelQDef
momentOfInertia :: ModelQDef
momentOfInertia = UnitalChunk -> ModelExpr -> ModelQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
QP.momentOfInertia ModelExpr
momentOfInertiaEqn

momentOfInertiaEqn :: ModelExpr
momentOfInertiaEqn :: ModelExpr
momentOfInertiaEqn = Symbol -> ModelExpr -> ModelExpr
forall r. ModelExprC r => Symbol -> r -> r
sumAll (String -> Symbol
variable String
"j") (ModelExpr -> ModelExpr) -> ModelExpr -> ModelExpr
forall a b. (a -> b) -> a -> b
$ UnitalChunk -> ModelExpr
forall c. (HasUID c, HasSymbol c) => c -> ModelExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
massj ModelExpr -> ModelExpr -> ModelExpr
forall r. ExprC r => r -> r -> r
$* ModelExpr -> ModelExpr
forall r. (ExprC r, LiteralC r) => r -> r
square (UnitalChunk -> ModelExpr
forall c. (HasUID c, HasSymbol c) => c -> ModelExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
rRot)

momentOfInertiaDesc :: Sentence
momentOfInertiaDesc :: Sentence
momentOfInertiaDesc = [Sentence] -> Sentence
foldlSent [String -> Sentence
S String
"The", UnitalChunk -> Sentence
forall a. Quantity a => a -> Sentence
getTandS UnitalChunk
QP.momentOfInertia,
 String -> Sentence
S String
"of a body measures how much", UnitalChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
QP.torque,
 String -> Sentence
S String
"is needed" Sentence -> Sentence -> Sentence
`S.for` String -> Sentence
S String
"the body to achieve angular acceleration about the axis of rotation"]

---------------------------DD17 Potential Energy-------------------------------------------

potEnergyDD :: DataDefinition
potEnergyDD :: DataDefinition
potEnergyDD = SimpleQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddENoRefs SimpleQDef
potEnergy Maybe Derivation
forall a. Maybe a
Nothing String
"potEnergy"
 [Sentence
potEnergyDesc, Sentence
rigidTwoDAssump, Sentence
noDampingAssump] 

potEnergy :: SimpleQDef
potEnergy :: SimpleQDef
potEnergy = UnitalChunk -> Expr -> SimpleQDef
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
QP.potEnergy Expr
potEnergyEqn

potEnergyEqn :: Expr
potEnergyEqn :: Expr
potEnergyEqn = UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QPP.mass Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$* UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.gravitationalAccel Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$* UnitalChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
QP.height

potEnergyDesc :: Sentence
potEnergyDesc :: Sentence
potEnergyDesc = [Sentence] -> Sentence
foldlSent [NP -> Sentence
forall n. NounPhrase n => n -> Sentence
atStartNP (UnitalChunk -> NP
forall t. NamedIdea t => t -> NP
the UnitalChunk
QP.potEnergy) Sentence -> Sentence -> Sentence
`S.of_`
  String -> Sentence
S String
"an object" Sentence -> Sentence -> Sentence
`S.isThe` UnitalChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
QP.energy, String -> Sentence
S String
"held by an object because of its",
  UnitalChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
QP.position, String -> Sentence
S String
"to other objects"]

---

collisionAssump, noDampingAssump, rightHandAssump, rigidBodyAssump, rigidTwoDAssump :: Sentence
collisionAssump :: Sentence
collisionAssump = String -> Sentence
S String
"All collisions" Sentence -> Sentence -> Sentence
`S.are` String -> Sentence
S String
"vertex-to-edge" Sentence -> Sentence -> Sentence
+:+. ConceptInstance -> Sentence
forall r. (Referable r, HasShortName r) => r -> Sentence
fromSource ConceptInstance
assumpCT
noDampingAssump :: Sentence
noDampingAssump = String -> Sentence
S String
"No damping occurs during the simulation" Sentence -> Sentence -> Sentence
+:+. ConceptInstance -> Sentence
forall r. (Referable r, HasShortName r) => r -> Sentence
fromSource ConceptInstance
assumpDI
rightHandAssump :: Sentence
rightHandAssump = String -> Sentence
S String
"A" Sentence -> Sentence -> Sentence
+:+ ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
rightHand Sentence -> Sentence -> Sentence
`S.is` String -> Sentence
S String
"used" Sentence -> Sentence -> Sentence
+:+. ConceptInstance -> Sentence
forall r. (Referable r, HasShortName r) => r -> Sentence
fromSource ConceptInstance
assumpAD
rigidBodyAssump :: Sentence
rigidBodyAssump = String -> Sentence
S String
"All bodies are assumed to be rigid" Sentence -> Sentence -> Sentence
+:+. ConceptInstance -> Sentence
forall r. (Referable r, HasShortName r) => r -> Sentence
fromSource ConceptInstance
assumpOT
rigidTwoDAssump :: Sentence
rigidTwoDAssump = [Sentence] -> Sentence
foldlSent [String -> Sentence
S String
"All bodies are assumed to be rigid",
  ConceptInstance -> Sentence
forall r. (Referable r, HasShortName r) => r -> Sentence
fromSource ConceptInstance
assumpOT Sentence -> Sentence -> Sentence
`S.and_` CI -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase CI
twoD, ConceptInstance -> Sentence
forall r. (Referable r, HasShortName r) => r -> Sentence
fromSource ConceptInstance
assumpOD]