Categories
Tags
3d ABI Actions algorithms alignment analyze APIT Arc Architecture arm array ascii ash assembly asynchronous attribute base64 bithacks Blogging box c c23 cdylib CHAR_BIT clamp clang clang-format client clippy cmake compiler Computer concat concurrency const_fn constexpr contravariant cos covariant cpp cpu crate CS Customization cybersecurity DataStructure db debugging Demo deserialization discrete dll doc DP drawio dtruss dylib Dynamic emulator example Example FFI ffmpeg flamegraph flat_map fold format FP fsanitize Functional FunctionalProgramming functions futures Fuwari game GATs gcc gccrs generics gitignore glibc GUI hacking hashmap haskell heap hyperfine Imperative inference intel interop invariant iterator join justfile kernel LaTeX leak LFU limits linux lto MachineLearning macOS map Markdown math ML mmap mod mp3 nc nextest OnceLock optimization OS ownership panic parallels perf physics pin postgresql procedure product profiling pub radare2 rayon release reverse RPIT rust sanitizer Science science serialization server shift SIMD sin size SmallProjects so socket std strace String StringView strip strlen struct sum super surrealdb SWAR swisstable synchronous syscall tan test thread time toml tracing traits trap triangulation type uint32_t UnsafeRust utf16 utf8 vector Video vulkan wsl x86_64 xilem zig
200 words
1 minutes
240701_for_all_vs_for_some
link
1. The core idea (logic symbols)|🔝|
| English phrase | Logical quantifier | Symbol |
|---|---|---|
| for some | existential | ∃ |
| for all | universal | ∀ |
2. Formal mathematical meaning|🔝|
- 🔹 “For some”
There exists at least one element that satisfies the condition.
- 🔹 “For all”
Every element must satisfy the condition.
3. Programming intuition (Rust-style)|🔝|
For some → any()
let exists = xs.iter().any(|x| x % 2 == 0);Stop early on FIRST trueFor all → all()
let all = xs.iter().all(|x| x % 2 == 0);Stop early on FIRST false
4. Rust 코드로 실습|🔝|
use std::ops::Rem;
fn for_some<T>(x: &[T]) -> bool
where
T: Copy + Rem<T, Output = T> + PartialEq<T> + From<u8>,
{
if x.iter().any(|xi| *xi % T::from(2) == T::from(0)) {
true
} else {
false
}
}
fn for_all<T>(x: &[T]) -> bool
where
T: Copy + Rem<T, Output = T> + PartialEq<T> + From<u8>,
{
if x.iter().all(|xi| *xi % T::from(2) == T::from(0)) {
true
} else {
false
}
}
fn main() {
let a = vec![1, 2, 3, 4, 5];
let b = vec![1, 2, 3, 4, 5];
let is_some = for_some(&a);
println!("a is some : {is_some}");
let is_all = for_all(&b);
println!("b is all : {is_all}");
}- result
a is some : true
b is all : false240701_for_all_vs_for_some
https://younghakim7.github.io/blog/posts/240701_for_all_vs_for_some/