LMCAS
Lamina Computer Algebra System
Toggle main menu visibility
载入中...
搜索中...
未找到
symbolic_matrix_solve.cpp
浏览该文件的文档.
1
#include "
internal/symbolic_matrix_support.hpp
"
2
3
namespace
LMCAS
{
4
using namespace
detail::matrix_api
;
5
MatrixNullspaceResult
matrix_nullspace_checked
(
6
const
std::shared_ptr<SymbolicExpr>& A,
7
ComputationContext
&
context
) {
8
const
std::string operation =
"matrix_nullspace"
;
9
auto
matrix =
require_matrix
(A,
context
, operation);
10
if
(!matrix)
return
MatrixNullspaceResult::failure
(matrix.error());
11
auto
nullspace =
detail::nullspace_exact
(
12
exact_matrix_data
(*matrix.value()),
context
, operation);
13
if
(!nullspace)
return
MatrixNullspaceResult::failure
(nullspace.error());
14
return
MatrixNullspaceResult::success
(std::move(nullspace.value()));
15
}
16
17
MatrixNullspaceResult
matrix_nullspace_checked
(
18
const
std::shared_ptr<SymbolicExpr>& A) {
19
ComputationContext
context
;
20
return
matrix_nullspace_checked
(A,
context
);
21
}
22
23
MatrixLinearSolveResult
matrix_solve_linear_checked
(
24
const
std::shared_ptr<SymbolicExpr>& coefficients,
25
const
std::shared_ptr<SymbolicExpr>& right_hand_side,
26
ComputationContext
&
context
) {
27
const
std::string operation =
"matrix_solve_linear"
;
28
auto
matrix =
require_matrix
(coefficients,
context
, operation);
29
if
(!matrix)
return
MatrixLinearSolveResult::failure
(matrix.error());
30
auto
rhs
=
require_matrix
(right_hand_side,
context
, operation);
31
if
(!
rhs
)
return
MatrixLinearSolveResult::failure
(
rhs
.error());
32
if
(
rhs
.value()->rows() != matrix.value()->rows() ||
33
rhs
.value()->cols() != 1) {
34
return
MatrixLinearSolveResult::failure
(
35
CasErrc::InvalidArgument
,
36
"right-hand side must be a matching column matrix"
, operation);
37
}
38
39
detail::ExactMatrixData
augmented{
40
matrix.value()->rows(), matrix.value()->cols() + 1, {}};
41
augmented.
entries
.reserve(augmented.
rows
* augmented.
cols
);
42
for
(std::size_t row = 0; row < augmented.
rows
; ++row) {
43
for
(std::size_t column = 0;
44
column < matrix.value()->cols(); ++column) {
45
augmented.
entries
.push_back(
46
LMCAS::detail::make_expression_ptr
(
47
matrix.value()->get(row, column)));
48
}
49
augmented.
entries
.push_back(
50
LMCAS::detail::make_expression_ptr
(
rhs
.value()->get(row, 0)));
51
}
52
auto
solved =
detail::solve_linear_exact
(
53
std::move(augmented), matrix.value()->cols(),
context
, operation);
54
if
(!solved)
return
MatrixLinearSolveResult::failure
(solved.error());
55
if
(
auto
* unique =
56
std::get_if<detail::UniqueLinearSolution>(&solved.value())) {
57
return
MatrixLinearSolveResult::success
(
58
MatrixUniqueLinearSolution
{std::move(unique->values)});
59
}
60
if
(
auto
* parametric =
61
std::get_if<detail::ParametricLinearSolution>(&solved.value())) {
62
return
MatrixLinearSolveResult::success
(
63
MatrixParametricLinearSolution
{
64
std::move(parametric->particular),
65
std::move(parametric->nullspace_basis),
66
std::move(parametric->free_columns)});
67
}
68
return
MatrixLinearSolveResult::success
(
69
MatrixInconsistentLinearSolution
{});
70
}
71
72
MatrixLinearSolveResult
matrix_solve_linear_checked
(
73
const
std::shared_ptr<SymbolicExpr>& coefficients,
74
const
std::shared_ptr<SymbolicExpr>& right_hand_side) {
75
ComputationContext
context
;
76
return
matrix_solve_linear_checked
(
77
coefficients, right_hand_side,
context
);
78
}
79
80
}
LMCAS::ComputationContext
定义
computation_context.hpp:99
LMCAS::Result< std::vector< std::vector< std::shared_ptr< SymbolicExpr > > > >::failure
static Result failure(CasErrc code, std::string message, std::string operation={})
定义
result.hpp:52
LMCAS::Result< std::vector< std::vector< std::shared_ptr< SymbolicExpr > > > >::success
static Result success(std::vector< std::vector< std::shared_ptr< SymbolicExpr > > > value)
定义
result.hpp:48
LMCAS::detail::matrix_api
定义
symbolic_matrix_support.hpp:8
LMCAS::detail::matrix_api::exact_matrix_data
ExactMatrixData exact_matrix_data(const MatrixNode &matrix)
定义
symbolic_matrix_support.cpp:49
LMCAS::detail::matrix_api::require_matrix
Result< std::shared_ptr< const MatrixNode > > require_matrix(const std::shared_ptr< SymbolicExpr > &expr, ComputationContext &context, const std::string &operation)
定义
symbolic_matrix_support.cpp:5
LMCAS::detail::nullspace_exact
Result< std::vector< std::vector< ExprPtr > > > nullspace_exact(ExactMatrixData coefficients, ComputationContext &context, const std::string &operation)
定义
exact_matrix_solve.cpp:162
LMCAS::detail::make_expression_ptr
std::shared_ptr<::LMCAS::SymbolicExpr > make_expression_ptr(SymbolicNodePtr root)
定义
base.hpp:111
LMCAS::detail::solve_linear_exact
Result< ExactLinearSolution > solve_linear_exact(ExactMatrixData augmented, std::size_t coefficient_columns, ComputationContext &context, const std::string &operation)
定义
exact_matrix_solve.cpp:116
LMCAS
定义
assumption.hpp:11
LMCAS::MatrixLinearSolveResult
Result< MatrixLinearSolution > MatrixLinearSolveResult
定义
symbolic_matrix.hpp:94
LMCAS::context
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
定义
exact_factorization.hpp:65
LMCAS::CasErrc::InvalidArgument
@ InvalidArgument
定义
result.hpp:13
LMCAS::matrix_solve_linear_checked
MatrixLinearSolveResult matrix_solve_linear_checked(const std::shared_ptr< SymbolicExpr > &coefficients, const std::shared_ptr< SymbolicExpr > &right_hand_side, ComputationContext &context)
定义
symbolic_matrix_solve.cpp:23
LMCAS::rhs
const ExprPtr & rhs
定义
expr.hpp:150
LMCAS::MatrixNullspaceResult
Result< std::vector< std::vector< std::shared_ptr< SymbolicExpr > > > > MatrixNullspaceResult
定义
symbolic_matrix.hpp:75
LMCAS::matrix_nullspace_checked
MatrixNullspaceResult matrix_nullspace_checked(const std::shared_ptr< SymbolicExpr > &A, ComputationContext &context)
定义
symbolic_matrix_solve.cpp:5
LMCAS::MatrixUniqueLinearSolution
定义
symbolic_matrix.hpp:78
LMCAS::MatrixInconsistentLinearSolution
定义
symbolic_matrix.hpp:88
LMCAS::MatrixParametricLinearSolution
定义
symbolic_matrix.hpp:82
LMCAS::detail::ExactMatrixData
定义
exact_matrix.hpp:26
LMCAS::detail::ExactMatrixData::rows
std::size_t rows
定义
exact_matrix.hpp:27
LMCAS::detail::ExactMatrixData::cols
std::size_t cols
定义
exact_matrix.hpp:28
LMCAS::detail::ExactMatrixData::entries
std::vector< ExprPtr > entries
定义
exact_matrix.hpp:29
symbolic_matrix_support.hpp
src
symbolic_matrix_solve.cpp
生成于
, 为 LMCAS使用
1.18.0