$SPAD/src/input rules.input

Timothy Daly December 3, 2016

Abstract

Contents

2

1 License

— license —

--Copyright The Numerical Algorithms Group Limited 1991.

———-

— * —

)set break resume
)spool rules.output
)set message test on
)set message auto off
)clear all

———-

First a single rule — * —

--S 1 of 21
logrule := rule log(x) + log(y) == log(x * y)
--R
--R
--R   (1)  log(y) + log(x) + %B == log(x y) + %B
--R                       Type: RewriteRule(Integer,Integer,Expression(Integer))
--E 1
--S 2 of 21
f := log sin x + log x
--R
--R
--R   (2)  log(sin(x)) + log(x)
--R                                                    Type: Expression(Integer)
--E 2
--S 3 of 21
logrule f
--R
--R
--R   (3)  log(x sin(x))
--R                                                    Type: Expression(Integer)
--E 3

———-

Now a pile of several rules — * —

--S 4 of 21
logrules := rule
  log(x) + log(y) == log(x * y)
  y * log x       == log(x ** y)
--R
--R
--R                                                                y
--R   (4)  {log(y) + log(x) + %C == log(x y) + %C,y log(x) == log(x )}
--R                           Type: Ruleset(Integer,Integer,Expression(Integer))
--E 4
--S 5 of 21
f := a * log(sin x) - 2 * log x
--R
--R
--R   (5)  a log(sin(x)) - 2log(x)
--R                                                    Type: Expression(Integer)
--E 5
--S 6 of 21
logrules f
--R
--R
--R                  a
--R            sin(x)
--R   (6)  log(-------)
--R                2
--R               x
--R                                                    Type: Expression(Integer)
--E 6

———-

Example of a predicate attached to a pattern variable — * —

--S 7 of 21
logrules2 := rule
  log(x) + log(y)          == log(x * y)
  (y | integer? y) * log x == log(x ** y)
--R
--R
--R                                                                y
--R   (7)  {log(y) + log(x) + %D == log(x y) + %D,y log(x) == log(x )}
--R                           Type: Ruleset(Integer,Integer,Expression(Integer))
--E 7
--S 8 of 21
logrules2 f
--R

--R
--R                             1
--R   (8)  a log(sin(x)) + log(--)
--R                             2
--R                            x
--R                                                    Type: Expression(Integer)
--E 8

———-

Rules for linearizing sines and cosines — * —

--S 9 of 21
trigLinearize := rule
  sin(x) * sin(y)                      == cos(x-y)/2 - cos(x+y)/2
  cos(x) * cos(y)                      == cos(x+y)/2 + cos(x-y)/2
  sin(x) * cos(y)                      == sin(x+y)/2 + sin(x-y)/2
  sin(x) ** (n | integer? n and n > 1) == (1-cos(2*x))/2 * sin(x)**(n-2)
  cos(x) ** (n | integer? n and n > 1) == (1+cos(2*x))/2 * cos(x)**(n-2)
--R
--R
--R   (9)
--R                       - %F cos(y + x) + %F cos(y - x)
--R   {%F sin(x)sin(y) == -------------------------------,
--R                                      2
--R                       %G cos(y + x) + %G cos(y - x)
--R    %G cos(x)cos(y) == -----------------------------,
--R                                     2
--R                       %H sin(y + x) - %H sin(y - x)
--R    %H cos(y)sin(x) == -----------------------------,
--R                                     2
--R                                    n - 2                                n - 2
--R          n    (- cos(2x) + 1)sin(x)             n    (cos(2x) + 1)cos(x)
--R    sin(x)  == --------------------------, cos(x)  == ------------------------}
--R                            2                                     2
--R                           Type: Ruleset(Integer,Integer,Expression(Integer))
--E 9
--S 10 of 21
g := sin(a)*cos(b) + sin(a)*cos(a) + cos(2*a)*cos(3*a)
--R
--R
--R   (10)  (cos(b) + cos(a))sin(a) + cos(2a)cos(3a)
--R                                                    Type: Expression(Integer)
--E 10
--S 11 of 21
trigLinearize g
--R

--R
--R         sin(b + a) - sin(b - a) + sin(2a) + cos(5a) + cos(a)
--R   (11)  ----------------------------------------------------
--R                                   2
--R                                                    Type: Expression(Integer)
--E 11

———-

Here we show the use of ? to indicate an ’optional’ pattern variables — * —

--S 12 of 21
eirule := rule integral((?y + exp x)/x,x) == integral(y/x,x) + Ei x
--R
--R
--R            x   %K
--R          ++  %e   + y                   y
--R   (12)   |   -------- d%K  == 'integral(-,x) + 'Ei(x)
--R         ++      %K                      x
--R                       Type: RewriteRule(Integer,Integer,Expression(Integer))
--E 12
--S 13 of 21
eirule integral(exp u/u, u)
--R
--R
--R   (13)  Ei(u)
--R                                                    Type: Expression(Integer)
--E 13
--S 14 of 21
eirule integral(sin u + exp u/u, u)
--R
--R
--R            u
--R          ++
--R   (14)   |   sin(%K)d%K  + Ei(u)
--R         ++
--R                                                    Type: Expression(Integer)
--E 14

———-

Here we show the use of : to indicate a ’multiple’ pattern variables — * —

--S 15 of 21
u := operator u
--R
--R

--R   (15)  u
--R                                                          Type: BasicOperator
--E 15
--S 16 of 21
v := operator v
--R
--R
--R   (16)  v
--R                                                          Type: BasicOperator
--E 16
--S 17 of 21
myrule := rule u(x + y) == u x + v y
--R
--R
--R   (17)  u(y + x) == 'v(y) + 'u(x)
--R                       Type: RewriteRule(Integer,Integer,Expression(Integer))
--E 17
--S 18 of 21
h := u(a + b + c + d)
--R
--R
--R   (18)  u(d + c + b + a)
--R                                                    Type: Expression(Integer)
--E 18
--S 19 of 21
myrule h
--R
--R
--R   (19)  v(d + c + b) + u(a)
--R                                                    Type: Expression(Integer)
--E 19
--S 20 of 21
myrule2 := rule u(:x + y) == u x + v y
--R
--R
--R   (20)  u(y + x) == 'v(y) + 'u(x)
--R                       Type: RewriteRule(Integer,Integer,Expression(Integer))
--E 20
--S 21 of 21
myrule2 h
--R
--R
--R   (21)  v(c) + v(b) + v(a) + u(d)
--R                                                    Type: Expression(Integer)

--E 21 )spool )lisp (bye) ———-

8

References^{[1] nothing}

9