Commit Graph

4054 Commits

Author SHA1 Message Date
Gabriel Ozouf
ddbe76fec5 [poincare/unit] Add missing additonal results
Additional results are proposed for all units combinations that include
a non-base unit, in addition to units with special results.

Change-Id: I91f2a1a43c72bad0327132396534a223e87b06a2
2020-11-04 15:33:01 +01:00
Gabriel Ozouf
4e771fdb54 [poincare/unit] Missing prefix reset
When tuning the representative without tuning the prefix, the prefix
would not be reset to its default value, causing a problem for masses,
whose base prefix depend on the representative (k for grams, none for
the rest).
Fixes a crash when typing sqrt(_N) with country set to US.

Change-Id: Iade900de5fb31e06fdfafef34ae27da3f36983fa
2020-11-04 15:33:01 +01:00
Gabriel Ozouf
d862d5503c [poincare/unit] Fix rational exponent rounding
In metric, sqrt(N) would be simplified to _N_kg^-0.5_m^-0.5_s instead of
_kg^0.5_m^0.5_s^-1.
We solve this issue by preventing simplification using derived units
in presence of rational exponents.

Change-Id: I97118bb32c963809c8d176b7b297d1682965e9af
2020-11-04 15:33:01 +01:00
Hugo Saint-Vignes
073893ae48 [poincare] Exact undef results with GCD and LCM
Change-Id: Iba39cd6140d8ef5b3fd24e0f53c9e28fbd57d438
2020-11-04 15:33:01 +01:00
Hugo Saint-Vignes
a89878a24d [poincare] Allow more BinomialCoefficient exact results
Change-Id: I9dbbf9471ee6d9e12fe4861a5b11990858382562
2020-11-04 15:33:01 +01:00
Gabriel Ozouf
857ca4eecd [poincare/trigonometry] Fix wrong use of pi
In Trigonometry::shallowReduceInverseFunction, the reduction of
atan(1/x) used the hard value of pi instead of its equivalent in the
selected angle unit.
This fixes a bug causing atan(1/tan(40°)) to be equal to π/2-40 instead
of 50.

Change-Id: Ifd7df5cd168fadf3146eee168c0bc2136ea15a7b
2020-11-04 15:33:01 +01:00
Hugo Saint-Vignes
91d9438421 [poincare] Fix forbidden array access
Change-Id: I3de76c114f6712ee08007601766577d87ed96877
2020-11-04 15:33:01 +01:00
Gabriel Ozouf
4bde3ed4b0 [poincare/solver] Fix type ambiguity warning
Change-Id: I9248080520d6fa6430dddb8811dbd0120fc08d79
2020-11-04 15:33:00 +01:00
Gabriel Ozouf
3f19d66c78 [poincare/unit] Change temperature symbols
Celsius and Fahrenheit now use the degree symbol °.
  _Cel -> _°C
  _Fah -> _°F

Change-Id: Ic5935d3a6263a556692bebb6254b6b6d4de48431
2020-11-04 15:33:00 +01:00
Gabriel Ozouf
67e6e38825 [poincare/parsing] Parse degree sign ° in units
Change-Id: I518aba17214b049dfa8fd3b89f4ce124dbd6b41a
2020-11-04 15:33:00 +01:00
Gabriel Ozouf
d37540f032 [poincare/unit] Add Celsius and Fahrenheit
Temperatures can be converted to and from degree Celsius and Fahrenheit.
When used in non-trivial calculations, they are always reduced to undef,
as the rules for manipulating relative scales are not well defined.

Change-Id: If59e224a0e7f940b421bc894bbe2279c90f38d04
2020-11-04 15:33:00 +01:00
Arthur Camouseigt
960335c330 [Sequences] Fixed a few crashes
Change-Id: Ib929bbae0f9ca06409706336ff799075e1288694
2020-11-04 15:32:59 +01:00
Arthur Camouseigt
913c81a0d3 [solver] Modified the way to solve some equations
The solutions of equations that need numerical approximations to be
solved are now computed base on the undeveloped equation (instead of
fully the expended one used to identify polynomials)

