Tatooine
symbolic.h
Go to the documentation of this file.
1#ifndef TATOOINE_SYMBOLIC_H
2#define TATOOINE_SYMBOLIC_H
3#include <tatooine/available_libraries.h>
4#if TATOOINE_GINAC_AVAILABLE
5//==============================================================================
6#include <ginac/ginac.h>
7//==============================================================================
9//==============================================================================
10#define sym(sym) \
11 template <size_t... Is> \
12 static auto sym(size_t idx, std::index_sequence<Is...> /*is*/)->auto& { \
13 static std::array<GiNaC::symbol, sizeof...(Is)> sym_arr{ \
14 ((void)Is, \
15 GiNaC::symbol{#sym + std::string{"_"} + std::to_string(Is)})...}; \
16 return sym_arr[idx]; \
17 } \
18 static auto sym(size_t idx)->auto& { \
19 return sym(idx, std::make_index_sequence<num_pos_symbols>{}); \
20 } \
21 static auto sym()->auto& { \
22 static GiNaC::symbol sym{#sym}; \
23 return sym; \
24 }
25
26struct symbol {
27 static constexpr size_t num_pos_symbols = 100;
28 sym(i) sym(j) sym(k) sym(x) sym(y) sym(z) sym(t)
29};
30#undef sym
31#undef symarr
32//----------------------------------------------------------------------------
34template <typename... Relations>
35auto ev(const GiNaC::ex& expr, Relations&&... relations) {
36 GiNaC::lst substitutions{std::forward<Relations>(relations)...};
37 return expr.subs(substitutions);
38}
39//----------------------------------------------------------------------------
42template <typename out_real_type = double, typename... Relations>
43auto evtod(const GiNaC::ex& expr, Relations&&... relations) {
44 return static_cast<out_real_type>(
45 GiNaC::ex_to<GiNaC::numeric>(
46 ev(expr, std::forward<Relations>(relations)...).evalf())
47 .to_double());
48}
49//==============================================================================
50} // namespace tatooine::symbolic
51//==============================================================================
52// type_traits
53//==============================================================================
54#include "type_traits.h"
55//==============================================================================
56namespace tatooine {
57//==============================================================================
58template <typename T>
60 : std::integral_constant<bool, std::is_same_v<T, GiNaC::ex> ||
61 std::is_same_v<T, GiNaC::symbol>> {};
62// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63template <typename T>
64static constexpr auto is_symbolic_v = is_symbolic<T>::value;
65// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66template <typename... Ts>
68// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69template <typename... Ts>
70static constexpr auto are_symbolic_v = are_symbolic<Ts...>::value;
71// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72template <>
73struct are_symbolic<> : std::false_type {};
74// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75template <typename T>
76struct are_symbolic<T> : std::integral_constant<bool, is_symbolic_v<T>> {};
77// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78template <typename T0, typename T1, typename... Ts>
79struct are_symbolic<T0, T1, Ts...>
80 : std::integral_constant<bool, are_symbolic_v<T0> &&
81 are_symbolic_v<T1, Ts...>> {};
82//------------------------------------------------------------------------------
83template <typename... Ts>
85 : std::integral_constant<bool, are_arithmetic_v<Ts...> ||
86 are_symbolic_v<Ts...>> {};
87// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
88template <typename... Ts>
89static constexpr auto are_arithmetic_or_symbolic_v =
90 are_arithmetic_or_symbolic<Ts...>::value;
91//==============================================================================
92template <typename... Ts>
94 : std::integral_constant<bool, are_arithmetic_v<Ts...> ||
95 are_complex_v<Ts...> ||
96 are_symbolic_v<Ts...>> {};
97// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
98template <typename... Ts>
101//==============================================================================
102} // namespace tatooine
103//==============================================================================
104#endif
105#endif
Definition: symbolic.h:8
auto evtod(const GiNaC::ex &expr, Relations &&... relations)
Definition: symbolic.h:43
auto ev(const GiNaC::ex &expr, Relations &&... relations)
substitudes expression with relations
Definition: symbolic.h:35
Definition: algorithm.h:6
static constexpr auto is_symbolic_v
Definition: symbolic.h:64
static constexpr auto are_arithmetic_complex_or_symbolic_v
Definition: symbolic.h:99
static constexpr auto are_symbolic_v
Definition: symbolic.h:70
void evalf(base_tensor< Tensor, GiNaC::ex, Dims... > &m)
Definition: tensor_symbolic.h:58
static constexpr auto are_arithmetic_or_symbolic_v
Definition: symbolic.h:89
Definition: symbolic.h:86
Definition: symbolic.h:67
Definition: symbolic.h:61
Definition: symbolic.h:26
static constexpr size_t num_pos_symbols
Definition: symbolic.h:27