Skip to content

Commit c6e4841

Browse files
tmp
1 parent 1bedabf commit c6e4841

16 files changed

Lines changed: 11145 additions & 623 deletions

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- in facts / antecedent-style use, undefined partial primitive calls cause the rule to skip rather than firing
3939
- in higher-order container ops, the container primitive should define the policy for undefined callback results, for example skipping those entries or failing the whole op
4040
- Use partial builtins in antecedent/lookup positions by default; do not materialize them in actions unless definedness has already been proven.
41+
- For Python helper wrappers around `catch`, prefer accepting the symbolic Egglog expression directly and wrapping it inside the helper, for example `try_match(expr, on_some, default)` should internally use `catch(lambda: expr)`. Python still evaluates arguments eagerly, but Egglog DSL expressions such as `map[key]` are symbolic construction, not runtime lookup execution; keep an explicit caller-side thunk only when constructing the expression itself can fail or has side effects.
4142
- In Python, only pass exact builtins or partials of exact builtins into higher-order container ops for this workflow.
4243
- Do not add Python-bodied primitive/container helpers or anonymous lambda callbacks for these paths.
4344
- Prefer `x == y` over `eq(x).to(y)` for ordinary equality facts, checks, and rule antecedents when the sort uses the default equality relation.

Cargo.lock

Lines changed: 1 addition & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/egglog/builtins.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@
7171
"map_contains_key_swapped",
7272
"map_divide_all_values_by_f64",
7373
"map_drop_zero_values",
74+
"map_factor_coef_for_integer_residual_split",
7475
"map_filter_defined_kv",
7576
"map_filter_kv",
7677
"map_fold_kv",
78+
"map_integer_residual_split_candidate",
7779
"map_intersect_with",
7880
"map_keys",
7981
"map_map_values",
@@ -573,10 +575,7 @@ def value(self) -> dict[T, V]:
573575
items.append((k, v))
574576
if get_callable_args(self, Map.empty) is None:
575577
raise ExprValueError(self, "Map.empty or Map.insert")
576-
d = {}
577-
for k, v in reversed(items):
578-
d[k] = v
579-
return d
578+
return dict(reversed(items))
580579

581580
__match_args__ = ("value",)
582581

@@ -714,6 +713,14 @@ def map_nonconst_nonunit_f64_values(xs: Map[Map[T, V], f64]) -> MultiSet[f64]: .
714713
def map_divide_all_values_by_f64(factor: f64, xs: Map[T, f64]) -> Map[T, f64]: ...
715714

716715

716+
@function(egg_fn="map-integer-residual-split-candidate", builtin=True)
717+
def map_integer_residual_split_candidate(xs: Map[Map[T, BigRat], f64]) -> Pair[Map[T, BigRat], Map[Map[T, BigRat], f64]]: ...
718+
719+
720+
@function(egg_fn="map-factor-coef-for-integer-residual-split", builtin=True)
721+
def map_factor_coef_for_integer_residual_split(xs: Map[Map[T, BigRat], f64]) -> f64: ...
722+
723+
717724
@function(egg_fn="map-shared-factor-atoms", builtin=True)
718725
def map_shared_factor_atoms(xs: Map[Map[T, BigRat], V]) -> Set[T]: ...
719726

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
_expr_1 = Value.var("q2") * Value.var("bp1") + Value.var("q5") * Value.var("bp2") + Value.var("q8") * Value.var("bp3") + Value.var("bp4") * Value.var("q11")
2+
_expr_2 = Value.var("bpp2") * Value.var("q6") + Value.var("q3") * Value.var("bpp1") + Value.var("bpp3") * Value.var("q9") + Value.var("bpp4") * Value.var("q12")
3+
_expr_3 = Value.var("bp1") * Value.var("q3") + Value.var("bp2") * Value.var("q6") + Value.var("q12") * Value.var("bp4") + Value.var("bp3") * Value.var("q9")
4+
_expr_4 = Value.var("bpp2") * Value.var("q5") + Value.var("q2") * Value.var("bpp1") + Value.var("bpp3") * Value.var("q8") + Value.var("bpp4") * Value.var("q11")
5+
_expr_5 = Value.var("q4") * Value.var("bpp2") + Value.var("q7") * Value.var("bpp3") + Value.var("q10") * Value.var("bpp4") + Value.var("bpp1") * Value.var("q1")
6+
_expr_6 = Value.var("q4") * Value.var("bp2") + Value.var("q7") * Value.var("bp3") + Value.var("bp1") * Value.var("q1") + Value.var("q10") * Value.var("bp4")
7+
NDArray(
8+
RecursiveValue(
9+
(
10+
(_expr_1 * _expr_2 + Value.from_int(Int(-1)) * (_expr_3 * _expr_4)) ** Value.from_int(Int(2))
11+
+ (_expr_3 * _expr_5 + Value.from_int(Int(-1)) * (_expr_6 * _expr_2)) ** Value.from_int(Int(2))
12+
+ (_expr_6 * _expr_4 + Value.from_int(Int(-1)) * (_expr_1 * _expr_5)) ** Value.from_int(Int(2))
13+
)
14+
/ (_expr_6 ** Value.from_int(Int(2)) + _expr_1 ** Value.from_int(Int(2)) + _expr_3 ** Value.from_int(Int(2))) ** Value.from_int(Int(3))
15+
)
16+
)

0 commit comments

Comments
 (0)