This allow (x-10)^7=0 to yield x=10 as result (9.95 before)
Change-Id: Ia8acbe57a9cfebf0b5016e9c896d21c8ddac7a64
2020-11-04 15:32:59 +01:00
Gabriel Ozouf
6e9a5a010f [poincare/integer] Add tests on euclidean division
This commit also adds tests on mixed fractions.

Change-Id: I0fee88eb00febccaa9445230f8f2bbb92cd1ba98
2020-11-04 15:32:59 +01:00
Gabriel Ozouf
bad21f0ab5 [poincare/integer] Fix negative mixed fraction
Mixed fractions for negative rational numbers are now computed as the
opposite of their opposite's mixed fraction, as is conventionnal.
ex : -9/5 is now decomposed as -1-4/5 instead of -2+1/5

Change-Id: I6df3dce585ccadd1bcd7cc562576995face98f9c
2020-11-04 15:32:59 +01:00
Arthur Camouseigt
fa0e8de0a9 [VariableBoxController] Changed the way sequences appear
Change-Id: I45a1cb01ab9c5aefd298c40050e69850a4cc5c71
2020-11-04 15:32:58 +01:00
Arthur Camouseigt
1d71a14d2c [Context] Modifying context method signature for sequences
This allows sequences to be used in functions by calling u(x)

Change-Id: I336e84a19bf9b3dd0f2e435d1aaebda3c9e71ec8
2020-11-04 15:32:58 +01:00
Arthur Camouseigt
3dca515441 [VariableBox] Added sequences to the variable box
It is now possible to call the value of a defined sequence anywhere.

Change-Id: I1990e93c50f9add175b7ea274e07004ba63289e5
2020-11-04 15:32:58 +01:00
Arthur Camouseigt
c006ed7b10 [Sequence & Shared] Changed the location of various files
Moved sequences files to shared in order to allow the system to compile
without the app sequence.

Change-Id: Ia8349814a72776244acc41af964059f24e58cff0
2020-11-04 15:32:58 +01:00
Arthur Camouseigt
ed358590ce [Sequence] Changed the way sequences are parsed
Change-Id: If19b46a317e4f336ac857690827ab08e147ac75a
2020-11-04 15:32:58 +01:00
Arthur Camouseigt
8434da60ef [sequence] Changed sequences behavior
Sequences can now be defined using specific terms form other sequences :
Un = n
Vn = u(3)

Initial values can also depend on other sequences.
Should there be a circular dependency, the sequences concerned will
display "undef" as value

Change-Id: I6fe1f3ff7b500f35d480ddefb42de729c327432e
2020-11-04 15:32:58 +01:00
Gabriel Ozouf
d917b2e1c9 [poincare/unit_convert] Fix improper reduction
In UnitConvert::shallowBeautify, an orphan expression would be reduced
without reaffecting the reduction's result. The reduction not being
taken into account would cause problem when handling undef values.
ex : Try to calculate i->_min

Change-Id: I4e53afa40ba838fed8c2fba9944c9c9ed1dc95b4
2020-11-04 15:30:53 +01:00
Arthur Camouseigt
1995781a9f [Poincare/IEEE754] Changed methods to use std function
Implemented std::nextafter to replace hand made one.
Methods next and previous are no longer making the difference between -0
and +0

Change-Id: I42e1a073623b70656d9df954694803840cf3088c
2020-11-04 15:30:53 +01:00
Arthur Camouseigt
ae43ec0cc9 [Poincare/layouts] Fixed a crash due to infinite loop
Change-Id: Ieb6563dd978c5c363326163b983b40ed13dab913
2020-11-04 15:30:53 +01:00
Gabriel Ozouf
0ed0cc56e9 [poincare] Remove characteristicXHalfRange
Method characteristicXHalfRange was used to compute the range on which
to display cartesian function in Graph. With the new zoom algorithm,
this method is deprecated.

Change-Id: Ic681fab8d58d0f5628a94302a7b49dacaaa1a6a3
2020-11-04 15:30:53 +01:00
Gabriel Ozouf
1917999f6d [poincare/unit] Fix crash with Units in Graph
In Graph, the weak ReductionTarget would cause _X^0 to not be simplified
to 1, and would break an assertion in
Unit::chooseBestRepresentativeAndPrefix.

