Skip to content

Instantly share code, notes, and snippets.

View Shekharrajak's full-sized avatar
📚
Being Geek!

Shekhar Prasad Rajak Shekharrajak

📚
Being Geek!
View GitHub Profile
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
# 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:
# 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]
@Shekharrajak
Shekharrajak / trig_general_union_PR11188.py
Created August 14, 2016 04:20
logic which is changed to issuperset
# 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))
# 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 ∊ ℤ⎬
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.
# 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
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
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
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]