Re: Fwd: [fricas-devel] Extentions to symbols and strings

2023-11-27 Thread Waldek Hebisch
On Sun, Nov 26, 2023 at 05:04:06PM +0100, Ralf Hemmecke wrote:
> On 11/26/23 15:15, Waldek Hebisch wrote:
> > Attached is code defining Greek symbols organized as a package.
> 
> There is a trailing space at the end of the file.

Hmm, I see only a newline (empty line).

> Another thing that I do not quite like is the function names of capital
> letters. I am not a fan of having Alpha, Beta, etc. since that violates the
> convention that variable and function names should start with a small letter
> and only constructors begin with a capital.

I think this is strong case for exception to the convention, plain
Alpha is much more natural.

> Although it is longer, but I would rather use capitalAlpha, capitalBeta,
> etc. There is no reason that FriCAS must have short names. We have a macro
> system to help users if they feel that function names are too long.
> 
> I would also rather like mathsym.spad instead of math_sym.spad.

Well, math_sym.spad is more readible.

-- 
  Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ZWSJlVHClnZQzWUM%40fricas.org.


Re: Fwd: [fricas-devel] Extentions to symbols and strings

2023-11-26 Thread Ralf Hemmecke

On 11/26/23 15:15, Waldek Hebisch wrote:

Attached is code defining Greek symbols organized as a package.


There is a trailing space at the end of the file.

Another thing that I do not quite like is the function names of capital 
letters. I am not a fan of having Alpha, Beta, etc. since that violates 
the convention that variable and function names should start with a 
small letter and only constructors begin with a capital.


Although it is longer, but I would rather use capitalAlpha, capitalBeta, 
etc. There is no reason that FriCAS must have short names. We have a 
macro system to help users if they feel that function names are too long.


I would also rather like mathsym.spad instead of math_sym.spad.

Ralf

--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/01f7d2ec-fac5-4484-8c62-c54e2288cecf%40hemmecke.org.


Re: Fwd: [fricas-devel] Extentions to symbols and strings

2023-11-26 Thread Bill Page
On Sun, 26 Nov 2023 at 09:15, Waldek Hebisch  wrote:
>
> Attached is code defining Greek symbols organized as a package.
>
> Note: ucodeToString takes Unicode code point as argument, so
> I had to decrease all character codes by 1 (index used in
> original code adds 1).
>
> Extra remark: Some capital Greek letters look exactly the
> same as roman letters.  They are needed when one wants
> actual Greek text, but one probably should not use them
> in math.  For this reason some capital Greek letters
> were/are excluded from TeX.  I think it makes sense to
> exclude them.
>

-1 No, I think you should keep them.  Whether Greek versus Roman characters
look the same depends on the presentation layer, i.e. what fonts are used
to render the final result. The same thing applies to other homoglyph
characters in other language, e.g. Latin and Cryllic. It is often of
interest to use different font sets for different languages appearing in
the same document. TeX should not be considered as a de facto standard.

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/CAC6x94RXur0tD2Dxi87OTP%3D4WmxJaBCiSZR%3DaowoHzT7YMH-4w%40mail.gmail.com.


Re: Fwd: [fricas-devel] Extentions to symbols and strings

2023-11-26 Thread Waldek Hebisch
Attached is code defining Greek symbols organized as a package.

Note: ucodeToString takes Unicode code point as argument, so
I had to decrease all character codes by 1 (index used in
original code adds 1).

Extra remark: Some capital Greek letters look exactly the
same as roman letters.  They are needed when one wants
actual Greek text, but one probably should not use them
in math.  For this reason some capital Greek letters
were/are exluded from TeX.  I think it makes sense to
exclude them.

