Skip to content

Commit

Permalink
add piecewise
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Metelkin committed Jun 29, 2021
1 parent ff1edc8 commit 3fafea6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ 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.

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

Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- `@StopSwitcher` as an experimental class
- remove `@SimpleTask`
- `piesewise()` function inside MathExpr (experimental)

## 0.4.0

Expand Down
37 changes: 33 additions & 4 deletions math.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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

Expand Down Expand Up @@ -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
```

0 comments on commit 3fafea6

Please sign in to comment.