home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol166 / deriv.cnv < prev    next >
Encoding:
Text File  |  1984-04-29  |  3.3 KB  |  133 lines

  1.  
  2. [DERIV.CNV]
  3. [Calculate symbolic derivatives]
  4. [Harold V. McIntosh, 26 July 1983]
  5.  
  6. [[
  7. Symbolic differentiation is a symbol manipulation process, in
  8. which the known rules for derivatives, such as: the derivative
  9. of a sum is a sum of derivatives, the derivative of a product
  10. is a sum in which one factor is differentiated at a time, or
  11. the chain rule for the derivative of a function of a function,
  12. are applied recursively until finally the derivative of a constant
  13. is zero or the derivative of the variable iself is one.
  14.  
  15. Enter an algebraic expression - only sums, differences, products,
  16. and quotients are considered, and only integer constants. Terms
  17. may be enclosed in parentheses.  Terminate your expression with a
  18. carriage return. The expression will be parsed and differentiated,
  19. finally the result shown; the result may be surprising because very
  20. little simplification and no rearrangement is made. Exit with a
  21. single carriage return. The message "other" indicates an error.
  22. ]]
  23.  
  24.  
  25.  
  26. [individual cases]
  27. (()()(0 1)(
  28.         ((PWS,intermediate )(or),);
  29.   [sum]        ((and,(itr,<:j:>)+,<0>+<>)<1>,(s,(x,<0>)<,>(x,<1>)));
  30.   [difference]    ((and,(ITR,<:l:>-),<0>-<>)<1>,(m,(x,<0>)<,>(x,<1>)));
  31.   [product]    ((and,(itr,<:j:>)*,<0>*<>)<1>,<<
  32.             >>(s,(p,<0><,>(x,<1>))<<
  33.             >><,>(p,(x,<0>)<,><1>)));
  34.   [quotient]    ((and,(itr,<:j:>)/,<0>/<>)<1>,<<
  35.             >>(q,<(>(u,(m,(p,(x,<0>)<,><1>)<<
  36.             >><,>(p,<0><,>(x,<1>))))<)><<
  37.             >><,>(p,<1><,><1>)));
  38.   [paren]    ((and,<:i:><>,<(><0><)><>),<0>):
  39.   [unary -]    (-<0>,(n,(x,<0>)));
  40.   [variable]    (x<>,1);
  41.   [constant]    (<:j:><>,0);
  42.   [other]    (<0>,(%C,other: <0>));
  43.   )) x
  44.  
  45. [simplify difference]
  46. (()()(0 1)(
  47.         (<0><,><0>,0);
  48.         (<0><,>0<>,<0>);
  49.         (0<,><0>,(n,<0>));
  50.         ((and,<:U:><,><:U:><>,<0><,><1>),(#-,<0>-<1>));
  51.         (<0><,><1>,<0>-<1>);
  52.   )) m
  53.  
  54. [simplify negative]
  55. (()()(0)(
  56.         (0<>,0);
  57.         (<(>(and,(or,-,)<:k:>,<0>)<)><>,<0>):
  58.         (-(and,<:k:><>,<0>),<0>);
  59.         ((and,<:k:><>,<0>),-<0>);
  60.         (<0>,-<(><0><)>);
  61.   )) n
  62.  
  63. [parenthesize composite]
  64. (()()(0)(
  65.         ((and,<:k:><>,<0>),<0>);
  66.         (<0>,<(><0><)>);
  67.   )) o
  68.  
  69. [simplify product]
  70. (()()(0 1)(
  71.         (0<,><-->,0);
  72.         (<--><,>0<>,0);
  73.         (1<,><0>,<0>);
  74.         (<0><,>1<>,<0>);
  75.         ((and,<:U:><,><:U:><>,<0><,><1>),(#*,<0>*<1>)) ;
  76.         (<0><,><1>,(o,<0>)*(o,<1>));
  77.   )) p
  78.  
  79. [simplify quotient]
  80. (()()(0 1)(
  81.         (0<,><-->,0);
  82.         (<(>(and,<:k:>,<0>)<)><,><1>,<0><,><1>):
  83.         (<(>-(and,<:k:>,<0>)<)><,><1>,-<0><,><1>):
  84.         (<0><,>1<>,<0>);
  85.         (<0><,><1>,(o,<0>)/(o,<1>));
  86.   )) q
  87.  
  88. [simplify sum]
  89. (()()(0 1)(
  90.         (0<,><0>,<0>);
  91.         (<0><,>0<>,<0>);
  92.         ((and,<:U:><,><:U:><>,<0><,><1>),(#+,<0>+<1>));
  93.         (<0><,><0>,2*<0>);
  94.         (<0><,><1>,<0>+<1>);
  95.   )) s
  96.  
  97. [negate expression]
  98. (()()(0 1)(
  99.     ((and,<:l:>,<0>)+<1>,<0>-(t,<1>));
  100.     ((and,<:l:>,<0>)-<1>,<0>+(t,<1>));
  101.   )) t
  102.  
  103. [common level for sum or difference]
  104. (()()(0 1)(
  105.     ((and,<:i:>,<(><0><)>)+(and,<:i:>,<(><1><)>),<0>+<1>);
  106.     ((and,<:i:>,<(><0><)>)-(and,<:i:>,<(><1><)>),<0>-(t,<1>));
  107.   )) u
  108.  
  109. [collect]
  110. (()()(0 1 2)(
  111.   )) v
  112.  
  113. [main program]
  114. ((
  115.   [alfanum]  ((and,<[1]>,(IVL, ,~,))) a
  116.   [numeric]  ((and,<[1]>,(IVL,0,9,))) b
  117.   [uconst]   (<:b:>(ITR,<:b:>)) U
  118.   [number]   ((or,-,)<:U:>) c
  119.   [pelem]    ((and,<[1]>,(nor,<(>,<)>))) e
  120.   [telem]    ((and,<[1]>,(nor,<(>,<)>,+,-,*,/))) f
  121.   [token]    (<:f:>(ITR,<:f:>)) g
  122.   [paren]    (<(>(ITR,<:j:>)<)>) i
  123.   [term]     ((or,<:i:>,<:e:>)) j
  124.   [t or p]   ((or,<:g:>,<:i:>)) k
  125.   [prqu]     (<:k:>(ITR,(or,*,/)<:k:>)) l
  126.  
  127.   )()(0)(
  128.     ((or,;,<>),goodbye);
  129.     (<0>,(%C,(x,<0>))(%R)):
  130.   ))
  131.  
  132. [end]
  133.