login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for SymbolInteger revision 1 of 1

1
Editor: pagani
Time: 2022/09/02 14:47:22 GMT+0
Note:

changed:
-
\begin{spad}
)abbrev package SYMINT SymbolInteger
++ Date Created: Fri Sep 02 01:11:15 CEST 2022
++ Description: _[-]d+ ; symbols as integers 
++
SymbolInteger(T:Type) : Exports == Implementation where

  CIP ==> ConvertibleTo InputForm
  CFS ==> CoercibleFrom Symbol

  Exports ==  with   
    integerSymbol? : T -> Boolean
    sym2int : T -> Integer
    int2sym : Integer -> T
   	
  Implementation ==  add 
    
    if T has CIP and T has CFS then
      integerSymbol?(s:T):Boolean ==
        p:InputForm:=convert(s)$T
        sym:=symbol(p)$InputForm
        str:=string sym
        lcs:=entries str
        if first lcs = char 95 then lcs:=rest lcs
        first lcs = char 45 => every?(digit?,rest lcs) 
        every?(digit?,lcs)
        
      
      sym2int(s:T):Integer ==
      -- char 48 ... char 57 <=> 0..9, char 45 <=> "-", 95=_
        p:InputForm:=convert(s)$T
        sym:=symbol(p)$InputForm
        str:=string sym
        lcs:=entries str 
        sgn:Integer
        if first lcs = char 95 then lcs:=rest lcs
        if first lcs = char 45 then
          sgn:=-1
          lcs:=rest lcs
        else
          sgn:=1
        dig:List Integer:=reverse [ord(c) for c in lcs]
        m:Integer:=(dig.1 - 48)
        for i in 1..#dig-1 repeat
          m:=m+(dig.(i+1) - 48) * 10^i
        sgn * m

      int2sym(p:Integer):T ==
        underscore:String:=char(95)$Character::String
        s:String:= underscore string(p)$String
        sym:=s::Symbol
        sym::T   
   
\end{spad}

\begin{axiom}

SPI:=SYMINT(POLY INT)
SEI:=SYMINT(EXPR INT)
SSY:=SYMINT(Symbol)


integerSymbol?(_344::POLY(INT)) --> true
integerSymbol?(_344::EXPR(INT)) --> true
--integerSymbol?(_344::Symbol)    --> true / not after adding CFS

integerSymbol?(_-122222222222222229888::POLY INT) --> true
integerSymbol?(_122222222222222229888::POLY INT)  --> true
integerSymbol?(m::POLY INT)                       --> false

sym2int(_1234567890::POLY INT)  --> 1234567890
sym2int(_-1234567890::POLY INT) --> - 1234567890
sym2int(_1234567890::EXPR INT)
sym2int(_-1234567890::EXPR INT)

int2sym(1234567890)$SYMINT(POLY INT) --> _1234567890 Polynomial(Integer)
int2sym(-1234567890)$SYMINT(POLY INT) --> _-1234567890
int2sym(-1234567890)$SYMINT(EXPR INT) --> _-1234567890

T:=POLY INT

sum(x:List T):T ==
  f:=(t:T):T+->if integerSymbol? t then sym2int t else t
  b:=map(f,x)
  reduce(_+,b)


sum [_1::T,_2::T]  --> 3
sum [_1::T,_2::T,_-3::T] --> 0

T:=EXPR INT
prod(x:List T):T ==
  f:=(t:T):T+->if integerSymbol? t then sym2int t else t
  b:=map(f,x)
  reduce(_*,b)
  
p1:=prod [_2::T,_9999::T,_333333333::T]
p2:=prod [_-2::T,_9999::T,_333333333::T]

q1:=int2sym(p1)$SEI
q2:=int2sym(p2)$SEI

prod [q1,q2]

--- why not????
Symbol has CoercibleFrom Symbol 

--- Clue from Waldek, Re: [fricas-devel] Numbers as type parameters
PRETTYPRINT(p1::Polynomial(Integer))$Lisp
PRETTYPRINT(q1::Polynomial(Integer))$Lisp

\end{axiom}

