Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6c66f2f79d6d
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: db4dceaac5ed
Choose a head ref
  • 9 commits
  • 11 files changed
  • 1 contributor

Commits on Oct 25, 2020

  1. Copy the full SHA
    509375d View commit details
  2. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    e9cfa99 View commit details
  3. Copy the full SHA
    4975643 View commit details
  4. Copy the full SHA
    8b63026 View commit details
  5. Fix the tests.

    pleroy committed Oct 25, 2020
    Copy the full SHA
    95771b4 View commit details
  6. Fix the clients.

    pleroy committed Oct 25, 2020
    Copy the full SHA
    0186ad6 View commit details
  7. Copy the full SHA
    c804014 View commit details
  8. Lint.

    pleroy committed Oct 25, 2020
    Copy the full SHA
    c0c9fa2 View commit details
  9. Merge pull request #2771 from pleroy/Reorder

    Split PiecewisePoissonSeries to its own files
    pleroy authored Oct 25, 2020
    Copy the full SHA
    db4dcea View commit details
1 change: 1 addition & 0 deletions mathematica/mathematica.hpp
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
#include "geometry/r3x3_matrix.hpp"
#include "geometry/symmetric_bilinear_form.hpp"
#include "numerics/fixed_arrays.hpp"
#include "numerics/piecewise_poisson_series.hpp"
#include "numerics/poisson_series.hpp"
#include "numerics/polynomial.hpp"
#include "physics/degrees_of_freedom.hpp"
2 changes: 2 additions & 0 deletions numerics/frequency_analysis_test.cpp
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@
#include "gtest/gtest.h"
#include "numerics/apodization.hpp"
#include "numerics/fast_fourier_transform.hpp"
#include "numerics/piecewise_poisson_series.hpp"
#include "numerics/poisson_series.hpp"
#include "numerics/polynomial_evaluators.hpp"
#include "quantities/elementary_functions.hpp"
#include "quantities/named_quantities.hpp"
3 changes: 3 additions & 0 deletions numerics/numerics.vcxproj
Original file line number Diff line number Diff line change
@@ -48,6 +48,8 @@
<ClInclude Include="newhall_body.hpp" />
<ClInclude Include="pid.hpp" />
<ClInclude Include="pid_body.hpp" />
<ClInclude Include="piecewise_poisson_series.hpp" />
<ClInclude Include="piecewise_poisson_series_body.hpp" />
<ClInclude Include="poisson_series.hpp" />
<ClInclude Include="poisson_series_basis.hpp" />
<ClInclude Include="poisson_series_basis_body.hpp" />
@@ -91,6 +93,7 @@
<ClCompile Include="max_abs_normalized_associated_legendre_functions_test.cc" />
<ClCompile Include="newhall_test.cpp" />
<ClCompile Include="pid_test.cpp" />
<ClCompile Include="piecewise_poisson_series_test.cpp" />
<ClCompile Include="poisson_series_basis_test.cpp" />
<ClCompile Include="poisson_series_test.cpp" />
<ClCompile Include="polynomial_evaluators_test.cpp" />
9 changes: 9 additions & 0 deletions numerics/numerics.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -176,6 +176,12 @@
<ClInclude Include="scale_b.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="piecewise_poisson_series.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="piecewise_poisson_series_body.hpp">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="чебышёв_series_test.cpp">
@@ -268,6 +274,9 @@
<ClCompile Include="scale_b_test.cpp">
<Filter>Test Files</Filter>
</ClCompile>
<ClCompile Include="piecewise_poisson_series_test.cpp">
<Filter>Test Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="xgscd.proto.txt">
320 changes: 320 additions & 0 deletions numerics/piecewise_poisson_series.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@

#pragma once

#include <algorithm>
#include <optional>
#include <string>
#include <vector>

#include "base/macros.hpp"
#include "base/not_null.hpp"
#include "geometry/complexification.hpp"
#include "geometry/hilbert.hpp"
#include "geometry/interval.hpp"
#include "geometry/named_quantities.hpp"
#include "numerics/poisson_series.hpp"
#include "quantities/named_quantities.hpp"
#include "quantities/quantities.hpp"
#include "serialization/numerics.pb.h"

