
(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 (+ 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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -9.5e-32)
(* y z)
(if (<= y 9.2e-23)
x
(if (or (<= y 5.6e+71)
(and (not (<= y 2.3e+118))
(or (<= y 1.02e+210)
(and (not (<= y 4.6e+262)) (<= y 1.35e+289)))))
(* y z)
(* x (- y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.5e-32) {
tmp = y * z;
} else if (y <= 9.2e-23) {
tmp = x;
} else if ((y <= 5.6e+71) || (!(y <= 2.3e+118) && ((y <= 1.02e+210) || (!(y <= 4.6e+262) && (y <= 1.35e+289))))) {
tmp = y * z;
} else {
tmp = x * -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 <= (-9.5d-32)) then
tmp = y * z
else if (y <= 9.2d-23) then
tmp = x
else if ((y <= 5.6d+71) .or. (.not. (y <= 2.3d+118)) .and. (y <= 1.02d+210) .or. (.not. (y <= 4.6d+262)) .and. (y <= 1.35d+289)) then
tmp = y * z
else
tmp = x * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -9.5e-32) {
tmp = y * z;
} else if (y <= 9.2e-23) {
tmp = x;
} else if ((y <= 5.6e+71) || (!(y <= 2.3e+118) && ((y <= 1.02e+210) || (!(y <= 4.6e+262) && (y <= 1.35e+289))))) {
tmp = y * z;
} else {
tmp = x * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.5e-32: tmp = y * z elif y <= 9.2e-23: tmp = x elif (y <= 5.6e+71) or (not (y <= 2.3e+118) and ((y <= 1.02e+210) or (not (y <= 4.6e+262) and (y <= 1.35e+289)))): tmp = y * z else: tmp = x * -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.5e-32) tmp = Float64(y * z); elseif (y <= 9.2e-23) tmp = x; elseif ((y <= 5.6e+71) || (!(y <= 2.3e+118) && ((y <= 1.02e+210) || (!(y <= 4.6e+262) && (y <= 1.35e+289))))) tmp = Float64(y * z); else tmp = Float64(x * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9.5e-32) tmp = y * z; elseif (y <= 9.2e-23) tmp = x; elseif ((y <= 5.6e+71) || (~((y <= 2.3e+118)) && ((y <= 1.02e+210) || (~((y <= 4.6e+262)) && (y <= 1.35e+289))))) tmp = y * z; else tmp = x * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.5e-32], N[(y * z), $MachinePrecision], If[LessEqual[y, 9.2e-23], x, If[Or[LessEqual[y, 5.6e+71], And[N[Not[LessEqual[y, 2.3e+118]], $MachinePrecision], Or[LessEqual[y, 1.02e+210], And[N[Not[LessEqual[y, 4.6e+262]], $MachinePrecision], LessEqual[y, 1.35e+289]]]]], N[(y * z), $MachinePrecision], N[(x * (-y)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{-32}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 9.2 \cdot 10^{-23}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{+71} \lor \neg \left(y \leq 2.3 \cdot 10^{+118}\right) \land \left(y \leq 1.02 \cdot 10^{+210} \lor \neg \left(y \leq 4.6 \cdot 10^{+262}\right) \land y \leq 1.35 \cdot 10^{+289}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < -9.4999999999999999e-32 or 9.2000000000000004e-23 < y < 5.60000000000000004e71 or 2.30000000000000016e118 < y < 1.02000000000000005e210 or 4.5999999999999999e262 < y < 1.35e289Initial program 100.0%
Taylor expanded in z around inf 62.2%
Taylor expanded in x around 0 60.2%
if -9.4999999999999999e-32 < y < 9.2000000000000004e-23Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 75.3%
if 5.60000000000000004e71 < y < 2.30000000000000016e118 or 1.02000000000000005e210 < y < 4.5999999999999999e262 or 1.35e289 < y Initial program 99.9%
Taylor expanded in z around 0 75.9%
mul-1-neg75.9%
distribute-rgt-neg-out75.9%
Simplified75.9%
Taylor expanded in y around inf 75.9%
mul-1-neg75.9%
distribute-rgt-neg-in75.9%
Simplified75.9%
Final simplification68.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.8e+21) (not (<= x 1.75e+93))) (- x (* x y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e+21) || !(x <= 1.75e+93)) {
tmp = x - (x * y);
} else {
tmp = x + (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 ((x <= (-2.8d+21)) .or. (.not. (x <= 1.75d+93))) then
tmp = x - (x * y)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e+21) || !(x <= 1.75e+93)) {
tmp = x - (x * y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.8e+21) or not (x <= 1.75e+93): tmp = x - (x * y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.8e+21) || !(x <= 1.75e+93)) tmp = Float64(x - Float64(x * y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.8e+21) || ~((x <= 1.75e+93))) tmp = x - (x * y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.8e+21], N[Not[LessEqual[x, 1.75e+93]], $MachinePrecision]], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+21} \lor \neg \left(x \leq 1.75 \cdot 10^{+93}\right):\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -2.8e21 or 1.74999999999999999e93 < x Initial program 100.0%
Taylor expanded in z around 0 89.8%
mul-1-neg89.8%
distribute-rgt-neg-out89.8%
Simplified89.8%
Taylor expanded in x around 0 89.8%
neg-mul-189.8%
+-commutative89.8%
distribute-rgt1-in89.8%
cancel-sign-sub-inv89.8%
Simplified89.8%
if -2.8e21 < x < 1.74999999999999999e93Initial program 100.0%
Taylor expanded in z around inf 85.3%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (<= y -9.5e-30) (* y z) (if (<= y 4.8e-18) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.5e-30) {
tmp = y * z;
} else if (y <= 4.8e-18) {
tmp = 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 <= (-9.5d-30)) then
tmp = y * z
else if (y <= 4.8d-18) then
tmp = 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 <= -9.5e-30) {
tmp = y * z;
} else if (y <= 4.8e-18) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.5e-30: tmp = y * z elif y <= 4.8e-18: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.5e-30) tmp = Float64(y * z); elseif (y <= 4.8e-18) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9.5e-30) tmp = y * z; elseif (y <= 4.8e-18) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.5e-30], N[(y * z), $MachinePrecision], If[LessEqual[y, 4.8e-18], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{-30}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{-18}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -9.49999999999999939e-30 or 4.79999999999999988e-18 < y Initial program 100.0%
Taylor expanded in z around inf 55.4%
Taylor expanded in x around 0 54.0%
if -9.49999999999999939e-30 < y < 4.79999999999999988e-18Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 75.3%
Final simplification63.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.95e+259) (* x (- y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.95e+259) {
tmp = x * -y;
} else {
tmp = x + (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 (x <= (-1.95d+259)) then
tmp = x * -y
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.95e+259) {
tmp = x * -y;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.95e+259: tmp = x * -y else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.95e+259) tmp = Float64(x * Float64(-y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.95e+259) tmp = x * -y; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.95e+259], N[(x * (-y)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{+259}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.94999999999999993e259Initial program 100.0%
Taylor expanded in z around 0 100.0%
mul-1-neg100.0%
distribute-rgt-neg-out100.0%
Simplified100.0%
Taylor expanded in y around inf 92.1%
mul-1-neg92.1%
distribute-rgt-neg-in92.1%
Simplified92.1%
if -1.94999999999999993e259 < x Initial program 100.0%
Taylor expanded in z around inf 77.5%
Final simplification78.1%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return 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
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 74.7%
Taylor expanded in x around inf 35.1%
Final simplification35.1%
herbie shell --seed 2023278
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))