
(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 8 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 y (- z x) x))
double code(double x, double y, double z) {
return fma(y, (z - x), x);
}
function code(x, y, z) return fma(y, Float64(z - x), x) end
code[x_, y_, z_] := N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, z - x, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -4.8e-35)
(* y z)
(if (<= y 1.4e-25)
x
(if (or (<= y 4300000.0) (and (not (<= y 2.7e+129)) (<= y 3.5e+244)))
(* y z)
(* y (- x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e-35) {
tmp = y * z;
} else if (y <= 1.4e-25) {
tmp = x;
} else if ((y <= 4300000.0) || (!(y <= 2.7e+129) && (y <= 3.5e+244))) {
tmp = y * z;
} else {
tmp = 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 <= (-4.8d-35)) then
tmp = y * z
else if (y <= 1.4d-25) then
tmp = x
else if ((y <= 4300000.0d0) .or. (.not. (y <= 2.7d+129)) .and. (y <= 3.5d+244)) then
tmp = y * z
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e-35) {
tmp = y * z;
} else if (y <= 1.4e-25) {
tmp = x;
} else if ((y <= 4300000.0) || (!(y <= 2.7e+129) && (y <= 3.5e+244))) {
tmp = y * z;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.8e-35: tmp = y * z elif y <= 1.4e-25: tmp = x elif (y <= 4300000.0) or (not (y <= 2.7e+129) and (y <= 3.5e+244)): tmp = y * z else: tmp = y * -x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.8e-35) tmp = Float64(y * z); elseif (y <= 1.4e-25) tmp = x; elseif ((y <= 4300000.0) || (!(y <= 2.7e+129) && (y <= 3.5e+244))) tmp = Float64(y * z); else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.8e-35) tmp = y * z; elseif (y <= 1.4e-25) tmp = x; elseif ((y <= 4300000.0) || (~((y <= 2.7e+129)) && (y <= 3.5e+244))) tmp = y * z; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.8e-35], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.4e-25], x, If[Or[LessEqual[y, 4300000.0], And[N[Not[LessEqual[y, 2.7e+129]], $MachinePrecision], LessEqual[y, 3.5e+244]]], N[(y * z), $MachinePrecision], N[(y * (-x)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{-35}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-25}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 4300000 \lor \neg \left(y \leq 2.7 \cdot 10^{+129}\right) \land y \leq 3.5 \cdot 10^{+244}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if y < -4.8000000000000003e-35 or 1.39999999999999994e-25 < y < 4.3e6 or 2.7000000000000001e129 < y < 3.49999999999999973e244Initial program 100.0%
Taylor expanded in y around inf 99.9%
Taylor expanded in z around inf 62.7%
if -4.8000000000000003e-35 < y < 1.39999999999999994e-25Initial program 100.0%
Taylor expanded in y around 0 76.7%
if 4.3e6 < y < 2.7000000000000001e129 or 3.49999999999999973e244 < y Initial program 99.9%
Taylor expanded in y around inf 99.9%
Taylor expanded in y around inf 98.6%
Taylor expanded in z around 0 64.7%
mul-1-neg64.7%
distribute-lft-neg-out64.7%
*-commutative64.7%
Simplified64.7%
Final simplification69.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -15500000.0) (not (<= y 8.5e-7))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -15500000.0) || !(y <= 8.5e-7)) {
tmp = y * (z - x);
} 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 ((y <= (-15500000.0d0)) .or. (.not. (y <= 8.5d-7))) then
tmp = y * (z - x)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -15500000.0) || !(y <= 8.5e-7)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -15500000.0) or not (y <= 8.5e-7): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -15500000.0) || !(y <= 8.5e-7)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -15500000.0) || ~((y <= 8.5e-7))) tmp = y * (z - x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -15500000.0], N[Not[LessEqual[y, 8.5e-7]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -15500000 \lor \neg \left(y \leq 8.5 \cdot 10^{-7}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1.55e7 or 8.50000000000000014e-7 < y Initial program 99.9%
Taylor expanded in y around inf 99.9%
Taylor expanded in y around inf 98.9%
if -1.55e7 < y < 8.50000000000000014e-7Initial program 100.0%
Taylor expanded in z around inf 99.0%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.5e-5) (not (<= y 4e-9))) (* y (- z x)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e-5) || !(y <= 4e-9)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - 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-5)) .or. (.not. (y <= 4d-9))) then
tmp = y * (z - x)
else
tmp = x * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e-5) || !(y <= 4e-9)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.5e-5) or not (y <= 4e-9): tmp = y * (z - x) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.5e-5) || !(y <= 4e-9)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9.5e-5) || ~((y <= 4e-9))) tmp = y * (z - x); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.5e-5], N[Not[LessEqual[y, 4e-9]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{-5} \lor \neg \left(y \leq 4 \cdot 10^{-9}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -9.5000000000000005e-5 or 4.00000000000000025e-9 < y Initial program 99.9%
Taylor expanded in y around inf 99.9%
Taylor expanded in y around inf 98.9%
if -9.5000000000000005e-5 < y < 4.00000000000000025e-9Initial program 100.0%
Taylor expanded in x around inf 75.7%
mul-1-neg75.7%
unsub-neg75.7%
Simplified75.7%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.1e-21) (not (<= z 3.4e+134))) (* y z) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e-21) || !(z <= 3.4e+134)) {
tmp = y * z;
} else {
tmp = x * (1.0 - 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 <= (-3.1d-21)) .or. (.not. (z <= 3.4d+134))) then
tmp = y * z
else
tmp = x * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e-21) || !(z <= 3.4e+134)) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.1e-21) or not (z <= 3.4e+134): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.1e-21) || !(z <= 3.4e+134)) tmp = Float64(y * z); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.1e-21) || ~((z <= 3.4e+134))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.1e-21], N[Not[LessEqual[z, 3.4e+134]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{-21} \lor \neg \left(z \leq 3.4 \cdot 10^{+134}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -3.0999999999999998e-21 or 3.40000000000000018e134 < z Initial program 100.0%
Taylor expanded in y around inf 89.5%
Taylor expanded in z around inf 71.2%
if -3.0999999999999998e-21 < z < 3.40000000000000018e134Initial program 99.9%
Taylor expanded in x around inf 81.8%
mul-1-neg81.8%
unsub-neg81.8%
Simplified81.8%
Final simplification77.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.4e-33) (not (<= y 3e-25))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.4e-33) || !(y <= 3e-25)) {
tmp = y * z;
} else {
tmp = 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 <= (-1.4d-33)) .or. (.not. (y <= 3d-25))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.4e-33) || !(y <= 3e-25)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.4e-33) or not (y <= 3e-25): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.4e-33) || !(y <= 3e-25)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.4e-33) || ~((y <= 3e-25))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.4e-33], N[Not[LessEqual[y, 3e-25]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-33} \lor \neg \left(y \leq 3 \cdot 10^{-25}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.4e-33 or 2.9999999999999998e-25 < y Initial program 99.9%
Taylor expanded in y around inf 99.9%
Taylor expanded in z around inf 56.9%
if -1.4e-33 < y < 2.9999999999999998e-25Initial program 100.0%
Taylor expanded in y around 0 76.7%
Final simplification66.3%
(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%
(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 y around 0 38.8%
herbie shell --seed 2024106
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))