SmartMath Plugin - Real-time Calculations in AkelPad
- Author
- Message
-
Offline
- Posts: 1334
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: SmartMath Plugin - Real-time Calculations in AkelPad
Latest changes:
- correcting `sin`, `cos`, `tan` to return exactly 0 where appropriate;
- fixed: invalid user-defined functions did not report an error;
- corrections for `NaN` in comparisons;
- optimizing comparison and bitwise operators (identifying operators by numeric Id instead of string);
- correcting: `int`, `ceil` etc. reject `Inf` and `NaN` arguments;
- new: `rad` and `deg` as a trailing command, similarly to `hex`;
- some code cleanup in "SmartMath.bas".
Still TODO:
- reduce blinking while the calculation results are displayed.
(Actually, it is possible to reduce the number of repaint operations - but, in that case, the calculation results look worse, as if several paint operations are superimposed on one another. This does not look clean and sharp).
- correcting `sin`, `cos`, `tan` to return exactly 0 where appropriate;
- fixed: invalid user-defined functions did not report an error;
- corrections for `NaN` in comparisons;
- optimizing comparison and bitwise operators (identifying operators by numeric Id instead of string);
- correcting: `int`, `ceil` etc. reject `Inf` and `NaN` arguments;
- new: `rad` and `deg` as a trailing command, similarly to `hex`;
- some code cleanup in "SmartMath.bas".
Still TODO:
- reduce blinking while the calculation results are displayed.
(Actually, it is possible to reduce the number of repaint operations - but, in that case, the calculation results look worse, as if several paint operations are superimposed on one another. This does not look clean and sharp).
-
Offline
- Posts: 1334
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: SmartMath Plugin - Real-time Calculations in AkelPad
Latest news:
- SmartMath preserves 64-bit integer accuracy during calculations when possible;
- SmartMath preserves 64-bit integer accuracy of input values in a form like `1e18` and even `0.1234e6`;
- while validating a user-defined function, its parameters no more use global variables with the same name (see "User-Defined Functions Validation" inside the "USAGE_AND_SYNTAX.md").
SmartMath is expected to give you strong guarantee of preserving 64-bit integer accuracy during calculations when possible.
Thus, the result of e.g. `2**63 + 2**62` and `(2**63 - 1) << 1` is an accurate integer value.
This was a part of the initial design of SmartMath'es expression parser and evaluator. It was stated in both "USAGE_AND_SYNTAX.md" and in the "add-mathparser-function" skill for AI.
However, I had to manually re-check each operation and function to ensure they really preserve the 64-bit integer accuracy when possible (because not all of them actually did). It's a good example of the magic of AI-driven development
Whatever you tell it to do, you always must verify the results. And not just the output results, but also the way how AI implemented that. While AI does amazing job in performing exact tasks, it still needs to be controlled to not do stupid things and to apply the most appropriate approach.
Given that, how I can be sure the implementation of SmartMath'es expression parser and evaluator matches the expectations? Well, we have almost 1000 tests that cover most of its functionality. And we always can add more to fix the exact behavior!
The most recent "USAGE_AND_SYNTAX.md" is here:
https://github.com/d0vgan/AkelPad-Smart ... _SYNTAX.md
And the current binaries (if you don't want to deal with FreeBasic) are here:
https://drive.google.com/file/d/1eendPg ... drive_link
- SmartMath preserves 64-bit integer accuracy during calculations when possible;
- SmartMath preserves 64-bit integer accuracy of input values in a form like `1e18` and even `0.1234e6`;
- while validating a user-defined function, its parameters no more use global variables with the same name (see "User-Defined Functions Validation" inside the "USAGE_AND_SYNTAX.md").
SmartMath is expected to give you strong guarantee of preserving 64-bit integer accuracy during calculations when possible.
Thus, the result of e.g. `2**63 + 2**62` and `(2**63 - 1) << 1` is an accurate integer value.
This was a part of the initial design of SmartMath'es expression parser and evaluator. It was stated in both "USAGE_AND_SYNTAX.md" and in the "add-mathparser-function" skill for AI.
However, I had to manually re-check each operation and function to ensure they really preserve the 64-bit integer accuracy when possible (because not all of them actually did). It's a good example of the magic of AI-driven development
Given that, how I can be sure the implementation of SmartMath'es expression parser and evaluator matches the expectations? Well, we have almost 1000 tests that cover most of its functionality. And we always can add more to fix the exact behavior!
The most recent "USAGE_AND_SYNTAX.md" is here:
https://github.com/d0vgan/AkelPad-Smart ... _SYNTAX.md
And the current binaries (if you don't want to deal with FreeBasic) are here:
https://drive.google.com/file/d/1eendPg ... drive_link
-
Offline
- Posts: 1334
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: SmartMath Plugin - Real-time Calculations in AkelPad
With the latest updates, SmartMath becomes even smarter than before! 
1. Time values are supported:
`01:25 + 00:37` -> `02:02`
`1h20m + 15m30s` -> `01:35:30`
`hours((30m, 6m, 40s))` -> `(0.5, 0.1, 0.011111)`
2. Complex numbers are optionally supported:
- By default, `sqrt(-1)` and `ln(-1)` produce `NaN`.
- With "Complex Numbers" enabled in the menu, `sqrt(-1)` is `i` and `ln(-1)` is `3.141593i`.
In general, complex numbers are supported by most of the operators and functions where they make sense.
Did you know, but the way, the complex numbers can not be compared in terms of `>` and `<`? Only equality and non-equality are supported.
This is another check-point in the development of SmartMath.
At this moment, I have just 2 more functions to add. After that, there will be refactoring, corrections, bug-fixes, if any.
the current binaries (if you don't want to deal with FreeBasic) are here:
https://drive.google.com/file/d/1goPTl1 ... drive_link
1. Time values are supported:
`01:25 + 00:37` -> `02:02`
`1h20m + 15m30s` -> `01:35:30`
`hours((30m, 6m, 40s))` -> `(0.5, 0.1, 0.011111)`
2. Complex numbers are optionally supported:
- By default, `sqrt(-1)` and `ln(-1)` produce `NaN`.
- With "Complex Numbers" enabled in the menu, `sqrt(-1)` is `i` and `ln(-1)` is `3.141593i`.
In general, complex numbers are supported by most of the operators and functions where they make sense.
Did you know, but the way, the complex numbers can not be compared in terms of `>` and `<`? Only equality and non-equality are supported.
This is another check-point in the development of SmartMath.
At this moment, I have just 2 more functions to add. After that, there will be refactoring, corrections, bug-fixes, if any.
the current binaries (if you don't want to deal with FreeBasic) are here:
https://drive.google.com/file/d/1goPTl1 ... drive_link
-
Offline
- Posts: 69
- Joined: Thu Feb 04, 2016 5:27 am
Re: SmartMath Plugin - Real-time Calculations in AkelPad
Haha, great work Dovgan.
It never ceases to amaze me just how many features the plugin has now.
By the way, how can we make your fork the main repository?
I think it would be ideal so that it shows up indexed in GitHub's results; for example, at the moment if we search for "akelpad", my repository appears in the results but not your fork with all the improvements.
Or maybe give you access so you can update the main repository directly?
To be honest, I don't know much about how GitHub works or its options. I was looking and there's an "Invite collaborators" option; maybe if I invite you, you can update the main repository directly?
What do you think?
Another thing, maybe you noticed or maybe you didn't, but I originally made this first to get to the heart of SmartMath, since AkelPad didn't have anything like Scintilla's "Line Hints".
https://akelpad.sourceforge.net/forum/v ... php?t=3008
https://github.com/c-sanchez/AkelPad-LineHint-Plugin
However, even though this plugin isn't useful on its own, as I said, I made it with SmartMath in mind, and although it does the job, I suppose it could be improved/optimised; could you take a look at it as well? :p
It never ceases to amaze me just how many features the plugin has now.
By the way, how can we make your fork the main repository?
I think it would be ideal so that it shows up indexed in GitHub's results; for example, at the moment if we search for "akelpad", my repository appears in the results but not your fork with all the improvements.
Or maybe give you access so you can update the main repository directly?
To be honest, I don't know much about how GitHub works or its options. I was looking and there's an "Invite collaborators" option; maybe if I invite you, you can update the main repository directly?
What do you think?
Another thing, maybe you noticed or maybe you didn't, but I originally made this first to get to the heart of SmartMath, since AkelPad didn't have anything like Scintilla's "Line Hints".
https://akelpad.sourceforge.net/forum/v ... php?t=3008
https://github.com/c-sanchez/AkelPad-LineHint-Plugin
However, even though this plugin isn't useful on its own, as I said, I made it with SmartMath in mind, and although it does the job, I suppose it could be improved/optimised; could you take a look at it as well? :p
-
Offline
- Posts: 1334
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: SmartMath Plugin - Real-time Calculations in AkelPad
Once the code is refactored and verified for some time to be treated as stable, I'll raise a pull request to the main repository.
After that, just a click on the "Merge" button will prevent it from being merged into the main repo.
Surely, there may be review comments that will be addressed before merging.
In long-time perspective, having access to the main repository will be quite useful.
In the future I may use the C++ version of the MathParser to e.g. make a plugin for Notepad++. In such case, some corrections to the MathParser will most likely be needed.
That was a good start indeed, with a new functionality that rather demonstrates a way to achieve more.c-sanchez wrote: ↑Sat May 16, 2026 7:37 pmAnother thing, maybe you noticed or maybe you didn't, but I originally made this first to get to the heart of SmartMath, since AkelPad didn't have anything like Scintilla's "Line Hints".
https://akelpad.sourceforge.net/forum/v ... php?t=3008
https://github.com/c-sanchez/AkelPad-LineHint-Plugin
While it can be perfectly useful for users who need accessibility assistance, I'm not sure I have ideas how to enhance it at the moment.
-
Offline
- Posts: 1334
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: SmartMath Plugin - Real-time Calculations in AkelPad
Next checkpoint:
1. New function: ratio
`ratio(-0.5)` -> `-1/2`
`ratio(days(1h))` -> `1/24`
`ratio(sqrt(2))` -> `13250218/9369319`
2. New function: sortby
`f(x)=1/x; sortby((1,-1,-2,0,2), f)` -> `(-1, -2, 2, 1, 0)`
`sortby((1:00,0:30,1:30), x: -x)` -> `(01:30, 01:00, 00:30)`
3. Various corrections and improvements.
At this point, I'm finding and fixing so stupid errors which reveal the main difference between AI and human. This is a simple yet fundamentally important point: AI lacks common sense. Whatever you do with AI, AI can always interpret it in the most stupid way. Basically, AI has unlimited abilities to be limitlessly stupid
Now there are more that 1100 tests, that gives a hope that most of the functionality is correct. But let's see.
The current binaries (if you don't want to deal with FreeBasic) are here:
https://drive.google.com/file/d/1PlB1qy ... drive_link
1. New function: ratio
`ratio(-0.5)` -> `-1/2`
`ratio(days(1h))` -> `1/24`
`ratio(sqrt(2))` -> `13250218/9369319`
2. New function: sortby
`f(x)=1/x; sortby((1,-1,-2,0,2), f)` -> `(-1, -2, 2, 1, 0)`
`sortby((1:00,0:30,1:30), x: -x)` -> `(01:30, 01:00, 00:30)`
3. Various corrections and improvements.
At this point, I'm finding and fixing so stupid errors which reveal the main difference between AI and human. This is a simple yet fundamentally important point: AI lacks common sense. Whatever you do with AI, AI can always interpret it in the most stupid way. Basically, AI has unlimited abilities to be limitlessly stupid
Now there are more that 1100 tests, that gives a hope that most of the functionality is correct. But let's see.
The current binaries (if you don't want to deal with FreeBasic) are here:
https://drive.google.com/file/d/1PlB1qy ... drive_link
-
Offline
- Posts: 1334
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: SmartMath Plugin - Real-time Calculations in AkelPad
Latest checkpoint:
1. Main focus was: corrections, improvements, clarifications.
The eventual goal is to raise a pull request against the main branch to deliver all these changes to the official repository.
Prior to that, I want to ensure the behavior is stable and expected at that point.
2. Even though I've been concentrating on corrections, improvements and clarifications, I noticed that SmartMath needs one more function, so I've added it.
Here it is: `factorint(n)` - prime factorization of integer `n` as an array.
Example:
As you can see, `factorint` splits an integer number into primal number multipliers, while `product` can take the result and calculate the original number by multiplying the array values.
The implementation of `factorint` is highly optimized, so you may have up to 50-100 `factorint`calculations within the same file/document until you notice a slight delay.
The implementation of `ratio`, by the way, is also highly optimized, and you may have up to 100-200 `ratio` calculations within the same file/document until you notice a slight delay.
Talking about `ratio`, it uses a precision around `1e-14` which allows to produce pretty accurate results while preserving sanity
Here is an example:
The current binaries (if you don't want to deal with FreeBasic) are here:
https://drive.google.com/file/d/1iD8P26 ... drive_link
1. Main focus was: corrections, improvements, clarifications.
The eventual goal is to raise a pull request against the main branch to deliver all these changes to the official repository.
Prior to that, I want to ensure the behavior is stable and expected at that point.
2. Even though I've been concentrating on corrections, improvements and clarifications, I noticed that SmartMath needs one more function, so I've added it.
Here it is: `factorint(n)` - prime factorization of integer `n` as an array.
Example:
Code: Select all
a = factorint(383864250) = (2, 3, 5**3, 7, 11, 17**2, 23)
product(a) = 383864250The implementation of `factorint` is highly optimized, so you may have up to 50-100 `factorint`calculations within the same file/document until you notice a slight delay.
The implementation of `ratio`, by the way, is also highly optimized, and you may have up to 100-200 `ratio` calculations within the same file/document until you notice a slight delay.
Talking about `ratio`, it uses a precision around `1e-14` which allows to produce pretty accurate results while preserving sanity
Code: Select all
e = 2.718281828459045
ratio(e) = 14665106/5394991
e - ratio(e) = 1.687538997430238e-14https://drive.google.com/file/d/1iD8P26 ... drive_link
-
Offline
- Posts: 1334
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: SmartMath Plugin - Real-time Calculations in AkelPad
Latest checkpoint:
- corrections for multiplication and division to preserve an exact integer result when possible (such as `9*(1/3)` and `3/(1/3)`);
- corrections for `ratio` as a part of a math expression (such as `1 + ratio(1/3) + 2`);
- corrections for `min`/`max` to preserve the exact integer metadata and ignore `NaN`;
- corrections for complex numbers: `1/2i` means `1/(2i)`, `2**7i` means `2**(7i)`, similarly to Python and SpeQ Math.
The number of tests is around 3000 now, that really helps to verify the exact behavior and to avoid regressions.
(Note: the C++ version shows smaller number of tests because the C++ test suite combines several similar tests under one test-case and reports a single success for one test-case).
My fork is getting closer and closer to the moment of raising a pull request against the base branch.
The current binaries (if you don't want to deal with FreeBasic) are here:
https://drive.google.com/file/d/1UPih40 ... drive_link
- corrections for multiplication and division to preserve an exact integer result when possible (such as `9*(1/3)` and `3/(1/3)`);
- corrections for `ratio` as a part of a math expression (such as `1 + ratio(1/3) + 2`);
- corrections for `min`/`max` to preserve the exact integer metadata and ignore `NaN`;
- corrections for complex numbers: `1/2i` means `1/(2i)`, `2**7i` means `2**(7i)`, similarly to Python and SpeQ Math.
The number of tests is around 3000 now, that really helps to verify the exact behavior and to avoid regressions.
(Note: the C++ version shows smaller number of tests because the C++ test suite combines several similar tests under one test-case and reports a single success for one test-case).
My fork is getting closer and closer to the moment of raising a pull request against the base branch.
The current binaries (if you don't want to deal with FreeBasic) are here:
https://drive.google.com/file/d/1UPih40 ... drive_link
-
Offline
- Posts: 69
- Joined: Thu Feb 04, 2016 5:27 am
Re: SmartMath Plugin - Real-time Calculations in AkelPad
Hi DV, what if, instead of using the text/keyword #smartmarth to activate the evaluator, we used an option that lets you enable/disable the plugin/evaluator per tab?
This would be more convenient for users, and it could allow for things like adding a button with that option to the toolbar, enabling us to toggle it on or off with a single click.
I’ve added the option and updated the main repository with that single update.
In fact, I originally created the plugin for Notepad++, so you could perhaps update the evaluator for the Notepad++ version as well?
https://github.com/c-sanchez/npp-smart-math


Ironically, the option to enable/disable the plugin per tab was something I forgot to implement in AkelPad
This would be more convenient for users, and it could allow for things like adding a button with that option to the toolbar, enabling us to toggle it on or off with a single click.
I’ve added the option and updated the main repository with that single update.
In fact, I originally created the plugin for Notepad++, so you could perhaps update the evaluator for the Notepad++ version as well?
https://github.com/c-sanchez/npp-smart-math


Ironically, the option to enable/disable the plugin per tab was something I forgot to implement in AkelPad
-
Offline
- Posts: 1334
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: SmartMath Plugin - Real-time Calculations in AkelPad
This approach will not work for the Pseudo-MDI mode, when the same window is used for different tabs. But the idea is interesting. What if this menu item will add or remove the "# SmartMath" mark?
-
Offline
- Posts: 1334
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: SmartMath Plugin - Real-time Calculations in AkelPad
May I ask you to revert this change for now? This change would produce a lot of merge conficts in both SmartMath.bas and SmartMath_Menu.bas between my branch and the main branch - and I'd like to avoid resolving them because these files are very different now.
-
Offline
- Posts: 69
- Joined: Thu Feb 04, 2016 5:27 am
Re: SmartMath Plugin - Real-time Calculations in AkelPad
Sure, I've already reverted the changes to the modified files: SmartMath.bas, SmartMath_Menu.bas, and SmartMath_Globals.bi.
Although I did this by manually replacing the current code with the previous version, I'm not sure if this will cause any issues. I hope not.
I hadn't considered the PMDI mode. Although I think the ideal approach would be to avoid having a required text or keyword in the file itself.
Although I did this by manually replacing the current code with the previous version, I'm not sure if this will cause any issues. I hope not.
I hadn't considered the PMDI mode. Although I think the ideal approach would be to avoid having a required text or keyword in the file itself.
-
Offline
- Posts: 1334
- Joined: Thu Nov 16, 2006 11:53 am
- Location: Kyiv, Ukraine
Re: SmartMath Plugin - Real-time Calculations in AkelPad
Finally, I've raised a pull request against the main branch! 
I think we can get rid of the "# SmartMath" mark, though it will not be as easy as it seems. Because:
1) in case of MDI and PMDI, we need to maintain an array that will contain frame pointers where SmartMath is enabled;
2) correspondingly, each frame (tab) activation need to be synchronized with this array;
3) correspondingly, each frame (tab) closing need to be synchronized with this array;
4) then, would should happen when AkelPad is exited and then started again? Should all the frames (tabs) wait until "Active on Current Tab" is manually selected? Or should we write the file paths where SmartMath was enabled to the plugin's configuration to automatically enable the calculations in these files when AkelPad is restarted?
So, we can achieve anything we want, it's just a question of an exact approach and behavior.
Just in case, here are the current binaries with all the latest corrections and refactoring:
https://drive.google.com/file/d/1f-HiSM ... drive_link
I think we can get rid of the "# SmartMath" mark, though it will not be as easy as it seems. Because:
1) in case of MDI and PMDI, we need to maintain an array that will contain frame pointers where SmartMath is enabled;
2) correspondingly, each frame (tab) activation need to be synchronized with this array;
3) correspondingly, each frame (tab) closing need to be synchronized with this array;
4) then, would should happen when AkelPad is exited and then started again? Should all the frames (tabs) wait until "Active on Current Tab" is manually selected? Or should we write the file paths where SmartMath was enabled to the plugin's configuration to automatically enable the calculations in these files when AkelPad is restarted?
So, we can achieve anything we want, it's just a question of an exact approach and behavior.
Just in case, here are the current binaries with all the latest corrections and refactoring:
https://drive.google.com/file/d/1f-HiSM ... drive_link