symcalc 0.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/LICENSE.txt +202 -95
  3. data/lib/symcalc.rb +173 -31
  4. metadata +5 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab527844085471beb0057a27b9538997e055c41331a4d72791a3017ab3b0babb
4
- data.tar.gz: 81d11403ccf1a3ebb81cc4af3ac952161f11d7213dbf9be1f0368db48f1380ba
3
+ metadata.gz: dcfa9e29e383d1a24d3545c1944efac692a2e973861548dafeeaa61b34641147
4
+ data.tar.gz: 5bca902b27d64a837d3908b1bd835f519f1f8f707e4dc56fd99d5b971e9821c9
5
5
  SHA512:
6
- metadata.gz: eea3871f2af7102b5c7718153d681efaf6ddc8761afdcacb1e65946f236f23e57e86994937c6937d9a773bc3bd6c701dcd7ecf36b0835a5446b39d7f0ec8dbab
7
- data.tar.gz: a75450e788eebba783db6057055f8b2142df9e6a6663c2d97f6ce5b79267efde188d081b8f09d0c3b538758811aff6a4a638f66fd99e8f2d7487a94e62f1a799
6
+ metadata.gz: 49729eafc708ea1e59c50ad7f3c5d3a9dfd06ce21d673379e2050cc091b4ade9631d554e0d113db992f64303f5bd1f2c5ea0123a84aa36536a744d8d577d6e64
7
+ data.tar.gz: 7c84949657233ded9848633861fbd43963379b6fc468ef862cdb48830d2677547a1b7c8931d8e60d21356afef64cb5486229dcf29ff298af836a91b034321fcd
data/lib/LICENSE.txt CHANGED
@@ -1,95 +1,202 @@
1
- Attribution-ShareAlike 4.0 International
2
-
3
- By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.
4
-
5
- Section 1 – Definitions.
6
-
7
- Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image.
8
- Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License.
9
- BY-SA Compatible License means a license listed at creativecommons.org/compatiblelicenses , approved by Creative Commons as essentially the equivalent of this Public License.
10
- Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.
11
- Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements.
12
- Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.
13
- License Elements means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution and ShareAlike.
14
- Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License.
15
- Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.
16
- Licensor means the individual(s) or entity(ies) granting rights under this Public License.
17
- Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.
18
- Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.
19
- You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning.
20
- Section 2 Scope.
21
-
22
- License grant .
23
- Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:
24
- reproduce and Share the Licensed Material, in whole or in part; and
25
- produce, reproduce, and Share Adapted Material.
26
- Exceptions and Limitations . For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions.
27
- Term . The term of this Public License is specified in Section 6(a) .
28
- Media and formats; technical modifications allowed . The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material.
29
- Downstream recipients .
30
- Offer from the Licensor – Licensed Material . Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License.
31
- Additional offer from the Licensor Adapted Material . Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply.
32
- No downstream restrictions . You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.
33
- No endorsement . Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i) .
34
- Other rights .
35
- Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise.
36
- Patent and trademark rights are not licensed under this Public License.
37
- To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties.
38
- Section 3 License Conditions.
39
-
40
- Your exercise of the Licensed Rights is expressly made subject to the following conditions.
41
-
42
- Attribution .
43
- If You Share the Licensed Material (including in modified form), You must:
44
-
45
- retain the following if it is supplied by the Licensor with the Licensed Material:
46
- identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated);
47
- a copyright notice;
48
- a notice that refers to this Public License;
49
- a notice that refers to the disclaimer of warranties;
50
- a URI or hyperlink to the Licensed Material to the extent reasonably practicable;
51
- indicate if You modified the Licensed Material and retain an indication of any previous modifications; and
52
- indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License.
53
- You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.
54
- If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable.
55
- ShareAlike .
56
- In addition to the conditions in Section 3(a) , if You Share Adapted Material You produce, the following conditions also apply.
57
-
58
- The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-SA Compatible License.
59
- You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material.
60
- You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply.
61
- Section 4 Sui Generis Database Rights.
62
-
63
- Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:
64
-
65
- for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database;
66
- if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b) ; and
67
- You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database.
68
- For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights.
69
-
70
- Section 5 Disclaimer of Warranties and Limitation of Liability.
71
-
72
- Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.
73
- To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.
74
- The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.
75
- Section 6 Term and Termination.
76
-
77
- This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically.
78
- Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates:
79
-
80
- automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or
81
- upon express reinstatement by the Licensor.
82
- For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License.
83
-
84
- For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License.
85
- Sections 1 , 5 , 6 , 7 , and 8 survive termination of this Public License.
86
- Section 7 Other Terms and Conditions.
87
-
88
- The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.
89
- Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.
90
- Section 8 Interpretation.
91
-
92
- For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License.
93
- To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions.
94
- No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.
95
- Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/lib/symcalc.rb CHANGED
@@ -1,11 +1,20 @@
1
+ # Copyright (c) 2024 Kyryl Shyshko
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
1
6
  #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
