Dear Stan developers,

**Question.** Might it be possible as a future development to have a run-time option to have standard sampling statements, like `y ~ normal(mu, sigma)`

, sample in a way that keeps the constant aspects of the log probability (called e.g. `keep_constants_in_lp`

), like the `target += ...`

notation does now?

**Rationale.** Sampling statements like `y ~ normal(mu, sigma)`

drop constant terms, while “target” notation like `target += normal_lpdf(mu, sigma)`

keeps them [1]. Some applications like bridge sampling require these constants [2, 3]. So, Stan code needs to be rewritten for that purpose. The code gets ugly fast, and this increases the barriers to entry and the chance of errors. Some of those difficulties relate to the relative lack of flexibility of “target” notation. For example, if you want to sample with boundaries, e.g. `vector<lower=a, upper=b> y`

, then you also have to adjust `target`

using `<distribution>_lcdf(upper | parameters)`

etc. [2]. If you try to automate this, to reduce the chance of programming errors, you run into the problem that Stan functions can’t have the same names but different signatures – my approach has been to write code [4] to write a bunch of Stan functions [5] that handle sampling with “target” notation. In contrast, `~`

notation handles lots of variable types automatically with the same notation, which is clean and simple.

Would this be feasible in Stan itself? That is, if `keep_constants_in_lp`

is false, it would works as it does now (for speed). If `keep_constants_in_lp`

is true, it would behave like `target +=`

notation does now, and if it’s sampling a variable with explicit `lower`

and/or `upper`

limits, it would apply the correction(s). That would allow much simpler syntax for this sort of situation.

**Thanks** as ever for a fantastic piece of software!

all the best,

Rudolf.

[1] 7.4 Sampling Statements | Stan Reference Manual

[2] CRAN - Package bridgesampling

[3] https://doi.org/10.1016/j.jmp.2017.09.005

[4] e.g. https://egret.psychol.cam.ac.uk/rlib/make_commonfunc_stan.py

[5] e.g. https://egret.psychol.cam.ac.uk/rlib/commonfunc.stan