
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (- z x) y x))
double code(double x, double y, double z) {
return fma((z - x), y, x);
}
function code(x, y, z) return fma(Float64(z - x), y, x) end
code[x_, y_, z_] := N[(N[(z - x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - x, y, x\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- y) x)))
(if (<= y -1.0)
t_0
(if (<= y 1.55e-53) (* 1.0 x) (if (<= y 1.45e+254) (* y z) t_0)))))
double code(double x, double y, double z) {
double t_0 = -y * x;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.55e-53) {
tmp = 1.0 * x;
} else if (y <= 1.45e+254) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = -y * x
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 1.55d-53) then
tmp = 1.0d0 * x
else if (y <= 1.45d+254) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -y * x;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.55e-53) {
tmp = 1.0 * x;
} else if (y <= 1.45e+254) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -y * x tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 1.55e-53: tmp = 1.0 * x elif y <= 1.45e+254: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-y) * x) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 1.55e-53) tmp = Float64(1.0 * x); elseif (y <= 1.45e+254) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -y * x; tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 1.55e-53) tmp = 1.0 * x; elseif (y <= 1.45e+254) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-y) * x), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 1.55e-53], N[(1.0 * x), $MachinePrecision], If[LessEqual[y, 1.45e+254], N[(y * z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-y\right) \cdot x\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-53}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{+254}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1.45e254 < y Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6463.8
Applied rewrites63.8%
Taylor expanded in y around inf
Applied rewrites63.1%
if -1 < y < 1.55000000000000008e-53Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6478.3
Applied rewrites78.3%
Taylor expanded in y around 0
Applied rewrites77.8%
if 1.55000000000000008e-53 < y < 1.45e254Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6457.8
Applied rewrites57.8%
Final simplification67.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- z x)))) (if (<= y -850000.0) t_0 (if (<= y 0.48) (fma (- y) x x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -850000.0) {
tmp = t_0;
} else if (y <= 0.48) {
tmp = fma(-y, x, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(z - x)) tmp = 0.0 if (y <= -850000.0) tmp = t_0; elseif (y <= 0.48) tmp = fma(Float64(-y), x, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -850000.0], t$95$0, If[LessEqual[y, 0.48], N[((-y) * x + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -850000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.48:\\
\;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.5e5 or 0.47999999999999998 < y Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
distribute-rgt-inN/A
associate-+l+N/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-neg.f6497.8
Applied rewrites97.8%
Taylor expanded in y around inf
*-commutativeN/A
mul-1-negN/A
sub-negN/A
lower-*.f64N/A
lower--.f6499.7
Applied rewrites99.7%
if -8.5e5 < y < 0.47999999999999998Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6476.7
Applied rewrites76.7%
Applied rewrites76.7%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (<= x -6.8e-60) (* (- 1.0 y) x) (if (<= x 2.35e-80) (* y z) (fma (- y) x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.8e-60) {
tmp = (1.0 - y) * x;
} else if (x <= 2.35e-80) {
tmp = y * z;
} else {
tmp = fma(-y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -6.8e-60) tmp = Float64(Float64(1.0 - y) * x); elseif (x <= 2.35e-80) tmp = Float64(y * z); else tmp = fma(Float64(-y), x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -6.8e-60], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 2.35e-80], N[(y * z), $MachinePrecision], N[((-y) * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{-60}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{elif}\;x \leq 2.35 \cdot 10^{-80}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\
\end{array}
\end{array}
if x < -6.80000000000000013e-60Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6485.2
Applied rewrites85.2%
if -6.80000000000000013e-60 < x < 2.34999999999999986e-80Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6476.5
Applied rewrites76.5%
if 2.34999999999999986e-80 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6491.8
Applied rewrites91.8%
Applied rewrites91.8%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 y) x))) (if (<= x -6.8e-60) t_0 (if (<= x 2.35e-80) (* y z) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - y) * x;
double tmp;
if (x <= -6.8e-60) {
tmp = t_0;
} else if (x <= 2.35e-80) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (1.0d0 - y) * x
if (x <= (-6.8d-60)) then
tmp = t_0
else if (x <= 2.35d-80) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (1.0 - y) * x;
double tmp;
if (x <= -6.8e-60) {
tmp = t_0;
} else if (x <= 2.35e-80) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - y) * x tmp = 0 if x <= -6.8e-60: tmp = t_0 elif x <= 2.35e-80: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - y) * x) tmp = 0.0 if (x <= -6.8e-60) tmp = t_0; elseif (x <= 2.35e-80) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - y) * x; tmp = 0.0; if (x <= -6.8e-60) tmp = t_0; elseif (x <= 2.35e-80) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -6.8e-60], t$95$0, If[LessEqual[x, 2.35e-80], N[(y * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - y\right) \cdot x\\
\mathbf{if}\;x \leq -6.8 \cdot 10^{-60}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.35 \cdot 10^{-80}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -6.80000000000000013e-60 or 2.34999999999999986e-80 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6488.5
Applied rewrites88.5%
if -6.80000000000000013e-60 < x < 2.34999999999999986e-80Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6476.5
Applied rewrites76.5%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (<= y -2.6e-12) (* y z) (if (<= y 1.55e-53) (* 1.0 x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.6e-12) {
tmp = y * z;
} else if (y <= 1.55e-53) {
tmp = 1.0 * x;
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-2.6d-12)) then
tmp = y * z
else if (y <= 1.55d-53) then
tmp = 1.0d0 * x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.6e-12) {
tmp = y * z;
} else if (y <= 1.55e-53) {
tmp = 1.0 * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.6e-12: tmp = y * z elif y <= 1.55e-53: tmp = 1.0 * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.6e-12) tmp = Float64(y * z); elseif (y <= 1.55e-53) tmp = Float64(1.0 * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.6e-12) tmp = y * z; elseif (y <= 1.55e-53) tmp = 1.0 * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.6e-12], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.55e-53], N[(1.0 * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{-12}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-53}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -2.59999999999999983e-12 or 1.55000000000000008e-53 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6449.8
Applied rewrites49.8%
if -2.59999999999999983e-12 < y < 1.55000000000000008e-53Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6478.8
Applied rewrites78.8%
Taylor expanded in y around 0
Applied rewrites78.8%
Final simplification61.8%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return y * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6438.6
Applied rewrites38.6%
Final simplification38.6%
herbie shell --seed 2024327
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))