Skip to content

Commit b01b9ea

Browse files
committed
Not too strict
1 parent 544a62e commit b01b9ea

4 files changed

Lines changed: 12 additions & 154 deletions

File tree

docs/en/basics/expressions.ipynb

Lines changed: 3 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/ja/basics/expressions.ipynb

Lines changed: 3 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

markdowns/en/basics/expressions.md

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,8 @@ def _(problem: jm.DecoratedProblem):
278278
display(problem.infer(A))
279279
```
280280

281-
Comprehensions used with `jm.genarray` must satisfy the following conditions:
282-
283-
1. It must be a **generator expression** enclosed in parentheses. List comprehensions enclosed in `[ ]` are not supported.
284-
2. The `for` clause must be a single loop of the form `for p in e`, where `e` is a natural-number expression or tuple expression of natural numbers, and `p` is a pattern.
285-
+ `p` may be any pattern that matches `e`.
286-
287-
The following is an example that raises an error because it uses multiple `for` clauses:
281+
Only one `for .. in ...` clause is allowed in a `genarray` comprehension.
282+
Be careful, because using multiple `for` clauses as shown below raises an error:
288283

289284
```{code-cell} ipython3
290285
try:
@@ -300,24 +295,7 @@ except SyntaxError as e:
300295
print(str(e))
301296
```
302297

303-
Also, the right-hand side of `in` in `genarray` specifies only the shape.
304-
In particular, be careful not to use `jm.product` as shown below, because it creates a set and results in an error:
305-
306-
```{code-cell} ipython3
307-
try:
308-
309-
@jm.Problem.define("genarray example")
310-
def _(problem):
311-
N = problem.Natural()
312-
M = problem.Natural()
313-
a = problem.Float(shape=(N, M))
314-
x = problem.BinaryVar(shape=N)
315-
Sums = problem.NamedExpr(jm.genarray(a[i, j] * x[i] for i, j in jm.product(N, M)))
316-
except Exception as e:
317-
print(str(e))
318-
```
319-
320-
:::{admonition} Division by decision variables
298+
::{admonition} Division by decision variables
321299
:class: caution
322300

323301
At the modeling stage, decision variables can appear on either side of arithmetic operators.

markdowns/ja/basics/expressions.md

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,8 @@ def _(problem: jm.DecoratedProblem):
265265
display(problem.infer(A))
266266
```
267267

268-
`jm.genarray` で使える内包表記は以下の条件に従う必要があります:
269-
270-
1. 丸括弧で囲まれた**ジェネレータ式**であること。 `[ ]` で囲まれたリスト内包表記は利用できません。
271-
2. `for` 部は自然数式または自然数のタプル式 `e` パターン `p` に対し、 `for p in e` の形の単一のループであること。
272-
+ `p``E` に合致するパターンであれば何でも構いません。
273-
274-
以下は、複数の `for`-節を使ってしまい、エラーになっている例です:
268+
`genarray` の内包表記では、`for .. in ...` は一つしか許容されません。
269+
以下のように、複数の `for`-節を使ってしまうとエラーになるので注意してください:
275270

276271
```{code-cell} ipython3
277272
try:
@@ -287,24 +282,7 @@ except SyntaxError as e:
287282
print(str(e))
288283
```
289284

290-
また、`genarray``in` の右辺はあくまでもシェイプを指定するものです。
291-
特に、以下のように`jm.product` を使ってしまうと集合になってしまい、エラーとなるので注意してください:
292-
293-
```{code-cell} ipython3
294-
try:
295-
296-
@jm.Problem.define("genarray example")
297-
def _(problem):
298-
N = problem.Natural()
299-
M = problem.Natural()
300-
a = problem.Float(shape=(N, M))
301-
x = problem.BinaryVar(shape=N)
302-
Sums = problem.NamedExpr(jm.genarray(a[i, j] * x[i] for i, j in jm.product(N, M)))
303-
except Exception as e:
304-
print(str(e))
305-
```
306-
307-
:::{admonition} 決定変数による除算について
285+
::{admonition} 決定変数による除算について
308286
:class: caution
309287

310288
モデルの構築の時点では、決定変数が現れうる式は加減乗除の左右どちらの辺にも現れることができます。

0 commit comments

Comments
 (0)