namespace principia {
namespace numerics {
FORWARD_DECLARE_FROM(piecewise_poisson_series,
TEMPLATE(typename Value, int degree_,
template<typename, typename, int> class Evaluator)
class,
PiecewisePoissonSeries);
} // namespace numerics

namespace mathematica {
FORWARD_DECLARE_FUNCTION_FROM(
mathematica,
TEMPLATE(typename Value, int degree_,
template<typename, typename, int> class Evaluator,
typename OptionalExpressIn) std::string,
ToMathematicaExpression,
(numerics::PiecewisePoissonSeries<Value, degree_, Evaluator> const& series,
OptionalExpressIn express_in));
} // namespace mathematica

namespace numerics {
namespace internal_piecewise_poisson_series {

using base::not_null;
using geometry::Complexification;
using geometry::Hilbert;
using geometry::Instant;
using geometry::Interval;
using quantities::AngularFrequency;
using quantities::Primitive;
using quantities::Product;
using quantities::Quotient;
using quantities::Time;

// The trigonometric functions are by default assumed to look like a polynomial
// of this degree over an interval of a piecewise series.
constexpr int estimated_trigonometric_degree = 1;

// A function defined by Poisson series piecewise. Each of the Poisson series
// making up the function applies over the semi-open interval
// [internal.min, interval.max[. It's not required that the function be
// continuous.
template<typename Value, int degree_,
template<typename, typename, int> class Evaluator>
class PiecewisePoissonSeries {
public:
static constexpr int degree = degree_;
using Series = PoissonSeries<Value, degree_, Evaluator>;
using Spectrum = std::function<Complexification<Primitive<Value, Time>>(
AngularFrequency const&)>;

PiecewisePoissonSeries(Interval<Instant> const& interval,
Series const& series);

// The intervals for successive calls to Append must be consecutive. For the
// first call, the interval must be consecutive with the one passed at
// construction.
void Append(Interval<Instant> const& interval,
Series const& series);

Instant t_min() const;
Instant t_max() const;

// t must be in the interval [t_min, t_max].
Value operator()(Instant const& t) const;

// Returns the Fourier transform of this piecewise Poisson series.
// The function is taken to be 0 outside [t_min, t_max].
// The convention used is ∫ f(t) exp(-iωt) dt, corresponding to Mathematica’s
// FourierParameters -> {1, -1} for FourierTransform (the “pure mathematics;
// systems engineering”).
// When evaluated at a given frequency, the Fourier transform is computed by
// Gauss-Legendre quadrature on each subinterval, where the number of points
// is chosen assuming that the periods of periodic terms are all large
// compared to the subintervals.
// If apodization is desired, |*this| should be multiplied by an apodization
// function, and |FourierTransform| should be called on the product.
// |*this| must outlive the resulting function.
Spectrum FourierTransform() const;

template<int d>
PiecewisePoissonSeries& operator+=(
PoissonSeries<Value, d, Evaluator> const& right);
template<int d>
PiecewisePoissonSeries& operator-=(
PoissonSeries<Value, d, Evaluator> const& right);

void WriteToMessage(
not_null<serialization::PiecewisePoissonSeries*> message) const;
static PiecewisePoissonSeries ReadFromMessage(
serialization::PiecewisePoissonSeries const& message);

private:
PiecewisePoissonSeries(std::vector<Instant> const& bounds,
std::vector<Series> const& series,
std::optional<Series> const& addend);

Value EvaluateAddend(Instant const& t) const;

std::vector<Instant> bounds_;
std::vector<Series> series_;
std::optional<Series> addend_;

template<typename V, int r, template<typename, typename, int> class E>
PiecewisePoissonSeries<V, r, E>
friend operator-(PiecewisePoissonSeries<V, r, E> const& right);
template<typename S, typename V, int d,
template<typename, typename, int> class E>
PiecewisePoissonSeries<Product<S, V>, d, E>
friend operator*(S const& left,
PiecewisePoissonSeries<V, d, E> const& right);
template<typename S, typename V, int d,
template<typename, typename, int> class E>
PiecewisePoissonSeries<Product<V, S>, d, E>
friend operator*(PiecewisePoissonSeries<V, d, E> const& left,
S const& right);
template<typename S, typename V, int d,
template<typename, typename, int> class E>
PiecewisePoissonSeries<Quotient<V, S>, d, E>
friend operator/(PiecewisePoissonSeries<V, d, E> const& left,
S const& right);
template<typename V, int l, int r, template<typename, typename, int> class E>
PiecewisePoissonSeries<V, std::max(l, r), E>
friend operator+(PoissonSeries<V, l, E> const& left,
PiecewisePoissonSeries<V, r, E> const& right);
template<typename V, int l, int r, template<typename, typename, int> class E>
PiecewisePoissonSeries<V, std::max(l, r), E>
friend operator+(PiecewisePoissonSeries<V, l, E> const& left,
PoissonSeries<V, r, E> const& right);
template<typename V, int l, int r, template<typename, typename, int> class E>
PiecewisePoissonSeries<V, std::max(l, r), E>
friend operator-(PoissonSeries<V, l, E> const& left,
PiecewisePoissonSeries<V, r, E> const& right);
template<typename V, int l, int r, template<typename, typename, int> class E>
PiecewisePoissonSeries<V, std::max(l, r), E>
friend operator-(PiecewisePoissonSeries<V, l, E> const& left,
PoissonSeries<V, r, E> const& right);
template<typename L, typename R, int l, int r,
template<typename, typename, int> class E>
PiecewisePoissonSeries<Product<L, R>, l + r, E>
friend operator*(PoissonSeries<L, l, E> const& left,
PiecewisePoissonSeries<R, r, E> const& right);
template<typename L, typename R, int l, int r,
template<typename, typename, int> class E>
PiecewisePoissonSeries<Product<L, R>, l + r, E>
friend operator*(PiecewisePoissonSeries<L, l, E> const& left,
PoissonSeries<R, r, E> const& right);
template<typename L, typename R, int l, int r, int w,
template<typename, typename, int> class E, int p>
typename Hilbert<L, R>::InnerProductType
friend InnerProduct(PoissonSeries<L, l, E> const& left,
PiecewisePoissonSeries<R, r, E> const& right,
PoissonSeries<double, w, E> const& weight,
Instant const& t_min,
Instant const& t_max);
template<typename L, typename R, int l, int r, int w,
template<typename, typename, int> class E, int p>
typename Hilbert<L, R>::InnerProductType
friend InnerProduct(PiecewisePoissonSeries<L, l, E> const& left,
PoissonSeries<R, r, E> const& right,
PoissonSeries<double, w, E> const& weight,
Instant const& t_min,
Instant const& t_max);
template<typename V, int d,
template<typename, typename, int> class E,
typename O>
friend std::string mathematica::internal_mathematica::ToMathematicaExpression(
PiecewisePoissonSeries<V, d, E> const& polynomial,
O express_in);
};

// Some of the vector space operations for piecewise Poisson series. Note that
// while piecewise Poisson series have an algebra structure, we do not need it.

template<typename Value, int rdegree_,
template<typename, typename, int> class Evaluator>
PiecewisePoissonSeries<Value, rdegree_, Evaluator>
operator+(PiecewisePoissonSeries<Value, rdegree_, Evaluator> const& right);

template<typename Value, int rdegree_,
template<typename, typename, int> class Evaluator>
PiecewisePoissonSeries<Value, rdegree_, Evaluator>
operator-(PiecewisePoissonSeries<Value, rdegree_, Evaluator> const& right);

template<typename Scalar,
typename Value, int degree_,
template<typename, typename, int> class Evaluator>
PiecewisePoissonSeries<Product<Scalar, Value>, degree_, Evaluator>
operator*(Scalar const& left,
PiecewisePoissonSeries<Value, degree_, Evaluator> const& right);

template<typename Scalar,
typename Value, int degree_,
template<typename, typename, int> class Evaluator>
PiecewisePoissonSeries<Product<Value, Scalar>, degree_, Evaluator>
operator*(PiecewisePoissonSeries<Value, degree_, Evaluator> const& left,
Scalar const& right);

template<typename Scalar,
typename Value, int degree_,
template<typename, typename, int> class Evaluator>
PiecewisePoissonSeries<Quotient<Value, Scalar>, degree_, Evaluator>
operator/(PiecewisePoissonSeries<Value, degree_, Evaluator> const& left,
Scalar const& right);

// Action of Poisson series on piecewise Poisson series.

template<typename Value, int ldegree_, int rdegree_,
template<typename, typename, int> class Evaluator>
PiecewisePoissonSeries<Value, std::max(ldegree_, rdegree_), Evaluator>
operator+(PoissonSeries<Value, ldegree_, Evaluator> const& left,
PiecewisePoissonSeries<Value, rdegree_, Evaluator> const& right);

template<typename Value, int ldegree_, int rdegree_,
template<typename, typename, int> class Evaluator>
PiecewisePoissonSeries<Value, std::max(ldegree_, rdegree_), Evaluator>
operator+(PiecewisePoissonSeries<Value, ldegree_, Evaluator> const& left,
PoissonSeries<Value, rdegree_, Evaluator> const& right);

template<typename Value, int ldegree_, int rdegree_,
template<typename, typename, int> class Evaluator>
PiecewisePoissonSeries<Value, std::max(ldegree_, rdegree_), Evaluator>
operator-(PoissonSeries<Value, ldegree_, Evaluator> const& left,
PiecewisePoissonSeries<Value, rdegree_, Evaluator> const& right);

template<typename Value, int ldegree_, int rdegree_,
template<typename, typename, int> class Evaluator>
PiecewisePoissonSeries<Value, std::max(ldegree_, rdegree_), Evaluator>
operator-(PiecewisePoissonSeries<Value, ldegree_, Evaluator> const& left,
PoissonSeries<Value, rdegree_, Evaluator> const& right);

template<typename LValue, typename RValue,
int ldegree_, int rdegree_,
template<typename, typename, int> class Evaluator>
PiecewisePoissonSeries<Product<LValue, RValue>, ldegree_ + rdegree_, Evaluator>
operator*(PoissonSeries<LValue, ldegree_, Evaluator> const& left,
PiecewisePoissonSeries<RValue, rdegree_, Evaluator> const& right);

template<typename LValue, typename RValue,
int ldegree_, int rdegree_,
template<typename, typename, int> class Evaluator>
PiecewisePoissonSeries<Product<LValue, RValue>, ldegree_ + rdegree_, Evaluator>
operator*(PiecewisePoissonSeries<LValue, ldegree_, Evaluator> const& left,
PoissonSeries<RValue, rdegree_, Evaluator> const& right);

template<typename LValue, typename RValue,
int ldegree_, int rdegree_, int wdegree_,
template<typename, typename, int> class Evaluator,
int points = (ldegree_ + estimated_trigonometric_degree +
rdegree_ + estimated_trigonometric_degree +
wdegree_ + estimated_trigonometric_degree) / 2>
typename Hilbert<LValue, RValue>::InnerProductType
InnerProduct(PoissonSeries<LValue, ldegree_, Evaluator> const& left,
PiecewisePoissonSeries<RValue, rdegree_, Evaluator> const& right,
PoissonSeries<double, wdegree_, Evaluator> const& weight);

template<typename LValue, typename RValue,
int ldegree_, int rdegree_, int wdegree_,
template<typename, typename, int> class Evaluator,
int points = (ldegree_ + estimated_trigonometric_degree +
rdegree_ + estimated_trigonometric_degree +
wdegree_ + estimated_trigonometric_degree) / 2>
typename Hilbert<LValue, RValue>::InnerProductType
InnerProduct(PoissonSeries<LValue, ldegree_, Evaluator> const& left,
PiecewisePoissonSeries<RValue, rdegree_, Evaluator> const& right,
PoissonSeries<double, wdegree_, Evaluator> const& weight,
Instant const& t_min,
Instant const& t_max);

template<typename LValue, typename RValue,
int ldegree_, int rdegree_, int wdegree_,
template<typename, typename, int> class Evaluator,
int points = (ldegree_ + estimated_trigonometric_degree +
rdegree_ + estimated_trigonometric_degree +
wdegree_ + estimated_trigonometric_degree) / 2>
typename Hilbert<LValue, RValue>::InnerProductType
InnerProduct(PiecewisePoissonSeries<LValue, ldegree_, Evaluator> const& left,
PoissonSeries<RValue, rdegree_, Evaluator> const& right,
PoissonSeries<double, wdegree_, Evaluator> const& weight);

template<typename LValue, typename RValue,
int ldegree_, int rdegree_, int wdegree_,
template<typename, typename, int> class Evaluator,
int points = (ldegree_ + estimated_trigonometric_degree +
rdegree_ + estimated_trigonometric_degree +
wdegree_ + estimated_trigonometric_degree) / 2>
typename Hilbert<LValue, RValue>::InnerProductType
InnerProduct(PiecewisePoissonSeries<LValue, ldegree_, Evaluator> const& left,
PoissonSeries<RValue, rdegree_, Evaluator> const& right,
PoissonSeries<double, wdegree_, Evaluator> const& weight,
Instant const& t_min,
Instant const& t_max);

} // namespace internal_piecewise_poisson_series

using internal_piecewise_poisson_series::PiecewisePoissonSeries;

} // namespace numerics
} // namespace principia

#include "numerics/piecewise_poisson_series_body.hpp"
Loading