
(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.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
+-commutative98.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.9e+257)
(* x y)
(if (<= x -7.6e+195)
(* x z)
(if (<= x -3.5e-11) (* x y) (if (<= x 1.0) (- z) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e+257) {
tmp = x * y;
} else if (x <= -7.6e+195) {
tmp = x * z;
} else if (x <= -3.5e-11) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = -z;
} else {
tmp = x * 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.9d+257)) then
tmp = x * y
else if (x <= (-7.6d+195)) then
tmp = x * z
else if (x <= (-3.5d-11)) then
tmp = x * y
else if (x <= 1.0d0) then
tmp = -z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e+257) {
tmp = x * y;
} else if (x <= -7.6e+195) {
tmp = x * z;
} else if (x <= -3.5e-11) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = -z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.9e+257: tmp = x * y elif x <= -7.6e+195: tmp = x * z elif x <= -3.5e-11: tmp = x * y elif x <= 1.0: tmp = -z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.9e+257) tmp = Float64(x * y); elseif (x <= -7.6e+195) tmp = Float64(x * z); elseif (x <= -3.5e-11) tmp = Float64(x * y); elseif (x <= 1.0) tmp = Float64(-z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.9e+257) tmp = x * y; elseif (x <= -7.6e+195) tmp = x * z; elseif (x <= -3.5e-11) tmp = x * y; elseif (x <= 1.0) tmp = -z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.9e+257], N[(x * y), $MachinePrecision], If[LessEqual[x, -7.6e+195], N[(x * z), $MachinePrecision], If[LessEqual[x, -3.5e-11], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.0], (-z), N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{+257}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -7.6 \cdot 10^{+195}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -3.5 \cdot 10^{-11}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.89999999999999999e257 or -7.6e195 < x < -3.50000000000000019e-11Initial program 92.8%
Taylor expanded in y around inf 65.3%
if -1.89999999999999999e257 < x < -7.6e195 or 1 < x Initial program 98.7%
Taylor expanded in y around 0 62.2%
Taylor expanded in x around inf 60.4%
*-commutative60.4%
Simplified60.4%
if -3.50000000000000019e-11 < x < 1Initial program 100.0%
Taylor expanded in x around 0 68.5%
neg-mul-168.5%
Simplified68.5%
Final simplification65.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.2e-11) (not (<= x 6.4e-15))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e-11) || !(x <= 6.4e-15)) {
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 <= (-4.2d-11)) .or. (.not. (x <= 6.4d-15))) 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 <= -4.2e-11) || !(x <= 6.4e-15)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.2e-11) or not (x <= 6.4e-15): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.2e-11) || !(x <= 6.4e-15)) 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 <= -4.2e-11) || ~((x <= 6.4e-15))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.2e-11], N[Not[LessEqual[x, 6.4e-15]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{-11} \lor \neg \left(x \leq 6.4 \cdot 10^{-15}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.1999999999999997e-11 or 6.3999999999999999e-15 < x Initial program 96.3%
Taylor expanded in x around inf 97.3%
+-commutative97.3%
Simplified97.3%
if -4.1999999999999997e-11 < x < 6.3999999999999999e-15Initial program 100.0%
Taylor expanded in x around 0 69.1%
neg-mul-169.1%
Simplified69.1%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -4e-10) (not (<= x 12000.0))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4e-10) || !(x <= 12000.0)) {
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 <= (-4d-10)) .or. (.not. (x <= 12000.0d0))) 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 <= -4e-10) || !(x <= 12000.0)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4e-10) or not (x <= 12000.0): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4e-10) || !(x <= 12000.0)) 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 <= -4e-10) || ~((x <= 12000.0))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4e-10], N[Not[LessEqual[x, 12000.0]], $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 -4 \cdot 10^{-10} \lor \neg \left(x \leq 12000\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -4.00000000000000015e-10 or 12000 < x Initial program 96.2%
Taylor expanded in x around inf 99.1%
+-commutative99.1%
Simplified99.1%
if -4.00000000000000015e-10 < x < 12000Initial program 100.0%
Taylor expanded in y around 0 69.5%
Final simplification84.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.4e-10) (not (<= x 8e-14))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e-10) || !(x <= 8e-14)) {
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 <= (-1.4d-10)) .or. (.not. (x <= 8d-14))) 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 <= -1.4e-10) || !(x <= 8e-14)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.4e-10) or not (x <= 8e-14): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.4e-10) || !(x <= 8e-14)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.4e-10) || ~((x <= 8e-14))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.4e-10], N[Not[LessEqual[x, 8e-14]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-10} \lor \neg \left(x \leq 8 \cdot 10^{-14}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.40000000000000008e-10 or 7.99999999999999999e-14 < x Initial program 96.3%
Taylor expanded in y around inf 52.4%
if -1.40000000000000008e-10 < x < 7.99999999999999999e-14Initial program 100.0%
Taylor expanded in x around 0 69.1%
neg-mul-169.1%
Simplified69.1%
Final simplification60.2%
(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.0%
Taylor expanded in x around 0 34.3%
neg-mul-134.3%
Simplified34.3%
Final simplification34.3%
herbie shell --seed 2024082
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))