symcalc 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/symcalc.rb +32 -32
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e57698a5da7f300ef21e41ecc27fe2e0be86186213daa9b3736c8603b005b9fa
4
- data.tar.gz: b108fddfb4a9ad62327f2b1161e2557b9c4c0fc132403e5bea08658470bc903c
3
+ metadata.gz: d1cb3c53ef5f25cad69cde67e01cffa1114da6954c06cd75b5a8377ffc382777
4
+ data.tar.gz: 617a794848e3a658f83f5a8aaf0873e9727acd46ceb485b12020c8813efabcfb
5
5
  SHA512:
6
- metadata.gz: d811d18c96abea729176dd8b918c9c75de4e183706c7b7912d049efd2cfd028321d923cda9149ba443772ef21073aba693476a824b777c758b65f89c9128adf5
7
- data.tar.gz: d56da69a5f839a0dd2c7efba40f85f4ca78980219109fad8228182b3cab2db48f7515a1be49910c19d9c4785ab187ad95618c1aaa15e8fa64560dade60b234a3
6
+ metadata.gz: '0108441596b3221a311b2ff0fd7f423adfb4440c0400f0bbbc138d454ea2db163fbb71b453566e89b3dfa70704dbb4ed7bae648b641d7966d5e04986db8ba50b'
7
+ data.tar.gz: 59e7edab69404cb37e93f82a6cfa0de2a05b8a4ae2105bbf9d526792359717539b0059640d5b8d141870b3964b6a31675a490a5071df2b4838fafb32fcc85782
data/lib/symcalc.rb CHANGED
@@ -36,23 +36,23 @@ class Equation
36
36
  end
37
37
 
38
38
  def coerce(other)
39
- [to_equation(other), self]
39
+ [SymCalc.to_equation(other), self]
40
40
  end
41
41
 
42
42
  def *(eq)
43
- eq = Multiplication.new([self, to_equation(eq)])
43
+ eq = Multiplication.new([self, SymCalc.to_equation(eq)])
44
44
  eq = eq.simplify if $SYMCALC_AUTO_SIMPLIFY
45
45
  eq
46
46
  end
47
47
 
48
48
  def /(eq)
49
- eq = Division.new(self, to_equation(eq))
49
+ eq = Division.new(self, SymCalc.to_equation(eq))
50
50
  eq = eq.simplify if $SYMCALC_AUTO_SIMPLIFY
51
51
  eq
52
52
  end
53
53
 
54
54
  def +(eq)
55
- eq = Sum.new([self, to_equation(eq)])
55
+ eq = Sum.new([self, SymCalc.to_equation(eq)])
56
56
  eq = eq.simplify if $SYMCALC_AUTO_SIMPLIFY
57
57
  eq
58
58
  end
@@ -64,13 +64,13 @@ class Equation
64
64
  end
65
65
 
66
66
  def -(eq)
67
- eq = Sum.new([self, Negate.new(to_equation(eq))])
67
+ eq = Sum.new([self, Negate.new(SymCalc.to_equation(eq))])
68
68
  eq = eq.simplify if $SYMCALC_AUTO_SIMPLIFY
69
69
  eq
70
70
  end
71
71
 
72
72
  def **(eq)
73
- eq = Power.new(self, to_equation(eq))
73
+ eq = Power.new(self, SymCalc.to_equation(eq))
74
74
  eq = eq.simplify if $SYMCALC_AUTO_SIMPLIFY
75
75
  eq
76
76
  end
@@ -154,7 +154,7 @@ class Equation
154
154
 
155
155
 
156
156
  def __sub__ original, replacement
157
- return to_equation(replacement) if self == to_equation(original)
157
+ return SymCalc.to_equation(replacement) if self == SymCalc.to_equation(original)
158
158
  return self
159
159
  end
160
160
 
@@ -288,7 +288,7 @@ class Variable < Equation
288
288
  if variable == nil || variable == self
289
289
  return EquationValue.new 1
290
290
  else
291
- return to_equation(0)
291
+ return SymCalc.to_equation(0)
292
292
  end
293
293
  end
294
294
 
@@ -349,7 +349,7 @@ class Sum < Equation
349
349
  end
350
350
 
351
351
  def __sub__ original, replacement