Change-Id: I8167a472802baf0a73bf48513f492e78517107ef
2020-11-04 15:30:53 +01:00
Gabriel Ozouf
d6c7b2b1ac [poincare/multiplication] Factoring undef power
When factoring 1^inf * 1^-inf with Multiplication::factorizeBase, an
Undef factor would appear an be carried into the reduced multiplication.
We escape early in this situation by returning Undef.

Change-Id: Id826ad3cc131349e5bb460f7a8c82fe606294b97
2020-11-04 15:30:53 +01:00
Gabriel Ozouf
db4a1b0265 [poincare/tests] Add tests on power layout
Change-Id: Ic7b0fbf87eec528221a4f836d34e1736e219ab96
2020-11-04 15:11:45 +01:00
Gabriel Ozouf
7c27440916 [poincare/layout] Tracking issue in addSibling
The addSibling method sometimes did not take into account the offset
introduced by adding parentheses, leading to some issues :
  - Type 2 SQUARE RIGHTPARENTHESIS LEFT SQUARE. Parentheses are added
    but the new square should be outside, between the two right
    parentheses.

Change-Id: Ifbc49cee2cd03c4511fc5a678d6d5d42243f4a22
2020-11-04 15:11:45 +01:00
Gabriel Ozouf
be8e452285 [poincare/layout_cursor] Fix cursor after Square
When typing Square in 2D Edition mode, the cursor would not be
repositionned correctly, leading to some issues :
  - Typing 2 POW 3, pressing RIGHT to return to the baseline, then
    typing POW again adds parentheses around 2^3, as is mathematically
    correct. Typing 2 SQUARE, then POW, would show 2^2^_, while
    the user really typed (2^2)^_.

Change-Id: I29c01d964924907a1866490189ea56e40771521d
2020-11-04 15:11:45 +01:00
Gabriel Ozouf
ec6ee82b81 [poincare/multiplication] Imperial volume display
With the imperial system selected, volumes are expressed as volume in
Calculation's results, instead of cubic lengths.

Change-Id: Ib6c0a1a595dce8ae8db6371b41af818b3fdc6236
2020-11-04 15:11:45 +01:00
Gabriel Ozouf
860ce558c2 [poincare/unit] Remove some additional results
Imperial additional results now only appear when the selected unit
system is Imperial.

Change-Id: Icc314d0148810bea67e4d729179393f1fceaf214
2020-11-04 15:11:45 +01:00
Gabriel Ozouf
801c61549c [poincare/unit] Change units for volume split
In additional outputs, a volume is now splitted as :
  _gal+_qt+_pt+_cup
instead of :
  _gal+_cup+_floz

Change-Id: I5020afbab23be6331d8a8742fd6295db178f0b37
2020-11-04 15:11:45 +01:00
Gabriel Ozouf
5e06f62ff6 [poincare/unit] Symbols for cup and tablespoon
_cp   -> _cup
_Tbsp -> _tbsp

Change-Id: Ied3e1624edc980f76c2f775cbb9e6028db8a83c5
2020-11-04 15:11:45 +01:00
Gabriel Ozouf
52dcd8e749 [poincare/unit] Restructure Unit
1. Information about a unit's dimension now uses inheritance.
   _m is an instance of DistanceAlias, which is derived from Alias.
   A UnitNode now keeps a pointer to an Alias and one to a Prefix.
   All aliases are still defined as constexpr.
   This cleans up a lot of the code used namely for computing the
   additional outputs in Calculation.

2. Instead of being defined with a string, each unit is described by its
   ratio with the base SI unit (ex: _L is 0.001 instead of "0.001_m^3").
   This greatly speeds up the calculations using units, as the algorithm
   to find the best unit used to parse the definition.

Change-Id: I4d6ed6ad4cb967026a3f01a335aec270066e2b9f
2020-11-04 15:11:45 +01:00
Gabriel Ozouf
e48e826536 [poincare/test] Updated tests on units
Change-Id: I7c146174bcedcccc3ed31a298c9720aa2a5ba3a9
2020-11-04 15:11:45 +01:00
Gabriel Ozouf
1f3c4b66a0 [poincare/unit] Changed imperial units definitions
Imperial units are now defined directly from the base unit, instead of
building on one another.

