This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pivot_table' | |
require 'daru' | |
class Order | |
attr_reader :city, :quarter, :top_sales | |
def initialize args | |
args.each do |k,v| | |
instance_variable_set("@#{k}", v) unless v.nil? | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# code from sympy.diophantine | |
for solution in solns_pell: | |
for X_i in [-solution[0], solution[0]]: | |
for Y_i in [-solution[1], solution[1]]: | |
s = P*Matrix([X_i, Y_i]) + Q | |
try: | |
sol.add(tuple([as_int(_) for _ in s])) | |
except ValueError: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# args = list(FiniteSet(*args)) | |
length = len(args) | |
reduced = [[None for x in range(length)] for x in range(length)] | |
# base case | |
reduced[0][0] = [args[0]] | |
# first row | |
for i in range(1, length - 1): | |
new_set = reduced[0][i - 1][0]._union(args[i]) | |
if new_set is not None: | |
reduced[0][i] = [new_set] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# logic for imageSet union | |
# img1 = ImageSet(Lambda(n, a*n + b), S.Integers) | |
# img2 = ImageSet(Lambda(n, c*n + d), S.Integers) | |
# When a != c and (c + (b - d)) mod a == 0, means (c + (b-d))*n may be multiple of a*n. | |
# After checking it for 3 values, returns img1. | |
# In [1]: Union(ImageSet(Lambda(n, 3*n), S.Integers), ImageSet(Lambda(n, 6*n), S.Integers)) | |
# Out[1]: {3⋅n | n ∊ ℤ} | |
# In [2]: Union(ImageSet(Lambda(n, 3*n ), S.Integers), ImageSet(Lambda(n, 7*n ), S.Integers)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# master branch | |
In [1]: solveset(cos(x) + cos(3*x) + cos(5*x), x, S.Reals) | |
Out[1]: | |
⎧ π ⎫ ⎧ 3⋅π ⎫ ⎧ 4⋅π ⎫ ⎧ 2⋅π ⎫ ⎧ 5⋅π ⎫ ⎧ π ⎫ ⎧ | |
⎨2⋅n⋅π + ─ | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─ | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + | |
⎩ 2 ⎭ ⎩ 2 ⎭ ⎩ 3 ⎭ ⎩ 3 ⎭ ⎩ 3 ⎭ ⎩ 3 ⎭ ⎩ | |
7⋅π ⎫ ⎧ 5⋅π ⎫ ⎧ 11⋅π ⎫ ⎧ π ⎫ | |
─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ──── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─ | n ∊ ℤ⎬ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _union(self, other): | |
""" | |
This function should only be used internally. | |
See Set._union for docstring | |
Used within the :class:`Union` class | |
This function club imageset `other` with `self` if there is difference | |
of `pi` or `2*pi` and returns this new imageset otherwise None. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in fancyset/ImageSet class | |
lamda_vars = property(lambda self: self.lamda.variables) | |
def put_values(self, symbol, val=None): | |
""" | |
Returns ImageSet expr value in FiniteSet after substituting the given | |
`values` for `symbol`. | |
Input can be either a single symbol and corresponding value | |
or a dictionary of symbols and values. If symbol(s) are present in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def substitution(system, symbols, result=[{}], known_symbols=[], | |
exclude=[], all_symbols=None): | |
r""" Solves the `system` using substitution method. | |
A helper function for `nonlinsolve`. This will be called from | |
`nonlinsolve` when any equation(s) is non polynomial equation. | |
Parameters | |
========== | |
system : list of equations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _solve_using_known_values(result, solver): | |
"""Solves the system using already known solution | |
(result contains the dict <symbol: value>). | |
solver is `solveset_complex` or `solveset_real`. | |
""" | |
# stores imageset <expr: imageset(Lambda(n, expr), base)>. | |
soln_imageset = {} | |
total_solveset_call_inner = 0 | |
total_conditionset_inner = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _extract_main_soln(sol, soln_imageset): | |
"""separate the Complements, Intersections, ImageSet lambda expr | |
and it's base_set. | |
""" | |
# if there is union, then need to check | |
# complement, intersection, Imageset | |
# order should not be changed. | |
if isinstance(sol, Complement): | |
# extract solution and complement | |
complements[sym] = sol.args[1] |