# Equations in pre and postsynaptic triggers

**URL:** <https://brian.discourse.group/t/equations-in-pre-and-postsynaptic-triggers/1265>\
**Category:** Support\
**Tags:** synapses, equations\
**Created:** [23 July 2024 14:34 UTC](https://brian.discourse.group/t/equations-in-pre-and-postsynaptic-triggers/1265 "2024-07-23T14:34:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjourne](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/bjourne/32/738_2.png) [@bjourne](https://brian.discourse.group/u/bjourne)\
**Post date:** [23 July 2024 14:34 UTC](https://brian.discourse.group/t/equations-in-pre-and-postsynaptic-triggers/1265/1 "2024-07-23T14:34:05Z")

</div>

Hi everyone,

An example explains it best:

`Synapses(..., on_pre = Equations('ge_post += w; w += del_w', del_w = 0.1))`

So I want to make `del_w` a tunable constant which should be bound by value to the synapse model. But this doesn’t work and Brian2 raises a parse error. Is there some better way to pass named constants to on\_pre, on\_post, and other kinds of triggers/actions?

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [23 July 2024 16:56 UTC](https://brian.discourse.group/t/equations-in-pre-and-postsynaptic-triggers/1265/2 "2024-07-23T16:56:32Z")

</div>

Hi @bjourne. The `on_pre` statement is not an equation, so this does indeed not work. But I am not 100% sure I understood what you want to do. Do you want to have a hardcoded value there? In this case, you could use standard string processing tools of Python, e.g. `on_pre=f"ge_post +=w; w+= {del_w}"`, passing in the value of `del_w` from the environment. You could also have an external constant that is only visible by a specific `Synapses` object by using the `namespace` argument, e.g.

```python
Synapses(..., on_pre='ge_post +=w; w += del_w', namespace={'del_w': 0.1})

```

Hope one of these options works for you!

---

<div class="post-metadata">

**Author:** ![bjourne](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/bjourne/32/738_2.png) [@bjourne](https://brian.discourse.group/u/bjourne)\
**Post date:** [24 July 2024 11:12 UTC](https://brian.discourse.group/t/equations-in-pre-and-postsynaptic-triggers/1265/3 "2024-07-24T11:12:03Z")

</div>

Yes, I can use standard string processing when building the on\_pre/post actions. But it becomes kind of messy when you have multiple named constants you want to interpolate into multiple places. F-strings doesn’t work because they call `str` on the expression and not `repr` so you have to write `“w += %r” % del\_w.

The namespace method could work, but here I think that the value of `del_w` is not interpolated so this could decrease performance?

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [24 July 2024 12:40 UTC](https://brian.discourse.group/t/equations-in-pre-and-postsynaptic-triggers/1265/4 "2024-07-24T12:40:13Z")

</div>

Regarding the f-string, you can use them, but they are indeed not super-readable. For using `repr` you can use `!r`, e.g. `on_pre=f"ge_post +=w; w+= {del_w!r}"`.

Regarding the performance of using `namespace`: I doubt it makes a measurable change for the performance. And if you use the C++ standalone mode, then the compiler will most likely do the constant folding for you, so both solutions become basically equivalent.
