From 3fafea6ff4679a0fd500cc7fb6c325ea5cf2885f Mon Sep 17 00:00:00 2001 From: Evgeny Metelkin Date: Tue, 29 Jun 2021 12:57:45 +0300 Subject: [PATCH] add `piecewise` --- README.md | 8 ++++---- changelog.md | 1 + math.md | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 16c27e9..6c8fdbc 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ See also the [Heta video tutorial](https://hetalang.github.io/#/resources/?id=le **Heta** language is a domain-specific programming language (DSL) for dynamic quantitative models used in quantitative systems pharmacology (QSP) and systems biology (SB). It describes the biological systems as the components of QSP/SB modeling platform. -Heta language represents the dynamic model as a set of interacting components which describe volumes, concentrations, amounts, rates, and others. You don't need to writing an ODE system manually. The differential equations are compiled "on the fly" when they are required. +The Heta language represents the dynamic model as a set of interacting components describing volumes, concentrations, amounts, rates, and others. You don't need to writing an ODE system manually. The differential equations are compiled "on the fly" where they are required. The key idea of Heta language is the development and editing of the bio-mathematical models as expressive programming code which gives us the benefits of programming languages: compact and human-readable format, modularity, reusability, etc. The model development can be easily organized as a workflow inside a group. The Heta code is friendly for version control systems and different continuous integration and delivery (CI/CD) tools can be used to reach maximal productivity. @@ -35,11 +35,11 @@ The important pre-formulated requirements to the language were: - Human-readable/writable code can be used for model creation, modification, or integration. - Easy code parsing and transformation for potential implementation into different tools and frameworks. -- Modularity: QSP platform can be subdivided into several files and spaces for better project management. +- Modularity: QSP platform can be sub-divided into several files and spaces for better project management. - Polymorphism of code: code can be presented in different formats with the same meaning. -- Reusability: modeling platforms should be easily extended. Model parts and datasets can be used for other purposes. +- Reusability: modeling platforms should be easily extended. Model parts and datasets can be used for other models and applications. - Reach annotation capabilities for better code revision and reporting. -- The easy transformation from/to different formats of platforms and models currently used in practice: SBML, DBSolve, Spreadsheets, databases, mrgsolve, Simbiology, etc. +- The easy transformation from/to different formats of platforms and models currently used in practice: SBML, DBSolve, tables, databases, mrgsolve, Simbiology, etc. ## "Hello world!" example diff --git a/changelog.md b/changelog.md index e29dca4..b9b1f7c 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ - `@StopSwitcher` as an experimental class - remove `@SimpleTask` +- `piesewise()` function inside MathExpr (experimental) ## 0.4.0 diff --git a/math.md b/math.md index 4149153..91dcb7d 100644 --- a/math.md +++ b/math.md @@ -1,10 +1,10 @@ # Math expressions -All [@Record](./classes#record) instances (Species, Process, etc.) include `assimptions` property which is set of assignments for different cases: initial assignment `start_`, rule assignment `ode_` and any number of switcher assignments. +All [@Record](./classes#record) instances (Species, Process, etc.) include `assignments` property which is set of assignments for different scopes: initial assignment `start_`, rule assignment `ode_` and any number of switcher assignments. The right hand side (RHS) of assignments is string of the specific format [MathExpr](./classes#mathexpr). -The right hand side (RHS) of assignments is string of specific format [MathExpr](./classes#mathexpr). +[@CSwitcher](./classes#cswitcher) includes [MathExpr](./classes#mathexpr) inside property `trigger`. -The property `trigger` of [@DSwitcher](./classes#dswitcher) also includes [MathExpr](./classes#mathexpr) but this expression must return boolean result. +The `trigger` property of [@DSwitcher](./classes#dswitcher) and [StopSwitcher](./classes#stopswitcher) also include [MathExpr](./classes#mathexpr) but this expression must return boolean result. `MathExpr` may include: numbers, identifiers, operators, functions, parentheses. @@ -19,7 +19,7 @@ The another possible values of double are: ## Boolean values -Boolen constants: `true`, `false` can also be used as part of boolean expressions +Boolean constants: `true`, `false` can also be used as part of boolean expressions ## Pre defined constants @@ -94,3 +94,32 @@ sin(x), tan(x) acosh(x), acoth(x), acsch(x), asech(x), asinh(x), atanh(x), cosh(x), coth(x), csch(x), sech(x), sinh(x), tanh(x) + + +### piecewise function (experimental) + +`piecewise` is a special function which can be used to switch values based on conditions. +It can be applied as an extension of the ternary operator or `ifgt`-like functions for more than one condition. + +The `piecewise` function can have several arguments with the following meaning. + +```heta +y1 := piecewise(value1, cond1, value2, cond2, ..., otherwise) +``` + +`value1` is returned if `cond1` is true, `value2` is returned if `cond2` is true, etc. + +If neither conditions is true, than it returns `otherwise` value. +`otherwise` value can be skipped. In that case the function returns `NaN`. + +Each condition argument must be of boolean type: comparison operator, boolean value, etc. + +__Example__ + +```heta +// 0 -> human, 1 -> monkey, 2 -> rat, default -> mouse +animal @Const = 999; +body_weight @Record .= piecewise(BW_human, animal==0, BW_monkey, animal==1, BW_rat, animal==2, BW_mouse); + +// the body_weight value will be equal to BW_mouse +```