[libcxx-commits] [libcxx] [libc++][math] Mathematical Special Functions: Hermite Polynomial (PR #89982)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 25 10:01:57 PDT 2024


================
@@ -0,0 +1,49 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the internal implementations of std::hermite.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_EXPERIMENTAL___MATH_HERMITE_H
+#define _LIBCPP_EXPERIMENTAL___MATH_HERMITE_H
+
+#include <cmath> // std::isnan
+#include <experimental/__config>
+#include <limits> // std::numeric_limits
+
+/// \return the hermite polynomial \f$ H_{n}(x) \f$
+/// \note The implementation is based on the recurrence formula
+/// \f[
+/// H_{n+1}(x) = 2x H_{n}(x) - 2 n H_{n-1}
+/// \f]
+/// Press, William H., et al. Numerical recipes 3rd edition: The art of
+/// scientific computing. Cambridge university press, 2007, p. 183.
+template <class _Real>
+_Real __libcpp_hermite_recurrence(const unsigned __n, const _Real __x) {
+  if (0 == __n)
+    return 1;
+
+  _Real __H_nPrev{1};
+  _Real __H_n = 2 * __x;
+  for (unsigned __i = 1; __i < __n; ++__i) {
+    const _Real __H_nNext = 2 * (__x * __H_n - __i * __H_nPrev);
----------------
mordante wrote:

We typically don't use const. 
We generally use snake_case. I've no issue to make an exception for mathematical symbols. There I think the proper case aids readability.
```suggestion
    _Real __H_n_next = 2 * (__x * __H_n - __i * __H_n_prev);
```

https://github.com/llvm/llvm-project/pull/89982


More information about the libcxx-commits mailing list