mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 22:00:28 +01:00
[poincare] NormCDF
This commit is contained in:
@@ -93,6 +93,7 @@ poincare_src += $(addprefix poincare/src/,\
|
||||
multiplication.cpp \
|
||||
n_ary_expression.cpp \
|
||||
naperian_logarithm.cpp \
|
||||
norm_cdf.cpp \
|
||||
nth_root.cpp \
|
||||
number.cpp \
|
||||
opposite.cpp \
|
||||
|
||||
@@ -65,6 +65,7 @@ class Expression : public TreeHandle {
|
||||
friend class Multiplication;
|
||||
friend class MultiplicationNode;
|
||||
friend class NaperianLogarithm;
|
||||
friend class NormCDF;
|
||||
friend class NthRoot;
|
||||
friend class Number;
|
||||
friend class Opposite;
|
||||
@@ -274,7 +275,11 @@ protected:
|
||||
assert(children.type() == ExpressionNode::Type::Matrix);
|
||||
return U::Builder(children.childAtIndex(0), children.childAtIndex(1));
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
static Expression UntypedBuilderThreeChildren(Expression children) {
|
||||
assert(children.type() == ExpressionNode::Type::Matrix);
|
||||
return U::Builder(children.childAtIndex(0), children.childAtIndex(1), children.childAtIndex(2));
|
||||
}
|
||||
|
||||
template<class T> T convert() const {
|
||||
/* This function allows to convert Expression to derived Expressions.
|
||||
|
||||
@@ -72,6 +72,7 @@ public:
|
||||
Logarithm,
|
||||
MatrixTrace,
|
||||
NaperianLogarithm,
|
||||
NormCDF,
|
||||
NthRoot,
|
||||
Opposite,
|
||||
Parenthesis,
|
||||
|
||||
52
poincare/include/poincare/norm_cdf.h
Normal file
52
poincare/include/poincare/norm_cdf.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef POINCARE_NORMCDF_H
|
||||
#define POINCARE_NORMCDF_H
|
||||
|
||||
#include <poincare/approximation_helper.h>
|
||||
#include <poincare/expression.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class NormCDFNode final : public ExpressionNode {
|
||||
public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(NormCDFNode); }
|
||||
int numberOfChildren() const override;
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const override {
|
||||
stream << "NormCDF";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::NormCDF; }
|
||||
Sign sign(Context * context) const override { return Sign::Positive; }
|
||||
Expression setSign(Sign s, ReductionContext reductionContext) override;
|
||||
|
||||
private:
|
||||
// Layout
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
// Simplication
|
||||
Expression shallowReduce(ReductionContext reductionContext) override;
|
||||
LayoutShape leftLayoutShape() const override { return LayoutShape::MoreLetters; };
|
||||
LayoutShape rightLayoutShape() const override { return LayoutShape::BoundaryPunctuation; }
|
||||
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, complexFormat, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, complexFormat, angleUnit); }
|
||||
template<typename T> Evaluation<T> templatedApproximate(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
};
|
||||
|
||||
class NormCDF final : public Expression {
|
||||
public:
|
||||
NormCDF(const NormCDFNode * n) : Expression(n) {}
|
||||
static NormCDF Builder(Expression child0, Expression child1, Expression child2) { return TreeHandle::FixedArityBuilder<NormCDF, NormCDFNode>(ArrayBuilder<TreeHandle>(child0, child1, child2).array(), 3); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("normcdf", 3, &UntypedBuilderThreeChildren<NormCDF>);
|
||||
Expression shallowReduce(ExpressionNode::ReductionContext reductionContext);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -51,6 +51,7 @@
|
||||
#include <poincare/matrix_transpose.h>
|
||||
#include <poincare/multiplication.h>
|
||||
#include <poincare/naperian_logarithm.h>
|
||||
#include <poincare/norm_cdf.h>
|
||||
#include <poincare/nth_root.h>
|
||||
#include <poincare/number.h>
|
||||
#include <poincare/opposite.h>
|
||||
|
||||
46
poincare/src/norm_cdf.cpp
Normal file
46
poincare/src/norm_cdf.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <poincare/norm_cdf.h>
|
||||
#include <poincare/layout_helper.h>
|
||||
#include <poincare/serialization_helper.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
constexpr Expression::FunctionHelper NormCDF::s_functionHelper;
|
||||
|
||||
int NormCDFNode::numberOfChildren() const { return NormCDF::s_functionHelper.numberOfChildren(); }
|
||||
|
||||
Expression NormCDFNode::setSign(Sign s, ReductionContext reductionContext) {
|
||||
assert(s == Sign::Positive);
|
||||
return NormCDF(this);
|
||||
}
|
||||
|
||||
Layout NormCDFNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
return LayoutHelper::Prefix(NormCDF(this), floatDisplayMode, numberOfSignificantDigits, NormCDF::s_functionHelper.name());
|
||||
}
|
||||
|
||||
int NormCDFNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, NormCDF::s_functionHelper.name());
|
||||
}
|
||||
|
||||
Expression NormCDFNode::shallowReduce(ReductionContext reductionContext) {
|
||||
return NormCDF(this).shallowReduce(reductionContext);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Evaluation<T> NormCDFNode::templatedApproximate(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
|
||||
//TODO LEA
|
||||
return Complex<T>::Builder(0.0);
|
||||
}
|
||||
|
||||
Expression NormCDF::shallowReduce(ExpressionNode::ReductionContext reductionContext) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
//TODO LEA
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -120,6 +120,7 @@ private:
|
||||
&NaperianLogarithm::s_functionHelper,
|
||||
&CommonLogarithm::s_functionHelper,
|
||||
&Logarithm::s_functionHelper,
|
||||
&NormCDF::s_functionHelper,
|
||||
&PermuteCoefficient::s_functionHelper,
|
||||
&SimplePredictionInterval::s_functionHelper,
|
||||
&PredictionInterval::s_functionHelper,
|
||||
|
||||
@@ -316,6 +316,7 @@ template MatrixTrace TreeHandle::FixedArityBuilder<MatrixTrace, MatrixTraceNode>
|
||||
template MatrixTranspose TreeHandle::FixedArityBuilder<MatrixTranspose, MatrixTransposeNode>(TreeHandle*, size_t);
|
||||
template Multiplication TreeHandle::NAryBuilder<Multiplication, MultiplicationNode>(TreeHandle*, size_t);
|
||||
template NaperianLogarithm TreeHandle::FixedArityBuilder<NaperianLogarithm, NaperianLogarithmNode>(TreeHandle*, size_t);
|
||||
template NormCDF TreeHandle::FixedArityBuilder<NormCDF, NormCDFNode>(TreeHandle*, size_t);
|
||||
template NthRoot TreeHandle::FixedArityBuilder<NthRoot, NthRootNode>(TreeHandle*, size_t);
|
||||
template Opposite TreeHandle::FixedArityBuilder<Opposite, OppositeNode>(TreeHandle*, size_t);
|
||||
template Parenthesis TreeHandle::FixedArityBuilder<Parenthesis, ParenthesisNode>(TreeHandle*, size_t);
|
||||
|
||||
Reference in New Issue
Block a user