Commit graph

1900 commits

Author SHA1 Message Date
Christophe de Dinechin
84605bc349 Release 0.7.18 "Who" - Subst, Where, Apply
This release implements the `Apply`, `Subst` and `|` (`Where`) commands.

**Features**

* ui: Allow Shift-SPC to enter `=` in an expression
* Implement `subst` and `where`
* Implement the `Apply` command
* Implement the `EQNLIB` command
* Add `CONSTANTS` as a way to select mathematical constants menu
* Add `CONLIB` as an alias for `ConstantsMenu`.

**Bug fixes**

* solver: Adjust detection of "epsilon" for large values
* ttf2font: Flip x coordinates for dense fonts

**Improvements**

* doc: List commands that will never be implemented

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-16 01:11:54 +02:00
Christophe de Dinechin
3b176a4ac1 ui: Allow Shift-SPC to enter = in an expression
When entering `Shift-SPC` in the expression mode, enter an `=` sign
instead of a program separator (which makes no sense in an expression)

We also reached the stage where we need to switch back to optimizing
for space instead of speed.

Fixes: #1189

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-16 01:11:54 +02:00
Christophe de Dinechin
3c79ef7f9c Implement subst and where
Implement the `subst` and `where` commands.

The `where` command can also be used as an operator `|` in
expressions, for example `'A+B|A=X-3'` will evaluate as `'X-3+B'`.

The HP syntax with parentheses for multiple substitutions, for example
`'A+B|(A=3;B=2)'`, is not implemented in this commit. It can be
replaced with sequences, like `'A+B|A=3|B=2'`.

Fixes: #1187

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-16 01:11:54 +02:00
Christophe de Dinechin
9812e0532f Implement the Apply command
The `Apply` command builds a function expression from a name and an
argument list. For example, `{ 1 2 3} 'F' APPLY` generates a function
call like `'F(1;2;3)'`.

The DB48X `Apply` command is extended compared to the HP48: it accepts
algebraic functions as names, e.g. `{ 'x+y' } 'sin' APPLY` builds a
`'sin(x+y)'` expression.

Fixes: #1185

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-15 18:43:16 +02:00
Christophe de Dinechin
033a767c45 solver: Adjust detection of "epsilon" for large values
Compute the "epsilon" for X and Y axis as follows:

- For the X axis, use the initial range of X
- For the Y axis, use the first computed value for the function

This fixes the original problem in #1179, where the equation was in
the form `f(x)=0`, and we had a heuristic in that case that would
deduce an incorrect epsilon from the right-hand-side value `0`.

That heuristic was implemented to solve equations with very large
values, such as found in physics when dealing for example with
Avogadro number. A simple example would be something like
`1E45*sin(x)=0.5E45`. But the heuristic was depending on being able to
isolate the left and right hand sides. It would fail for example if
the expresion was initially written as `1E45*sin(x)-0.5E45`.

Instead, the new heuristic computes the epsilon for the Y axis from
the first run of the equation. In that case, if the original epsilon
is `1E-18` (which is the default for a `Precision` of 24 digits and a
`SolverImprecision` value of 6), then the target precision will be in
the order of `1E45*1E-18`.

Fixes: #1179

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-15 17:39:39 +02:00
Christophe de Dinechin
d796f31932 Implement the EQNLIB command
This is an alias for the `EquationsMenu`

Fixes: #1184

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-14 00:48:24 +02:00
Christophe de Dinechin
e6d582818b Add CONSTANTS as a way to select mathematical constants menu
On the HP50G, the `CONSTANTS` menu selects "CAS constants".
This seems to approximately match DB48X mathematical constants menus.

Fixes: #1183

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-13 23:58:13 +02:00
Christophe de Dinechin
e791180d14 Add CONLIB as an alias for ConstantsMenu.
Also change `CONSTANTS` to point to the mathematics menu.

Fixes: #1180

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-13 23:16:47 +02:00
Christophe de Dinechin
01927b1c97 Release 0.7.17 "Open" - DoSubs, DoList, entering units
This release adds `DoSubs`, `DoList`, `NSub` and `EndSub` commands, and fixes
related issues that were found with the associated examples in teh HP50G
Advanced Reference Manual.

**Features**

* lists: Implement `DoList`, `DoSubs`, `NSub` and `EndSub`
* units: Add usual "big" units to `Computing` units menu (e.g. KB, MB)
* graphics: Add `Freeze` command
* ui: Make it easier to enter units
* expressions: Accept algebraic forms for `integrate` and `root`
* expressions: Graphical rendering of integrals

