Match any generic rule that is not one of the above match_*() rules.
(
g: gh.Graph,
cache: Callable[str, list[tuple[gm.Point, ...]]],
theorem: pr.Theorem
)
| 853 | |
| 854 | |
| 855 | def match_generic( |
| 856 | g: gh.Graph, |
| 857 | cache: Callable[str, list[tuple[gm.Point, ...]]], |
| 858 | theorem: pr.Theorem |
| 859 | ) -> Generator[dict[str, gm.Point], None, None]: |
| 860 | """Match any generic rule that is not one of the above match_*() rules.""" |
| 861 | clause2enum = {} |
| 862 | |
| 863 | clauses = [] |
| 864 | numerical_checks = [] |
| 865 | for clause in theorem.premise: |
| 866 | if clause.name in ['ncoll', 'npara', 'nperp', 'sameside']: |
| 867 | numerical_checks.append(clause) |
| 868 | continue |
| 869 | |
| 870 | enum = cache(clause.name) |
| 871 | if len(enum) == 0: # pylint: disable=g-explicit-length-test |
| 872 | return 0 |
| 873 | |
| 874 | clause2enum[clause] = enum |
| 875 | clauses.append((len(set(clause.args)), clause)) |
| 876 | |
| 877 | clauses = sorted(clauses, key=lambda x: x[0], reverse=True) |
| 878 | _, clauses = zip(*clauses) |
| 879 | |
| 880 | for mapping in try_to_map([(c, clause2enum[c]) for c in clauses], {}): |
| 881 | if not mapping: |
| 882 | continue |
| 883 | |
| 884 | checks_ok = True |
| 885 | for check in numerical_checks: |
| 886 | args = [mapping[a] for a in check.args] |
| 887 | if check.name == 'ncoll': |
| 888 | checks_ok = g.check_ncoll(args) |
| 889 | elif check.name == 'npara': |
| 890 | checks_ok = g.check_npara(args) |
| 891 | elif check.name == 'nperp': |
| 892 | checks_ok = g.check_nperp(args) |
| 893 | elif check.name == 'sameside': |
| 894 | checks_ok = g.check_sameside(args) |
| 895 | if not checks_ok: |
| 896 | break |
| 897 | if not checks_ok: |
| 898 | continue |
| 899 | |
| 900 | yield mapping |
| 901 | |
| 902 | |
| 903 | BUILT_IN_FNS = { |
no test coverage detected