fricas
(1) -> <spad>
fricas
)abbrev package SYMINT SymbolInteger
++ Date Created: Fri Sep 02 01:11:15 CEST 2022
++ Description: _[-]d+ ; symbols as integers 
++
SymbolInteger(T:Type) : Exports == Implementation where
CIP ==> ConvertibleTo InputForm CFS ==> CoercibleFrom Symbol
Exports == with integerSymbol? : T -> Boolean sym2int : T -> Integer int2sym : Integer -> T
Implementation == add
if T has CIP and T has CFS then integerSymbol?(s:T):Boolean == p:InputForm:=convert(s)$T sym:=symbol(p)$InputForm str:=string sym lcs:=entries str if first lcs = char 95 then lcs:=rest lcs first lcs = char 45 => every?(digit?,rest lcs) every?(digit?,lcs)
sym2int(s:T):Integer == -- char 48 ... char 57 <=> 0..9, char 45 <=> "-", 95=_ p:InputForm:=convert(s)$T sym:=symbol(p)$InputForm str:=string sym lcs:=entries str sgn:Integer if first lcs = char 95 then lcs:=rest lcs if first lcs = char 45 then sgn:=-1 lcs:=rest lcs else sgn:=1 dig:List Integer:=reverse [ord(c) for c in lcs] m:Integer:=(dig.1 - 48) for i in 1..#dig-1 repeat m:=m+(dig.(i+1) - 48) * 10^i sgn * m
int2sym(p:Integer):T == underscore:String:=char(95)$Character::String s:String:= underscore string(p)$String sym:=s::Symbol sym::T</spad>
fricas
Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6963949273566260192-25px001.spad
      using old system compiler.
   SYMINT abbreviates package SymbolInteger 
------------------------------------------------------------------------
   initializing NRLIB SYMINT for SymbolInteger 
   compiling into NRLIB SYMINT 
****** Domain: T$ already in scope
augmenting T$: (ConvertibleTo (InputForm))
****** Domain: T$ already in scope
augmenting T$: (CoercibleFrom (Symbol))
   compiling exported integerSymbol? : T$ -> Boolean
Time: 0.03 SEC.
compiling exported sym2int : T$ -> Integer Time: 0.01 SEC.
compiling exported int2sym : Integer -> T$ Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |SymbolInteger| REDEFINED
;;; *** |SymbolInteger| REDEFINED Time: 0 SEC.
Cumulative Statistics for Constructor SymbolInteger Time: 0.05 seconds
finalizing NRLIB SYMINT Processing SymbolInteger for Browser database: --------constructor--------- --->-->SymbolInteger((integerSymbol? ((Boolean) T$))): Not documented!!!! --->-->SymbolInteger((sym2int ((Integer) T$))): Not documented!!!! --->-->SymbolInteger((int2sym (T$ (Integer)))): Not documented!!!! ; compiling file "/var/aw/var/LatexWiki/SYMINT.NRLIB/SYMINT.lsp" (written 02 NOV 2024 02:48:14 AM):
; wrote /var/aw/var/LatexWiki/SYMINT.NRLIB/SYMINT.fasl ; compilation finished in 0:00:00.020 ------------------------------------------------------------------------ SymbolInteger is now explicitly exposed in frame initial SymbolInteger will be automatically loaded when needed from /var/aw/var/LatexWiki/SYMINT.NRLIB/SYMINT

fricas
SPI:=SYMINT(POLY INT)

\label{eq1}\hbox{\axiomType{SymbolInteger}\ } \left({\hbox{\axiomType{Polynomial}\ } \left({\hbox{\axiomType{Integer}\ }}\right)}\right)(1)
Type: Type
fricas
SEI:=SYMINT(EXPR INT)

\label{eq2}\hbox{\axiomType{SymbolInteger}\ } \left({\hbox{\axiomType{Expression}\ } \left({\hbox{\axiomType{Integer}\ }}\right)}\right)(2)
Type: Type
fricas
SSY:=SYMINT(Symbol)

\label{eq3}\hbox{\axiomType{SymbolInteger}\ } \left({\hbox{\axiomType{Symbol}\ }}\right)(3)
Type: Type
fricas
integerSymbol?(_344::POLY(INT)) --> true

\label{eq4} \mbox{\rm true} (4)
Type: Boolean
fricas
integerSymbol?(_344::EXPR(INT)) --> true

\label{eq5} \mbox{\rm true} (5)
Type: Boolean
fricas
--integerSymbol?(_344::Symbol)    --> true / not after adding CFS
integerSymbol?(_-122222222222222229888::POLY INT) --> true

