
(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 (+ (* (- z x) y) x))
double code(double x, double y, double z) {
return ((z - x) * y) + x;
}
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) + x
end function
public static double code(double x, double y, double z) {
return ((z - x) * y) + x;
}
def code(x, y, z): return ((z - x) * y) + x
function code(x, y, z) return Float64(Float64(Float64(z - x) * y) + x) end
function tmp = code(x, y, z) tmp = ((z - x) * y) + x; end
code[x_, y_, z_] := N[(N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(z - x\right) \cdot y + x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- x) y)))
(if (<= y -5.2e+164)
(* z y)
(if (<= y -1.7e+82)
t_0
(if (<= y -2.85e-58)
(* z y)
(if (<= y 7e-16)
(* 1.0 x)
(if (<= y 3.1e+61) (* z y) (if (<= y 2.1e+193) t_0 (* z y)))))))))
double code(double x, double y, double z) {
double t_0 = -x * y;
double tmp;
if (y <= -5.2e+164) {
tmp = z * y;
} else if (y <= -1.7e+82) {
tmp = t_0;
} else if (y <= -2.85e-58) {
tmp = z * y;
} else if (y <= 7e-16) {
tmp = 1.0 * x;
} else if (y <= 3.1e+61) {
tmp = z * y;
} else if (y <= 2.1e+193) {
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 = -x * y
if (y <= (-5.2d+164)) then
tmp = z * y
else if (y <= (-1.7d+82)) then
tmp = t_0
else if (y <= (-2.85d-58)) then
tmp = z * y
else if (y <= 7d-16) then
tmp = 1.0d0 * x
else if (y <= 3.1d+61) then
tmp = z * y
else if (y <= 2.1d+193) 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 = -x * y;
double tmp;
if (y <= -5.2e+164) {
tmp = z * y;
} else if (y <= -1.7e+82) {
tmp = t_0;
} else if (y <= -2.85e-58) {
tmp = z * y;
} else if (y <= 7e-16) {
tmp = 1.0 * x;
} else if (y <= 3.1e+61) {
tmp = z * y;
} else if (y <= 2.1e+193) {
tmp = t_0;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): t_0 = -x * y tmp = 0 if y <= -5.2e+164: tmp = z * y elif y <= -1.7e+82: tmp = t_0 elif y <= -2.85e-58: tmp = z * y elif y <= 7e-16: tmp = 1.0 * x elif y <= 3.1e+61: tmp = z * y elif y <= 2.1e+193: tmp = t_0 else: tmp = z * y return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) * y) tmp = 0.0 if (y <= -5.2e+164) tmp = Float64(z * y); elseif (y <= -1.7e+82) tmp = t_0; elseif (y <= -2.85e-58) tmp = Float64(z * y); elseif (y <= 7e-16) tmp = Float64(1.0 * x); elseif (y <= 3.1e+61) tmp = Float64(z * y); elseif (y <= 2.1e+193) tmp = t_0; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x * y; tmp = 0.0; if (y <= -5.2e+164) tmp = z * y; elseif (y <= -1.7e+82) tmp = t_0; elseif (y <= -2.85e-58) tmp = z * y; elseif (y <= 7e-16) tmp = 1.0 * x; elseif (y <= 3.1e+61) tmp = z * y; elseif (y <= 2.1e+193) tmp = t_0; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) * y), $MachinePrecision]}, If[LessEqual[y, -5.2e+164], N[(z * y), $MachinePrecision], If[LessEqual[y, -1.7e+82], t$95$0, If[LessEqual[y, -2.85e-58], N[(z * y), $MachinePrecision], If[LessEqual[y, 7e-16], N[(1.0 * x), $MachinePrecision], If[LessEqual[y, 3.1e+61], N[(z * y), $MachinePrecision], If[LessEqual[y, 2.1e+193], t$95$0, N[(z * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-x\right) \cdot y\\
\mathbf{if}\;y \leq -5.2 \cdot 10^{+164}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq -1.7 \cdot 10^{+82}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -2.85 \cdot 10^{-58}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-16}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+61}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+193}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -5.1999999999999998e164 or -1.69999999999999997e82 < y < -2.85000000000000016e-58 or 7.00000000000000035e-16 < y < 3.0999999999999999e61 or 2.1e193 < y Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6467.2
Applied rewrites67.2%
if -5.1999999999999998e164 < y < -1.69999999999999997e82 or 3.0999999999999999e61 < y < 2.1e193Initial 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 rewrites75.1%
if -2.85000000000000016e-58 < y < 7.00000000000000035e-16Initial 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--.f6476.5
Applied rewrites76.5%
Taylor expanded in y around 0
Applied rewrites76.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z x) y))) (if (<= y -1.0) t_0 (if (<= y 2.7e-9) (+ (* z y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 2.7e-9) {
tmp = (z * y) + 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 = (z - x) * y
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 2.7d-9) then
tmp = (z * y) + x
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 <= -1.0) {
tmp = t_0;
} else if (y <= 2.7e-9) {
tmp = (z * y) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z - x) * y tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 2.7e-9: tmp = (z * 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 <= -1.0) tmp = t_0; elseif (y <= 2.7e-9) tmp = Float64(Float64(z * y) + x); 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 <= -1.0) tmp = t_0; elseif (y <= 2.7e-9) tmp = (z * y) + x; 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, -1.0], t$95$0, If[LessEqual[y, 2.7e-9], N[(N[(z * y), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - x\right) \cdot y\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-9}:\\
\;\;\;\;z \cdot y + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 2.7000000000000002e-9 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.9
Applied rewrites99.9%
if -1 < y < 2.7000000000000002e-9Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z x) y))) (if (<= y -2.85e-58) t_0 (if (<= y 2e-13) (* (- 1.0 y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -2.85e-58) {
tmp = t_0;
} else if (y <= 2e-13) {
tmp = (1.0 - y) * 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 = (z - x) * y
if (y <= (-2.85d-58)) then
tmp = t_0
else if (y <= 2d-13) then
tmp = (1.0d0 - y) * x
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 <= -2.85e-58) {
tmp = t_0;
} else if (y <= 2e-13) {
tmp = (1.0 - y) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z - x) * y tmp = 0 if y <= -2.85e-58: tmp = t_0 elif y <= 2e-13: tmp = (1.0 - 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 <= -2.85e-58) tmp = t_0; elseif (y <= 2e-13) tmp = Float64(Float64(1.0 - y) * x); 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 <= -2.85e-58) tmp = t_0; elseif (y <= 2e-13) tmp = (1.0 - y) * x; 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, -2.85e-58], t$95$0, If[LessEqual[y, 2e-13], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - x\right) \cdot y\\
\mathbf{if}\;y \leq -2.85 \cdot 10^{-58}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-13}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.85000000000000016e-58 or 2.0000000000000001e-13 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.0
Applied rewrites99.0%
if -2.85000000000000016e-58 < y < 2.0000000000000001e-13Initial 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--.f6476.5
Applied rewrites76.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 y) x))) (if (<= x -2.4e-135) t_0 (if (<= x 4.2e-74) (* z y) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - y) * x;
double tmp;
if (x <= -2.4e-135) {
tmp = t_0;
} else if (x <= 4.2e-74) {
tmp = z * 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 = (1.0d0 - y) * x
if (x <= (-2.4d-135)) then
tmp = t_0
else if (x <= 4.2d-74) then
tmp = z * y
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 <= -2.4e-135) {
tmp = t_0;
} else if (x <= 4.2e-74) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - y) * x tmp = 0 if x <= -2.4e-135: tmp = t_0 elif x <= 4.2e-74: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - y) * x) tmp = 0.0 if (x <= -2.4e-135) tmp = t_0; elseif (x <= 4.2e-74) tmp = Float64(z * y); 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 <= -2.4e-135) tmp = t_0; elseif (x <= 4.2e-74) tmp = z * y; 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, -2.4e-135], t$95$0, If[LessEqual[x, 4.2e-74], N[(z * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - y\right) \cdot x\\
\mathbf{if}\;x \leq -2.4 \cdot 10^{-135}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-74}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.3999999999999999e-135 or 4.2e-74 < 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--.f6482.9
Applied rewrites82.9%
if -2.3999999999999999e-135 < x < 4.2e-74Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6472.7
Applied rewrites72.7%
(FPCore (x y z) :precision binary64 (if (<= y -2.85e-58) (* z y) (if (<= y 7e-16) (* 1.0 x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.85e-58) {
tmp = z * y;
} else if (y <= 7e-16) {
tmp = 1.0 * 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 (y <= (-2.85d-58)) then
tmp = z * y
else if (y <= 7d-16) then
tmp = 1.0d0 * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.85e-58) {
tmp = z * y;
} else if (y <= 7e-16) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.85e-58: tmp = z * y elif y <= 7e-16: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.85e-58) tmp = Float64(z * y); elseif (y <= 7e-16) tmp = Float64(1.0 * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.85e-58) tmp = z * y; elseif (y <= 7e-16) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.85e-58], N[(z * y), $MachinePrecision], If[LessEqual[y, 7e-16], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.85 \cdot 10^{-58}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-16}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -2.85000000000000016e-58 or 7.00000000000000035e-16 < y Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6455.7
Applied rewrites55.7%
if -2.85000000000000016e-58 < y < 7.00000000000000035e-16Initial 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--.f6476.5
Applied rewrites76.5%
Taylor expanded in y around 0
Applied rewrites76.5%
(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 z around inf
*-commutativeN/A
lower-*.f6443.3
Applied rewrites43.3%
herbie shell --seed 2024270
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))