S.I/Lisp/

_Is_1_2?




A1="Water is not wet."
A2="Mary is a woman."
A3="All women are mortal."
A4="Women is the plural of woman."

=_Is_1_2?("water", "wet", A1:A4)
-> "No. Water is not wet."

=_Is_1_2?("Mary", "mortal", A1:A4)
-> "Yes. Mary is mortal."
        



DEFINE(
    _Is_1_2?,
    LAMBDA(
        _1,
        _2,
        knowledgebase,
        LET(
            knowledgecolumn,
                TOCOL(knowledgebase),
            affirmation,
                OR(
                    CONTAINS(
                        knowledgecolumn,
                        FORMAT(
                            "{1} is {2}.",
                            CAPITALIZE(_1),
                            _2)),
                    NOTERROR?(
                        MATCH(
                            _?_is_the_1_of_2.(
                                "plural",
                                TEXTAFTER(
                                    _1_is_?.(_1, knowledgecolumn),
                                    " "),
                                knowledgecolumn),
                            _All_?_are_1.(_2, knowledgecolumn)))),
            negation,
                CONTAINS(
                    knowledgecolumn,
                    FORMAT(
                        "{1} is not {2}.",
                        CAPITALIZE(_1),
                        _2)),
            template,
                IFS(
                    AND(
                        affirmation,
                        negation),
                        "Yes and no. {1} simultaneously is and is not {2}.",
                    affirmation,
                        "Yes. {1} is {2}.",
                    negation,
                        "No. {1} is not {2}.",
                    OTHERWISE,
                        "Unknown."),
            FORMAT(
                template,
                CAPITALIZE(_1),
                _2))))
        



Help us optimize this function