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

Commits on Dec 28, 2020

  1. Logging of DoublePrecision.

    pleroy committed Dec 28, 2020
    Copy the full SHA
    8b71763 View commit details

Commits on Dec 31, 2020

  1. Merge.

    pleroy committed Dec 31, 2020
    Copy the full SHA
    5572531 View commit details
  2. Exact double precision.

    pleroy committed Dec 31, 2020
    Copy the full SHA
    58ae2ab View commit details
  3. Merge pull request #2826 from pleroy/MmaDoublePrecision

    Mathematica output of DoublePrecision
    pleroy authored Dec 31, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5316ec0 View commit details
Showing with 26 additions and 2 deletions.
  1. +7 −1 mathematica/mathematica.hpp
  2. +9 −1 mathematica/mathematica_body.hpp
  3. +10 −0 mathematica/mathematica_test.cpp
8 changes: 7 additions & 1 deletion mathematica/mathematica.hpp
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
#include "geometry/r3_element.hpp"
#include "geometry/r3x3_matrix.hpp"
#include "geometry/symmetric_bilinear_form.hpp"
#include "numerics/double_precision.hpp"
#include "numerics/fixed_arrays.hpp"
#include "numerics/piecewise_poisson_series.hpp"
#include "numerics/poisson_series.hpp"
@@ -40,6 +41,7 @@ using geometry::R3Element;
using geometry::R3x3Matrix;
using geometry::SymmetricBilinearForm;
using geometry::Vector;
using numerics::DoublePrecision;
using numerics::FixedVector;
using numerics::PiecewisePoissonSeries;
using numerics::PoissonSeries;
@@ -171,10 +173,14 @@ template<typename D, typename... Qs>
std::string ToMathematica(Quantity<D> const& quantity,
ExpressIn<Qs...> express_in);

template<typename D, typename OptionalExpressIn = std::nullopt_t>
template<typename D>
std::string ToMathematica(Quantity<D> const& quantity,
std::nullopt_t express_in = std::nullopt);

template<typename T, typename OptionalExpressIn = std::nullopt_t>
std::string ToMathematica(DoublePrecision<T> const& double_precision,
OptionalExpressIn express_in = std::nullopt);

template<typename S, typename F, typename OptionalExpressIn = std::nullopt_t>
std::string ToMathematica(Vector<S, F> const& vector,
OptionalExpressIn express_in = std::nullopt);
10 changes: 9 additions & 1 deletion mathematica/mathematica_body.hpp
Original file line number Diff line number Diff line change
@@ -349,7 +349,7 @@ std::string ToMathematica(Quantity<D> const& quantity,
return ToMathematica(express_in(quantity));
}

template<typename D, typename OptionalExpressIn>
template<typename D>
std::string ToMathematica(Quantity<D> const& quantity,
std::nullopt_t express_in) {
std::string s = DebugString(quantity);
@@ -359,6 +359,14 @@ std::string ToMathematica(Quantity<D> const& quantity,
return Apply("Quantity", {number, units});
}

template<typename T, typename OptionalExpressIn>
std::string ToMathematica(DoublePrecision<T> const& double_precision,
OptionalExpressIn express_in) {
return Apply("Plus",
{ToMathematica(double_precision.value, express_in),
ToMathematica(double_precision.error, express_in)});
}

template<typename S, typename F, typename OptionalExpressIn>
std::string ToMathematica(Vector<S, F> const& vector,
OptionalExpressIn express_in) {
10 changes: 10 additions & 0 deletions mathematica/mathematica_test.cpp
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ using geometry::R3x3Matrix;
using geometry::SymmetricBilinearForm;
using geometry::Vector;
using geometry::Velocity;
using numerics::DoublePrecision;
using numerics::FixedVector;
using numerics::HornerEvaluator;
using numerics::PiecewisePoissonSeries;
@@ -147,6 +148,15 @@ TEST_F(MathematicaTest, ToMathematica) {
{{u8"α", ToMathematica(1.5)}}),
ToMathematica(1.5 * Metre / Second));
}
{
DoublePrecision<double> d(3);
d += 5e-20;
EXPECT_EQ(absl::StrReplaceAll(
u8"Plus[α,β]",
{{u8"α", ToMathematica(3.0)},
{u8"β", ToMathematica(5e-20)}}),
ToMathematica(d));
}
{
Vector<double, F> const v({2.0, 3.0, -4.0});
EXPECT_EQ(ToMathematica(v.coordinates()), ToMathematica(v));