LMCAS
Lamina Computer Algebra System
Toggle main menu visibility
载入中...
搜索中...
未找到
squared_norm.cpp
浏览该文件的文档.
1
#include "
internal/squared_norm.hpp
"
2
3
namespace
LMCAS::detail
{
4
namespace
{
5
6
const
SymbolicNode
*
square_root_argument
(
const
SymbolicNode
& root) {
7
if
(
const
auto
*
function
=
dynamic_cast<
const
FunctionNode
*
>
(&root)) {
8
if
(
function
->type() ==
FunctionNode::FuncType::Sqrt
&&
function
->arguments().size() == 1) {
9
return
function
->arguments().front().get();
10
}
11
return
nullptr
;
12
}
13
const
auto
* power =
dynamic_cast<
const
PowerNode
*
>
(&root);
14
if
(!power) {
15
return
nullptr
;
16
}
17
const
auto
*
exponent
=
dynamic_cast<
const
NumberNode
*
>
(power->exponent().get());
18
if
(!
exponent
) {
19
return
nullptr
;
20
}
21
const
auto
&
value
=
exponent
->value();
22
const
bool
half = std::holds_alternative<Rational>(
value
) &&
23
std::get<Rational>(
value
) == Rational(1, 2);
24
return
half ? power->base().get() :
nullptr
;
25
}
26
27
const
PowerNode
*
squared_term
(
const
SymbolicNode
*
node
) {
28
const
auto
* power =
dynamic_cast<
const
PowerNode
*
>
(
node
);
29
if
(!power) {
30
return
nullptr
;
31
}
32
const
auto
*
exponent
=
dynamic_cast<
const
NumberNode
*
>
(power->exponent().get());
33
if
(!
exponent
) {
34
return
nullptr
;
35
}
36
const
auto
&
value
=
exponent
->value();
37
const
bool
two = std::holds_alternative<BigInt>(
value
)
38
? std::get<BigInt>(
value
) == BigInt(2)
39
: std::get<Rational>(
value
) == Rational(2);
40
return
two ? power :
nullptr
;
41
}
42
43
}
44
45
std::array<const PowerNode*, 2>
squared_norm_terms
(
const
SymbolicNode
& root) {
46
const
auto
* argument = square_root_argument(root);
47
if
(
const
auto
* single = squared_term(argument)) {
48
return
{single,
nullptr
};
49
}
50
const
auto
* sum =
dynamic_cast<
const
AddNode
*
>
(argument);
51
if
(!sum || sum->operands().size() != 2) {
52
return
{};
53
}
54
const
auto
* first = squared_term(sum->operands()[0].get());
55
const
auto
* second = squared_term(sum->operands()[1].get());
56
return
first && second ? std::array<const PowerNode*, 2>{first, second}
57
: std::array<const PowerNode*, 2>{};
58
}
59
60
}
LMCAS::AddNode
加法节点,表示多个操作数的求和。
定义
arithmetic.hpp:55
LMCAS::FunctionNode
函数节点,表示数学函数调用(三角函数、对数、特殊函数等)。
定义
functions.hpp:10
LMCAS::FunctionNode::FuncType::Sqrt
@ Sqrt
对数、绝对值、平方根。
定义
functions.hpp:16
LMCAS::NumberNode
定义
numbers.hpp:8
LMCAS::PowerNode
幂运算节点,表示 base^exponent。
定义
arithmetic.hpp:218
LMCAS::SymbolicNode
定义
base.hpp:147
LMCAS::detail::anonymous_namespace{squared_norm.cpp}::square_root_argument
const SymbolicNode * square_root_argument(const SymbolicNode &root)
定义
squared_norm.cpp:6
LMCAS::detail::anonymous_namespace{squared_norm.cpp}::squared_term
const PowerNode * squared_term(const SymbolicNode *node)
定义
squared_norm.cpp:27
LMCAS::detail
多元 Hensel 提升(单变量步)
定义
assumption_context.hpp:31
LMCAS::detail::node
const SymbolicNodePtr & node(const ::LMCAS::SymbolicExpr &expression) noexcept
定义
base.hpp:91
LMCAS::detail::squared_norm_terms
std::array< const PowerNode *, 2 > squared_norm_terms(const SymbolicNode &root)
Recognize real-numeric norm forms without evaluating their squares.
定义
squared_norm.cpp:45
LMCAS::exponent
const ExprPtr & exponent
定义
expr.hpp:215
LMCAS::value
const std::string const ExprPtr & value
定义
expr.hpp:293
LMCAS::function
ExprResult function(const std::string &name, std::vector< ExprPtr > arguments)
定义
expr_facade.cpp:135
squared_norm.hpp
src
squared_norm.cpp
生成于
, 为 LMCAS使用
1.18.0