-- 
  Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ZWNTCMQkf84So1pQ%40fricas.org.
)abbrev package MATHSYM MathematicalSymbols
MathematicalSymbols() : with
 newGreek : () -> Symbol
   ++ newGreek() returns the next greek symbol.
 resetNewGreek : () -> Void
   ++ resetNewGreek() resets the internals counters that newGreek()
   ++ used to return distinct symbols every time.
 partial: constant -> Symbol
   ++ partial() returns symbol for partial derivative.
 alpha: constant -> Symbol
   ++ alpha() returns symbol for small greek letter alpha.
 beta: constant -> Symbol
   ++ beta() returns symbol for small greek letter beta.
 gamma: constant -> Symbol
   ++ gamm() returns symbol for small greek letter gamma.
 delta: constant -> Symbol
   ++ delta() returns symbol for small greek letter delta.
 epsilon: constant -> Symbol
   ++ epsilon() returns symbol for small greek letter epsilon.
 zeta: constant -> Symbol
   ++ zeta() returns symbol for small greek letter zeta.
 eta: constant -> Symbol
   ++ eta() returns symbol for small greek letter eta.
 theta: constant -> Symbol
   ++ theta() returns symbol for small greek letter theta.
 iota: constant -> Symbol
   ++ iota() returns symbol for small greek letter iota.
 kappa: constant -> Symbol
   ++ kappa() returns symbol for small greek letter kappa.
 lambda: constant -> Symbol
   ++ lambda() returns symbol for small greek letter lambda.
 mu: constant -> Symbol
   ++ mu() returns symbol for small greek letter mu.
 nu: constant -> Symbol
   ++ nu() returns symbol for small greek letter nu.
 xi: constant -> Symbol
   ++ xi() returns symbol for small greek letter xi.
 omicron: constant -> Symbol
   ++ omicron() returns symbol for small greek letter omicron.
 pi: constant -> Symbol
   ++ pi() returns symbol for small greek letter pi.
 rho: constant -> Symbol
   ++ rho() returns symbol for small greek letter rho.
 sigma: constant -> Symbol
   ++ sigma() returns symbol for small greek letter sigma.
 tau: constant -> Symbol
   ++ tau() returns symbol for small greek letter tau.
 upsilon: constant -> Symbol
   ++ upsilon() returns symbol for small greek letter upsilon.
 phi: constant -> Symbol
   ++ phi() returns symbol for small greek letter phi.
 chi: constant -> Symbol
   ++ chi() returns symbol for small greek letter chi.
 psi: constant -> Symbol
   ++ psi() returns symbol for small greek letter psi.
 omega: constant -> Symbol
   ++ omega() returns symbol for small greek letter omega.
 Alpha: constant -> Symbol
   ++ Alpha() returns symbol for capital greek letter alpha.
 Beta: constant -> Symbol
   ++ Beta() returns symbol for capital greek letter beta.
 Gamma: constant -> Symbol
   ++ Gamm() returns symbol for capital greek letter gamma.
 Delta: constant -> Symbol
   ++ Delta() returns symbol for capital greek letter delta.
 Epsilon: constant -> Symbol
   ++ Epsilon() returns symbol for capital greek letter epsilon.
 Zeta: constant -> Symbol
   ++ Zeta() returns symbol for capital greek letter zeta.
 Eta: constant -> Symbol
   ++ Eta() returns symbol for capital greek letter eta.
 Theta: constant -> Symbol
   ++ Theta() returns symbol for capital greek letter theta.
 Iota: constant -> Symbol
   ++ Iota() returns symbol for capital greek letter iota.
 Kappa: constant -> Symbol
   ++ Kappa() returns symbol for capital greek letter kappa.
 Lambda: constant -> Symbol
   ++ Lambda() returns symbol for capital greek letter lambda.
 Mu: constant -> Symbol
   ++ Mu() returns symbol for capital greek letter mu.
 Nu: constant -> Symbol
   ++ Nu() returns symbol for capital greek letter nu.
 Xi: constant -> Symbol
   ++ Xi() returns symbol for capital greek letter xi.
 Omicron: constant -> Symbol
   ++ Omicron() returns symbol for capital greek letter omicron.
 Pi: constant -> Symbol
   ++ Pi() returns symbol for capital 

Re: Fwd: [fricas-devel] Extentions to symbols and strings

