|
|
last edited 7 years ago by pagani |
1 | ||
Editor: pagani
Time: 2016/12/23 03:29:37 GMT+0 |
||
Note: |
changed: - \begin{axiom} )abbrev package EQREASON EquationalReasoning ++ Author: Kurt Pagani ++ Date Created: Mon Mar 21 17:10:18 CET 2016 ++ License: BSD ++ References: ++ Description: ++ EquationalReasoning(R) : Exports == Implementation where R : Join(Comparable, IntegralDomain) X ==> Expression R EQX ==> Equation X LEQX ==> List EQX Y ==> Union(LEQX,"failed") Exports == with unify: (LEQX, LEQX) -> Y reduceWith: (LEQX,LEQX) -> LEQX --coerce : % -> OutputForm Implementation == add symbolClash(x:EQX):Boolean == l:X:=lhs x r:X:=rhs x kl:=mainKernel l kr:=mainKernel r if (kl case Kernel(X)) and (kr case Kernel(X)) then return test(name kl ~= name kr) else true termReduce(x:EQX):Y == l:=lhs x r:=rhs x kl:=mainKernel l kr:=mainKernel r if (kl case Kernel(X)) and (kr case Kernel(X)) then al:=argument kl ar:=argument kr #al ~= #ar => "failed" [al.j = ar.j for j in 1..#al] else "failed" app?(x:X):Boolean == k:=mainKernel(x) if (k case Kernel X) then test(height k > 1) else false var?(x:X):Boolean == not(app?(x) or number?(x)) reduceWith2(x:LEQX, y:LEQX):LEQX == r:=x for i in 1..#y repeat r:=[subst(r.j,y.i) for j in 1..#x] return r reduceWith(x:LEQX, y:LEQX):LEQX == [subst(lhs(x.i),y) = subst(rhs(x.i),y) for i in 1..#x] occurs(x:X,y:X):Boolean == member?(x,[s::X for s in variables(y)]) unify(x:LEQX,S:LEQX):Y == if empty? x then return S l:=lhs(first x) r:=rhs(first x) if l = r then return unify(rest x,S) if number? l and number? r then return "failed" if (app? l or number? l) and var? r then return unify(concat([r=l],rest x),S) if var? l then if occurs(l,r) then return "failed" return unify(reduceWith(rest x,[l=r]),concat(reduceWith(S,[l=r]),[l=r])) if app? l and app? r then if symbolClash(l=r) then return "failed" rr:Y:=termReduce(l=r) if (rr case LEQX) then return unify(concat(rr,rest x),S) else return "failed" \end{axiom} \begin{axiom} -- nilqed Fre Sep 30 18:25:37 CEST 2016 :: helix -- 76 lines (66 sloc) 2.49 KB )clear all p:=operator 'p f:=operator 'f g:=operator 'g h:=operator 'h m:=operator 'm N:=29 -- number of tests ----------------------------------------- -- Type: List Equation Expression Integer ----------------------------------------- P1:=[f(g(x),x) = f(y,a)] P2:=[f(x,h(x),y) = f(g(z), u, z)] P3:=[p(a,x,f(y)) = p(u,v,w),p(a,x,f(y))= p(a, s,f(c)),p(u,v,w) = p(a,s,f(c))] P4:=[f(x, b, g(z)) = f(f(y), y, g(u))] P5:=[p(a,x,h(g(z))) = p(z,h(y),h(y))] P6:=[p(f(a),g(x)) = p(y,y)] P7:=[p(x,x) = p(y,f(y))] P8:=[sin(x+y) = sin(u^2+v^2)] P9:=[p(c,b)=p(a,c),p(a,b)=p(b,c)] P10:=[p(c,b)=p(a,c),p(a,b)=p(b,c),m(a,b)=m(c,d)] P11:=[g(x,f(x,b))=g(f(a,b),f(y,z))] P12:=[p(a,x,h(g(z)))=p(z,h(y),h(y))] P13:=[p(f(a),g(x))=p(y,y)] P14:=[f(x1)=f(g(x0,x0))] P15:=[f(x1,x2)=f(g(x0,x0),g(x1,x1))] P16:=[f(x1,x2,x3)=f(g(x0,x0),g(x1,x1),g(x2,x2))] -- Result list res:List(Boolean):=[false for i in 1..N] -------- -- unify -------- res.1:=test (unify(P1,[])=[y= g(a),x= a]) res.2:=test (unify(P2,[])=[x= g(z),u= h(g(z)),y= z]) res.3:=test (unify(P3,[])=[a= u,x= s,w= f(c),v= s,y= c]) res.4:=test (unify(P4,[])=[x= f(y),b= y,z= u]) res.5:=test (unify(P5,[])=[a= z,x= h(g(z)),y= g(z)]) res.6:=test (unify(P6,[]) case "failed") res.7:=test (unify(P7,[]) case "failed") res.8:=test (unify(P8,[])=[y + x = v^2 + u^2 ]) res.9:=test (unify(P9,[])= [c = a,b = a]) res.10:=test (unify(P10,[])= [c = d,b = d,a = d]) res.11:=test (unify(P11,[])=[x= f(a,z),y= f(a,z),b= z]) res.12:=test (unify(P12,[])=[a = z,x = h(g(z)),y = g(z)]) res.13:=test (unify(P13,[]) case "failed") res.14:=test (unify(P14,[])= [x1 = g(x0,x0)]) res.15:=test (unify(P15,[])=[x1 = g(x0,x0),x2 = g(g(x0,x0),g(x0,x0))]) res.16:=test (unify(P16,[])= [x1 = g(x0,x0), x2 = g(g(x0,x0),g(x0,x0)), _ x3 = g(g(g(x0,x0),g(x0,x0)),g(g(x0,x0),g(x0,x0)))]) res.17:=true ------------- -- reduceWith ------------- res.18:=test (reduceWith(P1,unify(P1,[])).1) res.19:=test (reduceWith(P2,unify(P2,[])).1) res.20:=test (reduceWith(P3,unify(P3,[])).1) res.21:=test (reduceWith(P4,unify(P4,[])).1) res.22:=test (reduceWith(P5,unify(P5,[])).1) res.23:=test (reduceWith(P9,unify(P9,[])).1) res.24:=test (reduceWith(P10,unify(P10,[])).1) res.25:=test (reduceWith(P11,unify(P11,[])).1) res.26:=test (reduceWith(P12,unify(P12,[])).1) res.27:=test (reduceWith(P14,unify(P14,[])).1) res.28:=test (reduceWith(P15,unify(P15,[])).1) res.29:=test (reduceWith(P16,unify(P16,[])).1) -- ***** Final result ***** reduce(_and,res) \end{axiom}
(1) -> )abbrev package EQREASON EquationalReasoning ++ Author: Kurt Pagani ++ Date Created: Mon Mar 21 17:10:18 CET 2016 ++ License: BSD ++ References: ++ Description: ++ EquationalReasoning(R) : Exports == Implementation where
R : Join(Comparable,IntegralDomain) X ==> Expression R EQX ==> Equation X LEQX ==> List EQX Y ==> Union(LEQX, "failed")
Exports == with
unify: (LEQX,LEQX) -> Y reduceWith: (LEQX, LEQX) -> LEQX --coerce : % -> OutputForm
Implementation == add
symbolClash(x:EQX):Boolean == l:X:=lhs x r:X:=rhs x kl:=mainKernel l kr:=mainKernel r if (kl case Kernel(X)) and (kr case Kernel(X)) then return test(name kl ~= name kr) else true
termReduce(x:EQX):Y == l:=lhs x r:=rhs x kl:=mainKernel l kr:=mainKernel r if (kl case Kernel(X)) and (kr case Kernel(X)) then al:=argument kl ar:=argument kr #al ~= #ar => "failed" [al.j = ar.j for j in 1..#al] else "failed"
app?(x:X):Boolean == k:=mainKernel(x) if (k case Kernel X) then test(height k > 1) else false
var?(x:X):Boolean == not(app?(x) or number?(x))
reduceWith2(x:LEQX,y:LEQX):LEQX == r:=x for i in 1..#y repeat r:=[subst(r.j, y.i) for j in 1..#x] return r
reduceWith(x:LEQX,y:LEQX):LEQX == [subst(lhs(x.i), y) = subst(rhs(x.i), y) for i in 1..#x]
occurs(x:X,y:X):Boolean == member?(x, [s::X for s in variables(y)])
unify(x:LEQX,S:LEQX):Y == if empty? x then return S l:=lhs(first x) r:=rhs(first x) if l = r then return unify(rest x, S) if number? l and number? r then return "failed" if (app? l or number? l) and var? r then return unify(concat([r=l], rest x), S) if var? l then if occurs(l, r) then return "failed" return unify(reduceWith(rest x, [l=r]), concat(reduceWith(S, [l=r]), [l=r])) if app? l and app? r then if symbolClash(l=r) then return "failed" rr:Y:=termReduce(l=r) if (rr case LEQX) then return unify(concat(rr, rest x), S) else return "failed"
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/3793212659814308865-25px.001.spad using old system compiler. EQREASON abbreviates package EquationalReasoning ------------------------------------------------------------------------ initializing NRLIB EQREASON for EquationalReasoning compiling into NRLIB EQREASON ****** Domain: R already in scope compiling local symbolClash : Equation Expression R -> Boolean Time: 0.03 SEC.
compiling local termReduce : Equation Expression R -> Union(List Equation Expression R,failed) Time: 0.01 SEC.
compiling local app? : Expression R -> Boolean Time: 0 SEC.
compiling local var? : Expression R -> Boolean Time: 0 SEC.
compiling local reduceWith2 : (List Equation Expression R,List Equation Expression R) -> List Equation Expression R Time: 0 SEC.
compiling exported reduceWith : (List Equation Expression R,List Equation Expression R) -> List Equation Expression R Time: 0 SEC.
compiling local occurs : (Expression R,Expression R) -> Boolean Time: 0 SEC.
compiling exported unify : (List Equation Expression R,List Equation Expression R) -> Union(List Equation Expression R, failed) Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |EquationalReasoning| REDEFINED
;;; *** |EquationalReasoning| REDEFINED Time: 0 SEC.
Cumulative Statistics for Constructor EquationalReasoning Time: 0.08 seconds
finalizing NRLIB EQREASON Processing EquationalReasoning for Browser database: --------constructor--------- --->-->EquationalReasoning((unify ((Union (List (Equation (Expression R))) failed) (List (Equation (Expression R))) (List (Equation (Expression R)))))): Not documented!!!! --->-->EquationalReasoning((reduceWith ((List (Equation (Expression R))) (List (Equation (Expression R))) (List (Equation (Expression R)))))): Not documented!!!! ; compiling file "/var/aw/var/LatexWiki/EQREASON.NRLIB/EQREASON.lsp" (written 01 NOV 2024 12:52:04 AM):
; wrote /var/aw/var/LatexWiki/EQREASON.NRLIB/EQREASON.fasl ; compilation finished in 0:00:00.036 ------------------------------------------------------------------------ EquationalReasoning is now explicitly exposed in frame initial EquationalReasoning will be automatically loaded when needed from /var/aw/var/LatexWiki/EQREASON.NRLIB/EQREASON
-- nilqed Fre Sep 30 18:25:37 CEST 2016 :: helix
)clear all
All user variables and function definitions have been cleared.
p:=operator 'p
(1) |
f:=operator 'f
(2) |
g:=operator 'g
(3) |
h:=operator 'h
(4) |
m:=operator 'm
(5) |
N:=29 -- number of tests
(6) |
----------------------------------------- --
----------------------------------------- P1:=[f(g(x),x) = f(y, a)]
(7) |
P2:=[f(x,h(x), y) = f(g(z), u, z)]
(8) |
P3:=[p(a,x, f(y)) = p(u, v, w), p(a, x, f(y))= p(a, s, f(c)), p(u, v, w) = p(a, s, f(c))]
(9) |
P4:=[f(x,b, g(z)) = f(f(y), y, g(u))]
(10) |
P5:=[p(a,x, h(g(z))) = p(z, h(y), h(y))]
(11) |
P6:=[p(f(a),g(x)) = p(y, y)]
(12) |
P7:=[p(x,x) = p(y, f(y))]
(13) |
P8:=[sin(x+y) = sin(u^2+v^2)]
(14) |
P9:=[p(c,b)=p(a, c), p(a, b)=p(b, c)]
(15) |
P10:=[p(c,b)=p(a, c), p(a, b)=p(b, c), m(a, b)=m(c, d)]
(16) |
P11:=[g(x,f(x, b))=g(f(a, b), f(y, z))]
(17) |
P12:=[p(a,x, h(g(z)))=p(z, h(y), h(y))]
(18) |
P13:=[p(f(a),g(x))=p(y, y)]
(19) |
P14:=[f(x1)=f(g(x0,x0))]
(20) |
P15:=[f(x1,x2)=f(g(x0, x0), g(x1, x1))]
(21) |
P16:=[f(x1,x2, x3)=f(g(x0, x0), g(x1, x1), g(x2, x2))]
(22) |
-- Result list res:List(Boolean):=[false for i in 1..N]
(23) |
-------- -- unify -------- res.1:=test (unify(P1,[])=[y= g(a), x= a])
(24) |
res.2:=test (unify(P2,[])=[x= g(z), u= h(g(z)), y= z])
(25) |
res.3:=test (unify(P3,[])=[a= u, x= s, w= f(c), v= s, y= c])
(26) |
res.4:=test (unify(P4,[])=[x= f(y), b= y, z= u])
(27) |
res.5:=test (unify(P5,[])=[a= z, x= h(g(z)), y= g(z)])
(28) |
res.6:=test (unify(P6,[]) case "failed")
(29) |
res.7:=test (unify(P7,[]) case "failed")
(30) |
res.8:=test (unify(P8,[])=[y + x = v^2 + u^2 ])
(31) |
res.9:=test (unify(P9,[])= [c = a, b = a])
(32) |
res.10:=test (unify(P10,[])= [c = d, b = d, a = d])
(33) |
res.11:=test (unify(P11,[])=[x= f(a, z), y= f(a, z), b= z])
(34) |
res.12:=test (unify(P12,[])=[a = z, x = h(g(z)), y = g(z)])
(35) |
res.13:=test (unify(P13,[]) case "failed")
(36) |
res.14:=test (unify(P14,[])= [x1 = g(x0, x0)])
(37) |
res.15:=test (unify(P15,[])=[x1 = g(x0, x0), x2 = g(g(x0, x0), g(x0, x0))])
(38) |
res.16:=test (unify(P16,[])= [x1 = g(x0, x0), x2 = g(g(x0, x0), g(x0, x0)), _ x3 = g(g(g(x0, x0), g(x0, x0)), g(g(x0, x0), g(x0, x0)))])
(39) |
res.17:=true
(40) |
------------- -- reduceWith ------------- res.18:=test (reduceWith(P1,unify(P1, [])).1)
(41) |
res.19:=test (reduceWith(P2,unify(P2, [])).1)
(42) |
res.20:=test (reduceWith(P3,unify(P3, [])).1)
(43) |
res.21:=test (reduceWith(P4,unify(P4, [])).1)
(44) |
res.22:=test (reduceWith(P5,unify(P5, [])).1)
(45) |
res.23:=test (reduceWith(P9,unify(P9, [])).1)
(46) |
res.24:=test (reduceWith(P10,unify(P10, [])).1)
(47) |
res.25:=test (reduceWith(P11,unify(P11, [])).1)
(48) |
res.26:=test (reduceWith(P12,unify(P12, [])).1)
(49) |
res.27:=test (reduceWith(P14,unify(P14, [])).1)
(50) |
res.28:=test (reduceWith(P15,unify(P15, [])).1)
(51) |
res.29:=test (reduceWith(P16,unify(P16, [])).1)
(52) |
-- ***** Final result ***** reduce(_and,res)
(53) |