
(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 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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- 1.0 y))))
(if (<= x -1.72e-46)
t_0
(if (<= x -3.3e-126)
(* y z)
(if (<= x -1.15e-138) x (if (<= x 3e-143) (* y z) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -1.72e-46) {
tmp = t_0;
} else if (x <= -3.3e-126) {
tmp = y * z;
} else if (x <= -1.15e-138) {
tmp = x;
} else if (x <= 3e-143) {
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 * (1.0d0 - y)
if (x <= (-1.72d-46)) then
tmp = t_0
else if (x <= (-3.3d-126)) then
tmp = y * z
else if (x <= (-1.15d-138)) then
tmp = x
else if (x <= 3d-143) 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 * (1.0 - y);
double tmp;
if (x <= -1.72e-46) {
tmp = t_0;
} else if (x <= -3.3e-126) {
tmp = y * z;
} else if (x <= -1.15e-138) {
tmp = x;
} else if (x <= 3e-143) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (1.0 - y) tmp = 0 if x <= -1.72e-46: tmp = t_0 elif x <= -3.3e-126: tmp = y * z elif x <= -1.15e-138: tmp = x elif x <= 3e-143: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(1.0 - y)) tmp = 0.0 if (x <= -1.72e-46) tmp = t_0; elseif (x <= -3.3e-126) tmp = Float64(y * z); elseif (x <= -1.15e-138) tmp = x; elseif (x <= 3e-143) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (1.0 - y); tmp = 0.0; if (x <= -1.72e-46) tmp = t_0; elseif (x <= -3.3e-126) tmp = y * z; elseif (x <= -1.15e-138) tmp = x; elseif (x <= 3e-143) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.72e-46], t$95$0, If[LessEqual[x, -3.3e-126], N[(y * z), $MachinePrecision], If[LessEqual[x, -1.15e-138], x, If[LessEqual[x, 3e-143], N[(y * z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y\right)\\
\mathbf{if}\;x \leq -1.72 \cdot 10^{-46}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -3.3 \cdot 10^{-126}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;x \leq -1.15 \cdot 10^{-138}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-143}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.7199999999999999e-46 or 2.99999999999999985e-143 < x Initial program 100.0%
Taylor expanded in x around inf 81.4%
+-commutative81.4%
distribute-rgt1-in81.4%
mul-1-neg81.4%
cancel-sign-sub-inv81.4%
Simplified81.4%
Taylor expanded in x around 0 81.4%
if -1.7199999999999999e-46 < x < -3.3000000000000001e-126 or -1.14999999999999995e-138 < x < 2.99999999999999985e-143Initial program 100.0%
Taylor expanded in z around inf 96.9%
Taylor expanded in x around 0 81.5%
if -3.3000000000000001e-126 < x < -1.14999999999999995e-138Initial program 100.0%
Taylor expanded in y around 0 99.4%
Final simplification81.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3e-42) (not (<= x 1.35e+80))) (* x (- 1.0 y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3e-42) || !(x <= 1.35e+80)) {
tmp = x * (1.0 - 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 <= (-3d-42)) .or. (.not. (x <= 1.35d+80))) then
tmp = x * (1.0d0 - 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 <= -3e-42) || !(x <= 1.35e+80)) {
tmp = x * (1.0 - y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3e-42) or not (x <= 1.35e+80): tmp = x * (1.0 - y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3e-42) || !(x <= 1.35e+80)) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3e-42) || ~((x <= 1.35e+80))) tmp = x * (1.0 - y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3e-42], N[Not[LessEqual[x, 1.35e+80]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{-42} \lor \neg \left(x \leq 1.35 \cdot 10^{+80}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -3.00000000000000027e-42 or 1.34999999999999991e80 < x Initial program 100.0%
Taylor expanded in x around inf 90.5%
+-commutative90.5%
distribute-rgt1-in90.5%
mul-1-neg90.5%
cancel-sign-sub-inv90.5%
Simplified90.5%
Taylor expanded in x around 0 90.5%
if -3.00000000000000027e-42 < x < 1.34999999999999991e80Initial program 100.0%
Taylor expanded in z around inf 91.3%
Final simplification90.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.15e-76) (* y z) (if (<= y 3.8e-13) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.15e-76) {
tmp = y * z;
} else if (y <= 3.8e-13) {
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 <= (-1.15d-76)) then
tmp = y * z
else if (y <= 3.8d-13) 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 <= -1.15e-76) {
tmp = y * z;
} else if (y <= 3.8e-13) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.15e-76: tmp = y * z elif y <= 3.8e-13: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.15e-76) tmp = Float64(y * z); elseif (y <= 3.8e-13) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.15e-76) tmp = y * z; elseif (y <= 3.8e-13) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.15e-76], N[(y * z), $MachinePrecision], If[LessEqual[y, 3.8e-13], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{-76}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-13}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.15000000000000003e-76 or 3.8e-13 < y Initial program 100.0%
Taylor expanded in z around inf 57.3%
Taylor expanded in x around 0 50.2%
if -1.15000000000000003e-76 < y < 3.8e-13Initial program 100.0%
Taylor expanded in y around 0 74.2%
Final simplification61.1%
(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 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 39.2%
Final simplification39.2%
herbie shell --seed 2023228
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))