
(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 (* (- x) y)))
(if (<= y -1.15e+92)
t_0
(if (<= y -1.6e-52)
(* y z)
(if (<= y 4.1e-42) (* 1.0 x) (if (<= y 1.35e+145) (* y z) t_0))))))
double code(double x, double y, double z) {
double t_0 = -x * y;
double tmp;
if (y <= -1.15e+92) {
tmp = t_0;
} else if (y <= -1.6e-52) {
tmp = y * z;
} else if (y <= 4.1e-42) {
tmp = 1.0 * x;
} else if (y <= 1.35e+145) {
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 = -x * y
if (y <= (-1.15d+92)) then
tmp = t_0
else if (y <= (-1.6d-52)) then
tmp = y * z
else if (y <= 4.1d-42) then
tmp = 1.0d0 * x
else if (y <= 1.35d+145) 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 = -x * y;
double tmp;
if (y <= -1.15e+92) {
tmp = t_0;
} else if (y <= -1.6e-52) {
tmp = y * z;
} else if (y <= 4.1e-42) {
tmp = 1.0 * x;
} else if (y <= 1.35e+145) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -x * y tmp = 0 if y <= -1.15e+92: tmp = t_0 elif y <= -1.6e-52: tmp = y * z elif y <= 4.1e-42: tmp = 1.0 * x elif y <= 1.35e+145: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) * y) tmp = 0.0 if (y <= -1.15e+92) tmp = t_0; elseif (y <= -1.6e-52) tmp = Float64(y * z); elseif (y <= 4.1e-42) tmp = Float64(1.0 * x); elseif (y <= 1.35e+145) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x * y; tmp = 0.0; if (y <= -1.15e+92) tmp = t_0; elseif (y <= -1.6e-52) tmp = y * z; elseif (y <= 4.1e-42) tmp = 1.0 * x; elseif (y <= 1.35e+145) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) * y), $MachinePrecision]}, If[LessEqual[y, -1.15e+92], t$95$0, If[LessEqual[y, -1.6e-52], N[(y * z), $MachinePrecision], If[LessEqual[y, 4.1e-42], N[(1.0 * x), $MachinePrecision], If[LessEqual[y, 1.35e+145], N[(y * z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-x\right) \cdot y\\
\mathbf{if}\;y \leq -1.15 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.6 \cdot 10^{-52}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{-42}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+145}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.14999999999999999e92 or 1.35000000000000011e145 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
Applied rewrites63.5%
if -1.14999999999999999e92 < y < -1.60000000000000005e-52 or 4.1000000000000001e-42 < y < 1.35000000000000011e145Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6467.7
Applied rewrites67.7%
if -1.60000000000000005e-52 < y < 4.1000000000000001e-42Initial program 100.0%
Taylor expanded in z around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6481.1
Applied rewrites81.1%
Taylor expanded in y around 0
Applied rewrites81.1%
Final simplification71.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- z x)))) (if (<= y -1.0) t_0 (if (<= y 8.5e-9) (+ (* y z) x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 8.5e-9) {
tmp = (y * z) + x;
} 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 * (z - x)
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 8.5d-9) then
tmp = (y * z) + x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 8.5e-9) {
tmp = (y * z) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z - x) tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 8.5e-9: tmp = (y * z) + x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z - x)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 8.5e-9) tmp = Float64(Float64(y * z) + x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (z - x); tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 8.5e-9) tmp = (y * z) + x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 8.5e-9], N[(N[(y * z), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-9}:\\
\;\;\;\;y \cdot z + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 8.5e-9 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6498.7
Applied rewrites98.7%
if -1 < y < 8.5e-9Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6499.3
Applied rewrites99.3%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- z x)))) (if (<= y -1.55e-52) t_0 (if (<= y 5.2e-42) (* 1.0 x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -1.55e-52) {
tmp = t_0;
} else if (y <= 5.2e-42) {
tmp = 1.0 * x;
} 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 * (z - x)
if (y <= (-1.55d-52)) then
tmp = t_0
else if (y <= 5.2d-42) then
tmp = 1.0d0 * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -1.55e-52) {
tmp = t_0;
} else if (y <= 5.2e-42) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z - x) tmp = 0 if y <= -1.55e-52: tmp = t_0 elif y <= 5.2e-42: tmp = 1.0 * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z - x)) tmp = 0.0 if (y <= -1.55e-52) tmp = t_0; elseif (y <= 5.2e-42) tmp = Float64(1.0 * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (z - x); tmp = 0.0; if (y <= -1.55e-52) tmp = t_0; elseif (y <= 5.2e-42) tmp = 1.0 * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.55e-52], t$95$0, If[LessEqual[y, 5.2e-42], N[(1.0 * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -1.55 \cdot 10^{-52}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-42}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.5499999999999999e-52 or 5.2e-42 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6495.8
Applied rewrites95.8%
if -1.5499999999999999e-52 < y < 5.2e-42Initial program 100.0%
Taylor expanded in z around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6481.1
Applied rewrites81.1%
Taylor expanded in y around 0
Applied rewrites81.1%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 y) x))) (if (<= x -5.5e-127) t_0 (if (<= x 2.05e-198) (* y z) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - y) * x;
double tmp;
if (x <= -5.5e-127) {
tmp = t_0;
} else if (x <= 2.05e-198) {
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 <= (-5.5d-127)) then
tmp = t_0
else if (x <= 2.05d-198) 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 <= -5.5e-127) {
tmp = t_0;
} else if (x <= 2.05e-198) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - y) * x tmp = 0 if x <= -5.5e-127: tmp = t_0 elif x <= 2.05e-198: 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 <= -5.5e-127) tmp = t_0; elseif (x <= 2.05e-198) 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 <= -5.5e-127) tmp = t_0; elseif (x <= 2.05e-198) 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, -5.5e-127], t$95$0, If[LessEqual[x, 2.05e-198], 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 -5.5 \cdot 10^{-127}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{-198}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5.50000000000000036e-127 or 2.05000000000000006e-198 < x Initial program 100.0%
Taylor expanded in z around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6477.8
Applied rewrites77.8%
if -5.50000000000000036e-127 < x < 2.05000000000000006e-198Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6485.5
Applied rewrites85.5%
Final simplification79.6%
(FPCore (x y z) :precision binary64 (if (<= y -1.6e-52) (* y z) (if (<= y 4.1e-42) (* 1.0 x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.6e-52) {
tmp = y * z;
} else if (y <= 4.1e-42) {
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 <= (-1.6d-52)) then
tmp = y * z
else if (y <= 4.1d-42) 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 <= -1.6e-52) {
tmp = y * z;
} else if (y <= 4.1e-42) {
tmp = 1.0 * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.6e-52: tmp = y * z elif y <= 4.1e-42: tmp = 1.0 * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.6e-52) tmp = Float64(y * z); elseif (y <= 4.1e-42) 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 <= -1.6e-52) tmp = y * z; elseif (y <= 4.1e-42) tmp = 1.0 * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.6e-52], N[(y * z), $MachinePrecision], If[LessEqual[y, 4.1e-42], N[(1.0 * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{-52}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{-42}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.60000000000000005e-52 or 4.1000000000000001e-42 < y Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6456.3
Applied rewrites56.3%
if -1.60000000000000005e-52 < y < 4.1000000000000001e-42Initial program 100.0%
Taylor expanded in z around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6481.1
Applied rewrites81.1%
Taylor expanded in y around 0
Applied rewrites81.1%
Final simplification66.4%
(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 z around inf
*-commutativeN/A
lower-*.f6441.0
Applied rewrites41.0%
Final simplification41.0%
herbie shell --seed 2024244
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))