summaryrefslogtreecommitdiff
path: root/p-spin.cpp
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2025-04-18 23:02:43 -0300
committerJaron Kent-Dobias <jaron@kent-dobias.com>2025-04-18 23:02:43 -0300
commite4ab12ce914b2471355a99943b58c5b274d8754c (patch)
treece730c80936dba6ed4ac82e210cd5b7faddbc258 /p-spin.cpp
parent92bd43e33e79a7d682267d3f6054e8b1dd9d00db (diff)
downloadcode-e4ab12ce914b2471355a99943b58c5b274d8754c.tar.gz
code-e4ab12ce914b2471355a99943b58c5b274d8754c.tar.bz2
code-e4ab12ce914b2471355a99943b58c5b274d8754c.zip
Refactor
Diffstat (limited to 'p-spin.cpp')
-rw-r--r--p-spin.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/p-spin.cpp b/p-spin.cpp
new file mode 100644
index 0000000..3691ed6
--- /dev/null
+++ b/p-spin.cpp
@@ -0,0 +1,25 @@
+#include "p-spin.hpp"
+
+inline Real fP(unsigned p, Real q) {
+ return 0.5 * pow(q, p);
+}
+
+inline Real dfP(unsigned p, Real q) {
+ return 0.5 * p * pow(q, p - 1);
+}
+
+inline Real ddfP(unsigned p, Real q) {
+ return 0.5 * p * (p - 1) * pow(q, p - 2);
+}
+
+Real f(Real λ, unsigned p, unsigned s, Real q) {
+ return (1 - λ) * fP(p, q) + λ * fP(s, q);
+}
+
+Real df(Real λ, unsigned p, unsigned s, Real q) {
+ return (1 - λ) * dfP(p, q) + λ * dfP(s, q);
+}
+
+Real ddf(Real λ, unsigned p, unsigned s, Real q) {
+ return (1 - λ) * ddfP(p, q) + λ * ddfP(s, q);
+}