2023-11-25 Thread Waldek Hebisch
Attached is diff with respect to current trunk which
should give the same functionality as your code, but
omits most problematic changes.

As I wrote in previous mail, changes to Symbol IMO
should go to a separate package.  From changes to
'string.spad' we probaly should take some but not
all.

-- 
  Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ZWKY5diqMW5qp54O%40fricas.org.
diff --git a/src/algebra/string.spad b/src/algebra/string.spad
index 92a16e76..a2eff212 100644
--- a/src/algebra/string.spad
+++ b/src/algebra/string.spad
@@ -22,6 +22,10 @@ Character : Join(OrderedFinite(), Hashable) with
 ++ char(s) provides a character from a string s of length one.
 space :  () -> %
 ++ space() provides the blank character.
+-- begin new code jg
+infinityCharacter :  () -> %
+++ infinityCharacter() provides ∞.
+-- end new code jg
 quote :  () -> %
 ++ quote() provides the string quote character, \spad{"}.
 underscore : () -> %
@@ -56,12 +60,20 @@ Character : Join(OrderedFinite(), Hashable) with
 alphanumeric? : % -> Boolean
 ++ alphanumeric?(c) tests if c is either a letter or number,
 ++ i.e. one of 0..9, a..z or A..Z.
+-- begin new code jg
+greek? : % -> Boolean
+++ greek?(c) tests if c is a greek letter.
+toDigit: % -> Integer
+++ toDigit(c) transforms c to a digit, error if not possible.
+-- end new code jg
 
 == add
 Rep := SingleInteger  -- 0..(1114112 - 1)
 
 CC ==> CharacterClass()
 import from CC
+OF ==> OutputForm
+import from OF
 
 --cl: Record(dig: CC, hex: CC, upp: CC, low: CC, alpha: CC, alnum: CC) :=
 --[ digit(), hexDigit(),
@@ -89,6 +101,24 @@ Character : Join(OrderedFinite(), Hashable) with
 lowerCase? c   == member?(c pretend Character, lowerCase())
 alphabetic? c  == member?(c pretend Character, alphabetic())
 alphanumeric? c== member?(c pretend Character, alphanumeric())
+-- begin new code jg
+infinityCharacter(): % == char 8734
+greek? c	== member?(c pretend Character, greek())
+toDigit(c: %): Integer ==
+  --print blankSeparate [msg "toDigit aufgerufen mit c = ", c :: OF]
+  c = char "0" => 0
+  c = char "1" => 1
+  c = char "2" => 2
+  c = char "3" => 3
+  c = char "4" => 4
+  c = char "5" => 5
+  c = char "6" => 6
+  c = char "7" => 7
+  c = char "8" => 8
+  c = char "9" => 9
+  error "toDigit: not a number"
+  -1
+-- end new code jg
 
 char(s : String) == STR_to_CHAR(s)$Lisp
 --  (#s) = 1 => s(minIndex s) pretend %
@@ -147,6 +177,11 @@ CharacterClass : Join(SetCategory, ConvertibleTo String,
 alphanumeric :  constant -> %
 ++ alphanumeric() returns the class of all characters for which
 ++ \spadfunFrom{alphanumeric?}{Character} is true.
+-- begin new code jg
+greek  :  constant -> %
+++ greek() returns the class of all characters for which
+++ \spadfunFrom{greek?}{Character} is true.
+-- end new code jg
 
 == add
 Rep := IndexedBits(0)
@@ -154,7 +189,8 @@ CharacterClass : Join(SetCategory, ConvertibleTo String,
 
 import from Character
 
-N   := 256
+--N   := 256
+N   := 1024
 
 a, b : %
 
@@ -164,6 +200,13 @@ CharacterClass : Join(SetCategory, ConvertibleTo String,
 lowerCase() == charClass "abcdefghijklmnopqrstuvwxyz"
 alphabetic()== union(upperCase(), lowerCase())
 alphanumeric()  == union(alphabetic(), digit())
+-- begin new code jg
+gL : String :=   construct [index(u :: PositiveInteger) for u in 946..962]
+gL := concat(gL, construct [index(u :: PositiveInteger) for u in 964..970] )
+gL := concat(gL, construct [index(u :: PositiveInteger) for u in 914..930] )
+gL := concat(gL, construct [index(u :: PositiveInteger) for u in 932..938] )
+greek() == charClass gL
+-- end new code jg
 
 a = b   == a =$Rep b
 
@@ -424,8 +467,54 @@ String() : StringCategory with
   ++ as sequence of octets using UTF-8 encoding.  Consegently
   ++ length of returened list may be smaller than length
   ++ of the string in octets.
+-- begin new code jg
+toInteger: % -> Integer
+  ++ toInteger(s) changes s into an integer, if it is a list of digits
+  ++ possible after a minus sign.
+toDecimalExpansion: % -> DecimalExpansion
+  

Re: Fwd: [fricas-devel] Extentions to symbols and strings

2023-11-25 Thread Waldek Hebisch
On Sat, Nov 25, 2023 at 05:24:10PM +0100, Prof. Dr. Johannes Grabmeier wrote:
> 
> I enhanced Character and String with greek letters and other useful
> functions. Code string-enhanced.spad is included. Also symbol-jg.spad with
> signatures like alpha: () -> Sybol
 
> I am curious to learn what is going wrong now. And, if this can be fixed I
> would appreciate to include my enhancements to the distribution.

After fixing the make_full_CVEC problem your changes compile fine.

Some comments about includinhg them in FriCAS distribution: currently
we can not assume that Unicode characters are a single FriCAS
character.  We have utility function that produces FriCAS string
consisting of single Unicode character.  Currently GCL uses UFT-8
encoding where character codes are 8-bit and non-ASCII Unicode characters
produce strings of length bigger than 1.  And I would like to
have possiblity of representing FriCAS strings as byte arrays
even when using different Lisp.  So I do not like idea of
adding Unicode character to FriCAS Character.

I also do not like idea representing CharacterClass by array with
more than 256 entries.  First, it does not work when character
codes are 8-bit.  Second, once we add more codes there is no
natural limit, logically we should have entire Unicode, that
is 1114112 positions.  But such tables are very troublesome
performancewise.  They take a lot of space and it takes time
to initialize them.  One may think that with gigabyte memories
this is not a problem.  Well, modern machine are fast when
data is in caches.  Caches have limited size and big tables
may exceed size of caches.  Also, FriCAS normally is usable
on quite small machines, spending a lot of memory on something
that looks trivial means that it would be less usable on
small machines.

We already have equvalent functionality to some things that
you want to add.  In package ScanningUtilities there is
'parse_integer' function which converts a string to an integer.
This covers functionalty of 'toInteger'.  If function to convert
digits to integers is desired it would be natural to add it in
the same package.  I am not sure how important is
'toDecimalExpansion' but AFAICS the effect may be obtained by

decimal(parse_integer(s)::FRAC(INT))

Also we have 'newline()' to get end of line character,
so your 'endOfLine' just introduces a duplicate name.

Concerning adding greek letter and other symbols to Symbol,
I am affraid of "namespace pollution".  Symbol is used
a lot and users may want to use names of Greek letters for
their purposes.  So I would put such functions in a separate
unexposed package.  Concering implementation, 'getUTF'
may be implemented as

getUTF(i : PositiveInteger) : Symbol == ucodeToString(i)::Symbol

which should work with our convention.  Similarly, 'newGreek'
should use array of strings as set of greek letters (or
use ucodeToString to produce them on the fly).  ATM FriCAS
sources should use ASCII (not ASCII charcter may cause but
failure in some cases).  So documentaion string should use
spelled-out name of character, not to charater itself.

More generally, for handling Unicode strings there may be some
use in functions that extract next Unicode code point (Integer
from 0 to 1114112 - 1 and function to give first string index
after/befor a Unicode character.  Such functions allow iteration
over Unicode strings in both directions which should be
enough for basic Unicode-aware string operations.

-- 
  Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ZWKMe7kig75WvCEK%40fricas.org.