**Bug fixes**

* case: Preserve the code for the default case (which was lost before)
* parser: Parse arg-less alegbraic commmands such as `NSub`
* equations: Fix syntax errors in built-in equations, e.g. missing parentheses
* equations: Replace variables that match DB48X command names, e.g. `Re`
* equations: Replace imperial units with SI units, e.g. `in` with `cm`
* units: Reject user-defined functions in unit expressions
* constants: Fix definition for the `qε0` constant

**Improvements**

* Update help about equations with some additional material
* tests: Run through all the builtin equations
* ui: Do not insert an extra space before parentheses in equation
* simulator: Add macOS icons for DB48X and DB50X
* font: Record saved font with `v` update

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-12 00:50:35 +02:00
Christophe de Dinechin
4d7cbf0b3a equations: Add graphical rendering for integrate
Render integrals graphically, in line with sums and products.

Fixes: #1174

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-12 00:50:35 +02:00
Christophe de Dinechin
3ac9ce15d6 constants: Fix definition of the qε0 constant
The definition of the `qε0` constant contains a space, which is
now reported as a syntax error. Also fix the test that incorrectly
accepted a value without the associated unit.

Fixes: #1173

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-12 00:50:35 +02:00
Christophe de Dinechin
b8d2be1425 expressions: Accept algebraic forms for integrate and root
Acceptable syntaxes:

- `‘integrate(1;2;sin(X);X)’` or `‘∫(1;2;sin(X);X)’`

- `‘root(sin(X)-0.5;X;1)’`

Fixes: #1172

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-12 00:50:35 +02:00
Christophe de Dinechin
8330601303 units: Do not accept user functions in unit expressions
Reject something like `1_km(s+N)`

Fixes: #1171

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-12 00:50:35 +02:00
Christophe de Dinechin
60faccd143 ui: Make it easier to enter units
Improve entry for units as follows:

* Add a `unit` mode with `U` as the cursor
* Correctly append unit names after numbers and units
* Same with inverse units
* Let `EEX`/`Cycle` key switch prefix units

Fixes: #1170

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-12 00:50:35 +02:00
Christophe de Dinechin
69605725f5 graphics: Implement Freeze command
The `Freeze` command preserves some specific areas on the screen.
It takes a numerical value as input, which is a combination of bits:

1: Status area
2: Stack / command area
4: Menu area

Note that the refresh algorithm on DB48X is not exaclty similar to how
things work on HP calculators because it's designed for an always-on
e-Ink screen

Fixes; #1169

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-11 10:18:19 +02:00
Christophe de Dinechin
82611a6b77 lists: Implement DoList, DoSubs, NSub and EndSub
Implement the `DoList`, `DoSubs`, `NSub` and `EndSub` commands

Fixes: #1165

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-11 10:18:12 +02:00
Christophe de Dinechin
f2c178aeda case: Do not lose the default condition
The default condition was dropped and replaced with an empty one.

Fixes: #1168

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-09 01:55:35 +02:00
Christophe de Dinechin
9cfca545c2 parser: Parse arg-less alegbraic commmands
Ensure that we can parse algebraic commands that have no argument.
This is useful for `NSUB` and `ENDSUB`.

Fixes: #1167

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-09 01:02:42 +02:00
Christophe de Dinechin
4c75e9c894 equations: Fix syntax errors in built-in equations
Fix various syntax errors in the built-in equations contributed by
@Wiljea.

Also some changes in units:

* use `Ω` (Unicode 937) character instead of `Ω` (Unicode 8486) for
  the Ohm unit. There is a dedicated Unicode codepoint, but since we
  don't use special characters for `m` or `s` units, there is no
  reason we should make things more difficult for Ohm.

* Use metric units consistently, i.e. replace `_lb` with `_kg`, `_in`
  with `_cm`, `_lbf` with `_N` and so on. It might be worth it later
  to make a metric and an imperial variant of this file.

* Use degrees for user angles input in equations.

* Rename variables that are reserved words, e.g. `Re` and `vx`.
  This is because DB48X is by default case-insensitive.
  Note that we could have a prefix character forcing a symbol for
  reserved names (much like we have a prefix for constants).

Fixes: #1162

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-04 12:49:38 +02:00
Christophe de Dinechin
6e9f73ac08 units: Add usual "big" units to Computing units menu
Add units such as kilobytes, etc to the units menu

Fixes: #1163

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-04 12:49:37 +02:00
Christophe de Dinechin
c1e5a906bf tests: Run through all the builtin equations
Parse all the built-in equations to check if there are syntax errors.

