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: 9d71cf0f117f
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a97bfd9744b8
Choose a head ref
  • 8 commits
  • 4 files changed
  • 1 contributor

Commits on May 17, 2021

  1. Start polynomial changes.

    pleroy committed May 17, 2021
    Copy the full SHA
    6292736 View commit details

Commits on May 18, 2021

  1. Copy the full SHA
    ddee7ad View commit details
  2. Copy the full SHA
    0b35218 View commit details
  3. Something that compiles.

    pleroy committed May 18, 2021
    Copy the full SHA
    61ebbff View commit details
  4. Integrate is for vectors.

    pleroy committed May 18, 2021
    Copy the full SHA
    0a39862 View commit details
  5. Serialization test.

    pleroy committed May 18, 2021
    Copy the full SHA
    cb4f5a9 View commit details
  6. Obsolete comment.

    pleroy committed May 18, 2021
    Copy the full SHA
    2a81018 View commit details
  7. Merge pull request #2989 from pleroy/Polynomial

    Rewrite PolynomialInMonomialBasis to avoid specializations
    pleroy authored May 18, 2021
    Copy the full SHA
    a97bfd9 View commit details
Showing with 139 additions and 431 deletions.
  1. +18 −141 numerics/polynomial.hpp
  2. +110 −285 numerics/polynomial_body.hpp
  3. +4 −4 numerics/polynomial_test.cpp
  4. +7 −1 serialization/numerics.proto
