例題集
各分野でソルバーを使う方法の例題です。1つ開いて解答を確認し、自分の問題に書き換えて解いてみましょう。
代数
方程式
不等式
導関数
積分
極限
級数と和
数列
- 平方数
find_sequence_function([1, 4, 9, 16, 25], n) - フィボナッチ数
find_sequence_function([1, 1, 2, 3, 5, 8, 13], n) - 三角数
find_sequence_function([1, 3, 6, 10, 15, 21, 28], n) - 2の累乗
find_sequence_function([2, 4, 8, 16, 32], n) - 階乗
find_sequence_function([1, 2, 6, 24, 120, 720], n) - カタラン数
find_sequence_function([1, 1, 2, 5, 14, 42, 132], n) - 次の項は何か
next_terms([5, 11, 23, 47, 95, 191]) - 漸化式
find_linear_recurrence([1, 3, 4, 7, 11, 18, 29])
統計
- 平均値
mean([2, 4, 4, 4, 5, 5, 7, 9]) - 中央値
median([3, 1, 4, 1, 5, 9, 2, 6]) - 標準偏差
standard_deviation([2, 4, 4, 4, 5, 5, 7, 9]) - 相関
correlation([1, 2, 3, 4], [2, 4, 5, 9]) - 回帰直線
fit([[0, 1], [1, 3], [2, 5], [3, 8]], [1, x], x) - 正規確率
probability(x > 1, distributed(x, normal_distribution(0, 1))) - 二項確率
probability(1 < x < 4, distributed(x, binomial_distribution(5, 1/2))) - 期待値
expectation(x^2, distributed(x, poisson_distribution(lambda)))
線形代数
- 行列式
det([[2, 0, 1], [1, 3, 2], [0, 1, 4]]) - 固有値
eigenvalues([[2, 1], [1, 2]]) - 固有ベクトル
eigenvectors([[4, 1], [2, 3]]) - 階数
rank([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) - 零空間
null_space([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) - 行簡約
row_reduce([[1, 2, 3], [4, 5, 6]]) - 連立一次方程式
linear_solve([[2, 1], [1, 3]], [3, 5]) - 行列指数関数
matrix_exp([[0, 1], [-1, 0]]) - 行列の積
dot([[1, 2], [3, 4]], [[5, 6], [7, 8]]) - 行列の累乗
matrix_power([[1, 1], [1, 0]], 10) - 転置
transpose([[1, 2, 3], [4, 5, 6]]) - 外積
cross([1, 2, 3], [4, 5, 6])
微分方程式
確率解析
- 伊藤の公式
ito_formula(x^2, x, mu·x, sigma·x, t) - GBMの対数
ito_formula(ln(x), x, mu·x, sigma·x, t) - ブラウン運動の2乗
ito_formula(x^2, x, 0, 1, t) - W dWの伊藤積分
ito_integral(w, w, s, t) - W²の伊藤積分
ito_integral(w^2, w, s, t) - 時間の関数の積分
ito_integral(exp(s), w, s, t) - 伊藤の等長性
variance(ito_integral(w, w, s, t)) - 幾何ブラウン運動の明示的な経路
geometric_sde_path(mu, sigma, x0, w, t) - OU過程の平均
mean(ornstein_uhlenbeck_process(mu, sigma, theta, x0), t) - OU過程の分散
variance(ornstein_uhlenbeck_process(mu, sigma, theta, x0), t) - 幾何ブラウン運動の分散
variance(geometric_brownian_motion_process(mu, sigma, x0), t) - OU過程の定常分布
stationary_distribution(ornstein_uhlenbeck_process(mu, sigma, theta, x0)) - アフィンSDEのモーメント
affine_sde_moments(a, b, sigma, x0, t)
複素数
最適化
- 最小
minimize(x^2 - 4x + 7, x) - 最大
maximize(x·(10 - x), x) - 2変数
minimize(x^2 + y^2 - 2x, [x, y]) - 線形計画問題
minimize([x + y, x + 2y >= 4, 3x + y >= 6, x >= 0, y >= 0], [x, y]) - 整数
maximize([5x + 4y, 6x + 4y <= 24, x + 2y <= 6, x >= 0, y >= 0, [x, y] : integer], [x, y]) - 絶対値
minimize([abs(x - 2) + abs(y + 1) + abs(x + y - 5), x >= 0, y >= 0], [x, y]) - 複数のうち最大のもの
minimize([max(x + y, 2x - y, 3 - x), x >= -5, x <= 5, y >= -5, y <= 5], [x, y]) - 距離の和
minimize([norm([x - 1, y - 2]) + norm([x + 1, y]), x + y >= 0], [x, y]) - 非凸、整数
minimize([x·y - 3x + 2y, x >= -2, x <= 3, y >= -1, y <= 4, [x, y] : integer], [x, y]) - 大域的な数値探索
numeric_minimize([sin(3x) + (x - 1)^2/10, x >= -10, x <= 10], x)
特殊関数
変換
整数論
論理
- 条件式を簡略化
boolean_minimize((p and q) or (p and not q)) - 多数決
boolean_minimize((a and b) or (a and c) or (b and c and not a)) - ド・モルガンの法則
is_tautology(not (p and q) == (not p or not q)) - 恒真式
is_tautology(implies(p, q) or implies(q, p)) - 真にする
satisfiability_instances(p and (q or not p)) - 場合の数を数える
satisfiability_count(a or b or c) - 分配する
logical_expand((p or q) and r) - 矛盾式
is_satisfiable(p and not p) - 規則の連鎖
is_tautology(implies(implies(p, q) and implies(q, r), implies(p, r)))
規則
- 矛盾する規則
is_satisfiable((x > 1 or y > 1) and x <= 0 and y < 0) - 衝突する価格の規則
conflicting_rules([implies(premium, d <= 3/10), premium, d > 1/2, p >= 0]) - 1つのポリシーに2つの矛盾
conflicting_rules([implies(premium, d <= 3/10), premium, d > 1/2, s >= 2, s <= 1]) - 自己矛盾するポリシー
conflicting_rules([implies(admin, mfa), implies(mfa, phone), admin, not phone, audit]) - 2つの予約が重なる
eliminate_quantifiers(exists(x, a <= x <= b and c <= x <= d)) - 期間が別の期間に収まる
eliminate_quantifiers(for_all(x, implies(a <= x <= b, c <= x <= d))) - 100を超える注文
eliminate_quantifiers(exists(n, n > 0 and n < 10 and n·p > 100)) - 2つの作業の締め切り
eliminate_quantifiers(exists([s, t], s >= 0 and t >= s + 3 and t + 2 <= d)) - 予算内に収まる割引
eliminate_quantifiers(exists(d, d >= 0 and d <= 1/5 and p·(1 - d) <= 100)) - 規則を満たす点
find_instance(x + y > 10 and x - y < 2 and x < 5, [x, y], real) - 円周上の有理点
find_instance(x^2 + y^2 = 1 and x > 3/5 and y > 3/5, [x, y], real) - 負にならない放物線
eliminate_quantifiers(for_all(x, x^2 + b·x + c >= 0)) - 0 を下回らない直線
eliminate_quantifiers(for_all(t, implies(0 <= t <= 1, a·t + b >= 0))) - 40人を6人席と4人席に
conflicting_rules([6·t + 4·u = 40, t >= 5, u >= 2], integer) - 合計が決して合わない個数
find_instance(2·x + 4·y = 7, [x, y], integer)
アルゴリズム
- マージソート
solve_recurrence([t(n) = 2·t(n/2) + n, t(1) = 1], t, n) - 二分探索
solve_recurrence([t(n) = t(n/2) + 1, t(1) = 1], t, n) - カラツバ乗算
solve_recurrence([t(n) = 3·t(n/2) + n, t(1) = 1], t, n) - シュトラッセンの行列積
solve_recurrence([t(n) = 7·t(n/2) + n^2, t(1) = 1], t, n) - マスター定理
recurrence_growth(t(n) = 2·t(n/2) + n^2, t, n) - 不均等な分割
recurrence_growth(t(n) = t(n/3) + t(2·n/3) + n, t, n)
暗号
金融
待ち行列と信頼性
- M/M/1待ち行列の客数
sum(n·(1 - rho)·rho^n, n = 0..inf) - 修理可能な装置
solve([-l·p0 + m·p1 = 0, p0 + p1 = 1], [p0, p1]) - ワイブル分布の生存確率
probability(x > 50, distributed(x, weibull_distribution(2, 100))) - 直列系
integrate(exp(-(l1 + l2 + l3)·t), t = 0..inf, assuming = [l1 > 0, l2 > 0, l3 > 0]) - 3つのうち2つ
integrate(3·exp(-2·l·t) - 2·exp(-3·l·t), t = 0..inf, assuming = l > 0)