And "assume" system based on equational reasoning.
fricas
domains:=empty()$Table(Symbol,BasicOperator)
Type: Table(Symbol,
BasicOperator
?)
fricas
assume(x:Expression Integer,t:Symbol):Expression Integer ==
-- cache operators
if not key?(t,domains) then domains.t := operator t
(domains.t) x
Function declaration assume : (Expression(Integer),Symbol) ->
Expression(Integer) has been added to workspace.
Type: Void
fricas
markConstants(x:Expression Integer):Expression Integer ==
if (s:=isPlus(x)) case List Expression Integer then
return reduce(+,[markConstants i for i in s::List Expression Integer])
if (s:=isTimes(x)) case List Expression Integer then
return reduce(*,[markConstants i for i in s::List Expression Integer])
if (r:=retractIfCan(x)@Union(Integer,"failed")) case Integer then
if r<0 then return assume(x,'integer)
if r>0 then return assume(x,'positiveInteger)
return assume(x, 'nonNegativeInteger)
return x
Function declaration markConstants : Expression(Integer) ->
Expression(Integer) has been added to workspace.
Type: Void
fricas
prove := rule
-- subtypes
assume(assume(x,'integer),'integer) == assume(x,'integer)
assume(assume(x,'integer),'nonNegativeInteger) == assume(x,'nonNegativeInteger)
assume(assume(x,'integer),'positiveInteger) == assume(x,'positiveInteger)
--
assume(assume(x,'nonNegativeInteger),'integer) == assume(x,'nonNegativeInteger)
assume(assume(x,'nonNegativeInteger),'nonNegativeInteger) == assume(x,'nonNegativeInteger)
assume(assume(x,'nonNegativeInteger),'positiveInteger) == assume(x,'positiveInteger)
--
assume(assume(x,'positiveInteger),'integer) == assume(x,'positiveInteger)
assume(assume(x,'positiveInteger),'nonNegativeInteger) == assume(x,'positiveInteger)
assume(assume(x,'positiveInteger),'positiveInteger) == assume(x,'positiveInteger)
-- operations
assume(x,'integer) + assume(y,'integer) == assume(x+y,'integer)
assume(x,'integer) + assume(y,'nonNegativeInteger) == assume(x+y,'integer)
assume(x,'integer) + assume(y,'positiveInteger) == assume(x+y,'integer)
assume(x,'nonNegativeInteger) + assume(y,'nonNegativeInteger) == assume(x+y,'nonNegativeInteger)
assume(x,'nonNegativeInteger) + assume(y,'positiveInteger) == assume(x+y,'nonNegativeInteger)
assume(x,'positiveInteger)+assume(y,'positiveInteger) == assume(x+y,'positiveInteger)
assume(x,'positiveInteger)+assume(y,'nonNegativeInteger) == assume(x+y,'positiveInteger)
fricas
Compiling function assume with type (Expression(Integer),Symbol) ->
Expression(Integer)
Type: Ruleset(Integer,Integer,Expression(Integer))
fricas
check(x:Expression Integer,t:Symbol):Boolean ==
--k:=retractIfCan(prove markConstants x)@Union(Kernel Expression Integer,"failed")
--if k case Kernel Expression Integer then is?(k,t) else false
p := prove markConstants x
e := equation(p, prove markConstants assume(p,t))
output e
e
Function declaration check : (Expression(Integer),Symbol) -> Boolean
has been added to workspace.
Type: Void
fricas
assume(x,'positiveInteger)
Type: Expression(Integer)
fricas
prove %
Type: Expression(Integer)
fricas
assume(x,'positiveInteger)+1
Type: Expression(Integer)
fricas
prove markConstants %
fricas
Compiling function markConstants with type Expression(Integer) ->
Expression(Integer)
Type: Expression(Integer)
fricas
assume(assume(x,'nonNegativeInteger),'positiveInteger)
Type: Expression(Integer)
fricas
prove %
Type: Expression(Integer)
fricas
check(assume(x,'positiveInteger),'positiveInteger)
fricas
Compiling function check with type (Expression(Integer),Symbol) ->
Boolean
positiveInteger(x) = positiveInteger(x)
Type: Boolean
fricas
check(assume(x,'positiveInteger)+1,'positiveInteger)
positiveInteger(x + 1) = positiveInteger(x + 1)
Type: Boolean
fricas
check(3,'positiveInteger)
positiveInteger(3) = positiveInteger(3)
Type: Boolean
fricas
check(-3,'positiveInteger)
integer(- 3) = positiveInteger(- 3)
Type: Boolean
fricas
check(0,'positiveInteger)
nonNegativeInteger(0) = positiveInteger(0)
Type: Boolean
fricas
--
assume(x,'nonNegativeInteger)
Type: Expression(Integer)
fricas
prove %
Type: Expression(Integer)
fricas
check(assume(x,'positiveInteger),'nonNegativeInteger)
positiveInteger(x) = positiveInteger(x)
Type: Boolean
fricas
assume(x,'nonNegativeInteger)+1
Type: Expression(Integer)
fricas
prove markConstants %
Type: Expression(Integer)
fricas
assume(assume(x,'integer),'nonNegativeInteger)
Type: Expression(Integer)
fricas
prove %
Type: Expression(Integer)
fricas
check(assume(x,'nonNegativeInteger),'nonNegativeInteger)
nonNegativeInteger(x) = nonNegativeInteger(x)
Type: Boolean
fricas
check(assume(x,'nonNegativeInteger)+1,'nonNegativeInteger)
positiveInteger(x + 1) = positiveInteger(x + 1)
Type: Boolean
fricas
check(3,'nonNegativeInteger)
positiveInteger(3) = positiveInteger(3)
Type: Boolean
fricas
check(-3,'nonNegativeInteger)
integer(- 3) = nonNegativeInteger(- 3)
Type: Boolean
fricas
check(0,'nonNegativeInteger)
nonNegativeInteger(0) = nonNegativeInteger(0)
Type: Boolean
fricas
--
assume(x,'integer)
Type: Expression(Integer)
fricas
prove %
Type: Expression(Integer)
fricas
check(assume(x,'positiveInteger),'integer)
positiveInteger(x) = positiveInteger(x)
Type: Boolean
fricas
assume(x,'integer)+1
Type: Expression(Integer)
fricas
prove markConstants %
Type: Expression(Integer)
fricas
assume(assume(x,'integer),'integer)
Type: Expression(Integer)
fricas
prove %
Type: Expression(Integer)
fricas
check(assume(x,'integer),'integer)
integer(x) = integer(x)
Type: Boolean
fricas
check(assume(x,'integer)+1,'integer)
integer(x + 1) = integer(x + 1)
Type: Boolean
fricas
check(3,'integer)
positiveInteger(3) = positiveInteger(3)
Type: Boolean
fricas
check(-3,'integer)
integer(- 3) = integer(- 3)
Type: Boolean
fricas
check(0,'integer)
nonNegativeInteger(0) = nonNegativeInteger(0)
Type: Boolean
fricas
domains
Type: Table(Symbol,
BasicOperator
?)