Fixes: #1161

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-04 12:49:37 +02:00
Christophe de Dinechin
fc3c46fbda ui: Do not insert an extra space before parentheses in equation
When hitting F F, we expect `'()'` and not `' ()'`.

Fixes: #1160

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-04 12:49:37 +02:00
Christophe de Dinechin
1fd19a423b equations: Remove need to define SINC
The `SINC` function is quite trivial, and the only special case is 0.
Use `IFTE` to special case 0 out and return 1 in that case.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-03 15:58:05 +02:00
Wiljea
d4e3e1070b Update equations.cc
Fix the units for `I` in several equations.

Signed-off-by: Wiljea <143950411+Wiljea@users.noreply.github.com>
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-03 15:54:56 +02:00
Christophe de Dinechin
ba092c2d25 Release 0.7.16 "Clean" - New commands
The focus of this release is on new commands, notably for matrix and vector
operations. This release also ships with a DM48X-specific keymap, which fixes a
problem with teh file selector on the DM32. The equation library has been extended with numerous equations, but they are not fully validated yet.

**Features**

* `con`, `idn` and `ranm` matrix generation commands
* `Array→` and `→Array` commands to convert array to/from stack
* `dot` product and `cross` product commands for vectors
* `DispXY` styled text rendering command
* `DupDup` command duplicating top item twice
* Add a large number of equations to equation library

**Bug fixes**

* Fix `decimal::to_bignum` for small magnitudes
* Return angle unit for `atan2` and `arg` commands
* The `for` loop on lists no longer ends leaving the debugger active
* Interactive stack `DropN` command returns to level 1
* Fix file selector's "New file" on DM32 so that ENTER terminates it
* A few fixes in equations in the equation library

**Improvements**

* Improve graphical rendering of expressions such as multiplication operators
* doc: Update status
* font: Fix `v` glyph vertical placement, add dot and cross glyphs
* ttf2font: Add additional verbose info about source data
* Add `CONSTANTS` as an alias for `ConstantsMenu`
* Replace documentation references to `EEX` with `×10ⁿ`
* Optimize parsing of real numbers in parentheses

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-02 03:22:28 +02:00
Christophe de Dinechin
cf89de6e72 decimal: Fix decimal::to_bignum for small magnitudes
When the decimal value has a negative expoonent, we should not loop
forever building a very large multiplier, and we should not generate a
negative 0 either.

Fixes: #1156
Fixes: #1157

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-02 03:01:10 +02:00
Christophe de Dinechin
b2694b4dcf array: Implement ranm (RandomMatrix) command
The `ranm` command generates a random matrix.

Compared to the HP50G, the DB48X can also generate a random vector
in a way similar to `CON` for constant values.

Fixes: #1155

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-02 02:35:51 +02:00
Christophe de Dinechin
5aff1dc8db array: Implement idn command (IdentityMatrix)
This returns a diagonal matrix with 1 on the diagonal and 0 elsewhere.

Fixes: #1154

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-02 01:58:19 +02:00
Christophe de Dinechin
9d3346e683 array: Implement con (ConstantArray) command
The `con` command (`ConstantArray`) creates a constant array from
dimensions, another array or vector.

Fixes: #1153

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-02 01:53:32 +02:00
Christophe de Dinechin
5e4b661bdd arithmetic: Return angle unit for atan2
Like for `arg`, `atan2` returns an angle.

Fixes: #1151

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-01 15:11:32 +02:00
Christophe de Dinechin
3bb852224b array: Add Array→ and →Array commands
Add commands to expand and construct an array from stack elements.

Fixes: #1150

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-01 15:11:32 +02:00
Christophe de Dinechin
985b8a4619 complex: Return an angle from arg function
The `arg` function now returns an angle in current angle mode.

Fixes: #1149

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-09-01 15:10:18 +02:00
Christophe de Dinechin
c6068d1c37 grob: Render expressions in expression mode
This ensures that we get the right multiplication operators.

Fixes: #1148

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-31 23:16:38 +02:00
Christophe de Dinechin
4d0350b0cd loops: Properly exit for loops on lists
When running a `for` loop on a list, make sure we cleanup properly on
exit.

Fixes: #1147

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-31 23:14:50 +02:00
Christophe de Dinechin
2a38b88600 arrays: Implement dot and cross
Implement dot and cross products.

Fixes: #1145

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-31 23:14:50 +02:00
Christophe de Dinechin
60236d8fc5 font: Fix v glyph vertical placement, add dot and cross glyphs
Fix the vertical bearing of the `v` glyph so that it does not appear
to be one pixel above the others.

