1#ifndef CPROVER_PYTHON_FRONTEND_PYTHON_MATH_H
2#define CPROVER_PYTHON_FRONTEND_PYTHON_MATH_H
7#include <nlohmann/json.hpp>
11#include <unordered_map>
32 mutable std::unordered_map<std::string_view, const symbolt *>
40 exprt resolve_symbol(
const exprt &operand)
const;
49 std::optional<BigInt> try_fold_int_constant(
const exprt &expr)
const;
53 exprt promote_to_double_if_needed(
exprt operand)
const;
56 exprt build_unary_c_math_call(
58 const char *display_name,
60 const nlohmann::json &element);
65 get_c_math_symbol_cached(
const char *
symbol_id,
const char *display_name);
99 const std::string &caller,
100 const std::string &func_name)
const;
113 const std::string &caller,
114 const std::string &func_name);
129 std::string_view func_name,
131 const nlohmann::json &element);
141 std::string_view func_name,
144 const nlohmann::json &element);
250 const exprt &bin_expr);
377 const nlohmann::json &element);
379 const typet ÷nd_type,
380 const typet &divisor_type,
381 const nlohmann::json &element);
static const twodig_t base
Definition bigint.cpp:28
Main converter for transforming Python AST into ESBMC's intermediate representation.
Definition python_converter.h:76
exprt handle_fabs(exprt operand, const nlohmann::json &element)
Handle absolute value for floats (math.fabs).
Definition python_math.cpp:1322
exprt handle_hypot(exprt lhs, exprt rhs, const nlohmann::json &element)
Handle hypot function (math.hypot).
Definition python_math.cpp:1538
exprt handle_acosh(exprt operand, const nlohmann::json &element)
Handle acosh function (math.acosh).
Definition python_math.cpp:1516
exprt handle_cosh(exprt operand, const nlohmann::json &element)
Handle hyperbolic cosine function (math.cosh).
Definition python_math.cpp:1439
exprt handle_atan2(exprt y_operand, exprt x_operand, const nlohmann::json &element)
Handle two-argument arctangent function (math.atan2).
Definition python_math.cpp:1253
exprt handle_log10(exprt operand, const nlohmann::json &element)
Handle base-10 logarithm function (math.log10).
Definition python_math.cpp:1461
exprt handle_asin(exprt operand, const nlohmann::json &element)
Handle arcsine function (math.asin).
Definition python_math.cpp:1417
exprt handle_asinh(exprt operand, const nlohmann::json &element)
Handle asinh function (math.asinh).
Definition python_math.cpp:1505
static const BigInt kMaxConstantFoldExponent
Definition python_math.h:85
bool is_math_dispatch_target_cached(const std::string &caller, const std::string &func_name)
Cached variant of is_math_dispatch_target.
Definition python_math.cpp:206
exprt handle_fmod(exprt lhs, exprt rhs, const nlohmann::json &element)
Handle floating-point remainder (math.fmod).
Definition python_math.cpp:1356
python_math(python_converter &conv, contextt &ctx, type_handler &th)
Constructor.
Definition python_math.cpp:149
exprt handle_sinh(exprt operand, const nlohmann::json &element)
Handle hyperbolic sine function (math.sinh).
Definition python_math.cpp:1428
exprt handle_power_symbolic(exprt base, exprt exp)
Handle power operation symbolically using C's pow() function.
Definition python_math.cpp:511
exprt handle(std::string_view func_name, exprt operand, const nlohmann::json &element)
Dispatch supported unary math functions through a single entrypoint.
Definition python_math.cpp:244
exprt handle_dist(exprt p, exprt q, const nlohmann::json &element)
Handle dist function (math.dist) for tuple arguments.
Definition python_math.cpp:1562
exprt handle_pow(exprt base, exprt exp, const nlohmann::json &element)
Handle power function (math.pow).
Definition python_math.cpp:1298
exprt handle_acos(exprt operand, const nlohmann::json &element)
Handle arccosine function (math.acos).
Definition python_math.cpp:1231
exprt build_power_expression(const exprt &base, const BigInt &exp)
Build power expression using exponentiation by squaring.
Definition python_math.cpp:525
void promote_int_to_float(exprt &op, const typet &target_type) const
Promote integer expression to floating-point type.
Definition python_math.cpp:934
std::optional< double > try_resolve_constant_double(const exprt &operand) const
Resolve a constant-like expression (constant or constant-valued symbol) to a host double when possibl...
Definition python_math.cpp:395
exprt handle_trunc(exprt operand, const nlohmann::json &element)
Handle truncate to integer towards zero (math.trunc).
Definition python_math.cpp:1333
exprt handle_sqrt(exprt operand, const nlohmann::json &element)
Handle square root operation (math.sqrt).
Definition python_math.cpp:983
exprt handle_exp2(exprt operand, const nlohmann::json &element)
Handle exp2 function (math.exp2).
Definition python_math.cpp:1494
bool is_unary_dispatch_function(std::string_view func_name) const
Return true when func_name is handled by unary math dispatch.
Definition python_math.cpp:227
exprt handle_floor_division(const exprt &lhs, const exprt &rhs, const exprt &bin_expr)
Handle Python's floor division operator (//).
Definition python_math.cpp:744
exprt handle_divmod(exprt dividend, exprt divisor, const nlohmann::json &element)
Handle divmod() built-in function.
Definition python_math.cpp:1031
exprt handle_atan(exprt operand, const nlohmann::json &element)
Handle arctangent function (math.atan).
Definition python_math.cpp:1242
exprt handle_atanh(exprt operand, const nlohmann::json &element)
Handle atanh function (math.atanh).
Definition python_math.cpp:1527
static bool fits_in_width(const BigInt &value, unsigned width, bool is_signed)
Definition python_math.cpp:173
exprt handle_copysign(exprt lhs, exprt rhs, const nlohmann::json &element)
Handle copy sign (math.copysign).
Definition python_math.cpp:1380
exprt handle_tanh(exprt operand, const nlohmann::json &element)
Handle hyperbolic tangent function (math.tanh).
Definition python_math.cpp:1450
exprt handle_sin(exprt operand, const nlohmann::json &element)
Handle sine function (math.sin).
Definition python_math.cpp:1187
exprt handle_cos(exprt operand, const nlohmann::json &element)
Handle cosine function (math.cos).
Definition python_math.cpp:1198
exprt handle_log2(exprt operand, const nlohmann::json &element)
Handle base-2 logarithm function (math.log2).
Definition python_math.cpp:1279
exprt handle_log1p(exprt operand, const nlohmann::json &element)
Handle log1p function (math.log1p).
Definition python_math.cpp:1483
void handle_float_division(exprt &lhs, exprt &rhs, exprt &bin_expr) const
Handle Python's true division operator (/).
Definition python_math.cpp:877
exprt handle_power(exprt lhs, exprt rhs)
Handle Python's power operator (**).
Definition python_math.cpp:606
exprt handle_modulo(exprt lhs, exprt rhs, const nlohmann::json &element)
Handle Python's modulo operator (%).
Definition python_math.cpp:704
static BigInt pow_bigint_non_negative(BigInt base, BigInt exp)
Definition python_math.cpp:157
exprt handle_exp(exprt operand, const nlohmann::json &element)
Handle exponential function (math.exp).
Definition python_math.cpp:1209
exprt handle_log(exprt operand, const nlohmann::json &element)
Handle natural logarithm function (math.log).
Definition python_math.cpp:1220
exprt handle_tan(exprt operand, const nlohmann::json &element)
Handle tangent function (math.tan).
Definition python_math.cpp:1406
exprt compute_expr(const exprt &expr) const
Fold a +,-,*,/ expression to a constant when it is genuinely one.
Definition python_math.cpp:382
exprt handle_numeric_divmod(exprt dividend, exprt divisor, const nlohmann::json &element)
Definition python_math.cpp:1063
exprt handle_expm1(exprt operand, const nlohmann::json &element)
Handle expm1 function (math.expm1).
Definition python_math.cpp:1472
bool is_binary_dispatch_function(std::string_view func_name) const
Return true when func_name is handled by binary math dispatch.
Definition python_math.cpp:238
exprt handle_int_modulo(const exprt &lhs, const exprt &rhs, const exprt &bin_expr)
Handle Python's integer modulo operator (%).
Definition python_math.cpp:824
exprt raise_divmod_type_error(const typet ÷nd_type, const typet &divisor_type, const nlohmann::json &element)
The TypeError is planted as a statement ahead of the call, and an (int, int) tuple stands in for the ...
Definition python_math.cpp:1011
exprt handle_power_symbolic_exponent(exprt lhs, exprt rhs)
An integer power whose exponent is not a constant: pow(), or the bits of 2.0 ** n for a base of 2.
Definition python_math.cpp:596
bool is_math_dispatch_target(const std::string &caller, const std::string &func_name) const
Classify whether a call should be handled by math dispatch.
Definition python_math.cpp:184
Definition type_handler.h:113
double exp(double x)
Definition exp.c:84