
(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 6 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 (- (* 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 98.4%
*-commutative98.4%
sub-neg98.4%
distribute-rgt-in98.4%
metadata-eval98.4%
neg-mul-198.4%
associate-+r+98.4%
unsub-neg98.4%
+-commutative98.4%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -2e+204)
(* x z)
(if (<= x -1.9e+173)
(* x y)
(if (<= x -9.5e+153)
(* x z)
(if (<= x -8e+96)
(* x y)
(if (<= x -5.1e-8)
(* x z)
(if (<= x 1.0) (- z) (if (<= x 9.5e+181) (* x z) (* x y)))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2e+204) {
tmp = x * z;
} else if (x <= -1.9e+173) {
tmp = x * y;
} else if (x <= -9.5e+153) {
tmp = x * z;
} else if (x <= -8e+96) {
tmp = x * y;
} else if (x <= -5.1e-8) {
tmp = x * z;
} else if (x <= 1.0) {
tmp = -z;
} else if (x <= 9.5e+181) {
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 <= (-2d+204)) then
tmp = x * z
else if (x <= (-1.9d+173)) then
tmp = x * y
else if (x <= (-9.5d+153)) then
tmp = x * z
else if (x <= (-8d+96)) then
tmp = x * y
else if (x <= (-5.1d-8)) then
tmp = x * z
else if (x <= 1.0d0) then
tmp = -z
else if (x <= 9.5d+181) 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 <= -2e+204) {
tmp = x * z;
} else if (x <= -1.9e+173) {
tmp = x * y;
} else if (x <= -9.5e+153) {
tmp = x * z;
} else if (x <= -8e+96) {
tmp = x * y;
} else if (x <= -5.1e-8) {
tmp = x * z;
} else if (x <= 1.0) {
tmp = -z;
} else if (x <= 9.5e+181) {
tmp = x * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2e+204: tmp = x * z elif x <= -1.9e+173: tmp = x * y elif x <= -9.5e+153: tmp = x * z elif x <= -8e+96: tmp = x * y elif x <= -5.1e-8: tmp = x * z elif x <= 1.0: tmp = -z elif x <= 9.5e+181: tmp = x * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2e+204) tmp = Float64(x * z); elseif (x <= -1.9e+173) tmp = Float64(x * y); elseif (x <= -9.5e+153) tmp = Float64(x * z); elseif (x <= -8e+96) tmp = Float64(x * y); elseif (x <= -5.1e-8) tmp = Float64(x * z); elseif (x <= 1.0) tmp = Float64(-z); elseif (x <= 9.5e+181) 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 <= -2e+204) tmp = x * z; elseif (x <= -1.9e+173) tmp = x * y; elseif (x <= -9.5e+153) tmp = x * z; elseif (x <= -8e+96) tmp = x * y; elseif (x <= -5.1e-8) tmp = x * z; elseif (x <= 1.0) tmp = -z; elseif (x <= 9.5e+181) tmp = x * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2e+204], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.9e+173], N[(x * y), $MachinePrecision], If[LessEqual[x, -9.5e+153], N[(x * z), $MachinePrecision], If[LessEqual[x, -8e+96], N[(x * y), $MachinePrecision], If[LessEqual[x, -5.1e-8], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.0], (-z), If[LessEqual[x, 9.5e+181], N[(x * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+204}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.9 \cdot 10^{+173}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -9.5 \cdot 10^{+153}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -8 \cdot 10^{+96}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -5.1 \cdot 10^{-8}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{+181}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.99999999999999998e204 or -1.90000000000000005e173 < x < -9.4999999999999995e153 or -8.0000000000000004e96 < x < -5.10000000000000001e-8 or 1 < x < 9.50000000000000032e181Initial program 97.4%
Taylor expanded in y around 0 68.5%
Taylor expanded in x around inf 68.2%
*-commutative68.2%
Simplified68.2%
if -1.99999999999999998e204 < x < -1.90000000000000005e173 or -9.4999999999999995e153 < x < -8.0000000000000004e96 or 9.50000000000000032e181 < x Initial program 95.7%
Taylor expanded in y around inf 79.2%
if -5.10000000000000001e-8 < x < 1Initial program 100.0%
Taylor expanded in x around 0 72.6%
mul-1-neg72.6%
Simplified72.6%
Final simplification72.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.95e-34) (not (<= x 26.5))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.95e-34) || !(x <= 26.5)) {
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 <= (-2.95d-34)) .or. (.not. (x <= 26.5d0))) 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 <= -2.95e-34) || !(x <= 26.5)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.95e-34) or not (x <= 26.5): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.95e-34) || !(x <= 26.5)) 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 <= -2.95e-34) || ~((x <= 26.5))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.95e-34], N[Not[LessEqual[x, 26.5]], $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 -2.95 \cdot 10^{-34} \lor \neg \left(x \leq 26.5\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -2.9500000000000001e-34 or 26.5 < x Initial program 97.0%
Taylor expanded in x around inf 97.7%
+-commutative97.7%
Simplified97.7%
if -2.9500000000000001e-34 < x < 26.5Initial program 100.0%
Taylor expanded in y around 0 76.9%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.3e-34) (not (<= x 5.5e-52))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e-34) || !(x <= 5.5e-52)) {
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 <= (-3.3d-34)) .or. (.not. (x <= 5.5d-52))) 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 <= -3.3e-34) || !(x <= 5.5e-52)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.3e-34) or not (x <= 5.5e-52): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.3e-34) || !(x <= 5.5e-52)) 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 <= -3.3e-34) || ~((x <= 5.5e-52))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.3e-34], N[Not[LessEqual[x, 5.5e-52]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{-34} \lor \neg \left(x \leq 5.5 \cdot 10^{-52}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.29999999999999983e-34 or 5.5e-52 < x Initial program 97.2%
Taylor expanded in x around inf 93.7%
+-commutative93.7%
Simplified93.7%
if -3.29999999999999983e-34 < x < 5.5e-52Initial program 100.0%
Taylor expanded in x around 0 78.3%
mul-1-neg78.3%
Simplified78.3%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.3e-34) (not (<= x 1e-51))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e-34) || !(x <= 1e-51)) {
tmp = x * 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 <= (-3.3d-34)) .or. (.not. (x <= 1d-51))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e-34) || !(x <= 1e-51)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.3e-34) or not (x <= 1e-51): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.3e-34) || !(x <= 1e-51)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.3e-34) || ~((x <= 1e-51))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.3e-34], N[Not[LessEqual[x, 1e-51]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{-34} \lor \neg \left(x \leq 10^{-51}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.29999999999999983e-34 or 1e-51 < x Initial program 97.2%
Taylor expanded in y around inf 53.0%
if -3.29999999999999983e-34 < x < 1e-51Initial program 100.0%
Taylor expanded in x around 0 78.3%
mul-1-neg78.3%
Simplified78.3%
Final simplification64.3%
(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 98.4%
Taylor expanded in x around 0 38.6%
mul-1-neg38.6%
Simplified38.6%
herbie shell --seed 2024101
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))