Contains function. These are
dimnames
consistent?
(:require [diman.analyze :refer [dimnames consistent?]])
Consider the case
(def varpars [{:symbol "x", :dimension "length"},
{:symbol "v", :dimension "velocity"}
{:symbol "t", :dimension "time"}
{:symbol "a", :dimension "acceleration"}])
(def lhs "x^(1)")
(def rhs {:term1 "x^(1)", :term2 "v^(2)", :term3 "t^(1)", :term4 "0.5*a^(1)*t^(2)"})
(def eqn {:lhs lhs, :rhs rhs})
Then using (require '[diman.formula :refer [formula-term formula-eqn-side]])
The formula for the right hand side of the equation is
=> (formula-eqn-side varpars rhs)
"[L^(1)] + [T^(-2)*M^(0)*L^(2)] + [T^(1)] + [T^(0)*M^(0)*L^(1)]"
The rhs of our example equation as dimension names is
=> (dimnames (formula-eqn-side varpars rhs))
"length^(1) + length^(1) + length^(1)"
and for lhs
=> (dimnames (formula-eqn-side varpars lhs))
"length^(1)"
Notice that names of the dimensions with exponent value = 0 is not seen.
To check if the lhs and rhs of the dimensional formula are the same do
=> (consistent? varpars eqn)
true
Contains function. These are - `dimnames` - `consistent?` ## How to use ### Loading ``` (:require [diman.analyze :refer [dimnames consistent?]]) ``` ### Examples Consider the case ``` (def varpars [{:symbol "x", :dimension "length"}, {:symbol "v", :dimension "velocity"} {:symbol "t", :dimension "time"} {:symbol "a", :dimension "acceleration"}]) (def lhs "x^(1)") (def rhs {:term1 "x^(1)", :term2 "v^(2)", :term3 "t^(1)", :term4 "0.5*a^(1)*t^(2)"}) (def eqn {:lhs lhs, :rhs rhs}) ``` Then using ```(require '[diman.formula :refer [formula-term formula-eqn-side]])``` The formula for the right hand side of the equation is ``` => (formula-eqn-side varpars rhs) "[L^(1)] + [T^(-2)*M^(0)*L^(2)] + [T^(1)] + [T^(0)*M^(0)*L^(1)]" ``` #### Dimension names of an equation side The rhs of our example equation as dimension names is ``` => (dimnames (formula-eqn-side varpars rhs)) "length^(1) + length^(1) + length^(1)" ``` and for lhs ``` => (dimnames (formula-eqn-side varpars lhs)) "length^(1)" ``` Notice that names of the dimensions with exponent value = 0 is not seen. #### Consistency check To check if the lhs and rhs of the dimensional formula are the same do ``` => (consistent? varpars eqn) true ```
Contains function. These are:
tie-notn-expt
tie-subformula-expt
tie-notnlist-exptlist
tie-ref-with-distinct-next
tie-subformulae-in-term
tie-subformulae-in-eqn-side
tie-names-in-subformula
(:require [diman.attach :refer :all])
For notation [M]
with exponent 2
=> (tie-notn-expt "[M]" "2")
"M^(2)"
which is a formula with just one component, M^(2)
.
Consider the expression v^2
where variable/parameter v
stands for velocity with
the standard formula [M^(0)*L^(1)*T^(-1)]
. To attach the exponent (= 2) of v
to
its standard formula is to multiply all the exponents of the notations contained in
the standard formula
=> (tie-subformula-expt "[M^(0)*L^(1)*T^(-1)]" "2")
"[M^(0.0)*L^(2.0)*T^(-2.0)]"
NOTE:
tie-subformula-expt
is for all practical purpose multiplying exponents of all the
notations in the formula by the desired exponent value.allexpt-times-expt
in diman.exponents
but unlike it
tie-subformula-expt
returns the same form of the formula (say, standard formula) but
with exponents changed while allexpt-times-expt
only returns the list of changed exponents.For a list [("M" "L" "T") ("0" "1" "-2")]
defined in x
its formula is
=> (tie-notnlist-exptlist x)
"[M^(0)*L^(1)*T^(-2)]"
NOTE:
list-varpar-expt
(in diman.filter
namespace)lform = [form1 form2 from3 ...]
to get the
list of notation and exponents of form1
you get x
from
(list-varpar-expt (remove-brackets (first lform)))
Given an expression (lhs or rhs of the equation), let us assume that a variable/parameter for the defined problem has a formula representation. An expression is composed of subexpressions separated by + sign. We shall refer to each subexpression as a term.
As a general convention formula for each term is referred here as a sub-formula. The sub-formula will be the result of the term regardless of the number of variable/parameter. A sub-formula consists of components which themselves are made up of the base notations. The number of components in a sub-formula resulting from a term with one variable/parameter will be the number of base notations in the sub-formula.
However, if the sub-formula is a result of a term with more than one variable/parameter then each formula resulting from respective variable/parameter is referred to as the supra-component. A supra-component consists of components made up of base notations.
A term with one variable/parameter will have only one supra-component or sub-formula (dimensional formula of the variable/parameter). A term with n variable/parameters will have n supra-components in one sub-formula. In such cases, the sub-formula of the term is the union of supra-components.
For the example of the term whose list of sub-formulae is
(def lform '("[M^(0)*L^(1)*T^(-2)]" "[A^(1)*T^(2)]" "[cd]^(0)*[mol]^(-2)]"))
"[M^(0)*L^(1)*T^(-2)]" is taken as the reference sub-formula because it is the longest.
Looking at "[A^(1)*T^(2)]"
the notation common with the reference is T
so
=> (tie-ref-with-distinct-next (first lform) (second lform) "[T^(2)]")
"[T^(-2)*M^(0)*L^(1)*A^(1)]"
Considering "[cd]^(0)*[mol]^(-2)]"
since there are nil
notations in common with
the reference
=> (tie-ref-with-distinct-next (first lform) (last lform) nil)
"[T^(-2)*mol^(-2)*M^(0)*cd^(0)*L^(1)]"
Also notice that tying with itself (reference subformula) will return itself
=> (tie-ref-with-distinct-next (first lform1) (first lform1) nil)
"[T^(-2)*M^(0)*L^(1)]"
Therefore, this function returns a sub-formula comprising all the distinct components among the sub-formulae resulting from the variable/parameter.
The sub-formulae of a term or expression will normally have notations and hence components that are in common to the sub-formulae generated from the variable/parameter defined in the expression. Therefore, to obtain the sub-formula of a term or an expression comprised of just one term the first step is to create a sub-formula composed of distinct components.
Given the list of sub-formulae defined above
=> lform
("[M^(0)*L^(1)*T^(-2)]" "[A^(1)*T^(2)]" "[cd]^(0)*[mol]^(-2)]")
with the reference sub-formula "[M^(0)*L^(1)*T^(-2)]"
, notice that there are
other sub-formula in the list that have components with same notation as in the
reference sub-formula. Here, it is T^(2)
. Also, although it is represented as a
list the sub-formulae have the multiplication operator between them. With this
knowledge and the law of exponents the updated reference sub-formula is
"[M^(0)*L^(1)*T^(0)]"
Then the formula of the term is its tied sub-formulae
=> (tie-subformulae-in-term lform "[M^(0)*L^(1)*T^(0)]")
"[mol^(-2)*T^(0)*M^(0)*cd^(0)*L^(1)*A^(1)]"
Notice that this function ties up the updated reference sub-formula with distinct components in the rest of the sub-formulae; note distinct relative to the reference.
In the context of formula for a side of the equation the formulae of each of term
are its sub-formulae. These then can be tied up using tie-subformulae-in-eqn-side
.
Therefore, if the right hand side of the equation is
(def rhs {:term1 "x^(1)", :term2 "v^(2)", :term3 "t^(1)", :term4 "0.5*a^(1)*t^(2)"})
resulting in its corresponding sub-formulae
("[L^(1)]" "[T^(-2)*M^(0)*L^(2)]" "[T^(1)]" "[T^(0)*M^(0)*L^(1)]")
Then when tied up we get
=> (tie-subformulae-in-eqn-side '("[L^(1)]" "[T^(-2)*M^(0)*L^(2)]" "[T^(1)]" "[T^(0)*M^(0)*L^(1)]"))
"[L^(1)] + [T^(-2)*M^(0)*L^(2)] + [T^(1)] + [T^(0)*M^(0)*L^(1)]"
NOTE: Unlike tying of sub-formulae for getting the term formula, sub-formulae tying for the equation side does not perform exponent operation. This is because for the case of equation side the sub-formulae are separated by the addition operator.
To have a more readable view of the sub-formula of the term
=> (tie-subformulae-in-term lform "[M^(0)*L^(1)*T^(0)]")
"[mol^(-2)*T^(0)*M^(0)*cd^(0)*L^(1)*A^(1)]"
you can call tie-names-in-subformula
as
=> (tie-names-in-subformula "[mol^(-2)*T^(0)*M^(0)*cd^(0)*L^(1)*A^(1)]")
"amount of substance^(-2)*length^(1)*electric current^(1)"
Notice that names of the dimensions with exponent value = 0 is not shown. If it were it would have appeared as
"amount of substance^(-2)*time^(0)*mass^(0)*luminous intensity^(0)*length^(1)*electric current^(1)"
Contains function. These are: - `tie-notn-expt` - `tie-subformula-expt` - `tie-notnlist-exptlist` - `tie-ref-with-distinct-next` - `tie-subformulae-in-term` - `tie-subformulae-in-eqn-side` - `tie-names-in-subformula` ## How to use ### Loading ``` (:require [diman.attach :refer :all]) ``` ### Examples #### Attaching an exponent to one of seven fundamental notations For notation `[M]` with exponent 2 ``` => (tie-notn-expt "[M]" "2") "M^(2)" ``` which is a formula with just one component, `M^(2)`. #### Attach exponent of a variable/parameter in the expression Consider the expression `v^2` where variable/parameter `v` stands for velocity with the standard formula `[M^(0)*L^(1)*T^(-1)]`. To attach the exponent (= 2) of `v` to its standard formula is to multiply all the exponents of the notations contained in the standard formula ``` => (tie-subformula-expt "[M^(0)*L^(1)*T^(-1)]" "2") "[M^(0.0)*L^(2.0)*T^(-2.0)]" ``` **NOTE**: - `tie-subformula-expt` is for all practical purpose multiplying exponents of all the notations in the formula by the desired exponent value. - it is similar to `allexpt-times-expt` in `diman.exponents` but unlike it `tie-subformula-expt` returns the same form of the formula (say, standard formula) but with exponents changed while `allexpt-times-expt` only returns the list of changed exponents. #### Attach list of notation and its corresponding list of exponents For a list `[("M" "L" "T") ("0" "1" "-2")]` defined in `x` its formula is ``` => (tie-notnlist-exptlist x) "[M^(0)*L^(1)*T^(-2)]" ``` **NOTE**: - the list of notation and its exponents is usually that of a sub-formula, that is, formula of variable/parameter in a term comprised of >= variable/parameter - the list can be obtained using the `list-varpar-expt` (in `diman.filter` namespace) - for a list of sub-formulae = `lform = [form1 form2 from3 ...]` to get the list of notation and exponents of `form1` you get `x` from `(list-varpar-expt (remove-brackets (first lform)))` #### Attach distinct components in next sub-formula to the reference sub-formula Given an expression (lhs or rhs of the equation), let us assume that a variable/parameter for the defined problem has a formula representation. An expression is composed of subexpressions separated by **+** sign. We shall refer to each subexpression as a **term**. As a general convention formula for each term is referred here as a **sub-formula**. The sub-formula will be the result of the term regardless of the number of variable/parameter. A sub-formula consists of __components which themselves are made up of the base notations.__ The number of components in a sub-formula resulting from a term with one variable/parameter will be the number of base notations in the sub-formula. However, if the sub-formula is a result of a term with more than one variable/parameter then each formula resulting from respective variable/parameter is referred to as the **supra-component**. A supra-component consists of components made up of base notations. A term with one variable/parameter will have only one supra-component or sub-formula (dimensional formula of the variable/parameter). A term with __n__ variable/parameters will have __n__ supra-components in **one** sub-formula. In such cases, the sub-formula of the term is the union of supra-components. For the example of the term whose list of sub-formulae is `(def lform '("[M^(0)*L^(1)*T^(-2)]" "[A^(1)*T^(2)]" "[cd]^(0)*[mol]^(-2)]"))` "[M^(0)*L^(1)*T^(-2)]" is taken as the reference sub-formula because it is the longest. Looking at `"[A^(1)*T^(2)]"` the notation common with the reference is `T` so ``` => (tie-ref-with-distinct-next (first lform) (second lform) "[T^(2)]") "[T^(-2)*M^(0)*L^(1)*A^(1)]" ``` Considering `"[cd]^(0)*[mol]^(-2)]"` since there are `nil` notations in common with the reference ``` => (tie-ref-with-distinct-next (first lform) (last lform) nil) "[T^(-2)*mol^(-2)*M^(0)*cd^(0)*L^(1)]" ``` Also notice that tying with itself (reference subformula) will return itself ``` => (tie-ref-with-distinct-next (first lform1) (first lform1) nil) "[T^(-2)*M^(0)*L^(1)]" ``` Therefore, this function returns a sub-formula comprising all the distinct components among the sub-formulae resulting from the variable/parameter. #### Tying the sub-formulae of a term to get the **term formula** The sub-formulae of a term or expression will normally have notations and hence components that are in common to the sub-formulae generated from the variable/parameter defined in the expression. Therefore, to obtain the sub-formula of a term or an expression comprised of just one term the first step is to create a sub-formula composed of distinct components. Given the list of sub-formulae defined above ``` => lform ("[M^(0)*L^(1)*T^(-2)]" "[A^(1)*T^(2)]" "[cd]^(0)*[mol]^(-2)]") ``` with the reference sub-formula `"[M^(0)*L^(1)*T^(-2)]"`, notice that there are other sub-formula in the list that have components with same notation as in the reference sub-formula. Here, it is `T^(2)`. Also, although it is represented as a list the sub-formulae have the multiplication operator between them. With this knowledge and the law of exponents the updated reference sub-formula is ``` "[M^(0)*L^(1)*T^(0)]" ``` Then the formula of the term is its tied sub-formulae ``` => (tie-subformulae-in-term lform "[M^(0)*L^(1)*T^(0)]") "[mol^(-2)*T^(0)*M^(0)*cd^(0)*L^(1)*A^(1)]" ``` Notice that this function ties up the updated reference sub-formula with distinct components in the rest of the sub-formulae; note distinct relative to the reference. #### Tying the sub-formulae of an equation side to get its **formula** In the context of formula for a side of the equation the formulae of each of term are its sub-formulae. These then can be tied up using `tie-subformulae-in-eqn-side`. Therefore, if the right hand side of the equation is ``` (def rhs {:term1 "x^(1)", :term2 "v^(2)", :term3 "t^(1)", :term4 "0.5*a^(1)*t^(2)"}) ``` resulting in its corresponding sub-formulae ``` ("[L^(1)]" "[T^(-2)*M^(0)*L^(2)]" "[T^(1)]" "[T^(0)*M^(0)*L^(1)]") ``` Then when tied up we get ``` => (tie-subformulae-in-eqn-side '("[L^(1)]" "[T^(-2)*M^(0)*L^(2)]" "[T^(1)]" "[T^(0)*M^(0)*L^(1)]")) "[L^(1)] + [T^(-2)*M^(0)*L^(2)] + [T^(1)] + [T^(0)*M^(0)*L^(1)]" ``` NOTE: Unlike tying of sub-formulae for getting the term formula, sub-formulae tying for the equation side does not perform exponent operation. This is because for the case of equation side the sub-formulae are separated by the addition operator. #### Tying dimension names in a sub-formula To have a more readable view of the sub-formula of the term ``` => (tie-subformulae-in-term lform "[M^(0)*L^(1)*T^(0)]") "[mol^(-2)*T^(0)*M^(0)*cd^(0)*L^(1)*A^(1)]" ``` you can call `tie-names-in-subformula` as ``` => (tie-names-in-subformula "[mol^(-2)*T^(0)*M^(0)*cd^(0)*L^(1)*A^(1)]") "amount of substance^(-2)*length^(1)*electric current^(1)" ``` Notice that names of the dimensions with exponent value = 0 is not shown. If it were it would have appeared as ``` "amount of substance^(-2)*time^(0)*mass^(0)*luminous intensity^(0)*length^(1)*electric current^(1)" ```
Contains definitions and their getters. These are:
base_dimensions
standard_formula
grab-notation
and grab-name
from base-dimensions
grab-sformula
from standard-formula
notation?
matched-notation-sformula
update-sformula
(require '[diman.dimensions :refer [base_dimensions standard_formula
grab-notation grab-name grab-sformula
notation? matched-notation-sformula]])
(pprint bas e_dimensions)
=> (grab-notation "mass")
"[M]"
=> (grab-name "[M]")
"mass"
(pprint standard_formula)
=> (grab-sformula "acceleration")
"[L^(1)*T^(-2)]"
Notice that a formula in standard_formula
is a dimensional formula and hence as a consequence a dimension.
Let us define symbol x, v, t and a representing a combination of variables and parameters as
(def varpars [{:symbol "x", :quantity "length"}
{:symbol "v", :quantity "velocity"}
{:symbol "t", :quantity "time"}
{:symbol "a", :quantity "acceleration"}])
Then based on the dimensions defined for respective symbol use
=> (matched-notation-sformula varpars "x")
"[L]"
=> (matched-notation-sformula varpars "a")
"[L^(1)*T^(-2)]"
NOTE:
:symbol
:dimension
whose value must be a string corresponding to either
:name
values, i.e, one of the seven fundamental dimensionsquantity
values, i.e, one of the standard formulaeContains definitions and their getters. These are: - `base_dimensions` - `standard_formula` - `grab-notation` and `grab-name` from `base-dimensions` - `grab-sformula` from `standard-formula` - `notation?` - `matched-notation-sformula` - `update-sformula` ## How to use ### Loading ``` (require '[diman.dimensions :refer [base_dimensions standard_formula grab-notation grab-name grab-sformula notation? matched-notation-sformula]]) ``` ### Examples #### View the seven fundamental dimensions `(pprint bas e_dimensions)` #### Get notation for the base dimension name "mass" ``` => (grab-notation "mass") "[M]" ``` #### Get base dimension name for notation "[M]" ``` => (grab-name "[M]") "mass" ``` #### View available standard formula `(pprint standard_formula)` #### Get formula of a quantity in the standard formula ``` => (grab-sformula "acceleration") "[L^(1)*T^(-2)]" ``` Notice that a formula in `standard_formula` is a dimensional formula and hence as a consequence a dimension. #### Get matching notation/standard formula of a defined symbol Let us define symbol *x*, *v*, *t* and *a* representing a combination of variables and parameters as ``` (def varpars [{:symbol "x", :quantity "length"} {:symbol "v", :quantity "velocity"} {:symbol "t", :quantity "time"} {:symbol "a", :quantity "acceleration"}]) ``` Then based on the dimensions defined for respective symbol use ``` => (matched-notation-sformula varpars "x") "[L]" => (matched-notation-sformula varpars "a") "[L^(1)*T^(-2)]" ``` NOTE: * definition of any __single letter__ symbol must be a value to key `:symbol` * and must also have the key `:dimension` whose value must be a string corresponding to either - one of the seven `:name` values, i.e, one of the seven fundamental dimensions - one of the `quantity` values, i.e, one of the standard formulae
Contains functions. These are:
allexpt-times-expt
ref-expt-plus-expt-allmatch
(:require [diman.exponents :refer [allexpt-times-expt
ref-expt-plus-expt-allmatch]])
For (def subform1 "[M^(2)]")
, to square it, ie., perform "[M^(2)]^2"
=> (allexpt-times-expt subform1 "2")
("4.0")
For (def subform2 "[M^(2/3)*cd^(1)*mol^(-2)]")
with exponent "(2)")
=> (allexpt-times-expt subform2 "3")
("2.0" "3.0" "-6.0")
NOTE:
For an expression (def expr "0.5*a^(1)*t^(2)")
resulting in a
dimensional formula with components "[M^(0)*L^(1)*T^(-2)]"
and "[T^(2)]"
.
The 'longer' sub-formula is taken as the reference. Since all its components are
separated by the multiplier *
operator any exponents of common notations must be
added. That is, "[M^(0)*L^(1)*T^(-2)] * [T^(2)] = [M^(0)*L^(1)*T^(-2+2)]"
.
Thus, for list of sub-formulae(def lform '("[M^(0)*L^(1)*T^(-2)]" "[T^(2)]")
=> (ref-expt-plus-expt-allmatch (first formcomps) (last formcomps))
[("M" "L" "T") ("0" "1" "0")]
returns a list of notations which is the same as the original reference sub-formula (first argument) but updated exponent values as a result of adding the exponents in in components with common notations in the next sub-formula (second argument).
Contains functions. These are: - `allexpt-times-expt` - `ref-expt-plus-expt-allmatch` ## How to use ### Loading ``` (:require [diman.exponents :refer [allexpt-times-expt ref-expt-plus-expt-allmatch]]) ``` ### Examples #### Taking exponent of all the notations within a sub-formula For `(def subform1 "[M^(2)]")`, to square it, ie., perform "[M^(2)]^2" ``` => (allexpt-times-expt subform1 "2") ("4.0") ``` For `(def subform2 "[M^(2/3)*cd^(1)*mol^(-2)]")` with exponent "(2)") ``` => (allexpt-times-expt subform2 "3") ("2.0" "3.0" "-6.0") ``` **NOTE**: - Function returns a list of exponents - list length of corresponds to the number of notations in the expression #### Adding exponents among components with same notations For an expression `(def expr "0.5*a^(1)*t^(2)")` resulting in a dimensional formula with components `"[M^(0)*L^(1)*T^(-2)]"` and `"[T^(2)]"`. The 'longer' sub-formula is taken as the reference. Since all its components are separated by the multiplier `*` operator any exponents of common notations must be added. That is, `"[M^(0)*L^(1)*T^(-2)] * [T^(2)] = [M^(0)*L^(1)*T^(-2+2)]"`. Thus, for list of sub-formulae`(def lform '("[M^(0)*L^(1)*T^(-2)]" "[T^(2)]")` ``` => (ref-expt-plus-expt-allmatch (first formcomps) (last formcomps)) [("M" "L" "T") ("0" "1" "0")] ``` returns a list of notations which is the same as the original reference sub-formula (first argument) but updated exponent values as a result of adding the exponents in in components with common notations in the next sub-formula (second argument).
Contains functions. These are:
list-varpar-expt
notns-in-subformula
expts-in-subformula
names-in-subformula
next-subformula-components-with-common-notation
remove-zero-powers
(require '[diman.filter :refer [list-varpar-expt notns-in-subformula
expts-in-subformula names-in-subformula
next-subformula-components-with-common-notation
remove-zero-powers]])
Given an expression
(def expr "0.5*a^(1)*t^(2)")
the variable/parameter and corresponding exponents can be filtered out as
=> (list-varpar-expt expr)
[("a" "t") ("1" "2")]
A sub-formula (special case of dimensional formula)
(def subform1 "[M^(0)*L^(1)*T^(-2)]")
is also an expression. Therefore,
=> (list-varpar-expt "M^(0)*L^(1)*T^(-2)")
[("M" "L" "T") ("0" "1" "-2")]
Similarly, for (def subform2 "[M^(2/3)*cd^(1)*mol^(-2)]")
=> (list-varpar-expt (remove-brackets subform2))
[("M" "cd" "mol") ("2/3" "1" "-2")]
For the same subform2
defined above
=> (notns-in-subformula subform2)
("M" "cd" "mol")
and
=> (expts-in-subformula subform2)
("2/3" "1" "-2")
The names of the notations are
=> (names-in-subformula subform2)
("mass" "luminous intensity" "amount of substance")
For (def lsubform '("[M^(0)*L^(1)*T^(-2)]" "[A^(1)*T^(2)]" "[cd]^(0)*[mol]^(-2)]"))
consider "[M^(0)*L^(1)*T^(-2)]"
to be the reference sub-formula (because it has the
largest number of unique notations). Component in the next sub-formula "[A^(1)*T^(2)]"
with common notation is given in formula representation as
=> (next-subformula-components-with-common-notation (first lsubform) (second lsubform))
"[T^(2)]"
and if "[cd]^(0)*[mol]^(-2)]"
is the next component
=> (next-subformula-components-with-common-notation (first lsubform) (last lsubform))
nil
and with itself
=> (next-subformula-components-with-common-notation (first lsubform) (first lsubform))
nil
For (def subformula "[T^(0)*L^(1)]")
and
(def formula "[L^(1)] + [T^(-2)*L^(2)] + [T^(1)] + [T^(0)*L^(1)]")
their reduced forms are
=> (remove-zero-powers subformula)
"[L^(1)]"
and
=> (remove-zero-powers formula)
"[L^(1)] + [T^(-2)*L^(2)] + [T^(1)] + [L^(1)]"
Contains functions. These are: - `list-varpar-expt` - `notns-in-subformula` - `expts-in-subformula` - `names-in-subformula` - `next-subformula-components-with-common-notation` - `remove-zero-powers` ## How to use ### Loading ``` (require '[diman.filter :refer [list-varpar-expt notns-in-subformula expts-in-subformula names-in-subformula next-subformula-components-with-common-notation remove-zero-powers]]) ``` ### Examples #### Filter out the variable/parameter and its exponents separately Given an expression ```(def expr "0.5*a^(1)*t^(2)")``` the variable/parameter and corresponding exponents can be filtered out as ``` => (list-varpar-expt expr) [("a" "t") ("1" "2")] ``` #### Filtering out one of the seven fundamental notations and its exponents A sub-formula (special case of dimensional formula) ```(def subform1 "[M^(0)*L^(1)*T^(-2)]")``` is also an expression. Therefore, ``` => (list-varpar-expt "M^(0)*L^(1)*T^(-2)") [("M" "L" "T") ("0" "1" "-2")] ``` Similarly, for `(def subform2 "[M^(2/3)*cd^(1)*mol^(-2)]")` ``` => (list-varpar-expt (remove-brackets subform2)) [("M" "cd" "mol") ("2/3" "1" "-2")] ``` #### Filter out the notations, notations names in a sub-formula and also its corresponding exponents For the same `subform2` defined above ``` => (notns-in-subformula subform2) ("M" "cd" "mol") ``` and ``` => (expts-in-subformula subform2) ("2/3" "1" "-2") ``` The names of the notations are ``` => (names-in-subformula subform2) ("mass" "luminous intensity" "amount of substance") ``` #### Filter out recurring notation of component/s in next sub-formula w.r.t reference sub-formula For `(def lsubform '("[M^(0)*L^(1)*T^(-2)]" "[A^(1)*T^(2)]" "[cd]^(0)*[mol]^(-2)]"))` consider `"[M^(0)*L^(1)*T^(-2)]"` to be the reference sub-formula (because it has the largest number of unique notations). Component in the next sub-formula `"[A^(1)*T^(2)]"` with common notation is given in formula representation as ``` => (next-subformula-components-with-common-notation (first lsubform) (second lsubform)) "[T^(2)]" ``` and if `"[cd]^(0)*[mol]^(-2)]"` is the next component ``` => (next-subformula-components-with-common-notation (first lsubform) (last lsubform)) nil ``` and with itself ``` => (next-subformula-components-with-common-notation (first lsubform) (first lsubform)) nil ``` #### Filtering out base notations having zero exponents in a sub-formula or the formula for a side of the equation. For `(def subformula "[T^(0)*L^(1)]")` and `(def formula "[L^(1)] + [T^(-2)*L^(2)] + [T^(1)] + [T^(0)*L^(1)]")` their reduced forms are ``` => (remove-zero-powers subformula) "[L^(1)]" ``` and ``` => (remove-zero-powers formula) "[L^(1)] + [T^(-2)*L^(2)] + [T^(1)] + [L^(1)]" ```
Contains function. These are:
formula-term
formula-eqn-side
formula-eqn-side-manifold
(require '[diman.formula :refer [formula-term formula-eqn-side formula-eqn-side-manifold]])
Given
(def varpars [{:symbol "x", :quantity "length"}
{:symbol "v", :quantity "velocity"}
{:symbol "t", :quantity "time"}
{:symbol "a", :quantity "acceleration"}])
(def lhs "x^(1)")
(def rhs {:term1 "x^(1)", :term2 "v^(2)", :term3 "t^(1)", :term4 "0.5*a^(1)*t^(2)"})
(def eqn {:lhs lhs, :rhs rhs})
To get the formula of a term, say, (:term4 rhs)
=> (formula-term varpars (:term4 rhs))
"[T^(0)*L^(1)]"
and for left hand side
=> (formula-term varpars lhs)
"[L^(1)]"
For right hand side
=> (formula-eqn-side varpars rhs)
"[L^(1)] + [T^(-2)*L^(2)] + [T^(1)] + [T^(0)*L^(1)]"
for left hand side
=> (formula-eqn-side varpars lhs)
"[L^(1)]"
Lets say we have two different equations
(def p_leftside "p^(1)")
(def p_rightside {:term1 "x^(2)*v^(-1)*t^(1)"})
(def p_equation {:lhs p_leftside, :rhs p_rightside})
and
(def q_leftside "q^(1)")
(def q_rightside {:term1 "x^(1)*a^(6)*t^(20)"})
(def q_equation {:lhs q_leftside, :rhs q_rightside})
The RHS of the above two equations can be evaluated in one step using
formula-eqn-side-manifold
. To do this let us set up its argument
(def manifold_eqn [{:name "p_quantity" :eqn (:rhs p_equation)}
{:name "q_quantity" :eqn (:rhs q_equation)}])
Now we may invoke the method by passing the above as the argument
=> (formula-eqn-side-manifold varpars manifold_eqn)
[{:quantity "p_quantity", :dimension "[L^(-1)*L^(2)*T^(2)]"}
{:quantity "q_quantity", :dimension "[L^(6)*T^(8)*L^(1)]"}]
NOTE: If the user plans to insert these derived dimensional formulae into
the standard_formula
the name given for respective :quantity
in the above
argument (here we named it manifold_eqn
) should be the name defined for
the quantity (so, in the definition varpars
).
Contains function. These are: - `formula-term` - `formula-eqn-side` - `formula-eqn-side-manifold` ## How to use ### Loading ``` (require '[diman.formula :refer [formula-term formula-eqn-side formula-eqn-side-manifold]]) ``` ### Example Given ``` (def varpars [{:symbol "x", :quantity "length"} {:symbol "v", :quantity "velocity"} {:symbol "t", :quantity "time"} {:symbol "a", :quantity "acceleration"}]) (def lhs "x^(1)") (def rhs {:term1 "x^(1)", :term2 "v^(2)", :term3 "t^(1)", :term4 "0.5*a^(1)*t^(2)"}) (def eqn {:lhs lhs, :rhs rhs}) ``` #### Formula of term To get the formula of a term, say, `(:term4 rhs)` ``` => (formula-term varpars (:term4 rhs)) "[T^(0)*L^(1)]" ``` and for left hand side ``` => (formula-term varpars lhs) "[L^(1)]" ``` #### Formula of a side of the equation For right hand side ``` => (formula-eqn-side varpars rhs) "[L^(1)] + [T^(-2)*L^(2)] + [T^(1)] + [T^(0)*L^(1)]" ``` for left hand side ``` => (formula-eqn-side varpars lhs) "[L^(1)]" ``` #### Evaluating formula for a side for multiple equations Lets say we have two different equations ``` (def p_leftside "p^(1)") (def p_rightside {:term1 "x^(2)*v^(-1)*t^(1)"}) (def p_equation {:lhs p_leftside, :rhs p_rightside}) ``` and ``` (def q_leftside "q^(1)") (def q_rightside {:term1 "x^(1)*a^(6)*t^(20)"}) (def q_equation {:lhs q_leftside, :rhs q_rightside}) ``` The RHS of the above two equations can be evaluated in one step using `formula-eqn-side-manifold`. To do this let us set up its argument ``` (def manifold_eqn [{:name "p_quantity" :eqn (:rhs p_equation)} {:name "q_quantity" :eqn (:rhs q_equation)}]) ``` Now we may invoke the method by passing the above as the argument ``` => (formula-eqn-side-manifold varpars manifold_eqn) [{:quantity "p_quantity", :dimension "[L^(-1)*L^(2)*T^(2)]"} {:quantity "q_quantity", :dimension "[L^(6)*T^(8)*L^(1)]"}] ``` **NOTE:** If the user plans to insert these derived dimensional formulae into the `standard_formula` the name given for respective `:quantity` in the above argument (here we named it `manifold_eqn`) **should be the name defined** for the quantity (so, in the definition `varpars`).
Contains function. These are:
get-row-echelon
to get row-echelon formreduce-up
to get reduced row-echelon form (invoke get-row-echelon
first)Contains function. These are: - `get-row-echelon` to get row-echelon form - `reduce-up` to get reduced row-echelon form (invoke `get-row-echelon` **first**)
Contains functions. These are:
remove-brackets
remove-parentheses
include-brackets
include-parentheses
key-in-expr?
(:require [diman.utilities :refer [remove-brackets remove-parentheses
include-brackets include-parentheses]
)
Self-explanatory
Contains functions. These are: - `remove-brackets` - `remove-parentheses` - `include-brackets` - `include-parentheses` - `key-in-expr?` ## How to use ### Loading ``` (:require [diman.utilities :refer [remove-brackets remove-parentheses include-brackets include-parentheses] ) ``` ### Examples Self-explanatory
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close