
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ x -1.0) z (* x y)))
double code(double x, double y, double z) {
return fma((x + -1.0), z, (x * y));
}
function code(x, y, z) return fma(Float64(x + -1.0), z, Float64(x * y)) end
code[x_, y_, z_] := N[(N[(x + -1.0), $MachinePrecision] * z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + -1, z, x \cdot y\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-def100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -2.6e-34)
(* x y)
(if (<= x 3.1e-33)
(- z)
(if (<= x 1.45e+40) (* x y) (if (<= x 1.95e+258) (* x z) (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.6e-34) {
tmp = x * y;
} else if (x <= 3.1e-33) {
tmp = -z;
} else if (x <= 1.45e+40) {
tmp = x * y;
} else if (x <= 1.95e+258) {
tmp = x * 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 (x <= (-2.6d-34)) then
tmp = x * y
else if (x <= 3.1d-33) then
tmp = -z
else if (x <= 1.45d+40) then
tmp = x * y
else if (x <= 1.95d+258) then
tmp = x * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.6e-34) {
tmp = x * y;
} else if (x <= 3.1e-33) {
tmp = -z;
} else if (x <= 1.45e+40) {
tmp = x * y;
} else if (x <= 1.95e+258) {
tmp = x * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.6e-34: tmp = x * y elif x <= 3.1e-33: tmp = -z elif x <= 1.45e+40: tmp = x * y elif x <= 1.95e+258: tmp = x * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.6e-34) tmp = Float64(x * y); elseif (x <= 3.1e-33) tmp = Float64(-z); elseif (x <= 1.45e+40) tmp = Float64(x * y); elseif (x <= 1.95e+258) tmp = Float64(x * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.6e-34) tmp = x * y; elseif (x <= 3.1e-33) tmp = -z; elseif (x <= 1.45e+40) tmp = x * y; elseif (x <= 1.95e+258) tmp = x * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.6e-34], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.1e-33], (-z), If[LessEqual[x, 1.45e+40], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.95e+258], N[(x * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{-34}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{-33}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{+40}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.95 \cdot 10^{+258}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.5999999999999999e-34 or 3.09999999999999997e-33 < x < 1.45000000000000009e40 or 1.95000000000000019e258 < x Initial program 100.0%
Taylor expanded in y around inf 74.4%
if -2.5999999999999999e-34 < x < 3.09999999999999997e-33Initial program 100.0%
Taylor expanded in x around 0 77.8%
neg-mul-177.8%
Simplified77.8%
if 1.45000000000000009e40 < x < 1.95000000000000019e258Initial program 99.9%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 66.2%
Final simplification74.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e-34) (not (<= x 2.5e-34))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-34) || !(x <= 2.5e-34)) {
tmp = x * (z + y);
} else {
tmp = -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 <= (-5.8d-34)) .or. (.not. (x <= 2.5d-34))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-34) || !(x <= 2.5e-34)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.8e-34) or not (x <= 2.5e-34): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.8e-34) || !(x <= 2.5e-34)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.8e-34) || ~((x <= 2.5e-34))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e-34], N[Not[LessEqual[x, 2.5e-34]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-34} \lor \neg \left(x \leq 2.5 \cdot 10^{-34}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -5.8000000000000004e-34 or 2.5000000000000001e-34 < x Initial program 100.0%
Taylor expanded in x around inf 96.5%
+-commutative96.5%
Simplified96.5%
if -5.8000000000000004e-34 < x < 2.5000000000000001e-34Initial program 100.0%
Taylor expanded in x around 0 77.8%
neg-mul-177.8%
Simplified77.8%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.6e-34) (not (<= x 5.2e-8))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e-34) || !(x <= 5.2e-8)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.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) :: tmp
if ((x <= (-1.6d-34)) .or. (.not. (x <= 5.2d-8))) then
tmp = x * (z + y)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e-34) || !(x <= 5.2e-8)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.6e-34) or not (x <= 5.2e-8): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.6e-34) || !(x <= 5.2e-8)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.6e-34) || ~((x <= 5.2e-8))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.6e-34], N[Not[LessEqual[x, 5.2e-8]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-34} \lor \neg \left(x \leq 5.2 \cdot 10^{-8}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -1.60000000000000001e-34 or 5.2000000000000002e-8 < x Initial program 100.0%
Taylor expanded in x around inf 98.7%
+-commutative98.7%
Simplified98.7%
if -1.60000000000000001e-34 < x < 5.2000000000000002e-8Initial program 100.0%
Taylor expanded in y around 0 76.4%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.5e-34) (not (<= x 1.02e-6))) (* x (+ z y)) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e-34) || !(x <= 1.02e-6)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - 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 <= (-6.5d-34)) .or. (.not. (x <= 1.02d-6))) then
tmp = x * (z + y)
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e-34) || !(x <= 1.02e-6)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.5e-34) or not (x <= 1.02e-6): tmp = x * (z + y) else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.5e-34) || !(x <= 1.02e-6)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.5e-34) || ~((x <= 1.02e-6))) tmp = x * (z + y); else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.5e-34], N[Not[LessEqual[x, 1.02e-6]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-34} \lor \neg \left(x \leq 1.02 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if x < -6.49999999999999985e-34 or 1.02e-6 < x Initial program 100.0%
Taylor expanded in x around inf 98.7%
+-commutative98.7%
Simplified98.7%
if -6.49999999999999985e-34 < x < 1.02e-6Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
associate-+r+100.0%
metadata-eval100.0%
mul-1-neg100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 76.4%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (<= x -4.8e-33) (+ (* x z) (* x y)) (if (<= x 2.2e-9) (- (* x z) z) (* x (+ z y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e-33) {
tmp = (x * z) + (x * y);
} else if (x <= 2.2e-9) {
tmp = (x * z) - z;
} else {
tmp = x * (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 (x <= (-4.8d-33)) then
tmp = (x * z) + (x * y)
else if (x <= 2.2d-9) then
tmp = (x * z) - z
else
tmp = x * (z + y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e-33) {
tmp = (x * z) + (x * y);
} else if (x <= 2.2e-9) {
tmp = (x * z) - z;
} else {
tmp = x * (z + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.8e-33: tmp = (x * z) + (x * y) elif x <= 2.2e-9: tmp = (x * z) - z else: tmp = x * (z + y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.8e-33) tmp = Float64(Float64(x * z) + Float64(x * y)); elseif (x <= 2.2e-9) tmp = Float64(Float64(x * z) - z); else tmp = Float64(x * Float64(z + y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.8e-33) tmp = (x * z) + (x * y); elseif (x <= 2.2e-9) tmp = (x * z) - z; else tmp = x * (z + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.8e-33], N[(N[(x * z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.2e-9], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-33}:\\
\;\;\;\;x \cdot z + x \cdot y\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{-9}:\\
\;\;\;\;x \cdot z - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + y\right)\\
\end{array}
\end{array}
if x < -4.8e-33Initial program 100.0%
Taylor expanded in x around inf 98.5%
if -4.8e-33 < x < 2.1999999999999998e-9Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
associate-+r+100.0%
metadata-eval100.0%
mul-1-neg100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 76.4%
if 2.1999999999999998e-9 < x Initial program 99.9%
Taylor expanded in x around inf 98.9%
+-commutative98.9%
Simplified98.9%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.52e-31) (* x y) (if (<= x 1.9e-33) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.52e-31) {
tmp = x * y;
} else if (x <= 1.9e-33) {
tmp = -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 (x <= (-1.52d-31)) then
tmp = x * y
else if (x <= 1.9d-33) then
tmp = -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.52e-31) {
tmp = x * y;
} else if (x <= 1.9e-33) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.52e-31: tmp = x * y elif x <= 1.9e-33: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.52e-31) tmp = Float64(x * y); elseif (x <= 1.9e-33) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.52e-31) tmp = x * y; elseif (x <= 1.9e-33) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.52e-31], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.9e-33], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.52 \cdot 10^{-31}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-33}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.52000000000000003e-31 or 1.89999999999999997e-33 < x Initial program 100.0%
Taylor expanded in y around inf 63.4%
if -1.52000000000000003e-31 < x < 1.89999999999999997e-33Initial program 100.0%
Taylor expanded in x around 0 77.8%
neg-mul-177.8%
Simplified77.8%
Final simplification69.9%
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + 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 = (x * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
associate-+r+100.0%
metadata-eval100.0%
mul-1-neg100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 37.4%
neg-mul-137.4%
Simplified37.4%
Final simplification37.4%
herbie shell --seed 2023238
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))