Also add glyphs for

* dot-product (`⋅`, U8901)
* cross-product (`⨯`, 10799)

These can be used to refer to the `CROSS` and `DOT` commands.

Fixes: #1117

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-31 17:19:56 +02:00
Christophe de Dinechin
f511df292e graphics: Implement DispXY command
The `DispXY` command on the HP50G takes a font ID that takes 2 values,
1 for small font and 2 for regular font.

In order to implement this in a more easy way, reorder the font IDs so
that they "match", except that 0 gives the even smaller help font and
3 gives the larger editor font.

Fixes: #1146

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-31 01:41:18 +02:00
Christophe de Dinechin
9433f046b5 stack: Implement DupDup command
Implement the `DupDup`, duplicate the top of stack twice.

Fixes: #1144

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-30 22:43:00 +02:00
Christophe de Dinechin
acdb672f3b menus: Add CONSTANTS as an alias for ConstantsMenu
This is for compatibility with the HP50G

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-30 16:26:45 +02:00
Christophe de Dinechin
6af117e8b5 ui: Update interactive pointer on DropN
When dropping stack items, we need to put the interactive pointer at
the bottom since the stack items have been removed.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-30 16:19:49 +02:00
Christophe de Dinechin
709436d095 dm32: Add DB48-specific keymap
Add a DM48 keymap that restores correct keybindings in the file
selector dialog.

Fixes: #1002

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-30 15:51:19 +02:00
Christophe de Dinechin
0c7cef7bc7 library: Equation fixes
Various fixes in equations to avoid errors while parsing them.

Fixes: #1129

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-28 01:38:27 +02:00
Christophe de Dinechin
20c127d064 library: Add larger set of equations
Add a number of new equations to the equation library, contributed by
Jean Wilson.

Fixes: #1129

Co-authored-by: Jean Wilson <srmjwilson@gmail.com>
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-28 01:38:27 +02:00
Christophe de Dinechin
993f84efb8 complex: Fix parsing error when parsing units
When parsing units or expressions with parentheses, turn ERROR into
SKIP to make sure the higher-level selected expression parsing.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-28 01:38:27 +02:00
Christophe de Dinechin
fcbb81dcff Release 0.7.15 "Teaching" - Bug fixes notably on iOS
This release mostly focuses on issues exposed by the iOS releases.
It's a bug-fixes only release.

***Bug fixes***

* ios: Fix a screen refresh bug delaying the display of computation results
* ios: Increase user-accesssible memory for DB50X to match the DM32
* files: Avoid opening two files when a loaded file contains units/constants
* units: Restrict unit expressions further, e.g. forbid `1_km^s`
* build: Do not add unwanted macOS-specific files in release tar files
* build: Remove irrelevant help file from releae tar file
* constants: Fix numerical value for G constant
* tests: Rename `M` demo helper to `D`, since we use `M` in symbolic tests
* makefile: Add `mv` echo to targets doing image comparison
* units: Use pi constant in definition of radians unit
* parser: Detect syntax error on `(inv(x))` in non-expression mode
* units: Avoid infinite loop for bad unit exponents
* files: Avoid crash in `file_closer` if file does not exist
* tests: Add DMS/HMS operations to math demo
* tests: Add keyboard shortcuts to launch the demos

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-25 22:03:42 +02:00
Christophe de Dinechin
97a3252c91 units: Restrict unit expressions further
Only allow exponents with real values, and restrict allowed commands.

Fixes: #1135

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-23 14:38:42 +02:00
Christophe de Dinechin
1ee54c9662 constants: Fix numerical value for G constant
The G constant had a bad definition with `2•kg` instead of `2*kg`.

Fixes; #1128

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-23 11:55:32 +02:00
Christophe de Dinechin
2157a99937 tests: Rename 'M' demo helper to 'D'
The 'M' name is actually used in a number of other tests, where we
expect a symbolic result and get a bug instead.

Renaming to 'D' ensures we don't disrupt those tests if we run them
after a demo.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-23 11:55:22 +02:00
Christophe de Dinechin
ce3faed861 files: Close source files before evaluating them
Since source file evaluation can involve units, constants, etc, we
need to make sure that the file is closed before evaluating it.

Fixes: #1137

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-23 11:55:22 +02:00
Christophe de Dinechin
9fb4489922 units: Use pi constant in definition of radians unit
The `r` unit is now defined as a function of `pi`.

As a side effect, fix parsing of expressions in units, allowing `inv`
to parse correctly in the definition of radians.

Fixes: #1136

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-08-23 11:55:21 +02:00