\label{eq6} \mbox{\rm true} (6)
Type: Boolean
fricas
integerSymbol?(_122222222222222229888::POLY INT)  --> true

\label{eq7} \mbox{\rm true} (7)
Type: Boolean
fricas
integerSymbol?(m::POLY INT)                       --> false

\label{eq8} \mbox{\rm false} (8)
Type: Boolean
fricas
sym2int(_1234567890::POLY INT)  --> 1234567890

\label{eq9}1234567890(9)
Type: PositiveInteger?
fricas
sym2int(_-1234567890::POLY INT) --> - 1234567890

\label{eq10}-{1234567890}(10)
Type: Integer
fricas
sym2int(_1234567890::EXPR INT)

\label{eq11}1234567890(11)
Type: PositiveInteger?
fricas
sym2int(_-1234567890::EXPR INT)

\label{eq12}-{1234567890}(12)
Type: Integer
fricas
int2sym(1234567890)$SYMINT(POLY INT) --> _1234567890 Polynomial(Integer)

\label{eq13}\<u> 1234567890(13)
Type: Polynomial(Integer)
fricas
int2sym(-1234567890)$SYMINT(POLY INT) --> _-1234567890

\label{eq14}\<u> - 1234567890(14)
Type: Polynomial(Integer)
fricas
int2sym(-1234567890)$SYMINT(EXPR INT) --> _-1234567890

\label{eq15}\<u> - 1234567890(15)
Type: Expression(Integer)
fricas
T:=POLY INT

\label{eq16}\hbox{\axiomType{Polynomial}\ } \left({\hbox{\axiomType{Integer}\ }}\right)(16)
Type: Type
fricas
sum(x:List T):T ==
  f:=(t:T):T+->if integerSymbol? t then sym2int t else t
  b:=map(f,x)
  reduce(_+,b)
Function declaration sum : List(Polynomial(Integer)) -> Polynomial( Integer) has been added to workspace.
Type: Void
fricas
sum [_1::T,_2::T]  --> 3
fricas
Compiling function sum with type List(Polynomial(Integer)) -> 
      Polynomial(Integer)

\label{eq17}3(17)
Type: Polynomial(Integer)
fricas
sum [_1::T,_2::T,_-3::T] --> 0

\label{eq18}0(18)
Type: Polynomial(Integer)
fricas
T:=EXPR INT

\label{eq19}\hbox{\axiomType{Expression}\ } \left({\hbox{\axiomType{Integer}\ }}\right)(19)
Type: Type
fricas
prod(x:List T):T ==
  f:=(t:T):T+->if integerSymbol? t then sym2int t else t
  b:=map(f,x)
  reduce(_*,b)
Function declaration prod : List(Expression(Integer)) -> Expression( Integer) has been added to workspace.
Type: Void
fricas
p1:=prod [_2::T,_9999::T,_333333333::T]
fricas
Compiling function prod with type List(Expression(Integer)) -> 
      Expression(Integer)

\label{eq20}6665999993334(20)
Type: Expression(Integer)
fricas
p2:=prod [_-2::T,_9999::T,_333333333::T]

\label{eq21}-{6665999993334}(21)
Type: Expression(Integer)
fricas
q1:=int2sym(p1)$SEI

\label{eq22}\<u> 6665999993334(22)
Type: Expression(Integer)
fricas
q2:=int2sym(p2)$SEI

\label{eq23}\<u> - 6665999993334(23)
Type: Expression(Integer)
fricas
prod [q1,q2]

\label{eq24}-{44435555911128888044435556}(24)
Type: Expression(Integer)
fricas
--- why not????
Symbol has CoercibleFrom Symbol

\label{eq25} \mbox{\rm false} (25)
Type: Boolean
fricas
--- Clue from Waldek, Re: [fricas-devel] Numbers as type parameters
PRETTYPRINT(p1::Polynomial(Integer))$Lisp
(0 . 6665999993334)

\label{eq26}\left(\right)(26)
Type: SExpression?
fricas
PRETTYPRINT(q1::Polynomial(Integer))$Lisp
(1 |_6665999993334| (1 0 . 1))

\label{eq27}\left(\right)(27)
Type: SExpression?