Change-Id: Ieb020643983ef49092d2d3033a7cc2135c646015
2020-11-04 15:11:45 +01:00
Gabriel Ozouf
f288573db0 [apps/unit] Add short and long tons
Change-Id: Ib48c6a7c773e9e1d18c9f55e6dda5330fe0a28f9
2020-11-04 15:11:44 +01:00
Gabriel Ozouf
284c501532 [apps/unit] Add restriction to some input prefixes
The symbol for pint (_pt) conflicts with the symbol for pico-tonne. To
solve that, prefixes for tonnes are now restricted to the positive
prefixes : k, M, G, T.

Change-Id: Ie968374bbb5e0ebd2c0f08e4b1bdc1708eb6a041
2020-11-04 15:11:44 +01:00
Gabriel Ozouf
fad375c11c [poincare] Add unitFormat to ReductionContext
Change-Id: I1d3fcd2f47c973c041e1be84e9a902dd58de3562
2020-11-04 15:11:44 +01:00
Gabriel Ozouf
6c676782aa [apps/calculation] New additional results on units
The additional results on units now include conversions into both unit
systems (metric and imperial).

Change-Id: Ie0f12eb3735e775560b66c2cbd78bc9a659145bb
2020-11-04 15:11:44 +01:00
Gabriel Ozouf
3ff25fb5c1 [poincare/unit] Standard unit methods
Added methods to return the standard format for each dimension,
depending on the chosen unit system.

Change-Id: I3591a806beca315674cc09093b57e8753db5db6a
2020-11-04 15:11:44 +01:00
Gabriel Ozouf
9f40e45b20 [poincare/unit] Split for several dimensions
A split (such as _h+_min+_s) can now be generated for distances, volumes
and masses using imperial units.

Change-Id: Ib3ad63614979eddd02fbe0e99f16cf09dcf7c1fc
2020-11-04 15:11:44 +01:00
Gabriel Ozouf
4d9f3aae97 [poincare/unit] Generalized BuildTimeSplit method
BuildTimesplit (used to create expressions of the form h+min+s) is now
based on the more general BuildSplit.

Change-Id: I3e55359cc6b9735269140942b29bd1d364fc35e7
2020-11-04 15:11:44 +01:00
Gabriel Ozouf
5a31a6c1e2 [poincare/unit] Output units based on region
When the country is USA, the units will be simplified to common imperial
units rather than metric.

Change-Id: Ia533527a429ac26526380e324b9543b359f3b400
2020-11-04 15:11:44 +01:00
Gabriel Ozouf
e2a6edd78f [poincare/preferences] Added UnitFormat preference
The UnitFormat can either be Imperial (for the US) or Metric (for the
rest of the world.

Change-Id: Ic698e6732f1fa225d88a14e61751b775fe70f1ab
2020-11-04 15:11:44 +01:00
Gabriel Ozouf
4d6682e211 [poincare/unit] Added imperial units
The new units are :
  distance    mile, yard, foot, inch
  mass        pound, ounce
  volume      gallon, quart, pint, cup, fluid ounce
              table spoon, tea spoon

Change-Id: I6864067a1822a077764ed3b61fc46004732e9447
2020-11-04 15:11:44 +01:00
Gabriel Ozouf
0a7833ec3d [poincare/test] Added 0*inf*π = undef test
Change-Id: Ie18e75c3cfd2a39f8436405f1061ba8fc5317b7f
2020-11-04 15:11:44 +01:00
Gabriel Ozouf
206013f2db [poincare/multiplication] Return Undef early
Multiplication::privateShallowReduce can create an Undef node by
multiplying 0 and inf. In this case, we set the whole multiplication to
undef, to avoid things such as undef*π.
This fixes the following bug :
  - In Graph, enter i*inf*π as one of the bounds. An assertion fails in
    Multiplication::removeUnit.

Change-Id: Ie9d0d561d6e310f52220b98541f22a4b5e56762c
2020-11-04 15:11:44 +01:00
Arthur Camouseigt
58b69c2779 [AbsoluteValue] Adding formal derivate to absolute value
This will prevent diff(|x|, x, 0) to be evaluated to 0 instead of undef
This fixes issue #1393
Change-Id: I73f40aa29f04c373cd3e9edbbd4fbe7be6d7a988
2020-11-04 15:11:44 +01:00