// A conjunction is valid iff either oerand is valid. // // TODO: Validate the easier branch first. But what is an "easier" // branch? Validation find_logical_support(Proof& p, Prop_list& ants, Disjunction_cons const& c) { Validation v = check_term(p, ants, c.left()); if (v == valid_proof || v == incomplete_proof) return v; return check_term(p, ants, c.right()); }
static int dissect_beep_mime_header(tvbuff_t *tvb, int offset, struct beep_proto_data *beep_frame_data, proto_tree *tree) { proto_tree *ti = NULL, *mime_tree = NULL; int mime_length = header_len(tvb, offset), cc = 0; if (beep_frame_data && !beep_frame_data->mime_hdr) return 0; if (tree) { /* FIXME: Should calculate the whole length of the mime headers */ ti = proto_tree_add_text(tree, tvb, offset, mime_length, "Mime header: %s", tvb_format_text(tvb, offset, mime_length)); mime_tree = proto_item_add_subtree(ti, ett_mime_header); } if (mime_length == 0) { /* Default header */ if (tree) { proto_tree_add_text(mime_tree, tvb, offset, 0, "Default values"); } if ((cc = check_term(tvb, offset, mime_tree)) <= 0) { /* Ignore it, it will cause funnies in the rest of the dissect */ } } else { /* FIXME: Process the headers */ if (tree) { proto_tree_add_text(mime_tree, tvb, offset, mime_length, "Header: %s", tvb_format_text(tvb, offset, mime_length)); } if ((cc = check_term(tvb, offset + mime_length, mime_tree)) <= 0) { /* Ignore it, it will cause funnies in the rest of the dissect */ } } return mime_length + cc; /* FIXME: Check that the CRLF is there */ }
// // Returns true iff model was successfully constructed. // Conflicts are saved as a side effect. // bool check() { bool retv = true; for (unsigned i = 0; i < m_abstr_model->get_num_constants(); i++) { func_decl * const c = m_abstr_model->get_constant(i); app * const _term = m_info->find_term(c); expr * const term = _term ? _term : m_m.mk_const(c); if (!check_term(term)) retv = false; } return retv; }
// Determine if the squent (or goal) of the form: // // A1, A2, ..., An |- C1, C2, ... Cm, // // The sequent is a valid proof if any Ai prove any Ci. The sequent // is invalid only when all Ai provie no Ci. The proof is incomplete // when it is invalid, but some Ai is a non-atomic proposition. Validation check_goal(Proof& p, Sequent& s) { Prop_list& as = s.antecedents(); Prop_list& cs = s.consequents(); Validation r = invalid_proof; for (Cons const* c : cs) { Validation v = check_term(p, as, *c); if (v == valid_proof) return v; if (v == incomplete_proof) r = v; } return r; }
static void smt_eval_mk_eq(tstack_t *stack, stack_elem_t *f, uint32_t n) { term_t *arg, last, first, t; uint32_t i; if (n == 2) { first = get_term(stack, f); last = get_term(stack, f+1); t = yices_eq(first, last); } else { arg = get_aux_buffer(stack, n); n --; last = get_term(stack, f+n); for (i=0; i<n; i++) { t = yices_eq(get_term(stack, f+i), last); check_term(stack, t); arg[i] = t; } t = yices_and(n, arg); } check_term(stack, t); tstack_pop_frame(stack); set_term_result(stack, t); }
static int is_consistent(diagnostic_problem problem, const_gotcha_node node, const_tv_term_list_list systems) { register unsigned int ix; #if 0 register unsigned int iy; #endif memset(gotcha_var_buffer, 0, sizeof(signed char) * problem->variables->sz); /* * Move backwards in the loop below, as it is more likely recently * added terms to conflict. */ for (ix = node->depth - 1; ix < node->depth; ix--) { if (!check_and_add_term(systems->arr[ix]->arr[node->offsets[ix]])) { return 0; } } #if 0 /* Check forward consistency with unit systems. */ for (ix = node->depth; ix < systems->sz; ix++) { const_tv_term_list system = systems->arr[ix]; unsigned int consistent_terms = 0; unsigned int last_consistent = 0; for (iy = 0; iy < system->sz; iy++) { if (check_term(system->arr[iy])) { consistent_terms += 1; last_consistent = iy; } } if (0 == consistent_terms) { increase_int_counter("forward inconsistent"); return 0; } if (1 == consistent_terms) { if (!check_and_add_term(system->arr[last_consistent])) { increase_int_counter("forward inconsistent"); return 0; } } } #endif return 1; }
void init_term(t_term *term) { int x; term->term = my_getenv("TERM="); check_term(term->term); term->fo = STDIN_FILENO; x = tgetent(term->buff, term->term); check_tgetent(x); term->cl = tgetstr("cl", &(term->buff)); term->ue = tgetstr("ue", &(term->buff)); term->so = tgetstr("so", &(term->buff)); term->me = tgetstr("me", &(term->buff)); term->us = tgetstr("us", &(term->buff)); term->vi = tgetstr("vi", &(term->buff)); term->ve = tgetstr("ve", &(term->buff)); }
static int dissect_beep_tree(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, struct beep_request_val *request_val, struct beep_proto_data *beep_frame_data) { proto_tree *ti = NULL, *hdr = NULL; /*proto_item *hidden_item;*/ int st_offset, msgno, ansno, seqno, size, channel, ackno, window, cc, more; const char * cmd_temp = NULL; int is_ANS = 0; st_offset = offset; if (tvb_strneql(tvb, offset, "MSG ", 4) == 0) cmd_temp = "Command: MSG"; if (tvb_strneql(tvb, offset, "RPY ", 4) == 0) cmd_temp = "Command: RPY"; if (tvb_strneql(tvb, offset, "ERR ", 4) == 0) cmd_temp = "Command: ERR"; if (tvb_strneql(tvb, offset, "NUL ", 4) == 0) cmd_temp = "Command: NUL"; if (tvb_strneql(tvb, offset, "ANS ", 4) == 0) { cmd_temp = "Command: ANS"; is_ANS = 1; } if (cmd_temp != NULL) { if (tree) { hdr = proto_tree_add_subtree(tree, tvb, offset, header_len(tvb, offset) + 2, ett_header, NULL, "Header"); ti = proto_tree_add_item(hdr, hf_beep_cmd, tvb, offset, 3, ENC_NA|ENC_ASCII); /* Include space */ proto_item_set_len(ti, 4); proto_tree_add_boolean(hdr, hf_beep_req, tvb, offset, 3, TRUE); } offset += 4; /* Get the channel */ offset += dissect_beep_int(tvb, offset, hdr, hf_beep_channel, &channel, req_chan_hfa); offset += 1; /* Skip the space */ /* Dissect the message number */ offset += dissect_beep_int(tvb, offset, hdr, hf_beep_msgno, &msgno, req_msgno_hfa); offset += 1; /* skip the space */ /* Insert the more elements ... */ if ((more = dissect_beep_more(tvb, pinfo, offset, hdr)) >= 0) { /* Figure out which direction this is in and what mime_hdr flag to * add to the beep_frame_data. If there are missing segments, this code * will get it wrong! */ set_mime_hdr_flags(more, request_val, beep_frame_data, pinfo); } else { /* Protocol violation, so dissect rest as undisectable */ if (tree && (tvb_length_remaining(tvb, offset) > 0)) { proto_tree_add_item(tree, hf_beep_payload_undissected, tvb, offset, tvb_length_remaining(tvb, offset), ENC_NA|ENC_ASCII); } return -1; } offset += 2; /* Skip the flag and the space ... */ /* now for the seqno */ offset += dissect_beep_int(tvb, offset, hdr, hf_beep_seqno, &seqno, req_seqno_hfa); offset += 1; /* skip the space */ offset += dissect_beep_int(tvb, offset, hdr, hf_beep_size, &size, req_size_hfa); if (request_val) /* FIXME, is this the right order ... */ request_val -> size = size; /* Stash this away */ else if (beep_frame_data) { beep_frame_data->pl_size = size; if (beep_frame_data->pl_size < 0) beep_frame_data->pl_size = 0; /* FIXME: OK? */ } /* offset += 1; skip the space */ if (is_ANS) { /* We need to put in the ansno */ offset += 1; /* skip the space */ /* Dissect the message number */ offset += dissect_beep_int(tvb, offset, hdr, hf_beep_ansno, &ansno, req_ansno_hfa); } if ((cc = check_term(tvb, pinfo, offset, hdr)) <= 0) { /* We dissect the rest as data and bail ... */ if (tree && (tvb_length_remaining(tvb, offset) > 0)) { proto_tree_add_item(tree, hf_beep_payload_undissected, tvb, offset, tvb_length_remaining(tvb, offset), ENC_NA|ENC_ASCII); } return -1; } offset += cc; /* Insert MIME header ... */ if (beep_frame_data && beep_frame_data->mime_hdr) offset += dissect_beep_mime_header(tvb, pinfo, offset, beep_frame_data, hdr); /* Now for the payload, if any */ if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect what is left as payload */ int pl_size = MIN(size, tvb_length_remaining(tvb, offset)); /* Except, check the payload length, and only dissect that much */ /* We need to keep track, in the conversation, of how much is left * so in the next packet, we can figure out what is part of the payload * and what is the next message */ if (tree) { proto_tree_add_item(tree, hf_beep_payload, tvb, offset, pl_size, ENC_NA|ENC_ASCII); } offset += pl_size; if (request_val) { request_val->size -= pl_size; if (request_val->size < 0) request_val->size = 0; } else if (beep_frame_data) { beep_frame_data->pl_size -= pl_size; if (beep_frame_data->pl_size < 0) beep_frame_data->pl_size = 0; } } /* If anything else left, dissect it ... */ if (tvb_length_remaining(tvb, offset) > 0) offset += dissect_beep_tree(tvb, offset, pinfo, tree, request_val, beep_frame_data); } else if (tvb_strneql(tvb, offset, "SEQ ", 4) == 0) { if (tree) { ti = proto_tree_add_item(hdr, hf_beep_cmd, tvb, offset, 3, ENC_NA|ENC_ASCII); /* Include space */ proto_item_set_len(ti, 4); } offset += 3; /* Now check the space: FIXME */ offset += 1; offset += dissect_beep_int(tvb, offset, tree, hf_beep_channel, &channel, seq_chan_hfa); /* Check the space: FIXME */ offset += 1; offset += dissect_beep_int(tvb, offset, tree, hf_beep_ackno, &ackno, seq_ackno_hfa); /* Check the space: FIXME */ offset += 1; offset += dissect_beep_int(tvb, offset, tree, hf_beep_window, &window, seq_window_hfa); if ((cc = check_term(tvb, pinfo, offset, tree)) <= 0) { /* We dissect the rest as data and bail ... */ if (tree && (tvb_length_remaining(tvb, offset) > 0)) { proto_tree_add_item(tree, hf_beep_payload_undissected, tvb, offset, tvb_length_remaining(tvb, offset), ENC_NA|ENC_ASCII); } return -1; } offset += cc; } else if (tvb_strneql(tvb, offset, "END", 3) == 0) { proto_tree *tr = NULL; if (tree) { tr = proto_tree_add_subtree(tree, tvb, offset, MIN(5, MAX(0, tvb_length_remaining(tvb, offset))), ett_trailer, NULL, "Trailer"); proto_tree_add_item(hdr, hf_beep_cmd, tvb, offset, 3, ENC_NA|ENC_ASCII); } offset += 3; if ((cc = check_term(tvb, pinfo, offset, tr)) <= 0) { /* We dissect the rest as data and bail ... */ if (tree && (tvb_length_remaining(tvb, offset) > 0)) { proto_tree_add_item(tree, hf_beep_payload_undissected, tvb, offset, tvb_length_remaining(tvb, offset), ENC_NA|ENC_ASCII); } return -1; } offset += cc; } if (tvb_length_remaining(tvb, offset) > 0) { /* Dissect anything left over */ int pl_size = 0; if (request_val) { pl_size = MIN(request_val->size, tvb_length_remaining(tvb, offset)); if (pl_size == 0) { /* The whole of the rest must be payload */ pl_size = tvb_length_remaining(tvb, offset); /* Right place ? */ } } else if (beep_frame_data) { pl_size = MIN(beep_frame_data->pl_size, tvb_length_remaining(tvb, offset)); } else { /* Just in case */ pl_size = tvb_length_remaining(tvb, offset); } /* Take care here to handle the payload correctly, and if there is * another message here, then handle it correctly as well. */ /* If the pl_size == 0 and the offset == 0?, then we have not processed * anything in this frame above, so we better treat all this data as * payload to avoid recursion loops */ if (pl_size == 0 && offset == st_offset) pl_size = tvb_length_remaining(tvb, offset); if (pl_size > 0) { if (tree) { proto_tree_add_item(tree, hf_beep_payload, tvb, offset, pl_size, ENC_NA|ENC_ASCII); } offset += pl_size; /* Advance past the payload */ if (request_val){ request_val->size -= pl_size; /* Reduce payload by what we added */ if (request_val->size < 0) request_val->size = 0; } else if (beep_frame_data) { beep_frame_data->pl_size -= pl_size; if (beep_frame_data->pl_size < 0) beep_frame_data->pl_size = 0; } } if (tvb_length_remaining(tvb, offset) > 0) { offset += dissect_beep_tree(tvb, offset, pinfo, tree, request_val, beep_frame_data); } } return offset - st_offset; }
// Validate against the constraint of C. Validation find_parametric_support(Proof& p, Prop_list& ants, Parameterized_cons const& c) { return check_term(p, ants, c.constraint()); }
// Validate against the expansion of C. Validation find_concept_support(Proof& p, Prop_list& ants, Concept_cons const& c) { return check_term(p, ants, expand(p.context(), c)); }
tactic contradiction_tactic() { auto fn = [=](environment const & env, io_state const & ios, proof_state const & s) { goals const & gs = s.get_goals(); if (empty(gs)) { throw_no_goal_if_enabled(s); return optional<proof_state>(); } goal const & g = head(gs); expr const & t = g.get_type(); substitution subst = s.get_subst(); auto tc = mk_type_checker(env); auto conserv_tc = mk_type_checker(env, UnfoldReducible); buffer<expr> hyps; g.get_hyps(hyps); for (expr const & h : hyps) { expr h_type = mlocal_type(h); h_type = tc->whnf(h_type).first; expr lhs, rhs, arg; if (is_false(env, h_type)) { assign(subst, g, mk_false_rec(*tc, h, t)); return some_proof_state(proof_state(s, tail(gs), subst)); } else if (is_not(env, h_type, arg)) { optional<expr> h_pos; for (expr const & h_prime : hyps) { constraint_seq cs; if (conserv_tc->is_def_eq(arg, mlocal_type(h_prime), justification(), cs) && !cs) { h_pos = h_prime; break; } } if (h_pos) { assign(subst, g, mk_absurd(*tc, t, *h_pos, h)); return some_proof_state(proof_state(s, tail(gs), subst)); } } else if (is_eq(h_type, lhs, rhs)) { lhs = tc->whnf(lhs).first; rhs = tc->whnf(rhs).first; optional<name> lhs_c = is_constructor_app(env, lhs); optional<name> rhs_c = is_constructor_app(env, rhs); if (lhs_c && rhs_c && *lhs_c != *rhs_c) { if (optional<name> I_name = inductive::is_intro_rule(env, *lhs_c)) { name no_confusion(*I_name, "no_confusion"); try { expr I = tc->whnf(tc->infer(lhs).first).first; buffer<expr> args; expr I_fn = get_app_args(I, args); if (is_constant(I_fn)) { level t_lvl = sort_level(tc->ensure_type(t).first); expr V = mk_app(mk_app(mk_constant(no_confusion, cons(t_lvl, const_levels(I_fn))), args), t, lhs, rhs, h); if (auto r = lift_down_if_hott(*tc, V)) { check_term(*tc, *r); assign(subst, g, *r); return some_proof_state(proof_state(s, tail(gs), subst)); } } } catch (kernel_exception & ex) { regular(env, ios) << ex << "\n"; } } } } } return none_proof_state(); }; return tactic01(fn); }