159 changes: 18 additions & 141 deletions numerics/polynomial.hpp
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
#include "base/traits.hpp"
#include "geometry/hilbert.hpp"
#include "geometry/point.hpp"
#include "geometry/traits.hpp"
#include "quantities/named_quantities.hpp"
#include "quantities/tuples.hpp"
#include "serialization/numerics.pb.h"
@@ -45,6 +46,7 @@ namespace internal_polynomial {
using base::is_instance_of_v;
using base::not_constructible;
using base::not_null;
using geometry::is_vector_v;
using geometry::Hilbert;
using geometry::Point;
using quantities::Derivative;
@@ -55,10 +57,6 @@ using quantities::Quotient;

// |Value_| must belong to an affine space. |Argument_| must belong to a ring
// or to Point based on a ring.
// TODO(phl): We would like the base case to be the affine case (not limited to
// Point) and the specialized case to check for the existence of Sum and Product
// for Argument_, and that works with Clang but not with VS2015. Revisit once
// MSFT has fixed their bugs.
template<typename Value_, typename Argument_>
class Polynomial {
public:
@@ -105,7 +103,12 @@ class PolynomialInMonomialBasis : public Polynomial<Value_, Argument_> {
// Derivative<Derivative<Value, Argument>>...>
using Coefficients = Derivatives<Value, Argument, degree_ + 1>;

// The coefficients are applied to powers of argument.
// The coefficients are relative to origin; in other words they are applied to
// powers of (argument - origin).
constexpr PolynomialInMonomialBasis(Coefficients coefficients,
Argument const& origin);
template<typename A = Argument,
typename = std::enable_if_t<is_vector_v<A>>>
explicit constexpr PolynomialInMonomialBasis(
Coefficients coefficients);

@@ -124,154 +127,28 @@ class PolynomialInMonomialBasis : public Polynomial<Value_, Argument_> {
constexpr int degree() const override;
bool is_zero() const override;

template<int order = 1>
PolynomialInMonomialBasis<
Derivative<Value, Argument, order>, Argument, degree_ - order, Evaluator>
Derivative() const;

// The constant term of the result is zero.
template<typename V = Value,
typename = std::enable_if_t<!base::is_instance_of_v<Point, V>>>
PolynomialInMonomialBasis<quantities::Primitive<Value, Argument>, Argument,
degree_ + 1, Evaluator>
Primitive() const;

quantities::Primitive<Value, Argument> Integrate(
Argument const& argument1,
Argument const& argument2) const;

PolynomialInMonomialBasis& operator+=(PolynomialInMonomialBasis const& right);
PolynomialInMonomialBasis& operator-=(PolynomialInMonomialBasis const& right);

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

private:
Coefficients coefficients_;

template<typename V, typename A, int r,
template<typename, typename, int> typename E>
constexpr PolynomialInMonomialBasis<V, A, r, E>
friend operator-(PolynomialInMonomialBasis<V, A, r, E> const& right);
template<typename V, typename A, int l, int r,
template<typename, typename, int> typename E>
constexpr PolynomialInMonomialBasis<V, A, PRINCIPIA_MAX(l, r), E>
friend operator+(PolynomialInMonomialBasis<V, A, l, E> const& left,
PolynomialInMonomialBasis<V, A, r, E> const& right);
template<typename V, typename A, int l, int r,
template<typename, typename, int> typename E>
constexpr PolynomialInMonomialBasis<V, A, PRINCIPIA_MAX(l, r), E>
friend operator-(PolynomialInMonomialBasis<V, A, l, E> const& left,
PolynomialInMonomialBasis<V, A, r, E> const& right);
template<typename S,
typename V, typename A, int d,
template<typename, typename, int> typename E>
constexpr PolynomialInMonomialBasis<Product<S, V>, A, d, E>
friend operator*(S const& left,
PolynomialInMonomialBasis<V, A, d, E> const& right);
template<typename S,
typename V, typename A, int d,
template<typename, typename, int> typename E>
constexpr PolynomialInMonomialBasis<Product<V, S>, A, d, E>
friend operator*(PolynomialInMonomialBasis<V, A, d, E> const& left,
S const& right);
template<typename S,
typename V, typename A, int d,
template<typename, typename, int> typename E>
constexpr PolynomialInMonomialBasis<Quotient<V, S>, A, d, E>
friend operator/(PolynomialInMonomialBasis<V, A, d, E> const& left,
S const& right);
template<typename L, typename R, typename A,
int l, int r,
template<typename, typename, int> typename E>
constexpr PolynomialInMonomialBasis<Product<L, R>, A, l + r, E>
friend operator*(
PolynomialInMonomialBasis<L, A, l, E> const& left,
PolynomialInMonomialBasis<R, A, r, E> const& right);
template<typename L, typename R, typename A,
int l, int r,
template<typename, typename, int> typename E>
constexpr PolynomialInMonomialBasis<L, A, l * r, E>
friend Compose(PolynomialInMonomialBasis<L, R, l, E> const& left,
PolynomialInMonomialBasis<R, A, r, E> const& right);
template<typename L, typename R, typename A,
int l, int r,
template<typename, typename, int> typename E>
constexpr PolynomialInMonomialBasis<
typename Hilbert<L, R>::InnerProductType, A, l + r, E>
friend PointwiseInnerProduct(
PolynomialInMonomialBasis<L, A, l, E> const& left,
PolynomialInMonomialBasis<R, A, r, E> const& right);
template<typename V, typename A, int d,
template<typename, typename, int> typename E>
friend std::ostream& operator<<(
std::ostream& out,
PolynomialInMonomialBasis<V, A, d, E> const& polynomial);
template<typename V, typename A, int d,
template<typename, typename, int> class E,
typename O>
friend std::string mathematica::internal_mathematica::ToMathematicaBody(
PolynomialInMonomialBasis<V, A, d, E> const& polynomial,
O express_in);
};

template<typename Value_, typename Argument_, int degree_,
template<typename, typename, int> typename Evaluator>
class PolynomialInMonomialBasis<Value_, Point<Argument_>, degree_, Evaluator>
: public Polynomial<Value_, Point<Argument_>> {
public:
using Argument = Argument_;
using Value = Value_;

// Equivalent to:
// std::tuple<Value,
// Derivative<Value, Argument>,
// Derivative<Derivative<Value, Argument>>...>
using Coefficients = Derivatives<Value, Argument, degree_ + 1>;

// The coefficients are relative to origin; in other words they are applied to
// powers of (argument - origin).
constexpr PolynomialInMonomialBasis(Coefficients coefficients,
Point<Argument> const& origin);

// A polynomial may be explicitly converted to a higher degree (possibly with
// a different evaluator).
template<int higher_degree_,
template<typename, typename, int> class HigherEvaluator>
explicit operator PolynomialInMonomialBasis<
Value, Point<Argument>, higher_degree_, HigherEvaluator>() const;

FORCE_INLINE(inline) Value
operator()(Point<Argument> const& argument) const override;
FORCE_INLINE(inline) Derivative<Value, Argument>
EvaluateDerivative(Point<Argument> const& argument) const override;

constexpr int degree() const override;
bool is_zero() const override;

Point<Argument> const& origin() const;
Argument const& origin() const;

// Returns a copy of this polynomial adjusted to the given origin.
PolynomialInMonomialBasis AtOrigin(Point<Argument> const& origin) const;
PolynomialInMonomialBasis AtOrigin(Argument const& origin) const;

template<int order = 1>
PolynomialInMonomialBasis<
Derivative<Value, Argument, order>, Point<Argument>, degree_ - order,
Evaluator>
Derivative<Value, Argument, order>, Argument, degree_ - order, Evaluator>
Derivative() const;

// The constant term of the result is zero.
template<typename V = Value,
typename = std::enable_if_t<!base::is_instance_of_v<Point, V>>>
typename = std::enable_if_t<is_vector_v<V>>>
PolynomialInMonomialBasis<quantities::Primitive<Value, Argument>,
Point<Argument>, degree_ + 1, Evaluator>
Argument, degree_ + 1, Evaluator>
Primitive() const;

template<typename V = Value,
typename = std::enable_if_t<is_vector_v<V>>>
quantities::Primitive<Value, Argument> Integrate(
Point<Argument> const& argument1,
Point<Argument> const& argument2) const;
Argument const& argument1,
Argument const& argument2) const;

PolynomialInMonomialBasis& operator+=(const PolynomialInMonomialBasis& right);
PolynomialInMonomialBasis& operator-=(const PolynomialInMonomialBasis& right);
@@ -283,7 +160,7 @@ class PolynomialInMonomialBasis<Value_, Point<Argument_>, degree_, Evaluator>

private:
Coefficients coefficients_;
Point<Argument> origin_;
Argument origin_;

template<typename V, typename A, int r,
template<typename, typename, int> typename E>
Loading