Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenClontz committed Dec 13, 2024
1 parent 5922ce7 commit f632813
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
19 changes: 6 additions & 13 deletions packages/viewer/src/components/Traits/Redundancy.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
<script lang="ts">
import { checkNegation } from '@/stores/deduction'
import { checkIfRedundant } from '@/stores/deduction'
import context from '@/context'
import type { Space, Property } from '@/types'
import type { Theorem } from '@/models'
import Table from '../Theorems/Table.svelte'
export let space: Space
export let property: Property
const { theorems, traits } = context()
$: result = checkNegation($theorems, space, $traits, property)
let thms: Theorem[]
$: if (result.kind === 'contradiction') {
thms = result.contradiction.theorems
.map(i => $theorems.find(i))
.filter(t => t !== null)
}
$: result = checkIfRedundant(space, property, $theorems, $traits)
</script>

{#if result.kind === 'contradiction'}
{#if result.redundant}
<div class="alert alert-warning">
<strong>Notice:</strong>
This asserted property can be deduced from the other asserted traits for
this space.
This asserted property can be deduced from the other asserted traits for this
space, due to the following theorems.
</div>
<Table theorems={thms} />
<Table theorems={result.theorems} />
{/if}
20 changes: 14 additions & 6 deletions packages/viewer/src/stores/deduction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type {
Traits,
} from '@/models'
import { eachTick, read, subscribeUntil } from '@/util'
import type { Result } from '@pi-base/core'

export type State = {
checked: Set<number>
Expand Down Expand Up @@ -190,12 +189,12 @@ function loadProof(
return result
}

export function checkNegation(
theorems: Theorems,
export function checkIfRedundant(
space: Space,
traits: Traits,
property: Property,
): Result<number, number> {
thms: Theorems,
traits: Traits,
): { redundant: boolean; theorems: Theorem[] } {
const assertedTraits = traits.forSpace(space).filter(([_, t]) => t.asserted)
const map = new Map(
assertedTraits.map(([p, t]) => {
Expand All @@ -206,5 +205,14 @@ export function checkNegation(
}
}),
)
return deduceTraits(indexTheorems(theorems), map)
const result = deduceTraits(indexTheorems(thms), map)
const redundant = result.kind === 'contradiction'
if (!redundant) {
const theorems: Theorem[] = []
return { redundant, theorems }
}
const theorems = result.contradiction.theorems
.map(t => thms.find(t))
.filter(t => t !== null)
return { redundant, theorems }
}

0 comments on commit f632813

Please sign in to comment.