Browse Source

Write additions definition

Samuel W. Flint 5 years ago
parent
commit
aa34602083
1 changed files with 28 additions and 3 deletions
  1. 28 3
      larcs.org

+ 28 - 3
larcs.org

@@ -453,7 +453,7 @@ Equality of constants is a bit different, and is checked as follows:
        (slot-value expression-b 'value)))
 #+END_SRC
 
-** WORKING Compound Types [4/7]
+** WORKING Compound Types [5/7]
 :PROPERTIES:
 :ID:       a0d2eb19-8a1e-4dee-9b41-c454a49cacc4
 :END:
@@ -471,6 +471,32 @@ Compound types are the majority of expressions.  An atom is well and good, but o
     nil)
 #+END_SRC
 
+*** DONE Additions
+CLOSED: [2019-01-05 Sat 16:00]
+:PROPERTIES:
+:ID:       a1a01fb4-59e1-4459-9ab9-d32269af77dd
+:END:
+
+~<addition>~ is simple, an ~<addition>~ has only a list of terms.  As with ~<multiplication>~, two ~<addition>~ objects are equal if they have the same number of terms and all terms are the same, order not withstanding (as addition is commutative).
+
+#+Caption: Additions
+#+Name: type-additions
+#+BEGIN_SRC lisp 
+  @export
+  (defclass <addition> (<compound>)
+    ((terms :reader terms
+            :initarg :terms
+            :type (list <expression>))))
+
+  (defmethod eqal ((expression-a <addition>) (expression-b <addition>))
+    (let ((terms-a (terms expression-a))
+          (terms-b (terms expression-b)))
+      (and (= (length terms-a)
+            (length terms-b))
+         (null (set-difference terms-a terms-b
+                               :test #'eqal)))))
+#+END_SRC
+
 *** DONE Multiplications
 CLOSED: [2019-01-05 Sat 12:17]
 :PROPERTIES:
@@ -600,8 +626,6 @@ CLOSED: [2019-01-05 Sat 15:47]
 
 *** TODO Trigonometric
 
-*** TODO Additions
-
 *** TODO Subtractions
 
 ** DONE Blended Types -- Polynomial Terms
@@ -2028,6 +2052,7 @@ As all of the packages are defined centrally, this makes resolving inter-package
   <<type-constants>>
 
   <<type-compound>>
+  <<type-additions>>
   <<type-multiplications>>
   <<type-division>>
   <<type-exponentials>>