2
8
  #
3
- # Copyright (c) 2023 Kyryl Shyshko
4
- #
5
- # This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License
6
- # To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/legalcode.en, or read LICENSE.txt
9
+ # or
7
10
  #
11
+ # read LICENSE.txt in the SymCalc lib folder
8
12
  #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
9
18
 
10
19
 
11
20
  class Equation
@@ -152,10 +161,8 @@ class Equation
152
161
 
153
162
  end
154
163
 
155
- # coeff = to_equation(coeff.eval({}))
156
164
  coeff = coeff.__simplify__
157
165
 
158
-
159
166
  if coeff == to_equation(1)
160
167
  eq = eq
161
168
  elsif coeff == to_equation(0)
@@ -185,28 +192,38 @@ class Equation
185
192
  # puts fx.eval(x: 3)
186
193
  #
187
194
  def eval(var_hash)
188
- # begin
189
- if var_hash.values.size == 0
190
- return self.__eval__(Hash.new)
191
- elsif !var_hash.values[0].is_a?(Array)
192
- return self.__eval__ var_hash
193
- elsif var_hash.values[0].is_a? Array
194
- computed = []
195
- var_hash.values[0].size.times do |i|
196
- hash = var_hash.map {|k, v| [k, v[i]]}.to_h
197
- computed << self.__eval__(hash)
198
- end
199
- return computed
195
+ if var_hash.values.size == 0
196
+ result = self.__eval__(Hash.new)
197
+ elsif !var_hash.values[0].is_a?(Array)
198
+ result = self.__eval__ var_hash
199
+ elsif var_hash.values[0].is_a? Array
200
+ result = []
201
+ var_hash.values[0].size.times do |i|
202
+ hash = var_hash.map {|k, v| [k, v[i]]}.to_h
203
+ result << self.__eval__(hash)
200
204
  end
201
- # rescue
202
- # puts "Could not compute the value. Skipping"
203
- # return nil
204
- # end
205
+ end
206
+ result
205
207
  end
206
208
 
207
209
 
208
210
 
211
+ def __sub__ original, replacement
212
+ return to_equation(replacement) if self == to_equation(original)
213
+ return self
214
+ end
209
215
 
216
+ # Returns an equation with an expression substituted for the replacement
217
+ #
218
+ # Example:
219
+ # a = SymCalc.var("a")
220
+ # f = a ** 2
221
+ # x = SymCalc.var("x")
222
+ # puts f.sub(a, 3 * x) # => (3 * x) ** 2
223
+ #
224
+ def sub original, replacement
225
+ self.__sub__(original, replacement).simplify
226
+ end
210
227
  end
211
228
 
212
229
  # Converts the given argument into the equation type, if not already an equation
@@ -232,7 +249,11 @@ class EquationValue < Equation
232
249
  end
233
250
 
234
251
  def __eval__ var_hash
235
- return @value.to_f
252
+ if @value.is_a? Integer
253
+ return @value.to_f
254
+ else
255
+ return @value
256
+ end
236
257
  end
237
258
 
238
259
  def __derivative__ variable: nil
@@ -240,11 +261,7 @@ class EquationValue < Equation
240
261
  end
241
262
 
242
263
  def ==(value)
243
- if value.is_a? EquationValue
244
- return @value == value.value
245
- else
246
- return false
247
- end
264
+ @value == value
248
265
  end
249
266
 
250
267
  def hash
@@ -293,7 +310,6 @@ class Variable < Equation
293
310
  return @name
294
311
  end
295
312
 
296
-
297
313
  def __eval__ var_hash
298
314
  if @fixed_value
299
315
  return @fixed_value
@@ -380,6 +396,10 @@ class Sum < Equation
380
396
  return (@lside.all_variables + @rside.all_variables).uniq
381
397
  end
382
398
 
399
+ def __sub__ original, replacement
400
+ return to_equation(replacement) if self == to_equation(original)
401
+ return @lside.__sub__(original, replacement) + @rside.__sub__(original, replacement)
402
+ end
383
403
  end
384
404
 
385
405
  # Implements the subtraction operation in SymCalc
@@ -430,6 +450,11 @@ class Subtraction < Equation
430
450
  def all_variables
431
451
  return (@lside.all_variables + @rside.all_variables).uniq
432
452
  end
