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)
Type: Type
fricas
SEI:=SYMINT(EXPR INT)
Type: Type
fricas
SSY:=SYMINT(Symbol)
Type: Type
fricas
integerSymbol?(_344::POLY(INT)) --> true
Type: Boolean
fricas
integerSymbol?(_344::EXPR(INT)) --> true
Type: Boolean
fricas
--integerSymbol?(_344::Symbol) --> true / not after adding CFS
integerSymbol?(_-122222222222222229888::POLY INT) --> true
Type: Boolean
fricas
integerSymbol?(_122222222222222229888::POLY INT) --> true
Type: Boolean
fricas
integerSymbol?(m::POLY INT) --> false
Type: Boolean
fricas
sym2int(_1234567890::POLY INT) --> 1234567890
fricas
sym2int(_-1234567890::POLY INT) --> - 1234567890
Type: Integer
fricas
sym2int(_1234567890::EXPR INT)
fricas
sym2int(_-1234567890::EXPR INT)
Type: Integer
fricas
int2sym(1234567890)$SYMINT(POLY INT) --> _1234567890 Polynomial(Integer)
Type: Polynomial(Integer)
fricas
int2sym(-1234567890)$SYMINT(POLY INT) --> _-1234567890
Type: Polynomial(Integer)
fricas
int2sym(-1234567890)$SYMINT(EXPR INT) --> _-1234567890
Type: Expression(Integer)
fricas
T:=POLY INT
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)
Type: Polynomial(Integer)
fricas
sum [_1::T,_2::T,_-3::T] --> 0
Type: Polynomial(Integer)
fricas
T:=EXPR INT
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)
Type: Expression(Integer)
fricas
p2:=prod [_-2::T,_9999::T,_333333333::T]
Type: Expression(Integer)
fricas
q1:=int2sym(p1)$SEI
Type: Expression(Integer)
fricas
q2:=int2sym(p2)$SEI
Type: Expression(Integer)
fricas
prod [q1,q2]
Type: Expression(Integer)
fricas
--- why not????
Symbol has CoercibleFrom Symbol
Type: Boolean
fricas
--- Clue from Waldek, Re: [fricas-devel] Numbers as type parameters
PRETTYPRINT(p1::Polynomial(Integer))$Lisp
(0 . 6665999993334)
fricas
PRETTYPRINT(q1::Polynomial(Integer))$Lisp
(1 |_6665999993334| (1 0 . 1))