File size: 2,833 Bytes
d06fa57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""SRHarness Engine: structured symbolic models for scientific discovery."""

from __future__ import annotations

from typing import Any, Callable

from .expression import (
    Aggregate,
    Binary,
    Expression,
    Function,
    Gather,
    GroupedParameter,
    Index,
    Indexed,
    Number,
    Parameter,
    Reduction,
    RelationLift,
    Symbol,
    Variable,
    aggr,
    function,
    gather,
    grouped_param,
    param,
    reduction,
    sour,
    targ,
)
from .analysis import count_parameters, fold_constants, parameter_values, unbound_parameters
from .desugar import desugar
from .evaluation import evaluate
from .optimize import FitResult, bind_parameters, fit
from .indexed_evaluation import RelationField
from .parser import parse
from .render import render


def _unary(name: str) -> Callable[[Any], Expression]:
    def constructor(value: Any) -> Expression:
        """Create a unary symbolic function expression.

        Args:
            value: Symbolic expression or value to wrap.

        Returns:
            A symbolic unary function call.
        """
        return function(name, value)

    constructor.__name__ = name
    constructor.__qualname__ = name
    return constructor


sin = _unary("sin")
cos = _unary("cos")
tan = _unary("tan")
tanh = _unary("tanh")
sinh = _unary("sinh")
cosh = _unary("cosh")
arcsin = _unary("arcsin")
arccos = _unary("arccos")
arctan = _unary("arctan")
asin = arcsin
acos = arccos
atan = arctan
exp = _unary("exp")
log = _unary("log")
log10 = _unary("log10")
log2 = _unary("log2")
ln = log
lg = log10
sqrt = _unary("sqrt")
abs = _unary("abs")
sigmoid = _unary("sigmoid")
sign = _unary("sign")
sec = _unary("sec")
sech = _unary("sech")
csc = _unary("csc")
cot = _unary("cot")
inv = _unary("inv")


def delay(value: Any, delta: Any) -> Expression:
    """Create a delayed-value expression.

    Args:
        value: Time-dependent expression to sample from the past.
        delta: Scalar or sample-aligned delay interval.

    Returns:
        A symbolic ``delay(value, delta)`` call.
    """
    return function("delay", value, delta)


__all__ = [
    "Aggregate", "Binary", "Expression", "FitResult", "Function", "Gather",
    "GroupedParameter",
    "Index", "Indexed", "Number", "Parameter", "Reduction", "RelationField",
    "RelationLift", "Symbol",
    "Variable", "abs", "acos", "aggr", "arccos", "arcsin", "arctan", "asin", "atan",
    "cos", "cosh",
    "bind_parameters", "cot", "count_parameters", "csc", "delay", "desugar",
    "evaluate", "exp", "fit",
    "fold_constants", "function", "gather", "grouped_param", "inv", "lg", "ln", "log",
    "log10", "log2",
    "param", "parameter_values", "parse", "reduction", "render", "sec", "sech",
    "sigmoid", "sign", "sin",
    "sinh", "sour", "sqrt", "tan", "tanh", "targ", "unbound_parameters",
]