
(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 (* (- z x) y)))
(if (<= y -230000000000.0)
t_0
(if (<= y 3.3e-11)
(+ x (* z y))
(if (<= y 7200000000.0) (fma (- x) y x) t_0)))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -230000000000.0) {
tmp = t_0;
} else if (y <= 3.3e-11) {
tmp = x + (z * y);
} else if (y <= 7200000000.0) {
tmp = fma(-x, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z - x) * y) tmp = 0.0 if (y <= -230000000000.0) tmp = t_0; elseif (y <= 3.3e-11) tmp = Float64(x + Float64(z * y)); elseif (y <= 7200000000.0) tmp = fma(Float64(-x), y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -230000000000.0], t$95$0, If[LessEqual[y, 3.3e-11], N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7200000000.0], N[((-x) * y + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - x\right) \cdot y\\
\mathbf{if}\;y \leq -230000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{-11}:\\
\;\;\;\;x + z \cdot y\\
\mathbf{elif}\;y \leq 7200000000:\\
\;\;\;\;\mathsf{fma}\left(-x, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.3e11 or 7.2e9 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
if -2.3e11 < y < 3.3000000000000002e-11Initial program 100.0%
Taylor expanded in z around inf
lower-*.f64100.0
Applied rewrites100.0%
if 3.3000000000000002e-11 < y < 7.2e9Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z x) y)))
(if (<= y -230000000000.0)
t_0
(if (<= y 3.3e-11)
(+ x (* z y))
(if (<= y 7200000000.0) (- x (* x y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -230000000000.0) {
tmp = t_0;
} else if (y <= 3.3e-11) {
tmp = x + (z * y);
} else if (y <= 7200000000.0) {
tmp = x - (x * y);
} 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 = (z - x) * y
if (y <= (-230000000000.0d0)) then
tmp = t_0
else if (y <= 3.3d-11) then
tmp = x + (z * y)
else if (y <= 7200000000.0d0) then
tmp = x - (x * y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -230000000000.0) {
tmp = t_0;
} else if (y <= 3.3e-11) {
tmp = x + (z * y);
} else if (y <= 7200000000.0) {
tmp = x - (x * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z - x) * y tmp = 0 if y <= -230000000000.0: tmp = t_0 elif y <= 3.3e-11: tmp = x + (z * y) elif y <= 7200000000.0: tmp = x - (x * y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z - x) * y) tmp = 0.0 if (y <= -230000000000.0) tmp = t_0; elseif (y <= 3.3e-11) tmp = Float64(x + Float64(z * y)); elseif (y <= 7200000000.0) tmp = Float64(x - Float64(x * y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z - x) * y; tmp = 0.0; if (y <= -230000000000.0) tmp = t_0; elseif (y <= 3.3e-11) tmp = x + (z * y); elseif (y <= 7200000000.0) tmp = x - (x * y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -230000000000.0], t$95$0, If[LessEqual[y, 3.3e-11], N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7200000000.0], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - x\right) \cdot y\\
\mathbf{if}\;y \leq -230000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{-11}:\\
\;\;\;\;x + z \cdot y\\
\mathbf{elif}\;y \leq 7200000000:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.3e11 or 7.2e9 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
if -2.3e11 < y < 3.3000000000000002e-11Initial program 100.0%
Taylor expanded in z around inf
lower-*.f64100.0
Applied rewrites100.0%
if 3.3000000000000002e-11 < y < 7.2e9Initial program 99.8%
Taylor expanded in x around inf
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z x) y))) (if (<= y -4.4e-15) t_0 (if (<= y 7200000000.0) (- x (* x y)) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -4.4e-15) {
tmp = t_0;
} else if (y <= 7200000000.0) {
tmp = x - (x * y);
} 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 = (z - x) * y
if (y <= (-4.4d-15)) then
tmp = t_0
else if (y <= 7200000000.0d0) then
tmp = x - (x * y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -4.4e-15) {
tmp = t_0;
} else if (y <= 7200000000.0) {
tmp = x - (x * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z - x) * y tmp = 0 if y <= -4.4e-15: tmp = t_0 elif y <= 7200000000.0: tmp = x - (x * y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z - x) * y) tmp = 0.0 if (y <= -4.4e-15) tmp = t_0; elseif (y <= 7200000000.0) tmp = Float64(x - Float64(x * y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z - x) * y; tmp = 0.0; if (y <= -4.4e-15) tmp = t_0; elseif (y <= 7200000000.0) tmp = x - (x * y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -4.4e-15], t$95$0, If[LessEqual[y, 7200000000.0], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - x\right) \cdot y\\
\mathbf{if}\;y \leq -4.4 \cdot 10^{-15}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7200000000:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.39999999999999971e-15 or 7.2e9 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
if -4.39999999999999971e-15 < y < 7.2e9Initial program 100.0%
Taylor expanded in x around inf
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6474.6
Applied rewrites74.6%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (<= z -9.8e-11) (* z y) (if (<= z 1.18e-157) (* y (- x)) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.8e-11) {
tmp = z * y;
} else if (z <= 1.18e-157) {
tmp = y * -x;
} else {
tmp = z * y;
}
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 (z <= (-9.8d-11)) then
tmp = z * y
else if (z <= 1.18d-157) then
tmp = y * -x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -9.8e-11) {
tmp = z * y;
} else if (z <= 1.18e-157) {
tmp = y * -x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.8e-11: tmp = z * y elif z <= 1.18e-157: tmp = y * -x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.8e-11) tmp = Float64(z * y); elseif (z <= 1.18e-157) tmp = Float64(y * Float64(-x)); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.8e-11) tmp = z * y; elseif (z <= 1.18e-157) tmp = y * -x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.8e-11], N[(z * y), $MachinePrecision], If[LessEqual[z, 1.18e-157], N[(y * (-x)), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.8 \cdot 10^{-11}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 1.18 \cdot 10^{-157}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -9.7999999999999998e-11 or 1.18e-157 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6461.7
Applied rewrites61.7%
if -9.7999999999999998e-11 < z < 1.18e-157Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f6445.8
Applied rewrites45.8%
Taylor expanded in z around 0
Applied rewrites39.2%
Final simplification54.1%
(FPCore (x y z) :precision binary64 (* (- z x) y))
double code(double x, double y, double z) {
return (z - x) * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z - x) * y
end function
public static double code(double x, double y, double z) {
return (z - x) * y;
}
def code(x, y, z): return (z - x) * y
function code(x, y, z) return Float64(Float64(z - x) * y) end
function tmp = code(x, y, z) tmp = (z - x) * y; end
code[x_, y_, z_] := N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(z - x\right) \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f6464.3
Applied rewrites64.3%
Final simplification64.3%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return z * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6443.9
Applied rewrites43.9%
Final simplification43.9%
herbie shell --seed 2024226
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))