352
- return to_equation(replacement) if self == to_equation(original)
352
+ return SymCalc.to_equation(replacement) if self == SymCalc.to_equation(original)
353
353
 
354
354
  return Sum.new(@elements.map{|eq| eq.__sub__(original, replacement)})
355
355
  end
@@ -382,7 +382,7 @@ class Negate < Equation
382
382
  end
383
383
 
384
384
  def __sub__ original, replacement
385
- return to_equation(replacement) if self == to_equation(original)
385
+ return SymCalc.to_equation(replacement) if self == SymCalc.to_equation(original)
386
386
  return Negate.new(@eq.__sub__(original, replacement))
387
387
  end
388
388
  end
@@ -476,7 +476,7 @@ class Multiplication < Equation
476
476
  end
477
477
 
478
478
  def __sub__ original, replacement
479
- return to_equation(replacement) if self == to_equation(original)
479
+ return SymCalc.to_equation(replacement) if self == SymCalc.to_equation(original)
480
480
  return Multiplication.new(@elements.map{|el| el.__sub__(original, replacement)})
481
481
  end
482
482
  end
@@ -501,7 +501,7 @@ class Division < Equation
501
501
 
502
502
  def __derivative__ variable: nil
503
503
  # return (@lside * @rside ** (-1)).derivative(variable: variable)
504
- return (@lside.derivative * @rside - @lside * @rside.derivative) / (@rside ** 2)
504
+ return (@lside.derivative(variable: variable) * @rside - @lside * @rside.derivative(variable: variable)) / (@rside ** 2)
505
505
  end
506
506
 
507
507
  def __simplify__
@@ -528,7 +528,7 @@ class Division < Equation
528
528
  end
529
529
 
530
530
  def __sub__ original, replacement
531
- return to_equation(replacement) if self == to_equation(original)
531
+ return SymCalc.to_equation(replacement) if self == SymCalc.to_equation(original)
532
532
  return @lside.__sub__(original, replacement) / @rside.__sub__(original, replacement)
533
533
  end
534
534
  end
@@ -540,7 +540,7 @@ class Exp < Equation
540
540
  attr_accessor :power
541
541
 
542
542
  def initialize power
543
- @power = to_equation(power)
543
+ @power = SymCalc.to_equation(power)
544
544
  end
545
545
 
546
546
  def display
@@ -578,7 +578,7 @@ class Exp < Equation
578
578
  end
579
579
 
580
580
  def __sub__ original, replacement
581
- return to_equation(replacement) if self == to_equation(original)
581
+ return SymCalc.to_equation(replacement) if self == SymCalc.to_equation(original)
582
582
  return Exp.new(@power.__sub__(original, replacement))
583
583
  end
584
584
  end
@@ -629,7 +629,7 @@ class Power < Equation
629
629
  elsif s_base.is_a?(EquationValue) && s_power.is_a?(EquationValue)
630
630
  computed = s_base.value ** s_power.value
631
631
  if computed.to_s.size <= 6
632
- return to_equation(computed)
632
+ return SymCalc.to_equation(computed)
633
633
  else
634
634
  return s_base ** power
635
635
  end
@@ -648,7 +648,7 @@ class Power < Equation
648
648
  end
649
649
 
650
650
  def __sub__ original, replacement
651
- return to_equation(replacement) if self == to_equation(original)
651
+ return SymCalc.to_equation(replacement) if self == SymCalc.to_equation(original)
652
652
  return @base.__sub__(original, replacement) ** @power.__sub__(original, replacement)
653
653
  end
654
654
  end
@@ -680,7 +680,7 @@ class Sin < Equation
680
680
  end
681
681
 
682
682
  def __sub__ original, replacement
683
- return to_equation(replacement) if self == to_equation(original)
683
+ return SymCalc.to_equation(replacement) if self == SymCalc.to_equation(original)
684
684
  return Sin.new(@eq.__sub__(original, replacement))
685
685
  end
686
686
  end
@@ -712,7 +712,7 @@ class Cos < Equation
712
712
  end
713
713
 
714
714
  def __sub__ original, replacement
715
- return to_equation(replacement) if self == to_equation(original)
715
+ return SymCalc.to_equation(replacement) if self == SymCalc.to_equation(original)
716
716
  return Cos.new(@eq.__sub__(original, replacement))