453
+
454
+ def __sub__ original, replacement
455
+ return to_equation(replacement) if self == to_equation(original)
456
+ return @lside.__sub__(original, replacement) - @rside.__sub__(original, replacement)
457
+ end
433
458
  end
434
459
 
435
460
  # Implements the multiplication operation in SymCalc
@@ -482,6 +507,11 @@ class Multiplication < Equation
482
507
  def all_variables
483
508
  return (@lside.all_variables + @rside.all_variables).uniq
484
509
  end
510
+
511
+ def __sub__ original, replacement
512
+ return to_equation(replacement) if self == to_equation(original)
513
+ return @lside.__sub__(original, replacement) * @rside.__sub__(original, replacement)
514
+ end
485
515
  end
486
516
 
487
517
  # Implements the division operation in SymCalc
@@ -542,6 +572,11 @@ class Division < Equation
542
572
  def all_variables
543
573
  return (@lside.all_variables + @rside.all_variables).uniq
544
574
  end
575
+
576
+ def __sub__ original, replacement
577
+ return to_equation(replacement) if self == to_equation(original)
578
+ return @lside.__sub__(original, replacement) / @rside.__sub__(original, replacement)
579
+ end
545
580
  end
546
581
 
547
582
 
@@ -596,6 +631,11 @@ class Exp < Equation
596
631
  def all_variables
597
632
  return @power.all_variables
598
633
  end
634
+
635
+ def __sub__ original, replacement
636
+ return to_equation(replacement) if self == to_equation(original)
637
+ return Exp.new(@power.__sub__(original, replacement))
638
+ end
599
639
  end
600
640
 
601
641
 
@@ -660,6 +700,10 @@ class Power < Equation
660
700
  else
661
701
  return base ** power
662
702
  end
703
+ elsif base.is_a?(Power)
704
+ new_base = base.base
705
+ new_power = base.power * power
706
+ return (new_base ** new_power).simplify
663
707
  else
664
708
  return base ** power
665
709
  end
@@ -669,6 +713,11 @@ class Power < Equation
669
713
  def all_variables
670
714
  return (@base.all_variables + @power.all_variables).uniq
671
715
  end
716
+
717
+ def __sub__ original, replacement
718
+ return to_equation(replacement) if self == to_equation(original)
719
+ return @base.__sub__(original, replacement) ** @power.__sub__(original, replacement)
720
+ end
672
721
  end
673
722
 
674
723
  # Implements the sin operation in SymCalc
@@ -689,6 +738,10 @@ class Sin < Equation
689
738
  return Cos.new(@eq) * @eq.derivative(variable: variable)
690
739
  end
691
740
 
741
+ def __simplify__
742
+ return Sin.new(@eq.__simplify__)
743
+ end
744
+
692
745
  def __get_m_elements__ var_hash
693
746
  if var_hash.keys.include? self
694
747
  var_hash[self] += 1
@@ -701,6 +754,11 @@ class Sin < Equation
701
754
  def all_variables
702
755
  return @eq.all_variables
703
756
  end
757
+
758
+ def __sub__ original, replacement
759
+ return to_equation(replacement) if self == to_equation(original)
760
+ return Sin.new(@eq.__sub__(original, replacement))
761
+ end
704
762
  end
705
763
 
706
764
  # Implements the cos operation in SymCalc
@@ -721,6 +779,10 @@ class Cos < Equation
721
779
  return -1 * Sin.new(@eq) * @eq.derivative(variable: variable)
722
780
  end
723
781
 
782
+ def __simplify__
783
+ return Cos.new(@eq.__simplify__)
784
+ end
785
+
724
786
  def __get_m_elements__ var_hash
725
787
  if var_hash.keys.include? self
726
788
  var_hash[self] += 1
@@ -733,6 +795,11 @@ class Cos < Equation
733
795
  def all_variables
734
796
  return @eq.all_variables
735
797
  end
798
+
799
+ def __sub__ original, replacement
800
+ return to_equation(replacement) if self == to_equation(original)
801
+ return Cos.new(@eq.__sub__(original, replacement))
802
+ end
736
803
  end
737
804
 
738
805
 
@@ -757,6 +824,10 @@ class Ln < Equation
757
824
  return 1 / @eq * @eq.derivative(variable: variable)
758
825
  end
759
826
 
827
+ def __simplify__
828
+ return Ln.new(@eq.__simplify__)
829
+ end
830
+
760
831
  def __get_m_elements__ var_hash
761
832
  if var_hash.keys.include? self
762
833
  var_hash[self] += 1
@@ -769,6 +840,11 @@ class Ln < Equation
769
840
  def all_variables
770
841
  return @eq.all_variables
771
842
  end
843
+
844
+ def __sub__ original, replacement
845
+ return to_equation(replacement) if self == to_equation(original)
846
+ return Ln.new(@eq.__sub__(original, replacement))
847
+ end
772
848
  end
