
(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 6 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 -1e+19)
t_0
(if (<= y -5e-11)
(* z y)
(if (<= y 5e-9) (* 1.0 x) (if (<= y 5e+64) t_0 (* z y)))))))
double code(double x, double y, double z) {
double t_0 = -y * x;
double tmp;
if (y <= -1e+19) {
tmp = t_0;
} else if (y <= -5e-11) {
tmp = z * y;
} else if (y <= 5e-9) {
tmp = 1.0 * x;
} else if (y <= 5e+64) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = -y * x
if (y <= (-1d+19)) then
tmp = t_0
else if (y <= (-5d-11)) then
tmp = z * y
else if (y <= 5d-9) then
tmp = 1.0d0 * x
else if (y <= 5d+64) then
tmp = t_0
else
tmp = z * y
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 <= -1e+19) {
tmp = t_0;
} else if (y <= -5e-11) {
tmp = z * y;
} else if (y <= 5e-9) {
tmp = 1.0 * x;
} else if (y <= 5e+64) {
tmp = t_0;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): t_0 = -y * x tmp = 0 if y <= -1e+19: tmp = t_0 elif y <= -5e-11: tmp = z * y elif y <= 5e-9: tmp = 1.0 * x elif y <= 5e+64: tmp = t_0 else: tmp = z * y return tmp
function code(x, y, z) t_0 = Float64(Float64(-y) * x) tmp = 0.0 if (y <= -1e+19) tmp = t_0; elseif (y <= -5e-11) tmp = Float64(z * y); elseif (y <= 5e-9) tmp = Float64(1.0 * x); elseif (y <= 5e+64) tmp = t_0; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = -y * x; tmp = 0.0; if (y <= -1e+19) tmp = t_0; elseif (y <= -5e-11) tmp = z * y; elseif (y <= 5e-9) tmp = 1.0 * x; elseif (y <= 5e+64) tmp = t_0; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-y) * x), $MachinePrecision]}, If[LessEqual[y, -1e+19], t$95$0, If[LessEqual[y, -5e-11], N[(z * y), $MachinePrecision], If[LessEqual[y, 5e-9], N[(1.0 * x), $MachinePrecision], If[LessEqual[y, 5e+64], t$95$0, N[(z * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-y\right) \cdot x\\
\mathbf{if}\;y \leq -1 \cdot 10^{+19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -5 \cdot 10^{-11}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-9}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;y \leq 5 \cdot 10^{+64}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -1e19 or 5.0000000000000001e-9 < y < 5e64Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6465.5
Applied rewrites65.5%
Taylor expanded in y around inf
Applied rewrites64.8%
if -1e19 < y < -5.00000000000000018e-11 or 5e64 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6461.6
Applied rewrites61.6%
if -5.00000000000000018e-11 < y < 5.0000000000000001e-9Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6474.1
Applied rewrites74.1%
Taylor expanded in y around 0
Applied rewrites73.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -5e-11) (not (<= y 2.65e-9))) (* (- z x) y) (* (- 1.0 y) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5e-11) || !(y <= 2.65e-9)) {
tmp = (z - x) * y;
} else {
tmp = (1.0 - y) * x;
}
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 <= (-5d-11)) .or. (.not. (y <= 2.65d-9))) then
tmp = (z - x) * y
else
tmp = (1.0d0 - y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5e-11) || !(y <= 2.65e-9)) {
tmp = (z - x) * y;
} else {
tmp = (1.0 - y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5e-11) or not (y <= 2.65e-9): tmp = (z - x) * y else: tmp = (1.0 - y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5e-11) || !(y <= 2.65e-9)) tmp = Float64(Float64(z - x) * y); else tmp = Float64(Float64(1.0 - y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5e-11) || ~((y <= 2.65e-9))) tmp = (z - x) * y; else tmp = (1.0 - y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5e-11], N[Not[LessEqual[y, 2.65e-9]], $MachinePrecision]], N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-11} \lor \neg \left(y \leq 2.65 \cdot 10^{-9}\right):\\
\;\;\;\;\left(z - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\end{array}
\end{array}
if y < -5.00000000000000018e-11 or 2.65000000000000015e-9 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6447.8
Applied rewrites47.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.3
Applied rewrites99.3%
if -5.00000000000000018e-11 < y < 2.65000000000000015e-9Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6474.1
Applied rewrites74.1%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.6e-140) (not (<= x 1.1e-64))) (* (- 1.0 y) x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.6e-140) || !(x <= 1.1e-64)) {
tmp = (1.0 - 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 ((x <= (-9.6d-140)) .or. (.not. (x <= 1.1d-64))) then
tmp = (1.0d0 - 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 ((x <= -9.6e-140) || !(x <= 1.1e-64)) {
tmp = (1.0 - y) * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.6e-140) or not (x <= 1.1e-64): tmp = (1.0 - y) * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.6e-140) || !(x <= 1.1e-64)) tmp = Float64(Float64(1.0 - y) * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.6e-140) || ~((x <= 1.1e-64))) tmp = (1.0 - y) * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.6e-140], N[Not[LessEqual[x, 1.1e-64]], $MachinePrecision]], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.6 \cdot 10^{-140} \lor \neg \left(x \leq 1.1 \cdot 10^{-64}\right):\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -9.59999999999999947e-140 or 1.1e-64 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6483.7
Applied rewrites83.7%
if -9.59999999999999947e-140 < x < 1.1e-64Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6477.9
Applied rewrites77.9%
Final simplification81.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -5e-11) (not (<= y 4.2e-11))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5e-11) || !(y <= 4.2e-11)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
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 <= (-5d-11)) .or. (.not. (y <= 4.2d-11))) then
tmp = z * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5e-11) || !(y <= 4.2e-11)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5e-11) or not (y <= 4.2e-11): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5e-11) || !(y <= 4.2e-11)) tmp = Float64(z * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5e-11) || ~((y <= 4.2e-11))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5e-11], N[Not[LessEqual[y, 4.2e-11]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-11} \lor \neg \left(y \leq 4.2 \cdot 10^{-11}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -5.00000000000000018e-11 or 4.1999999999999997e-11 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6447.8
Applied rewrites47.8%
if -5.00000000000000018e-11 < y < 4.1999999999999997e-11Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6474.1
Applied rewrites74.1%
Taylor expanded in y around 0
Applied rewrites73.6%
Final simplification59.9%
(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
*-commutativeN/A
lower-*.f6438.7
Applied rewrites38.7%
herbie shell --seed 2024329
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))