717
717
  end
718
718
  end
@@ -748,7 +748,7 @@ class Ln < Equation
748
748
  end
749
749
 
750
750
  def __sub__ original, replacement
751
- return to_equation(replacement) if self == to_equation(original)
751
+ return SymCalc.to_equation(replacement) if self == SymCalc.to_equation(original)
752
752
  return Ln.new(@eq.__sub__(original, replacement))
753
753
  end
754
754
  end
@@ -767,8 +767,8 @@ class Log < Equation
767
767
  # fx = Log.new 10, x ** 2
768
768
  #
769
769
  def initialize base, eq
770
- @base = to_equation(base)
771
- @eq = to_equation(eq)
770
+ @base = SymCalc.to_equation(base)
771
+ @eq = SymCalc.to_equation(eq)
772
772
  end
773
773
 
774
774
  def display
@@ -792,7 +792,7 @@ class Log < Equation
792
792
  end
793
793
 
794
794
  def __sub__ original, replacement
795
- return to_equation(replacement) if self == to_equation(original)
795
+ return SymCalc.to_equation(replacement) if self == SymCalc.to_equation(original)
796
796
  return Log.new(@base.__sub__(original, replacement), @eq.__sub__(original, replacement))
797
797
  end
798
798
  end
@@ -803,7 +803,7 @@ class Abs < Equation
803
803
  attr_accessor :eq
804
804
 
805
805
  def initialize eq
806
- @eq = to_equation(eq)
806
+ @eq = SymCalc.to_equation(eq)
807
807
  end
808
808
 
809
809
  def display
@@ -830,7 +830,7 @@ class Abs < Equation
830
830
  end
831
831
 
832
832
  def __sub__ original, replacement
833
- return to_equation(replacement) if self == to_equation(original)
833
+ return SymCalc.to_equation(replacement) if self == SymCalc.to_equation(original)
834
834
  return Abs.new(@eq.__sub__(original, replacement))
835
835
  end
836
836
  end
@@ -849,27 +849,27 @@ end
849
849
 
850
850
  # sin(equation) is the same as Sin.new(equation), just shorter
851
851
  def sin(eq)
852
- return Sin.new(to_equation(eq))
852
+ return Sin.new(SymCalc.to_equation(eq))
853
853
  end
854
854
 
855
855
  # cos(equation) is the same as Cos.new(equation), just shorter
856
856
  def cos(eq)
857
- return Cos.new(to_equation(eq))
857
+ return Cos.new(SymCalc.to_equation(eq))
858
858
  end
859
859
 
860
860
  # ln(equation) is the same as Ln.new(equation), just shorter
861
861
  def ln(eq)
862
- return Ln.new(to_equation(eq))
862
+ return Ln.new(SymCalc.to_equation(eq))
863
863
  end
864
864
 
865
865
  # log(base, equation) is the same as Log.new(base, equation), just shorter
866
866
  def log(base, eq)
867
- return Log.new(to_equation(base), to_equation(eq))
867
+ return Log.new(SymCalc.to_equation(base), SymCalc.to_equation(eq))
868
868
  end
869
869
 
870
870
  # exp(equation) is the same as Exp.new(equation), just shorter
871
871
  def exp(power)
872
- return Exp.new(to_equation(power))
872
+ return Exp.new(SymCalc.to_equation(power))
873
873
  end
874
874
 
875
875
  # var(name) is the same as Variable.new(name), just shorter
@@ -883,9 +883,9 @@ end
883
883
 
884
884
  # abs(equation) is the same as Abs.new(equation), just shorter
885
885
  def abs eq
886
- return Abs.new(to_equation(eq))
886
+ return Abs.new(SymCalc.to_equation(eq))
887
887
  end
888
888
 
889
- module_function :sin, :cos, :ln, :log, :exp, :var, :abs, :const
889
+ module_function :sin, :cos, :ln, :log, :exp, :var, :abs, :const, :to_equation
890
890
 
891
891
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symcalc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyryl Shyshko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-29 00:00:00.000000000 Z
11
+ date: 2024-11-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'SymCalc adds symbolic mathematics and calculus to your code. Create,
14
14
  evaluate and differentiate mathematical functions with a single method call.