773
849
 
774
850
  # Implements the logarithm operation in SymCalc
@@ -776,7 +852,7 @@ class Log < Equation
776
852
 
777
853
  attr_accessor :eq, :base
778
854
 
779
- # Implements the subtraction operation in SymCalc
855
+ # Implements the logarithm operation in SymCalc
780
856
  # Accepts the base and equation arguments
781
857
  #
782
858
  # Example:
@@ -801,6 +877,10 @@ class Log < Equation
801
877
  return 1 / (Ln.new(@base) * @eq) * @eq.derivative(variable: variable)
802
878
  end
803
879
 
880
+ def __simplify__
881
+ return Log.new(@base.__simplify__, @eq.__simplify__)
882
+ end
883
+
804
884
  def __get_m_elements__ var_hash
805
885
  if var_hash.keys.include? self
806
886
  var_hash[self] += 1
@@ -813,8 +893,65 @@ class Log < Equation
813
893
  def all_variables
814
894
  return (@base.all_variables + @eq.all_variables).uniq
815
895
  end
896
+
897
+ def __sub__ original, replacement
898
+ return to_equation(replacement) if self == to_equation(original)
899
+ return Log.new(@base.__sub__(original, replacement), @eq.__sub__(original, replacement))
900
+ end
816
901
  end
817
902
 
903
+ # Implements the absolute value operation in SymCalc
904
+ class Abs < Equation
905
+
906
+ attr_accessor :eq
907
+
908
+ def initialize eq
909
+ @eq = to_equation(eq)
910
+ end
911
+
912
+ def display
913
+ return "|#{@eq.display}|"
914
+ end
915
+
916
+ def __eval__ var_hash
917
+ return @eq.eval(var_hash).abs
918
+ end
919
+
920
+ def __derivative__ variable: nil
921
+ return @eq / Abs.new(@eq) * @eq.derivative(variable: variable)
922
+ end
923
+
924
+ def __simplify__
925
+ return Abs.new(@eq.__simplify__)
926
+ end
927
+
928
+ def __get_m_elements__ var_hash
929
+ if var_hash.keys.include? self
930
+ var_hash[self] += 1
931
+ else
932
+ var_hash[self] = 1
933
+ end
934
+ return var_hash
935
+ end
936
+
937
+ def __simplify__
938
+ if @eq.is_a?(Power) && @eq.power.is_a?(EquationValue) && @eq.power.value.is_a?(Numeric) && (@eq.power.value % 2 == 0)
939
+ return @eq
940
+ end
941
+ self
942
+ end
943
+
944
+ def all_variables
945
+ return @eq.all_variables
946
+ end
947
+
948
+ def __sub__ original, replacement
949
+ return to_equation(replacement) if self == to_equation(original)
950
+ return Abs.new(@eq.__sub__(original, replacement))
951
+ end
952
+ end
953
+
954
+
818
955
  # The SymCalc module implemenets the standard function class creations shorter
819
956
  module SymCalc
820
957
 
@@ -848,6 +985,11 @@ module SymCalc
848
985
  Variable.new name, fixed_value
849
986
  end
850
987
 
851
- module_function :sin, :cos, :ln, :log, :exp, :var
988
+ # abs(equation) is the same as Abs.new(equation), just shorter
989
+ def abs eq
990
+ return Abs.new(to_equation(eq))
991
+ end
992
+
993
+ module_function :sin, :cos, :ln, :log, :exp, :var, :abs
852
994
 
853
995
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symcalc
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyryl Shyshko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-16 00:00:00.000000000 Z
11
+ date: 2024-01-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: SymCalc empowers developers with the ability of creating symbolic functions,
14
- deriving them and evaluating them, substituting variables for numbers.
14
+ evaluating them and finding their derivatives in code.
15
15
  email: kyryloshy@gmail.com
16
16
  executables: []
17
17
  extensions: []
@@ -21,7 +21,7 @@ files:
21
21
  - lib/symcalc.rb
22
22
  homepage: https://rubygems.org/gems/symcalc
23
23
  licenses:
24
- - CC BY-SA 4.0
24
+ - Apache-2.0
25
25
  metadata: {}
26
26
  post_install_message:
27
27
  rdoc_options: []
@@ -41,6 +41,5 @@ requirements: []
41
41
  rubygems_version: 3.3.11
42
42
  signing_key:
43
43
  specification_version: 4
44
- summary: SymCalc is a Ruby gem for symbolic mathematics that implements basic calculus
45
- in code.
44
+ summary: Mathematical symbolic functions, calculus and differentiation in code
46
45
  test_files: []