Numworks Epsilon  1.4.1
Graphing Calculator Operating System
sequence.h
Go to the documentation of this file.
1 #ifndef SEQUENCE_SEQUENCE_H
2 #define SEQUENCE_SEQUENCE_H
3 
4 #include "../shared/function.h"
5 #include "sequence_context.h"
6 #include <assert.h>
7 
8 namespace Sequence {
9 
10 class Sequence : public Shared::Function {
11 public:
12  enum class Type {
13  Explicit = 0,
14  SingleRecurrence = 1,
15  DoubleRecurrence = 2
16  };
17  Sequence(const char * text = nullptr, KDColor color = KDColorBlack);
18  ~Sequence();
19  Sequence& operator=(const Sequence& other);
20  Sequence& operator=(Sequence&& other) = delete;
21  Sequence(const Sequence& other) = delete;
22  Sequence(Sequence&& other) = delete;
23  uint32_t checksum() override;
24  Type type();
25  int initialRank() const {
26  return m_initialRank;
27  }
28  const char * firstInitialConditionText();
29  const char * secondInitialConditionText();
30  Poincare::Expression * firstInitialConditionExpression(Poincare::Context * context) const;
31  Poincare::Expression * secondInitialConditionExpression(Poincare::Context * context) const;
32  Poincare::ExpressionLayout * firstInitialConditionLayout();
33  Poincare::ExpressionLayout * secondInitialConditionLayout();
34  /* WARNING: after calling setType, setContent, setFirstInitialConditionContent
35  * or setSecondInitialConditionContent, the sequence context needs to
36  * invalidate the cache because the sequences evaluations might have changed. */
37  void setType(Type type);
38  void setInitialRank(int rank);
39  void setContent(const char * c) override;
40  void setFirstInitialConditionContent(const char * c);
41  void setSecondInitialConditionContent(const char * c);
42  int numberOfElements();
43  Poincare::ExpressionLayout * nameLayout();
44  Poincare::ExpressionLayout * definitionName();
45  Poincare::ExpressionLayout * firstInitialConditionName();
46  Poincare::ExpressionLayout * secondInitialConditionName();
47  bool isDefined() override;
48  bool isEmpty() override;
49  float evaluateAtAbscissa(float x, Poincare::Context * context) const override {
50  return templatedApproximateAtAbscissa(x, static_cast<SequenceContext *>(context));
51  }
52  double evaluateAtAbscissa(double x, Poincare::Context * context) const override {
53  return templatedApproximateAtAbscissa(x, static_cast<SequenceContext *>(context));
54  }
55  template<typename T> T approximateToNextRank(int n, SequenceContext * sqctx) const;
56  double sumBetweenBounds(double start, double end, Poincare::Context * context) const override;
57  void tidy() override;
58  constexpr static int k_initialRankNumberOfDigits = 3; // m_initialRank is capped by 999
59 private:
60  constexpr static double k_maxNumberOfTermsInSum = 100000.0;
61  constexpr static size_t k_dataLengthInBytes = (3*TextField::maxBufferSize()+3)*sizeof(char)+sizeof(int)+1;
62  static_assert((k_dataLengthInBytes & 0x3) == 0, "The sequence data size is not a multiple of 4 bytes (cannot compute crc)"); // Assert that dataLengthInBytes is a multiple of 4
63  char symbol() const override;
64  template<typename T> T templatedApproximateAtAbscissa(T x, SequenceContext * sqctx) const;
65  Type m_type;
66  char m_firstInitialConditionText[TextField::maxBufferSize()];
67  char m_secondInitialConditionText[TextField::maxBufferSize()];
68  mutable Poincare::Expression * m_firstInitialConditionExpression;
69  mutable Poincare::Expression * m_secondInitialConditionExpression;
70  Poincare::ExpressionLayout * m_firstInitialConditionLayout;
71  Poincare::ExpressionLayout * m_secondInitialConditionLayout;
72  Poincare::ExpressionLayout * m_nameLayout;
73  Poincare::ExpressionLayout * m_definitionName;
74  Poincare::ExpressionLayout * m_firstInitialConditionName;
75  Poincare::ExpressionLayout * m_secondInitialConditionName;
76  int m_initialRank;
77 };
78 
79 }
80 
81 #endif
static constexpr int maxBufferSize()
Definition: text_field.h:23
int initialRank() const
Definition: sequence.h:25
#define T(x)
Definition: events.cpp:26
c(generic_all_nodes)
unsigned int uint32_t
Definition: stdint.h:6
double evaluateAtAbscissa(double x, Poincare::Context *context) const override
Definition: sequence.h:52
constexpr KDColor KDColorBlack
Definition: color.h:41
void start()
Definition: rt0.cpp:31
Definition: color.h:6
Definition: app.cpp:7
float evaluateAtAbscissa(float x, Poincare::Context *context) const override
Definition: sequence.h:49